svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 5503
History | View | Annotate | Download (10.6 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 | 596 | fernando | import com.iver.andami.PluginServices; |
48 | import com.iver.andami.messages.NotificationManager; |
||
49 | 3135 | caballero | |
50 | 654 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
51 | 596 | fernando | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
52 | import com.iver.cit.gvsig.gui.layout.Layout; |
||
53 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
54 | import com.iver.cit.gvsig.gui.project.SaveException; |
||
55 | 3135 | caballero | import com.iver.cit.gvsig.project.Project; |
56 | |||
57 | 596 | fernando | import com.iver.utiles.XMLEntity; |
58 | 312 | fernando | |
59 | 3135 | caballero | 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 | 596 | fernando | |
65 | 3135 | caballero | import java.util.ArrayList; |
66 | |||
67 | |||
68 | 312 | fernando | /**
|
69 | 398 | vcaballero | * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
70 | 312 | fernando | * incluso de si mismo.
|
71 | *
|
||
72 | * @author Vicente Caballero Navarro
|
||
73 | */
|
||
74 | 3610 | caballero | public class FFrameGroup extends FFrame implements IFFrameUseProject, |
75 | IFFrameLayoutDependence { |
||
76 | 3103 | caballero | private ArrayList m_fframes = new ArrayList(); |
77 | private Rectangle2D.Double rg = null; |
||
78 | private AffineTransform m_at; |
||
79 | 3135 | caballero | private Project project;
|
80 | 4779 | caballero | private Layout layout;
|
81 | 3610 | caballero | |
82 | 3103 | caballero | /**
|
83 | * Crea un nuevo FFrameGroup.
|
||
84 | */
|
||
85 | public FFrameGroup() {
|
||
86 | } |
||
87 | 312 | fernando | |
88 | 3103 | caballero | /**
|
89 | * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
|
||
90 | *
|
||
91 | * @param fframe FFrame a a?adir.
|
||
92 | */
|
||
93 | public void addFFrame(IFFrame fframe) { |
||
94 | m_fframes.add(fframe); |
||
95 | } |
||
96 | 312 | fernando | |
97 | 3103 | caballero | /**
|
98 | * Devuelve una ArrayList que contiene todos los FFrames que forman parte
|
||
99 | * del grupo.
|
||
100 | *
|
||
101 | * @return Arraylist con los fframes.
|
||
102 | */
|
||
103 | 3553 | caballero | public IFFrame[] getFFrames() { |
104 | 3610 | caballero | return (IFFrame[]) m_fframes.toArray(new IFFrame[0]); |
105 | 3103 | caballero | } |
106 | 312 | fernando | |
107 | 3103 | caballero | /**
|
108 | * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
|
||
109 | *
|
||
110 | * @param at Matriz de transformaci?n
|
||
111 | *
|
||
112 | * @return Rect?ngulo.
|
||
113 | */
|
||
114 | public Rectangle2D.Double getRectangle(AffineTransform at) { |
||
115 | boolean first = true; |
||
116 | Rectangle2D.Double rec = new Rectangle2D.Double(); |
||
117 | 4779 | caballero | IFFrame[] fframes=getFFrames();
|
118 | for (int i = 0; i < fframes.length; i++) { |
||
119 | Rectangle2D.Double rs = fframes[i].getBoundingBox(at);
|
||
120 | 312 | fernando | |
121 | 3103 | caballero | if (first) {
|
122 | rec.setRect(rs); |
||
123 | first = false;
|
||
124 | } |
||
125 | 312 | fernando | |
126 | 3103 | caballero | rec.add(rs); |
127 | } |
||
128 | 312 | fernando | |
129 | 3103 | caballero | rg = new Rectangle2D.Double(); |
130 | rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
||
131 | 312 | fernando | |
132 | 3103 | caballero | return rec;
|
133 | } |
||
134 | 312 | fernando | |
135 | 3103 | caballero | /**
|
136 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
||
137 | * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
||
138 | * de dibujar.
|
||
139 | *
|
||
140 | * @param g Graphics
|
||
141 | * @param at Transformada afin.
|
||
142 | * @param rv rect?ngulo sobre el que hacer un clip.
|
||
143 | * @param imgBase Imagen utilizada para acelerar el dibujado.
|
||
144 | *
|
||
145 | * @throws DriverException
|
||
146 | */
|
||
147 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
148 | BufferedImage imgBase) throws DriverException { |
||
149 | Rectangle2D.Double r = getBoundingBox(at);
|
||
150 | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
||
151 | r.y + (r.height / 2));
|
||
152 | m_at = at; |
||
153 | 312 | fernando | |
154 | 3103 | caballero | for (int i = 0; i < m_fframes.size(); i++) { |
155 | ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase); |
||
156 | } |
||
157 | 398 | vcaballero | |
158 | 3103 | caballero | g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
159 | r.y + (r.height / 2));
|
||
160 | } |
||
161 | 312 | fernando | |
162 | 3103 | caballero | /**
|
163 | * Rellena la transformada que se esta utilizando en el Layout.
|
||
164 | *
|
||
165 | * @param at Matriz de transformaci?n.
|
||
166 | */
|
||
167 | public void setAt(AffineTransform at) { |
||
168 | m_at = at; |
||
169 | } |
||
170 | 398 | vcaballero | |
171 | 3103 | caballero | /**
|
172 | * Reimplementaci?n del m?todo papa poder modificar los BoundBox de cada
|
||
173 | * uno de los FFrames que contiene dentro este FFrameGroup.
|
||
174 | *
|
||
175 | * @param r Rect?ngulo.
|
||
176 | */
|
||
177 | public void setBoundBox(Rectangle2D r) { |
||
178 | getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
||
179 | 312 | fernando | |
180 | 3103 | caballero | double dx = 1; |
181 | double dy = 1; |
||
182 | double dw = 1; |
||
183 | double dh = 1; |
||
184 | 312 | fernando | |
185 | 3103 | caballero | if (rg != null) { |
186 | Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, |
||
187 | rg.width, rg.height); |
||
188 | dx = r.getX() - raux1.x; |
||
189 | dy = r.getY() - raux1.y; |
||
190 | dw = r.getWidth() / raux1.width; |
||
191 | dh = r.getHeight() / raux1.height; |
||
192 | 312 | fernando | |
193 | 3553 | caballero | for (int i = 0; i < getFFrames().length; i++) { |
194 | IFFrame fframe = (IFFrame) getFFrames()[i]; |
||
195 | 3103 | caballero | Rectangle2D.Double raux = new Rectangle2D.Double(); |
196 | raux.setRect(fframe.getBoundBox()); |
||
197 | 312 | fernando | |
198 | 3103 | caballero | AffineTransform escalado = new AffineTransform(); |
199 | 312 | fernando | |
200 | 3103 | caballero | escalado.setToScale(dw, dh); |
201 | escalado.translate(dx - r.getX(), dy - r.getY()); |
||
202 | 398 | vcaballero | |
203 | 3103 | caballero | Point2D.Double pd = new Point2D.Double(); |
204 | escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
||
205 | 312 | fernando | |
206 | 3103 | caballero | raux.x = pd.x + r.getX(); |
207 | raux.y = pd.y + r.getY(); |
||
208 | raux.width = raux.width * dw; |
||
209 | raux.height = raux.height * dh; |
||
210 | 312 | fernando | |
211 | 3103 | caballero | fframe.setBoundBox(raux); |
212 | } |
||
213 | } else {
|
||
214 | rg = new Rectangle2D.Double(); |
||
215 | rg.setRect(r); |
||
216 | } |
||
217 | 2183 | fernando | |
218 | 3103 | caballero | rg.setRect(r); |
219 | } |
||
220 | 312 | fernando | |
221 | 3103 | caballero | /**
|
222 | * DOCUMENT ME!
|
||
223 | *
|
||
224 | * @return DOCUMENT ME!
|
||
225 | *
|
||
226 | 3610 | caballero | * @throws SaveException
|
227 | 3103 | caballero | *
|
228 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
||
229 | */
|
||
230 | 3183 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
231 | 3610 | caballero | XMLEntity xml = super.getXMLEntity();
|
232 | 3103 | caballero | xml.putProperty("type", Layout.RECTANGLEGROUP);
|
233 | 4779 | caballero | IFFrame[] fframes=getFFrames();
|
234 | for (int i = 0; i < fframes.length; i++) { |
||
235 | xml.addChild(fframes[i].getXMLEntity()); |
||
236 | 3103 | caballero | } |
237 | 649 | vcaballero | |
238 | 3103 | caballero | return xml;
|
239 | } |
||
240 | |||
241 | /**
|
||
242 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
243 | */
|
||
244 | public void setXMLEntity03(XMLEntity xml, Layout l) { |
||
245 | if (xml.getIntProperty("m_Selected") != 0) { |
||
246 | this.setSelected(true); |
||
247 | } else {
|
||
248 | this.setSelected(false); |
||
249 | } |
||
250 | |||
251 | IFFrame fframechild = null;
|
||
252 | |||
253 | for (int i = 0; i < xml.getNumChild(); i++) { |
||
254 | try {
|
||
255 | Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
||
256 | fframechild = (IFFrame) clase.newInstance(); |
||
257 | } catch (Exception e) { |
||
258 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
||
259 | e); |
||
260 | } |
||
261 | |||
262 | fframechild.setName(xml.getStringProperty("m_name"));
|
||
263 | |||
264 | fframechild.setBoundBox(new Rectangle2D.Double( |
||
265 | xml.getChild(i).getDoubleProperty("x"),
|
||
266 | xml.getChild(i).getDoubleProperty("y"),
|
||
267 | xml.getChild(i).getDoubleProperty("w"),
|
||
268 | xml.getChild(i).getDoubleProperty("h")));
|
||
269 | fframechild.setTag(xml.getChild(i).getStringProperty("tag"));
|
||
270 | fframechild.setXMLEntity03(xml.getChild(i), l); |
||
271 | this.addFFrame(fframechild);
|
||
272 | } |
||
273 | } |
||
274 | |||
275 | /**
|
||
276 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
277 | */
|
||
278 | 3135 | caballero | public void setXMLEntity(XMLEntity xml) { |
279 | 3103 | caballero | if (xml.getIntProperty("m_Selected") != 0) { |
280 | this.setSelected(true); |
||
281 | } else {
|
||
282 | this.setSelected(false); |
||
283 | } |
||
284 | |||
285 | setRotation(xml.getDoubleProperty("m_rotation"));
|
||
286 | |||
287 | for (int i = 0; i < xml.getNumChild(); i++) { |
||
288 | 3183 | caballero | try {
|
289 | 3610 | caballero | IFFrame frame = FFrame.createFFrame(xml.getChild(i), project); |
290 | this.addFFrame(frame);
|
||
291 | } catch (OpenException e) {
|
||
292 | e.showError(); |
||
293 | } |
||
294 | 3103 | caballero | } |
295 | } |
||
296 | |||
297 | /**
|
||
298 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
||
299 | */
|
||
300 | public String getNameFFrame() { |
||
301 | 5476 | caballero | return PluginServices.getText(this, "grupo")+ num; |
302 | 3103 | caballero | } |
303 | |||
304 | /**
|
||
305 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
306 | * java.awt.geom.AffineTransform)
|
||
307 | */
|
||
308 | public void print(Graphics2D g, AffineTransform at) |
||
309 | throws DriverException {
|
||
310 | Rectangle2D.Double r = getBoundingBox(at);
|
||
311 | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
||
312 | r.y + (r.height / 2));
|
||
313 | |||
314 | for (int i = 0; i < m_fframes.size(); i++) { |
||
315 | ((IFFrame) m_fframes.get(i)).print(g, at); |
||
316 | } |
||
317 | |||
318 | g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
||
319 | r.y + (r.height / 2));
|
||
320 | } |
||
321 | 3135 | caballero | |
322 | /**
|
||
323 | * Inserta una referencia al proyecto nesecario.
|
||
324 | *
|
||
325 | * @param project DOCUMENT ME!
|
||
326 | */
|
||
327 | public void setProject(Project project) { |
||
328 | this.project = project;
|
||
329 | } |
||
330 | 3553 | caballero | |
331 | 3610 | caballero | /**
|
332 | * DOCUMENT ME!
|
||
333 | *
|
||
334 | * @param layout DOCUMENT ME!
|
||
335 | */
|
||
336 | public void setLayout(Layout layout) { |
||
337 | 4779 | caballero | this.layout=layout;
|
338 | IFFrame[] fs = getFFrames();
|
||
339 | 3610 | caballero | |
340 | for (int i = 0; i < fs.length; i++) { |
||
341 | if (fs[i] instanceof IFFrameLayoutDependence) { |
||
342 | ((IFFrameLayoutDependence) fs[i]).setLayout(layout); |
||
343 | } |
||
344 | |||
345 | if (fs[i] instanceof IFFrameViewDependence) { |
||
346 | ((IFFrameViewDependence) fs[i]).initDependence(fs); |
||
347 | } |
||
348 | } |
||
349 | } |
||
350 | 4203 | caballero | |
351 | public void initialize() { |
||
352 | // TODO Auto-generated method stub
|
||
353 | |||
354 | } |
||
355 | 4779 | caballero | public void clearFFrames(){ |
356 | m_fframes.clear(); |
||
357 | } |
||
358 | public IFFrame removeFFrame(int i){ |
||
359 | return (IFFrame)m_fframes.remove(i);
|
||
360 | } |
||
361 | public void removeFFrame(IFFrame fframe){ |
||
362 | m_fframes.remove(fframe); |
||
363 | } |
||
364 | |||
365 | public Layout getLayout() {
|
||
366 | return layout;
|
||
367 | } |
||
368 | 312 | fernando | } |