root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 2970
History | View | Annotate | Download (9.19 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 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 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.messages.NotificationManager; |
56 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
58 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
59 |
import com.iver.cit.gvsig.gui.layout.Layout; |
60 |
import com.iver.utiles.XMLEntity; |
61 |
|
62 |
|
63 |
/**
|
64 |
* FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
65 |
* incluso de si mismo.
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class FFrameGroup extends FFrame { |
70 |
private ArrayList m_fframes = new ArrayList(); |
71 |
private Rectangle2D.Double rg = null; |
72 |
private AffineTransform m_at; |
73 |
//private Rectangle2D.Double ra = null;
|
74 |
|
75 |
/**
|
76 |
* Crea un nuevo FFrameGroup.
|
77 |
*/
|
78 |
public FFrameGroup() {
|
79 |
} |
80 |
|
81 |
/**
|
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 |
|
90 |
/**
|
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 |
|
100 |
/**
|
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 |
|
115 |
for (int i = 0; i < m_fframes.size(); i++) { |
116 |
Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
|
117 |
|
118 |
if (first) {
|
119 |
rec.setRect(rs); |
120 |
first = false;
|
121 |
} |
122 |
|
123 |
rec.add(rs); |
124 |
} |
125 |
|
126 |
rg = new Rectangle2D.Double(); |
127 |
rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
128 |
|
129 |
return rec;
|
130 |
} |
131 |
|
132 |
/**
|
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 |
* @param imgBase Imagen utilizada para acelerar el dibujado.
|
141 |
*
|
142 |
* @throws DriverIOException
|
143 |
*/
|
144 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
145 |
BufferedImage imgBase) throws DriverException { |
146 |
Rectangle2D.Double r = getBoundingBox(at);
|
147 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
148 |
r.y + (r.height / 2));
|
149 |
m_at = at; |
150 |
|
151 |
for (int i = 0; i < m_fframes.size(); i++) { |
152 |
((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase); |
153 |
} |
154 |
g.rotate(Math.toRadians(-getRotation()),
|
155 |
r.x + (r.width / 2), r.y + (r.height / 2)); |
156 |
} |
157 |
|
158 |
/**
|
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 |
|
167 |
/**
|
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 |
public void setBoundBox(Rectangle2D r) { |
174 |
getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
175 |
|
176 |
double dx=1; |
177 |
double dy=1; |
178 |
double dw=1; |
179 |
double dh=1; |
180 |
//double scalex=1;
|
181 |
//double scaley=1;
|
182 |
if (rg!=null){ |
183 |
|
184 |
Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width, |
185 |
rg.height); |
186 |
dx = r.getX() - raux1.x; |
187 |
dy = r.getY() - raux1.y; |
188 |
dw = r.getWidth() / raux1.width; |
189 |
dh = r.getHeight() / raux1.height; |
190 |
|
191 |
//scalex = r.width / raux1.width;
|
192 |
//scaley = r.height / raux1.height;
|
193 |
|
194 |
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 |
|
199 |
AffineTransform escalado = new AffineTransform(); |
200 |
|
201 |
|
202 |
escalado.setToScale(dw, dh); |
203 |
escalado.translate(dx - r.getX(), dy - r.getY()); |
204 |
|
205 |
Point2D.Double pd = new Point2D.Double(); |
206 |
escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
207 |
|
208 |
raux.x = pd.x + r.getX(); |
209 |
raux.y = pd.y + r.getY(); |
210 |
raux.width = raux.width * dw; |
211 |
raux.height = raux.height * dh; |
212 |
|
213 |
fframe.setBoundBox(raux); |
214 |
} |
215 |
}else{
|
216 |
rg=new Rectangle2D.Double(); |
217 |
rg.setRect(r); |
218 |
} |
219 |
|
220 |
rg.setRect(r); |
221 |
} |
222 |
|
223 |
/**
|
224 |
* @throws XMLException
|
225 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
226 |
*/
|
227 |
public XMLEntity getXMLEntity() throws XMLException { |
228 |
XMLEntity xml = new XMLEntity();
|
229 |
xml.putProperty("className",this.getClass().getName()); |
230 |
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 |
xml.putProperty("m_rotation",getRotation());
|
239 |
for (int i = 0; i < getFFrames().size(); i++) { |
240 |
xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity()); |
241 |
} |
242 |
|
243 |
return xml;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
248 |
*/
|
249 |
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 |
Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
260 |
fframechild = (IFFrame) clase.newInstance(); |
261 |
} catch (Exception e) { |
262 |
NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
263 |
e); |
264 |
} |
265 |
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 |
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 |
public void setXMLEntity(XMLEntity xml, Layout l) { |
280 |
if (xml.getIntProperty("m_Selected") != 0) { |
281 |
this.setSelected(true); |
282 |
} else {
|
283 |
this.setSelected(false); |
284 |
} |
285 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
286 |
IFFrame fframechild = null;
|
287 |
|
288 |
for (int i = 0; i < xml.getNumChild(); i++) { |
289 |
try {
|
290 |
Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
291 |
fframechild = (IFFrame) clase.newInstance(); |
292 |
} catch (Exception e) { |
293 |
NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
294 |
e); |
295 |
} |
296 |
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 |
fframechild.setXMLEntity(xml.getChild(i), l); |
303 |
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 |
throws DriverException {
|
320 |
Rectangle2D.Double r = getBoundingBox(at);
|
321 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
322 |
r.y + (r.height / 2));
|
323 |
for (int i = 0; i < m_fframes.size(); i++) { |
324 |
((IFFrame) m_fframes.get(i)).print(g, at); |
325 |
} |
326 |
g.rotate(Math.toRadians(-getRotation()),
|
327 |
r.x + (r.width / 2), r.y + (r.height / 2)); |
328 |
} |
329 |
} |