Statistics
| Revision:

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

History | View | Annotate | Download (9.37 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.project.documents.layout.fframes.FFrameGroup;
52
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroupFactory;
53
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameLegend;
54
import com.iver.cit.gvsig.project.documents.layout.fframes.FrameFactory;
55
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
56
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
57
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
58
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
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"simplify"));
88
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
89
                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
                                        ((FFrameLegend) fframe).toFFrames(layout.getLayoutContext());
95
                                }
96
                        }
97
                }
98
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
99
                layout.getLayoutControl().refresh();
100
        }
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
                FFrameGroup fframegroup =(FFrameGroup)FrameFactory.createFrameFromName(FFrameGroupFactory.registerName);
108

    
109
                fframegroup.setLayout(layout);
110
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
111
                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
                                        layout.getLayoutContext().delFFrame(fframe);
120
                                }
121
                        }
122

    
123
                        for (int i = selecList.size() - 1; i >= 0; i--) {
124
                                fframegroup.addFFrame((IFFrame) selecList.get(i));
125
                        }
126

    
127
                        fframegroup.setAt(layout.getLayoutControl().getAT());
128

    
129
                        Rectangle2D.Double rd = fframegroup.getRectangle(layout.getLayoutControl().getAT());
130

    
131
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
132
                                        layout.getLayoutControl().getAT());
133

    
134
                        fframegroup.setBoundBox(rd1);
135
                        fframegroup.setSelected(true);
136
                        layout.getLayoutContext().addFFrame(fframegroup, true,true);
137
                        layout.getLayoutControl().refresh();
138
                }
139
        }
140

    
141
        /**
142
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
143
         * FFrames individuales.
144
         */
145
        public void ungrouping() {
146
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"ungroup"));
147
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
148
                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
                                                layout.getLayoutContext().addFFrameSameProperties(frame);
165
                                        }
166
                                        layout.getLayoutContext().delFFrame(fframegroup);
167
                                }
168
                        }
169
                }
170
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
171
                layout.getLayoutControl().refresh();
172
        }
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
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"change_before"));
186
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
187
                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
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
192
                                }
193

    
194
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
195
                                fframeAux.setLevel(layout.getLayoutContext().getNumBefore());
196
                                layout.getLayoutContext().getFrameCommandsRecord().update(fframe,fframeAux);
197
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
198
                        }
199
                }
200
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
201
                layout.getLayoutContext().updateFFrames();
202
                layout.getLayoutControl().refresh();
203
        }
204

    
205
        /**
206
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
207
         * seleccionados.
208
         */
209
        public void behind() {
210
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"change_behind"));
211
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
212
                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
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
217
                                }
218

    
219
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
220
                                fframeAux.setLevel(layout.getLayoutContext().getNumBehind());
221
                                layout.getLayoutContext().getFrameCommandsRecord().update(fframe,fframeAux);
222
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
223
                        }
224
                }
225
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
226
                layout.getLayoutContext().updateFFrames();
227
                layout.getLayoutControl().refresh();
228
        }
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
        public boolean openFFrameDialog() {
235
                IFFrame[] selecList = layout.getLayoutContext().getFFrameSelected();
236

    
237
                if (selecList.length == 1) {
238
                        IFFrame frame=selecList[0];
239
//                        int toolaux = layout.getTool();
240
//                        layout.setTool(getType(frame));
241
//                        IFFrame fframeAux=frame.cloneFFrame(layout);
242
                        IFFrame fframeAux=layout.openFFrameDialog(frame);
243
                        if (fframeAux!=null) {
244
                                if (fframeAux instanceof IFFrameUseFMap)
245
                                        ((IFFrameUseFMap)fframeAux).refresh();
246
                                layout.getLayoutContext().getFrameCommandsRecord().update(frame,fframeAux);
247
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
248
                                layout.getLayoutContext().updateFFrames();
249
                                layout.getLayoutControl().setIsReSel(true);
250
                                layout.getLayoutControl().refresh();
251
                        }
252
//                        layout.setTool(toolaux);
253
                        if (fframeAux!=null)
254
                                return true;
255
                }
256
                return false;
257
        }
258

    
259
        /**
260
         * Selecci?n de todos los FFrames del Layout.
261
         */
262
        public void selecAll() {
263
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
264
                for (int i = fframes.length - 1; i >= 0; i--) {
265
                        IFFrame fframe =fframes[i];
266
                        fframe.setSelected(true);
267
                }
268
                layout.getLayoutControl().refresh();
269
        }
270

    
271
        /**
272
         * Abre el di?logo para a?adir un borde a los fframes.
273
         */
274
        public boolean border() {
275
                borderdialog = new FBorderDialog(layout);
276
                PluginServices.getMDIManager().addWindow(borderdialog);
277
                return borderdialog.isAccepted();
278
        }
279

    
280
        /**
281
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
282
         */
283
        public void position() {
284

    
285
                IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
286
                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
}