svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 312
History | View | Annotate | Download (7.46 KB)
1 |
/*
|
---|---|
2 |
* Created on 15-jul-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig.gui.layout.fframes; |
8 |
|
9 |
import java.awt.Graphics2D; |
10 |
import java.awt.geom.AffineTransform; |
11 |
import java.awt.geom.Point2D; |
12 |
import java.awt.geom.Rectangle2D; |
13 |
import java.awt.image.BufferedImage; |
14 |
import java.util.ArrayList; |
15 |
|
16 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
17 |
import com.iver.cit.gvsig.gui.layout.Layout; |
18 |
import com.iver.cit.gvsig.project.Project; |
19 |
import com.iver.utiles.XMLEntity; |
20 |
|
21 |
|
22 |
/**
|
23 |
* FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
24 |
* incluso de si mismo.
|
25 |
*
|
26 |
* @author Vicente Caballero Navarro
|
27 |
*/
|
28 |
public class FFrameGroup extends FFrame { |
29 |
private ArrayList m_fframes = new ArrayList(); |
30 |
private Rectangle2D.Double rg = null; |
31 |
private AffineTransform m_at; |
32 |
private Rectangle2D.Double ra = null; |
33 |
|
34 |
/**
|
35 |
* Crea un nuevo FFrameGroup.
|
36 |
*/
|
37 |
public FFrameGroup() {
|
38 |
} |
39 |
|
40 |
/**
|
41 |
* A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
|
42 |
*
|
43 |
* @param fframe. FFrame a a?adir.
|
44 |
*/
|
45 |
public void addFFrame(IFFrame fframe) { |
46 |
m_fframes.add(fframe); |
47 |
} |
48 |
|
49 |
/**
|
50 |
* Devuelve una ArrayList que contiene todos los FFrames que forman parte del grupo.
|
51 |
*
|
52 |
* @return Arraylist con los fframes.
|
53 |
*/
|
54 |
public ArrayList getFFrames() { |
55 |
return m_fframes;
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
|
60 |
*
|
61 |
* @param at Matriz de transformaci?n
|
62 |
*
|
63 |
* @return Rect?ngulo.
|
64 |
*/
|
65 |
public Rectangle2D.Double getRectangle(AffineTransform at) { |
66 |
double minX = 0; |
67 |
double minY = 0; |
68 |
double maxX = 0; |
69 |
double maxY = 0; |
70 |
boolean first = true; |
71 |
Rectangle2D.Double rec = new Rectangle2D.Double(); |
72 |
|
73 |
for (int i = 0; i < m_fframes.size(); i++) { |
74 |
Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
|
75 |
|
76 |
if (first) {
|
77 |
rec.setRect(rs); |
78 |
first = false;
|
79 |
} |
80 |
|
81 |
rec.add(rs); |
82 |
} |
83 |
|
84 |
rg = new Rectangle2D.Double(); |
85 |
rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
86 |
|
87 |
return rec;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
92 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
93 |
* de dibujar.
|
94 |
*
|
95 |
* @param g Graphics
|
96 |
* @param at Transformada afin.
|
97 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
98 |
*/
|
99 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,BufferedImage imgBase) { |
100 |
Rectangle2D.Double r = getBoundingBox(at);
|
101 |
m_at = at; |
102 |
|
103 |
for (int i = 0; i < m_fframes.size(); i++) { |
104 |
((IFFrame) m_fframes.get(i)).draw(g, at, rv,imgBase); |
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Rellena la transformada que se esta utilizando en el Layout.
|
110 |
*
|
111 |
* @param at Matriz de transformaci?n.
|
112 |
*/
|
113 |
public void setAt(AffineTransform at) { |
114 |
m_at = at; |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Reimplementaci?n del m?todo papa poder modificar los BoundBox
|
119 |
* de cada uno de los FFrames que contiene dentro este FFrameGroup.
|
120 |
*
|
121 |
* @param r Rect?ngulo.
|
122 |
*/
|
123 |
public void setBoundBox(Rectangle2D.Double r) { |
124 |
getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
125 |
if (rg==null){ |
126 |
rg=new Rectangle2D.Double(r.x,r.y,r.width,r.height); |
127 |
} |
128 |
Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width, |
129 |
rg.height); |
130 |
|
131 |
double dx = r.x - raux1.x;
|
132 |
double dy = r.y - raux1.y;
|
133 |
double dw = r.width / raux1.width;
|
134 |
double dh = r.height / raux1.height;
|
135 |
|
136 |
for (int i = 0; i < getFFrames().size(); i++) { |
137 |
IFFrame fframe = (IFFrame) getFFrames().get(i); |
138 |
Rectangle2D.Double raux = new Rectangle2D.Double(); |
139 |
raux.setRect(fframe.getBoundBox()); |
140 |
|
141 |
AffineTransform escalado = new AffineTransform(); |
142 |
double scalex = r.width / raux1.width;
|
143 |
double scaley = r.height / raux1.height;
|
144 |
|
145 |
escalado.setToScale(dw, dh); |
146 |
escalado.translate(dx - r.x, dy - r.y); |
147 |
|
148 |
Point2D.Double pd = new Point2D.Double(); |
149 |
escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
150 |
|
151 |
raux.x = pd.x + r.x; |
152 |
raux.y = pd.y + r.y; |
153 |
raux.width = raux.width * dw; |
154 |
raux.height = raux.height * dh; |
155 |
|
156 |
fframe.setBoundBox(raux); |
157 |
} |
158 |
|
159 |
rg.setRect(r); |
160 |
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
165 |
*/
|
166 |
public XMLEntity getXMLEntity() {
|
167 |
XMLEntity xml = super.getXMLEntity();
|
168 |
xml.putProperty("type", Layout.RECTANGLEGROUP);
|
169 |
|
170 |
for (int i = 0; i < getFFrames().size(); i++) { |
171 |
xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity()); |
172 |
} |
173 |
|
174 |
return xml;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
179 |
*
|
180 |
* @param xml XMLEntity
|
181 |
*
|
182 |
* @return Objeto de esta clase.
|
183 |
*/
|
184 |
public static FFrameGroup createFFrameGroup(XMLEntity xml, Project p) { |
185 |
FFrameGroup fframe = new FFrameGroup();
|
186 |
|
187 |
if (xml.getIntProperty("m_Selected") != 0) { |
188 |
fframe.setSelected(true);
|
189 |
} else {
|
190 |
fframe.setSelected(false);
|
191 |
} |
192 |
|
193 |
IFFrame fframechild = null;
|
194 |
|
195 |
for (int i = 0; i < xml.getNumChild(); i++) { |
196 |
|
197 |
switch (xml.getChild(i).getIntProperty("type")) { |
198 |
case (Layout.RECTANGLEVIEW):
|
199 |
fframechild = FFrameView.createFFrameView(xml.getChild(i), p); |
200 |
|
201 |
break;
|
202 |
|
203 |
case (Layout.RECTANGLETEXT):
|
204 |
fframechild = FFrameText.createFFrameText(xml.getChild(i)); |
205 |
|
206 |
break;
|
207 |
|
208 |
case (Layout.RECTANGLESCALEBAR):
|
209 |
fframechild = FFrameScaleBar.createFFrameScaleBar(xml.getChild(i), p); |
210 |
|
211 |
break;
|
212 |
|
213 |
case (Layout.RECTANGLEPICTURE):
|
214 |
fframechild = FFramePicture.createFFramePicture(xml.getChild(i)); |
215 |
|
216 |
break;
|
217 |
|
218 |
case (Layout.RECTANGLELEGEND):
|
219 |
fframechild = FFrameLegend.createFFrameLegend(xml.getChild(i), p); |
220 |
|
221 |
break;
|
222 |
|
223 |
case (Layout.GRAPHICS):
|
224 |
fframechild = FFrameGraphics.createFFrameGraphics(xml.getChild(i)); |
225 |
|
226 |
break;
|
227 |
|
228 |
case (Layout.RECTANGLEGROUP):
|
229 |
fframechild = FFrameGroup.createFFrameGroup(xml.getChild(i), p); |
230 |
|
231 |
break;
|
232 |
|
233 |
case (Layout.RECTANGLESYMBOL):
|
234 |
fframechild = FFrameSymbol.createFFrameSymbol(xml.getChild(i)); |
235 |
|
236 |
break;
|
237 |
} |
238 |
fframechild.setName(xml.getChild(i).getStringProperty("m_name"));
|
239 |
fframechild.setBoundBox(new Rectangle2D.Double(xml.getChild(i).getDoubleProperty("x"), |
240 |
xml.getChild(i).getDoubleProperty("y"), xml.getChild(i).getDoubleProperty("w"), |
241 |
xml.getChild(i).getDoubleProperty("h")));
|
242 |
fframe.addFFrame(fframechild); |
243 |
} |
244 |
|
245 |
return fframe;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
250 |
*/
|
251 |
public void updateNum() { |
252 |
} |
253 |
|
254 |
/**
|
255 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
|
256 |
*/
|
257 |
public int getNum() { |
258 |
return 0; |
259 |
} |
260 |
} |