Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrame.java @ 9392

History | View | Annotate | Download (27.3 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.project.documents.layout.fframes;
46

    
47
import java.awt.Color;
48
import java.awt.Font;
49
import java.awt.Graphics2D;
50
import java.awt.Image;
51
import java.awt.Rectangle;
52
import java.awt.event.MouseEvent;
53
import java.awt.geom.AffineTransform;
54
import java.awt.geom.Point2D;
55
import java.awt.geom.Rectangle2D;
56
import java.awt.image.BufferedImage;
57
import java.net.URL;
58
import java.util.HashMap;
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.project.Project;
68
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
69
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
70
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
71
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
72
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.Tag;
73
import com.iver.utiles.XMLEntity;
74

    
75

    
76
/**
77
 * Clase que implementa la interface IFFrame con los m?todos por defecto de
78
 * todos los FFrames  que extenderan de este, dejando uno como m?todo
79
 * abstracto para implementar por todos los  FFrames para ser dibujados.
80
 *
81
 * @author Vicente Caballero Navarro
82
 */
83
public abstract class FFrame implements IFFrame {
84
    protected String m_name = "FFrame";
85
    private Rectangle2D.Double m_BoundBox = new Rectangle2D.Double();
86
    private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double();
87
    protected int m_Selected = 0;
88
    protected Rectangle n = new Rectangle();
89
    protected Rectangle ne = new Rectangle();
90
    protected Rectangle e = new Rectangle();
91
    protected Rectangle se = new Rectangle();
92
    protected Rectangle s = new Rectangle();
93
    protected Rectangle so = new Rectangle();
94
    protected Rectangle o = new Rectangle();
95
    protected Rectangle no = new Rectangle();
96
    private String tag = null;
97
    protected int num = 0;
98
    private double m_rotation = 0;
99
    private int level = -1;
100
        private Rectangle2D lastMoveRect;
101
        private Layout layout;
102
        private static final Image iNEResize = new ImageIcon(AddLayer.class
103
                    .getClassLoader().getResource("images/NEResize.png")).getImage();
104
        private static final Image iEResize = new ImageIcon(AddLayer.class
105
            .getClassLoader().getResource("images/EResize.png")).getImage();
106
        private static final Image iNResize = new ImageIcon(AddLayer.class
107
            .getClassLoader().getResource("images/NResize.png")).getImage();
108
        private static final Image iMove = new ImageIcon(AddLayer.class
109
            .getClassLoader().getResource("images/Move.png")).getImage();
110
        private static final Image iSEResize = new ImageIcon(AddLayer.class
111
            .getClassLoader().getResource("images/SEResize.png")).getImage();
112
    private static final HashMap classnames=new HashMap();
113
        static {
114
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameBasic",FFrameBasic.class.getName());
115
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFramaeGraphics",FFrameGraphics.class.getName());
116
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup",FFrameGroup.class.getName());
117
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend",FFrameLegend.class.getName());
118
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth",FFrameNorth.class.getName());
119
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameOverView",FFrameOverView.class.getName());
120
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFramePicture",FFramePicture.class.getName());
121
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar",FFrameScaleBar.class.getName());
122
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameSymbol",FFrameSymbol.class.getName());
123
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameTable",FFrameTable.class.getName());
124
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameText",FFrameText.class.getName());
125
                classnames.put("com.iver.cit.gvsig.gui.layout.fframes.FFrameView",FFrameView.class.getName());
126
        }
127
    /**
128
     * Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
129
     * par?metro.
130
     *
131
     * @param g Graphics sobre el que dibujar.
132
     */
133
    public void drawHandlers(Graphics2D g) {
134
        int size = 10;
135
        Rectangle2D r = getBoundingBox(null);
136
        Point2D p = new Point2D.Double();
137
        g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2),
138
            r.getY() + (r.getHeight() / 2));
139

    
140
        AffineTransform atRotate = new AffineTransform();
141
        atRotate.rotate(Math.toRadians(getRotation()),
142
            r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2));
143

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

    
149
        g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size);
150
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p);
151
        ne.setRect((int) p.getX(), (int) p.getY(), size, size);
152

    
153
        g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size);
154
        atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p);
155
        so.setRect((int) p.getX(), (int) p.getY(), size, size);
156

    
157
        g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size);
158
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p);
159
        se.setRect((int) p.getX(), (int) p.getY(), size, size);
160

    
161
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size,
162
            size, size);
163
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
164
                r.getY() - size), p);
165
        n.setRect((int) p.getX(), (int) p.getY(), size, size);
166

    
167
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size,
168
            size);
169
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
170
                r.getMaxY()), p);
