svn-document-layout / branches / usability_v2 / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrame.java @ 142
History | View | Annotate | Download (25.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.fframes; |
23 |
|
24 |
import java.awt.BasicStroke; |
25 |
import java.awt.Color; |
26 |
import java.awt.Font; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.Image; |
29 |
import java.awt.Rectangle; |
30 |
import java.awt.event.MouseEvent; |
31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.Point2D; |
33 |
import java.awt.geom.Rectangle2D; |
34 |
import java.awt.image.BufferedImage; |
35 |
|
36 |
import org.gvsig.andami.PluginServices; |
37 |
import org.gvsig.app.project.ProjectManager; |
38 |
import org.gvsig.app.project.documents.layout.Attributes; |
39 |
import org.gvsig.app.project.documents.layout.DefaultLayoutManager; |
40 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
41 |
import org.gvsig.app.project.documents.layout.LayoutContext; |
42 |
import org.gvsig.app.project.documents.layout.LayoutControl; |
43 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.dispose.Disposable; |
46 |
import org.gvsig.tools.dynobject.DynStruct; |
47 |
import org.gvsig.tools.observer.ObservableHelper; |
48 |
import org.gvsig.tools.observer.Observer; |
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
50 |
import org.gvsig.tools.persistence.PersistentState; |
51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
/**
|
56 |
* Clase que implementa la interface IFFrame con los m�todos por defecto de
|
57 |
* todos los FFrames que extenderan de este, dejando uno como m�todo
|
58 |
* abstracto para implementar por todos los FFrames para ser dibujados.
|
59 |
*
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*/
|
62 |
public abstract class FFrame implements IFFrame { |
63 |
|
64 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrame"; |
65 |
|
66 |
private static final String BOUNDINGBOX_FIELD = "boundingBox"; |
67 |
private static final String SELECTED_FIELD = "selected"; |
68 |
private static final String TAG_FIELD = "tag"; |
69 |
private static final String ROTATION_FIELD = "rotation"; |
70 |
private static final String LEVEL_FIELD = "level"; |
71 |
private static final String NUM_FIELD = "num"; |
72 |
|
73 |
protected static final Logger LOG = LoggerFactory.getLogger(FFrame.class); |
74 |
|
75 |
protected Rectangle2D.Double m_BoundBox = new Rectangle2D.Double(); |
76 |
// initially identity
|
77 |
protected AffineTransform lastAT = AffineTransform.getShearInstance(0,0); |
78 |
// private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double();
|
79 |
|
80 |
protected int m_Selected = 0; |
81 |
protected Rectangle n = new Rectangle(); |
82 |
protected Rectangle ne = new Rectangle(); |
83 |
protected Rectangle e = new Rectangle(); |
84 |
protected Rectangle se = new Rectangle(); |
85 |
protected Rectangle s = new Rectangle(); |
86 |
protected Rectangle so = new Rectangle(); |
87 |
protected Rectangle o = new Rectangle(); |
88 |
protected Rectangle no = new Rectangle(); |
89 |
private String tag = null; |
90 |
protected int num = 0; |
91 |
private double m_rotation = 0; |
92 |
private int level = -1; |
93 |
private Rectangle2D lastMoveRect; |
94 |
protected FrameFactory frameFactory;
|
95 |
|
96 |
private static Image iNEResize = null; |
97 |
private static Image iEResize = null; |
98 |
private static Image iNResize = null; |
99 |
private static Image iMove = null; |
100 |
private static Image iSEResize = null; |
101 |
|
102 |
protected LayoutManager layoutManager = null; |
103 |
protected LayoutContext layoutContext = null; |
104 |
protected LayoutControl layoutControl = null; |
105 |
|
106 |
protected ObservableHelper observers;
|
107 |
|
108 |
public FFrame() {
|
109 |
super();
|
110 |
layoutManager = |
111 |
(LayoutManager) ProjectManager.getInstance().getDocumentManager(
|
112 |
DefaultLayoutManager.TYPENAME); |
113 |
observers = new ObservableHelper();
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
118 |
* par�metro.
|
119 |
*
|
120 |
* @param g
|
121 |
* Graphics sobre el que dibujar.
|
122 |
*/
|
123 |
public void drawHandlers(Graphics2D g) { |
124 |
int size = 10; |
125 |
Rectangle2D r = getBoundingBox(null); |
126 |
Point2D p = new Point2D.Double(); |
127 |
g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
128 |
r.getY() + (r.getHeight() / 2));
|
129 |
|
130 |
AffineTransform atRotate = new AffineTransform(); |
131 |
atRotate.rotate(Math.toRadians(getRotation()), r.getX()
|
132 |
+ (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
133 |
|
134 |
g.fillRect((int) r.getX() - size, (int) r.getY() - size, size, size); |
135 |
atRotate.transform( |
136 |
new Point2D.Double(r.getX() - size, r.getY() - size), p); |
137 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
138 |
|
139 |
g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
140 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
141 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
142 |
|
143 |
g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
144 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
145 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
146 |
|
147 |
g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
148 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
149 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
150 |
|
151 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size, |
152 |
size, size); |
153 |
atRotate |
154 |
.transform(new Point2D.Double(r.getCenterX() - (size / 2), r.getY() |
155 |
- size), p); |
156 |
n.setRect((int) p.getX(), (int) p.getY(), size, size); |
157 |
|
158 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size, |
159 |
size); |
160 |
atRotate.transform( |
161 |
new Point2D.Double(r.getCenterX() - (size / 2), r.getMaxY()), p); |
162 |
s.setRect((int) p.getX(), (int) p.getY(), size, size); |
163 |
|
164 |
g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2), |
165 |
size, size); |
166 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getCenterY() |
167 |
- (size / 2)), p);
|
168 |
o.setRect((int) p.getX(), (int) p.getY(), size, size); |
169 |
|
170 |
g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size, |
171 |
size); |
172 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getCenterY() |
173 |
- (size / 2)), p);
|
174 |
e.setRect((int) p.getX(), (int) p.getY(), size, size); |
175 |
g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
176 |
r.getY() + (r.getHeight() / 2));
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Establece que tipo de selecci�n se realiza sobre el fframe.
|
181 |
*
|
182 |
* @param p
|
183 |
* punto sobre el que se debe de establecer si se selecciona o no
|
184 |
* el fframe.
|
185 |
*/
|
186 |
public void setSelected(Point2D p, MouseEvent e) { |
187 |
m_Selected = getContains(p); |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Actualiza el BoundBox del FFrame a partir de su rect�ngulo en pixels y
|
192 |
* la matriz de transformaci�n.
|
193 |
*
|
194 |
* @param r
|
195 |
* Rect�ngulo.
|
196 |
* @param at
|
197 |
* Matriz de transformaci�n.
|
198 |
*/
|
199 |
public void updateRect(Rectangle2D r, AffineTransform at) { |
200 |
Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
|
201 |
rec.setRect((int) rec.getMinX(), (int) rec.getMinY(), |
202 |
(int) rec.getWidth(), (int) rec.getHeight()); |
203 |
setBoundBox(rec); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Devuelve el rect�ngulo a partir del desplazamiento en el eje x y el
|
208 |
* desplazamiento en el eje y.
|
209 |
*
|
210 |
* @param difx
|
211 |
* desplazamiento sobre el eje x.
|
212 |
* @param dify
|
213 |
* desplazamiento sobre el eje y.
|
214 |
*
|
215 |
* @return rect�ngulo modificado en funci�n del desplazamiento
|
216 |
* realizado.
|
217 |
*/
|
218 |
public Rectangle2D getMovieRect(int difx, int dify) { |
219 |
double x = 0; |
220 |
double y = 0; |
221 |
double w = 0; |
222 |
double h = 0; |
223 |
|
224 |
lastMoveRect = |
225 |
new Rectangle2D.Double(this.getBoundingBox(null).x, |
226 |
this.getBoundingBox(null).y, this.getBoundingBox(null).width, |
227 |
this.getBoundingBox(null).height); |
228 |
Rectangle2D.Double rec = this.getBoundingBox(null); |
229 |
int difn = 0; |
230 |
difn = difx; |
231 |
x = lastMoveRect.getX(); |
232 |
y = lastMoveRect.getY(); |
233 |
w = lastMoveRect.getWidth(); |
234 |
h = lastMoveRect.getHeight(); |
235 |
|
236 |
switch (this.getSelected()) { |
237 |
case (RECT):
|
238 |
lastMoveRect.setRect((x + difx), (y + dify), w, h); |
239 |
|
240 |
break;
|
241 |
|
242 |
case (N):
|
243 |
|
244 |
if ((y + dify) > rec.getMaxY()) {
|
245 |
y = rec.getMaxY(); |
246 |
} else {
|
247 |
y = y + dify; |
248 |
} |
249 |
|
250 |
lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
|
251 |
|
252 |
break;
|
253 |
|
254 |
case (O):
|
255 |
|
256 |
if ((x + difx) > rec.getMaxX()) {
|
257 |
x = rec.getMaxX(); |
258 |
} else {
|
259 |
x = x + difx; |
260 |
} |
261 |
|
262 |
lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
|
263 |
|
264 |
break;
|
265 |
|
266 |
case (S):
|
267 |
|
268 |
if (y > (rec.getMaxY() + dify)) {
|
269 |
y = rec.getMaxY() + dify; |
270 |
} |
271 |
|
272 |
lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
|
273 |
|
274 |
break;
|
275 |
|
276 |
case (E):
|
277 |
|
278 |
if (x > (rec.getMaxX() + difx)) {
|
279 |
x = rec.getMaxX() + difx; |
280 |
} |
281 |
|
282 |
lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
|
283 |
|
284 |
break;
|
285 |
|
286 |
case (NE):
|
287 |
|
288 |
if ((y - difn) > rec.getMaxY()) {
|
289 |
y = rec.getMaxY(); |
290 |
x = rec.getMaxX() + difn; |
291 |
} else {
|
292 |
y = y - difn; |
293 |
} |
294 |
|
295 |
lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
296 |
|
297 |
break;
|
298 |
|
299 |
case (NO):
|
300 |
|
301 |
if ((y + difn) > rec.getMaxY()) {
|
302 |
y = rec.getMaxY(); |
303 |
x = rec.getMaxX(); |
304 |
} else {
|
305 |
x = x + difn; |
306 |
y = y + difn; |
307 |
} |
308 |
|
309 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
310 |
|
311 |
break;
|
312 |
|
313 |
case (SE):
|
314 |
|
315 |
if (y > (rec.getMaxY() + difn)) {
|
316 |
y = rec.getMaxY() + difn; |
317 |
x = rec.getMaxX() + difn; |
318 |
} |
319 |
|
320 |
lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
321 |
|
322 |
break;
|
323 |
|
324 |
case (SO):
|
325 |
|
326 |
if ((x + difn) > rec.getMaxX()) {
|
327 |
x = rec.getMaxX(); |
328 |
y = rec.getMaxY() - difn; |
329 |
} else {
|
330 |
x = x + difn; |
331 |
} |
332 |
|
333 |
lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
334 |
|
335 |
break;
|
336 |
|
337 |
default:
|
338 |
lastMoveRect.setRect((x), (y), w, h); |
339 |
} |
340 |
|
341 |
return lastMoveRect;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* Devuelve el rect�ngulo que representa el �ltimo generado al desplazar
|
346 |
* o modificar el tama�o del fframe.
|
347 |
*
|
348 |
* @return Rectangle2D
|
349 |
*
|
350 |
*/
|
351 |
public Rectangle2D getLastMoveRect() { |
352 |
return lastMoveRect;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* Devuelve un entero que representa el tipo de selecci�n que se ha
|
357 |
* realizado sobre el fframe.
|
358 |
*
|
359 |
* @return tipo de selecci�n que se ha realizado.
|
360 |
*/
|
361 |
public int getSelected() { |
362 |
return m_Selected;
|
363 |
} |
364 |
|
365 |
public boolean isSelected() { |
366 |
return getSelected()!=IFFrame.NOSELECT;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Devuelve true, si el punto que se pasa como par�metro esta contenido
|
371 |
* dentro del boundingbox del fframe.
|
372 |
*
|
373 |
* @param p
|
374 |
* punto a comprobar.
|
375 |
*
|
376 |
* @return true si el punto esta dentro del boundingbox.
|
377 |
*/
|
378 |
public boolean contains(Point2D p) { |
379 |
return getBoundingBox(null).contains(p.getX(), p.getY()); |
380 |
} |
381 |
|
382 |
/**
|
383 |
* Devuelve un entero que representa donde esta contenido el punto que se
|
384 |
* pasa como par�metro.
|
385 |
*
|
386 |
* @param p
|
387 |
* punto a comparar.
|
388 |
*
|
389 |
* @return entero que representa como esta contenido el punto.
|
390 |
*/
|
391 |
public int getContains(Point2D p) { |
392 |
if (n.contains(p.getX(), p.getY())) {
|
393 |
return N;
|
394 |
} else
|
395 |
if (ne.contains(p.getX(), p.getY())) {
|
396 |
return NE;
|
397 |
} else
|
398 |
if (e.contains(p.getX(), p.getY())) {
|
399 |
return E;
|
400 |
} else
|
401 |
if (se.contains(p.getX(), p.getY())) {
|
402 |
return SE;
|
403 |
} else
|
404 |
if (s.contains(p.getX(), p.getY())) {
|
405 |
return S;
|
406 |
} else
|
407 |
if (so.contains(p.getX(), p.getY())) {
|
408 |
return SO;
|
409 |
} else
|
410 |
if (o.contains(p.getX(), p.getY())) {
|
411 |
return O;
|
412 |
} else
|
413 |
if (no.contains(p.getX(), p.getY())) {
|
414 |
return NO;
|
415 |
} else
|
416 |
if (getBoundingBox(null).contains( |
417 |
p.getX(), p.getY())) { |
418 |
return RECT;
|
419 |
} |
420 |
|
421 |
return NOSELECT;
|
422 |
} |
423 |
|
424 |
/**
|
425 |
* Devuelve el Cursor adecuado seg�n como est� contenido el punto, si es
|
426 |
* para desplazamiento, o cambio de tama�o.
|
427 |
*
|
428 |
* @param p
|
429 |
* punto a comprobar.
|
430 |
*
|
431 |
* @return Cursor adecuado a la posici�n.
|
432 |
*/
|
433 |
public Image getMapCursor(Point2D p) { |
434 |
int select = getContains(p);
|
435 |
|
436 |
switch (select) {
|
437 |
case (N):
|
438 |
return iNResize;
|
439 |
|
440 |
case (NE):
|
441 |
return iNEResize;
|
442 |
|
443 |
case (E):
|
444 |
return iEResize;
|
445 |
|
446 |
case (SE):
|
447 |
return iSEResize;
|
448 |
|
449 |
case (S):
|
450 |
return iNResize;
|
451 |
|
452 |
case (SO):
|
453 |
return iNEResize;
|
454 |
|
455 |
case (O):
|
456 |
return iEResize;
|
457 |
|
458 |
case (NO):
|
459 |
return iSEResize;
|
460 |
|
461 |
case (RECT):
|
462 |
return iMove;
|
463 |
} |
464 |
|
465 |
return null; |
466 |
} |
467 |
|
468 |
/**
|
469 |
* Este m�todo se implementa en cada una de las fframe, ya que cada una se
|
470 |
* dibuja de una forma diferente sobre el graphics. M�todo que dibuja
|
471 |
* sobre el graphics que se le pasa como par�metro, seg�n la
|
472 |
* transformada
|
473 |
* afin que se debe de aplicar y el rect�ngulo que se debe de dibujar.
|
474 |
* M�todo que dibuja sobre el graphics que se le pasa como par�metro,
|
475 |
* seg�n la transformada afin que se debe de aplicar y el rect�ngulo que
|
476 |
* se debe de dibujar.
|
477 |
*
|
478 |
* @param g
|
479 |
* Graphics
|
480 |
* @param at
|
481 |
* Transformada afin.
|
482 |
* @param r
|
483 |
* rect�ngulo sobre el que hacer un clip.
|
484 |
* @param imgBase
|
485 |
* DOCUMENT ME!
|
486 |
*/
|
487 |
public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r, |
488 |
BufferedImage imgBase);
|
489 |
|
490 |
/**
|
491 |
* Returns the bounding box (in pixels) of this FFrame, based on the provided
|
492 |
* AffineTransform. If the AffineTransform is null, it returns the last
|
493 |
* calculated bounding box.
|
494 |
*
|
495 |
* @param at Affine transform to apply to the sheet coordinates to get the
|
496 |
* bounding box in pixels.
|
497 |
* @return Rectangle representing the bounding box (in pixels) of this
|
498 |
* FFrame
|
499 |
*/
|
500 |
public Rectangle2D.Double getBoundingBox(AffineTransform at) { |
501 |
if (at != null) { |
502 |
lastAT = (AffineTransform) at.clone();
|
503 |
} |
504 |
return FLayoutUtilities.fromSheetRect(m_BoundBox, lastAT);
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* Rellena con el rect�ngulo que se pasa como par�metro el boundBox(en
|
509 |
* cent�metros) del fframe del cual con una transformaci�n se podr�
|
510 |
* calcular el BoundingBox (en pixels).
|
511 |
*
|
512 |
* @param r
|
513 |
* Rect�ngulo en cent�metros.
|
514 |
*/
|
515 |
public void setBoundBox(Rectangle2D r) { |
516 |
if (r == null) { |
517 |
LOG.info("Warning: BBOX set to NULL in FFrame!");
|
518 |
m_BoundBox = null;
|
519 |
} else {
|
520 |
m_BoundBox = new Rectangle2D.Double(r.getX(), r.getY(), |
521 |
r.getWidth(), r.getHeight()); |
522 |
} |
523 |
} |
524 |
|
525 |
/**
|
526 |
* Returns the bounding box in centimeters of this FFrame
|
527 |
* Returns the rectangle that represents the FFrame in centimeters.
|
528 |
*
|
529 |
* @return The bounding box of this FFrame, measured in centimeters.
|
530 |
*/
|
531 |
public Rectangle2D.Double getBoundBox() { |
532 |
return m_BoundBox;
|
533 |
} |
534 |
|
535 |
/**
|
536 |
* Pasando como par�metro true, se toma como que esta seleccionado el
|
537 |
* fframe y si es false como que esta sin seleccionar, de esta forma se
|
538 |
* selecciona un fframe directamente sin comprobar si un punto esta
|
539 |
* contenido en �l.
|
540 |
*
|
541 |
* @param b
|
542 |
* true si se quiere seleccionar y false si se quiere
|
543 |
* deseleccionar.
|
544 |
*/
|
545 |
public void setSelected(boolean b) { |
546 |
if (b) {
|
547 |
m_Selected = RECT; |
548 |
} else {
|
549 |
m_Selected = IFFrame.NOSELECT; |
550 |
} |
551 |
} |
552 |
|
553 |
/**
|
554 |
* Dibuja sobre el graphics el rect�ngulo del fframe en modo borrador.
|
555 |
*
|
556 |
* @param g
|
557 |
* Graphics so bre el que dibujar.
|
558 |
*/
|
559 |
public void drawDraft(Graphics2D g) { |
560 |
Rectangle2D r = getBoundingBox(null); |
561 |
|
562 |
g.setColor(Color.lightGray);
|
563 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
564 |
(int) r.getHeight());
|
565 |
g.setColor(Color.black);
|
566 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth() - 1, |
567 |
(int) r.getHeight() - 1); |
568 |
int scale = (int) (r.getWidth() / 12); |
569 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
570 |
g.setFont(f); |
571 |
g.drawString(getName(), |
572 |
(int) (r.getCenterX() - ((getName().length() * scale) / 4)), |
573 |
(int) (r.getCenterY()));
|
574 |
} |
575 |
|
576 |
/**
|
577 |
* Rellena con el n�mero de FFrame.
|
578 |
*
|
579 |
* @param i
|
580 |
* n�mero
|
581 |
*/
|
582 |
public void setNum(int i) { |
583 |
num = i; |
584 |
} |
585 |
|
586 |
/**
|
587 |
* Draws the FFrame rectangle on the provided Graphics2D, only showing the
|
588 |
* FFrame name on an empty rectangle.
|
589 |
*
|
590 |
* @param g The graphics to draw on
|
591 |
*/
|
592 |
public void drawEmpty(Graphics2D g) { |
593 |
Rectangle2D r = getBoundingBox(null); |
594 |
g.setColor(Color.lightGray);
|
595 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
596 |
(int) r.getHeight());
|
597 |
g.setColor(Color.darkGray);
|
598 |
g.setStroke(new BasicStroke(2)); |
599 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
600 |
(int) r.getHeight());
|
601 |
g.setColor(Color.black);
|
602 |
|
603 |
int scale = (int) (r.getWidth() / 12); |
604 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
605 |
g.setFont(f); |
606 |
|
607 |
String s =
|
608 |
this.getNameFFrame() + " " + PluginServices.getText(this, "vacia"); |
609 |
|
610 |
g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)), |
611 |
(int) (r.getCenterY()));
|
612 |
} |
613 |
|
614 |
/**
|
615 |
* Devuelve true si el rect�ngulo primero es null o si es distinto de null
|
616 |
* e intersecta.
|
617 |
*
|
618 |
* @param rv
|
619 |
* Rect�ngulo
|
620 |
* @param r
|
621 |
* Rect�ngulo
|
622 |
*
|
623 |
* @return True si intersecta o es null.
|
624 |
*/
|
625 |
public boolean intersects(Rectangle2D rv, Rectangle2D r) { |
626 |
return (((rv != null) && rv.intersects(r)) || (rv == null)); |
627 |
} |
628 |
|
629 |
/**
|
630 |
* Rellena el tag del FFrame.
|
631 |
*
|
632 |
* @param s
|
633 |
* String que representa el valor a guardar en el tag.
|
634 |
*/
|
635 |
public void setTag(String s) { |
636 |
tag = s; |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Devuelve el tag.
|
641 |
*
|
642 |
* @return tag.
|
643 |
*/
|
644 |
public String getTag() { |
645 |
return tag;
|
646 |
} |
647 |
|
648 |
/**
|
649 |
* Dibuja sobre el graphics que se pasa como par�metro el icono que
|
650 |
* representa que contiene un tag.
|
651 |
*
|
652 |
* @param g
|
653 |
* Graphics sobre el que dibujar el icono.
|
654 |
*/
|
655 |
public void drawSymbolTag(Graphics2D g) { |
656 |
Rectangle2D rec = getBoundingBox(null); |
657 |
g.rotate(Math.toRadians(getRotation()), rec.getX()
|
658 |
+ (rec.getWidth() / 2), rec.getY() + (rec.getHeight() / 2)); |
659 |
|
660 |
try {
|
661 |
Image image =
|
662 |
PluginServices.getIconTheme().get("symboltag-icon").getImage();
|
663 |
g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30, |
664 |
30, null); |
665 |
} catch (NullPointerException npe) { |
666 |
} |
667 |
|
668 |
g.rotate(Math.toRadians(-getRotation()), rec.getX()
|
669 |
+ (rec.getWidth() / 2), rec.getY() + (rec.getHeight() / 2)); |
670 |
} |
671 |
|
672 |
/**
|
673 |
* Rellenar la rotaci�n para aplicar al FFrame.
|
674 |
*
|
675 |
* @param rotation
|
676 |
* rotaci�n que se quiere aplicar.
|
677 |
*/
|
678 |
public void setRotation(double rotation) { |
679 |
m_rotation = rotation; |
680 |
} |
681 |
|
682 |
/**
|
683 |
* Devuelve la rotaci�n del FFrame.
|
684 |
*
|
685 |
* @return Rotaci�n del FFrame.
|
686 |
*/
|
687 |
public double getRotation() { |
688 |
return m_rotation;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* Devuelve el nivel en el que se encuentra el FFrame.
|
693 |
*
|
694 |
* @return nivel
|
695 |
*/
|
696 |
public int getLevel() { |
697 |
return level;
|
698 |
} |
699 |
|
700 |
/**
|
701 |
* Inserta el nivel al que se encuentra el FFrame.
|
702 |
*
|
703 |
* @param l
|
704 |
* entero que refleja el nivel del FFrame.
|
705 |
*/
|
706 |
public void setLevel(int l) { |
707 |
level = l; |
708 |
} |
709 |
|
710 |
@Override
|
711 |
public Object clone() throws CloneNotSupportedException { |
712 |
IFFrame frame = (IFFrame) super.clone();
|
713 |
frame.setBoundBox(this.getBoundBox());
|
714 |
return frame;
|
715 |
} |
716 |
|
717 |
public void setFrameFactory(FrameFactory flf) { |
718 |
frameFactory = flf; |
719 |
} |
720 |
|
721 |
public FrameFactory getFrameFactory() {
|
722 |
return frameFactory;
|
723 |
} |
724 |
|
725 |
/**
|
726 |
* Initilizes the static icons
|
727 |
*/
|
728 |
public static void initializeIcons() { |
729 |
iNEResize = |
730 |
PluginServices.getIconTheme().get("neresize-icon").getImage();
|
731 |
iEResize = PluginServices.getIconTheme().get("eresize-icon").getImage();
|
732 |
iNResize = PluginServices.getIconTheme().get("nresize-icon").getImage();
|
733 |
iMove = PluginServices.getIconTheme().get("graphic-move-icon").getImage();
|
734 |
iSEResize = |
735 |
PluginServices.getIconTheme().get("sereresize-icon").getImage();
|
736 |
} |
737 |
|
738 |
public static void registerPersistent() { |
739 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
740 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
741 |
DynStruct definition = |
742 |
manager.addDefinition(FFrame.class, |
743 |
PERSISTENCE_DEFINITION_NAME, |
744 |
"FFrame persistence definition", null, null); |
745 |
|
746 |
definition.addDynFieldObject(BOUNDINGBOX_FIELD) |
747 |
.setClassOfValue(Rectangle2D.class).setMandatory(true); |
748 |
definition.addDynFieldInt(SELECTED_FIELD).setMandatory(true);
|
749 |
definition.addDynFieldString(TAG_FIELD).setMandatory(false);
|
750 |
definition.addDynFieldDouble(ROTATION_FIELD).setMandatory(true);
|
751 |
definition.addDynFieldInt(LEVEL_FIELD).setMandatory(true);
|
752 |
definition.addDynFieldInt(NUM_FIELD).setMandatory(true);
|
753 |
} |
754 |
|
755 |
Attributes.registerPersistent();
|
756 |
AbstractFFrameViewDependence.registerPersistent(); |
757 |
FFrameBasic.registerPersistent(); |
758 |
FFrameGraphics.registerPersistent(); |
759 |
FFrameSymbol.registerPersistent(); |
760 |
FFrameGrid.registerPersistent(); |
761 |
FFrameGroup.registerPersistent(); |
762 |
FFrameTable.registerPersistent(); |
763 |
FFrameLegend.registerPersistent(); |
764 |
FFramePicture.registerPersistent(); |
765 |
FFrameNorth.registerPersistent(); |
766 |
FFrameScaleBar.registerPersistent(); |
767 |
FFrameText.registerPersistent(); |
768 |
FFrameView.registerPersistent(); |
769 |
FFrameOverView.registerPersistent(); |
770 |
} |
771 |
|
772 |
public void loadFromState(PersistentState state) |
773 |
throws PersistenceException {
|
774 |
m_BoundBox = (Rectangle2D.Double) state.get(BOUNDINGBOX_FIELD);
|
775 |
m_Selected = state.getInt(SELECTED_FIELD); |
776 |
tag = state.getString(TAG_FIELD); |
777 |
m_rotation = state.getDouble(ROTATION_FIELD); |
778 |
level = state.getInt(LEVEL_FIELD); |
779 |
num = state.getInt(NUM_FIELD); |
780 |
} |
781 |
|
782 |
public void saveToState(PersistentState state) throws PersistenceException { |
783 |
state.set(BOUNDINGBOX_FIELD, getBoundBox()); |
784 |
state.set(SELECTED_FIELD, m_Selected); |
785 |
state.set(TAG_FIELD, getTag()); |
786 |
state.set(ROTATION_FIELD, getRotation()); |
787 |
state.set(LEVEL_FIELD, getLevel()); |
788 |
state.set(NUM_FIELD, num); |
789 |
} |
790 |
|
791 |
public void addObserver(Observer o) { |
792 |
observers.addObserver(o); |
793 |
} |
794 |
|
795 |
public void deleteObserver(Observer o) { |
796 |
observers.deleteObserver(o); |
797 |
} |
798 |
|
799 |
public void deleteObservers() { |
800 |
observers.deleteObservers(); |
801 |
} |
802 |
|
803 |
/*
|
804 |
* (non-Javadoc)
|
805 |
* @see org.gvsig.tools.dispose.Disposable#dispose()
|
806 |
*/
|
807 |
public void dispose() { |
808 |
|
809 |
} |
810 |
} |