Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / FLayoutGraphics.java @ 36443

History | View | Annotate | Download (10.3 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 org.gvsig.app.project.documents.layout;
46

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

    
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.app.project.ProjectManager;
55
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup;
56
import org.gvsig.app.project.documents.layout.fframes.FFrameLegend;
57
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
58
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
59
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
60
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
61
import org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog;
62
import org.gvsig.app.project.documents.layout.gui.dialogs.FBorderDialog;
63
import org.gvsig.app.project.documents.layout.gui.dialogs.FPositionDialog;
64

    
65

    
66

    
67
/**
68
 * Operaciones realizadas sobre el conjunto de FFrames.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class FLayoutGraphics {
73
    protected static final Logger LOG = LoggerFactory.getLogger(FLayoutGraphics.class);
74
    private LayoutPanel layout;
75
        private FAlignDialog m_alignLayout = null;
76
        private FBorderDialog borderdialog = null;
77
        private FPositionDialog positiondialog = null;
78
        private LayoutManager layoutManager = null;
79

    
80
        /**
81
         * Crea un nuevo FLayoutGraphics.
82
         *
83
         * @param l Referencia al Layout.
84
         */
85
        public FLayoutGraphics(LayoutPanel layoutPanel) {
86
                layout = layoutPanel;
87
                layoutManager = (LayoutManager)ProjectManager.getInstance().getDocumentManager(DefaultLayoutManager.TYPENAME);
88
        }
89

    
90
        /**
91
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
92
         */
93
        public void simplify() {
94
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"simplify"));
95
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
96
                for (int i = fframes.length - 1; i >= 0; i--) {
97
                        IFFrame fframe = fframes[i];
98

    
99
                        if (fframe instanceof FFrameLegend) {
100
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
101
                                        ((FFrameLegend) fframe).toFFrames(layout.getLayoutContext());
102
                                }
103
                        }
104
                }
105
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
106
                layout.getLayoutControl().refresh();
107
        }
108

    
109
        /**
110
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
111
         */
112
        public void grouping() {
113
                //                Se debe controlar de alguna forma si hay varios seleccionados.
114
                FFrameGroup fframegroup =(FFrameGroup)layoutManager.createFrame(FFrameGroup.PERSISTENCE_DEFINITION_NAME);
115

    
116
//                fframegroup.setLayout(layout);
117
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
118
                if (fframes.length > 1) {
119
                        ArrayList selecList = new ArrayList();
120

    
121
                        for (int i = fframes.length - 1; i >= 0; i--) {
122
                                IFFrame fframe = fframes[i];
123

    
124
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
125
                                        selecList.add(fframe);
126
                                        layout.getLayoutContext().delFFrame(fframe);
127
                                }
128
                        }
129

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

    
134
                        fframegroup.setAt(layout.getLayoutControl().getAT());
135

    
136
                        Rectangle2D.Double rd = fframegroup.getRectangle(layout.getLayoutControl().getAT());
137

    
138
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
139
                                        layout.getLayoutControl().getAT());
140

    
141
                        fframegroup.setBoundBox(rd1);
142
                        fframegroup.setSelected(true);
143
                        layout.getLayoutContext().addFFrame(fframegroup, true,true);
144
                        layout.getLayoutControl().refresh();
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.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"ungroup"));
154
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
155
                for (int i = fframes.length - 1; i >= 0; i--) {
156
                        IFFrame fframe = fframes[i];
157

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

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

    
168
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
169
                                                IFFrame frame=(IFFrame) selecList.get(j);
170
                                                frame.setRotation(frame.getRotation()+fframe.getRotation());
171
                                                layout.getLayoutContext().addFFrameSameProperties(frame);
172
                                        }
173
                                        layout.getLayoutContext().delFFrame(fframegroup);
174
                                }
175
                        }
176
                }
177
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
178
                layout.getLayoutControl().refresh();
179
        }
180

    
181
        /**
182
         * Abre el di?logo para alinear los FFrames.
183
         */
184
        public void aligning() {
185
                m_alignLayout = new FAlignDialog(layout);
186
                PluginServices.getMDIManager().addWindow(m_alignLayout);
187
        }
188
        /**
189
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
190
         */