171
        s.setRect((int) p.getX(), (int) p.getY(), size, size);
172

    
173
        g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2),
174
            size, size);
175
        atRotate.transform(new Point2D.Double(r.getX() - size,
176
                r.getCenterY() - (size / 2)), p);
177
        o.setRect((int) p.getX(), (int) p.getY(), size, size);
178

    
179
        g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size,
180
            size);
181
        atRotate.transform(new Point2D.Double(r.getMaxX(),
182
                r.getCenterY() - (size / 2)), p);
183
        e.setRect((int) p.getX(), (int) p.getY(), size, size);
184
        g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2),
185
            r.getY() + (r.getHeight() / 2));
186
    }
187

    
188
    /**
189
     * Establece que tipo de selecci?n se realiza sobre el fframe.
190
     *
191
     * @param p punto sobre el que se debe de establecer si se selecciona o no
192
     *        el fframe.
193
     */
194
    public void setSelected(Point2D p,MouseEvent e) {
195
        m_Selected = getContains(p);
196
    }
197

    
198
    /**
199
     * Actualiza el BoundBox del FFrame a partir de su rect?ngulo en pixels y
200
     * la matriz de transformaci?n.
201
     *
202
     * @param r Rect?ngulo.
203
     * @param at Matriz de transformaci?n.
204
     */
205
    public void updateRect(Rectangle2D r, AffineTransform at) {
206
        Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
207
        rec.setRect((int) rec.getMinX(), (int) rec.getMinY(),
208
            (int) rec.getWidth(), (int) rec.getHeight());
209
        setBoundBox(rec);
210
    }
211

    
212
    /**
213
     * Devuelve el rect?ngulo a partir del desplazamiento en el eje x y el
214
     * desplazamiento en el eje y.
215
     *
216
     * @param difx desplazamiento sobre el eje x.
217
     * @param dify desplazamiento sobre el eje y.
218
     *
219
     * @return rect?ngulo modificado en funci?n del desplazamiento realizado.
220
     */
221
    public Rectangle2D getMovieRect(int difx, int dify) {
222
        double x = 0;
223
        double y = 0;
224
        double w = 0;
225
        double h = 0;
226

    
227
        lastMoveRect = new Rectangle2D.Double(this.getBoundingBox(
228
                    null).x, this.getBoundingBox(null).y,
229
                this.getBoundingBox(null).width,
230
                this.getBoundingBox(null).height);
231
        Rectangle2D.Double rec = this.getBoundingBox(null);
232
        int difn = 0;
233
        difn = difx;
234
        x = lastMoveRect.getX();
235
        y = lastMoveRect.getY();
236
        w = lastMoveRect.getWidth();
237
        h = lastMoveRect.getHeight();
238

    
239
        switch (this.getSelected()) {
240
            case (RECT):
241
                lastMoveRect.setRect((x + difx), (y + dify), w, h);
242

    
243
                break;
244

    
245
            case (N):
246

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

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

    
255
                break;
256

    
257
            case (O):
258

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

    
265
                lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
266

    
267
                break;
268

    
269
            case (S):
270

    
271
                if (y > (rec.getMaxY() + dify)) {
272
                    y = rec.getMaxY() + dify;
273
                }
274

    
275
                lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
276

    
277
                break;
278

    
279
            case (E):
280

    
281
                if (x > (rec.getMaxX() + difx)) {
282
                    x = rec.getMaxX() + difx;
283
                }
284

    
285
                lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
286

    
287
                break;
288

    
289
            case (NE):
290

    
291
                if ((y - difn) > rec.getMaxY()) {
292
                    y = rec.getMaxY();
293
                    x = rec.getMaxX() + difn;
294
                } else {
295
                    y = y - difn;
296
                }
297

    
298
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
299

    
300
                break;
301

    
302
            case (NO):
303

    
304
                if ((y + difn) > rec.getMaxY()) {
305
                    y = rec.getMaxY();
306
                    x = rec.getMaxX();
307
                } else {
308
                    x = x + difn;
309
                    y = y + difn;
310
                }
311

    
312
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
313

    
314
                break;
315

    
316
            case (SE):
317

    
318
                if (y > (rec.getMaxY() + difn)) {
319
                    y = rec.getMaxY() + difn;
320
                    x = rec.getMaxX() + difn;
321
                }
322

    
323
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
324

    
325
                break;
326

    
327
            case (SO):
328

    
329
                if ((x + difn) > rec.getMaxX()) {
330
                    x = rec.getMaxX();
331
                    y = rec.getMaxY() - difn;
332
                } else {
333
                    x = x + difn;
334
                }
335

    
336
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
337

    
338
                break;
339

    
340
            default:
341
                lastMoveRect.setRect((x), (y), w, h);
342
        }
343

    
344
        return lastMoveRect;
345
    }
