Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutGraphics.java @ 1763

History | View | Annotate | Download (9.85 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.gui.layout;
46

    
47
import com.iver.andami.PluginServices;
48

    
49
import com.iver.cit.gvsig.fmap.core.FGeometry;
50
import com.iver.cit.gvsig.fmap.core.Handler;
51
import com.iver.cit.gvsig.fmap.core.IGeometry;
52
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
53
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
54
import com.iver.cit.gvsig.fmap.layers.FBitSet;
55
import com.iver.cit.gvsig.gui.layout.dialogs.FAlignDialog;
56
import com.iver.cit.gvsig.gui.layout.dialogs.FBorderDialog;
57
import com.iver.cit.gvsig.gui.layout.dialogs.FPositionDialog;
58
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
59
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
60
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
61
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
62
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
63
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
64
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
65
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
66
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
67
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog;
68
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog;
69

    
70
import java.awt.Graphics2D;
71
import java.awt.geom.AffineTransform;
72
import java.awt.geom.Rectangle2D;
73
import java.io.IOException;
74

    
75
import java.util.ArrayList;
76

    
77

    
78
/**
79
 * Operaciones realizadas sobre el conjunto de FFrames.
80
 *
81
 * @author Vicente Caballero Navarro
82
 */
83
public class FLayoutGraphics {
84
        private Layout layout;
85
        private FAlignDialog m_alignLayout = null;
86
        private FBorderDialog borderdialog = null;
87
        private FPositionDialog positiondialog = null;
88

    
89
        /**
90
         * Crea un nuevo FLayoutGraphics.
91
         *
92
         * @param l Referencia al Layout.
93
         */
94
        public FLayoutGraphics(Layout l) {
95
                layout = l;
96
        }
97

    
98
        /**
99
         * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
100
         */
101
        public void simplify() {
102
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
103
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
104

    
105
                        if (fframe instanceof FFrameLegend) {
106
                                if (fframe.getSelected() != FFrame.NOSELECT) {
107
                                        ((FFrameLegend) fframe).toFFrames(layout);
108
                                }
109
                        }
110
                }
111

    
112
                layout.setStatus(Layout.DESACTUALIZADO);
113
                layout.repaint();
114
        }
115

    
116
        /**
117
         * Agrupar en un FFrameGroup todos los FFrames seleccionados.
118
         */
119
        public void grouping() {
120
                //Rectangle2D rex = new Rectangle2D.Double();
121
                //                Se debe controlar de alguna forma si hay varios seleccionados.
122
                IFFrame fframegroup = new FFrameGroup();
123

    
124
                if (layout.getFFrames().size() > 1) {
125
                        ArrayList selecList = new ArrayList();
126

    
127
                        for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
128
                                IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
129

    
130
                                if (fframe.getSelected() != FFrame.NOSELECT) {
131
                                        selecList.add(fframe);
132

    
133
                                        layout.getFFrames().remove(fframe);
134
                                }
135
                        }
136

    
137
                        for (int i = selecList.size() - 1; i >= 0; i--) {
138
                                ((FFrameGroup) fframegroup).addFFrame((IFFrame) selecList.get(i));
139
                        }
140

    
141
                        ((FFrameGroup) fframegroup).setAt(layout.getAT());
142

    
143
                        Rectangle2D.Double rd = ((FFrameGroup) fframegroup).getRectangle(layout.getAT());
144

    
145
                        //Rectangle re=new Rectangle((int)rd.getMinX(),(int)rd.getMinY(),(int)rd.getWidth(),(int)rd.getHeight());
146
                        Rectangle2D.Double rd1 = FLayoutUtilities.toSheetRect(rd,
147
                                        layout.getAT());
148

    
149
                        fframegroup.setBoundBox(rd1);
150
                        fframegroup.setSelected(true);
151
                        layout.addFFrame(fframegroup, true);
152
                        layout.setStatus(Layout.DESACTUALIZADO);
153
                        layout.repaint();
154
                }
155
        }
156

    
157
        /**
158
         * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
159
         * FFrames individuales.
160
         */
161
        public void ungrouping() {
162
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
163
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
164

    
165
                        if (fframe.getSelected() != FFrame.NOSELECT) {
166
                                if (fframe instanceof FFrameGroup) {
167
                                        FFrameGroup fframegroup = (FFrameGroup) fframe;
168
                                        ArrayList selecList = new ArrayList();
169

    
170
                                        for (int j = fframegroup.getFFrames().size() - 1; j >= 0;
171
                                                        j--) {
172
                                                selecList.add(fframegroup.getFFrames().get(j));
173

    
174
                                                fframegroup.getFFrames().remove(j);
175
                                        }
176

    
177
                                        for (int j = selecList.size() - 1; j >= 0; j--) {
178
                                                layout.addFFrame((IFFrame) selecList.get(j), false);
179
                                        }
180

    
181
                                        if (fframegroup.getFFrames().isEmpty()) {
182
                                                layout.getFFrames().remove(fframegroup);
183
                                        }
184
                                }
185
                        }
186
                }
187

    
188
                layout.setStatus(Layout.DESACTUALIZADO);
189
                layout.repaint();
190
        }
191

    
192
        /**
193
         * Abre el di?logo para alinear los FFrames.
194
         */
195
        public void aligning() {
196
                m_alignLayout = new FAlignDialog(layout);
197
                PluginServices.getMDIManager().addView(m_alignLayout);
198
        }
