Statistics
| Revision:

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

History | View | Annotate | Download (10.3 KB)

1
/*
2
 * Created on 15-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.fframes;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.messages.NotificationManager;
49

    
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
52
import com.iver.cit.gvsig.gui.layout.Layout;
53
import com.iver.cit.gvsig.gui.project.OpenException;
54
import com.iver.cit.gvsig.gui.project.SaveException;
55
import com.iver.cit.gvsig.project.Project;
56

    
57
import com.iver.utiles.XMLEntity;
58

    
59
import java.awt.Graphics2D;
60
import java.awt.geom.AffineTransform;
61
import java.awt.geom.Point2D;
62
import java.awt.geom.Rectangle2D;
63
import java.awt.image.BufferedImage;
64

    
65
import java.util.ArrayList;
66

    
67

    
68
/**
69
 * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
70
 * incluso de si mismo.
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74
public class FFrameGroup extends FFrame implements IFFrameUseProject,
75
    IFFrameLayoutDependence {
76
    private ArrayList m_fframes = new ArrayList();
77
    private Rectangle2D.Double rg = null;
78
    private AffineTransform m_at;
79
    private Project project;
80

    
81
    /**
82
     * Crea un nuevo FFrameGroup.
83
     */
84
    public FFrameGroup() {
85
    }
86

    
87
    /**
88
     * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
89
     *
90
     * @param fframe FFrame a a?adir.
91
     */
92
    public void addFFrame(IFFrame fframe) {
93
        m_fframes.add(fframe);
94
    }
95

    
96
    /**
97
     * Devuelve una ArrayList que contiene todos los FFrames que forman parte
98
     * del grupo.
99
     *
100
     * @return Arraylist con los fframes.
101
     */
102
    public IFFrame[] getFFrames() {
103
        return (IFFrame[]) m_fframes.toArray(new IFFrame[0]);
104
    }
105

    
106
    /**
107
     * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
108
     *
109
     * @param at Matriz de transformaci?n
110
     *
111
     * @return Rect?ngulo.
112
     */
113
    public Rectangle2D.Double getRectangle(AffineTransform at) {
114
        boolean first = true;
115
        Rectangle2D.Double rec = new Rectangle2D.Double();
116

    
117
        for (int i = 0; i < m_fframes.size(); i++) {
118
            Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
119

    
120
            if (first) {
121
                rec.setRect(rs);
122
                first = false;
123
            }
124

    
125
            rec.add(rs);
126
        }
127

    
128
        rg = new Rectangle2D.Double();
129
        rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at));
130

    
131
        return rec;
132
    }
133

    
134
    /**
135
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
136
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
137
     * de dibujar.
138
     *
139
     * @param g Graphics
140
     * @param at Transformada afin.
141
     * @param rv rect?ngulo sobre el que hacer un clip.
142
     * @param imgBase Imagen utilizada para acelerar el dibujado.
143
     *
144
     * @throws DriverException
145
     */
146
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
147
        BufferedImage imgBase) throws DriverException {
148
        Rectangle2D.Double r = getBoundingBox(at);
149
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
150
            r.y + (r.height / 2));
151
        m_at = at;
152

    
153
        for (int i = 0; i < m_fframes.size(); i++) {
154
            ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase);
155
        }
156

    
157
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
158
            r.y + (r.height / 2));
159
    }
160

    
161
    /**
162
     * Rellena la transformada que se esta utilizando en el Layout.
163
     *
164
     * @param at Matriz de transformaci?n.
165
     */
166
    public void setAt(AffineTransform at) {
167
        m_at = at;
168
    }
169

    
170
    /**
171
     * Reimplementaci?n del m?todo papa poder modificar los BoundBox  de cada
172
     * uno de los FFrames que contiene dentro este FFrameGroup.
173
     *
174
     * @param r Rect?ngulo.
175
     */