346
    /**
347
     * Devuelve el rect?ngulo que representa el ?ltimo generado al desplazar o modificar el tama?o del fframe.
348
     *
349
     * @return Rectangle2D
350
     *
351
     */
352
    public Rectangle2D getLastMoveRect(){
353
            return lastMoveRect;
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 punto a comprobar.
370
     *
371
     * @return true si el punto esta dentro del boundingbox.
372
     */
373
    public boolean contains(Point2D p) {
374
        return getBoundingBox(null).contains(p.getX(), p.getY());
375
    }
376

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

    
406
        return NOSELECT;
407
    }
408

    
409
    /**
410
     * Devuelve el Cursor adecuado seg?n como est? contenido el punto, si es
411
     * para desplazamiento, o cambio de tama?o.
412
     *
413
     * @param p punto a comprobar.
414
     *
415
     * @return Cursor adecuado a la posici?n.
416
     */
417
    public Image getMapCursor(Point2D p) {
418
        int select = getContains(p);
419

    
420
        switch (select) {
421
            case (N):
422
                return iNResize;
423

    
424
            case (NE):
425
                return iNEResize;
426

    
427
            case (E):
428
                return iEResize;
429

    
430
            case (SE):
431
                return iSEResize;
432

    
433
            case (S):
434
                return iNResize;
435

    
436
            case (SO):
437
                return iNEResize;
438

    
439
            case (O):
440
                return iEResize;
441

    
442
            case (NO):
443
                return iSEResize;
444

    
445
            case (RECT):
446
                return iMove;
447
        }
448

    
449
        return null;
450
    }
451

    
452
    /**
453
     * Este m?todo se implementa en cada una de las fframe, ya que cada una se
454
     * dibuja de una forma diferente sobre el graphics. M?todo que dibuja
455
     * sobre el graphics que se le pasa como par?metro, seg?n la transformada
456
     * afin que se debe de aplicar y el rect?ngulo que se debe de dibujar.
457
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro,
458
     * seg?n la transformada afin que se debe de aplicar y el rect?ngulo que
459
     * se debe de dibujar.
460
     *
461
     * @param g Graphics
462
     * @param at Transformada afin.
463
     * @param r rect?ngulo sobre el que hacer un clip.
464
     * @param imgBase DOCUMENT ME!
465
     *
466
     * @throws DriverException
467
     */
468
    public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r,
469
        BufferedImage imgBase) throws DriverException;
470

    
471
    /**
472
     * Devuelve el nombre que representa al fframe.
473
     *
474
     * @return String
475
     */
476
    public String getName() {
477
        return m_name;
478
    }
479

    
480
    /**
481
     * Rellena el String que representa al nombre del fframe.
482
     *
483
     * @param n nombre del fframe.
484
     */
485
    public void setName(String n) {
486
        m_name = n;
487
    }
488

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

    
503
        m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at);
504

    
505
        return m_BoundingBox;
506
    }
507

    
508
    /**
509
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
510
     * cent?metros) del fframe del cual con una transformaci?n se podr?
511
     * calcular el BoundingBox (en pixels).
512
     *
513
     * @param r Rect?ngulo en cent?metros.
514
     */
515
    public void setBoundBox(Rectangle2D r) {
516
        m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
517
    }
518

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

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

    
545
    /**
546
     * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
547
     * del XMLEntity.
548
     *
549
     * @param xml XMLEntity
550
     * @param l Layout.
551
     * @param p Proyecto.
552
     *
553
     * @return Objeto de esta clase.
554
     */
555
    public static IFFrame createFFrame03(XMLEntity xml, Layout l, Project p) {
556
        IFFrame fframe = null;
557

    
558
        try {
559
                String className;
560
                if (classnames.containsKey(xml.getStringProperty("className"))) {
561
                        className = (String)classnames.get(xml.getStringProperty("className"));
562
                }else {
563
                        className = xml.getStringProperty("className");
564
                }
565
            Class clase = Class.forName(className);
566
            fframe = (IFFrame) clase.newInstance();
567
        } catch (Exception e) {
568
            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
569
                e);
570
        }
571

    
572
        if (fframe instanceof IFFrameUseProject) {
573
            ((IFFrameUseProject) fframe).setProject(p);
574
        }
575

    
576
        fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
577
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
578
                xml.getDoubleProperty("h")));
579
        fframe.setXMLEntity03(xml, l);
580
        fframe.setName(xml.getStringProperty("m_name"));
