Statistics
| Revision:

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

History | View | Annotate | Download (10.8 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 5474 caballero
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameUseFMap;
63 312 fernando
64
import java.awt.geom.Rectangle2D;
65
66
import java.util.ArrayList;
67
68
69
/**
70
 * Operaciones realizadas sobre el conjunto de FFrames.
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74
public class FLayoutGraphics {
75 1074 vcaballero
        private Layout layout;
76
        private FAlignDialog m_alignLayout = null;
77
        private FBorderDialog borderdialog = null;
78
        private FPositionDialog positiondialog = null;
79 312 fernando
80 1074 vcaballero
        /**
81
         * Crea un nuevo FLayoutGraphics.
82
         *
83
         * @param l Referencia al Layout.
84
         */
85
        public FLayoutGraphics(Layout l) {
86
                layout = l;
87
        }
88 312 fernando
89 1074 vcaballero
        /**
90
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
91
         */
92
        public void simplify() {
93 3550 caballero
                layout.getEFS().startComplexCommand();
94
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
95
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
96 312 fernando
97 1074 vcaballero
                        if (fframe instanceof FFrameLegend) {
98 2263 vcaballero
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
99 1074 vcaballero
                                        ((FFrameLegend) fframe).toFFrames(layout);
100
                                }
101
                        }
102
                }
103 3550 caballero
                layout.getEFS().endComplexCommand();
104 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
105
                layout.repaint();
106 1074 vcaballero
        }
107 312 fernando
108 1074 vcaballero
        /**
109
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
110
         */
111
        public void grouping() {
112
                //Rectangle2D rex = new Rectangle2D.Double();
113
                //                Se debe controlar de alguna forma si hay varios seleccionados.
114
                IFFrame fframegroup = new FFrameGroup();
115 312 fernando
116 3550 caballero
                if (layout.getFFrames().length > 1) {
117 1074 vcaballero
                        ArrayList selecList = new ArrayList();
118 312 fernando
119 3550 caballero
                        for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
120
                                IFFrame fframe = (IFFrame) layout.getFFrame(i);
121 312 fernando
122 2263 vcaballero
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
123 1074 vcaballero
                                        selecList.add(fframe);
124 3550 caballero
                                        layout.delFFrame(fframe);
125
                                        ///layout.getFFrames().remove(fframe);
126 1074 vcaballero
                                }
127
                        }
128 312 fernando
129 1074 vcaballero
                        for (int i = selecList.size() - 1; i >= 0; i--) {
130
                                ((FFrameGroup) fframegroup).addFFrame((IFFrame) selecList.get(i));
131
                        }
132 312 fernando
133 1074 vcaballero
                        ((FFrameGroup) fframegroup).setAt(layout.getAT());
134 312 fernando
135 1074 vcaballero
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getAT());
136 312 fernando
137 1074 vcaballero
                        //Rectangle re=new Rectangle((int)rd.getMinX(),(int)rd.getMinY(),(int)rd.getWidth(),(int)rd.getHeight());
138
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
139
                                        layout.getAT());
140 312 fernando
141 1074 vcaballero
                        fframegroup.setBoundBox(rd1);
142
                        fframegroup.setSelected(true);
143 2835 caballero
                        layout.addFFrame(fframegroup, true,true);
144 312 fernando
                        layout.setStatus(Layout.DESACTUALIZADO);
145
                        layout.repaint();
146 1074 vcaballero
                }
147
        }
148 312 fernando
149 1074 vcaballero
        /**
150
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
151
         * FFrames individuales.
152
         */
