svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 5222
History | View | Annotate | Download (10.1 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.fmap.layers.XMLException; |
52 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
53 |
import com.iver.cit.gvsig.gui.layout.Layout; |
54 |
import com.iver.cit.gvsig.gui.project.OpenException; |
55 |
import com.iver.cit.gvsig.gui.project.SaveException; |
56 |
import com.iver.cit.gvsig.project.Project; |
57 |
|
58 |
import com.iver.utiles.XMLEntity; |
59 |
|
60 |
import java.awt.Graphics2D; |
61 |
import java.awt.geom.AffineTransform; |
62 |
import java.awt.geom.Point2D; |
63 |
import java.awt.geom.Rectangle2D; |
64 |
import java.awt.image.BufferedImage; |
65 |
|
66 |
import java.util.ArrayList; |
67 |
|
68 |
|
69 |
/**
|
70 |
* FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
71 |
* incluso de si mismo.
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class FFrameGroup extends FFrame implements IFFrameUseProject { |
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 ArrayList getFFrames() { |
103 |
return m_fframes;
|
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().size(); i++) { |
193 |
IFFrame fframe = (IFFrame) getFFrames().get(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 XMLException
|
226 |
*
|
227 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
228 |
*/
|
229 |
public XMLEntity getXMLEntity() throws SaveException { |
230 |
XMLEntity xml = new XMLEntity();
|
231 |
xml.putProperty("className", this.getClass().getName()); |
232 |
xml.putProperty("m_name", m_name);
|
233 |
xml.putProperty("x", getBoundBox().x);
|
234 |
xml.putProperty("y", getBoundBox().y);
|
235 |
xml.putProperty("w", getBoundBox().width);
|
236 |
xml.putProperty("h", getBoundBox().height);
|
237 |
xml.putProperty("m_Selected", m_Selected);
|
238 |
xml.putProperty("type", Layout.RECTANGLEGROUP);
|
239 |
xml.putProperty("tag", getTag());
|
240 |
xml.putProperty("m_rotation", getRotation());
|
241 |
|
242 |
for (int i = 0; i < getFFrames().size(); i++) { |
243 |
xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity()); |
244 |
} |
245 |
|
246 |
return xml;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
251 |
*/
|
252 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
253 |
if (xml.getIntProperty("m_Selected") != 0) { |
254 |
this.setSelected(true); |
255 |
} else {
|
256 |
this.setSelected(false); |
257 |
} |
258 |
|
259 |
IFFrame fframechild = null;
|
260 |
|
261 |
for (int i = 0; i < xml.getNumChild(); i++) { |
262 |
try {
|
263 |
Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
264 |
fframechild = (IFFrame) clase.newInstance(); |
265 |
} catch (Exception e) { |
266 |
NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
267 |
e); |
268 |
} |
269 |
|
270 |
fframechild.setName(xml.getStringProperty("m_name"));
|
271 |
|
272 |
fframechild.setBoundBox(new Rectangle2D.Double( |
273 |
xml.getChild(i).getDoubleProperty("x"),
|
274 |
xml.getChild(i).getDoubleProperty("y"),
|
275 |
xml.getChild(i).getDoubleProperty("w"),
|
276 |
xml.getChild(i).getDoubleProperty("h")));
|
277 |
fframechild.setTag(xml.getChild(i).getStringProperty("tag"));
|
278 |
fframechild.setXMLEntity03(xml.getChild(i), l); |
279 |
this.addFFrame(fframechild);
|
280 |
} |
281 |
} |
282 |
|
283 |
/**
|
284 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
285 |
*/
|
286 |
public void setXMLEntity(XMLEntity xml) { |
287 |
if (xml.getIntProperty("m_Selected") != 0) { |
288 |
this.setSelected(true); |
289 |
} else {
|
290 |
this.setSelected(false); |
291 |
} |
292 |
|
293 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
294 |
|
295 |
for (int i = 0; i < xml.getNumChild(); i++) { |
296 |
try {
|
297 |
this.addFFrame(FFrame.createFFrame(xml.getChild(i), project));
|
298 |
} catch (OpenException e) {
|
299 |
e.showError(); |
300 |
} |
301 |
} |
302 |
} |
303 |
|
304 |
/**
|
305 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
306 |
*/
|
307 |
public String getNameFFrame() { |
308 |
return PluginServices.getText(this, "grupo"); |
309 |
} |
310 |
|
311 |
/**
|
312 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
313 |
* java.awt.geom.AffineTransform)
|
314 |
*/
|
315 |
public void print(Graphics2D g, AffineTransform at) |
316 |
throws DriverException {
|
317 |
Rectangle2D.Double r = getBoundingBox(at);
|
318 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
319 |
r.y + (r.height / 2));
|
320 |
|
321 |
for (int i = 0; i < m_fframes.size(); i++) { |
322 |
((IFFrame) m_fframes.get(i)).print(g, at); |
323 |
} |
324 |
|
325 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
326 |
r.y + (r.height / 2));
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* Inserta una referencia al proyecto nesecario.
|
331 |
*
|
332 |
* @param project DOCUMENT ME!
|
333 |
*/
|
334 |
public void setProject(Project project) { |
335 |
this.project = project;
|
336 |
} |
337 |
|
338 |
public void initialize() { |
339 |
// TODO Auto-generated method stub
|
340 |
|
341 |
} |
342 |
} |