Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrame.java @ 7304

History | View | Annotate | Download (25.4 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.Layout;
54
import com.iver.cit.gvsig.project.Project;
55
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
56
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
57
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
58
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
59
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence;
60
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseProject;
61
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
62
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.Tag;
63

    
64
import com.iver.utiles.XMLEntity;
65

    
66
import java.awt.Color;
67
import java.awt.Cursor;
68
import java.awt.Font;
69
import java.awt.Graphics2D;
70
import java.awt.Image;
71
import java.awt.Rectangle;
72
import java.awt.event.MouseEvent;
73
import java.awt.geom.AffineTransform;
74
import java.awt.geom.Point2D;
75
import java.awt.geom.Rectangle2D;
76
import java.awt.image.BufferedImage;
77

    
78
import java.net.URL;
79

    
80
import javax.swing.ImageIcon;
81

    
82

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

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

    
122
        AffineTransform atRotate = new AffineTransform();
123
        atRotate.rotate(Math.toRadians(getRotation()),
124
            r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2));
125

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

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

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

    
139
        g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size);
140
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p);
141
        se.setRect((int) p.getX(), (int) p.getY(), size, size);
142

    
143
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size,
144
            size, size);
145
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
146
                r.getY() - size), p);
147
        n.setRect((int) p.getX(), (int) p.getY(), size, size);
148

    
149
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size,
150
            size);
151
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
152
                r.getMaxY()), p);
153
        s.setRect((int) p.getX(), (int) p.getY(), size, size);
154

    
155
        g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2),
156
            size, size);
157
        atRotate.transform(new Point2D.Double(r.getX() - size,
158
                r.getCenterY() - (size / 2)), p);
159
        o.setRect((int) p.getX(), (int) p.getY(), size, size);
160

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

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

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

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

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

    
221
        switch (this.getSelected()) {
222
            case (RECT):
223
                lastMoveRect.setRect((x + difx), (y + dify), w, h);
224

    
225
                break;
226

    
227
            case (N):
228

    
229
                if ((y + dify) > rec.getMaxY()) {
230
                    y = rec.getMaxY();
231
                } else {
232
                    y = y + dify;
233
                }
234

    
235
                lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
236

    
237
                break;
238

    
239
            case (O):
240

    
241
                if ((x + difx) > rec.getMaxX()) {
242
                    x = rec.getMaxX();
243
                } else {
244
                    x = x + difx;
245
                }
246

    
247
                lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
248

    
249
                break;
250

    
251
            case (S):
252

    
253
                if (y > (rec.getMaxY() + dify)) {
254
                    y = rec.getMaxY() + dify;
255
                }
256

    
257
                lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
258

    
259
                break;
260

    
261
            case (E):
262

    
263
                if (x > (rec.getMaxX() + difx)) {
264
                    x = rec.getMaxX() + difx;
265
                }
266

    
267
                lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
268

    
269
                break;
270

    
271
            case (NE):
272

    
273
                if ((y - difn) > rec.getMaxY()) {
274
                    y = rec.getMaxY();
275
                    x = rec.getMaxX() + difn;
276
                } else {
277
                    y = y - difn;
278
                }
279

    
280
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
281

    
282
                break;
283

    
284
            case (NO):
285

    
286
                if ((y + difn) > rec.getMaxY()) {
287
                    y = rec.getMaxY();
288
                    x = rec.getMaxX();
289
                } else {
290
                    x = x + difn;
291
                    y = y + difn;
292
                }
293

    
294
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
295

    
296
                break;
297

    
298
            case (SE):
299

    
300
                if (y > (rec.getMaxY() + difn)) {
301
                    y = rec.getMaxY() + difn;
302
                    x = rec.getMaxX() + difn;
303
                }
304

    
305
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
306

    
307
                break;
308

    
309
            case (SO):
310

    
311
                if ((x + difn) > rec.getMaxX()) {
312
                    x = rec.getMaxX();
313
                    y = rec.getMaxY() - difn;
314
                } else {
315
                    x = x + difn;
316
                }
317

    
318
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
319

    
320
                break;
321

    
322
            default:
323
                lastMoveRect.setRect((x), (y), w, h);
324
        }
325

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

    
347
    /**
348
     * Devuelve true, si el punto que se pasa como par?metro esta contenido
349
     * dentro del boundingbox del fframe.
350
     *
351
     * @param p punto a comprobar.
352
     *
353
     * @return true si el punto esta dentro del boundingbox.
354
     */
