Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrame.java @ 4776

History | View | Annotate | Download (24.5 KB)

1
/*
2
 * Created on 17-may-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.gui.layout.fframes;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.messages.NotificationManager;
49

    
50
import com.iver.cit.gvsig.AddLayer;
51
import com.iver.cit.gvsig.ProjectExtension;
52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
54
import com.iver.cit.gvsig.gui.layout.Layout;
55
import com.iver.cit.gvsig.gui.layout.dialogs.Tag;
56
import com.iver.cit.gvsig.gui.project.OpenException;
57
import com.iver.cit.gvsig.gui.project.SaveException;
58
import com.iver.cit.gvsig.project.Project;
59

    
60
import com.iver.utiles.XMLEntity;
61

    
62
import java.awt.Color;
63
import java.awt.Cursor;
64
import java.awt.Font;
65
import java.awt.Graphics2D;
66
import java.awt.Image;
67
import java.awt.Rectangle;
68
import java.awt.event.MouseEvent;
69
import java.awt.geom.AffineTransform;
70
import java.awt.geom.Point2D;
71
import java.awt.geom.Rectangle2D;
72
import java.awt.image.BufferedImage;
73

    
74
import java.net.URL;
75

    
76
import javax.swing.ImageIcon;
77

    
78

    
79
/**
80
 * Clase que implementa la interface IFFrame con los m?todos por defecto de
81
 * todos los FFrames  que extenderan de este, dejando uno como m?todo
82
 * abstracto para implementar por todos los  FFrames para ser dibujados.
83
 *
84
 * @author Vicente Caballero Navarro
85
 */
86
public abstract class FFrame implements IFFrame {
87
    protected String m_name = "FFrame";
88
    private Rectangle2D.Double m_BoundBox = new Rectangle2D.Double();
89
    private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double();
90
    protected int m_Selected = 0;
91
    protected Rectangle n = new Rectangle();
92
    protected Rectangle ne = new Rectangle();
93
    protected Rectangle e = new Rectangle();
94
    protected Rectangle se = new Rectangle();
95
    protected Rectangle s = new Rectangle();
96
    protected Rectangle so = new Rectangle();
97
    protected Rectangle o = new Rectangle();
98
    protected Rectangle no = new Rectangle();
99
    private String tag = null;
100
    protected int num = 0;
101
    private double m_rotation = 0;
102
    private int level = -1;
103
        private Rectangle2D lastMoveRect;
104

    
105
    /**
106
     * Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
107
     * par?metro.
108
     *
109
     * @param g Graphics sobre el que dibujar.
110
     */
111
    public void drawHandlers(Graphics2D g) {
112
        int size = 10;
113
        Rectangle2D r = getBoundingBox(null);
114
        Point2D p = new Point2D.Double();
115
        g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2),
116
            r.getY() + (r.getHeight() / 2));
117

    
118
        AffineTransform atRotate = new AffineTransform();
119
        atRotate.rotate(Math.toRadians(getRotation()),
120
            r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2));
121

    
122
        g.fillRect((int) r.getX() - size, (int) r.getY() - size, size, size);
123
        atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() - size),
124
            p);
125
        no.setRect((int) p.getX(), (int) p.getY(), size, size);
126

    
127
        g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size);
128
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p);
129
        ne.setRect((int) p.getX(), (int) p.getY(), size, size);
130

    
131
        g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size);
132
        atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p);
133
        so.setRect((int) p.getX(), (int) p.getY(), size, size);
134

    
135
        g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size);
136
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p);
137
        se.setRect((int) p.getX(), (int) p.getY(), size, size);
138

    
139
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size,
140
            size, size);
141
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
142
                r.getY() - size), p);
143
        n.setRect((int) p.getX(), (int) p.getY(), size, size);
144

    
145
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size,
146
            size);
147
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
148
                r.getMaxY()), p);
149
        s.setRect((int) p.getX(), (int) p.getY(), size, size);
150

    
151
        g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2),
152
            size, size);
153
        atRotate.transform(new Point2D.Double(r.getX() - size,
154
                r.getCenterY() - (size / 2)), p);
