Statistics
| Revision:

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

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

    
61
import javax.swing.ImageIcon;
62

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

    
80

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
223
                break;
224

    
225
            case (N):
226

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

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

    
235
                break;
236

    
237
            case (O):
238

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

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

    
247
                break;
248

    
249
            case (S):
250

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

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

    
257
                break;
258

    
259
            case (E):
260

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

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

    
267
                break;
268

    
269
            case (NE):
270

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

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

    
280
                break;
281

    
282
            case (NO):
283

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

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

    
294
                break;
295

    
296
            case (SE):
297

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

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

    
305
                break;
306

    
307
            case (SO):
308

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

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

    
318
                break;
319

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

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

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

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

    
386
        return NOSELECT;
387
    }
388

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

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

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

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

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

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

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

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

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

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

    
429
        return null;
430
    }
431

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

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

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

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

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

    
485
        return m_BoundingBox;
486
    }
487

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

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

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

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

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

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

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

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

    
558
        return fframe;
559
    }
560

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

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

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

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

    
604

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

    
621
        return fframe;
622
    }
623

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

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

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

    
655
    /**
656
     * Dibuja sobre el graphics el rect?ngulo del fframe pero vacio, mostrando
657
     * el nombre del fframe y vacio.
658
     *
659
     * @param g Graphics sobre el que dibujar.
660
     */
661
    public void drawEmpty(Graphics2D g) {
662
        Rectangle2D r = getBoundingBox(null);
663
        g.setColor(Color.lightGray);
664
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
665
            (int) r.getHeight());
666
        g.setColor(Color.darkGray);
667
        g.setStroke(new BasicStroke(2));
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.getCenterY(), 30, 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
        cloneActions(frame);
809
        return frame;
810
    }
811
    /**
812
     * DOCUMENT ME!
813
     *
814
     * @return DOCUMENT ME!
815
     *
816
     * @throws SaveException DOCUMENT ME!
817
     */
818
    public XMLEntity getXMLEntity() throws SaveException {
819
        XMLEntity xml = new XMLEntity();
820
        xml.putProperty("className", this.getClass().getName());
821
        xml.putProperty("m_name", m_name);
822
        xml.putProperty("x", getBoundBox().x);
823
        xml.putProperty("y", getBoundBox().y);
824
        xml.putProperty("w", getBoundBox().width);
825
        xml.putProperty("h", getBoundBox().height);
826
        xml.putProperty("m_Selected", m_Selected);
827
        xml.putProperty("tag", getTag());
828
        xml.putProperty("m_rotation", getRotation());
829
        xml.putProperty("level",getLevel());
830
        xml.putProperty("num",num);
831
        return xml;
832
    }
833

    
834
}