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
/*
2
 * Created on 27-jul-2004
3
 *
4
 */
5
/* 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
package com.iver.cit.gvsig.gui.layout;
46

    
47
import com.iver.andami.PluginServices;
48

    
49
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
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable;
53
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
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
57
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
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameUseFMap;
63

    
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
        private Layout layout;
76
        private FAlignDialog m_alignLayout = null;
77
        private FBorderDialog borderdialog = null;
78
        private FPositionDialog positiondialog = null;
79

    
80
        /**
81
         * Crea un nuevo FLayoutGraphics.
82
         *
83
         * @param l Referencia al Layout.
84
         */
85
        public FLayoutGraphics(Layout l) {
86
                layout = l;
87
        }
88

    
89
        /**
90
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
91
         */
92
        public void simplify() {
93
                layout.getEFS().startComplexCommand();
94
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
95
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
96

    
97
                        if (fframe instanceof FFrameLegend) {
98
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
99
                                        ((FFrameLegend) fframe).toFFrames(layout);
100
                                }
101
                        }
102
                }
103
                layout.getEFS().endComplexCommand();
104
                layout.setStatus(Layout.DESACTUALIZADO);
105
                layout.repaint();
106
        }
107

    
108
        /**
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

    
116
                if (layout.getFFrames().length > 1) {
117
                        ArrayList selecList = new ArrayList();
118

    
119
                        for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
120
                                IFFrame fframe = (IFFrame) layout.getFFrame(i);
121

    
122
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
123
                                        selecList.add(fframe);
124
                                        layout.delFFrame(fframe);
125
                                        ///layout.getFFrames().remove(fframe);
126
                                }
127
                        }
128

    
129
                        for (int i = selecList.size() - 1; i >= 0; i--) {
130
                                ((FFrameGroup) fframegroup).addFFrame((IFFrame) selecList.get(i));
131
                        }
132

    
133
                        ((FFrameGroup) fframegroup).setAt(layout.getAT());
134

    
135
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getAT());
136

    
137
                        //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

    
141
                        fframegroup.setBoundBox(rd1);
142
                        fframegroup.setSelected(true);
143
                        layout.addFFrame(fframegroup, true,true);
144
                        layout.setStatus(Layout.DESACTUALIZADO);
145
                        layout.repaint();
146
                }
147
        }
148

    
149
        /**
150
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
151
         * FFrames individuales.
152
         */
153
        public void ungrouping() {
154
                layout.getEFS().startComplexCommand();
155
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
156
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
157

    
158
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
159
                                if (fframe instanceof FFrameGroup) {
160
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
161
                                        ArrayList selecList = new ArrayList();
162

    
163
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
164
                                                        j--) {
165
                                                selecList.add(fframegroup.getFFrames()[j]);
166

    
167
                                                ///fframegroup.getFFrames().remove(j);
168
                                        }
169

    
170
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
171
                                                IFFrame frame=(IFFrame) selecList.get(j);
172
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
173
                                                layout.addFFrame(frame, false,true);
174
                                        }
175

    
176
                                        ///if (fframegroup.getFFrames().length==0) {
177
                                                layout.delFFrame(fframegroup);
178
                                                ///layout.getFFrames().remove(fframegroup);
179
                                        ///}
180
                                }
181
                        }
182
                }
183
                layout.getEFS().endComplexCommand();
184
                layout.setStatus(Layout.DESACTUALIZADO);
185
                layout.repaint();
186
        }
187

    
188
        /**
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
                layout.getEFS().startComplexCommand();
200
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
201
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
202
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
203
                                if (fframe instanceof FFrameGroup) {
204
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
205
                                }
206

    
207
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
208
                                fframeAux.setLevel(layout.getNumBefore());
209
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
210
                                fframeAux.getBoundingBox(layout.getAT());
211
                        }
212
                }
213
                layout.getEFS().endComplexCommand();
214
                layout.updateFFrames();
215
                layout.refresh();
216
        }
217

    
218
        /**
219
         * 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
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
246
         * seleccionados.
247
         */
248
        public void behind() {
249
                layout.getEFS().startComplexCommand();
250
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
251
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
252
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
253
                                if (fframe instanceof FFrameGroup) {
254
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
255
                                }
256

    
257
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
258
                                fframeAux.setLevel(layout.getNumBehind());
259
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
260
                                fframeAux.getBoundingBox(layout.getAT());
261
                        }
262
                }
263
                layout.getEFS().endComplexCommand();
264
                layout.updateFFrames();
265
                layout.refresh();
266
        }
267

    
268
        /**
269
         * 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
         * 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
                IFFrame[] selecList = layout.getFFrameSelected();
302

    
303
                if (selecList.length == 1) {
304
                        IFFrame frame=selecList[0];//.cloneFFrame(layout);
305
                        int toolaux = layout.getTool();
306
                        layout.setTool(getType(frame));
307
                        layout.openFFrameDialog(frame);
308
                        //layout.getEFS().modifyFFrame(selecList[0],frame);
309
                        //layout.updateFFrames();
310
                        layout.setTool(toolaux);
311
                }
312
        }
313

    
314
        /**
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
                } else if (fframe instanceof FFrameNorth) {
331
                        return Layout.RECTANGLENORTH;
332
                } else if (fframe instanceof FFrameTable) {
333
                        return Layout.RECTANGLEBOX;
334
                } 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
                } else if (fframe instanceof FFrameGroup) {
341
                        return Layout.RECTANGLEGROUP;
342
                }
343

    
344
                return Layout.SELECT;
345
        }
346

    
347
        /**
348
         * Selecci?n de todos los FFrames del Layout.
349
         */
350
        public void selecAll() {
351
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
352
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
353
                        fframe.setSelected(true);
354
                }
355

    
356
                layout.setStatus(Layout.DESACTUALIZADO);
357
                layout.repaint();
358
        }
359

    
360
        /**
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

    
373
                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
        }
381
}