Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 686

History | View | Annotate | Download (8.78 KB)

1
/*
2
 * Created on 15-jul-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.gui.layout.fframes;
8

    
9
import java.awt.Graphics2D;
10
import java.awt.geom.AffineTransform;
11
import java.awt.geom.Point2D;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.BufferedImage;
14
import java.util.ArrayList;
15

    
16
import com.iver.andami.PluginServices;
17
import com.iver.andami.messages.NotificationManager;
18
import com.iver.cit.gvsig.fmap.DriverException;
19
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
20
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
21
import com.iver.cit.gvsig.gui.layout.Layout;
22
import com.iver.utiles.XMLEntity;
23

    
24

    
25
/**
26
 * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
27
 * incluso de si mismo.
28
 *
29
 * @author Vicente Caballero Navarro
30
 */
31
public class FFrameGroup extends FFrame {
32
        private ArrayList m_fframes = new ArrayList();
33
        private Rectangle2D.Double rg = null;
34
        private AffineTransform m_at;
35
        private Rectangle2D.Double ra = null;
36

    
37
        /**
38
         * Crea un nuevo FFrameGroup.
39
         */
40
        public FFrameGroup() {
41
        }
42

    
43
        /**
44
         * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
45
         *
46
         * @param fframe FFrame a a?adir.
47
         */
48
        public void addFFrame(IFFrame fframe) {
49
                m_fframes.add(fframe);
50
        }
51

    
52
        /**
53
         * Devuelve una ArrayList que contiene todos los FFrames que forman parte
54
         * del grupo.
55
         *
56
         * @return Arraylist con los fframes.
57
         */
58
        public ArrayList getFFrames() {
59
                return m_fframes;
60
        }
61

    
62
        /**
63
         * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
64
         *
65
         * @param at Matriz de transformaci?n
66
         *
67
         * @return Rect?ngulo.
68
         */
69
        public Rectangle2D.Double getRectangle(AffineTransform at) {
70
                double minX = 0;
71
                double minY = 0;
72
                double maxX = 0;
73
                double maxY = 0;
74
                boolean first = true;
75
                Rectangle2D.Double rec = new Rectangle2D.Double();
76

    
77
                for (int i = 0; i < m_fframes.size(); i++) {
78
                        Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
79

    
80
                        if (first) {
81
                                rec.setRect(rs);
82
                                first = false;
83
                        }
84

    
85
                        rec.add(rs);
86
                }
87

    
88
                rg = new Rectangle2D.Double();
89
                rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at));
90

    
91
                return rec;
92
        }
93

    
94
        /**
95
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
96
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
97
         * de dibujar.
98
         *
99
         * @param g Graphics
100
         * @param at Transformada afin.
101
         * @param rv rect?ngulo sobre el que hacer un clip.
102
         * @param imgBase DOCUMENT ME!
103
         *
104
         * @throws DriverIOException
105
         */
106
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
107
                BufferedImage imgBase) throws DriverException {
108
                Rectangle2D.Double r = getBoundingBox(at);
109
                m_at = at;
110

    
111
                for (int i = 0; i < m_fframes.size(); i++) {
112
                        ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase);
113
                }
114
        }
115

    
116
        /**
117
         * Rellena la transformada que se esta utilizando en el Layout.
118
         *
119
         * @param at Matriz de transformaci?n.
120
         */
121
        public void setAt(AffineTransform at) {
122
                m_at = at;
123
        }
124

    
125
        /**
126
         * Reimplementaci?n del m?todo papa poder modificar los BoundBox  de cada
127
         * uno de los FFrames que contiene dentro este FFrameGroup.
128
         *
129
         * @param r Rect?ngulo.
130
         */
131
        public void setBoundBox(Rectangle2D.Double r) {
132
                getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
133

    
134
                Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width,
135
                                rg.height);
136
                double dx = r.x - raux1.x;
137
                double dy = r.y - raux1.y;
138
                double dw = r.width / raux1.width;
139
                double dh = r.height / raux1.height;
140

    
141
                for (int i = 0; i < getFFrames().size(); i++) {
142
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
143
                        Rectangle2D.Double raux = new Rectangle2D.Double();
144
                        raux.setRect(fframe.getBoundBox());
145

    
146
                        AffineTransform escalado = new AffineTransform();
147
                        double scalex = r.width / raux1.width;
148
                        double scaley = r.height / raux1.height;
149

    
150
                        escalado.setToScale(dw, dh);
151
                        escalado.translate(dx - r.x, dy - r.y);
152

    
153
                        Point2D.Double pd = new Point2D.Double();
154
                        escalado.transform(new Point2D.Double(raux.x, raux.y), pd);
155

    
156
                        raux.x = pd.x + r.x;
157
                        raux.y = pd.y + r.y;
158
                        raux.width = raux.width * dw;
159
                        raux.height = raux.height * dh;
160

    
161
                        fframe.setBoundBox(raux);
162
                }
163

    
164
                rg.setRect(r);
165
        }
166

    
167
        /**
168
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
169
         */
