Statistics
| Revision:

svn-document-layout / tags / 2059 / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrame.java @ 46

History | View | Annotate | Download (24.9 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.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

    
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.app.project.ProjectManager;
41
import org.gvsig.app.project.documents.layout.Attributes;
42
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
43
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
44
import org.gvsig.app.project.documents.layout.LayoutContext;
45
import org.gvsig.app.project.documents.layout.LayoutControl;
46
import org.gvsig.app.project.documents.layout.LayoutManager;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynobject.DynStruct;
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

    
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
    /**
366
     * Devuelve true, si el punto que se pasa como par�metro esta contenido
367
     * dentro del boundingbox del fframe.
368
     * 
369
     * @param p
370
     *            punto a comprobar.
371
     * 
372
     * @return true si el punto esta dentro del boundingbox.
373
     */
374
    public boolean contains(Point2D p) {
375
        return getBoundingBox(null).contains(p.getX(), p.getY());
376
    }
377

    
378
    /**
379
     * Devuelve un entero que representa donde esta contenido el punto que se
380
     * pasa como par�metro.
381
     * 
382
     * @param p
383
     *            punto a comparar.
384
     * 
385
     * @return entero que representa como esta contenido el punto.
386
     */
387
    public int getContains(Point2D p) {
388
        if (n.contains(p.getX(), p.getY())) {
389
            return N;
390
        } else
391
            if (ne.contains(p.getX(), p.getY())) {
392
                return NE;
393
            } else
394
                if (e.contains(p.getX(), p.getY())) {
395
                    return E;
396
                } else
397
                    if (se.contains(p.getX(), p.getY())) {
398
                        return SE;
399
                    } else
400
                        if (s.contains(p.getX(), p.getY())) {
401
                            return S;
402
                        } else
403
                            if (so.contains(p.getX(), p.getY())) {
404
                                return SO;
405
                            } else
406
                                if (o.contains(p.getX(), p.getY())) {
407
                                    return O;
408
                                } else
409
                                    if (no.contains(p.getX(), p.getY())) {
410
                                        return NO;
411
                                    } else
412
                                        if (getBoundingBox(null).contains(
413
                                            p.getX(), p.getY())) {
414
                                            return RECT;
415
                                        }
416

    
417
        return NOSELECT;
418
    }
419

    
420
    /**
421
     * Devuelve el Cursor adecuado seg�n como est� contenido el punto, si es
422
     * para desplazamiento, o cambio de tama�o.
423
     * 
424
     * @param p
425
     *            punto a comprobar.
426
     * 
427
     * @return Cursor adecuado a la posici�n.
428
     */
429
    public Image getMapCursor(Point2D p) {
430
        int select = getContains(p);
431

    
432
        switch (select) {
433
        case (N):
434
            return iNResize;
435

    
436
        case (NE):
437
            return iNEResize;
438

    
439
        case (E):
440
            return iEResize;
441

    
442
        case (SE):
443
            return iSEResize;
444

    
445
        case (S):
446
            return iNResize;
447

    
448
        case (SO):
449
            return iNEResize;
450

    
451
        case (O):
452
            return iEResize;
453

    
454
        case (NO):
455
            return iSEResize;
456

    
457
        case (RECT):
458
            return iMove;
459
        }
460

    
461
        return null;
462
    }
463

    
464
    /**
465
     * Este m�todo se implementa en cada una de las fframe, ya que cada una se
466
     * dibuja de una forma diferente sobre el graphics. M�todo que dibuja
467
     * sobre el graphics que se le pasa como par�metro, seg�n la
468
     * transformada
469
     * afin que se debe de aplicar y el rect�ngulo que se debe de dibujar.
470
     * M�todo que dibuja sobre el graphics que se le pasa como par�metro,
471
     * seg�n la transformada afin que se debe de aplicar y el rect�ngulo que
472
     * se debe de dibujar.
473
     * 
474
     * @param g
475
     *            Graphics
476
     * @param at
477
     *            Transformada afin.
478
     * @param r
479
     *            rect�ngulo sobre el que hacer un clip.
480
     * @param imgBase
481
     *            DOCUMENT ME!
482
     */
483
    public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r,
484
        BufferedImage imgBase);
485

    
486
    /**
487
     * Devuelve el boundingBox del fframe en funci�n de la transformada af�n
488
     * que se pasa como par�metro. Si se pasa como par�metro null, devuelve
489
     * el
490
     * �ltimo boundingbox que se calcul�.
491
     * 
492
     * @param at
493
     *            Transformada af�n
494
     * 
495
     * @return Rect�ngulo que representa el BoundingBox del fframe.
496
     */
497
    public Rectangle2D.Double getBoundingBox(AffineTransform at) {
498
        if (at != null) {
499
            lastAT = (AffineTransform) at.clone();
500
        }
501
        return FLayoutUtilities.fromSheetRect(m_BoundBox, lastAT);
502
    }
503

    
504
    /**
505
     * Rellena con el rect�ngulo que se pasa como par�metro el boundBox(en
506
     * cent�metros) del fframe del cual con una transformaci�n se podr�
507
     * calcular el BoundingBox (en pixels).
508
     * 
509
     * @param r
510
     *            Rect�ngulo en cent�metros.
511
     */