581

    
582
        fframe.setTag(xml.getStringProperty("tag"));
583

    
584
        return fframe;
585
    }
586

    
587
    /**
588
     * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
589
     * del XMLEntity.
590
     *
591
     * @param xml XMLEntity
592
     * @param p Proyecto.
593
     *
594
     * @return Objeto de esta clase.
595
     *
596
     * @throws OpenException DOCUMENT ME!
597
     */
598
    public static IFFrame createFFrame(XMLEntity xml, Project p,Layout layout)
599
        throws OpenException {
600
        IFFrame fframe = null;
601
        String className = "IFFrame";
602
        Class clase = null;
603

    
604
        try {
605
                if (classnames.containsKey(xml.getStringProperty("className"))) {
606
                        className = (String)classnames.get(xml.getStringProperty("className"));
607
                }else {
608
                        className = xml.getStringProperty("className");
609
                }
610
            clase = Class.forName(className);
611
        } catch (ClassNotFoundException e) {
612
            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
613
                e);
614
        }
615

    
616
        try {
617
            fframe = (IFFrame) clase.newInstance();
618
        } catch (InstantiationException e) {
619
            NotificationManager.addError("Fallo creando el Frame: " +
620
                clase.getName(), e);
621
        } catch (IllegalAccessException e) {
622
            NotificationManager.addError("Fallo creando el Frame: " +
623
                clase.getName(), e);
624
        }
625

    
626
        try {
627
            if (fframe instanceof IFFrameUseProject) {
628
                ((IFFrameUseProject) fframe).setProject(p);
629
            }
630
                fframe.setLayout(layout);
631

    
632

    
633
            if (xml.contains("level")) {
634
                fframe.setLevel(xml.getIntProperty("level"));
635
            }
636
            if (xml.contains("num")){
637
                    fframe.setNum(xml.getIntProperty("num"));
638
            }
639
            fframe.setName(xml.getStringProperty("m_name"));
640
            fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
641
                    xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
642
                    xml.getDoubleProperty("h")));
643
            fframe.setXMLEntity(xml);
644
            fframe.setTag(xml.getStringProperty("tag"));
645
        } catch (Exception e) {
646
            throw new OpenException(e, className);
647
        }
648

    
649
        return fframe;
650
    }
651

    
652
    /**
653
     * Dibuja sobre el graphics el rect?ngulo del fframe en modo borrador.
654
     *
655
     * @param g Graphics so bre el que dibujar.
656
     */
657
    public void drawDraft(Graphics2D g) {
658
        Rectangle2D r = getBoundingBox(null);
659

    
660
        g.setColor(Color.lightGray);
661
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
662
            (int) r.getHeight());
663
        g.setColor(Color.black);
664
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth()-1,
665
                (int) r.getHeight()-1);
666
        int scale = (int) (r.getWidth() / 12);
667
        Font f = new Font("SansSerif", Font.PLAIN, scale);
668
        g.setFont(f);
669
        g.drawString(getName(),
670
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
671
            (int) (r.getCenterY()));
672
    }
673

    
674
    /**
675
     * Rellena con el n?mero de FFrame.
676
     *
677
     * @param i n?mero
678
     */
679
    public void setNum(int i) {
680
        num = i;
681
    }
682

    
683
    /**
684
     * Dibuja sobre el graphics el rect?ngulo del fframe pero vacio, mostrando
685
     * el nombre del fframe y vacio.
686
     *
687
     * @param g Graphics sobre el que dibujar.
688
     */
689
    public void drawEmpty(Graphics2D g) {
690
        Rectangle2D r = getBoundingBox(null);
691
        g.setColor(Color.lightGray);
692
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
693
            (int) r.getHeight());
694
        g.setColor(Color.darkGray);
695
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
696
                (int) r.getHeight());
697
        g.setColor(Color.black);
698

    
699
        int scale = (int) (r.getWidth() / 12);
700
        Font f = new Font("SansSerif", Font.PLAIN, scale);
701
        g.setFont(f);
702

    
703
        String s = this.getNameFFrame() + " " +
704
            PluginServices.getText(this, "vacia");
705

    
706
        g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)),
707
            (int) (r.getCenterY()));
708
    }
709

    
710
    /**
711
     * Devuelve true si el rect?ngulo primero es null o si es distinto de null
712
     * e intersecta.
713
     *
714
     * @param rv Rect?ngulo
715
     * @param r Rect?ngulo
716
     *
717
     * @return True si intersecta o es null.
718
     */
719
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
720
        return (((rv != null) && rv.intersects(r)) || (rv == null));
721
    }