153
        public void ungrouping() {
154 3550 caballero
                layout.getEFS().startComplexCommand();
155
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
156
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
157 312 fernando
158 2263 vcaballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
159 1074 vcaballero
                                if (fframe instanceof FFrameGroup) {
160
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
161
                                        ArrayList selecList = new ArrayList();
162 312 fernando
163 3550 caballero
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
164 1074 vcaballero
                                                        j--) {
165 3550 caballero
                                                selecList.add(fframegroup.getFFrames()[j]);
166 5474 caballero
167 3550 caballero
                                                ///fframegroup.getFFrames().remove(j);
168 1074 vcaballero
                                        }
169 312 fernando
170 1074 vcaballero
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
171 2474 caballero
                                                IFFrame frame=(IFFrame) selecList.get(j);
172
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
173 2835 caballero
                                                layout.addFFrame(frame, false,true);
174 1074 vcaballero
                                        }
175 312 fernando
176 3550 caballero
                                        ///if (fframegroup.getFFrames().length==0) {
177
                                                layout.delFFrame(fframegroup);
178
                                                ///layout.getFFrames().remove(fframegroup);
179
                                        ///}
180 1074 vcaballero
                                }
181
                        }
182
                }
183 3550 caballero
                layout.getEFS().endComplexCommand();
184 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
185
                layout.repaint();
186 1074 vcaballero
        }
187 312 fernando
188 1074 vcaballero
        /**
189
         * Abre el di?logo para alinear los FFrames.
190
         */
191
        public void aligning() {
192
                m_alignLayout = new FAlignDialog(layout);
193
                PluginServices.getMDIManager().addView(m_alignLayout);
194
        }
195
        /**
196
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
197
         */
198
        public void before() {
199 3550 caballero
                layout.getEFS().startComplexCommand();
200
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
201
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
202 5474 caballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
203
                                if (fframe instanceof FFrameGroup) {
204
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
205
                                }
206 312 fernando
207 5474 caballero
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
208
                                fframeAux.setLevel(layout.getNumBefore());
209
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
210
                                fframeAux.getBoundingBox(layout.getAT());
211 1074 vcaballero
                        }
212
                }
213 3550 caballero
                layout.getEFS().endComplexCommand();
214 5474 caballero
                layout.updateFFrames();
215
                layout.refresh();
216 1074 vcaballero
        }
217 312 fernando
218 1074 vcaballero
        /**
219 5474 caballero
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
220
         */
221
//        public void before() {
222
//                layout.getEFS().startComplexCommand();
223
//                ArrayList auxList = new ArrayList();
224
//                int num = 0;
225
//
226
//                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
227
//                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
228
//
229
//                        if (fframe.getSelected() != IFFrame.NOSELECT) {
230
//                                fframe.setLevel(layout.getNumBefore());
231
//                                auxList.add(fframe);
232
//                                layout.delFFrame(fframe);
233
//                                num++;
234
//                        }
235
//                }
236
//
237
//                for (int i = num - 1; i >= 0; i--) {
238
//                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
239
//                }
240
//                layout.getEFS().endComplexCommand();
241
//                layout.setStatus(Layout.DESACTUALIZADO);
242
//                layout.repaint();
243
//        }
244
        /**
245 1074 vcaballero
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
246
         * seleccionados.
247
         */
248
        public void behind() {
249 3550 caballero
                layout.getEFS().startComplexCommand();
250
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
251
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
252 5474 caballero
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
253
                                if (fframe instanceof FFrameGroup) {
254
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
255
                                }
256 312 fernando
257 5474 caballero
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
258
                                fframeAux.setLevel(layout.getNumBehind());
259
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
260
                                fframeAux.getBoundingBox(layout.getAT());
261 1074 vcaballero
                        }
262
                }
263 3550 caballero
                layout.getEFS().endComplexCommand();
264 5474 caballero
                layout.updateFFrames();
265
                layout.refresh();
266 1074 vcaballero
        }
267 312 fernando
268 1074 vcaballero
        /**
269 5474 caballero
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
270
         * seleccionados.
271
         */
