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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
195
        /**
196
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
197
         */
198
        public void before() {
199
                layout.getEFS().startComplexCommand();
200
                ArrayList auxList = new ArrayList();
201
                int num = 0;
202

    
203
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
204
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
205

    
206
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
207
                                auxList.add(fframe);
208
                                layout.delFFrame(fframe);
209
                                ///layout.getFFrames().remove(fframe);
210
                                num++;
211
                        }
212
                }
213

    
214
                for (int i = num - 1; i >= 0; i--) {
215
                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
216
                        ///layout.getFFrames().add((IFFrame) auxList.get(i));
217
                }
218
                layout.getEFS().endComplexCommand();
219
                layout.setStatus(Layout.DESACTUALIZADO);
220
                layout.repaint();
221
        }
222

    
223
        /**
224
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
225
         * seleccionados.
226
         */
227
        public void behind() {
228
                layout.getEFS().startComplexCommand();
229
                ArrayList auxList = new ArrayList();
230
                int num = 0;
231

    
232
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
233
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
234

    
235
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
236
                                auxList.add(fframe);
237
                                layout.delFFrame(fframe);
238
                                ///layout.getFFrames().remove(fframe);
239
                                num++;
240
                        }
241
                }
242

    
243
                for (int i = 0; i < num; i++) {
244
                        layout.addFFrame((IFFrame) auxList.get(i),true,true);
245
                        ///layout.getFFrames().add(0, (IFFrame) auxList.get(i));
246
                }
247
                layout.getEFS().endComplexCommand();
248
                layout.setStatus(Layout.DESACTUALIZADO);
249
                layout.repaint();
250
        }
251

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

    
259
                if (selecList.length == 1) {
260
                        IFFrame frame=selecList[0];//.cloneFFrame(layout);
261
                        int toolaux = layout.getTool();
262
                        layout.setTool(getType(frame));
263
                        layout.openFFrameDialog(frame);
264
                        //layout.getEFS().modifyFFrame(selecList[0],frame);
265
                        //layout.updateFFrames();
266
                        layout.setTool(toolaux);
267
                }
268
        }
269

    
270
        /**
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
                } else if (fframe instanceof FFrameNorth) {
287
                        return Layout.RECTANGLENORTH;
288
                } else if (fframe instanceof FFrameTable) {
289
                        return Layout.RECTANGLEBOX;
290
                } 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
                } else if (fframe instanceof FFrameGroup) {
297
                        return Layout.RECTANGLEGROUP;
298
                }
299

    
300
                return Layout.SELECT;
301
        }
302

    
303
        /**
304
         * Selecci?n de todos los FFrames del Layout.
305
         */
306
        public void selecAll() {
307
                for (int i = layout.getFFrames().length - 1; i >= 0; i--) {
308
                        IFFrame fframe = (IFFrame) layout.getFFrame(i);
309
                        fframe.setSelected(true);
310
                }
311

    
312
                layout.setStatus(Layout.DESACTUALIZADO);
313
                layout.repaint();
314
        }
315

    
316
        /**
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
                
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
        }
337
}