root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrame.java @ 24759
History | View | Annotate | Download (28 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-may-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.BasicStroke; |
48 |
import java.awt.Color; |
49 |
import java.awt.Font; |
50 |
import java.awt.Graphics2D; |
51 |
import java.awt.Image; |
52 |
import java.awt.Rectangle; |
53 |
import java.awt.event.MouseEvent; |
54 |
import java.awt.geom.AffineTransform; |
55 |
import java.awt.geom.Point2D; |
56 |
import java.awt.geom.Rectangle2D; |
57 |
import java.awt.image.BufferedImage; |
58 |
|
59 |
import org.gvsig.fmap.dal.exception.ReadException; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.andami.messages.NotificationManager; |
63 |
import com.iver.cit.gvsig.ProjectExtension; |
64 |
import com.iver.cit.gvsig.project.Project; |
65 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
66 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
67 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
68 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
69 |
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.Tag; |
70 |
import com.iver.utiles.XMLEntity; |
71 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
72 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
73 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
74 |
|
75 |
|
76 |
/**
|
77 |
* Clase que implementa la interface IFFrame con los m�todos por defecto de
|
78 |
* todos los FFrames que extenderan de este, dejando uno como m�todo
|
79 |
* abstracto para implementar por todos los FFrames para ser dibujados.
|
80 |
*
|
81 |
* @author Vicente Caballero Navarro
|
82 |
*/
|
83 |
public abstract class FFrame implements IFFrame { |
84 |
protected String m_name = "FFrame"; |
85 |
private Rectangle2D.Double m_BoundBox = new Rectangle2D.Double(); |
86 |
private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double(); |
87 |
protected int m_Selected = 0; |
88 |
protected Rectangle n = new Rectangle(); |
89 |
protected Rectangle ne = new Rectangle(); |
90 |
protected Rectangle e = new Rectangle(); |
91 |
protected Rectangle se = new Rectangle(); |
92 |
protected Rectangle s = new Rectangle(); |
93 |
protected Rectangle so = new Rectangle(); |
94 |
protected Rectangle o = new Rectangle(); |
95 |
protected Rectangle no = new Rectangle(); |
96 |
private String tag = null; |
97 |
protected int num = 0; |
98 |
private double m_rotation = 0; |
99 |
private int level = -1; |
100 |
private Rectangle2D lastMoveRect; |
101 |
private Layout layout;
|
102 |
protected FrameFactory factory;
|
103 |
// protected PrintRequestAttributeSet printingProperties;
|
104 |
private static final Image iNEResize = PluginServices.getIconTheme() |
105 |
.get("neresize-icon").getImage();
|
106 |
private static final Image iEResize = PluginServices.getIconTheme() |
107 |
.get("eresize-icon").getImage();
|
108 |
private static final Image iNResize = PluginServices.getIconTheme() |
109 |
.get("nresize-icon").getImage();
|
110 |
private static final Image iMove = PluginServices.getIconTheme() |
111 |
.get("move-icon").getImage();
|
112 |
private static final Image iSEResize = PluginServices.getIconTheme() |
113 |
.get("sereresize-icon").getImage();
|
114 |
|
115 |
/**
|
116 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
117 |
* par�metro.
|
118 |
*
|
119 |
* @param g Graphics sobre el que dibujar.
|
120 |
*/
|
121 |
public void drawHandlers(Graphics2D g) { |
122 |
int size = 10; |
123 |
Rectangle2D r = getBoundingBox(null); |
124 |
Point2D p = new Point2D.Double(); |
125 |
g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
126 |
r.getY() + (r.getHeight() / 2));
|
127 |
|
128 |
AffineTransform atRotate = new AffineTransform(); |
129 |
atRotate.rotate(Math.toRadians(getRotation()),
|
130 |
r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
131 |
|
132 |
g.fillRect((int) r.getX() - size, (int) r.getY() - size, size, size); |
133 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() - size), |
134 |
p); |
135 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
136 |
|
137 |
g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
138 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
139 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
140 |
|
141 |
g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
142 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
143 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
144 |
|
145 |
g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
146 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
147 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
148 |
|
149 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size, |
150 |
size, size); |
151 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
152 |
r.getY() - size), p); |
153 |
n.setRect((int) p.getX(), (int) p.getY(), size, size); |
154 |
|
155 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size, |
156 |
size); |
157 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
158 |
r.getMaxY()), p); |
159 |
s.setRect((int) p.getX(), (int) p.getY(), size, size); |
160 |
|
161 |
g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2), |
162 |
size, size); |
163 |
atRotate.transform(new Point2D.Double(r.getX() - size, |
164 |
r.getCenterY() - (size / 2)), p);
|
165 |
o.setRect((int) p.getX(), (int) p.getY(), size, size); |
166 |
|
167 |
g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size, |
168 |
size); |
169 |
atRotate.transform(new Point2D.Double(r.getMaxX(), |
170 |
r.getCenterY() - (size / 2)), p);
|
171 |
e.setRect((int) p.getX(), (int) p.getY(), size, size); |
172 |
g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
173 |
r.getY() + (r.getHeight() / 2));
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Establece que tipo de selecci�n se realiza sobre el fframe.
|
178 |
*
|
179 |
* @param p punto sobre el que se debe de establecer si se selecciona o no
|
180 |
* el fframe.
|
181 |
*/
|
182 |
public void setSelected(Point2D p,MouseEvent e) { |
183 |
m_Selected = getContains(p); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Actualiza el BoundBox del FFrame a partir de su rect�ngulo en pixels y
|
188 |
* la matriz de transformaci�n.
|
189 |
*
|
190 |
* @param r Rect�ngulo.
|
191 |
* @param at Matriz de transformaci�n.
|
192 |
*/
|
193 |
public void updateRect(Rectangle2D r, AffineTransform at) { |
194 |
Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
|
195 |
rec.setRect((int) rec.getMinX(), (int) rec.getMinY(), |
196 |
(int) rec.getWidth(), (int) rec.getHeight()); |
197 |
setBoundBox(rec); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Devuelve el rect�ngulo a partir del desplazamiento en el eje x y el
|
202 |
* desplazamiento en el eje y.
|
203 |
*
|
204 |
* @param difx desplazamiento sobre el eje x.
|
205 |
* @param dify desplazamiento sobre el eje y.
|
206 |
*
|
207 |
* @return rect�ngulo modificado en funci�n del desplazamiento realizado.
|
208 |
*/
|
209 |
public Rectangle2D getMovieRect(int difx, int dify) { |
210 |
double x = 0; |
211 |
double y = 0; |
212 |
double w = 0; |
213 |
double h = 0; |
214 |
|
215 |
lastMoveRect = new Rectangle2D.Double(this.getBoundingBox( |
216 |
null).x, this.getBoundingBox(null).y, |
217 |
this.getBoundingBox(null).width, |
218 |
this.getBoundingBox(null).height); |
219 |
Rectangle2D.Double rec = this.getBoundingBox(null); |
220 |
int difn = 0; |
221 |
difn = difx; |
222 |
x = lastMoveRect.getX(); |
223 |
y = lastMoveRect.getY(); |
224 |
w = lastMoveRect.getWidth(); |
225 |
h = lastMoveRect.getHeight(); |
226 |
|
227 |
switch (this.getSelected()) { |
228 |
case (RECT):
|
229 |
lastMoveRect.setRect((x + difx), (y + dify), w, h); |
230 |
|
231 |
break;
|
232 |
|
233 |
case (N):
|
234 |
|
235 |
if ((y + dify) > rec.getMaxY()) {
|
236 |
y = rec.getMaxY(); |
237 |
} else {
|
238 |
y = y + dify; |
239 |
} |
240 |
|
241 |
lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
|
242 |
|
243 |
break;
|
244 |
|
245 |
case (O):
|
246 |
|
247 |
if ((x + difx) > rec.getMaxX()) {
|
248 |
x = rec.getMaxX(); |
249 |
} else {
|
250 |
x = x + difx; |
251 |
} |
252 |
|
253 |
lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
|
254 |
|
255 |
break;
|
256 |
|
257 |
case (S):
|
258 |
|
259 |
if (y > (rec.getMaxY() + dify)) {
|
260 |
y = rec.getMaxY() + dify; |
261 |
} |
262 |
|
263 |
lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
|
264 |
|
265 |
break;
|
266 |
|
267 |
case (E):
|
268 |
|
269 |
if (x > (rec.getMaxX() + difx)) {
|
270 |
x = rec.getMaxX() + difx; |
271 |
} |
272 |
|
273 |
lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
|
274 |
|
275 |
break;
|
276 |
|
277 |
case (NE):
|
278 |
|
279 |
if ((y - difn) > rec.getMaxY()) {
|
280 |
y = rec.getMaxY(); |
281 |
x = rec.getMaxX() + difn; |
282 |
} else {
|
283 |
y = y - difn; |
284 |
} |
285 |
|
286 |
lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
287 |
|
288 |
break;
|
289 |
|
290 |
case (NO):
|
291 |
|
292 |
if ((y + difn) > rec.getMaxY()) {
|
293 |
y = rec.getMaxY(); |
294 |
x = rec.getMaxX(); |
295 |
} else {
|
296 |
x = x + difn; |
297 |
y = y + difn; |
298 |
} |
299 |
|
300 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
301 |
|
302 |
break;
|
303 |
|
304 |
case (SE):
|
305 |
|
306 |
if (y > (rec.getMaxY() + difn)) {
|
307 |
y = rec.getMaxY() + difn; |
308 |
x = rec.getMaxX() + difn; |
309 |
} |
310 |
|
311 |
lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
312 |
|
313 |
break;
|
314 |
|
315 |
case (SO):
|
316 |
|
317 |
if ((x + difn) > rec.getMaxX()) {
|
318 |
x = rec.getMaxX(); |
319 |
y = rec.getMaxY() - difn; |
320 |
} else {
|
321 |
x = x + difn; |
322 |
} |
323 |
|
324 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
325 |
|
326 |
break;
|
327 |
|
328 |
default:
|
329 |
lastMoveRect.setRect((x), (y), w, h); |
330 |
} |
331 |
|
332 |
return lastMoveRect;
|
333 |
} |
334 |
/**
|
335 |
* Devuelve el rect�ngulo que representa el �ltimo generado al desplazar o modificar el tama�o del fframe.
|
336 |
*
|
337 |
* @return Rectangle2D
|
338 |
*
|
339 |
*/
|
340 |
public Rectangle2D getLastMoveRect(){ |
341 |
return lastMoveRect;
|
342 |
} |
343 |
/**
|
344 |
* Devuelve un entero que representa el tipo de selecci�n que se ha
|
345 |
* realizado sobre el fframe.
|
346 |
*
|
347 |
* @return tipo de selecci�n que se ha realizado.
|
348 |
*/
|
349 |
public int getSelected() { |
350 |
return m_Selected;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* Devuelve true, si el punto que se pasa como par�metro esta contenido
|
355 |
* dentro del boundingbox del fframe.
|
356 |
*
|
357 |
* @param p punto a comprobar.
|
358 |
*
|
359 |
* @return true si el punto esta dentro del boundingbox.
|
360 |
*/
|
361 |
public boolean contains(Point2D p) { |
362 |
return getBoundingBox(null).contains(p.getX(), p.getY()); |
363 |
} |
364 |
|
365 |
/**
|
366 |
* Devuelve un entero que representa donde esta contenido el punto que se
|
367 |
* pasa como par�metro.
|
368 |
*
|
369 |
* @param p punto a comparar.
|
370 |
*
|
371 |
* @return entero que representa como esta contenido el punto.
|
372 |
*/
|
373 |
public int getContains(Point2D p) { |
374 |
if (n.contains(p.getX(), p.getY())) {
|
375 |
return N;
|
376 |
} else if (ne.contains(p.getX(), p.getY())) { |
377 |
return NE;
|
378 |
} else if (e.contains(p.getX(), p.getY())) { |
379 |
return E;
|
380 |
} else if (se.contains(p.getX(), p.getY())) { |
381 |
return SE;
|
382 |
} else if (s.contains(p.getX(), p.getY())) { |
383 |
return S;
|
384 |
} else if (so.contains(p.getX(), p.getY())) { |
385 |
return SO;
|
386 |
} else if (o.contains(p.getX(), p.getY())) { |
387 |
return O;
|
388 |
} else if (no.contains(p.getX(), p.getY())) { |
389 |
return NO;
|
390 |
} else if (getBoundingBox(null).contains(p.getX(), p.getY())) { |
391 |
return RECT;
|
392 |
} |
393 |
|
394 |
return NOSELECT;
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* Devuelve el Cursor adecuado seg�n como est� contenido el punto, si es
|
399 |
* para desplazamiento, o cambio de tama�o.
|
400 |
*
|
401 |
* @param p punto a comprobar.
|
402 |
*
|
403 |
* @return Cursor adecuado a la posici�n.
|
404 |
*/
|
405 |
public Image getMapCursor(Point2D p) { |
406 |
int select = getContains(p);
|
407 |
|
408 |
switch (select) {
|
409 |
case (N):
|
410 |
return iNResize;
|
411 |
|
412 |
case (NE):
|
413 |
return iNEResize;
|
414 |
|
415 |
case (E):
|
416 |
return iEResize;
|
417 |
|
418 |
case (SE):
|
419 |
return iSEResize;
|
420 |
|
421 |
case (S):
|
422 |
return iNResize;
|
423 |
|
424 |
case (SO):
|
425 |
return iNEResize;
|
426 |
|
427 |
case (O):
|
428 |
return iEResize;
|
429 |
|
430 |
case (NO):
|
431 |
return iSEResize;
|
432 |
|
433 |
case (RECT):
|
434 |
return iMove;
|
435 |
} |
436 |
|
437 |
return null; |
438 |
} |
439 |
|
440 |
/**
|
441 |
* Este m�todo se implementa en cada una de las fframe, ya que cada una se
|
442 |
* dibuja de una forma diferente sobre el graphics. M�todo que dibuja
|
443 |
* sobre el graphics que se le pasa como par�metro, seg�n la transformada
|
444 |
* afin que se debe de aplicar y el rect�ngulo que se debe de dibujar.
|
445 |
* M�todo que dibuja sobre el graphics que se le pasa como par�metro,
|
446 |
* seg�n la transformada afin que se debe de aplicar y el rect�ngulo que
|
447 |
* se debe de dibujar.
|
448 |
*
|
449 |
* @param g Graphics
|
450 |
* @param at Transformada afin.
|
451 |
* @param r rect�ngulo sobre el que hacer un clip.
|
452 |
* @param imgBase DOCUMENT ME!
|
453 |
*/
|
454 |
public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r, |
455 |
BufferedImage imgBase) throws ReadException; |
456 |
|
457 |
/**
|
458 |
* Devuelve el nombre que representa al fframe.
|
459 |
*
|
460 |
* @return String
|
461 |
*/
|
462 |
public String getName() { |
463 |
return m_name;
|
464 |
} |
465 |
|
466 |
/**
|
467 |
* Rellena el String que representa al nombre del fframe.
|
468 |
*
|
469 |
* @param n nombre del fframe.
|
470 |
*/
|
471 |
public void setName(String n) { |
472 |
m_name = n; |
473 |
} |
474 |
|
475 |
/**
|
476 |
* Devuelve el boundingBox del fframe en funci�n de la transformada af�n
|
477 |
* que se pasa como par�metro. Si se pasa como par�metro null, devuelve el
|
478 |
* �ltimo boundingbox que se calcul�.
|
479 |
*
|
480 |
* @param at Transformada af�n
|
481 |
*
|
482 |
* @return Rect�ngulo que representa el BoundingBox del fframe.
|
483 |
*/
|
484 |
public Rectangle2D.Double getBoundingBox(AffineTransform at) { |
485 |
if (at == null) { |
486 |
return m_BoundingBox;
|
487 |
} |
488 |
|
489 |
m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at); |
490 |
|
491 |
return m_BoundingBox;
|
492 |
} |
493 |
|
494 |
/**
|
495 |
* Rellena con el rect�ngulo que se pasa como par�metro el boundBox(en
|
496 |
* cent�metros) del fframe del cual con una transformaci�n se podr�
|
497 |
* calcular el BoundingBox (en pixels).
|
498 |
*
|
499 |
* @param r Rect�ngulo en cent�metros.
|
500 |
*/
|
501 |
public void setBoundBox(Rectangle2D r) { |
502 |
m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
503 |
} |
504 |
|
505 |
/**
|
506 |
* Devuelve el rect�ngulo que representa el fframe en cent�metros.
|
507 |
*
|
508 |
* @return Rect�ngulo en centimetros.
|
509 |
*/
|
510 |
public Rectangle2D.Double getBoundBox() { |
511 |
return m_BoundBox;
|
512 |
} |
513 |
|
514 |
/**
|
515 |
* Pasando como par�metro true, se toma como que esta seleccionado el
|
516 |
* fframe y si es false como que esta sin seleccionar, de esta forma se
|
517 |
* selecciona un fframe directamente sin comprobar si un punto esta
|
518 |
* contenido en �l.
|
519 |
*
|
520 |
* @param b true si se quiere seleccionar y false si se quiere
|
521 |
* deseleccionar.
|
522 |
*/
|
523 |
public void setSelected(boolean b) { |
524 |
if (b) {
|
525 |
m_Selected = RECT; |
526 |
} else {
|
527 |
m_Selected = IFFrame.NOSELECT; |
528 |
} |
529 |
} |
530 |
|
531 |
/**
|
532 |
* Crea un Objeto FFrame seg�n el tipo que sea, a partir de la informaci�n
|
533 |
* del XMLEntity.
|
534 |
*
|
535 |
* @param xml XMLEntity
|
536 |
* @param l Layout.
|
537 |
* @param p Proyecto.
|
538 |
*
|
539 |
* @return Objeto de esta clase.
|
540 |
*/
|
541 |
// public static IFFrame createFFrame03(XMLEntity xml, Layout l, Project p) {
|
542 |
// IFFrame fframe = null;
|
543 |
//
|
544 |
// try {
|
545 |
// String className;
|
546 |
// if (classnames.containsKey(xml.getStringProperty("className"))) {
|
547 |
// className = (String)classnames.get(xml.getStringProperty("className"));
|
548 |
// }else {
|
549 |
// className = xml.getStringProperty("className");
|
550 |
// }
|
551 |
// Class clase = Class.forName(className);
|
552 |
// fframe = (IFFrame) clase.newInstance();
|
553 |
// } catch (Exception e) {
|
554 |
// NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
555 |
// e);
|
556 |
// }
|
557 |
//
|
558 |
// if (fframe instanceof IFFrameUseProject) {
|
559 |
// ((IFFrameUseProject) fframe).setProject(p);
|
560 |
// }
|
561 |
//
|
562 |
// fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
|
563 |
// xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
|
564 |
// xml.getDoubleProperty("h")));
|
565 |
// fframe.setXMLEntity03(xml, l);
|
566 |
// fframe.setName(xml.getStringProperty("m_name"));
|
567 |
//
|
568 |
// fframe.setTag(xml.getStringProperty("tag"));
|
569 |
//
|
570 |
// return fframe;
|
571 |
// }
|
572 |
|
573 |
/**
|
574 |
* Crea un Objeto FFrame seg�n el tipo que sea, a partir de la informaci�n
|
575 |
* del XMLEntity.
|
576 |
*
|
577 |
* @param xml XMLEntity
|
578 |
* @param p Proyecto.
|
579 |
*
|
580 |
* @return Objeto de esta clase.
|
581 |
*
|
582 |
* @throws OpenException DOCUMENT ME!
|
583 |
*/
|
584 |
// public static IFFrame createFFrame(XMLEntity xml, Project p,Layout layout)
|
585 |
// throws OpenException {
|
586 |
// IFFrame fframe = null;
|
587 |
// String className = "IFFrame";
|
588 |
// Class clase = null;
|
589 |
//
|
590 |
// try {
|
591 |
// if (classnames.containsKey(xml.getStringProperty("className"))) {
|
592 |
// className = (String)classnames.get(xml.getStringProperty("className"));
|
593 |
// }else {
|
594 |
// className = xml.getStringProperty("className");
|
595 |
// }
|
596 |
// clase = Class.forName(className);
|
597 |
// } catch (ClassNotFoundException e) {
|
598 |
// NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
599 |
// e);
|
600 |
// }
|
601 |
//
|
602 |
// try {
|
603 |
// fframe = (IFFrame) clase.newInstance();
|
604 |
// } catch (InstantiationException e) {
|
605 |
// NotificationManager.addError("Fallo creando el Frame: " +
|
606 |
// clase.getName(), e);
|
607 |
// } catch (IllegalAccessException e) {
|
608 |
// NotificationManager.addError("Fallo creando el Frame: " +
|
609 |
// clase.getName(), e);
|
610 |
// }
|
611 |
//
|
612 |
// try {
|
613 |
// if (fframe instanceof IFFrameUseProject) {
|
614 |
// ((IFFrameUseProject) fframe).setProject(p);
|
615 |
// }
|
616 |
// fframe.setLayout(layout);
|
617 |
//
|
618 |
//
|
619 |
// if (xml.contains("level")) {
|
620 |
// fframe.setLevel(xml.getIntProperty("level"));
|
621 |
// }
|
622 |
// if (xml.contains("num")){
|
623 |
// fframe.setNum(xml.getIntProperty("num"));
|
624 |
// }
|
625 |
// fframe.setName(xml.getStringProperty("m_name"));
|
626 |
// fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
|
627 |
// xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
|
628 |
// xml.getDoubleProperty("h")));
|
629 |
// fframe.setXMLEntity(xml);
|
630 |
// fframe.setTag(xml.getStringProperty("tag"));
|
631 |
// } catch (Exception e) {
|
632 |
// throw new OpenException(e, className);
|
633 |
// }
|
634 |
//
|
635 |
// return fframe;
|
636 |
// }
|
637 |
|
638 |
/**
|
639 |
* Dibuja sobre el graphics el rect�ngulo del fframe en modo borrador.
|
640 |
*
|
641 |
* @param g Graphics so bre el que dibujar.
|
642 |
*/
|
643 |
public void drawDraft(Graphics2D g) { |
644 |
Rectangle2D r = getBoundingBox(null); |
645 |
|
646 |
g.setColor(Color.lightGray);
|
647 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
648 |
(int) r.getHeight());
|
649 |
g.setColor(Color.black);
|
650 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth()-1, |
651 |
(int) r.getHeight()-1); |
652 |
int scale = (int) (r.getWidth() / 12); |
653 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
654 |
g.setFont(f); |
655 |
g.drawString(getName(), |
656 |
(int) (r.getCenterX() - ((getName().length() * scale) / 4)), |
657 |
(int) (r.getCenterY()));
|
658 |
} |
659 |
|
660 |
/**
|
661 |
* Rellena con el n�mero de FFrame.
|
662 |
*
|
663 |
* @param i n�mero
|
664 |
*/
|
665 |
public void setNum(int i) { |
666 |
num = i; |
667 |
} |
668 |
|
669 |
/**
|
670 |
* Dibuja sobre el graphics el rect�ngulo del fframe pero vacio, mostrando
|
671 |
* el nombre del fframe y vacio.
|
672 |
*
|
673 |
* @param g Graphics sobre el que dibujar.
|
674 |
*/
|
675 |
public void drawEmpty(Graphics2D g) { |
676 |
Rectangle2D r = getBoundingBox(null); |
677 |
g.setColor(Color.lightGray);
|
678 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
679 |
(int) r.getHeight());
|
680 |
g.setColor(Color.darkGray);
|
681 |
g.setStroke(new BasicStroke(2)); |
682 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
683 |
(int) r.getHeight());
|
684 |
g.setColor(Color.black);
|
685 |
|
686 |
int scale = (int) (r.getWidth() / 12); |
687 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
688 |
g.setFont(f); |
689 |
|
690 |
String s = this.getNameFFrame() + " " + |
691 |
PluginServices.getText(this, "vacia"); |
692 |
|
693 |
g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)), |
694 |
(int) (r.getCenterY()));
|
695 |
} |
696 |
|
697 |
/**
|
698 |
* Devuelve true si el rect�ngulo primero es null o si es distinto de null
|
699 |
* e intersecta.
|
700 |
*
|
701 |
* @param rv Rect�ngulo
|
702 |
* @param r Rect�ngulo
|
703 |
*
|
704 |
* @return True si intersecta o es null.
|
705 |
*/
|
706 |
public boolean intersects(Rectangle2D rv, Rectangle2D r) { |
707 |
return (((rv != null) && rv.intersects(r)) || (rv == null)); |
708 |
} |
709 |
|
710 |
/**
|
711 |
* Abre el di�logo para cambiar o a�adir el tag.
|
712 |
*/
|
713 |
public void openTag() { |
714 |
Tag tag = new Tag(this); |
715 |
PluginServices.getMDIManager().addWindow(tag); |
716 |
} |
717 |
|
718 |
/**
|
719 |
* Rellena el tag del FFrame.
|
720 |
*
|
721 |
* @param s String que representa el valor a guardar en el tag.
|
722 |
*/
|
723 |
public void setTag(String s) { |
724 |
tag = s; |
725 |
} |
726 |
|
727 |
/**
|
728 |
* Devuelve el tag.
|
729 |
*
|
730 |
* @return tag.
|
731 |
*/
|
732 |
public String getTag() { |
733 |
return tag;
|
734 |
} |
735 |
|
736 |
/**
|
737 |
* Dibuja sobre el graphics que se pasa como par�metro el icono que
|
738 |
* representa que contiene un tag.
|
739 |
*
|
740 |
* @param g Graphics sobre el que dibujar el icono.
|
741 |
*/
|
742 |
public void drawSymbolTag(Graphics2D g) { |
743 |
Rectangle2D rec = getBoundingBox(null); |
744 |
g.rotate(Math.toRadians(getRotation()),
|
745 |
rec.getX() + (rec.getWidth() / 2),
|
746 |
rec.getY() + (rec.getHeight() / 2));
|
747 |
|
748 |
try {
|
749 |
Image image = PluginServices.getIconTheme().get("symboltag-icon").getImage(); |
750 |
g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30, 30, null); |
751 |
} catch (NullPointerException npe) { |
752 |
} |
753 |
|
754 |
g.rotate(Math.toRadians(-getRotation()),
|
755 |
rec.getX() + (rec.getWidth() / 2),
|
756 |
rec.getY() + (rec.getHeight() / 2));
|
757 |
} |
758 |
|
759 |
/**
|
760 |
* Rellenar la rotaci�n para aplicar al FFrame.
|
761 |
*
|
762 |
* @param rotation rotaci�n que se quiere aplicar.
|
763 |
*/
|
764 |
public void setRotation(double rotation) { |
765 |
m_rotation = rotation; |
766 |
} |
767 |
|
768 |
/**
|
769 |
* Devuelve la rotaci�n del FFrame.
|
770 |
*
|
771 |
* @return Rotaci�n del FFrame.
|
772 |
*/
|
773 |
public double getRotation() { |
774 |
return m_rotation;
|
775 |
} |
776 |
|
777 |
/**
|
778 |
* Devuelve el nivel en el que se encuentra el FFrame.
|
779 |
*
|
780 |
* @return nivel
|
781 |
*/
|
782 |
public int getLevel() { |
783 |
return level;
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* Inserta el nivel al que se encuentra el FFrame.
|
788 |
*
|
789 |
* @param l entero que refleja el nivel del FFrame.
|
790 |
*/
|
791 |
public void setLevel(int l) { |
792 |
level = l; |
793 |
} |
794 |
|
795 |
/**
|
796 |
* DOCUMENT ME!
|
797 |
*
|
798 |
* @param layout DOCUMENT ME!
|
799 |
*
|
800 |
* @return DOCUMENT ME!
|
801 |
*/
|
802 |
public IFFrame cloneFFrame(Layout layout) {
|
803 |
Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject(); |
804 |
IFFrame frame = null;
|
805 |
|
806 |
try {
|
807 |
frame = createFromXML(this.getXMLEntity(), p,layout);
|
808 |
} catch (OpenException e) {
|
809 |
e.showError(); |
810 |
} catch (SaveException e) {
|
811 |
e.showError(); |
812 |
} |
813 |
((FFrame)frame).m_BoundingBox=this.m_BoundingBox;
|
814 |
frame.setLayout(layout); |
815 |
|
816 |
if (frame instanceof IFFrameViewDependence) { |
817 |
((IFFrameViewDependence) frame).initDependence(layout.getLayoutContext().getAllFFrames()); |
818 |
} |
819 |
frame.setFrameLayoutFactory(factory); |
820 |
cloneActions(frame); |
821 |
return frame;
|
822 |
} |
823 |
/**
|
824 |
* DOCUMENT ME!
|
825 |
*
|
826 |
* @return DOCUMENT ME!
|
827 |
*
|
828 |
* @throws SaveException DOCUMENT ME!
|
829 |
*/
|
830 |
public XMLEntity getXMLEntity() throws SaveException { |
831 |
XMLEntity xml = new XMLEntity();
|
832 |
xml.putProperty("className", getFrameLayoutFactory().getRegisterName());
|
833 |
xml.putProperty("m_name", m_name);
|
834 |
xml.putProperty("x", getBoundBox().x);
|
835 |
xml.putProperty("y", getBoundBox().y);
|
836 |
xml.putProperty("w", getBoundBox().width);
|
837 |
xml.putProperty("h", getBoundBox().height);
|
838 |
xml.putProperty("m_Selected", m_Selected);
|
839 |
xml.putProperty("tag", getTag());
|
840 |
xml.putProperty("m_rotation", getRotation());
|
841 |
xml.putProperty("level",getLevel());
|
842 |
xml.putProperty("num",num);
|
843 |
return xml;
|
844 |
} |
845 |
|
846 |
public void setLayout(Layout layout) { |
847 |
this.layout=layout;
|
848 |
} |
849 |
|
850 |
public Layout getLayout() {
|
851 |
return layout;
|
852 |
} |
853 |
|
854 |
public static IFFrame createFromXML(XMLEntity xml, Project p, Layout layout) |
855 |
throws OpenException {
|
856 |
FrameFactory flf = null;
|
857 |
try{
|
858 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
859 |
ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("FFrames"));
|
860 |
try {
|
861 |
flf = (FrameFactory) extPoint.create(xml.getStringProperty("className"));
|
862 |
} catch (InstantiationException e) { |
863 |
NotificationManager.addError("Clase de FFrame no reconocida",
|
864 |
e); |
865 |
} catch (IllegalAccessException e) { |
866 |
NotificationManager.addError("Clase de FFrame no reconocida",
|
867 |
e); |
868 |
} |
869 |
IFFrame frame=flf.createFrame(); |
870 |
frame.setFrameLayoutFactory(flf); |
871 |
|
872 |
if (frame instanceof IFFrameUseProject) { |
873 |
((IFFrameUseProject) frame).setProject(p); |
874 |
} |
875 |
frame.setLayout(layout); |
876 |
if (xml.contains("level")) { |
877 |
frame.setLevel(xml.getIntProperty("level"));
|
878 |
} |
879 |
if (xml.contains("num")){ |
880 |
frame.setNum(xml.getIntProperty("num"));
|
881 |
} |
882 |
frame.setName(xml.getStringProperty("m_name"));
|
883 |
frame.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
884 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
885 |
xml.getDoubleProperty("h")));
|
886 |
frame.setXMLEntity(xml); |
887 |
frame.setTag(xml.getStringProperty("tag"));
|
888 |
return frame;
|
889 |
}catch (Exception e) { |
890 |
throw new OpenException(e,flf.getNameType()); |
891 |
} |
892 |
} |
893 |
public void setFrameLayoutFactory(FrameFactory flf) { |
894 |
factory=flf; |
895 |
} |
896 |
|
897 |
public FrameFactory getFrameLayoutFactory() {
|
898 |
return factory;
|
899 |
} |
900 |
|
901 |
// public void setPrintingProperties(PrintRequestAttributeSet properties) {
|
902 |
// printingProperties=properties;
|
903 |
// }
|
904 |
} |