svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 1822
History | View | Annotate | Download (7.74 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 | 686 | vcaballero | 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 | 596 | fernando | import com.iver.andami.PluginServices; |
55 | import com.iver.andami.messages.NotificationManager; |
||
56 | 654 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
57 | 596 | fernando | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
58 | import com.iver.cit.gvsig.gui.layout.Layout; |
||
59 | import com.iver.utiles.XMLEntity; |
||
60 | 312 | fernando | |
61 | 596 | fernando | |
62 | 312 | fernando | /**
|
63 | 398 | vcaballero | * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
64 | 312 | fernando | * incluso de si mismo.
|
65 | *
|
||
66 | * @author Vicente Caballero Navarro
|
||
67 | */
|
||
68 | public class FFrameGroup extends FFrame { |
||
69 | 649 | vcaballero | private ArrayList m_fframes = new ArrayList(); |
70 | private Rectangle2D.Double rg = null; |
||
71 | private AffineTransform m_at; |
||
72 | private Rectangle2D.Double ra = null; |
||
73 | 312 | fernando | |
74 | 649 | vcaballero | /**
|
75 | * Crea un nuevo FFrameGroup.
|
||
76 | */
|
||
77 | public FFrameGroup() {
|
||
78 | } |
||
79 | 312 | fernando | |
80 | 649 | vcaballero | /**
|
81 | * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
|
||
82 | *
|
||
83 | * @param fframe FFrame a a?adir.
|
||
84 | */
|
||
85 | public void addFFrame(IFFrame fframe) { |
||
86 | m_fframes.add(fframe); |
||
87 | } |
||
88 | 312 | fernando | |
89 | 649 | vcaballero | /**
|
90 | * Devuelve una ArrayList que contiene todos los FFrames que forman parte
|
||
91 | * del grupo.
|
||
92 | *
|
||
93 | * @return Arraylist con los fframes.
|
||
94 | */
|
||
95 | public ArrayList getFFrames() { |
||
96 | return m_fframes;
|
||
97 | } |
||
98 | 312 | fernando | |
99 | 649 | vcaballero | /**
|
100 | * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
|
||
101 | *
|
||
102 | * @param at Matriz de transformaci?n
|
||
103 | *
|
||
104 | * @return Rect?ngulo.
|
||
105 | */
|
||
106 | public Rectangle2D.Double getRectangle(AffineTransform at) { |
||
107 | double minX = 0; |
||
108 | double minY = 0; |
||
109 | double maxX = 0; |
||
110 | double maxY = 0; |
||
111 | boolean first = true; |
||
112 | Rectangle2D.Double rec = new Rectangle2D.Double(); |
||
113 | 312 | fernando | |
114 | 649 | vcaballero | for (int i = 0; i < m_fframes.size(); i++) { |
115 | Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
|
||
116 | 312 | fernando | |
117 | 649 | vcaballero | if (first) {
|
118 | rec.setRect(rs); |
||
119 | first = false;
|
||
120 | } |
||
121 | 312 | fernando | |
122 | 649 | vcaballero | rec.add(rs); |
123 | } |
||
124 | 312 | fernando | |
125 | 649 | vcaballero | rg = new Rectangle2D.Double(); |
126 | rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
||
127 | 312 | fernando | |
128 | 649 | vcaballero | return rec;
|
129 | } |
||
130 | 312 | fernando | |
131 | 649 | vcaballero | /**
|
132 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
||
133 | * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
||
134 | * de dibujar.
|
||
135 | *
|
||
136 | * @param g Graphics
|
||
137 | * @param at Transformada afin.
|
||
138 | * @param rv rect?ngulo sobre el que hacer un clip.
|
||
139 | 1073 | vcaballero | * @param imgBase Imagen utilizada para acelerar el dibujado.
|
140 | 649 | vcaballero | *
|
141 | 1822 | vcaballero | * @throws DriverException
|
142 | 649 | vcaballero | */
|
143 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
144 | 654 | fernando | BufferedImage imgBase) throws DriverException { |
145 | 649 | vcaballero | Rectangle2D.Double r = getBoundingBox(at);
|
146 | m_at = at; |
||
147 | 312 | fernando | |
148 | 649 | vcaballero | for (int i = 0; i < m_fframes.size(); i++) { |
149 | ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase); |
||
150 | } |
||
151 | } |
||
152 | 398 | vcaballero | |
153 | 649 | vcaballero | /**
|
154 | * Rellena la transformada que se esta utilizando en el Layout.
|
||
155 | *
|
||
156 | * @param at Matriz de transformaci?n.
|
||
157 | */
|
||
158 | public void setAt(AffineTransform at) { |
||
159 | m_at = at; |
||
160 | } |
||
161 | 312 | fernando | |
162 | 649 | vcaballero | /**
|
163 | 1822 | vcaballero | * Reimplementaci?n del m?todo para poder modificar los BoundBox de cada
|
164 | 649 | vcaballero | * uno de los FFrames que contiene dentro este FFrameGroup.
|
165 | *
|
||
166 | * @param r Rect?ngulo.
|
||
167 | */
|
||
168 | public void setBoundBox(Rectangle2D.Double r) { |
||
169 | getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
||
170 | 398 | vcaballero | |
171 | 649 | vcaballero | Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width, |
172 | rg.height); |
||
173 | double dx = r.x - raux1.x;
|
||
174 | double dy = r.y - raux1.y;
|
||
175 | double dw = r.width / raux1.width;
|
||
176 | double dh = r.height / raux1.height;
|
||
177 | 312 | fernando | |
178 | 649 | vcaballero | for (int i = 0; i < getFFrames().size(); i++) { |
179 | IFFrame fframe = (IFFrame) getFFrames().get(i); |
||
180 | Rectangle2D.Double raux = new Rectangle2D.Double(); |
||
181 | raux.setRect(fframe.getBoundBox()); |
||
182 | 312 | fernando | |
183 | 649 | vcaballero | AffineTransform escalado = new AffineTransform(); |
184 | double scalex = r.width / raux1.width;
|
||
185 | double scaley = r.height / raux1.height;
|
||
186 | 312 | fernando | |
187 | 649 | vcaballero | escalado.setToScale(dw, dh); |
188 | escalado.translate(dx - r.x, dy - r.y); |
||
189 | 312 | fernando | |
190 | 649 | vcaballero | Point2D.Double pd = new Point2D.Double(); |
191 | escalado.transform(new Point2D.Double(raux.x, raux.y), pd); |
||
192 | 312 | fernando | |
193 | 649 | vcaballero | raux.x = pd.x + r.x; |
194 | raux.y = pd.y + r.y; |
||
195 | raux.width = raux.width * dw; |
||
196 | raux.height = raux.height * dh; |
||
197 | 312 | fernando | |
198 | 649 | vcaballero | fframe.setBoundBox(raux); |
199 | } |
||
200 | 398 | vcaballero | |
201 | 649 | vcaballero | rg.setRect(r); |
202 | } |
||
203 | 312 | fernando | |
204 | 649 | vcaballero | /**
|
205 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
||
206 | */
|
||
207 | public XMLEntity getXMLEntity() {
|
||
208 | XMLEntity xml = new XMLEntity();
|
||
209 | 1822 | vcaballero | xml.putProperty("className", this.getClass().getName()); |
210 | 649 | vcaballero | xml.putProperty("m_name", m_name);
|
211 | xml.putProperty("x", getBoundBox().x);
|
||
212 | xml.putProperty("y", getBoundBox().y);
|
||
213 | xml.putProperty("w", getBoundBox().width);
|
||
214 | xml.putProperty("h", getBoundBox().height);
|
||
215 | xml.putProperty("m_Selected", m_Selected);
|
||
216 | xml.putProperty("type", Layout.RECTANGLEGROUP);
|
||
217 | xml.putProperty("tag", getTag());
|
||
218 | 312 | fernando | |
219 | 649 | vcaballero | for (int i = 0; i < getFFrames().size(); i++) { |
220 | xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity()); |
||
221 | } |
||
222 | 312 | fernando | |
223 | 649 | vcaballero | return xml;
|
224 | } |
||
225 | 1822 | vcaballero | |
226 | 649 | vcaballero | /**
|
227 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
228 | */
|
||
229 | 686 | vcaballero | public void setXMLEntity(XMLEntity xml, Layout l) { |
230 | 649 | vcaballero | if (xml.getIntProperty("m_Selected") != 0) { |
231 | this.setSelected(true); |
||
232 | } else {
|
||
233 | this.setSelected(false); |
||
234 | } |
||
235 | 312 | fernando | |
236 | 649 | vcaballero | IFFrame fframechild = null;
|
237 | 312 | fernando | |
238 | 649 | vcaballero | for (int i = 0; i < xml.getNumChild(); i++) { |
239 | try {
|
||
240 | 1272 | vcaballero | Class clase = Class.forName(xml.getStringProperty("className")); |
241 | 649 | vcaballero | fframechild = (IFFrame) clase.newInstance(); |
242 | } catch (Exception e) { |
||
243 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
||
244 | e); |
||
245 | } |
||
246 | 312 | fernando | |
247 | 686 | vcaballero | fframechild.setXMLEntity(xml.getChild(i), l); |
248 | 649 | vcaballero | this.addFFrame(fframechild);
|
249 | } |
||
250 | } |
||
251 | |||
252 | /**
|
||
253 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
||
254 | */
|
||
255 | public String getNameFFrame() { |
||
256 | return PluginServices.getText(this, "grupo"); |
||
257 | } |
||
258 | |||
259 | /**
|
||
260 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
261 | * java.awt.geom.AffineTransform)
|
||
262 | */
|
||
263 | public void print(Graphics2D g, AffineTransform at) |
||
264 | 654 | fernando | throws DriverException {
|
265 | 649 | vcaballero | for (int i = 0; i < m_fframes.size(); i++) { |
266 | ((IFFrame) m_fframes.get(i)).print(g, at); |
||
267 | } |
||
268 | } |
||
269 | 1822 | vcaballero | |
270 | /**
|
||
271 | * Clonado de este FFrame.
|
||
272 | *
|
||
273 | * @param l Referencia al Layout.
|
||
274 | *
|
||
275 | * @return FFrame clonado.
|
||
276 | */
|
||
277 | public IFFrame cloneFFrame(Layout l) {
|
||
278 | IFFrame frame=null;
|
||
279 | try {
|
||
280 | //TODO esto esta por implementar, y hay varias opciones o se implementa el m?todo getXMLEntity y setXMLEntity en las fframes que estan agrupadas o se implementa un clone adecuado.
|
||
281 | frame = (IFFrame)this.clone();//new IFFrame[m_fframes.size()]; |
||
282 | /*for (int i = 0; i < m_fframes.size(); i++) {
|
||
283 | frames[i] = ((IFFrame) m_fframes.get(i)).cloneFFrame(l);
|
||
284 | }
|
||
285 | return createFFrame(this.getXMLEntity(), l,
|
||
286 | ((ProjectMap) l.getViewModel()).getProject());
|
||
287 | */
|
||
288 | } catch (CloneNotSupportedException e) { |
||
289 | e.printStackTrace(); |
||
290 | } |
||
291 | return frame;
|
||
292 | } |
||
293 | 312 | fernando | } |