Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutGraphics.java @ 8767

History | View | Annotate | Download (9.4 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.project.documents.layout;
46

    
47
import java.awt.geom.Rectangle2D;
48
import java.util.ArrayList;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.cit.gvsig.gui.layout.Layout;
52
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
53
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
54
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
55
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
56
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
57
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
58
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable;
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.project.documents.layout.fframes.IFFrame;
62
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
63
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FAlignDialog;
64
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FBorderDialog;
65
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FPositionDialog;
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
                IFFrame[] fframes=layout.getFFrames();
94
                for (int i = fframes.length - 1; i >= 0; i--) {
95
                        IFFrame fframe = fframes[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(PluginServices.getText(this,"simplify"));
104
                layout.refresh();
105
        }
106

    
107
        /**
108
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
109
         */
110
        public void grouping() {
111
                //                Se debe controlar de alguna forma si hay varios seleccionados.
112
                IFFrame fframegroup = new FFrameGroup();
113
                IFFrame[] fframes=layout.getFFrames();
114
                if (fframes.length > 1) {
115
                        ArrayList selecList = new ArrayList();
116

    
117
                        for (int i = fframes.length - 1; i >= 0; i--) {
118
                                IFFrame fframe = fframes[i];
119

    
120
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
121
                                        selecList.add(fframe);
122
                                        layout.delFFrame(fframe);
123
                                }
124
                        }
125

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

    
130
                        ((FFrameGroup) fframegroup).setAt(layout.getAT());
131

    
132
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getAT());
133

    
134
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
135
                                        layout.getAT());
136

    
137
                        fframegroup.setBoundBox(rd1);
138
                        fframegroup.setSelected(true);
139
                        layout.addFFrame(fframegroup, true,true);
140
                        layout.refresh();
141
                }
142
        }
143

    
144
        /**
145
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
146
         * FFrames individuales.
147
         */
148
        public void ungrouping() {
149
                layout.getEFS().startComplexCommand();
150
                IFFrame[] fframes=layout.getFFrames();
151
                for (int i = fframes.length - 1; i >= 0; i--) {
152
                        IFFrame fframe = fframes[i];
153

    
154
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
155
                                if (fframe instanceof FFrameGroup) {
156
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
157
                                        ArrayList selecList = new ArrayList();
158

    
159
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
160
                                                        j--) {
161
                                                selecList.add(fframegroup.getFFrames()[j]);
162
                                        }
163

    
164
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
165
                                                IFFrame frame=(IFFrame) selecList.get(j);
166
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
167
                                                layout.addFFrame(frame, false,true);
168
                                        }
169
                                        layout.delFFrame(fframegroup);
170
                                }
171
                        }
172
                }
173
                layout.getEFS().endComplexCommand(PluginServices.getText(this,"ungroup"));
174
                layout.refresh();
175
        }
176

    
177
        /**
178
         * Abre el di?logo para alinear los FFrames.
179
         */
180
        public void aligning() {
181
                m_alignLayout = new FAlignDialog(layout);
182
                PluginServices.getMDIManager().addWindow(m_alignLayout);
183
        }
184
        /**
185
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
186
         */
187
        public void before() {
188
                layout.getEFS().startComplexCommand();
189
                IFFrame[] fframes=layout.getFFrames();
190
                for (int i = fframes.length - 1; i >= 0; i--) {
191
                        IFFrame fframe = fframes[i];
192
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
193
                                if (fframe instanceof FFrameGroup) {
194
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
195
                                }
196

    
197
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
198
                                fframeAux.setLevel(layout.getNumBefore());
199
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
200
                                fframeAux.getBoundingBox(layout.getAT());
201
                        }
202
                }
203
                layout.getEFS().endComplexCommand(PluginServices.getText(this,"change_before"));
204
                layout.updateFFrames();
205
                layout.refresh();
206
        }
207

    
208
        /**
209
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
210
         * seleccionados.
211
         */