176
    public void setBoundBox(Rectangle2D r) {
177
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
178

    
179
        double dx = 1;
180
        double dy = 1;
181
        double dw = 1;
182
        double dh = 1;
183

    
184
        if (rg != null) {
185
            Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y,
186
                    rg.width, rg.height);
187
            dx = r.getX() - raux1.x;
188
            dy = r.getY() - raux1.y;
189
            dw = r.getWidth() / raux1.width;
190
            dh = r.getHeight() / raux1.height;
191

    
192
            for (int i = 0; i < getFFrames().length; i++) {
193
                IFFrame fframe = (IFFrame) getFFrames()[i];
194
                Rectangle2D.Double raux = new Rectangle2D.Double();
195
                raux.setRect(fframe.getBoundBox());
196

    
197
                AffineTransform escalado = new AffineTransform();
198

    
199
                escalado.setToScale(dw, dh);
200
                escalado.translate(dx - r.getX(), dy - r.getY());
201

    
202
                Point2D.Double pd = new Point2D.Double();
203
                escalado.transform(new Point2D.Double(raux.x, raux.y), pd);
204

    
205
                raux.x = pd.x + r.getX();
206
                raux.y = pd.y + r.getY();
207
                raux.width = raux.width * dw;
208
                raux.height = raux.height * dh;
209

    
210
                fframe.setBoundBox(raux);
211
            }
212
        } else {
213
            rg = new Rectangle2D.Double();
214
            rg.setRect(r);
215
        }
216

    
217
        rg.setRect(r);
218
    }
219

    
220
    /**
221
     * DOCUMENT ME!
222
     *
223
     * @return DOCUMENT ME!
224
     *
225
     * @throws SaveException
226
     *
227
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
228
     */
229
    public XMLEntity getXMLEntity() throws SaveException {
230
        XMLEntity xml = super.getXMLEntity();
231
        xml.putProperty("type", Layout.RECTANGLEGROUP);
232

    
233
        for (int i = 0; i < getFFrames().length; i++) {
234
            xml.addChild(((IFFrame) getFFrames()[i]).getXMLEntity());
235
        }
236

    
237
        return xml;
238
    }
239

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

    
250
        IFFrame fframechild = null;
251

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

    
261
            fframechild.setName(xml.getStringProperty("m_name"));
262

    
263
            fframechild.setBoundBox(new Rectangle2D.Double(
264
                    xml.getChild(i).getDoubleProperty("x"),
265
                    xml.getChild(i).getDoubleProperty("y"),
266
                    xml.getChild(i).getDoubleProperty("w"),
267
                    xml.getChild(i).getDoubleProperty("h")));
268
            fframechild.setTag(xml.getChild(i).getStringProperty("tag"));
269
            fframechild.setXMLEntity03(xml.getChild(i), l);
270
            this.addFFrame(fframechild);
271
        }
272
    }
273

    
274
    /**
275
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
276
     */
277
    public void setXMLEntity(XMLEntity xml) {
278
        if (xml.getIntProperty("m_Selected") != 0) {
279
            this.setSelected(true);
280
        } else {
281
            this.setSelected(false);
282
        }
283

    
284
        setRotation(xml.getDoubleProperty("m_rotation"));
285

    
286
        for (int i = 0; i < xml.getNumChild(); i++) {
287
            try {
288
                IFFrame frame = FFrame.createFFrame(xml.getChild(i), project);
289
                this.addFFrame(frame);
290
            } catch (OpenException e) {
291
                e.showError();
292
            }
293
        }
294
    }
295

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

    
303
    /**
304
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
305
     *      java.awt.geom.AffineTransform)
306
     */
307
    public void print(Graphics2D g, AffineTransform at)
308
        throws DriverException {
309
        Rectangle2D.Double r = getBoundingBox(at);
310
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
311
            r.y + (r.height / 2));
312

    
313
        for (int i = 0; i < m_fframes.size(); i++) {
314
            ((IFFrame) m_fframes.get(i)).print(g, at);
315
        }
316

    
317
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
318
            r.y + (r.height / 2));
319
    }
320

    
321
    /**
322
     * Inserta una referencia al proyecto nesecario.
323
     *
324
     * @param project DOCUMENT ME!
325
     */
326
    public void setProject(Project project) {
327
        this.project = project;
328
    }
329

    
330
    /**
331
     * DOCUMENT ME!
332
     *
333
     * @param layout DOCUMENT ME!
334
     */
335
    public void setLayout(Layout layout) {
336
        IFFrame[] fs = getFFrames();
337

    
338
        for (int i = 0; i < fs.length; i++) {
339
            if (fs[i] instanceof IFFrameLayoutDependence) {
340
                ((IFFrameLayoutDependence) fs[i]).setLayout(layout);
341
            }
342

    
343
            if (fs[i] instanceof IFFrameViewDependence) {
344
                ((IFFrameViewDependence) fs[i]).initDependence(fs);
345
            }
346
        }
347
    }
348

    
349
        public void initialize() {
350
                // TODO Auto-generated method stub
351

    
352
        }
353
}