Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutGraphics.java @ 4774

History | View | Annotate | Download (9.42 KB)

1 312 fernando
/*
2
 * Created on 27-jul-2004
3
 *
4
 */
5 1103 fjp
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45 312 fernando
package com.iver.cit.gvsig.gui.layout;
46
47 596 fernando
import com.iver.andami.PluginServices;
48 1074 vcaballero
49 312 fernando
import com.iver.cit.gvsig.gui.layout.dialogs.FAlignDialog;
50
import com.iver.cit.gvsig.gui.layout.dialogs.FBorderDialog;
51
import com.iver.cit.gvsig.gui.layout.dialogs.FPositionDialog;
52 4774 caballero
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable;
53 312 fernando
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
54
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
55
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
56 2914 caballero
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
57 312 fernando
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
58
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
59
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
60
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
61
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
62
63
import java.awt.geom.Rectangle2D;
64
65
import java.util.ArrayList;
66
67
68
/**
69
 * Operaciones realizadas sobre el conjunto de FFrames.
70
 *
71
 * @author Vicente Caballero Navarro
72
 */
73
public class FLayoutGraphics {
74 1074 vcaballero
        private Layout layout;
75
        private FAlignDialog m_alignLayout = null;
76
        private FBorderDialog borderdialog = null;
77
        private FPositionDialog positiondialog = null;
78 312 fernando
79 1074 vcaballero
        /**
80
         * Crea un nuevo FLayoutGraphics.
81
         *
82
         * @param l Referencia al Layout.
83
         */
84
        public FLayoutGraphics(Layout l) {
85
                layout = l;
86
        }
87 312 fernando
88 1074 vcaballero
        /**
89
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
90
         */
91
        public void simplify() {
92 3550 caballero
                layout.getEFS().startComplexCommand();
93
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
94
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
95 312 fernando
96 1074 vcaballero
                        if (fframe instanceof FFrameLegend) {
97 2263 vcaballero
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
98 1074 vcaballero
                                        ((FFrameLegend) fframe).toFFrames(layout);
99
                                }
100
                        }
101
                }
102 3550 caballero
                layout.getEFS().endComplexCommand();
103 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
104
                layout.repaint();
105 1074 vcaballero
        }
106 312 fernando
107 1074 vcaballero
        /**
108
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
109
         */
110
        public void grouping() {
111
                //Rectangle2D rex = new Rectangle2D.Double();
112
                //                Se debe controlar de alguna forma si hay varios seleccionados.
113
                IFFrame fframegroup = new FFrameGroup();
114 312 fernando
115 3550 caballero
                if (layout.getFFrames().length > 1) {
116 1074 vcaballero
                        ArrayList selecList = new ArrayList();
117 312 fernando
118 3550 caballero
                        for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
119
                                IFFrame fframe = (IFFrame) layout.getFFrame(i);
120 312 fernando
121 2263 vcaballero
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
122 1074 vcaballero
                                        selecList.add(fframe);
123 3550 caballero
                                        layout.delFFrame(fframe);
124
                                        ///layout.getFFrames().remove(fframe);
125 1074 vcaballero
                                }
126
                        }
127 312 fernando
128 1074 vcaballero
                        for (int i = selecList.size() - 1; i >= 0; i--) {
129
                                ((FFrameGroup) fframegroup).addFFrame((IFFrame) selecList.get(i));
130
                        }
131 312 fernando
132 1074 vcaballero
                        ((FFrameGroup) fframegroup).setAt(layout.getAT());
133 312 fernando
134 1074 vcaballero
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getAT());
135 312 fernando
136 1074 vcaballero
                        //Rectangle re=new Rectangle((int)rd.getMinX(),(int)rd.getMinY(),(int)rd.getWidth(),(int)rd.getHeight());
137
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
138
                                        layout.getAT());
139 312 fernando
140 1074 vcaballero
                        fframegroup.setBoundBox(rd1);
141
                        fframegroup.setSelected(true);
142 2835 caballero
                        layout.addFFrame(fframegroup, true,true);
143 312 fernando
                        layout.setStatus(Layout.DESACTUALIZADO);
144
                        layout.repaint();
145 1074 vcaballero
                }
146
        }
147 312 fernando
148 1074 vcaballero
        /**
149
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
150
         * FFrames individuales.
151
         */
152
        public void ungrouping() {
153 3550 caballero
                layout.getEFS().startComplexCommand();
154
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
155
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
156 312 fernando
157 2263 vcaballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
158 1074 vcaballero
                                if (fframe instanceof FFrameGroup) {
159
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
160
                                        ArrayList selecList = new ArrayList();
161 312 fernando
162 3550 caballero
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
163 1074 vcaballero
                                                        j--) {
164 3550 caballero
                                                selecList.add(fframegroup.getFFrames()[j]);
165
166
                                                ///fframegroup.getFFrames().remove(j);
167 1074 vcaballero
                                        }
168 312 fernando
169 1074 vcaballero
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
170 2474 caballero
                                                IFFrame frame=(IFFrame) selecList.get(j);
171
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
172 2835 caballero
                                                layout.addFFrame(frame, false,true);
173 1074 vcaballero
                                        }
174 312 fernando
175 3550 caballero
                                        ///if (fframegroup.getFFrames().length==0) {
176
                                                layout.delFFrame(fframegroup);
177
                                                ///layout.getFFrames().remove(fframegroup);
178
                                        ///}
179 1074 vcaballero
                                }
180
                        }
181
                }
182 3550 caballero
                layout.getEFS().endComplexCommand();
183 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
184
                layout.repaint();
185 1074 vcaballero
        }
186 312 fernando
187 1074 vcaballero
        /**
188
         * Abre el di?logo para alinear los FFrames.
189
         */
