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