170
        public XMLEntity getXMLEntity() {
171
                XMLEntity xml = new XMLEntity();
172
                xml.putProperty("nameClass", this.getClass().getName());
173
                xml.putProperty("m_name", m_name);
174
                xml.putProperty("x", getBoundBox().x);
175
                xml.putProperty("y", getBoundBox().y);
176
                xml.putProperty("w", getBoundBox().width);
177
                xml.putProperty("h", getBoundBox().height);
178
                xml.putProperty("m_Selected", m_Selected);
179
                xml.putProperty("type", Layout.RECTANGLEGROUP);
180
                xml.putProperty("tag", getTag());
181

    
182
                for (int i = 0; i < getFFrames().size(); i++) {
183
                        xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
184
                }
185

    
186
                return xml;
187
        }
188

    
189
        /**
190
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
191
         *
192
         * @param xml XMLEntity
193
         * @param p DOCUMENT ME!
194
         */
195

    
196
        /*
197
           public static FFrameGroup createFFrameGroup(XMLEntity xml, Project p) {
198
               FFrameGroup fframe = new FFrameGroup();
199
        
200
               if (xml.getIntProperty("m_Selected") != 0) {
201
                   fframe.setSelected(true);
202
               } else {
203
                   fframe.setSelected(false);
204
               }
205
               IFFrame fframechild = null;
206
               for (int i = 0; i < xml.getNumChild(); i++) {
207
                   switch (xml.getChild(i).getIntProperty("type")) {
208
                       case (Layout.RECTANGLEVIEW):
209
                           fframechild = FFrameView.createFFrameView(xml, p);
210
                           break;
211
                       case (Layout.RECTANGLETEXT):
212
                           fframechild = FFrameText.createFFrameText(xml);
213
                           break;
214
                       case (Layout.RECTANGLESCALEBAR):
215
                           fframechild = FFrameScaleBar.createFFrameScaleBar(xml, p);
216
                           break;
217
                       case (Layout.RECTANGLEPICTURE):
218
                           fframechild = FFramePicture.createFFramePicture(xml);
219
                           break;
220
                       case (Layout.RECTANGLELEGEND):
221
                           fframechild = FFrameLegend.createFFrameLegend(xml, p);
222
                           break;
223
                       case (Layout.GRAPHICS):
224
                           fframechild = FFrameGraphics.createFFrameGraphics(xml);
225
                           break;
226
                       case (Layout.RECTANGLEGROUP):
227
                           fframechild = FFrameGroup.createFFrameGroup(xml, p);
228
                           break;
229
                       case (Layout.RECTANGLESYMBOL):
230
                           fframechild = FFrameSymbol.createFFrameSymbol(xml);
231
                           break;
232
                   }
233
                   fframe.addFFrame(fframechild);
234
               }
235
               return fframe;
236
           }
237
         */
238

    
239
        /**
240
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
241
         */
242
        public void setXMLEntity(XMLEntity xml, Layout l) {
243
                if (xml.getIntProperty("m_Selected") != 0) {
244
                        this.setSelected(true);
245
                } else {
246
                        this.setSelected(false);
247
                }
248

    
249
                IFFrame fframechild = null;
250

    
251
                for (int i = 0; i < xml.getNumChild(); i++) {
252
                        try {
253
                                Class clase = Class.forName(xml.getStringProperty("nameClass"));
254
                                fframechild = (IFFrame) clase.newInstance();
255
                        } catch (Exception e) {
256
                                NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
257
                                        e);
258
                        }
259

    
260
                        fframechild.setXMLEntity(xml.getChild(i), l);
261

    
262
                        /*switch (xml.getChild(i).getIntProperty("type")) {
263
                           case (Layout.RECTANGLEVIEW):
264
                               fframechild = FFrameView.createFFrameView(xml, p);
265
                               break;
266
                           case (Layout.RECTANGLETEXT):
267
                               fframechild = FFrameText.createFFrameText(xml);
268
                               break;
269
                           case (Layout.RECTANGLESCALEBAR):
270
                               fframechild = FFrameScaleBar.createFFrameScaleBar(xml, p);
271
                               break;
272
                           case (Layout.RECTANGLEPICTURE):
273
                               fframechild = FFramePicture.createFFramePicture(xml);
274
                               break;
275
                           case (Layout.RECTANGLELEGEND):
276
                               fframechild = FFrameLegend.createFFrameLegend(xml, p);
277
                               break;
278
                           case (Layout.GRAPHICS):
279
                               fframechild = FFrameGraphics.createFFrameGraphics(xml);
280
                               break;
281
                           case (Layout.RECTANGLEGROUP):
282
                               fframechild = FFrameGroup.createFFrameGroup(xml, p);
283
                               break;
284
                           case (Layout.RECTANGLESYMBOL):
285
                               fframechild = FFrameSymbol.createFFrameSymbol(xml);
286
                               break;
287
                           }
288
                         */
289
                        this.addFFrame(fframechild);
290
                }
291
        }
292

    
293
        /**
294
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
295
         */
296
        public String getNameFFrame() {
297
                return PluginServices.getText(this, "grupo");
298
        }
299

    
300
        /**
301
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
302
         *                 java.awt.geom.AffineTransform)
303
         */
304
        public void print(Graphics2D g, AffineTransform at)
305
                throws DriverException {
306
                for (int i = 0; i < m_fframes.size(); i++) {
307
                        ((IFFrame) m_fframes.get(i)).print(g, at);
308
                }
309
        }
310
}