199

    
200
        /**
201
         * Posiciona los FFrames seleccionados delante de los no seleccionados.
202
         */
203
        public void before() {
204
                ArrayList auxList = new ArrayList();
205
                int num = 0;
206

    
207
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
208
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
209

    
210
                        if (fframe.getSelected() != FFrame.NOSELECT) {
211
                                auxList.add(fframe);
212
                                layout.getFFrames().remove(fframe);
213
                                num++;
214
                        }
215
                }
216

    
217
                for (int i = num - 1; i >= 0; i--) {
218
                        layout.getFFrames().add((IFFrame) auxList.get(i));
219
                }
220

    
221
                layout.setStatus(Layout.DESACTUALIZADO);
222
                layout.repaint();
223
        }
224

    
225
        /**
226
         * Posiciona los FFrames seleccionados detr?s de los FFrames no
227
         * seleccionados.
228
         */
229
        public void behind() {
230
                ArrayList auxList = new ArrayList();
231
                int num = 0;
232

    
233
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
234
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
235

    
236
                        if (fframe.getSelected() != FFrame.NOSELECT) {
237
                                auxList.add(fframe);
238
                                layout.getFFrames().remove(fframe);
239
                                num++;
240
                        }
241
                }
242

    
243
                for (int i = 0; i < num; i++) {
244
                        layout.getFFrames().add(0, (IFFrame) auxList.get(i));
245
                }
246

    
247
                layout.setStatus(Layout.DESACTUALIZADO);
248
                layout.repaint();
249
        }
250

    
251
        /**
252
         * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
253
         * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
254
         */
255
        public void openFFrameDialog() {
256
                FBitSet geomSel=layout.getCadToolAdapter().getSelection();
257
                ArrayList geometries=new ArrayList();
258
                for (int i = geomSel.nextSetBit(0);
259
                i >= 0;
260
                i = geomSel.nextSetBit(i + 1)){
261
                        try {
262
                                IGeometry geo=layout.getCadToolAdapter().getEditableFeatureSource().getGeometry(i);
263
                                geometries.add(geo);
264
                        } catch (IOException e) {
265
                                e.printStackTrace();
266
                        } catch (DriverIOException e) {
267
                                e.printStackTrace();
268
                        }
269
                        
270
                }
271
                if (!(geometries.size()==0)){
272
                        IFFrameDialog fframedialog = new FFrameGraphicsDialog(layout,
273
                                        (IGeometry[])geometries.toArray(new IGeometry[0]));
274
                        PluginServices.getMDIManager().addView(fframedialog);
275
                }else{
276
                ArrayList selecList = new ArrayList();
277

    
278
                for (int i = 0; i < layout.getFFrames().size(); i++) {
279
                        //Abrir el di?logo de cada uno de los fframe seleccionados o 
280
                        //uno que sea general como en arcView.
281
                        if (((IFFrame) layout.getFFrames().get(i)).getSelected() != FFrame.NOSELECT) {
282
                                selecList.add(layout.getFFrames().get(i));
283
                        }
284
                }
285

    
286
                if (selecList.size() == 1) {
287
                        int toolaux = layout.getTool();
288
                        layout.setTool(getType((IFFrame) selecList.get(0)));
289
                        layout.openFFrameDialog(((IFFrame) selecList.get(0)));
290
                        layout.setTool(toolaux);
291
                }
292
                }
293
        }
294

    
295
        /**
296
         * Devuelve un entero que representa el tipo de FFrame  que se le pasa como
297
         * par?metro.
298
         *
299
         * @param fframe FFrame que se pasa como par?metro, para saber de que tipo
300
         *                   es.
301
         *
302
         * @return entero.
303
         */
304
        private int getType(IFFrame fframe) {
305
                if (fframe instanceof FFrameView) {
306
                        return Layout.RECTANGLEVIEW;
307
                } else if (fframe instanceof FFrameText) {
308
                        return Layout.RECTANGLETEXT;
309
                } else if (fframe instanceof FFrameScaleBar) {
310
                        return Layout.RECTANGLESCALEBAR;
311
                } else if (fframe instanceof FFramePicture) {
312
                        return Layout.RECTANGLEPICTURE;
313
                } else if (fframe instanceof FFrameLegend) {
314
                        return Layout.RECTANGLELEGEND;
315
                } else if (fframe instanceof FFrameGraphics) {
316
                        return Layout.GRAPHICS;
317
                }
318

    
319
                return Layout.SELECT;
320
        }
321

    
322
        /**
323
         * Selecci?n de todos los FFrames del Layout.
324
         */
325
        public void selecAll() {
326
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
327
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
328
                        fframe.setSelected(true);
329
                }
330

    
331
                layout.setStatus(Layout.DESACTUALIZADO);
332
                layout.repaint();
333
        }
334

    
335
        /**
336
         * Abre el di?logo para a?adir un borde a los fframes.
337
         */
338
        public void border() {
339
                borderdialog = new FBorderDialog(layout);
340
                PluginServices.getMDIManager().addView(borderdialog);
341
        }
342

    
343
        /**
344
         * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
345
         */
346
        public void position() {
347
                
348
                IFFrame[] fframes=layout.getFFrameSelected();
349
                if (fframes.length!=0){
350
                        for (int i=0;i<fframes.length;i++){
351
                                positiondialog = new FPositionDialog(layout,fframes[i]);
352
                                PluginServices.getMDIManager().addView(positiondialog);
353
                        }
354
                }
355
        }
356
}