272
//        public void behind() {
273
//                layout.getEFS().startComplexCommand();
274
//                ArrayList auxList = new ArrayList();
275
//                int num = 0;
276
//
277
//                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
278
//                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
279
//
280
//                        if (fframe.getSelected() != IFFrame.NOSELECT) {
281
//                                fframe.setLevel(layout.getNumBehind());
282
//
283
//                                auxList.add(fframe);
284
//                                layout.delFFrame(fframe);
285
//                                num++;
286
//                        }
287
//                }
288
//
289
//                for (int i = 0; i < num; i++) {
290
//                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
291
//                }
292
//                layout.getEFS().endComplexCommand();
293
//                layout.refresh();
294
//        }
295
296
        /**
297 1074 vcaballero
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
298
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
299
         */
300
        public void openFFrameDialog() {
301 2474 caballero
                IFFrame[] selecList = layout.getFFrameSelected();
302 312 fernando
303 2474 caballero
                if (selecList.length == 1) {
304 3550 caballero
                        IFFrame frame=selecList[0];//.cloneFFrame(layout);
305 1074 vcaballero
                        int toolaux = layout.getTool();
306 3550 caballero
                        layout.setTool(getType(frame));
307
                        layout.openFFrameDialog(frame);
308
                        //layout.getEFS().modifyFFrame(selecList[0],frame);
309
                        //layout.updateFFrames();
310 1074 vcaballero
                        layout.setTool(toolaux);
311
                }
312
        }
313 312 fernando
314 1074 vcaballero
        /**
315
         * Devuelve un entero que representa el tipo de FFrame  que se le pasa como
316
         * par?metro.
317
         *
318
         * @param fframe FFrame que se pasa como par?metro, para saber de que tipo
319
         *                   es.
320
         *
321
         * @return entero.
322
         */
323
        private int getType(IFFrame fframe) {
324
                if (fframe instanceof FFrameView) {
325
                        return Layout.RECTANGLEVIEW;
326
                } else if (fframe instanceof FFrameText) {
327
                        return Layout.RECTANGLETEXT;
328
                } else if (fframe instanceof FFrameScaleBar) {
329
                        return Layout.RECTANGLESCALEBAR;
330 2914 caballero
                } else if (fframe instanceof FFrameNorth) {
331
                        return Layout.RECTANGLENORTH;
332 4774 caballero
                } else if (fframe instanceof FFrameTable) {
333 3610 caballero
                        return Layout.RECTANGLEBOX;
334 1074 vcaballero
                } else if (fframe instanceof FFramePicture) {
335
                        return Layout.RECTANGLEPICTURE;
336
                } else if (fframe instanceof FFrameLegend) {
337
                        return Layout.RECTANGLELEGEND;
338
                } else if (fframe instanceof FFrameGraphics) {
339
                        return Layout.GRAPHICS;
340 2474 caballero
                } else if (fframe instanceof FFrameGroup) {
341
                        return Layout.RECTANGLEGROUP;
342 1074 vcaballero
                }
343 312 fernando
344 1074 vcaballero
                return Layout.SELECT;
345
        }
346 312 fernando
347 1074 vcaballero
        /**
348
         * Selecci?n de todos los FFrames del Layout.
349
         */
350
        public void selecAll() {
351 3550 caballero
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
352
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
353 312 fernando
                        fframe.setSelected(true);
354 1074 vcaballero
                }
355
356 312 fernando
                layout.setStatus(Layout.DESACTUALIZADO);
357
                layout.repaint();
358 1074 vcaballero
        }
359 312 fernando
360 1074 vcaballero
        /**
361
         * Abre el di?logo para a?adir un borde a los fframes.
362
         */
363
        public void border() {
364
                borderdialog = new FBorderDialog(layout);
365
                PluginServices.getMDIManager().addView(borderdialog);
366
        }
367
368
        /**
369
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
370
         */
371
        public void position() {
372 5474 caballero
373 1210 vcaballero
                IFFrame[] fframes=layout.getFFrameSelected();
374
                if (fframes.length!=0){
375
                        for (int i=0;i<fframes.length;i++){
376
                                positiondialog = new FPositionDialog(layout,fframes[i]);
377
                                PluginServices.getMDIManager().addView(positiondialog);
378
                        }
379
                }
380 1074 vcaballero
        }
381 312 fernando
}