212
        public void behind() {
213
                layout.getEFS().startComplexCommand();
214
                IFFrame[] fframes=layout.getFFrames();
215
                for (int i = fframes.length - 1; i >= 0; i--) {
216
                        IFFrame fframe = fframes[i];
217
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
218
                                if (fframe instanceof FFrameGroup) {
219
                                        ((FFrameGroup) fframe).setAt(layout.getAT());
220
                                }
221

    
222
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
223
                                fframeAux.setLevel(layout.getNumBehind());
224
                                layout.getEFS().modifyFFrame(fframe,fframeAux);
225
                                fframeAux.getBoundingBox(layout.getAT());
226
                        }
227
                }
228
                layout.getEFS().endComplexCommand(PluginServices.getText(this,"change_behind"));
229
                layout.updateFFrames();
230
                layout.refresh();
231
        }
232

    
233
        /**
234
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
235
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
236
         */
237
        public void openFFrameDialog() {
238
                IFFrame[] selecList = layout.getFFrameSelected();
239

    
240
                if (selecList.length == 1) {
241
                        IFFrame frame=selecList[0];
242
                        int toolaux = layout.getTool();
243
                        layout.setTool(getType(frame));
244
                        IFFrame fframeAux=frame.cloneFFrame(layout);
245
                        if (layout.openFFrameDialog(fframeAux)) {
246
                                if (fframeAux instanceof IFFrameUseFMap)
247
                                        ((IFFrameUseFMap)fframeAux).refresh();
248
                                layout.getEFS().modifyFFrame(frame,fframeAux);
249
                                fframeAux.getBoundingBox(layout.getAT());
250
                                layout.updateFFrames();
251
                                layout.setIsReSel(true);
252
                        }
253
                        layout.setTool(toolaux);
254
                }
255
        }
256

    
257
        /**
258
         * Devuelve un entero que representa el tipo de FFrame  que se le pasa como
259
         * par?metro.
260
         *
261
         * @param fframe FFrame que se pasa como par?metro, para saber de que tipo
262
         *                   es.
263
         *
264
         * @return entero.
265
         */
266
        private int getType(IFFrame fframe) {
267
                if (fframe instanceof FFrameView) {
268
                        return Layout.RECTANGLEVIEW;
269
                } else if (fframe instanceof FFrameText) {
270
                        return Layout.RECTANGLETEXT;
271
                } else if (fframe instanceof FFrameScaleBar) {
272
                        return Layout.RECTANGLESCALEBAR;
273
                } else if (fframe instanceof FFrameNorth) {
274
                        return Layout.RECTANGLENORTH;
275
                } else if (fframe instanceof FFrameTable) {
276
                        return Layout.RECTANGLEBOX;
277
                } else if (fframe instanceof FFramePicture) {
278
                        return Layout.RECTANGLEPICTURE;
279
                } else if (fframe instanceof FFrameLegend) {
280
                        return Layout.RECTANGLELEGEND;
281
                } else if (fframe instanceof FFrameGraphics) {
282
                        return Layout.GRAPHICS;
283
                } else if (fframe instanceof FFrameGroup) {
284
                        return Layout.RECTANGLEGROUP;
285
                }
286

    
287
                return Layout.SELECT;
288
        }
289

    
290
        /**
291
         * Selecci?n de todos los FFrames del Layout.
292
         */
293
        public void selecAll() {
294
                IFFrame[] fframes=layout.getFFrames();
295
                for (int i = fframes.length - 1; i >= 0; i--) {
296
                        IFFrame fframe =fframes[i];
297
                        fframe.setSelected(true);
298
                }
299
                layout.refresh();
300
        }
301

    
302
        /**
303
         * Abre el di?logo para a?adir un borde a los fframes.
304
         */
305
        public void border() {
306
                borderdialog = new FBorderDialog(layout);
307
                PluginServices.getMDIManager().addWindow(borderdialog);
308
        }
309

    
310
        /**
311
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
312
         */
313
        public void position() {
314

    
315
                IFFrame[] fframes=layout.getFFrameSelected();
316
                if (fframes.length!=0){
317
                        for (int i=0;i<fframes.length;i++){
318
                                positiondialog = new FPositionDialog(layout,fframes[i]);
319
                                PluginServices.getMDIManager().addWindow(positiondialog);
320
                        }
321
                }
322
        }
323
}