Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / FFrame.java @ 29596

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

    
47
import java.awt.BasicStroke;
48
import java.awt.Color;
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

    
59
import org.gvsig.andami.PluginServices;
60
import org.gvsig.andami.messages.NotificationManager;
61
import org.gvsig.app.extension.ProjectExtension;
62
import org.gvsig.app.project.Project;
63
import org.gvsig.app.project.documents.exceptions.OpenException;
64
import org.gvsig.app.project.documents.exceptions.SaveException;
65
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
66
import org.gvsig.app.project.documents.layout.gui.Layout;
67
import org.gvsig.app.project.documents.layout.gui.dialogs.Tag;
68
import org.gvsig.tools.ToolsLocator;
69
import org.gvsig.tools.extensionpoint.ExtensionPoint;
70
import org.gvsig.utils.XMLEntity;
71

    
72

    
73

    
74

    
75
/**
76
 * Clase que implementa la interface IFFrame con los m�todos por defecto de
77
 * todos los FFrames  que extenderan de este, dejando uno como m�todo
78
 * abstracto para implementar por todos los  FFrames para ser dibujados.
79
 *
80
 * @author Vicente Caballero Navarro
81
 */
82
public abstract class FFrame implements IFFrame {
83
    protected String m_name = "FFrame";
84
    protected Rectangle2D.Double m_BoundBox = new Rectangle2D.Double();
85
    private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double();
86
    protected int m_Selected = 0;
87
    protected Rectangle n = new Rectangle();
88
    protected Rectangle ne = new Rectangle();
89
    protected Rectangle e = new Rectangle();
90
    protected Rectangle se = new Rectangle();
91
    protected Rectangle s = new Rectangle();
92
    protected Rectangle so = new Rectangle();
93
    protected Rectangle o = new Rectangle();
94
    protected Rectangle no = new Rectangle();
95
    private String tag = null;
96
    protected int num = 0;
97
    private double m_rotation = 0;
98
    private int level = -1;
99
        private Rectangle2D lastMoveRect;
100
        private Layout layout;
101
        protected FrameFactory factory;
102
//        protected PrintRequestAttributeSet printingProperties;
103
        private static final Image iNEResize = PluginServices.getIconTheme()
104
                .get("neresize-icon").getImage();
105
        private static final Image iEResize = PluginServices.getIconTheme()
106
                .get("eresize-icon").getImage();
107
        private static final Image iNResize = PluginServices.getIconTheme()
108
                .get("nresize-icon").getImage();
109
        private static final Image iMove = PluginServices.getIconTheme()
110
                .get("move-icon").getImage();
111
        private static final Image iSEResize = PluginServices.getIconTheme()
112
                .get("sereresize-icon").getImage();
113

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

    
127
        AffineTransform atRotate = new AffineTransform();
128
        atRotate.rotate(Math.toRadians(getRotation()),
129
            r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2));
130

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

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

    
140
        g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size);
141
        atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p);
142
        so.setRect((int) p.getX(), (int) p.getY(), size, size);
143

    
144
        g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size);
145
        atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p);
146
        se.setRect((int) p.getX(), (int) p.getY(), size, size);
147

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

    
154
        g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size,
155
            size);
156
        atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2),
157
                r.getMaxY()), p);
158
        s.setRect((int) p.getX(), (int) p.getY(), size, size);
159

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

    
166
        g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size,
167
            size);
168
        atRotate.transform(new Point2D.Double(r.getMaxX(),
169
                r.getCenterY() - (size / 2)), p);
170
        e.setRect((int) p.getX(), (int) p.getY(), size, size);
171
        g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2),
172
            r.getY() + (r.getHeight() / 2));
173
    }
174

    
175
    /**
176
     * Establece que tipo de selecci�n se realiza sobre el fframe.
177
     *
178
     * @param p punto sobre el que se debe de establecer si se selecciona o no
179
     *        el fframe.
180
     */
181
    public void setSelected(Point2D p,MouseEvent e) {
182
        m_Selected = getContains(p);
183
    }
184

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

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

    
214
        lastMoveRect = new Rectangle2D.Double(this.getBoundingBox(
215
                    null).x, this.getBoundingBox(null).y,
216
                this.getBoundingBox(null).width,
217
                this.getBoundingBox(null).height);
