svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / FFrameGroup.java @ 34228
History | View | Annotate | Download (10.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 org.gvsig.app.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 |
import java.util.List; |
54 |
|
55 |
import org.gvsig.andami.PluginServices; |
56 |
import org.gvsig.app.project.Project; |
57 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
58 |
import org.gvsig.compat.print.PrintAttributes; |
59 |
import org.gvsig.fmap.geom.Geometry; |
60 |
import org.gvsig.tools.ToolsLocator; |
61 |
import org.gvsig.tools.dynobject.DynStruct; |
62 |
import org.gvsig.tools.persistence.PersistenceManager; |
63 |
import org.gvsig.tools.persistence.PersistentState; |
64 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
65 |
|
66 |
|
67 |
|
68 |
/**
|
69 |
* FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
|
70 |
* incluso de si mismo.
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class FFrameGroup extends AbstractFFrameViewDependence implements IFFrameUseProject, IFFrameViewDependence{ |
75 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameGroup"; |
76 |
|
77 |
private static final String FFRAMES_FIELD = "fframes"; |
78 |
|
79 |
private List<IFFrame> m_fframes = new ArrayList<IFFrame>(); |
80 |
private Rectangle2D.Double rg = null; |
81 |
private AffineTransform m_at; |
82 |
private Project project;
|
83 |
|
84 |
/**
|
85 |
* Crea un nuevo FFrameGroup.
|
86 |
*/
|
87 |
public FFrameGroup() {
|
88 |
// do nothing
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
|
93 |
*
|
94 |
* @param fframe FFrame a a?adir.
|
95 |
*/
|
96 |
public void addFFrame(IFFrame fframe) { |
97 |
m_fframes.add(fframe); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Devuelve una ArrayList que contiene todos los FFrames que forman parte
|
102 |
* del grupo.
|
103 |
*
|
104 |
* @return Arraylist con los fframes.
|
105 |
*/
|
106 |
public IFFrame[] getFFrames() { |
107 |
return m_fframes.toArray(new IFFrame[0]); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
|
112 |
*
|
113 |
* @param at Matriz de transformaci?n
|
114 |
*
|
115 |
* @return Rect?ngulo.
|
116 |
*/
|
117 |
public Rectangle2D.Double getRectangle(AffineTransform at) { |
118 |
boolean first = true; |
119 |
Rectangle2D.Double rec = new Rectangle2D.Double(); |
120 |
IFFrame[] fframes=getFFrames();
|
121 |
for (int i = 0; i < fframes.length; i++) { |
122 |
Rectangle2D.Double rs = fframes[i].getBoundingBox(at);
|
123 |
|
124 |
if (first) {
|
125 |
rec.setRect(rs); |
126 |
first = false;
|
127 |
} |
128 |
|
129 |
rec.add(rs); |
130 |
} |
131 |
|
132 |
rg = new Rectangle2D.Double(); |
133 |
rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at)); |
134 |
|
135 |
return rec;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
140 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
141 |
* de dibujar.
|
142 |
*
|
143 |
* @param g Graphics
|
144 |
* @param at Transformada afin.
|
145 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
146 |
* @param imgBase Imagen utilizada para acelerar el dibujado.
|
147 |
*/
|
148 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
149 |
BufferedImage imgBase) {
|
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 |
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 |
* @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
224 |
*/
|
225 |
public String getNameFFrame() { |
226 |
return PluginServices.getText(this, "grupo")+ num; |
227 |
} |
228 |
|
229 |
public String getName() { |
230 |
return PERSISTENCE_DEFINITION_NAME;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
235 |
* java.awt.geom.AffineTransform)
|
236 |
*/
|
237 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
238 |
PrintAttributes printingProperties) { |
239 |
Rectangle2D.Double r = getBoundingBox(at);
|
240 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
241 |
r.y + (r.height / 2));
|
242 |
IFFrame[] fframes=m_fframes.toArray(new IFFrame[0]); |
243 |
for (int i = 0; i < fframes.length; i++) { |
244 |
// fframes[i].setPrintingProperties(printingProperties);
|
245 |
fframes[i].print(g, at, geom, printingProperties); |
246 |
// fframes[i].setPrintingProperties(null);
|
247 |
} |
248 |
|
249 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
250 |
r.y + (r.height / 2));
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Inserta una referencia al proyecto nesecario.
|
255 |
*
|
256 |
* @param project DOCUMENT ME!
|
257 |
*/
|
258 |
public void setProject(Project project) { |
259 |
this.project = project;
|
260 |
} |
261 |
|
262 |
public void initialize() { |
263 |
// TODO Auto-generated method stub
|
264 |
|
265 |
} |
266 |
|
267 |
public void clearFFrames(){ |
268 |
m_fframes.clear(); |
269 |
} |
270 |
|
271 |
public IFFrame removeFFrame(int i){ |
272 |
return m_fframes.remove(i);
|
273 |
} |
274 |
|
275 |
public void removeFFrame(IFFrame fframe){ |
276 |
m_fframes.remove(fframe); |
277 |
} |
278 |
|
279 |
public IFFrame clone() throws CloneNotSupportedException { |
280 |
FFrameGroup frame = (FFrameGroup)super.clone();
|
281 |
frame.setSelected(this.getSelected() != IFFrame.NOSELECT);
|
282 |
frame.m_fframes = new ArrayList<IFFrame>(); |
283 |
|
284 |
for(int i=0 ; i<m_fframes.size() ; i++) { |
285 |
frame.addFFrame((IFFrame)m_fframes.get(i).clone()); |
286 |
} |
287 |
return frame;
|
288 |
} |
289 |
|
290 |
public void setFFrameDependence(IFFrame f) { |
291 |
IFFrame[] frames=getFFrames();
|
292 |
for (int i =0;i<frames.length;i++){ |
293 |
if (frames[i] instanceof IFFrameViewDependence){ |
294 |
((IFFrameViewDependence)frames[i]).setFFrameDependence(f); |
295 |
} |
296 |
} |
297 |
} |
298 |
|
299 |
public IFFrame[] getFFrameDependence() { |
300 |
IFFrame[] frames=getFFrames();
|
301 |
ArrayList<IFFrame> dependences=new ArrayList<IFFrame>(); |
302 |
for (int i =0;i<frames.length;i++){ |
303 |
if (frames[i] instanceof IFFrameViewDependence){ |
304 |
IFFrame[] framesAux=((IFFrameViewDependence)frames[i]).getFFrameDependence();
|
305 |
for (int j =0;j<framesAux.length;j++){ |
306 |
dependences.add(framesAux[i]); |
307 |
} |
308 |
} |
309 |
} |
310 |
return dependences.toArray(new IFFrame[0]); |
311 |
} |
312 |
|
313 |
public void refreshDependence(IFFrame fant, IFFrame fnew) { |
314 |
IFFrame[] frames=getFFrames();
|
315 |
for (int i =0;i<frames.length;i++){ |
316 |
|
317 |
if (fnew instanceof FFrameGroup){ |
318 |
IFFrame[] framesGroupNew=((FFrameGroup)fnew).getFFrames();
|
319 |
for (int j=0;j<framesGroupNew.length;j++){ |
320 |
if (fant instanceof FFrameGroup){ |
321 |
IFFrame[] framesGroupAnt=((FFrameGroup)fant).getFFrames();
|
322 |
for (int k=0;k<framesGroupAnt.length;k++){ |
323 |
if (framesGroupAnt[k] instanceof IFFrameViewDependence){ |
324 |
refreshDependence(framesGroupAnt[k],framesGroupNew[j]); |
325 |
} |
326 |
} |
327 |
} |
328 |
} |
329 |
}else if (frames[i] instanceof IFFrameViewDependence){ |
330 |
((IFFrameViewDependence)frames[i]).refreshDependence(fant,fnew); |
331 |
} |
332 |
} |
333 |
} |
334 |
|
335 |
public static void registerPersistent() { |
336 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
337 |
if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
338 |
DynStruct definition = manager.addDefinition( |
339 |
FFrameGroup.class, |
340 |
PERSISTENCE_DEFINITION_NAME, |
341 |
"FFrameGroup persistence definition",
|
342 |
null,
|
343 |
null
|
344 |
); |
345 |
|
346 |
definition.extend(manager.getDefinition(AbstractFFrameViewDependence.PERSISTENCE_DEFINITION_NAME)); |
347 |
|
348 |
definition.addDynFieldList(FFRAMES_FIELD).setClassOfItems(IFFrame.class).setMandatory(true);
|
349 |
} |
350 |
} |
351 |
|
352 |
@Override
|
353 |
public void loadFromState(PersistentState state) |
354 |
throws PersistenceException {
|
355 |
super.loadFromState(state);
|
356 |
m_fframes = (List<IFFrame>)state.getList(FFRAMES_FIELD);
|
357 |
} |
358 |
|
359 |
@Override
|
360 |
public void saveToState(PersistentState state) throws PersistenceException { |
361 |
super.saveToState(state);
|
362 |
state.set(FFRAMES_FIELD, m_fframes); |
363 |
} |
364 |
} |