svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / FFrame.java @ 34228
History | View | Annotate | Download (23.9 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.slf4j.Logger; |
60 |
import org.slf4j.LoggerFactory; |
61 |
|
62 |
import org.gvsig.andami.PluginServices; |
63 |
import org.gvsig.app.project.ProjectManager; |
64 |
import org.gvsig.app.project.documents.layout.Attributes; |
65 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
66 |
import org.gvsig.app.project.documents.layout.LayoutContext; |
67 |
import org.gvsig.app.project.documents.layout.LayoutControl; |
68 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
69 |
import org.gvsig.tools.ToolsLocator; |
70 |
import org.gvsig.tools.dynobject.DynStruct; |
71 |
import org.gvsig.tools.persistence.PersistenceManager; |
72 |
import org.gvsig.tools.persistence.PersistentState; |
73 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
74 |
|
75 |
|
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 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrame"; |
87 |
|
88 |
private static final String BOUNDINGBOX_FIELD = "boundingBox"; |
89 |
private static final String SELECTED_FIELD = "selected"; |
90 |
private static final String TAG_FIELD = "tag"; |
91 |
private static final String ROTATION_FIELD = "rotation"; |
92 |
private static final String LEVEL_FIELD = "level"; |
93 |
private static final String NUM_FIELD = "num"; |
94 |
|
95 |
protected static final Logger LOG = LoggerFactory.getLogger(FFrame.class); |
96 |
|
97 |
protected Rectangle2D.Double m_BoundBox = new Rectangle2D.Double(); |
98 |
private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double(); |
99 |
protected int m_Selected = 0; |
100 |
protected Rectangle n = new Rectangle(); |
101 |
protected Rectangle ne = new Rectangle(); |
102 |
protected Rectangle e = new Rectangle(); |
103 |
protected Rectangle se = new Rectangle(); |
104 |
protected Rectangle s = new Rectangle(); |
105 |
protected Rectangle so = new Rectangle(); |
106 |
protected Rectangle o = new Rectangle(); |
107 |
protected Rectangle no = new Rectangle(); |
108 |
private String tag = null; |
109 |
protected int num = 0; |
110 |
private double m_rotation = 0; |
111 |
private int level = -1; |
112 |
private Rectangle2D lastMoveRect; |
113 |
protected FrameFactory frameFactory;
|
114 |
|
115 |
private static Image iNEResize = null; |
116 |
private static Image iEResize = null; |
117 |
private static Image iNResize = null; |
118 |
private static Image iMove = null; |
119 |
private static Image iSEResize = null; |
120 |
|
121 |
protected LayoutManager layoutManager = null; |
122 |
protected LayoutContext layoutContext = null; |
123 |
protected LayoutControl layoutControl = null; |
124 |
|
125 |
public FFrame() {
|
126 |
super();
|
127 |
layoutManager = (LayoutManager)ProjectManager.getInstance().getDocumentManagers(LayoutManager.TYPENAME); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
132 |
* par�metro.
|
133 |
*
|
134 |
* @param g Graphics sobre el que dibujar.
|
135 |
*/
|
136 |
public void drawHandlers(Graphics2D g) { |
137 |
int size = 10; |
138 |
Rectangle2D r = getBoundingBox(null); |
139 |
Point2D p = new Point2D.Double(); |
140 |
g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
141 |
r.getY() + (r.getHeight() / 2));
|
142 |
|
143 |
AffineTransform atRotate = new AffineTransform(); |
144 |
atRotate.rotate(Math.toRadians(getRotation()),
|
145 |
r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
146 |
|
147 |
g.fillRect((int) r.getX() - size, (int) r.getY() - size, size, size); |
148 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() - size), |
149 |
p); |
150 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
151 |
|
152 |
g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
153 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
154 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
155 |
|
156 |
g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
157 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
158 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
159 |
|
160 |
g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
161 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
162 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
163 |
|
164 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size, |
165 |
size, size); |
166 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
167 |
r.getY() - size), p); |
168 |
n.setRect((int) p.getX(), (int) p.getY(), size, size); |
169 |
|
170 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size, |
171 |
size); |
172 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
173 |
r.getMaxY()), p); |
174 |
s.setRect((int) p.getX(), (int) p.getY(), size, size); |
175 |
|
176 |
g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2), |
177 |
size, size); |
178 |
atRotate.transform(new Point2D.Double(r.getX() - size, |
179 |
r.getCenterY() - (size / 2)), p);
|
180 |
o.setRect((int) p.getX(), (int) p.getY(), size, size); |
181 |
|
182 |
g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size, |
183 |
size); |
184 |
atRotate.transform(new Point2D.Double(r.getMaxX(), |
185 |
r.getCenterY() - (size / 2)), p);
|
186 |
e.setRect((int) p.getX(), (int) p.getY(), size, size); |
187 |
g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
188 |
r.getY() + (r.getHeight() / 2));
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Establece que tipo de selecci�n se realiza sobre el fframe.
|
193 |
*
|
194 |
* @param p punto sobre el que se debe de establecer si se selecciona o no
|
195 |
* el fframe.
|
196 |
*/
|
197 |
public void setSelected(Point2D p,MouseEvent e) { |
198 |
m_Selected = getContains(p); |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Actualiza el BoundBox del FFrame a partir de su rect�ngulo en pixels y
|
203 |
* la matriz de transformaci�n.
|
204 |
*
|
205 |
* @param r Rect�ngulo.
|
206 |
* @param at Matriz de transformaci�n.
|
207 |
*/
|
208 |
public void updateRect(Rectangle2D r, AffineTransform at) { |
209 |
Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
|
210 |
rec.setRect((int) rec.getMinX(), (int) rec.getMinY(), |
211 |
(int) rec.getWidth(), (int) rec.getHeight()); |
212 |
setBoundBox(rec); |
213 |
} |
214 |
|
215 |
/**
|
216 |
* Devuelve el rect�ngulo a partir del desplazamiento en el eje x y el
|
217 |
* desplazamiento en el eje y.
|
218 |
*
|
219 |
* @param difx desplazamiento sobre el eje x.
|
220 |
* @param dify desplazamiento sobre el eje y.
|
221 |
*
|
222 |
* @return rect�ngulo modificado en funci�n del desplazamiento realizado.
|
223 |
*/
|
224 |
public Rectangle2D getMovieRect(int difx, int dify) { |
225 |
double x = 0; |
226 |
double y = 0; |
227 |
double w = 0; |
228 |
double h = 0; |
229 |
|
230 |
lastMoveRect = new Rectangle2D.Double(this.getBoundingBox( |
231 |
null).x, this.getBoundingBox(null).y, |
232 |
this.getBoundingBox(null).width, |
233 |
this.getBoundingBox(null).height); |
234 |
Rectangle2D.Double rec = this.getBoundingBox(null); |
235 |
int difn = 0; |
236 |
difn = difx; |
237 |
x = lastMoveRect.getX(); |
238 |
y = lastMoveRect.getY(); |
239 |
w = lastMoveRect.getWidth(); |
240 |
h = lastMoveRect.getHeight(); |
241 |
|
242 |
switch (this.getSelected()) { |
243 |
case (RECT):
|
244 |
lastMoveRect.setRect((x + difx), (y + dify), w, h); |
245 |
|
246 |
break;
|
247 |
|
248 |
case (N):
|
249 |
|
250 |
if ((y + dify) > rec.getMaxY()) {
|
251 |
y = rec.getMaxY(); |
252 |
} else {
|
253 |
y = y + dify; |
254 |
} |
255 |
|
256 |
lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
|
257 |
|
258 |
break;
|
259 |
|
260 |
case (O):
|
261 |
|
262 |
if ((x + difx) > rec.getMaxX()) {
|
263 |
x = rec.getMaxX(); |
264 |
} else {
|
265 |
x = x + difx; |
266 |
} |
267 |
|
268 |
lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
|
269 |
|
270 |
break;
|
271 |
|
272 |
case (S):
|
273 |
|
274 |
if (y > (rec.getMaxY() + dify)) {
|
275 |
y = rec.getMaxY() + dify; |
276 |
} |
277 |
|
278 |
lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
|
279 |
|
280 |
break;
|
281 |
|
282 |
case (E):
|
283 |
|
284 |
if (x > (rec.getMaxX() + difx)) {
|
285 |
x = rec.getMaxX() + difx; |
286 |
} |
287 |
|
288 |
lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
|
289 |
|
290 |
break;
|
291 |
|
292 |
case (NE):
|
293 |
|
294 |
if ((y - difn) > rec.getMaxY()) {
|
295 |
y = rec.getMaxY(); |
296 |
x = rec.getMaxX() + difn; |
297 |
} else {
|
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 (NO):
|
306 |
|
307 |
if ((y + difn) > rec.getMaxY()) {
|
308 |
y = rec.getMaxY(); |
309 |
x = rec.getMaxX(); |
310 |
} else {
|
311 |
x = x + difn; |
312 |
y = y + difn; |
313 |
} |
314 |
|
315 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
316 |
|
317 |
break;
|
318 |
|
319 |
case (SE):
|
320 |
|
321 |
if (y > (rec.getMaxY() + difn)) {
|
322 |
y = rec.getMaxY() + difn; |
323 |
x = rec.getMaxX() + difn; |
324 |
} |
325 |
|
326 |
lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
327 |
|
328 |
break;
|
329 |
|
330 |
case (SO):
|
331 |
|
332 |
if ((x + difn) > rec.getMaxX()) {
|
333 |
x = rec.getMaxX(); |
334 |
y = rec.getMaxY() - difn; |
335 |
} else {
|
336 |
x = x + difn; |
337 |
} |
338 |
|
339 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
340 |
|
341 |
break;
|
342 |
|
343 |
default:
|
344 |
lastMoveRect.setRect((x), (y), w, h); |
345 |
} |
346 |
|
347 |
return lastMoveRect;
|
348 |
} |
349 |
/**
|
350 |
* Devuelve el rect�ngulo que representa el �ltimo generado al desplazar o modificar el tama�o del fframe.
|
351 |
*
|
352 |
* @return Rectangle2D
|
353 |
*
|
354 |
*/
|
355 |
public Rectangle2D getLastMoveRect(){ |
356 |
return lastMoveRect;
|
357 |
} |
358 |
/**
|
359 |
* Devuelve un entero que representa el tipo de selecci�n que se ha
|
360 |
* realizado sobre el fframe.
|
361 |
*
|
362 |
* @return tipo de selecci�n que se ha realizado.
|
363 |
*/
|
364 |
public int getSelected() { |
365 |
return m_Selected;
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* Devuelve true, si el punto que se pasa como par�metro esta contenido
|
370 |
* dentro del boundingbox del fframe.
|
371 |
*
|
372 |
* @param p punto a comprobar.
|
373 |
*
|
374 |
* @return true si el punto esta dentro del boundingbox.
|
375 |
*/
|
376 |
public boolean contains(Point2D p) { |
377 |
return getBoundingBox(null).contains(p.getX(), p.getY()); |
378 |
} |
379 |
|
380 |
/**
|
381 |
* Devuelve un entero que representa donde esta contenido el punto que se
|
382 |
* pasa como par�metro.
|
383 |
*
|
384 |
* @param p punto a comparar.
|
385 |
*
|
386 |
* @return entero que representa como esta contenido el punto.
|
387 |
*/
|
388 |
public int getContains(Point2D p) { |
389 |
if (n.contains(p.getX(), p.getY())) {
|
390 |
return N;
|
391 |
} else if (ne.contains(p.getX(), p.getY())) { |
392 |
return NE;
|
393 |
} else if (e.contains(p.getX(), p.getY())) { |
394 |
return E;
|
395 |
} else if (se.contains(p.getX(), p.getY())) { |
396 |
return SE;
|
397 |
} else if (s.contains(p.getX(), p.getY())) { |
398 |
return S;
|
399 |
} else if (so.contains(p.getX(), p.getY())) { |
400 |
return SO;
|
401 |
} else if (o.contains(p.getX(), p.getY())) { |
402 |
return O;
|
403 |
} else if (no.contains(p.getX(), p.getY())) { |
404 |
return NO;
|
405 |
} else if (getBoundingBox(null).contains(p.getX(), p.getY())) { |
406 |
return RECT;
|
407 |
} |
408 |
|
409 |
return NOSELECT;
|
410 |
} |
411 |
|
412 |
/**
|
413 |
* Devuelve el Cursor adecuado seg�n como est� contenido el punto, si es
|
414 |
* para desplazamiento, o cambio de tama�o.
|
415 |
*
|
416 |
* @param p punto a comprobar.
|
417 |
*
|
418 |
* @return Cursor adecuado a la posici�n.
|
419 |
*/
|
420 |
public Image getMapCursor(Point2D p) { |
421 |
int select = getContains(p);
|
422 |
|
423 |
switch (select) {
|
424 |
case (N):
|
425 |
return iNResize;
|
426 |
|
427 |
case (NE):
|
428 |
return iNEResize;
|
429 |
|
430 |
case (E):
|
431 |
return iEResize;
|
432 |
|
433 |
case (SE):
|
434 |
return iSEResize;
|
435 |
|
436 |
case (S):
|
437 |
return iNResize;
|
438 |
|
439 |
case (SO):
|
440 |
return iNEResize;
|
441 |
|
442 |
case (O):
|
443 |
return iEResize;
|
444 |
|
445 |
case (NO):
|
446 |
return iSEResize;
|
447 |
|
448 |
case (RECT):
|
449 |
return iMove;
|
450 |
} |
451 |
|
452 |
return null; |
453 |
} |
454 |
|
455 |
/**
|
456 |
* Este m�todo se implementa en cada una de las fframe, ya que cada una se
|
457 |
* dibuja de una forma diferente sobre el graphics. M�todo que dibuja
|
458 |
* sobre el graphics que se le pasa como par�metro, seg�n la transformada
|
459 |
* afin que se debe de aplicar y el rect�ngulo que se debe de dibujar.
|
460 |
* M�todo que dibuja sobre el graphics que se le pasa como par�metro,
|
461 |
* seg�n la transformada afin que se debe de aplicar y el rect�ngulo que
|
462 |
* se debe de dibujar.
|
463 |
*
|
464 |
* @param g Graphics
|
465 |
* @param at Transformada afin.
|
466 |
* @param r rect�ngulo sobre el que hacer un clip.
|
467 |
* @param imgBase DOCUMENT ME!
|
468 |
*/
|
469 |
public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r, |
470 |
BufferedImage imgBase);
|
471 |
|
472 |
/**
|
473 |
* Devuelve el boundingBox del fframe en funci�n de la transformada af�n
|
474 |
* que se pasa como par�metro. Si se pasa como par�metro null, devuelve el
|
475 |
* �ltimo boundingbox que se calcul�.
|
476 |
*
|
477 |
* @param at Transformada af�n
|
478 |
*
|
479 |
* @return Rect�ngulo que representa el BoundingBox del fframe.
|
480 |
*/
|
481 |
public Rectangle2D.Double getBoundingBox(AffineTransform at) { |
482 |
if (at == null) { |
483 |
return m_BoundingBox;
|
484 |
} |
485 |
|
486 |
m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at); |
487 |
|
488 |
return m_BoundingBox;
|
489 |
} |
490 |
|
491 |
/**
|
492 |
* Rellena con el rect�ngulo que se pasa como par�metro el boundBox(en
|
493 |
* cent�metros) del fframe del cual con una transformaci�n se podr�
|
494 |
* calcular el BoundingBox (en pixels).
|
495 |
*
|
496 |
* @param r Rect�ngulo en cent�metros.
|
497 |
*/
|
498 |
public void setBoundBox(Rectangle2D r) { |
499 |
m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
500 |
} |
501 |
|
502 |
/**
|
503 |
* Devuelve el rect�ngulo que representa el fframe en cent�metros.
|
504 |
*
|
505 |
* @return Rect�ngulo en centimetros.
|
506 |
*/
|
507 |
public Rectangle2D.Double getBoundBox() { |
508 |
return m_BoundBox;
|
509 |
} |
510 |
|
511 |
/**
|
512 |
* Pasando como par�metro true, se toma como que esta seleccionado el
|
513 |
* fframe y si es false como que esta sin seleccionar, de esta forma se
|
514 |
* selecciona un fframe directamente sin comprobar si un punto esta
|
515 |
* contenido en �l.
|
516 |
*
|
517 |
* @param b true si se quiere seleccionar y false si se quiere
|
518 |
* deseleccionar.
|
519 |
*/
|
520 |
public void setSelected(boolean b) { |
521 |
if (b) {
|
522 |
m_Selected = RECT; |
523 |
} else {
|
524 |
m_Selected = IFFrame.NOSELECT; |
525 |
} |
526 |
} |
527 |
|
528 |
/**
|
529 |
* Dibuja sobre el graphics el rect�ngulo del fframe en modo borrador.
|
530 |
*
|
531 |
* @param g Graphics so bre el que dibujar.
|
532 |
*/
|
533 |
public void drawDraft(Graphics2D g) { |
534 |
Rectangle2D r = getBoundingBox(null); |
535 |
|
536 |
g.setColor(Color.lightGray);
|
537 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
538 |
(int) r.getHeight());
|
539 |
g.setColor(Color.black);
|
540 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth()-1, |
541 |
(int) r.getHeight()-1); |
542 |
int scale = (int) (r.getWidth() / 12); |
543 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
544 |
g.setFont(f); |
545 |
g.drawString(getName(), |
546 |
(int) (r.getCenterX() - ((getName().length() * scale) / 4)), |
547 |
(int) (r.getCenterY()));
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* Rellena con el n�mero de FFrame.
|
552 |
*
|
553 |
* @param i n�mero
|
554 |
*/
|
555 |
public void setNum(int i) { |
556 |
num = i; |
557 |
} |
558 |
|
559 |
/**
|
560 |
* Dibuja sobre el graphics el rect�ngulo del fframe pero vacio, mostrando
|
561 |
* el nombre del fframe y vacio.
|
562 |
*
|
563 |
* @param g Graphics sobre el que dibujar.
|
564 |
*/
|
565 |
public void drawEmpty(Graphics2D g) { |
566 |
Rectangle2D r = getBoundingBox(null); |
567 |
g.setColor(Color.lightGray);
|
568 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
569 |
(int) r.getHeight());
|
570 |
g.setColor(Color.darkGray);
|
571 |
g.setStroke(new BasicStroke(2)); |
572 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
573 |
(int) r.getHeight());
|
574 |
g.setColor(Color.black);
|
575 |
|
576 |
int scale = (int) (r.getWidth() / 12); |
577 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
578 |
g.setFont(f); |
579 |
|
580 |
String s = this.getNameFFrame() + " " + |
581 |
PluginServices.getText(this, "vacia"); |
582 |
|
583 |
g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)), |
584 |
(int) (r.getCenterY()));
|
585 |
} |
586 |
|
587 |
/**
|
588 |
* Devuelve true si el rect�ngulo primero es null o si es distinto de null
|
589 |
* e intersecta.
|
590 |
*
|
591 |
* @param rv Rect�ngulo
|
592 |
* @param r Rect�ngulo
|
593 |
*
|
594 |
* @return True si intersecta o es null.
|
595 |
*/
|
596 |
public boolean intersects(Rectangle2D rv, Rectangle2D r) { |
597 |
return (((rv != null) && rv.intersects(r)) || (rv == null)); |
598 |
} |
599 |
|
600 |
/**
|
601 |
* Rellena el tag del FFrame.
|
602 |
*
|
603 |
* @param s String que representa el valor a guardar en el tag.
|
604 |
*/
|
605 |
public void setTag(String s) { |
606 |
tag = s; |
607 |
} |
608 |
|
609 |
/**
|
610 |
* Devuelve el tag.
|
611 |
*
|
612 |
* @return tag.
|
613 |
*/
|
614 |
public String getTag() { |
615 |
return tag;
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* Dibuja sobre el graphics que se pasa como par�metro el icono que
|
620 |
* representa que contiene un tag.
|
621 |
*
|
622 |
* @param g Graphics sobre el que dibujar el icono.
|
623 |
*/
|
624 |
public void drawSymbolTag(Graphics2D g) { |
625 |
Rectangle2D rec = getBoundingBox(null); |
626 |
g.rotate(Math.toRadians(getRotation()),
|
627 |
rec.getX() + (rec.getWidth() / 2),
|
628 |
rec.getY() + (rec.getHeight() / 2));
|
629 |
|
630 |
try {
|
631 |
Image image = PluginServices.getIconTheme().get("symboltag-icon").getImage(); |
632 |
g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30, 30, null); |
633 |
} catch (NullPointerException npe) { |
634 |
} |
635 |
|
636 |
g.rotate(Math.toRadians(-getRotation()),
|
637 |
rec.getX() + (rec.getWidth() / 2),
|
638 |
rec.getY() + (rec.getHeight() / 2));
|
639 |
} |
640 |
|
641 |
/**
|
642 |
* Rellenar la rotaci�n para aplicar al FFrame.
|
643 |
*
|
644 |
* @param rotation rotaci�n que se quiere aplicar.
|
645 |
*/
|
646 |
public void setRotation(double rotation) { |
647 |
m_rotation = rotation; |
648 |
} |
649 |
|
650 |
/**
|
651 |
* Devuelve la rotaci�n del FFrame.
|
652 |
*
|
653 |
* @return Rotaci�n del FFrame.
|
654 |
*/
|
655 |
public double getRotation() { |
656 |
return m_rotation;
|
657 |
} |
658 |
|
659 |
/**
|
660 |
* Devuelve el nivel en el que se encuentra el FFrame.
|
661 |
*
|
662 |
* @return nivel
|
663 |
*/
|
664 |
public int getLevel() { |
665 |
return level;
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* Inserta el nivel al que se encuentra el FFrame.
|
670 |
*
|
671 |
* @param l entero que refleja el nivel del FFrame.
|
672 |
*/
|
673 |
public void setLevel(int l) { |
674 |
level = l; |
675 |
} |
676 |
|
677 |
@Override
|
678 |
public Object clone() throws CloneNotSupportedException { |
679 |
IFFrame frame = (IFFrame) super.clone();
|
680 |
return frame;
|
681 |
} |
682 |
|
683 |
public void setFrameFactory(FrameFactory flf) { |
684 |
frameFactory=flf; |
685 |
} |
686 |
|
687 |
public FrameFactory getFrameFactory() {
|
688 |
return frameFactory;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* Initilizes the static icons
|
693 |
*/
|
694 |
public static void initializeIcons(){ |
695 |
iNEResize = PluginServices.getIconTheme().get("neresize-icon").getImage();
|
696 |
iEResize = PluginServices.getIconTheme().get("eresize-icon").getImage();
|
697 |
iNResize = PluginServices.getIconTheme().get("nresize-icon").getImage();
|
698 |
iMove = PluginServices.getIconTheme().get("move-icon").getImage();
|
699 |
iSEResize = PluginServices.getIconTheme().get("sereresize-icon").getImage();
|
700 |
} |
701 |
|
702 |
public static void registerPersistent() { |
703 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
704 |
if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
705 |
DynStruct definition = manager.addDefinition( |
706 |
FFrame.class, |
707 |
PERSISTENCE_DEFINITION_NAME, |
708 |
"FFrame persistence definition",
|
709 |
null,
|
710 |
null
|
711 |
); |
712 |
|
713 |
definition.addDynFieldObject(BOUNDINGBOX_FIELD).setClassOfValue(Rectangle2D.class).setMandatory(true); |
714 |
definition.addDynFieldInt(SELECTED_FIELD).setMandatory(true);
|
715 |
definition.addDynFieldString(TAG_FIELD).setMandatory(false);
|
716 |
definition.addDynFieldDouble(ROTATION_FIELD).setMandatory(true);
|
717 |
definition.addDynFieldInt(LEVEL_FIELD).setMandatory(true);
|
718 |
definition.addDynFieldInt(NUM_FIELD).setMandatory(true);
|
719 |
} |
720 |
|
721 |
Attributes.registerPersistent();
|
722 |
AbstractFFrameViewDependence.registerPersistent(); |
723 |
FFrameBasic.registerPersistent(); |
724 |
FFrameGraphics.registerPersistent(); |
725 |
FFrameSymbol.registerPersistent(); |
726 |
FFrameGrid.registerPersistent(); |
727 |
FFrameGroup.registerPersistent(); |
728 |
FFrameTable.registerPersistent(); |
729 |
FFrameLegend.registerPersistent(); |
730 |
FFramePicture.registerPersistent(); |
731 |
FFrameNorth.registerPersistent(); |
732 |
FFrameScaleBar.registerPersistent(); |
733 |
FFrameText.registerPersistent(); |
734 |
FFrameView.registerPersistent(); |
735 |
FFrameOverView.registerPersistent(); |
736 |
} |
737 |
|
738 |
public void loadFromState(PersistentState state) |
739 |
throws PersistenceException {
|
740 |
m_BoundBox = (Rectangle2D.Double)state.get(BOUNDINGBOX_FIELD);
|
741 |
m_Selected = state.getInt(SELECTED_FIELD); |
742 |
tag = state.getString(TAG_FIELD); |
743 |
m_rotation = state.getDouble(ROTATION_FIELD); |
744 |
level = state.getInt(LEVEL_FIELD); |
745 |
num = state.getInt(NUM_FIELD); |
746 |
} |
747 |
|
748 |
public void saveToState(PersistentState state) throws PersistenceException { |
749 |
state.set(BOUNDINGBOX_FIELD, getBoundBox()); |
750 |
state.set(SELECTED_FIELD, m_Selected); |
751 |
state.set(TAG_FIELD, getTag()); |
752 |
state.set(ROTATION_FIELD, getRotation()); |
753 |
state.set(LEVEL_FIELD, getLevel()); |
754 |
state.set(NUM_FIELD, num); |
755 |
} |
756 |
|
757 |
public LayoutContext getLayoutContext() {
|
758 |
return layoutContext;
|
759 |
} |
760 |
|
761 |
public void setLayoutContext(LayoutContext theLayoutContext) { |
762 |
this.layoutContext = theLayoutContext;
|
763 |
} |
764 |
|
765 |
public LayoutControl getLayoutControl() {
|
766 |
return layoutControl;
|
767 |
} |
768 |
|
769 |
public void setLayoutControl(LayoutControl layoutControl) { |
770 |
this.layoutControl = layoutControl;
|
771 |
} |
772 |
|
773 |
// public void setPrintingProperties(PrintRequestAttributeSet properties) {
|
774 |
// printingProperties=properties;
|
775 |
// }
|
776 |
|
777 |
|
778 |
|
779 |
} |