218
        Rectangle2D.Double rec = this.getBoundingBox(null);
219
        int difn = 0;
220
        difn = difx;
221
        x = lastMoveRect.getX();
222
        y = lastMoveRect.getY();
223
        w = lastMoveRect.getWidth();
224
        h = lastMoveRect.getHeight();
225

    
226
        switch (this.getSelected()) {
227
            case (RECT):
228
                lastMoveRect.setRect((x + difx), (y + dify), w, h);
229

    
230
                break;
231

    
232
            case (N):
233

    
234
                if ((y + dify) > rec.getMaxY()) {
235
                    y = rec.getMaxY();
236
                } else {
237
                    y = y + dify;
238
                }
239

    
240
                lastMoveRect.setRect(x, y, w, Math.abs(h - dify));
241

    
242
                break;
243

    
244
            case (O):
245

    
246
                if ((x + difx) > rec.getMaxX()) {
247
                    x = rec.getMaxX();
248
                } else {
249
                    x = x + difx;
250
                }
251

    
252
                lastMoveRect.setRect(x, y, Math.abs(w - difx), h);
253

    
254
                break;
255

    
256
            case (S):
257

    
258
                if (y > (rec.getMaxY() + dify)) {
259
                    y = rec.getMaxY() + dify;
260
                }
261

    
262
                lastMoveRect.setRect(x, y, w, Math.abs(h + dify));
263

    
264
                break;
265

    
266
            case (E):
267

    
268
                if (x > (rec.getMaxX() + difx)) {
269
                    x = rec.getMaxX() + difx;
270
                }
271

    
272
                lastMoveRect.setRect(x, y, Math.abs(w + difx), h);
273

    
274
                break;
275

    
276
            case (NE):
277

    
278
                if ((y - difn) > rec.getMaxY()) {
279
                    y = rec.getMaxY();
280
                    x = rec.getMaxX() + difn;
281
                } else {
282
                    y = y - difn;
283
                }
284

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

    
287
                break;
288

    
289
            case (NO):
290

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

    
299
                lastMoveRect.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn));
300

    
301
                break;
302

    
303
            case (SE):
304

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

    
310
                lastMoveRect.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn));
311

    
312
                break;
313

    
314
            case (SO):
315

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

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

    
325
                break;
326

    
327
            default:
328
                lastMoveRect.setRect((x), (y), w, h);
329
        }
330

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

    
352
    /**
353
     * Devuelve true, si el punto que se pasa como par�metro esta contenido
354
     * dentro del boundingbox del fframe.
355
     *
356
     * @param p punto a comprobar.
357
     *
358
     * @return true si el punto esta dentro del boundingbox.
359
     */
360
    public boolean contains(Point2D p) {
361
        return getBoundingBox(null).contains(p.getX(), p.getY());
362
    }
363

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

    
393
        return NOSELECT;
394
    }
395

    
396
    /**
397
     * Devuelve el Cursor adecuado seg�n como est� contenido el punto, si es
398
     * para desplazamiento, o cambio de tama�o.
399
     *
400
     * @param p punto a comprobar.
401
     *
402
     * @return Cursor adecuado a la posici�n.
403
     */
404
    public Image getMapCursor(Point2D p) {
405
        int select = getContains(p);
406

    
407
        switch (select) {
408
            case (N):
409
                return iNResize;
410

    
411
            case (NE):
412
                return iNEResize;
413

    
414
            case (E):
415
                return iEResize;
416

    
417
            case (SE):
418
                return iSEResize;
419

    
420
            case (S):
421
                return iNResize;
422

    
423
            case (SO):
424
                return iNEResize;
425

    
426
            case (O):
427
                return iEResize;
428

    
429
            case (NO):
430
                return iSEResize;
431

    
432
            case (RECT):
433
                return iMove;
434
        }
435

    
436
        return null;
437
    }
438

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

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

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

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

    
488
        m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at);
489

    
490
        return m_BoundingBox;
491
    }
492

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

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

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

    
530
    /**
531
     * Crea un Objeto FFrame seg�n el tipo que sea, a partir de la informaci�n
532
     * del XMLEntity.
533
     *
534
     * @param xml XMLEntity
535
     * @param l Layout.
536
     * @param p Proyecto.
537
     *
538
     * @return Objeto de esta clase.
539
     */
