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