Statistics
| Revision:

root / branches / piloto3d / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrame.java @ 9529

History | View | Annotate | Download (25.6 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 java.awt.Color;
48
import java.awt.Cursor;
49
import java.awt.Font;
50
import java.awt.Graphics2D;
51
import java.awt.Image;
52
import java.awt.Rectangle;
53
import java.awt.event.MouseEvent;
54
import java.awt.geom.AffineTransform;
55
import java.awt.geom.Point2D;
56
import java.awt.geom.Rectangle2D;
57
import java.awt.image.BufferedImage;
58
import java.net.URL;
59

    
60
import javax.swing.ImageIcon;
61

    
62
import com.iver.andami.PluginServices;
63
import com.iver.andami.messages.NotificationManager;
64
import com.iver.cit.gvsig.AddLayer;
65
import com.iver.cit.gvsig.ProjectExtension;
66
import com.iver.cit.gvsig.fmap.DriverException;
67
import com.iver.cit.gvsig.gui.layout.Layout;
68
import com.iver.cit.gvsig.project.Project;
69
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
70
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
71
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
72
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
73
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence;
74
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseProject;
75
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
76
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.Tag;
77
import com.iver.utiles.XMLEntity;
78

    
79

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
222
                break;
223

    
224
            case (N):
225

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

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

    
234
                break;
235

    
236
            case (O):
237

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

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

    
246
                break;
247

    
248
            case (S):
249

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

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

    
256
                break;
257

    
258
            case (E):
259

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

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

    
266
                break;
267

    
268
            case (NE):
269

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

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

    
279
                break;
280

    
281
            case (NO):
282

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

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

    
293
                break;
294

    
295
            case (SE):
296

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

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

    
304
                break;
305

    
306
            case (SO):
307

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

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

    
317
                break;
318

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

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

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

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

    
385
        return NOSELECT;
386
    }
387

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

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

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

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

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

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

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

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

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

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

    
428
        return null;
429
    }
430

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

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

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

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

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

    
484
        return m_BoundingBox;
485
    }
486

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

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

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

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

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

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

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

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

    
557
        return fframe;
558
    }
559

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

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

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

    
595
        try {
596
            if (fframe instanceof IFFrameUseProject) {
597
                ((IFFrameUseProject) fframe).setProject(p);
598
            }
599
            if (fframe instanceof IFFrameLayoutDependence) {
600
                ((IFFrameLayoutDependence) fframe).setLayout(layout);
601
            }
602

    
603

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

    
620
        return fframe;
621
    }
622

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

    
631
        g.setColor(Color.lightGray);
632
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
633
            (int) r.getHeight());
634
        g.setColor(Color.black);
635
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth()-1,
636
                (int) r.getHeight()-1);
637
        int scale = (int) (r.getWidth() / 12);
638
        Font f = new Font("SansSerif", Font.PLAIN, scale);
639
        g.setFont(f);
640
        g.drawString(getName(),
641
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
642
            (int) (r.getCenterY()));
643
    }
644

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
803
        if (frame instanceof IFFrameViewDependence) {
804
            ((IFFrameViewDependence) frame).initDependence(layout.getAllFFrames());
805
        }
806
        cloneActions(frame);
807
        return frame;
808
    }
809
    /**
810
     * DOCUMENT ME!
811
     *
812
     * @return DOCUMENT ME!
813
     *
814
     * @throws SaveException DOCUMENT ME!
815
     */
816
    public XMLEntity getXMLEntity() throws SaveException {
817
        XMLEntity xml = new XMLEntity();
818
        xml.putProperty("className", this.getClass().getName());
819
        xml.putProperty("m_name", m_name);
820
        xml.putProperty("x", getBoundBox().x);
821
        xml.putProperty("y", getBoundBox().y);
822
        xml.putProperty("w", getBoundBox().width);
823
        xml.putProperty("h", getBoundBox().height);
824
        xml.putProperty("m_Selected", m_Selected);
825
        xml.putProperty("tag", getTag());
826
        xml.putProperty("m_rotation", getRotation());
827
        xml.putProperty("level",getLevel());
828
        xml.putProperty("num",num);
829
        return xml;
830
    }
831

    
832
}