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