root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 2970
History | View | Annotate | Download (9.19 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 | 2429 | caballero | //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 | 2429 | caballero | //double minX = 0;
|
109 | //double minY = 0;
|
||
110 | //double maxX = 0;
|
||
111 | //double maxY = 0;
|
||
112 | 649 | vcaballero | 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 | 2304 | vcaballero | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
148 | r.y + (r.height / 2));
|
||
149 | 649 | vcaballero | m_at = at; |
150 | 312 | fernando | |
151 | 649 | vcaballero | for (int i = 0; i < m_fframes.size(); i++) { |
152 | ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase); |
||
153 | } |
||
154 | 2304 | vcaballero | g.rotate(Math.toRadians(-getRotation()),
|
155 | r.x + (r.width / 2), r.y + (r.height / 2)); |
||
156 | 649 | vcaballero | } |
157 | 398 | vcaballero | |
158 | 649 | vcaballero | /**
|
159 | * Rellena la transformada que se esta utilizando en el Layout.
|
||
160 | *
|
||
161 | * @param at Matriz de transformaci?n.
|
||
162 | */
|
||
163 | public void setAt(AffineTransform at) { |
||
164 | m_at = at; |
||
165 | } |
||
166 | 312 | fernando | |
167 | 649 | vcaballero | /**
|
168 | * Reimplementaci?n del m?todo papa poder modificar los BoundBox de cada
|
||
169 | * uno de los FFrames que contiene dentro este FFrameGroup.
|
||
170 | *
|
||
171 | * @param r Rect?ngulo.
|
||
172 | */
|
||
173 | 2527 | caballero | public void setBoundBox(Rectangle2D r) { |
174 | 649 | vcaballero | getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
175 | 398 | vcaballero | |
176 | 2343 | vcaballero | double dx=1; |
177 | double dy=1; |
||
178 | double dw=1; |
||
179 | double dh=1; |
||
180 | 2429 | caballero | //double scalex=1;
|
181 | //double scaley=1;
|
||
182 | 2343 | vcaballero | if (rg!=null){ |
183 | |||
184 | 649 | vcaballero | Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width, |
185 | rg.height); |
||
186 | 2527 | caballero | dx = r.getX() - raux1.x; |
187 | dy = r.getY() - raux1.y; |
||
188 | dw = r.getWidth() / raux1.width; |
||
189 | dh = r.getHeight() / raux1.height; |
||
190 | 2343 | vcaballero | |
191 | 2429 | caballero | //scalex = r.width / raux1.width;
|
192 | //scaley = r.height / raux1.height;
|
||
193 | 2343 | vcaballero | |
194 | 649 | vcaballero | for (int i = 0; i < getFFrames().size(); i++) { |
195 | IFFrame fframe = (IFFrame) getFFrames().get(i); |
||
196 | Rectangle2D.Double raux = new Rectangle2D.Double(); |
||
197 | raux.setRect(fframe.getBoundBox()); |
||
198 | 312 | fernando | |
199 | 649 | vcaballero | AffineTransform escalado = new AffineTransform(); |
200 | 2343 | vcaballero | |
201 | 312 | fernando | |
202 | 649 | vcaballero | escalado.setToScale(dw, dh); |
203 | 2527 | caballero | escalado.translate(dx - r.getX(), dy - r.getY()); |
204 | 312 | fernando | |
205 | 649 | vcaballero | Point2D.Double pd = new Point2D.Double(); |
206 | escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
||
207 | 312 | fernando | |
208 | 2527 | caballero | raux.x = pd.x + r.getX(); |
209 | raux.y = pd.y + r.getY(); |
||
210 | 649 | vcaballero | raux.width = raux.width * dw; |
211 | raux.height = raux.height * dh; |
||
212 | 312 | fernando | |
213 | 649 | vcaballero | fframe.setBoundBox(raux); |
214 | } |
||
215 | 2343 | vcaballero | }else{
|
216 | rg=new Rectangle2D.Double(); |
||
217 | rg.setRect(r); |
||
218 | } |
||
219 | 398 | vcaballero | |
220 | 649 | vcaballero | rg.setRect(r); |
221 | } |
||
222 | 312 | fernando | |
223 | 649 | vcaballero | /**
|
224 | 1830 | fernando | * @throws XMLException
|
225 | 649 | vcaballero | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
226 | */
|
||
227 | 1830 | fernando | public XMLEntity getXMLEntity() throws XMLException { |
228 | 649 | vcaballero | XMLEntity xml = new XMLEntity();
|
229 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
230 | 649 | vcaballero | xml.putProperty("m_name", m_name);
|
231 | xml.putProperty("x", getBoundBox().x);
|
||
232 | xml.putProperty("y", getBoundBox().y);
|
||
233 | xml.putProperty("w", getBoundBox().width);
|
||
234 | xml.putProperty("h", getBoundBox().height);
|
||
235 | xml.putProperty("m_Selected", m_Selected);
|
||
236 | xml.putProperty("type", Layout.RECTANGLEGROUP);
|
||
237 | xml.putProperty("tag", getTag());
|
||
238 | 2304 | vcaballero | xml.putProperty("m_rotation",getRotation());
|
239 | 649 | vcaballero | for (int i = 0; i < getFFrames().size(); i++) { |
240 | xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity()); |
||
241 | } |
||
242 | 312 | fernando | |
243 | 649 | vcaballero | return xml;
|
244 | } |
||
245 | |||
246 | /**
|
||
247 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
248 | */
|
||
249 | 2183 | fernando | public void setXMLEntity03(XMLEntity xml, Layout l) { |
250 | if (xml.getIntProperty("m_Selected") != 0) { |
||
251 | this.setSelected(true); |
||
252 | } else {
|
||
253 | this.setSelected(false); |
||
254 | } |
||
255 | |||
256 | IFFrame fframechild = null;
|
||
257 | for (int i = 0; i < xml.getNumChild(); i++) { |
||
258 | try {
|
||
259 | 2343 | vcaballero | Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
260 | 2183 | fernando | fframechild = (IFFrame) clase.newInstance(); |
261 | } catch (Exception e) { |
||
262 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
||
263 | e); |
||
264 | } |
||
265 | 2343 | vcaballero | fframechild.setName(xml.getStringProperty("m_name"));
|
266 | |||
267 | fframechild.setBoundBox(new Rectangle2D.Double(xml.getChild(i).getDoubleProperty("x"), |
||
268 | xml.getChild(i).getDoubleProperty("y"), xml.getChild(i).getDoubleProperty("w"), |
||
269 | xml.getChild(i).getDoubleProperty("h")));
|
||
270 | fframechild.setTag(xml.getChild(i).getStringProperty("tag"));
|
||
271 | 2183 | fernando | fframechild.setXMLEntity03(xml.getChild(i), l); |
272 | this.addFFrame(fframechild);
|
||
273 | } |
||
274 | } |
||
275 | |||
276 | /**
|
||
277 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
278 | */
|
||
279 | 686 | vcaballero | public void setXMLEntity(XMLEntity xml, Layout l) { |
280 | 649 | vcaballero | if (xml.getIntProperty("m_Selected") != 0) { |
281 | this.setSelected(true); |
||
282 | } else {
|
||
283 | this.setSelected(false); |
||
284 | } |
||
285 | 2304 | vcaballero | setRotation(xml.getDoubleProperty("m_rotation"));
|
286 | 649 | vcaballero | IFFrame fframechild = null;
|
287 | 312 | fernando | |
288 | 649 | vcaballero | for (int i = 0; i < xml.getNumChild(); i++) { |
289 | try {
|
||
290 | 2343 | vcaballero | Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
291 | 649 | vcaballero | fframechild = (IFFrame) clase.newInstance(); |
292 | } catch (Exception e) { |
||
293 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
||
294 | e); |
||
295 | } |
||
296 | 2343 | vcaballero | fframechild.setName(xml.getStringProperty("m_name"));
|
297 | |||
298 | fframechild.setBoundBox(new Rectangle2D.Double(xml.getChild(i).getDoubleProperty("x"), |
||
299 | xml.getChild(i).getDoubleProperty("y"), xml.getChild(i).getDoubleProperty("w"), |
||
300 | xml.getChild(i).getDoubleProperty("h")));
|
||
301 | fframechild.setTag(xml.getChild(i).getStringProperty("tag"));
|
||
302 | 686 | vcaballero | fframechild.setXMLEntity(xml.getChild(i), l); |
303 | 649 | vcaballero | this.addFFrame(fframechild);
|
304 | } |
||
305 | } |
||
306 | |||
307 | /**
|
||
308 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
||
309 | */
|
||
310 | public String getNameFFrame() { |
||
311 | return PluginServices.getText(this, "grupo"); |
||
312 | } |
||
313 | |||
314 | /**
|
||
315 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
316 | * java.awt.geom.AffineTransform)
|
||
317 | */
|
||
318 | public void print(Graphics2D g, AffineTransform at) |
||
319 | 654 | fernando | throws DriverException {
|
320 | 2304 | vcaballero | Rectangle2D.Double r = getBoundingBox(at);
|
321 | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
||
322 | r.y + (r.height / 2));
|
||
323 | 649 | vcaballero | for (int i = 0; i < m_fframes.size(); i++) { |
324 | ((IFFrame) m_fframes.get(i)).print(g, at); |
||
325 | } |
||
326 | 2304 | vcaballero | g.rotate(Math.toRadians(-getRotation()),
|
327 | r.x + (r.width / 2), r.y + (r.height / 2)); |
||
328 | 649 | vcaballero | } |
329 | 312 | fernando | } |