540
//    public static IFFrame createFFrame03(XMLEntity xml, Layout l, Project p) {
541
//        IFFrame fframe = null;
542
//
543
//        try {
544
//                String className;
545
//                if (classnames.containsKey(xml.getStringProperty("className"))) {
546
//                        className = (String)classnames.get(xml.getStringProperty("className"));
547
//                }else {
548
//                        className = xml.getStringProperty("className");
549
//                }
550
//            Class clase = Class.forName(className);
551
//            fframe = (IFFrame) clase.newInstance();
552
//        } catch (Exception e) {
553
//            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
554
//                e);
555
//        }
556
//
557
//        if (fframe instanceof IFFrameUseProject) {
558
//            ((IFFrameUseProject) fframe).setProject(p);
559
//        }
560
//
561
//        fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
562
//                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
563
//                xml.getDoubleProperty("h")));
564
//        fframe.setXMLEntity03(xml, l);
565
//        fframe.setName(xml.getStringProperty("m_name"));
566
//
567
//        fframe.setTag(xml.getStringProperty("tag"));
568
//
569
//        return fframe;
570
//    }
571

    
572
    /**
573
     * Crea un Objeto FFrame seg�n el tipo que sea, a partir de la informaci�n
574
     * del XMLEntity.
575
     *
576
     * @param xml XMLEntity
577
     * @param p Proyecto.
578
     *
579
     * @return Objeto de esta clase.
580
     *
581
     * @throws OpenException DOCUMENT ME!
582
     */
583
//    public static IFFrame createFFrame(XMLEntity xml, Project p,Layout layout)
584
//        throws OpenException {
585
//        IFFrame fframe = null;
586
//        String className = "IFFrame";
587
//        Class clase = null;
588
//
589
//        try {
590
//                if (classnames.containsKey(xml.getStringProperty("className"))) {
591
//                        className = (String)classnames.get(xml.getStringProperty("className"));
592
//                }else {
593
//                        className = xml.getStringProperty("className");
594
//                }
595
//            clase = Class.forName(className);
596
//        } catch (ClassNotFoundException e) {
597
//            NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
598
//                e);
599
//        }
600
//
601
//        try {
602
//            fframe = (IFFrame) clase.newInstance();
603
//        } catch (InstantiationException e) {
604
//            NotificationManager.addError("Fallo creando el Frame: " +
605
//                clase.getName(), e);
606
//        } catch (IllegalAccessException e) {
607
//            NotificationManager.addError("Fallo creando el Frame: " +
608
//                clase.getName(), e);
609
//        }
610
//
611
//        try {
612
//            if (fframe instanceof IFFrameUseProject) {
613
//                ((IFFrameUseProject) fframe).setProject(p);
614
//            }
615
//                fframe.setLayout(layout);
616
//
617
//
618
//            if (xml.contains("level")) {
619
//                fframe.setLevel(xml.getIntProperty("level"));
620
//            }
621
//            if (xml.contains("num")){
622
//                    fframe.setNum(xml.getIntProperty("num"));
623
//            }
624
//            fframe.setName(xml.getStringProperty("m_name"));
625
//            fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
626
//                    xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
627
//                    xml.getDoubleProperty("h")));
628
//            fframe.setXMLEntity(xml);
629
//            fframe.setTag(xml.getStringProperty("tag"));
630
//        } catch (Exception e) {
631
//            throw new OpenException(e, className);
632
//        }
633
//
634
//        return fframe;
635
//    }
636

    
637
    /**
638
     * Dibuja sobre el graphics el rect�ngulo del fframe en modo borrador.
639
     *
640
     * @param g Graphics so bre el que dibujar.
641
     */
642
    public void drawDraft(Graphics2D g) {
643
        Rectangle2D r = getBoundingBox(null);
644

    
645
        g.setColor(Color.lightGray);
646
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
647
            (int) r.getHeight());
648
        g.setColor(Color.black);
649
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth()-1,
650
                (int) r.getHeight()-1);
651
        int scale = (int) (r.getWidth() / 12);
652
        Font f = new Font("SansSerif", Font.PLAIN, scale);
653
        g.setFont(f);