722

    
723
    /**
724
     * Abre el di?logo para cambiar o a?adir el tag.
725
     */
726
    public void openTag() {
727
        Tag tag = new Tag(this);
728
        PluginServices.getMDIManager().addWindow(tag);
729
    }
730

    
731
    /**
732
     * Rellena el tag del FFrame.
733
     *
734
     * @param s String que representa el valor a guardar en el tag.
735
     */
736
    public void setTag(String s) {
737
        tag = s;
738
    }
739

    
740
    /**
741
     * Devuelve el tag.
742
     *
743
     * @return tag.
744
     */
745
    public String getTag() {
746
        return tag;
747
    }
748

    
749
    /**
750
     * Dibuja sobre el graphics que se pasa como par?metro el icono que
751
     * representa que contiene un tag.
752
     *
753
     * @param g Graphics sobre el que dibujar el icono.
754
     */
755
    public void drawSymbolTag(Graphics2D g) {
756
        Rectangle2D rec = getBoundingBox(null);
757
        g.rotate(Math.toRadians(getRotation()),
758
            rec.getX() + (rec.getWidth() / 2),
759
            rec.getY() + (rec.getHeight() / 2));
760

    
761
        try {
762
            URL url = AddLayer.class.getClassLoader().getResource("images/symbolTag.gif");
763
            Image image = new ImageIcon(url).getImage();
764
            g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30, 30, null);
765
        } catch (NullPointerException npe) {
766
        }
767

    
768
        g.rotate(Math.toRadians(-getRotation()),
769
            rec.getX() + (rec.getWidth() / 2),
770
            rec.getY() + (rec.getHeight() / 2));
771
    }
772

    
773
    /**
774
     * Rellenar la rotaci?n para aplicar al FFrame.
775
     *
776
     * @param rotation rotaci?n que se quiere aplicar.
777
     */
778
    public void setRotation(double rotation) {
779
        m_rotation = rotation;
780
    }
781

    
782
    /**
783
     * Devuelve la rotaci?n del FFrame.
784
     *
785
     * @return Rotaci?n del FFrame.
786
     */
787
    public double getRotation() {
788
        return m_rotation;
789
    }
790

    
791
    /**
792
     * Devuelve el nivel en el que se encuentra el FFrame.
793
     *
794
     * @return nivel
795
     */
796
    public int getLevel() {
797
        return level;
798
    }
799

    
800
    /**
801
     * Inserta el nivel al que se encuentra el FFrame.
802
     *
803
     * @param l entero que refleja el nivel del FFrame.
804
     */
805
    public void setLevel(int l) {
806
        level = l;
807
    }
808

    
809
    /**
810
     * DOCUMENT ME!
811
     *
812
     * @param layout DOCUMENT ME!
813
     *
814
     * @return DOCUMENT ME!
815
     */
816
    public IFFrame cloneFFrame(Layout layout) {
817
        Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
818
        IFFrame frame = null;
819

    
820
        try {
821
            frame = createFFrame(this.getXMLEntity(), p,layout);
822
        } catch (OpenException e) {
823
            e.showError();
824
        } catch (SaveException e) {
825
            e.showError();
826
        }
827
        ((FFrame)frame).m_BoundingBox=this.m_BoundingBox;
828
            frame.setLayout(layout);
829

    
830
        if (frame instanceof IFFrameViewDependence) {
831
            ((IFFrameViewDependence) frame).initDependence(layout.getLayoutContext().getAllFFrames());
832
        }
833
        cloneActions(frame);
834
        return frame;
835
    }
836
    /**
837
     * DOCUMENT ME!
838
     *
839
     * @return DOCUMENT ME!
840
     *
841
     * @throws SaveException DOCUMENT ME!
842
     */
843
    public XMLEntity getXMLEntity() throws SaveException {
844
        XMLEntity xml = new XMLEntity();
845
        xml.putProperty("className", this.getClass().getName());
846
        xml.putProperty("m_name", m_name);
847
        xml.putProperty("x", getBoundBox().x);
848
        xml.putProperty("y", getBoundBox().y);
849
        xml.putProperty("w", getBoundBox().width);
850
        xml.putProperty("h", getBoundBox().height);
851
        xml.putProperty("m_Selected", m_Selected);
852
        xml.putProperty("tag", getTag());
853
        xml.putProperty("m_rotation", getRotation());
854
        xml.putProperty("level",getLevel());
855
        xml.putProperty("num",num);
856
        return xml;
857
    }
858

    
859
        public void setLayout(Layout layout) {
860
                this.layout=layout;
861
        }
862

    
863
        public Layout getLayout() {
864
                return layout;
865
        }
866

    
867
}