Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutGraphics.java @ 28368

History | View | Annotate | Download (9.27 KB)

1 7304 caballero
/*
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 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroup;
52 9516 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroupFactory;
53 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameLegend;
54 9516 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FrameFactory;
55 7304 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
56
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
57 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
58 7304 caballero
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FAlignDialog;
59
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FBorderDialog;
60
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FPositionDialog;
61
62
63
/**
64
 * Operaciones realizadas sobre el conjunto de FFrames.
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class FLayoutGraphics {
69
        private Layout layout;
70
        private FAlignDialog m_alignLayout = null;
71
        private FBorderDialog borderdialog = null;
72
        private FPositionDialog positiondialog = null;
73
74
        /**
75
         * Crea un nuevo FLayoutGraphics.
76
         *
77
         * @param l Referencia al Layout.
78
         */
79
        public FLayoutGraphics(Layout l) {
80
                layout = l;
81
        }
82
83
        /**
84
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
85
         */
86
        public void simplify() {
87 9392 caballero
                layout.getLayoutContext().getEFS().startComplexCommand();
88
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
89 7304 caballero
                for (int i = fframes.length - 1; i >= 0; i--) {
90
                        IFFrame fframe = fframes[i];
91
92
                        if (fframe instanceof FFrameLegend) {
93
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
94 9805 caballero
                                        ((FFrameLegend) fframe).toFFrames(layout.getLayoutContext());
95 7304 caballero
                                }
96
                        }
97
                }
98 9392 caballero
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"simplify"));
99
                layout.getLayoutControl().refresh();
100 7304 caballero
        }
101
102
        /**
103
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
104
         */
105
        public void grouping() {
106
                //                Se debe controlar de alguna forma si hay varios seleccionados.
107 9516 caballero
                FFrameGroup fframegroup =(FFrameGroup)FrameFactory.createFrameFromName(FFrameGroupFactory.registerName);
108
109 9392 caballero
                fframegroup.setLayout(layout);
110
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
111 7304 caballero
                if (fframes.length > 1) {
112
                        ArrayList selecList = new ArrayList();
113
114
                        for (int i = fframes.length - 1; i >= 0; i--) {
115
                                IFFrame fframe = fframes[i];
116
117
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
118
                                        selecList.add(fframe);
119 9392 caballero
                                        layout.getLayoutContext().delFFrame(fframe);
120 7304 caballero
                                }
121
                        }
122
123
                        for (int i = selecList.size() - 1; i >= 0; i--) {
124 9516 caballero
                                fframegroup.addFFrame((IFFrame) selecList.get(i));
125 7304 caballero
                        }
126
127 9516 caballero
                        fframegroup.setAt(layout.getLayoutControl().getAT());
128 7304 caballero
129 9516 caballero
                        Rectangle2D.Double rd = fframegroup.getRectangle(layout.getLayoutControl().getAT());
130 7304 caballero
131
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
132 9392 caballero
                                        layout.getLayoutControl().getAT());
133 7304 caballero
134
                        fframegroup.setBoundBox(rd1);
135
                        fframegroup.setSelected(true);
136 9392 caballero
                        layout.getLayoutContext().addFFrame(fframegroup, true,true);
137
                        layout.getLayoutControl().refresh();
138 7304 caballero
                }
139
        }
140
141
        /**
142
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
143
         * FFrames individuales.
144
         */
145
        public void ungrouping() {
146 9392 caballero
                layout.getLayoutContext().getEFS().startComplexCommand();
147
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
148 7304 caballero
                for (int i = fframes.length - 1; i >= 0; i--) {
149
                        IFFrame fframe = fframes[i];
150
151
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
152
                                if (fframe instanceof FFrameGroup) {
153
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
154
                                        ArrayList selecList = new ArrayList();
155
156
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
157
                                                        j--) {
158
                                                selecList.add(fframegroup.getFFrames()[j]);
159
                                        }
160
161
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
162
                                                IFFrame frame=(IFFrame) selecList.get(j);
163
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
164 12130 caballero
                                                layout.getLayoutContext().addFFrameSameProperties(frame);
165 7304 caballero
                                        }
166 9392 caballero
                                        layout.getLayoutContext().delFFrame(fframegroup);
167 7304 caballero
                                }
168
                        }
169
                }
170 9392 caballero
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"ungroup"));
171
                layout.getLayoutControl().refresh();
172 7304 caballero
        }
173
174
        /**
175
         * Abre el di?logo para alinear los FFrames.
176
         */