355
    public boolean contains(Point2D p) {
356
        return getBoundingBox(null).contains(p.getX(), p.getY());
357
    }
358

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

    
388
        return NOSELECT;
389
    }
390

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

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

    
406
            case (NE):
407
                return Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
408

    
409
            case (E):
410
                return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
411

    
412
            case (SE):
413
                return Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
414

    
415
            case (S):
416
                return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
417

    
418
            case (SO):
419
                return Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
420

    
421
            case (O):
422
                return Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
423

    
424
            case (NO):
425
                return Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
426

    
427
            case (RECT):
428
                return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
429
        }
430

    
431
        return null;
432
    }
433

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

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

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

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

    
485
        m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at);
486

    
487
        return m_BoundingBox;
488
    }
489

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

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

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

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

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

    
548
        if (fframe instanceof IFFrameUseProject) {
549
            ((IFFrameUseProject) fframe).setProject(p);
550
        }
551

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

    
558
        fframe.setTag(xml.getStringProperty("tag"));
559

    
560
        return fframe;
561
    }
562

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

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

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

    
598
        try {
599
            if (fframe instanceof IFFrameUseProject) {
600
                ((IFFrameUseProject) fframe).setProject(p);
601
            }
602
            if (fframe instanceof IFFrameLayoutDependence) {
603
                ((IFFrameLayoutDependence) fframe).setLayout(layout);
604
            }
605

    
606

    
607
            if (xml.contains("level")) {
608
                fframe.setLevel(xml.getIntProperty("level"));
609
            }
610
            if (xml.contains("num")){
611
                    fframe.setNum(xml.getIntProperty("num"));
612
            }
613
            fframe.setName(xml.getStringProperty("m_name"));
614
            fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
615
                    xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
616
                    xml.getDoubleProperty("h")));
617
            fframe.setXMLEntity(xml);
618
            fframe.setTag(xml.getStringProperty("tag"));
619
        } catch (Exception e) {
620
            throw new OpenException(e, className);
621
        }
622

    
623
        return fframe;
624
    }
625

    
626
    /**
627
     * Dibuja sobre el graphics el rect?ngulo del fframe en modo borrador.
628
     *
629
     * @param g Graphics so bre el que dibujar.
630
     */
631
    public void drawDraft(Graphics2D g) {
632
        Rectangle2D r = getBoundingBox(null);
633

    
634
        g.setColor(Color.lightGray);
635
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
636
            (int) r.getHeight());
637
        g.setColor(Color.black);
638

    
639
        int scale = (int) (r.getWidth() / 12);
640
        Font f = new Font("SansSerif", Font.PLAIN, scale);
641
        g.setFont(f);
642
        g.drawString(getName(),
643
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
644
            (int) (r.getCenterY()));
645
    }
646

    
647
    /**
648
     * Rellena con el n?mero de FFrame.
649
     *
650
     * @param i n?mero
651
     */
652
    public void setNum(int i) {
653
        num = i;
654
    }
655

    
656
    /**
657
     * Dibuja sobre el graphics el rect?ngulo del fframe pero vacio, mostrando
658
     * el nombre del fframe y vacio.
659
     *
660
     * @param g Graphics sobre el que dibujar.
661
     */
662
    public void drawEmpty(Graphics2D g) {
663
        Rectangle2D r = getBoundingBox(null);
664
        g.setColor(Color.lightGray);
665
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
666
            (int) r.getHeight());
667
        g.setColor(Color.darkGray);
668
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
669
                (int) r.getHeight());
670
        g.setColor(Color.black);
671

    
672
        int scale = (int) (r.getWidth() / 12);
673
        Font f = new Font("SansSerif", Font.PLAIN, scale);
674
        g.setFont(f);
675

    
676
        String s = this.getNameFFrame() + " " +
677
            PluginServices.getText(this, "vacia");
678

    
679
        g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)),
680
            (int) (r.getCenterY()));
681
    }
682

    
683
    /**
684
     * Devuelve true si el rect?ngulo primero es null o si es distinto de null
685
     * e intersecta.
686
     *
687
     * @param rv Rect?ngulo
688
     * @param r Rect?ngulo
689
     *
690
     * @return True si intersecta o es null.
691
     */
692
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
693
        return (((rv != null) && rv.intersects(r)) || (rv == null));
694
    }
695

    
696
    /**
697
     * Abre el di?logo para cambiar o a?adir el tag.
698
     */
