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