Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutGraphics.java @ 9392

History | View | Annotate | Download (8.99 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.FFrameLegend;
53
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
54
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
55
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
56
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FAlignDialog;
57
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FBorderDialog;
58
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FPositionDialog;
59

    
60

    
61
/**
62
 * Operaciones realizadas sobre el conjunto de FFrames.
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class FLayoutGraphics {
67
        private Layout layout;
68
        private FAlignDialog m_alignLayout = null;
69
        private FBorderDialog borderdialog = null;
70
        private FPositionDialog positiondialog = null;
71

    
72
        /**
73
         * Crea un nuevo FLayoutGraphics.
74
         *
75
         * @param l Referencia al Layout.
76
         */
77
        public FLayoutGraphics(Layout l) {
78
                layout = l;
79
        }
80

    
81
        /**
82
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
83
         */
84
        public void simplify() {
85
                layout.getLayoutContext().getEFS().startComplexCommand();
86
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
87
                for (int i = fframes.length - 1; i >= 0; i--) {
88
                        IFFrame fframe = fframes[i];
89

    
90
                        if (fframe instanceof FFrameLegend) {
91
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
92
                                        ((FFrameLegend) fframe).toFFrames(layout);
93
                                }
94
                        }
95
                }
96
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"simplify"));
97
                layout.getLayoutControl().refresh();
98
        }
99

    
100
        /**
101
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
102
         */
103
        public void grouping() {
104
                //                Se debe controlar de alguna forma si hay varios seleccionados.
105
                IFFrame fframegroup = new FFrameGroup();
106
                fframegroup.setLayout(layout);
107
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
108
                if (fframes.length > 1) {
109
                        ArrayList selecList = new ArrayList();
110

    
111
                        for (int i = fframes.length - 1; i >= 0; i--) {
112
                                IFFrame fframe = fframes[i];
113

    
114
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
115
                                        selecList.add(fframe);
116
                                        layout.getLayoutContext().delFFrame(fframe);
117
                                }
118
                        }
119

    
120
                        for (int i = selecList.size() - 1; i >= 0; i--) {
121
                                ((FFrameGroup) fframegroup).addFFrame((IFFrame) selecList.get(i));
122
                        }
123

    
124
                        ((FFrameGroup) fframegroup).setAt(layout.getLayoutControl().getAT());
125

    
126
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getLayoutControl().getAT());
127

    
128
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
129
                                        layout.getLayoutControl().getAT());
130

    
131
                        fframegroup.setBoundBox(rd1);
132
                        fframegroup.setSelected(true);
133
                        layout.getLayoutContext().addFFrame(fframegroup, true,true);
134
                        layout.getLayoutControl().refresh();
135
                }
136
        }
137

    
138
        /**
139
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
140
         * FFrames individuales.
141
         */
142
        public void ungrouping() {
143
                layout.getLayoutContext().getEFS().startComplexCommand();
144
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
145
                for (int i = fframes.length - 1; i >= 0; i--) {
146
                        IFFrame fframe = fframes[i];
147

    
148
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
149
                                if (fframe instanceof FFrameGroup) {
150
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
151
                                        ArrayList selecList = new ArrayList();
152

    
153
                                        for (int j = fframegroup.getFFrames().length - 1; j >= 0;
154
                                                        j--) {
155
                                                selecList.add(fframegroup.getFFrames()[j]);
156
                                        }
157

    
158
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
159
                                                IFFrame frame=(IFFrame) selecList.get(j);
160
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
161
                                                layout.getLayoutContext().addFFrame(frame, false,true);
162
                                        }
163
                                        layout.getLayoutContext().delFFrame(fframegroup);
164
                                }
165
                        }
166
                }
167
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"ungroup"));
168
                layout.getLayoutControl().refresh();
169
        }
170

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

    
191
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
192
                                fframeAux.setLevel(layout.getLayoutContext().getNumBefore());
193
                                layout.getLayoutContext().getEFS().modifyFFrame(fframe,fframeAux);
194
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
195
                        }
196
                }
197
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"change_before"));
198
                layout.getLayoutContext().updateFFrames();
199
                layout.getLayoutControl().refresh();
200
        }
201

    
202
        /**
203
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
204
         * seleccionados.
205
         */
206
        public void behind() {
207
                layout.getLayoutContext().getEFS().startComplexCommand();
208
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
209
                for (int i = fframes.length - 1; i >= 0; i--) {
210
                        IFFrame fframe = fframes[i];
211
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
212
                                if (fframe instanceof FFrameGroup) {
213
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
214
                                }
215

    
216
                                IFFrame fframeAux=fframe.cloneFFrame(layout);
217
                                fframeAux.setLevel(layout.getLayoutContext().getNumBehind());
218
                                layout.getLayoutContext().getEFS().modifyFFrame(fframe,fframeAux);
219
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
220
                        }
221
                }
222
                layout.getLayoutContext().getEFS().endComplexCommand(PluginServices.getText(this,"change_behind"));
223
                layout.getLayoutContext().updateFFrames();
224
                layout.getLayoutControl().refresh();
225
        }
226

    
227
        /**
228
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
229
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
230
         */
231
        public void openFFrameDialog() {
232
                IFFrame[] selecList = layout.getLayoutContext().getFFrameSelected();
233

    
234
                if (selecList.length == 1) {
235
                        IFFrame frame=selecList[0];
236
//                        int toolaux = layout.getTool();
237
//                        layout.setTool(getType(frame));
238
//                        IFFrame fframeAux=frame.cloneFFrame(layout);
239
                        IFFrame fframeAux=layout.openFFrameDialog(frame);
240
                        if (fframeAux!=null) {
241
                                if (fframeAux instanceof IFFrameUseFMap)
242
                                        ((IFFrameUseFMap)fframeAux).refresh();
243
                                layout.getLayoutContext().getEFS().modifyFFrame(frame,fframeAux);
244
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
245
                                layout.getLayoutContext().updateFFrames();
246
                                layout.getLayoutControl().setIsReSel(true);
247
                                layout.getLayoutControl().refresh();
248
                        }
249
//                        layout.setTool(toolaux);
250

    
251
                }
252
        }
253

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

    
266
        /**
267
         * Abre el di?logo para a?adir un borde a los fframes.
268
         */
269
        public void border() {
270
                borderdialog = new FBorderDialog(layout);
271
                PluginServices.getMDIManager().addWindow(borderdialog);
272
        }
273

    
274
        /**
275
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
276
         */
277
        public void position() {
278

    
279
                IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
280
                if (fframes.length!=0){
281
                        for (int i=0;i<fframes.length;i++){
282
                                positiondialog = new FPositionDialog(layout,fframes[i]);
283
                                PluginServices.getMDIManager().addWindow(positiondialog);
284
                        }
285
                }
286
        }
287
}