699
    public void openTag() {
700
        Tag tag = new Tag(this);
701
        PluginServices.getMDIManager().addWindow(tag);
702
    }
703

    
704
    /**
705
     * Rellena el tag del FFrame.
706
     *
707
     * @param s String que representa el valor a guardar en el tag.
708
     */
709
    public void setTag(String s) {
710
        tag = s;
711
    }
712

    
713
    /**
714
     * Devuelve el tag.
715
     *
716
     * @return tag.
717
     */
718
    public String getTag() {
719
        return tag;
720
    }
721

    
722
    /**
723
     * Dibuja sobre el graphics que se pasa como par?metro el icono que
724
     * representa que contiene un tag.
725
     *
726
     * @param g Graphics sobre el que dibujar el icono.
727
     */
728
    public void drawSymbolTag(Graphics2D g) {
729
        Rectangle2D rec = getBoundingBox(null);
730
        g.rotate(Math.toRadians(getRotation()),
731
            rec.getX() + (rec.getWidth() / 2),
732
            rec.getY() + (rec.getHeight() / 2));
733

    
734
        try {
735
            URL url = AddLayer.class.getClassLoader().getResource("images/symbolTag.gif");
736
            Image image = new ImageIcon(url).getImage();
737
            g.drawImage(image, (int) rec.getX(), (int) rec.getY(), 25, 30, null);
738
        } catch (NullPointerException npe) {
739
        }
740

    
741
        g.rotate(Math.toRadians(-getRotation()),
742
            rec.getX() + (rec.getWidth() / 2),
743
            rec.getY() + (rec.getHeight() / 2));
744
    }
745

    
746
    /**
747
     * Rellenar la rotaci?n para aplicar al FFrame.
748
     *
749
     * @param rotation rotaci?n que se quiere aplicar.
750
     */
751
    public void setRotation(double rotation) {
752
        m_rotation = rotation;
753
    }
754

    
755
    /**
756
     * Devuelve la rotaci?n del FFrame.
757
     *
758
     * @return Rotaci?n del FFrame.
759
     */
760
    public double getRotation() {
761
        return m_rotation;
762
    }
763

    
764
    /**
765
     * Devuelve el nivel en el que se encuentra el FFrame.
766
     *
767
     * @return nivel
768
     */
769
    public int getLevel() {
770
        return level;
771
    }
772

    
773
    /**
774
     * Inserta el nivel al que se encuentra el FFrame.
775
     *
776
     * @param l entero que refleja el nivel del FFrame.
777
     */
778
    public void setLevel(int l) {
779
        level = l;
780
    }
781

    
782
    /**
783
     * DOCUMENT ME!
784
     *
785
     * @param layout DOCUMENT ME!
786
     *
787
     * @return DOCUMENT ME!
788
     */
789
    public IFFrame cloneFFrame(Layout layout) {
790
        Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
791
        IFFrame frame = null;
792

    
793
        try {
794
            frame = createFFrame(this.getXMLEntity(), p,layout);
795
        } catch (OpenException e) {
796
            e.showError();
797
        } catch (SaveException e) {
798
            e.showError();
799
        }
800
        ((FFrame)frame).m_BoundingBox=this.m_BoundingBox;
801
        if (frame instanceof IFFrameLayoutDependence) {
802
            ((IFFrameLayoutDependence) frame).setLayout(layout);
803
        }
804

    
805
        if (frame instanceof IFFrameViewDependence) {
806
            ((IFFrameViewDependence) frame).initDependence(layout.getAllFFrames());
807
        }
808

    
809
        return frame;
810
    }
811

    
812
    /**
813
     * DOCUMENT ME!
814
     *
815
     * @return DOCUMENT ME!
816
     *
817
     * @throws SaveException DOCUMENT ME!
818
     */
819
    public XMLEntity getXMLEntity() throws SaveException {
820
        XMLEntity xml = new XMLEntity();
821
        xml.putProperty("className", this.getClass().getName());
822
        xml.putProperty("m_name", m_name);
823
        xml.putProperty("x", getBoundBox().x);
824
        xml.putProperty("y", getBoundBox().y);
825
        xml.putProperty("w", getBoundBox().width);
826
        xml.putProperty("h", getBoundBox().height);
827
        xml.putProperty("m_Selected", m_Selected);
828
        xml.putProperty("tag", getTag());
829
        xml.putProperty("m_rotation", getRotation());
830
        xml.putProperty("level",getLevel());
831
        xml.putProperty("num",num);
832
        return xml;
833
    }
834

    
835
}