654
        g.drawString(getName(),
655
            (int) (r.getCenterX() - ((getName().length() * scale) / 4)),
656
            (int) (r.getCenterY()));
657
    }
658

    
659
    /**
660
     * Rellena con el n�mero de FFrame.
661
     *
662
     * @param i n�mero
663
     */
664
    public void setNum(int i) {
665
        num = i;
666
    }
667

    
668
    /**
669
     * Dibuja sobre el graphics el rect�ngulo del fframe pero vacio, mostrando
670
     * el nombre del fframe y vacio.
671
     *
672
     * @param g Graphics sobre el que dibujar.
673
     */
674
    public void drawEmpty(Graphics2D g) {
675
        Rectangle2D r = getBoundingBox(null);
676
        g.setColor(Color.lightGray);
677
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
678
            (int) r.getHeight());
679
        g.setColor(Color.darkGray);
680
        g.setStroke(new BasicStroke(2));
681
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
682
                (int) r.getHeight());
683
        g.setColor(Color.black);
684

    
685
        int scale = (int) (r.getWidth() / 12);
686
        Font f = new Font("SansSerif", Font.PLAIN, scale);
687
        g.setFont(f);
688

    
689
        String s = this.getNameFFrame() + " " +
690
            PluginServices.getText(this, "vacia");
691

    
692
        g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)),
693
            (int) (r.getCenterY()));
694
    }
695

    
696
    /**
697
     * Devuelve true si el rect�ngulo primero es null o si es distinto de null
698
     * e intersecta.
699
     *
700
     * @param rv Rect�ngulo
701
     * @param r Rect�ngulo
702
     *
703
     * @return True si intersecta o es null.
704
     */
705
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
706
        return (((rv != null) && rv.intersects(r)) || (rv == null));
707
    }
708

    
709
    /**
710
     * Abre el di�logo para cambiar o a�adir el tag.
711
     */
712
    public void openTag() {
713
        Tag tag = new Tag(this);
714
        PluginServices.getMDIManager().addWindow(tag);
715
    }
716

    
717
    /**
718
     * Rellena el tag del FFrame.
719
     *
720
     * @param s String que representa el valor a guardar en el tag.
721
     */
722
    public void setTag(String s) {
723
        tag = s;
724
    }
725

    
726
    /**
727
     * Devuelve el tag.
728
     *
729
     * @return tag.
730
     */
731
    public String getTag() {
732
        return tag;
733
    }
734

    
735
    /**
736
     * Dibuja sobre el graphics que se pasa como par�metro el icono que
737
     * representa que contiene un tag.
738
     *
739
     * @param g Graphics sobre el que dibujar el icono.
740
     */
741
    public void drawSymbolTag(Graphics2D g) {
742
        Rectangle2D rec = getBoundingBox(null);
743
        g.rotate(Math.toRadians(getRotation()),
744
            rec.getX() + (rec.getWidth() / 2),
745
            rec.getY() + (rec.getHeight() / 2));
746

    
747
        try {
748
            Image image = PluginServices.getIconTheme().get("symboltag-icon").getImage();
749
            g.drawImage(image, (int) rec.getX(), (int) rec.getCenterY(), 30, 30, null);
750
        } catch (NullPointerException npe) {
751
        }
752

    
753
        g.rotate(Math.toRadians(-getRotation()),
754
            rec.getX() + (rec.getWidth() / 2),
755
            rec.getY() + (rec.getHeight() / 2));
756
    }
757

    
758
    /**
759
     * Rellenar la rotaci�n para aplicar al FFrame.
760
     *
761
     * @param rotation rotaci�n que se quiere aplicar.
762
     */
763
    public void setRotation(double rotation) {
764
        m_rotation = rotation;
765
    }
766

    
767
    /**
768
     * Devuelve la rotaci�n del FFrame.
769
     *
770
     * @return Rotaci�n del FFrame.
771
     */
772
    public double getRotation() {
773
        return m_rotation;
774
    }
775

    
776
    /**
777
     * Devuelve el nivel en el que se encuentra el FFrame.
778
     *
779
     * @return nivel
780
     */
781
    public int getLevel() {
782
        return level;
783
    }
784

    
785
    /**
786
     * Inserta el nivel al que se encuentra el FFrame.
787
     *
788
     * @param l entero que refleja el nivel del FFrame.
789
     */