512
    public void setBoundBox(Rectangle2D r) {
513
        if (r == null) {
514
            LOG.info("Warning: BBOX set to NULL in FFrame!");
515
            m_BoundBox = null;
516
        } else {
517
            m_BoundBox = new Rectangle2D.Double(r.getX(), r.getY(),
518
                r.getWidth(), r.getHeight());
519
        }
520
    }
521

    
522
    /**
523
     * Devuelve el rect�ngulo que representa el fframe en cent�metros.
524
     * 
525
     * @return Rect�ngulo en centimetros.
526
     */
527
    public Rectangle2D.Double getBoundBox() {
528
        return m_BoundBox;
529
    }
530

    
531
    /**
532
     * Pasando como par�metro true, se toma como que esta seleccionado el
533
     * fframe y si es false como que esta sin seleccionar, de esta forma se
534
     * selecciona un fframe directamente sin comprobar si un punto esta
535
     * contenido en �l.
536
     * 
537
     * @param b
538
     *            true si se quiere seleccionar y false si se quiere
539
     *            deseleccionar.
540
     */
541
    public void setSelected(boolean b) {
542
        if (b) {
543
            m_Selected = RECT;
544
        } else {
545
            m_Selected = IFFrame.NOSELECT;
546
        }
547
    }
548

    
549
    /**
550
     * Dibuja sobre el graphics el rect�ngulo del fframe en modo borrador.
551
     * 
552
     * @param g
553
     *            Graphics so bre el que dibujar.
554
     */
555
    public void drawDraft(Graphics2D g) {
556
        Rectangle2D r = getBoundingBox(null);
557

    
558
        g.setColor(Color.lightGray);
559
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
560
            (int) r.getHeight());
561
        g.setColor(Color.black);
562
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth() - 1,
563
            (int) r.getHeight() - 1);
564
        int scale = (int) (r.getWidth() / 12);
565
        Font f = new Font("SansSerif", Font.PLAIN, scale);
566
        g.setFont(f);
567
        g.drawString(getName(),
568
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
569
            (int) (r.getCenterY()));
570
    }
571

    
572
    /**
573
     * Rellena con el n�mero de FFrame.
574
     * 
575
     * @param i
576
     *            n�mero
577
     */
578
    public void setNum(int i) {
579
        num = i;
580
    }
581

    
582
    /**
583
     * Dibuja sobre el graphics el rect�ngulo del fframe pero vacio, mostrando
584
     * el nombre del fframe y vacio.
585
     * 
586
     * @param g
587
     *            Graphics sobre el que dibujar.
588
     */
589
    public void drawEmpty(Graphics2D g) {
590
        Rectangle2D r = getBoundingBox(null);
591
        g.setColor(Color.lightGray);
592
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
593
            (int) r.getHeight());
594
        g.setColor(Color.darkGray);
595
        g.setStroke(new BasicStroke(2));
596
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
597
            (int) r.getHeight());
598
        g.setColor(Color.black);
599

    
600
        int scale = (int) (r.getWidth() / 12);
601
        Font f = new Font("SansSerif", Font.PLAIN, scale);
602
        g.setFont(f);
603

    
604
        String s =
605
            this.getNameFFrame() + " " + PluginServices.getText(this, "vacia");
606

    
607
        g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)),
608
            (int) (r.getCenterY()));
609
    }
610

    
611
    /**
612
     * Devuelve true si el rect�ngulo primero es null o si es distinto de null
613
     * e intersecta.
614
     * 
615
     * @param rv
616
     *            Rect�ngulo
617
     * @param r
618
     *            Rect�ngulo
619
     * 
620
     * @return True si intersecta o es null.
621
     */
622
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
623
        return (((rv != null) && rv.intersects(r)) || (rv == null));
624
    }
625

    
626
    /**
627
     * Rellena el tag del FFrame.
628
     * 
629
     * @param s
630
     *            String que representa el valor a guardar en el tag.
631
     */
632
    public void setTag(String s) {
633
        tag = s;
634
    }
635

    
636
    /**
637
     * Devuelve el tag.
638
     * 
639
     * @return tag.
640
     */
641
    public String getTag() {
642
        return tag;
643
    }
644

    
645
    /**
646
     * Dibuja sobre el graphics que se pasa como par�metro el icono que
647
     * representa que contiene un tag.
648
     * 
649
     * @param g
650
     *            Graphics sobre el que dibujar el icono.
651
     */
652
    public void drawSymbolTag(Graphics2D g) {
653
        Rectangle2D rec = getBoundingBox(null);
654
        g.rotate(Math.toRadians(getRotation()), rec.getX()
655
            + (rec.getWidth() / 2), rec.getY() + (rec.getHeight() / 2));
656

    
657
        try {
658
            Image image =
659
                PluginServices.getIconTheme().get("symboltag-icon").getImage();
660
            g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30,
661
                30, null);
662
        } catch (NullPointerException npe) {
663
        }
