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