190
        public void aligning() {
191
                m_alignLayout = new FAlignDialog(layout);
192
                PluginServices.getMDIManager().addView(m_alignLayout);
193
        }
194 312 fernando
195 1074 vcaballero
        /**
196
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
197
         */
198
        public void before() {
199 3550 caballero
                layout.getEFS().startComplexCommand();
200 1074 vcaballero
                ArrayList auxList = new ArrayList();
201
                int num = 0;
202 312 fernando
203 3550 caballero
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
204
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
205 312 fernando
206 2263 vcaballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
207 1074 vcaballero
                                auxList.add(fframe);
208 3550 caballero
                                layout.delFFrame(fframe);
209
                                ///layout.getFFrames().remove(fframe);
210 1074 vcaballero
                                num++;
211
                        }
212
                }
213 312 fernando
214 1074 vcaballero
                for (int i = num - 1; i >= 0; i--) {
215 3550 caballero
                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
216
                        ///layout.getFFrames().add((IFFrame) auxList.get(i));
217 1074 vcaballero
                }
218 3550 caballero
                layout.getEFS().endComplexCommand();
219 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
220
                layout.repaint();
221 1074 vcaballero
        }
222 312 fernando
223 1074 vcaballero
        /**
224
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
225
         * seleccionados.
226
         */
227
        public void behind() {
228 3550 caballero
                layout.getEFS().startComplexCommand();
229 1074 vcaballero
                ArrayList auxList = new ArrayList();
230
                int num = 0;
231 312 fernando
232 3550 caballero
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
233
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
234 312 fernando
235 2263 vcaballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
236 1074 vcaballero
                                auxList.add(fframe);
237 3550 caballero
                                layout.delFFrame(fframe);
238
                                ///layout.getFFrames().remove(fframe);
239 1074 vcaballero
                                num++;
240
                        }
241
                }
242 312 fernando
243 1074 vcaballero
                for (int i = 0; i < num; i++) {
244 3550 caballero
                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
245
                        ///layout.getFFrames().add(0, (IFFrame) auxList.get(i));
246 1074 vcaballero
                }
247 3550 caballero
                layout.getEFS().endComplexCommand();
248 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
249
                layout.repaint();
250 1074 vcaballero
        }
251 312 fernando
252 1074 vcaballero
        /**
253
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
254
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
255
         */
256
        public void openFFrameDialog() {
257 2474 caballero
                IFFrame[] selecList = layout.getFFrameSelected();
258 312 fernando
259 2474 caballero
                if (selecList.length == 1) {
260 3550 caballero
                        IFFrame frame=selecList[0];//.cloneFFrame(layout);
261 1074 vcaballero
                        int toolaux = layout.getTool();
262 3550 caballero
                        layout.setTool(getType(frame));
263
                        layout.openFFrameDialog(frame);
264
                        //layout.getEFS().modifyFFrame(selecList[0],frame);
265
                        //layout.updateFFrames();
266 1074 vcaballero
                        layout.setTool(toolaux);
267
                }
268
        }
269 312 fernando
270 1074 vcaballero
        /**
271
         * Devuelve un entero que representa el tipo de FFrame  que se le pasa como
272
         * par?metro.
273
         *
274
         * @param fframe FFrame que se pasa como par?metro, para saber de que tipo
275
         *                   es.
276
         *
277
         * @return entero.
278
         */
279
        private int getType(IFFrame fframe) {
280
                if (fframe instanceof FFrameView) {
281
                        return Layout.RECTANGLEVIEW;
282
                } else if (fframe instanceof FFrameText) {
283
                        return Layout.RECTANGLETEXT;
284
                } else if (fframe instanceof FFrameScaleBar) {
285
                        return Layout.RECTANGLESCALEBAR;
286 2914 caballero
                } else if (fframe instanceof FFrameNorth) {
287
                        return Layout.RECTANGLENORTH;
288 4774 caballero
                } else if (fframe instanceof FFrameTable) {
289 3610 caballero
                        return Layout.RECTANGLEBOX;
290 1074 vcaballero
                } else if (fframe instanceof FFramePicture) {
291
                        return Layout.RECTANGLEPICTURE;
292
                } else if (fframe instanceof FFrameLegend) {
293
                        return Layout.RECTANGLELEGEND;
294
                } else if (fframe instanceof FFrameGraphics) {
295
                        return Layout.GRAPHICS;
296 2474 caballero
                } else if (fframe instanceof FFrameGroup) {
297
                        return Layout.RECTANGLEGROUP;
298 1074 vcaballero
                }
299 312 fernando
300 1074 vcaballero
                return Layout.SELECT;
301
        }
302 312 fernando
303 1074 vcaballero
        /**
304
         * Selecci?n de todos los FFrames del Layout.
305
         */
306
        public void selecAll() {
307 3550 caballero
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
308
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
309 312 fernando
                        fframe.setSelected(true);
310 1074 vcaballero
                }
311
312 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
313
                layout.repaint();
314 1074 vcaballero
        }
315 312 fernando
316 1074 vcaballero
        /**
317
         * Abre el di?logo para a?adir un borde a los fframes.
318
         */
319
        public void border() {
320
                borderdialog = new FBorderDialog(layout);
321
                PluginServices.getMDIManager().addView(borderdialog);
322
        }
323
324
        /**
325
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
326
         */
327
        public void position() {
328 1210 vcaballero
329
                IFFrame[] fframes=layout.getFFrameSelected();
330
                if (fframes.length!=0){
331
                        for (int i=0;i<fframes.length;i++){
332
                                positiondialog = new FPositionDialog(layout,fframes[i]);
333
                                PluginServices.getMDIManager().addView(positiondialog);
334
                        }
335
                }
336 1074 vcaballero
        }
337 312 fernando
}