177
        public void aligning() {
178
                m_alignLayout = new FAlignDialog(layout);
179
                PluginServices.getMDIManager().addWindow(m_alignLayout);
180
        }
181
        /**
182
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
183
         */
184
        public void before() {
185 9392 caballero
                layout.getLayoutContext().getEFS().startComplexCommand();
186
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
187 7304 caballero
                for (int i = fframes.length - 1; i >= 0; i--) {
188
                        IFFrame fframe = fframes[i];
189
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
190
                                if (fframe instanceof FFrameGroup) {
191 9392 caballero
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
192 7304 caballero
                                }
193
194
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
195 9392 caballero
                                fframeAux.setLevel(layout.getLayoutContext().getNumBefore());
196
                                layout.getLayoutContext().getEFS().modifyFFrame(fframe,fframeAux);
197
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
198 7304 caballero
                        }
199
                }
200 9392 caballero
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"change_before"));
201
                layout.getLayoutContext().updateFFrames();
202
                layout.getLayoutControl().refresh();
203 7304 caballero
        }
204
205
        /**
206
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
207
         * seleccionados.
208
         */
209
        public void behind() {
210 9392 caballero
                layout.getLayoutContext().getEFS().startComplexCommand();
211
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
212 7304 caballero
                for (int i = fframes.length - 1; i >= 0; i--) {
213
                        IFFrame fframe = fframes[i];
214
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
215
                                if (fframe instanceof FFrameGroup) {
216 9392 caballero
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
217 7304 caballero
                                }
218
219
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
220 9392 caballero
                                fframeAux.setLevel(layout.getLayoutContext().getNumBehind());
221
                                layout.getLayoutContext().getEFS().modifyFFrame(fframe,fframeAux);
222
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
223 7304 caballero
                        }
224
                }
225 9392 caballero
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"change_behind"));
226
                layout.getLayoutContext().updateFFrames();
227
                layout.getLayoutControl().refresh();
228 7304 caballero
        }
229
230
        /**
231
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
232
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
233
         */
234 9532 caballero
        public boolean openFFrameDialog() {
235 9392 caballero
                IFFrame[] selecList = layout.getLayoutContext().getFFrameSelected();
236 7304 caballero
237
                if (selecList.length == 1) {
238
                        IFFrame frame=selecList[0];
239 9392 caballero
//                        int toolaux = layout.getTool();
240
//                        layout.setTool(getType(frame));
241 9245 caballero
//                        IFFrame fframeAux=frame.cloneFFrame(layout);
242
                        IFFrame fframeAux=layout.openFFrameDialog(frame);
243
                        if (fframeAux!=null) {
244 7304 caballero
                                if (fframeAux instanceof IFFrameUseFMap)
245
                                        ((IFFrameUseFMap)fframeAux).refresh();
246 9392 caballero
                                layout.getLayoutContext().getEFS().modifyFFrame(frame,fframeAux);
247
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
248
                                layout.getLayoutContext().updateFFrames();
249
                                layout.getLayoutControl().setIsReSel(true);
250
                                layout.getLayoutControl().refresh();
251 7304 caballero
                        }
252 9392 caballero
//                        layout.setTool(toolaux);
253 9532 caballero
                        if (fframeAux!=null)
254
                                return true;
255 7304 caballero
                }
256 9532 caballero
                return false;
257 7304 caballero
        }
258
259
        /**
260
         * Selecci?n de todos los FFrames del Layout.
261
         */
262
        public void selecAll() {
263 9392 caballero
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
264 7304 caballero
                for (int i = fframes.length - 1; i >= 0; i--) {
265
                        IFFrame fframe =fframes[i];
266
                        fframe.setSelected(true);
267
                }
268 9392 caballero
                layout.getLayoutControl().refresh();
269 7304 caballero
        }
270
271
        /**
272
         * Abre el di?logo para a?adir un borde a los fframes.
273
         */
274 9532 caballero
        public boolean border() {
275 7304 caballero
                borderdialog = new FBorderDialog(layout);
276
                PluginServices.getMDIManager().addWindow(borderdialog);
277 9532 caballero
                return borderdialog.isAccepted();
278 7304 caballero
        }
279
280
        /**
281
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
282
         */
283
        public void position() {
284
285 9392 caballero
                IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
286 7304 caballero
                if (fframes.length!=0){
287
                        for (int i=0;i<fframes.length;i++){
288
                                positiondialog = new FPositionDialog(layout,fframes[i]);
289
                                PluginServices.getMDIManager().addWindow(positiondialog);
290
                        }
291
                }
292
        }
293
}