155
        o.setRect((int) p.getX(), (int) p.getY(), size, size);
156

    
157
        g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size,
158
            size);
159
        atRotate.transform(new Point2D.Double(r.getMaxX(),
160
                r.getCenterY() - (size / 2)), p);
161
        e.setRect((int) p.getX(), (int) p.getY(), size, size);
162
        g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2),
163
            r.getY() + (r.getHeight() / 2));
164
    }
165

    
166
    /**
167
     * Establece que tipo de selecci?n se realiza sobre el fframe.
168
     *
169
     * @param p punto sobre el que se debe de establecer si se selecciona o no
170
     *        el fframe.
171
     */
172
    public void setSelected(Point2D.Double p,MouseEvent e) {
173
        m_Selected = getContains(p);
174
    }
175

    
176
    /**
177
     * Actualiza el BoundBox del FFrame a partir de su rect?ngulo en pixels y
178
     * la matriz de transformaci?n.
179
     *
180
     * @param r Rect?ngulo.
181
     * @param at Matriz de transformaci?n.
182
     */
183
    public void updateRect(Rectangle2D r, AffineTransform at) {
184
        Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
185
        rec.setRect((int) rec.getMinX(), (int) rec.getMinY(),
186
            (int) rec.getWidth(), (int) rec.getHeight());
187
        setBoundBox(rec);
188
    }
189

    
190
    /**
191
     * Devuelve el rect?ngulo a partir del desplazamiento en el eje x y el
192
     * desplazamiento en el eje y.
193
     *
194
     * @param difx desplazamiento sobre el eje x.
195
     * @param dify desplazamiento sobre el eje y.
196
     *
197
     * @return rect?ngulo modificado en funci?n del desplazamiento realizado.
198
     */
199
    public Rectangle2D getMovieRect(int difx, int dify) {
200
        double x = 0;
201
        double y = 0;
202
        double w = 0;
203
        double h = 0;
204

    
205
        lastMoveRect = new Rectangle2D.Double(this.getBoundingBox(
206
                    null).x, this.getBoundingBox(null).y,
207
                this.getBoundingBox(null).width,
208
                this.getBoundingBox(null).height);
209
        Rectangle2D.Double rec = this.getBoundingBox(null);
210
        int difn = 0;
211
        difn = difx;
212
        x = lastMoveRect.getX();
213
        y = lastMoveRect.getY();
214
        w = lastMoveRect.getWidth();
215
        h = lastMoveRect.getHeight();
216

    
217
        switch (this.getSelected()) {
218
            case (RECT):
219
                lastMoveRect.setRect((x + difx), (y + dify), w, h);
220

    
221
                break;
222

    
223
            case (N):
224

    
225
                if ((y + dify) > rec.getMaxY()) {
226
                    y = rec.getMaxY();
227
                } else {
228
                    y = y + dify;
229
                }
230

    
231
                lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
232

    
233
                break;
234

    
235
            case (O):
236

    
237
                if ((x + difx) > rec.getMaxX()) {
238
                    x = rec.getMaxX();
239
                } else {
240
                    x = x + difx;
241
                }
242

    
243
                lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
244

    
245
                break;
246

    
247
            case (S):
248

    
249
                if (y > (rec.getMaxY() + dify)) {
250
                    y = rec.getMaxY() + dify;
251
                }
252

    
253
                lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
254

    
255
                break;
256

    
257
            case (E):
258

    
259
                if (x > (rec.getMaxX() + difx)) {
260
                    x = rec.getMaxX() + difx;
261
                }
262

    
263
                lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
264

    
265
                break;
266

    
267
            case (NE):
268

    
269
                if ((y - difn) > rec.getMaxY()) {
270
                    y = rec.getMaxY();
271
                    x = rec.getMaxX() + difn;
272
                } else {
273
                    y = y - difn;
274
                }
275

    
276
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
277

    
278
                break;
279

    
280
            case (NO):
281

    
282
                if ((y + difn) > rec.getMaxY()) {
283
                    y = rec.getMaxY();
284
                    x = rec.getMaxX();
285
                } else {
286
                    x = x + difn;
287
                    y = y + difn;
288
                }
289

    
290
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
291

    
292
                break;
293

    
294
            case (SE):
295

    
296
                if (y > (rec.getMaxY() + difn)) {
297
                    y = rec.getMaxY() + difn;
298
                    x = rec.getMaxX() + difn;
299
                }
300

    
301
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
302

    
303
                break;
304

    
305
            case (SO):
306

    
307
                if ((x + difn) > rec.getMaxX()) {
308
                    x = rec.getMaxX();
309
                    y = rec.getMaxY() - difn;
310
                } else {
311
                    x = x + difn;
312
                }
313

    
314
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
315

    
316
                break;
317

    
318
            default:
319
                lastMoveRect.setRect((x), (y), w, h);
320
        }
321

    
322
        return lastMoveRect;
323
    }
