Statistics
| Revision:

root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 2106

History | View | Annotate | Download (7.12 KB)

1 312 fernando
/*
2
 * Created on 15-jul-2004
3
 *
4
 */
5 1103 fjp
/* 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 312 fernando
package com.iver.cit.gvsig.gui.layout.fframes;
46
47 686 vcaballero
import java.awt.Graphics2D;
48
import java.awt.geom.AffineTransform;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52
import java.util.ArrayList;
53
54 596 fernando
import com.iver.andami.PluginServices;
55
import com.iver.andami.messages.NotificationManager;
56 654 fernando
import com.iver.cit.gvsig.fmap.DriverException;
57 1830 fernando
import com.iver.cit.gvsig.fmap.layers.XMLException;
58 596 fernando
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
59
import com.iver.cit.gvsig.gui.layout.Layout;
60
import com.iver.utiles.XMLEntity;
61 312 fernando
62 596 fernando
63 312 fernando
/**
64 398 vcaballero
 * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
65 312 fernando
 * incluso de si mismo.
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class FFrameGroup extends FFrame {
70 649 vcaballero
        private ArrayList m_fframes = new ArrayList();
71
        private Rectangle2D.Double rg = null;
72
        private AffineTransform m_at;
73
        private Rectangle2D.Double ra = null;
74 312 fernando
75 649 vcaballero
        /**
76
         * Crea un nuevo FFrameGroup.
77
         */
78
        public FFrameGroup() {
79
        }
80 312 fernando
81 649 vcaballero
        /**
82
         * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
83
         *
84
         * @param fframe FFrame a a?adir.
85
         */
86
        public void addFFrame(IFFrame fframe) {
87
                m_fframes.add(fframe);
88
        }
89 312 fernando
90 649 vcaballero
        /**
91
         * Devuelve una ArrayList que contiene todos los FFrames que forman parte
92
         * del grupo.
93
         *
94
         * @return Arraylist con los fframes.
95
         */
96
        public ArrayList getFFrames() {
97
                return m_fframes;
98
        }
99 312 fernando
100 649 vcaballero
        /**
101
         * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
102
         *
103
         * @param at Matriz de transformaci?n
104
         *
105
         * @return Rect?ngulo.
106
         */
107
        public Rectangle2D.Double getRectangle(AffineTransform at) {
108
                double minX = 0;
109
                double minY = 0;
110
                double maxX = 0;
111
                double maxY = 0;
112
                boolean first = true;
113
                Rectangle2D.Double rec = new Rectangle2D.Double();
114 312 fernando
115 649 vcaballero
                for (int i = 0; i < m_fframes.size(); i++) {
116
                        Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
117 312 fernando
118 649 vcaballero
                        if (first) {
119
                                rec.setRect(rs);
120
                                first = false;
121
                        }
122 312 fernando
123 649 vcaballero
                        rec.add(rs);
124
                }
125 312 fernando
126 649 vcaballero
                rg = new Rectangle2D.Double();
127
                rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at));
128 312 fernando
129 649 vcaballero
                return rec;
130
        }
131 312 fernando
132 649 vcaballero
        /**
133
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
134
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
135
         * de dibujar.
136
         *
137
         * @param g Graphics
138
         * @param at Transformada afin.
139
         * @param rv rect?ngulo sobre el que hacer un clip.
140 1073 vcaballero
         * @param imgBase Imagen utilizada para acelerar el dibujado.
141 649 vcaballero
         *
142
         * @throws DriverIOException
143
         */
144
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
145 654 fernando
                BufferedImage imgBase) throws DriverException {
146 649 vcaballero
                Rectangle2D.Double r = getBoundingBox(at);
147
                m_at = at;
148 312 fernando
149 649 vcaballero
                for (int i = 0; i < m_fframes.size(); i++) {
150
                        ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase);
151
                }
152
        }
153 398 vcaballero
154 649 vcaballero
        /**
155
         * Rellena la transformada que se esta utilizando en el Layout.
156
         *
157
         * @param at Matriz de transformaci?n.
158
         */
159
        public void setAt(AffineTransform at) {
160
                m_at = at;
161
        }
162 312 fernando
163 649 vcaballero
        /**
164
         * Reimplementaci?n del m?todo papa poder modificar los BoundBox  de cada
165
         * uno de los FFrames que contiene dentro este FFrameGroup.
166
         *
167
         * @param r Rect?ngulo.
168
         */
