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