324
    /**
325
     * Devuelve el rect?ngulo que representa el ?ltimo generado al desplazar o modificar el tama?o del fframe.
326
     *
327
     * @return Rectangle2D
328
     *
329
     */
330
    public Rectangle2D getLastMoveRect(){
331
            return lastMoveRect;
332
    }
333
    /**
334
     * Devuelve un entero que representa el tipo de selecci?n que se ha
335
     * realizado sobre el fframe.
336
     *
337
     * @return tipo de selecci?n que se ha realizado.
338
     */
339
    public int getSelected() {
340
        return m_Selected;
341
    }
342

    
343
    /**
344
     * Devuelve true, si el punto que se pasa como par?metro esta contenido
345
     * dentro del boundingbox del fframe.
346
     *
347
     * @param p punto a comprobar.
348
     *
349
     * @return true si el punto esta dentro del boundingbox.
350
     */
351
    public boolean contains(Point2D.Double p) {
352
        return getBoundingBox(null).contains(p.x, p.y);
353
    }
354

    
355
    /**
356
     * Devuelve un entero que representa donde esta contenido el punto que se
357
     * pasa como par?metro.
358
     *
359
     * @param p punto a comparar.
360
     *
361
     * @return entero que representa como esta contenido el punto.
362
     */
363
    public int getContains(Point2D.Double p) {
364
        if (n.contains(p.x, p.y)) {
365
            return N;
366
        } else if (ne.contains(p.x, p.y)) {
367
            return NE;
368
        } else if (e.contains(p.x, p.y)) {
369
            return E;
370
        } else if (e.contains(p.x, p.y)) {
371
            return E;
372
        } else if (se.contains(p.x, p.y)) {
373
            return SE;
374
        } else if (s.contains(p.x, p.y)) {
375
            return S;
376
        } else if (so.contains(p.x, p.y)) {
377
            return SO;
378
        } else if (o.contains(p.x, p.y)) {
379
            return O;
380
        } else if (no.contains(p.x, p.y)) {
381
            return NO;
382
        } else if (getBoundingBox(null).contains(p.x, p.y)) {
383
            return RECT;
384
        }
385

    
386
        return 0;
387
    }
388

    
389
    /**
390
     * Devuelve el Cursor adecuado seg?n como est? contenido el punto, si es
391
     * para desplazamiento, o cambio de tama?o.
392
     *
393
     * @param p punto a comprobar.
394
     *
395
     * @return Cursor adecuado a la posici?n.
396
     */
397
    public Cursor getMapCursor(Point2D.Double p) {
398
        int select = getContains(p);
399

    
400
        switch (select) {
401
            case (N):
402
                return Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
403

    
404
            case (NE):
405
                return Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
406

    
407
            case (E):
408
                return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
409

    
410
            case (SE):
411
                return Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
412

    
413
            case (S):
414
                return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
415

    
416
            case (SO):
417
                return Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
418

    
419
            case (O):
420
                return Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
421

    
422
            case (NO):
423
                return Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
424

    
425
            case (RECT):
426
                return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
427
        }
428

    
429
        return null;
430
    }
