root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 12104
History | View | Annotate | Download (12.7 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.gui.layout.Layout; |
58 |
import com.iver.cit.gvsig.project.Project; |
59 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
60 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
61 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
62 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
63 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence; |
64 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseProject; |
65 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence; |
66 |
import com.iver.utiles.XMLEntity; |
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 |
IFFrameLayoutDependence, IFFrameViewDependence { |
77 |
private ArrayList m_fframes = new ArrayList(); |
78 |
private Rectangle2D.Double rg = null; |
79 |
private AffineTransform m_at; |
80 |
private Project project;
|
81 |
private Layout layout;
|
82 |
|
83 |
/**
|
84 |
* Crea un nuevo FFrameGroup.
|
85 |
*/
|
86 |
public FFrameGroup() {
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
|
91 |
*
|
92 |
* @param fframe FFrame a a?adir.
|
93 |
*/
|
94 |
public void addFFrame(IFFrame fframe) { |
95 |
m_fframes.add(fframe); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Devuelve una ArrayList que contiene todos los FFrames que forman parte
|
100 |
* del grupo.
|
101 |
*
|
102 |
* @return Arraylist con los fframes.
|
103 |
*/
|
104 |
public IFFrame[] getFFrames() { |
105 |
return (IFFrame[]) m_fframes.toArray(new IFFrame[0]); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
|
110 |
*
|
111 |
* @param at Matriz de transformaci?n
|
112 |
*
|
113 |
* @return Rect?ngulo.
|
114 |
*/
|
115 |
public Rectangle2D.Double getRectangle(AffineTransform at) { |
116 |
boolean first = true; |
117 |
Rectangle2D.Double rec = new Rectangle2D.Double(); |
118 |
IFFrame[] fframes=getFFrames();
|
119 |
for (int i = 0; i < fframes.length; i++) { |
120 |
Rectangle2D.Double rs = fframes[i].getBoundingBox(at);
|
121 |
|
122 |
if (first) {
|
123 |
rec.setRect(rs); |
124 |
first = false;
|
125 |
} |
126 |
|
127 |
rec.add(rs); |
128 |
} |
129 |
|
130 |
rg = new Rectangle2D.Double(); |
131 |
rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
132 |
|
133 |
return rec;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
138 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
139 |
* de dibujar.
|
140 |
*
|
141 |
* @param g Graphics
|
142 |
* @param at Transformada afin.
|
143 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
144 |
* @param imgBase Imagen utilizada para acelerar el dibujado.
|
145 |
*
|
146 |
* @throws DriverException
|
147 |
*/
|
148 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
149 |
BufferedImage imgBase) throws DriverException { |
150 |
Rectangle2D.Double r = getBoundingBox(at);
|
151 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
152 |
r.y + (r.height / 2));
|
153 |
m_at = at; |
154 |
|
155 |
for (int i = 0; i < m_fframes.size(); i++) { |
156 |
((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase); |
157 |
} |
158 |
|
159 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
160 |
r.y + (r.height / 2));
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Rellena la transformada que se esta utilizando en el Layout.
|
165 |
*
|
166 |
* @param at Matriz de transformaci?n.
|
167 |
*/
|
168 |
public void setAt(AffineTransform at) { |
169 |
m_at = at; |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Reimplementaci?n del m?todo papa poder modificar los BoundBox de cada
|
174 |
* uno de los FFrames que contiene dentro este FFrameGroup.
|
175 |
*
|
176 |
* @param r Rect?ngulo.
|
177 |
*/
|
178 |
public void setBoundBox(Rectangle2D r) { |
179 |
getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
180 |
|
181 |
double dx = 1; |
182 |
double dy = 1; |
183 |
double dw = 1; |
184 |
double dh = 1; |
185 |
|
186 |
if (rg != null) { |
187 |
Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, |
188 |
rg.width, rg.height); |
189 |
dx = r.getX() - raux1.x; |
190 |
dy = r.getY() - raux1.y; |
191 |
dw = r.getWidth() / raux1.width; |
192 |
dh = r.getHeight() / raux1.height; |
193 |
IFFrame[] fframes=getFFrames();
|
194 |
for (int i = 0; i < fframes.length; i++) { |
195 |
IFFrame fframe = fframes[i]; |
196 |
Rectangle2D.Double raux = new Rectangle2D.Double(); |
197 |
raux.setRect(fframe.getBoundBox()); |
198 |
|
199 |
AffineTransform escalado = new AffineTransform(); |
200 |
|
201 |
escalado.setToScale(dw, dh); |
202 |
escalado.translate(dx - r.getX(), dy - r.getY()); |
203 |
|
204 |
Point2D.Double pd = new Point2D.Double(); |
205 |
escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
206 |
|
207 |
raux.x = pd.x + r.getX(); |
208 |
raux.y = pd.y + r.getY(); |
209 |
raux.width = raux.width * dw; |
210 |
raux.height = raux.height * dh; |
211 |
|
212 |
fframe.setBoundBox(raux); |
213 |
} |
214 |
} else {
|
215 |
rg = new Rectangle2D.Double(); |
216 |
rg.setRect(r); |
217 |
} |
218 |
|
219 |
rg.setRect(r); |
220 |
} |
221 |
|
222 |
/**
|
223 |
* DOCUMENT ME!
|
224 |
*
|
225 |
* @return DOCUMENT ME!
|
226 |
*
|
227 |
* @throws SaveException
|
228 |
*
|
229 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
|
230 |
*/
|
231 |
public XMLEntity getXMLEntity() throws SaveException { |
232 |
XMLEntity xml = super.getXMLEntity();
|
233 |
xml.putProperty("type", Layout.RECTANGLEGROUP);
|
234 |
IFFrame[] fframes=getFFrames();
|
235 |
for (int i = 0; i < fframes.length; i++) { |
236 |
xml.addChild(fframes[i].getXMLEntity()); |
237 |
} |
238 |
|
239 |
return xml;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
244 |
*/
|
245 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
246 |
if (xml.getIntProperty("m_Selected") != 0) { |
247 |
this.setSelected(true); |
248 |
} else {
|
249 |
this.setSelected(false); |
250 |
} |
251 |
|
252 |
IFFrame fframechild = null;
|
253 |
|
254 |
for (int i = 0; i < xml.getChildrenCount(); i++) { |
255 |
try {
|
256 |
Class clase = Class.forName(xml.getChild(i).getStringProperty("className")); |
257 |
fframechild = (IFFrame) clase.newInstance(); |
258 |
} catch (Exception e) { |
259 |
NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
260 |
e); |
261 |
} |
262 |
|
263 |
fframechild.setName(xml.getStringProperty("m_name"));
|
264 |
|
265 |
fframechild.setBoundBox(new Rectangle2D.Double( |
266 |
xml.getChild(i).getDoubleProperty("x"),
|
267 |
xml.getChild(i).getDoubleProperty("y"),
|
268 |
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.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
278 |
*/
|
279 |
public void setXMLEntity(XMLEntity xml) { |
280 |
if (xml.getIntProperty("m_Selected") != 0) { |
281 |
this.setSelected(true); |
282 |
} else {
|
283 |
this.setSelected(false); |
284 |
} |
285 |
|
286 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
287 |
|
288 |
for (int i = 0; i < xml.getChildrenCount(); i++) { |
289 |
try {
|
290 |
IFFrame frame = FFrame.createFFrame(xml.getChild(i), project,layout); |
291 |
this.addFFrame(frame);
|
292 |
} catch (OpenException e) {
|
293 |
e.showError(); |
294 |
} |
295 |
} |
296 |
} |
297 |
|
298 |
/**
|
299 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
300 |
*/
|
301 |
public String getNameFFrame() { |
302 |
return PluginServices.getText(this, "grupo")+ num; |
303 |
} |
304 |
|
305 |
/**
|
306 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
307 |
* java.awt.geom.AffineTransform)
|
308 |
*/
|
309 |
public void print(Graphics2D g, AffineTransform at) |
310 |
throws DriverException {
|
311 |
Rectangle2D.Double r = getBoundingBox(at);
|
312 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
313 |
r.y + (r.height / 2));
|
314 |
|
315 |
for (int i = 0; i < m_fframes.size(); i++) { |
316 |
((IFFrame) m_fframes.get(i)).print(g, at); |
317 |
} |
318 |
|
319 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
320 |
r.y + (r.height / 2));
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* Inserta una referencia al proyecto nesecario.
|
325 |
*
|
326 |
* @param project DOCUMENT ME!
|
327 |
*/
|
328 |
public void setProject(Project project) { |
329 |
this.project = project;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* DOCUMENT ME!
|
334 |
*
|
335 |
* @param layout DOCUMENT ME!
|
336 |
*/
|
337 |
public void setLayout(Layout layout) { |
338 |
this.layout=layout;
|
339 |
IFFrame[] fs = getFFrames();
|
340 |
|
341 |
for (int i = 0; i < fs.length; i++) { |
342 |
if (fs[i] instanceof IFFrameLayoutDependence) { |
343 |
((IFFrameLayoutDependence) fs[i]).setLayout(layout); |
344 |
} |
345 |
|
346 |
if (fs[i] instanceof IFFrameViewDependence) { |
347 |
((IFFrameViewDependence) fs[i]).initDependence(fs); |
348 |
} |
349 |
} |
350 |
} |
351 |
|
352 |
public void initialize() { |
353 |
// TODO Auto-generated method stub
|
354 |
|
355 |
} |
356 |
public void clearFFrames(){ |
357 |
m_fframes.clear(); |
358 |
} |
359 |
public IFFrame removeFFrame(int i){ |
360 |
return (IFFrame)m_fframes.remove(i);
|
361 |
} |
362 |
public void removeFFrame(IFFrame fframe){ |
363 |
m_fframes.remove(fframe); |
364 |
} |
365 |
|
366 |
public Layout getLayout() {
|
367 |
return layout;
|
368 |
} |
369 |
|
370 |
public void cloneActions(IFFrame frame) { |
371 |
// TODO Auto-generated method stub
|
372 |
|
373 |
} |
374 |
|
375 |
public void setFFrameDependence(IFFrame f) { |
376 |
IFFrame[] frames=getFFrames();
|
377 |
for (int i =0;i<frames.length;i++){ |
378 |
if (frames[i] instanceof IFFrameViewDependence){ |
379 |
((IFFrameViewDependence)frames[i]).setFFrameDependence(f); |
380 |
} |
381 |
} |
382 |
|
383 |
} |
384 |
|
385 |
public IFFrame[] getFFrameDependence() { |
386 |
IFFrame[] frames=getFFrames();
|
387 |
ArrayList dependences=new ArrayList(); |
388 |
for (int i =0;i<frames.length;i++){ |
389 |
if (frames[i] instanceof IFFrameViewDependence){ |
390 |
dependences.add(((IFFrameViewDependence)frames[i]).getFFrameDependence()); |
391 |
} |
392 |
} |
393 |
return (IFFrame[])dependences.toArray(new IFFrame[0]); |
394 |
} |
395 |
|
396 |
public void initDependence(IFFrame[] fframes) { |
397 |
IFFrame[] frames=getFFrames();
|
398 |
for (int i =0;i<frames.length;i++){ |
399 |
if (frames[i] instanceof IFFrameViewDependence){ |
400 |
((IFFrameViewDependence)frames[i]).initDependence(fframes); |
401 |
} |
402 |
} |
403 |
} |
404 |
|
405 |
public void refreshDependence(IFFrame fant, IFFrame fnew) { |
406 |
IFFrame[] frames=getFFrames();
|
407 |
for (int i =0;i<frames.length;i++){ |
408 |
|
409 |
if (fnew instanceof FFrameGroup){ |
410 |
IFFrame[] framesGroupNew=((FFrameGroup)fnew).getFFrames();
|
411 |
for (int j=0;j<framesGroupNew.length;j++){ |
412 |
if (fant instanceof FFrameGroup){ |
413 |
IFFrame[] framesGroupAnt=((FFrameGroup)fant).getFFrames();
|
414 |
for (int k=0;k<framesGroupAnt.length;k++){ |
415 |
if (framesGroupAnt[k] instanceof IFFrameViewDependence){ |
416 |
refreshDependence(framesGroupAnt[k],framesGroupNew[j]); |
417 |
} |
418 |
} |
419 |
} |
420 |
} |
421 |
}else if (frames[i] instanceof IFFrameViewDependence){ |
422 |
((IFFrameViewDependence)frames[i]).refreshDependence(fant,fnew); |
423 |
} |
424 |
} |
425 |
|
426 |
} |
427 |
} |