svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 370
History | View | Annotate | Download (16 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-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 com.iver.cit.gvsig.ProjectExtension; |
10 |
import com.iver.cit.gvsig.fmap.FMap; |
11 |
import com.iver.cit.gvsig.fmap.ViewPort; |
12 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
13 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
14 |
import com.iver.cit.gvsig.gui.layout.Layout; |
15 |
import com.iver.cit.gvsig.project.Project; |
16 |
import com.iver.cit.gvsig.project.ProjectView; |
17 |
import com.iver.cit.gvsig.project.castor.View; |
18 |
|
19 |
import com.iver.mdiApp.App; |
20 |
|
21 |
import com.iver.utiles.XMLEntity; |
22 |
|
23 |
import org.apache.log4j.Logger; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.Rectangle; |
28 |
import java.awt.geom.AffineTransform; |
29 |
import java.awt.geom.Point2D; |
30 |
import java.awt.geom.Rectangle2D; |
31 |
import java.awt.image.BufferedImage; |
32 |
|
33 |
import java.util.ArrayList; |
34 |
|
35 |
|
36 |
/**
|
37 |
* FFrame para introducir una vista en el Layout.
|
38 |
*
|
39 |
* @author Vicente Caballero Navarro
|
40 |
*/
|
41 |
public class FFrameView extends FFrame { |
42 |
private static Logger logger = Logger.getLogger(FFrameView.class.getName()); |
43 |
private static final int AUTOMATICO = 0; |
44 |
private static final int CONSTANTE = 1; |
45 |
private static final int MANUAL = 2; |
46 |
private static final int PRESENTACION = 0; |
47 |
private static final int BORRADOR = 1; |
48 |
private int m_Mode; |
49 |
private int m_typeScale = AUTOMATICO; |
50 |
private int m_extension = 0; |
51 |
private int m_quality = PRESENTACION; |
52 |
private int m_viewing = 0; |
53 |
private boolean m_bLinked = true; |
54 |
private View view = null; |
55 |
private FMap m_fmap = null; |
56 |
private double m_Scale = 0; |
57 |
private int m_mapUnits = 1; //Metros. |
58 |
private int num = 0; |
59 |
private BufferedImage m_image = null; |
60 |
private AffineTransform at = null; |
61 |
|
62 |
/**
|
63 |
* Creates a new FFrameView object.
|
64 |
*/
|
65 |
public FFrameView() {
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* DOCUMENT ME!
|
70 |
*
|
71 |
* @param n DOCUMENT ME!
|
72 |
*/
|
73 |
public void setNum(int n) { |
74 |
num = n; |
75 |
} |
76 |
|
77 |
/**
|
78 |
* DOCUMENT ME!
|
79 |
*
|
80 |
* @return DOCUMENT ME!
|
81 |
*/
|
82 |
public String toString() { |
83 |
if (getView() == null) { |
84 |
return "FFrameView " + num + ": " + "Vacio"; |
85 |
} |
86 |
|
87 |
return "FFrameView " + num + ": " + getView().getName(); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Rellena la escala de la vista que contiene el fframe.
|
92 |
*
|
93 |
* @param d escala de la vista.
|
94 |
*/
|
95 |
public void setScale(double d) { |
96 |
m_Scale = d; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* DOCUMENT ME!
|
101 |
*
|
102 |
* @param r DOCUMENT ME!
|
103 |
*/
|
104 |
public void setNewExtent(Rectangle2D.Double r) { |
105 |
getFMap().getViewPort().setExtent(r); |
106 |
m_Scale = FLayoutUtilities.getScaleView(getFMap(), getBoundBox().height); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
|
111 |
* escala fija.
|
112 |
*
|
113 |
* @return FMap.
|
114 |
*/
|
115 |
public FMap getFMap() {
|
116 |
/* if (!m_bLinked) {
|
117 |
return m_fmap;
|
118 |
}
|
119 |
if (getTypeScale() == AUTOMATICO) {
|
120 |
return m_fmap;
|
121 |
} else if (getTypeScale() == CONSTANTE) {
|
122 |
return m_fmap;
|
123 |
} else if (getTypeScale() == MANUAL) {
|
124 |
//Crear una copia del objeto map.
|
125 |
FMap auxfmap = (FMap) m_fmap.clone();
|
126 |
auxfmap.setExtent(getNewExtent(getScale()));
|
127 |
return auxfmap;
|
128 |
//m_fmap.setExtent(getNewExtent(getScale()));
|
129 |
//return m_fmap;
|
130 |
}
|
131 |
return null;
|
132 |
*/
|
133 |
return m_fmap;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Rellena la calidad que se quiere aplicar.
|
138 |
*
|
139 |
* @param q entero que representa la calidad a aplicar.
|
140 |
*/
|
141 |
public void setQuality(int q) { |
142 |
m_quality = q; |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Devuelve un entero que representa la calidad que est? seleccionada.
|
147 |
*
|
148 |
* @return tipo de calidad selccionada.
|
149 |
*/
|
150 |
public int getQuality() { |
151 |
return m_quality;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
156 |
*
|
157 |
* @return forma que se actualiza la vista.
|
158 |
*/
|
159 |
public int getViewing() { |
160 |
return m_viewing;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Rellena la forma de actualizar la vista.
|
165 |
*
|
166 |
* @param v entero que representa la forma de actualizar la vista.
|
167 |
*/
|
168 |
public void setViewing(int v) { |
169 |
m_viewing = v; |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Rellena el FMap creando una clonaci?n o no, seg?n si esta seleccionado
|
174 |
* el checkbox de que este unido a la vista original.
|
175 |
*
|
176 |
* @param v FMap a clonar o referenciar.
|
177 |
*/
|
178 |
|
179 |
/* public void setFMap(FMap map) {
|
180 |
if (!m_bLinked) {
|
181 |
m_fmap = (FMap) map.clone();
|
182 |
} else {
|
183 |
m_fmap = map;
|
184 |
}
|
185 |
}
|
186 |
*/
|
187 |
public void setView(View v) { |
188 |
/* if (!m_bLinked) {
|
189 |
m_fmap = (FMap) v.getMapContext().cloneFMap();
|
190 |
} else {
|
191 |
if (getTypeScale() == MANUAL) {
|
192 |
//Crear una copia del objeto map.
|
193 |
FMap auxfmap = (FMap) v.getMapContext().cloneFMap();
|
194 |
auxfmap.getViewPort().setExtent(getNewExtent(getScale()));
|
195 |
m_fmap = auxfmap;
|
196 |
} else {
|
197 |
m_fmap = v.getMapContext();
|
198 |
}
|
199 |
}
|
200 |
*/
|
201 |
m_fmap = v.getMapContext(); |
202 |
ViewPort vp=new ViewPort();
|
203 |
vp.setExtent(v.getMapContext().getViewPort().getExtent()); |
204 |
m_fmap = m_fmap.createNewFMap(vp); |
205 |
|
206 |
view = v; |
207 |
} |
208 |
|
209 |
/**
|
210 |
* DOCUMENT ME!
|
211 |
*
|
212 |
* @return DOCUMENT ME!
|
213 |
*/
|
214 |
public View getView() { |
215 |
return view;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* Devuelve un Rect?ngulo que representa el extent de la vista que se
|
220 |
* requiere a partir de una escala.
|
221 |
*
|
222 |
* @param scale DOCUMENT ME!
|
223 |
*
|
224 |
* @return Rect?ngulo.
|
225 |
*/
|
226 |
private Rectangle2D.Double getNewExtent(long scale) { |
227 |
double hview = getBoundBox().getHeight();
|
228 |
double wview = getBoundBox().getWidth();
|
229 |
double hextent = (scale * hview) / 100.0; |
230 |
double wextent = (scale * wview) / 100.0; |
231 |
double dif = hextent / m_fmap.getViewPort().getExtent().getHeight();
|
232 |
double newx = m_fmap.getViewPort().getExtent().getCenterX() -
|
233 |
((m_fmap.getViewPort().getExtent().getWidth() * dif) / 2.0);
|
234 |
double newy = m_fmap.getViewPort().getExtent().getCenterY() -
|
235 |
((m_fmap.getViewPort().getExtent().getHeight() * dif) / 2.0);
|
236 |
|
237 |
return new Rectangle2D.Double(newx, newy, wextent, hextent); |
238 |
} |
239 |
|
240 |
/**
|
241 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
242 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
243 |
* de dibujar.
|
244 |
*
|
245 |
* @param g Graphics
|
246 |
* @param at Transformada afin.
|
247 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
248 |
* @param imgBase
|
249 |
*
|
250 |
* @throws DriverIOException
|
251 |
*/
|
252 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
253 |
BufferedImage imgBase) throws DriverIOException { |
254 |
Rectangle2D.Double r = getBoundingBox(at);
|
255 |
|
256 |
if (intersects(rv, r)) {
|
257 |
if (getFMap() == null) { |
258 |
drawEmpty(g); |
259 |
} else {
|
260 |
if (rv != null) { |
261 |
// Dibujamos en pantalla
|
262 |
Rectangle rclip = g.getClipBounds();
|
263 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), |
264 |
(int) r.getWidth(), (int) r.getHeight()); |
265 |
|
266 |
if (getQuality() == PRESENTACION) {
|
267 |
/* this.getFMap().setTransparent(true);
|
268 |
this.getFMap().drawView((Graphics2D) g,
|
269 |
new Rectangle((int) (r.x), (int) (r.y),
|
270 |
(int) (r.width), (int) (r.height)),
|
271 |
(Rectangle) rv, false, imgBase);
|
272 |
*/
|
273 |
if (rv.intersects(r)) {
|
274 |
this.getFMap().getViewPort().setOffset(new Point2D.Double( |
275 |
r.x, r.y)); |
276 |
this.getFMap().getViewPort().setImageSize(new Dimension( |
277 |
(int) r.width, (int) r.height)); |
278 |
this.getFMap().draw(imgBase, g);
|
279 |
} |
280 |
|
281 |
if (rclip != null) { |
282 |
g.setClip(rclip.x, rclip.y, rclip.width, |
283 |
rclip.height); |
284 |
} |
285 |
} else {
|
286 |
drawDraft(g); |
287 |
} |
288 |
} else {
|
289 |
// Dibujamos en impresora
|
290 |
Rectangle rclip = g.getClipBounds();
|
291 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), |
292 |
(int) r.getWidth(), (int) r.getHeight()); |
293 |
|
294 |
/* this.getFMap().drawView((Graphics2D) g,
|
295 |
new Rectangle((int) (r.x), (int) (r.y),
|
296 |
(int) (r.width), (int) (r.height)), (Rectangle) rv,
|
297 |
true, imgBase);
|
298 |
*/
|
299 |
this.getFMap().getViewPort().setOffset(new Point2D.Double( |
300 |
r.x, r.y)); |
301 |
this.getFMap().getViewPort().setImageSize(new Dimension( |
302 |
(int) r.width, (int) r.height)); |
303 |
this.getFMap().print(g);
|
304 |
g.setClip(rclip.x, rclip.y, rclip.width, rclip.height); |
305 |
} |
306 |
} |
307 |
} |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Rellena la unidad de medida en la que est? la vista.
|
312 |
*
|
313 |
* @param i entero que representa la unidad de medida de la vista.
|
314 |
*/
|
315 |
public void setMapUnits(int i) { |
316 |
m_mapUnits = i; |
317 |
} |
318 |
|
319 |
/**
|
320 |
* Obtiene la unidad de medida en la que est? la vista.
|
321 |
*
|
322 |
* @return DOCUMENT ME!
|
323 |
*/
|
324 |
public int getMapUnits() { |
325 |
return m_mapUnits;
|
326 |
} |
327 |
|
328 |
/**
|
329 |
* Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
|
330 |
* a?adida la vista.
|
331 |
*
|
332 |
* @return escala.
|
333 |
*/
|
334 |
public long getScale() { |
335 |
/*if (m_bLinked){
|
336 |
return getScaleView1(METROS);
|
337 |
}
|
338 |
*/
|
339 |
if (getTypeScale() == AUTOMATICO) {
|
340 |
return FLayoutUtilities.getScaleView(getFMap(), getBoundBox().height);
|
341 |
} else if (getTypeScale() == CONSTANTE) { |
342 |
} else if (getTypeScale() == MANUAL) { |
343 |
return (long) m_Scale; |
344 |
} |
345 |
|
346 |
return (long) m_Scale; |
347 |
} |
348 |
|
349 |
/**
|
350 |
* Seleccionar si la vista esta relacionada o no con la original.
|
351 |
*
|
352 |
* @param b true si est? ligada y false si no lo est?.
|
353 |
*/
|
354 |
public void setLinked(boolean b) { |
355 |
m_bLinked = b; |
356 |
} |
357 |
|
358 |
/**
|
359 |
* DOCUMENT ME!
|
360 |
*
|
361 |
* @return DOCUMENT ME!
|
362 |
*/
|
363 |
public boolean getLinked() { |
364 |
return m_bLinked;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
|
369 |
* la vista.
|
370 |
*
|
371 |
* @return entero que representa la opci?n elegida.
|
372 |
*/
|
373 |
public int getExtension() { |
374 |
return m_extension;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
|
379 |
* MANUAL.
|
380 |
*
|
381 |
* @return entero que representa el tipo seleccionado.
|
382 |
*/
|
383 |
public int getTypeScale() { |
384 |
return m_typeScale;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
|
389 |
*
|
390 |
* @param i entero que representa la opci?n elegida.
|
391 |
*/
|
392 |
public void setExtension(int i) { |
393 |
m_extension = i; |
394 |
} |
395 |
|
396 |
/**
|
397 |
* Rellenar el tipo de escala que se desea.
|
398 |
*
|
399 |
* @param i entero que representa el tipo de escala.
|
400 |
*/
|
401 |
public void setTypeScale(int i) { |
402 |
m_typeScale = i; |
403 |
} |
404 |
|
405 |
/**
|
406 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
407 |
*/
|
408 |
public XMLEntity getXMLEntity() {
|
409 |
XMLEntity xml = super.getXMLEntity();
|
410 |
xml.putProperty("type", Layout.RECTANGLEVIEW);
|
411 |
xml.putProperty("m_Mode", m_Mode);
|
412 |
xml.putProperty("m_typeScale", m_typeScale);
|
413 |
xml.putProperty("m_extension", m_extension);
|
414 |
xml.putProperty("m_quality", m_quality);
|
415 |
xml.putProperty("m_viewing", m_viewing);
|
416 |
xml.putProperty("m_bLinked", m_bLinked);
|
417 |
xml.putProperty("m_mapUnits", m_mapUnits);
|
418 |
xml.putProperty("m_Scale", m_Scale);
|
419 |
|
420 |
xml.putProperty("extentX", getFMap().getViewPort().getExtent().getX());
|
421 |
xml.putProperty("extentY", getFMap().getViewPort().getExtent().getY());
|
422 |
xml.putProperty("extentW",
|
423 |
getFMap().getViewPort().getExtent().getWidth()); |
424 |
xml.putProperty("extentH",
|
425 |
getFMap().getViewPort().getExtent().getHeight()); |
426 |
|
427 |
ProjectExtension pe = (ProjectExtension) App.instance.getPc() |
428 |
.getExtension(ProjectExtension.class); |
429 |
ArrayList views = pe.getProject().getViews();
|
430 |
|
431 |
boolean hasIndex = false; |
432 |
|
433 |
for (int i = 0; i < views.size(); i++) { |
434 |
if (view.getMapContext() == ((ProjectView) views.get(i)).getMapContext()) {
|
435 |
xml.putProperty("indice", i);
|
436 |
hasIndex = true;
|
437 |
} |
438 |
} |
439 |
|
440 |
if (!hasIndex) {
|
441 |
xml.putProperty("indice", -1); |
442 |
} |
443 |
|
444 |
return xml;
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
449 |
*
|
450 |
* @param xml XMLEntity
|
451 |
* @param p DOCUMENT ME!
|
452 |
*
|
453 |
* @return Objeto de esta clase.
|
454 |
*/
|
455 |
public static FFrameView createFFrameView(XMLEntity xml, Project p) { |
456 |
FFrameView fframe = new FFrameView();
|
457 |
|
458 |
if (xml.getIntProperty("m_Selected") != 0) { |
459 |
fframe.setSelected(true);
|
460 |
} else {
|
461 |
fframe.setSelected(false);
|
462 |
} |
463 |
|
464 |
fframe.setName(xml.getStringProperty("m_name"));
|
465 |
fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
466 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
467 |
xml.getDoubleProperty("h")));
|
468 |
|
469 |
fframe.m_Mode = xml.getIntProperty("m_Mode");
|
470 |
fframe.m_typeScale = xml.getIntProperty("m_typeScale");
|
471 |
fframe.m_extension = xml.getIntProperty("m_extension");
|
472 |
fframe.m_quality = xml.getIntProperty("m_quality");
|
473 |
fframe.m_viewing = xml.getIntProperty("m_viewing");
|
474 |
fframe.m_bLinked = xml.getBooleanProperty("m_bLinked");
|
475 |
fframe.m_mapUnits = xml.getIntProperty("m_mapUnits");
|
476 |
|
477 |
ProjectExtension pe = (ProjectExtension) App.instance.getPc() |
478 |
.getExtension(ProjectExtension.class); |
479 |
fframe.m_Scale = xml.getDoubleProperty("m_Scale");
|
480 |
|
481 |
int indice = xml.getIntProperty("indice"); |
482 |
|
483 |
if (indice != -1) { |
484 |
ProjectView view = (ProjectView) p.getViews().get(indice); |
485 |
fframe.m_fmap = view.getMapContext(); |
486 |
fframe.setView((View) view);
|
487 |
|
488 |
//fframe.m_fmap = view.getMapContext();
|
489 |
fframe.getFMap().getViewPort().setExtent(new Rectangle2D.Double( |
490 |
xml.getDoubleProperty("extentX"),
|
491 |
xml.getDoubleProperty("extentY"),
|
492 |
xml.getDoubleProperty("extentW"),
|
493 |
xml.getDoubleProperty("extentH")));
|
494 |
} |
495 |
|
496 |
return fframe;
|
497 |
} |
498 |
|
499 |
/**
|
500 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
501 |
*/
|
502 |
public void updateNum() { |
503 |
num = Layout.numView++; |
504 |
} |
505 |
|
506 |
/**
|
507 |
* DOCUMENT ME!
|
508 |
*
|
509 |
* @return DOCUMENT ME!
|
510 |
*/
|
511 |
public int getNum() { |
512 |
return num;
|
513 |
} |
514 |
|
515 |
/**
|
516 |
* DOCUMENT ME!
|
517 |
*
|
518 |
* @param bi DOCUMENT ME!
|
519 |
*/
|
520 |
public void setBufferedImage(BufferedImage bi) { |
521 |
m_image = bi; |
522 |
} |
523 |
|
524 |
/**
|
525 |
* DOCUMENT ME!
|
526 |
*
|
527 |
* @return DOCUMENT ME!
|
528 |
*/
|
529 |
public BufferedImage getBufferedImage() { |
530 |
return m_image;
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* DOCUMENT ME!
|
535 |
*
|
536 |
* @return
|
537 |
*/
|
538 |
public AffineTransform getAt() { |
539 |
return at;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* DOCUMENT ME!
|
544 |
*
|
545 |
* @param transform
|
546 |
*/
|
547 |
public void setAt(AffineTransform transform) { |
548 |
at = transform; |
549 |
} |
550 |
} |