431

    
432
    /**
433
     * Este m?todo se implementa en cada una de las fframe, ya que cada una se
434
     * dibuja de una forma diferente sobre el graphics. M?todo que dibuja
435
     * sobre el graphics que se le pasa como par?metro, seg?n la transformada
436
     * afin que se debe de aplicar y el rect?ngulo que se debe de dibujar.
437
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro,
438
     * seg?n la transformada afin que se debe de aplicar y el rect?ngulo que
439
     * se debe de dibujar.
440
     *
441
     * @param g Graphics
442
     * @param at Transformada afin.
443
     * @param r rect?ngulo sobre el que hacer un clip.
444
     * @param imgBase DOCUMENT ME!
445
     *
446
     * @throws DriverException
447
     */
448
    public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r,
449
        BufferedImage imgBase) throws DriverException;
450

    
451
    /**
452
     * Devuelve el nombre que representa al fframe.
453
     *
454
     * @return String
455
     */
456
    public String getName() {
457
        return m_name;
458
    }
459

    
460
    /**
461
     * Rellena el String que representa al nombre del fframe.
462
     *
463
     * @param n nombre del fframe.
464
     */
465
    public void setName(String n) {
466
        m_name = n;
467
    }
468

    
469
    /**
470
     * Devuelve el boundingBox del fframe en funci?n de la transformada af?n
471
     * que se pasa como par?metro. Si se pasa como par?metro null, devuelve el
472
     * ?ltimo boundingbox que se calcul?.
473
     *
474
     * @param at Transformada af?n
475
     *
476
     * @return Rect?ngulo que representa el BoundingBox del fframe.
477
     */
478
    public Rectangle2D.Double getBoundingBox(AffineTransform at) {
479
        if (at == null) {
480
            return m_BoundingBox;
481
        }
482

    
483
        m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at);
484

    
485
        return m_BoundingBox;
486
    }
487

    
488
    /**
489
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
490
     * cent?metros) del fframe del cual con una transformaci?n se podr?
491
     * calcular el BoundingBox (en pixels).
492
     *
493
     * @param r Rect?ngulo en cent?metros.
494
     */
495
    public void setBoundBox(Rectangle2D r) {
496
        m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
497
    }
498

    
499
    /**
500
     * Devuelve el rect?ngulo que representa el fframe en cent?metros.
501
     *
502
     * @return Rect?ngulo en centimetros.
503
     */
504
    public Rectangle2D.Double getBoundBox() {
505
        return m_BoundBox;
506
    }
507

    
508
    /**
509
     * Pasando como par?metro true,  se toma como que esta seleccionado el
510
     * fframe  y si es false como que esta sin seleccionar,  de esta forma se
511
     * selecciona un fframe directamente  sin comprobar si un punto esta
512
     * contenido en ?l.
513
     *
514
     * @param b true si se quiere seleccionar y false si se quiere
515
     *        deseleccionar.
516
     */
517
    public void setSelected(boolean b) {
518
        if (b) {
519
            m_Selected = RECT;
520
        } else {
521
            m_Selected = IFFrame.NOSELECT;
522
        }
523
    }
524

    
525
    /**
526
     * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
527
     * del XMLEntity.
528
     *
529
     * @param xml XMLEntity
530
     * @param l Layout.
531
     * @param p Proyecto.
532
     *
533
     * @return Objeto de esta clase.
534
     */
535
    public static IFFrame createFFrame03(XMLEntity xml, Layout l, Project p) {
536
        IFFrame fframe = null;
537

    
538
        try {
539
            Class clase = Class.forName(xml.getStringProperty("className"));
540
            fframe = (IFFrame) clase.newInstance();
541
        } catch (Exception e) {
542
            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
543
                e);
544
        }
545

    
546
        if (fframe instanceof IFFrameUseProject) {
547
            ((IFFrameUseProject) fframe).setProject(p);
548
        }
549

    
550
        fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
551
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
552
                xml.getDoubleProperty("h")));
553
        fframe.setXMLEntity03(xml, l);
554
        fframe.setName(xml.getStringProperty("m_name"));
555

    
556
        fframe.setTag(xml.getStringProperty("tag"));
557

    
558
        return fframe;
559
    }
560

    
561
    /**
562
     * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
563
     * del XMLEntity.
564
     *
565
     * @param xml XMLEntity
566
     * @param p Proyecto.
567
     *
568
     * @return Objeto de esta clase.
569
     *
570
     * @throws OpenException DOCUMENT ME!
571
     */