664

    
665
        g.rotate(Math.toRadians(-getRotation()), rec.getX()
666
            + (rec.getWidth() / 2), rec.getY() + (rec.getHeight() / 2));
667
    }
668

    
669
    /**
670
     * Rellenar la rotaci�n para aplicar al FFrame.
671
     * 
672
     * @param rotation
673
     *            rotaci�n que se quiere aplicar.
674
     */
675
    public void setRotation(double rotation) {
676
        m_rotation = rotation;
677
    }
678

    
679
    /**
680
     * Devuelve la rotaci�n del FFrame.
681
     * 
682
     * @return Rotaci�n del FFrame.
683
     */
684
    public double getRotation() {
685
        return m_rotation;
686
    }
687

    
688
    /**
689
     * Devuelve el nivel en el que se encuentra el FFrame.
690
     * 
691
     * @return nivel
692
     */
693
    public int getLevel() {
694
        return level;
695
    }
696

    
697
    /**
698
     * Inserta el nivel al que se encuentra el FFrame.
699
     * 
700
     * @param l
701
     *            entero que refleja el nivel del FFrame.
702
     */
703
    public void setLevel(int l) {
704
        level = l;
705
    }
706

    
707
    @Override
708
    public Object clone() throws CloneNotSupportedException {
709
        IFFrame frame = (IFFrame) super.clone();
710
        frame.setBoundBox(this.getBoundBox());
711
        return frame;
712
    }
713

    
714
    public void setFrameFactory(FrameFactory flf) {
715
        frameFactory = flf;
716
    }
717

    
718
    public FrameFactory getFrameFactory() {
719
        return frameFactory;
720
    }
721

    
722
    /**
723
     * Initilizes the static icons
724
     */
725
    public static void initializeIcons() {
726
        iNEResize =
727
            PluginServices.getIconTheme().get("neresize-icon").getImage();
728
        iEResize = PluginServices.getIconTheme().get("eresize-icon").getImage();
729
        iNResize = PluginServices.getIconTheme().get("nresize-icon").getImage();
730
        iMove = PluginServices.getIconTheme().get("move-icon").getImage();
731
        iSEResize =
732
            PluginServices.getIconTheme().get("sereresize-icon").getImage();
733
    }
734

    
735
    public static void registerPersistent() {
736
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
737
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
738
            DynStruct definition =
739
                manager.addDefinition(FFrame.class,
740
                    PERSISTENCE_DEFINITION_NAME,
741
                    "FFrame persistence definition", null, null);
742

    
743
            definition.addDynFieldObject(BOUNDINGBOX_FIELD)
744
                .setClassOfValue(Rectangle2D.class).setMandatory(true);
745
            definition.addDynFieldInt(SELECTED_FIELD).setMandatory(true);
746
            definition.addDynFieldString(TAG_FIELD).setMandatory(false);
747
            definition.addDynFieldDouble(ROTATION_FIELD).setMandatory(true);
748
            definition.addDynFieldInt(LEVEL_FIELD).setMandatory(true);
749
            definition.addDynFieldInt(NUM_FIELD).setMandatory(true);
750
        }
751

    
752
        Attributes.registerPersistent();
753
        AbstractFFrameViewDependence.registerPersistent();
754
        FFrameBasic.registerPersistent();
755
        FFrameGraphics.registerPersistent();
756
        FFrameSymbol.registerPersistent();
757
        FFrameGrid.registerPersistent();
758
        FFrameGroup.registerPersistent();
759
        FFrameTable.registerPersistent();
760
        FFrameLegend.registerPersistent();
761
        FFramePicture.registerPersistent();
762
        FFrameNorth.registerPersistent();
763
        FFrameScaleBar.registerPersistent();
764
        FFrameText.registerPersistent();
765
        FFrameView.registerPersistent();
766
        FFrameOverView.registerPersistent();
767
    }
768

    
769
    public void loadFromState(PersistentState state)
770
        throws PersistenceException {
771
        m_BoundBox = (Rectangle2D.Double) state.get(BOUNDINGBOX_FIELD);
772
        m_Selected = state.getInt(SELECTED_FIELD);
773
        tag = state.getString(TAG_FIELD);
774
        m_rotation = state.getDouble(ROTATION_FIELD);
775
        level = state.getInt(LEVEL_FIELD);
776
        num = state.getInt(NUM_FIELD);
777
    }
778

    
779
    public void saveToState(PersistentState state) throws PersistenceException {
780
        state.set(BOUNDINGBOX_FIELD, getBoundBox());
781
        state.set(SELECTED_FIELD, m_Selected);
782
        state.set(TAG_FIELD, getTag());
783
        state.set(ROTATION_FIELD, getRotation());
784
        state.set(LEVEL_FIELD, getLevel());
785
        state.set(NUM_FIELD, num);
786
    }
787

    
788
    public void addObserver(Observer o) {
789
        observers.addObserver(o);        
790
    }
791

    
792
    public void deleteObserver(Observer o) {
793
      observers.deleteObserver(o);        
794
    }
795

    
796
    public void deleteObservers() {
797
       observers.deleteObservers();        
798
    }
799
}