191
        public void before() {
192
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"change_before"));
193
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
194
                for (int i = fframes.length - 1; i >= 0; i--) {
195
                        IFFrame fframe = fframes[i];
196
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
197
                                if (fframe instanceof FFrameGroup) {
198
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
199
                                }
200

    
201
                                IFFrame fframeAux;
202
                try {
203
                    fframeAux = (IFFrame)fframe.clone();
204
                    fframeAux.setLevel(layout.getLayoutContext().getNumBefore());
205
                    layout.getLayoutContext().getFrameCommandsRecord().update(fframe,fframeAux);
206
                    fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
207
                } catch (CloneNotSupportedException e) {
208
                    LOG.error("It is not possible clonate the object", e);
209
                }                                
210
                        }
211
                }
212
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
213
                layout.getLayoutContext().updateFFrames();
214
                layout.getLayoutControl().refresh();
215
        }
216

    
217
        /**
218
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
219
         * seleccionados.
220
         */
221
        public void behind() {
222
                layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this,"change_behind"));
223
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
224
                for (int i = fframes.length - 1; i >= 0; i--) {
225
                        IFFrame fframe = fframes[i];
226
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
227
                                if (fframe instanceof FFrameGroup) {
228
                                        ((FFrameGroup) fframe).setAt(layout.getLayoutControl().getAT());
229
                                }
230

    
231
                                IFFrame fframeAux;
232
                try {                    
233
                    fframeAux = (IFFrame)fframe.clone();
234
                    fframeAux.setLevel(layout.getLayoutContext().getNumBehind());
235
                    layout.getLayoutContext().getFrameCommandsRecord().update(fframe,fframeAux);
236
                    fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
237
                } catch (CloneNotSupportedException e) {
238
                    LOG.error("It is not possible clonate the object", e);
239
                }                                
240
                        }
241
                }
242
                layout.getLayoutContext().getFrameCommandsRecord().endComplex();
243
                layout.getLayoutContext().updateFFrames();
244
                layout.getLayoutControl().refresh();
245
        }
246

    
247
        /**
248
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
249
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
250
         */
251
        public boolean openFFrameDialog() {
252
                IFFrame[] selecList = layout.getLayoutContext().getFFrameSelected();
253

    
254
                if (selecList.length == 1) {
255
                        IFFrame frame=selecList[0];
256
//                        int toolaux = layout.getTool();
257
//                        layout.setTool(getType(frame));
258
//                        IFFrame fframeAux=frame.cloneFFrame(layout);
259
                        IFFrameDialog fframeDialog = layout.createFFrameDialog(frame);
260
                         IFFrame fframeAux = null;
261
                        if (fframeDialog != null) {
262
                            PluginServices.getMDIManager().addWindow(fframeDialog);
263
                            fframeAux = fframeDialog.getFFrame();
264
                                if (fframeAux instanceof IFFrameUseFMap)
265
                                        ((IFFrameUseFMap)fframeAux).refresh();                                
266
                                layout.getLayoutContext().getFrameCommandsRecord().update(frame,fframeAux);
267
                                fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
268
                                layout.getLayoutContext().updateFFrames();
269
                                layout.getLayoutControl().setIsReSel(true);
270
                                layout.getLayoutControl().refresh();
271
                        }
272
//                        layout.setTool(toolaux);
273
                        if (fframeAux!=null)
274
                                return true;
275
                }
276
                return false;
277
        }
278

    
279
        /**
280
         * Selecci?n de todos los FFrames del Layout.
281
         */
282
        public void selecAll() {
283
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
284
                for (int i = fframes.length - 1; i >= 0; i--) {
285
                        IFFrame fframe =fframes[i];
286
                        fframe.setSelected(true);
287
                }
288
                layout.getLayoutControl().refresh();
289
        }
290

    
291
        /**
292
         * Abre el di?logo para a?adir un borde a los fframes.
293
         */
294
        public boolean border() {
295
                borderdialog = new FBorderDialog(layout);
296
                PluginServices.getMDIManager().addWindow(borderdialog);
297
                return borderdialog.isAccepted();
298
        }
299

    
300
        /**
301
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
302
         */
303
        public void position() {
304

    
305
                IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
306
                if (fframes.length!=0){
307
                        for (int i=0;i<fframes.length;i++){
308
                                positiondialog = new FPositionDialog(layout,fframes[i]);
309
                                PluginServices.getMDIManager().addWindow(positiondialog);
310
                        }
311
                }
312
        }
313
}