572
    public static IFFrame createFFrame(XMLEntity xml, Project p)
573
        throws OpenException {
574
        IFFrame fframe = null;
575
        String className = "IFFrame";
576
        Class clase = null;
577

    
578
        try {
579
            className = xml.getStringProperty("className");
580
            clase = Class.forName(className);
581
        } catch (ClassNotFoundException e) {
582
            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
583
                e);
584
        }
585

    
586
        try {
587
            fframe = (IFFrame) clase.newInstance();
588
        } catch (InstantiationException e) {
589
            NotificationManager.addError("Fallo creando el Frame: " +
590
                clase.getName(), e);
591
        } catch (IllegalAccessException e) {
592
            NotificationManager.addError("Fallo creando el Frame: " +
593
                clase.getName(), e);
594
        }
595

    
596
        try {
597
            if (fframe instanceof IFFrameUseProject) {
598
                ((IFFrameUseProject) fframe).setProject(p);
599
            }
600

    
601
            fframe.setXMLEntity(xml);
602

    
603
            if (xml.contains("level")) {
604
                fframe.setLevel(xml.getIntProperty("level"));
605
            }
606

    
607
            fframe.setName(xml.getStringProperty("m_name"));
608
            fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
609
                    xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
610
                    xml.getDoubleProperty("h")));
611
            fframe.setTag(xml.getStringProperty("tag"));
612
        } catch (Exception e) {
613
            throw new OpenException(e, className);
614
        }
615

    
616
        return fframe;
617
    }
618

    
619
    /**
620
     * Dibuja sobre el graphics el rect?ngulo del fframe en modo borrador.
621
     *
622
     * @param g Graphics so bre el que dibujar.
623
     */
624
    public void drawDraft(Graphics2D g) {
625
        Rectangle2D r = getBoundingBox(null);
626

    
627
        g.setColor(Color.lightGray);
628
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
629
            (int) r.getHeight());
630
        g.setColor(Color.black);
631

    
632
        int scale = (int) (r.getWidth() / 12);
633
        Font f = new Font("SansSerif", Font.PLAIN, scale);
634
        g.setFont(f);
635
        g.drawString(getName(),
636
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
637
            (int) (r.getCenterY()));
638
    }
639

    
640
    /**
641
     * Rellena con el n?mero de FFrame.
642
     *
643
     * @param i n?mero
644
     */
645
    public void setNum(int i) {
646
        num = i;
647
    }
648

    
649
    /**
650
     * Dibuja sobre el graphics el rect?ngulo del fframe pero vacio, mostrando
651
     * el nombre del fframe y vacio.
652
     *
653
     * @param g Graphics sobre el que dibujar.
654
     */
655
    public void drawEmpty(Graphics2D g) {
656
        Rectangle2D r = getBoundingBox(null);
657
        g.setColor(Color.lightGray);
658
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
659
            (int) r.getHeight());
660
        g.setColor(Color.black);
661

    
662
        int scale = (int) (r.getWidth() / 12);
663
        Font f = new Font("SansSerif", Font.PLAIN, scale);
664
        g.setFont(f);
665

    
666
        String s = this.getNameFFrame() + " " +
667
            PluginServices.getText(this, "vacia");
668

    
669
        g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)),
670
            (int) (r.getCenterY()));
671
    }
672

    
673
    /**
674
     * Devuelve true si el rect?ngulo primero es null o si es distinto de null
675
     * e intersecta.
676
     *
677
     * @param rv Rect?ngulo
678
     * @param r Rect?ngulo
679
     *
680
     * @return True si intersecta o es null.
681
     */
682
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
683
        return (((rv != null) && rv.intersects(r)) || (rv == null));
684
    }
685

    
686
    /**
687
     * Abre el di?logo para cambiar o a?adir el tag.
688
     */
689
    public void openTag() {
690
        Tag tag = new Tag(this);
691
        PluginServices.getMDIManager().addView(tag);
692
    }
693

    
694
    /**
695
     * Rellena el tag del FFrame.
696
     *
697
     * @param s String que representa el valor a guardar en el tag.
698
     */