790
    public void setLevel(int l) {
791
        level = l;
792
    }
793

    
794
    /**
795
     * DOCUMENT ME!
796
     *
797
     * @param layout DOCUMENT ME!
798
     *
799
     * @return DOCUMENT ME!
800
     */
801
    public IFFrame cloneFFrame(Layout layout) {
802
        Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
803
        IFFrame frame = null;
804

    
805
        try {
806
            frame = createFromXML(this.getXMLEntity(), p,layout);
807
        } catch (OpenException e) {
808
            e.showError();
809
        } catch (SaveException e) {
810
            e.showError();
811
        }
812
        ((FFrame)frame).m_BoundingBox=this.m_BoundingBox;
813
        frame.setLayout(layout);
814

    
815
        if (frame instanceof IFFrameViewDependence) {
816
            ((IFFrameViewDependence) frame).initDependence(layout.getLayoutContext().getAllFFrames());
817
        }
818
        frame.setFrameLayoutFactory(factory);
819
        cloneActions(frame);
820
        return frame;
821
    }
822
    /**
823
     * DOCUMENT ME!
824
     *
825
     * @return DOCUMENT ME!
826
     *
827
     * @throws SaveException DOCUMENT ME!
828
     */
829
    public XMLEntity getXMLEntity() throws SaveException {
830
        XMLEntity xml = new XMLEntity();
831
        xml.putProperty("className", getFrameLayoutFactory().getRegisterName());
832
        xml.putProperty("m_name", m_name);
833
        xml.putProperty("x", getBoundBox().x);
834
        xml.putProperty("y", getBoundBox().y);
835
        xml.putProperty("w", getBoundBox().width);
836
        xml.putProperty("h", getBoundBox().height);
837
        xml.putProperty("m_Selected", m_Selected);
838
        xml.putProperty("tag", getTag());
839
        xml.putProperty("m_rotation", getRotation());
840
        xml.putProperty("level",getLevel());
841
        xml.putProperty("num",num);
842
        return xml;
843
    }
844

    
845
        public void setLayout(Layout layout) {
846
                this.layout=layout;
847
        }
848

    
849
        public Layout getLayout() {
850
                return layout;
851
        }
852

    
853
        public static IFFrame createFromXML(XMLEntity xml, Project p, Layout layout)
854
                throws OpenException {
855
                FrameFactory flf = null;
856
                try{
857
                        ExtensionPoint extPoint = ToolsLocator.getExtensionPointManager()
858
                                        .get("FFrames");
859
                        try {
860
                                flf = (FrameFactory) extPoint.create(xml.getStringProperty("className"));
861
                        } catch (InstantiationException e) {
862
                                NotificationManager.addError("Clase de FFrame no reconocida",
863
                                                e);
864
                        } catch (IllegalAccessException e) {
865
                                NotificationManager.addError("Clase de FFrame no reconocida",
866
                                        e);
867
                        }
868
                        IFFrame frame=flf.createFrame();
869
                        frame.setFrameLayoutFactory(flf);
870

    
871
                        if (frame instanceof IFFrameUseProject) {
872
                          ((IFFrameUseProject) frame).setProject(p);
873
                    }
874
                    frame.setLayout(layout);
875
            if (xml.contains("level")) {
876
                    frame.setLevel(xml.getIntProperty("level"));
877
                    }
878
                    if (xml.contains("num")){
879
                               frame.setNum(xml.getIntProperty("num"));
880
                    }
881
                    frame.setName(xml.getStringProperty("m_name"));
882
                    frame.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
883
                              xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
884
                              xml.getDoubleProperty("h")));
885
                    frame.setXMLEntity(xml);
886
                    frame.setTag(xml.getStringProperty("tag"));
887
                        return frame;
888
                }catch (Exception e) {
889
                        throw new OpenException(e,flf.getNameType());
890
                }
891
        }
892
        public void setFrameLayoutFactory(FrameFactory flf) {
893
                factory=flf;
894
        }
895

    
896
        public FrameFactory getFrameLayoutFactory() {
897
                return factory;
898
        }
899

    
900
//        public void setPrintingProperties(PrintRequestAttributeSet properties) {
901
//                printingProperties=properties;
902
//        }
903
}