169
        public void setBoundBox(Rectangle2D.Double r) {
170
                getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
171 398 vcaballero
172 649 vcaballero
                Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width,
173
                                rg.height);
174
                double dx = r.x - raux1.x;
175
                double dy = r.y - raux1.y;
176
                double dw = r.width / raux1.width;
177
                double dh = r.height / raux1.height;
178 312 fernando
179 649 vcaballero
                for (int i = 0; i < getFFrames().size(); i++) {
180
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
181
                        Rectangle2D.Double raux = new Rectangle2D.Double();
182
                        raux.setRect(fframe.getBoundBox());
183 312 fernando
184 649 vcaballero
                        AffineTransform escalado = new AffineTransform();
185
                        double scalex = r.width / raux1.width;
186
                        double scaley = r.height / raux1.height;
187 312 fernando
188 649 vcaballero
                        escalado.setToScale(dw, dh);
189
                        escalado.translate(dx - r.x, dy - r.y);
190 312 fernando
191 649 vcaballero
                        Point2D.Double pd = new Point2D.Double();
192
                        escalado.transform(new Point2D.Double(raux.x, raux.y), pd);
193 312 fernando
194 649 vcaballero
                        raux.x = pd.x + r.x;
195
                        raux.y = pd.y + r.y;
196
                        raux.width = raux.width * dw;
197
                        raux.height = raux.height * dh;
198 312 fernando
199 649 vcaballero
                        fframe.setBoundBox(raux);
200
                }
201 398 vcaballero
202 649 vcaballero
                rg.setRect(r);
203
        }
204 312 fernando
205 649 vcaballero
        /**
206 1830 fernando
         * @throws XMLException
207 649 vcaballero
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
208
         */
209 1830 fernando
        public XMLEntity getXMLEntity() throws XMLException {
210 649 vcaballero
                XMLEntity xml = new XMLEntity();
211 1094 vcaballero
                xml.putProperty("className",this.getClass().getName());
212 649 vcaballero
                xml.putProperty("m_name", m_name);
213
                xml.putProperty("x", getBoundBox().x);
214
                xml.putProperty("y", getBoundBox().y);
215
                xml.putProperty("w", getBoundBox().width);
216
                xml.putProperty("h", getBoundBox().height);
217
                xml.putProperty("m_Selected", m_Selected);
218
                xml.putProperty("type", Layout.RECTANGLEGROUP);
219
                xml.putProperty("tag", getTag());
220 312 fernando
221 649 vcaballero
                for (int i = 0; i < getFFrames().size(); i++) {
222
                        xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
223
                }
224 312 fernando
225 649 vcaballero
                return xml;
226
        }
227
228
        /**
229
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
230
         */
231 686 vcaballero
        public void setXMLEntity(XMLEntity xml, Layout l) {
232 649 vcaballero
                if (xml.getIntProperty("m_Selected") != 0) {
233
                        this.setSelected(true);
234
                } else {
235
                        this.setSelected(false);
236
                }
237 312 fernando
238 649 vcaballero
                IFFrame fframechild = null;
239 312 fernando
240 649 vcaballero
                for (int i = 0; i < xml.getNumChild(); i++) {
241
                        try {
242 1272 vcaballero
                                Class clase = Class.forName(xml.getStringProperty("className"));
243 649 vcaballero
                                fframechild = (IFFrame) clase.newInstance();
244
                        } catch (Exception e) {
245
                                NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
246
                                        e);
247
                        }
248 312 fernando
249 686 vcaballero
                        fframechild.setXMLEntity(xml.getChild(i), l);
250 649 vcaballero
                        this.addFFrame(fframechild);
251
                }
252
        }
253
254
        /**
255
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
256
         */
257
        public String getNameFFrame() {
258
                return PluginServices.getText(this, "grupo");
259
        }
260
261
        /**
262
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
263
         *                 java.awt.geom.AffineTransform)
264
         */
265
        public void print(Graphics2D g, AffineTransform at)
266 654 fernando
                throws DriverException {
267 649 vcaballero
                for (int i = 0; i < m_fframes.size(); i++) {
268
                        ((IFFrame) m_fframes.get(i)).print(g, at);
269
                }
270
        }
271 312 fernando
}