699
    public void setTag(String s) {
700
        tag = s;
701
    }
702

    
703
    /**
704
     * Devuelve el tag.
705
     *
706
     * @return tag.
707
     */
708
    public String getTag() {
709
        return tag;
710
    }
711

    
712
    /**
713
     * Dibuja sobre el graphics que se pasa como par?metro el icono que
714
     * representa que contiene un tag.
715
     *
716
     * @param g Graphics sobre el que dibujar el icono.
717
     */
718
    public void drawSymbolTag(Graphics2D g) {
719
        Rectangle2D rec = getBoundingBox(null);
720
        g.rotate(Math.toRadians(getRotation()),
721
            rec.getX() + (rec.getWidth() / 2),
722
            rec.getY() + (rec.getHeight() / 2));
723

    
724
        try {
725
            URL url = AddLayer.class.getClassLoader().getResource("images/symbolTag.gif");
726
            Image image = new ImageIcon(url).getImage();
727
            g.drawImage(image, (int) rec.getX(), (int) rec.getY(), 25, 30, null);
728
        } catch (NullPointerException npe) {
729
        }
730

    
731
        g.rotate(Math.toRadians(-getRotation()),
732
            rec.getX() + (rec.getWidth() / 2),
733
            rec.getY() + (rec.getHeight() / 2));
734
    }
735

    
736
    /**
737
     * Rellenar la rotaci?n para aplicar al FFrame.
738
     *
739
     * @param rotation rotaci?n que se quiere aplicar.
740
     */
741
    public void setRotation(double rotation) {
742
        m_rotation = rotation;
743
    }
744

    
745
    /**
746
     * Devuelve la rotaci?n del FFrame.
747
     *
748
     * @return Rotaci?n del FFrame.
749
     */
750
    public double getRotation() {
751
        return m_rotation;
752
    }
753

    
754
    /**
755
     * Devuelve el nivel en el que se encuentra el FFrame.
756
     *
757
     * @return nivel
758
     */
759
    public int getLevel() {
760
        return level;
761
    }
762

    
763
    /**
764
     * Inserta el nivel al que se encuentra el FFrame.
765
     *
766
     * @param l entero que refleja el nivel del FFrame.
767
     */
768
    public void setLevel(int l) {
769
        level = l;
770
    }
771

    
772
    /**
773
     * DOCUMENT ME!
774
     *
775
     * @param layout DOCUMENT ME!
776
     *
777
     * @return DOCUMENT ME!
778
     */
779
    public IFFrame cloneFFrame(Layout layout) {
780
        Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
781
        IFFrame frame = null;
782

    
783
        try {
784
            frame = createFFrame(this.getXMLEntity(), p);
785
        } catch (OpenException e) {
786
            e.showError();
787
        } catch (SaveException e) {
788
            e.showError();
789
        }
790

    
791
        if (frame instanceof IFFrameLayoutDependence) {
792
            ((IFFrameLayoutDependence) frame).setLayout(layout);
793
        }
794

    
795
        if (frame instanceof IFFrameViewDependence) {
796
            ((IFFrameViewDependence) frame).initDependence(layout.getAllFFrames());
797
        }
798

    
799
        return frame;
800
    }
801

    
802
    /**
803
     * DOCUMENT ME!
804
     *
805
     * @return DOCUMENT ME!
806
     *
807
     * @throws SaveException DOCUMENT ME!
808
     */
809
    public XMLEntity getXMLEntity() throws SaveException {
810
        XMLEntity xml = new XMLEntity();
811
        xml.putProperty("className", this.getClass().getName());
812
        xml.putProperty("m_name", m_name);
813
        xml.putProperty("x", getBoundBox().x);
814
        xml.putProperty("y", getBoundBox().y);
815
        xml.putProperty("w", getBoundBox().width);
816
        xml.putProperty("h", getBoundBox().height);
817
        xml.putProperty("m_Selected", m_Selected);
818
        xml.putProperty("tag", getTag());
819
        xml.putProperty("m_rotation", getRotation());
820

    
821
        return xml;
822
    }
823

    
824
}