Statistics
| Revision:

svn-document-layout / tags / 2059 / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameText.java @ 46

History | View | Annotate | Download (25.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes;
23

    
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Font;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29
import java.awt.font.FontRenderContext;
30
import java.awt.font.TextLayout;
31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.Rectangle2D;
33
import java.awt.image.BufferedImage;
34
import java.util.ArrayList;
35
import java.util.List;
36

    
37
import org.gvsig.andami.PluginServices;
38
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
39
import org.gvsig.compat.print.PrintAttributes;
40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynobject.DynStruct;
43
import org.gvsig.tools.persistence.PersistenceManager;
44
import org.gvsig.tools.persistence.PersistentState;
45
import org.gvsig.tools.persistence.exception.PersistenceException;
46

    
47
/**
48
 * FFrame para introducir un texto en el Layout.
49
 * 
50
 * @author Vicente Caballero Navarro
51
 */
52
public class FFrameText extends FFrame {
53

    
54
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameText";
55

    
56
    private static final String TEXT_FIELD = "text";
57
    private static final String S_FIELD = "s";
58
    private static final String ISFIXED_FIELD = "isFixed";
59
    private static final String FONT_FIELD = "font";
60
    private static final String POS_FIELD = "pos";
61
    private static final String TEXTCOLOR_FIELD = "textColor";
62
    private static final String TRANSITIONPIXELSMILIMETERS_FIELD =
63
        "transicionPixelsMilimetros";
64
    private static final String CELLPADDING_FIELD = "cellPadding";
65
    private static final String FONTSIZE_FIELD = "fontSize";
66
    private static final String FIXEDFONTSIZE_FIELD = "fixedFontSize";
67
    private static final String SURROUNDED_FIELD = "surrounded";
68
    private static final String HASTITLE_FIELD = "hasTitle";
69
    private static final String TITLE_FIELD = "title";
70
    private static final String TITLESIZE_FIELD = "titleSize";
71
    private static final String FRAMEBORDERSIZE_FIELD = "frameBorderSize";
72
    private static final String FRAMECOLOR_FIELD = "frameColor";
73
    private static final String TITLECOLOR_FIELD = "titleColor";
74

    
75
    /** Localizaci?n del texto. */
76
    public static final int LEFT = 0;
77
    public static final int CENTER = 1;
78
    public static final int RIGTH = 2;
79
    private ArrayList m_text = new ArrayList();
80
    private boolean m_isFixed = false;
81
    private int m_pos = LEFT;
82
    private Color textColor = Color.BLACK;
83

    
84
    // jaume
85
    private boolean surrounded = false; // The text field is surrounded by a
86
                                        // rectangle
87
    private double cellPadding = 0; // The gap between the the text field and
88
                                    // the surrounding rectangle
89
    private boolean fixedFontSize = false; // The text field font size is
90
                                           // constant fixed to the folio's size
91
    private int fontSize; // Text field's font size
92
    private boolean hasTitle; // The text field has title
93
    private String title; // The text for the title
94
    private int titleSize; // The title's font size
95
    private double frameBorderSize = 0; // The surrounding rectangle's border
96
                                        // size
97
    private Color frameColor = Color.BLACK; // The surrounding rectangle's color
98
    private Color titleColor = Color.BLACK; // The title's color
99
    private Font m_f = null;
100
    private boolean transicionPixelsMilimetros = true;
101

    
102
    /**
103
     * Crea un nuevo FFrameText.
104
     */
105
    public FFrameText() {
106
        m_f = new Font("SansSerif", Font.PLAIN, 9);
107
    }
108

    
109
    /**
110
     * Inserta la fuente del texto.
111
     * 
112
     * @param f
113
     *            Fuente del texto.
114
     */
115
    public void setFont(Font f) {
116
        m_f = f;
117
    }
118

    
119
    /**
120
     * Devuelve el color del texto del FFrameText.
121
     * 
122
     * @return Color del texto.
123
     */
124
    public Color getTextColor() {
125
        return textColor;
126
    }
127

    
128
    /**
129
     * Obtiene el fixedFontSize
130
     * 
131
     * @return boolean
132
     */
133
    public boolean isFontSizeFixed() {
134
        return fixedFontSize;
135
    }
136

    
137
    /**
138
     * Establece fixedFontSize
139
     * 
140
     * @param fixedFontSize
141
     */
142
    public void setFixedFontSize(boolean fixedFontSize) {
143
        this.fixedFontSize = fixedFontSize;
144
    }
145

    
146
    /**
147
     * Obtiene el fontSize
148
     * 
149
     * @return int
150
     */
151
    public int getFontSize() {
152
        return fontSize;
153
    }
154

    
155
    /**
156
     * Establece fontSize
157
     * 
158
     * @param fontSize
159
     */
160
    public void setFontSize(int fontSize) {
161
        this.fontSize = fontSize;
162
    }
163

    
164
    /**
165
     * Obtiene el cellPadding
166
     * 
167
     * @return int
168
     */
169
    public double getCellPadding() {
170
        return cellPadding;
171
    }
172

    
173
    /**
174
     * Inserta el color del texto a escribir.
175
     * 
176
     * @param color
177
     *            Color del texto.
178
     */
179
    public void setTextColor(Color color) {
180
        textColor = color;
181
    }
182

    
183
    /**
184
     * Devuelve la fuente del texto.
185
     * 
186
     * @return Fuente del texto.
187
     */
188
    public Font getFont() {
189
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
190
    }
191

    
192
    /**
193
     * Devuelve la posici?n izquierda, centro o derecha del texto.
194
     * 
195
     * @return Posici?n del texto.
196
     */
197
    public int getPos() {
198
        return m_pos;
199
    }
200

    
201
    /**
202
     * Pone la posici?n izquierda, centro o derecha del texto.
203
     * 
204
     * @param p
205
     *            0=LEFT,1=CENTER,2=RIGTH.
206
     */
207
    public void setPos(int p) {
208
        m_pos = p;
209
    }
210

    
211
    /**
212
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
213
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
214
     * de dibujar.
215
     * 
216
     * @param g
217
     *            Graphics
218
     * @param at
219
     *            Transformada af?n.
220
     * @param rv
221
     *            rect?ngulo sobre el que hacer un clip.
222
     * @param imgBase
223
     *            Imagen para acelerar el dibujado.
224
     */
225
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
226
        BufferedImage imgBase) {
227
        g.setColor(Color.BLACK);
228

    
229
        Rectangle2D.Double rec = getBoundingBox(at);
230
        Rectangle2D.Double raux = (Rectangle2D.Double) rec.clone();
231
        g.rotate(Math.toRadians(getRotation()), raux.x + (raux.width / 2),
232
            raux.y + (raux.height / 2));
233

    
234
        int longmax = 1;
235

    
236
        if (intersects(rv, raux)) { // comprueba que no cae fuera de la pantalla
237

    
238
            if (m_text.isEmpty()) {
239
                drawEmpty(g);
240
            } else {
241
                for (int i = 0; i < m_text.size(); i++) {
242
                    if (m_text.get(i) == null) {
243
                        m_text.set(i, "<NULL>");
244
                    }
245
                    String text = (String) m_text.get(i);
246
                    if (text.length() > longmax) {
247
                        longmax = text.length();
248
                    }
249
                }
250

    
251
                FontRenderContext frc = g.getFontRenderContext();
252
                int scaledFontSize;
253

    
254
                // TODO myScale es la escala sobre la que se extraen todos los
255
                // escalados. Esto
256
                // funciona bien tal cual est? si la ratio de aspecto
257
                // (alto/ancho) del folio es constante
258
                // porque se toma como medidas el ancho del folio real y el
259
                // ancho del folio en pantalla.
260
                // No se que pasar? si la ratio cambia, por ejemplo si se usan
261
                // USLetter en lugar de DIN A4
262
                double myScale = at.getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth();
263

    
264
                // Distinguish when the font has fixed size or not
265
                if (isFontSizeFixed()) {
266
                    scaledFontSize = (int) (myScale * fontSize);
267
                } else {
268
                    scaledFontSize = ((int) (raux.width)) / longmax;
269

    
270
                    if (scaledFontSize > (int) ((raux.height) / m_text.size())) {
271
                        scaledFontSize = (int) ((raux.height) / m_text.size());
272
                    }
273
                }
274

    
275
                if (m_f != null) {
276
                    // Aqu? se ajusta a partir de las caracter?sticas de la
277
                    // fuente, una nueva fuente con el tama?o ajustado.
278
                    m_f =
279
                        new Font(m_f.getFontName(), m_f.getStyle(),
280
                            scaledFontSize);
281
                } else {
282
                    // Aqu? pasa cuando se abre el di?logo para seleccionar un
283
                    // tipo de fuente y se cierra sin haber seleccionado
284
                    // ninguna.
285
                    m_f = new Font("SansSerif", Font.PLAIN, scaledFontSize);
286
                }
287

    
288
                // Draw the text title if it exists
289
                if (hasTitle()) {
290
                    int scaledTitleFontSize = (int) (myScale * titleSize);
291
                    int gap = 3;
292

    
293
                    if (isSurrounded()) {
294
                        // Para evitar que el marco se pinte sobre el t?tulo
295
                        gap +=
296
                            (int) (FLayoutUtilities.fromSheetDistance(
297
                                frameBorderSize, at) * myScale);
298
                    }
299

    
300
                    g.setColor(titleColor);
301

    
302
                    Font titleFont =
303
                        new Font(m_f.getFontName(), m_f.getStyle(),
304
                            scaledTitleFontSize);
305

    
306
                    if (!getTitle().equals("")) {
307
                        TextLayout titleTextLayout =
308
                            new TextLayout(getTitle(), titleFont, frc);
309
                        titleTextLayout.draw(g, (float) raux.getX(),
310
                            (float) (raux.getY() - (gap * myScale)));
311
                    }
312
                }
313

    
314
                // Draw the frame involving the text if it exists
315
                if (isSurrounded()) {
316
                    g.setColor(frameColor);
317
                    // g.drawRect((int) raux.x, (int) raux.y, (int) raux.width,
318
                    // (int) raux.height);
319

    
320
                    double scaledCellPadding =
321
                        FLayoutUtilities.fromSheetDistance(cellPadding, at);
322
                    double sizeBorder =
323
                        FLayoutUtilities.fromSheetDistance(frameBorderSize, at);
324

    
325
                    // if (sizeBorder > 1) {
326
                    int bordermm = (int) (sizeBorder * 10);
327
                    int scaledCellPaddingmm = (int) (scaledCellPadding * 10);
328
                    // System.out.println("borderSize = " + bordermm);
329
                    g.setStroke(new BasicStroke(bordermm));
330
                    // int scaledBorderSize = (int) (sizeBorder * myScale);
331

    
332
                    // for (int i = scaledBorderSize - 1; i > 0; i--)
333
                    // g.drawRect((int) raux.x - i, (int) raux.y - i,
334
                    // (int) raux.width + (2 * i),
335
                    // (int) raux.height + (2 * i));
336
                    g.drawRect((int) (raux.x + bordermm / 2 - 1), (int) (raux.y
337
                        + bordermm / 2 - 1), (int) (raux.width - bordermm + 2),
338
                        (int) (raux.height - bordermm + 2));
339
                    g.setStroke(new BasicStroke(0));
340
                    // }
341

    
342
                    // Recalibro el rectangulo para establecer el ?rea donde se
343
                    // dibujan las fuentes
344
                    // al ?rea marcada con el rat?n menos la distancia al marco
345
                    // especificada
346
                    raux.setRect(raux.getX() + scaledCellPaddingmm + bordermm,
347
                        raux.getY() + scaledCellPaddingmm + bordermm,
348
                        raux.getWidth() - (scaledCellPaddingmm * 2) - bordermm
349
                            * 2, raux.getHeight() - (scaledCellPaddingmm * 2)
350
                            - bordermm * 2);
351

    
352
                    if (raux.getWidth() <= 0 || raux.getHeight() <= 0) {
353
                        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"too_large_border")+": "+bordermm+
354
                        // " + "+scaledCellPaddingmm);
355
                        g.setColor(Color.red);
356
                        drawError(getBoundingBox(at), 15, g,
357
                            PluginServices.getText(this, "too_large_border")
358
                                + ": " + frameBorderSize + "cm + "
359
                                + cellPadding + "cm");
360
                        // g.rotate(Math.toRadians(-getRotation()),
361
                        // raux.x + (raux.width / 2), raux.y + (raux.height /
362
                        // 2));
363
                        return;
364
                    }
365
                }
366

    
367
                g.setColor(textColor);
368

    
369
                drawText(raux, scaledFontSize, g);
370
                g.rotate(Math.toRadians(-getRotation()), raux.x
371
                    + (raux.width / 2), raux.y + (raux.height / 2));
372
            }
373
        }
374

    
375
        raux = null;
376
    }
377

    
378
    private void drawError(Rectangle2D r, int sfs, Graphics2D g, String error) {
379
        FontRenderContext frc = g.getFontRenderContext();
380
        TextLayout textLayout = null;
381
        m_f = new Font(m_f.getFontName(), m_f.getStyle(), sfs);
382
        textLayout = new TextLayout(error, m_f, frc);
383
        textLayout.draw(g, (float) r.getCenterX(), (float) (r.getCenterY()));
384

    
385
    }
386

    
387
    /**
388
     * Dibuja el texto sobre el graphics con el tama?o adecuado.
389
     * 
390
     * @param r
391
     *            Rect?ngulo sobre el que dibujar.
392
     * @param sfs
393
     *            Tama?o aproximado del texto.
394
     * @param g
395
     *            Graphics sobre el que dibujar el texto.
396
     */
397
    private void drawText(Rectangle2D r, int sfs, Graphics2D g) {
398
        int minSFS = Integer.MAX_VALUE;
399
        FontRenderContext frc = g.getFontRenderContext();
400
        int ht = (int) (r.getHeight() / m_text.size());
401

    
402
        if (isFontSizeFixed()) {
403
            minSFS = sfs;
404
        } else {
405
            for (int i = 0; i < m_text.size(); i++) {
406
                if (!((String) m_text.get(i)).equals("")
407
                    && !((String) m_text.get(i)).equals("\n")) {
408
                    TextLayout textaux =
409
                        new TextLayout((String) m_text.get(i), m_f, frc);
410
                    Rectangle2D txtBound = textaux.getBounds();
411
                    double difW = txtBound.getWidth() / r.getWidth();
412
                    double difH =
413
                        (txtBound.getHeight() * m_text.size())
414
                            / (r.getHeight());
415

    
416
                    if (difW > difH) {
417
                        if (minSFS > sfs) {
418
                            minSFS = (int) (sfs / difW);
419
                        }
420
                    } else {
421
                        if (minSFS > sfs) {
422
                            minSFS = (int) (sfs / difH);
423
                        }
424
                    }
425
                }
426
            }
427
        }
428

    
429
        TextLayout textLayout = null;
430

    
431
        for (int i = 0; i < m_text.size(); i++) {
432
            if (!((String) m_text.get(i)).equals("")) {
433
                m_f = new Font(m_f.getFontName(), m_f.getStyle(), minSFS);
434

    
435
                textLayout = new TextLayout((String) m_text.get(i), m_f, frc);
436

    
437
                Rectangle2D txtBound = textLayout.getBounds();
438
                float difW = (float) (r.getWidth() - txtBound.getWidth());
439

    
440
                switch (m_pos) {
441
                case (LEFT):
442
                    textLayout.draw(g, (float) r.getX(),
443
                        (float) (r.getY() + (ht * (i + 0.8))));
444

    
445
                    break;
446

    
447
                case (CENTER):
448
                    textLayout.draw(g, (float) r.getX() + (difW / 2),
449
                        (float) (r.getY() + (ht * (i + 0.8))));
450

    
451
                    break;
452

    
453
                case (RIGTH):
454
                    textLayout.draw(g, (float) r.getX() + difW,
455
                        (float) (r.getY() + (ht * (i + 0.8)))); // - (ht /
456
                                                                // 2))));
457

    
458
                    break;
459
                }
460
            }
461
        }
462
    }
463

    
464
    /*
465
     * @see
466
     * com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java
467
     * .awt.Graphics2D,
468
     * java.awt.geom.AffineTransform)
469
     */
470
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
471
        PrintAttributes properties) {
472
        draw(g, at, null, null);
473
    }
474

    
475
    /**
476
     * Rellenar el texto que se quiere a?adir al Layout.
477
     * 
478
     * @param s
479
     *            String a a?adir.
480
     */
481
    public void addText(String s) {
482
        m_text.add(s);
483
    }
484

    
485
    /**
486
     * Devuelve el ArrayList que contiene las l?neas de texto.
487
     * 
488
     * @return ArrayList.
489
     */
490
    public ArrayList getText() {
491
        return m_text;
492
    }
493

    
494
    /**
495
     * Seleccionar si se quiere un tama?o fijo o adecuado a la escala.
496
     * 
497
     * @param b
498
     *            true si se quiere tama?o fijo.
499
     */
500
    public void setSizeFixed(boolean b) {
501
        m_isFixed = b;
502
    }
503

    
504
    /**
505
     * Devuelve si est? fijado el tama?o.
506
     * 
507
     * @return True si est? fijado el tama?o.
508
     */
509
    public boolean isSizeFixed() {
510
        return m_isFixed;
511
    }
512

    
513
    /**
514
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
515
     */
516
    public String getNameFFrame() {
517
        return PluginServices.getText(this, "texto") + num;
518
    }
519

    
520
    public String getName() {
521
        return PERSISTENCE_DEFINITION_NAME;
522
    }
523

    
524
    /**
525
     * Sets FFrameText to draw an involving rectangle
526
     * 
527
     * @param b
528
     */
529
    public void setSurrounded(boolean b) {
530
        surrounded = b;
531
    }
532

    
533
    /**
534
     * True if the FFrameText is set to draw an involving rectangle, or false
535
     * if not.
536
     * 
537
     * @return boolean
538
     */
539
    public boolean isSurrounded() {
540
        return surrounded;
541
    }
542

    
543
    /**
544
     * Sets the gap between the involving rectangle and the text
545
     * 
546
     * @param i
547
     */
548
    public void setCellPadding(double i) {
549
        cellPadding = i;
550
    }
551

    
552
    /**
553
     * Devuelve true si tiene un t?tulo.
554
     * 
555
     * @return
556
     */
557
    public boolean hasTitle() {
558
        return hasTitle;
559
    }
560

    
561
    /**
562
     * Devuelve un string con el t?tulo.
563
     * 
564
     * @return
565
     */
566
    public String getTitle() {
567
        return title;
568
    }
569

    
570
    /**
571
     * Inserta true si tiene t?tulo
572
     * 
573
     * @param b
574
     */
575
    public void setHasTitle(boolean b) {
576
        hasTitle = b;
577
    }
578

    
579
    /**
580
     * Inserta un string con el t?tulo.
581
     * 
582
     * @param text
583
     */
584
    public void setTitle(String text) {
585
        title = text;
586
    }
587

    
588
    /**
589
     * Devuelve el tama?o del t?tulo.
590
     * 
591
     * @return
592
     */
593
    public int getTitleSize() {
594
        return titleSize;
595
    }
596

    
597
    /**
598
     * Inserta el tama?o del t?tulo.
599
     * 
600
     * @param size
601
     *            DOCUMENT ME!
602
     */
603
    public void setTitleSize(int size) {
604
        titleSize = size;
605
    }
606

    
607
    /**
608
     * Inserta el tama?o del borde.
609
     * 
610
     * @param size
611
     */
612
    public void setFrameBorderSize(double size) {
613
        frameBorderSize = size;
614
    }
615

    
616
    /**
617
     * Devuelve el tama?o del borde.
618
     * 
619
     * @return
620
     */
621
    public double getFrameBorderSize() {
622
        return frameBorderSize;
623
    }
624

    
625
    /**
626
     * DOCUMENT ME!
627
     * 
628
     * @param frameColor
629
     */
630
    public void setFrameColor(Color frameColor) {
631
        this.frameColor = frameColor;
632
    }
633

    
634
    /**
635
     * DOCUMENT ME!
636
     * 
637
     * @param titleColor
638
     *            DOCUMENT ME!
639
     */
640
    public void setTitleColor(Color titleColor) {
641
        this.titleColor = titleColor;
642
    }
643

    
644
    /**
645
     * DOCUMENT ME!
646
     * 
647
     * @return DOCUMENT ME!
648
     */
649
    public Color getFrameColor() {
650
        return frameColor;
651
    }
652

    
653
    /**
654
     * DOCUMENT ME!
655
     * 
656
     * @return DOCUMENT ME!
657
     */
658
    public Color getTitleColor() {
659
        return titleColor;
660
    }
661

    
662
    /**
663
     * Use this method if you want the text in the FFrameText to be removed.
664
     */
665
    public void clearText() {
666
        m_text.clear();
667
    }
668

    
669
    public void initialize() {
670
        // TODO Auto-generated method stub
671

    
672
    }
673

    
674
    public static void registerPersistent() {
675
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
676
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
677
            DynStruct definition =
678
                manager.addDefinition(FFrameText.class,
679
                    PERSISTENCE_DEFINITION_NAME,
680
                    "FFrameText persistence definition", null, null);
681

    
682
            definition.extend(manager
683
                .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
684

    
685
            /*
686
             * field 's' is Rectangle but stored as Rectangle2D
687
             */
688
            definition.addDynFieldObject(S_FIELD)
689
                .setClassOfValue(Rectangle2D.class).setMandatory(true);
690
            definition.addDynFieldList(TEXT_FIELD)
691
                  .setClassOfValue(String.class).setMandatory(true);
692
            definition.addDynFieldBoolean(ISFIXED_FIELD).setMandatory(true);
693
            definition.addDynFieldObject(FONT_FIELD)
694
                .setClassOfValue(Font.class).setMandatory(true);
695
            definition.addDynFieldInt(POS_FIELD).setMandatory(true);
696
            definition.addDynFieldObject(TEXTCOLOR_FIELD)
697
                .setClassOfValue(Color.class).setMandatory(false);
698
            definition.addDynFieldBoolean(TRANSITIONPIXELSMILIMETERS_FIELD)
699
                .setMandatory(true);
700
            definition.addDynFieldDouble(CELLPADDING_FIELD).setMandatory(false);
701
            definition.addDynFieldInt(FONTSIZE_FIELD).setMandatory(false);
702
            definition.addDynFieldBoolean(FIXEDFONTSIZE_FIELD).setMandatory(
703
                false);
704
            definition.addDynFieldBoolean(SURROUNDED_FIELD).setMandatory(false);
705
            definition.addDynFieldBoolean(HASTITLE_FIELD).setMandatory(false);
706
            definition.addDynFieldString(TITLE_FIELD).setMandatory(false);
707
            definition.addDynFieldInt(TITLESIZE_FIELD).setMandatory(false);
708
            definition.addDynFieldDouble(FRAMEBORDERSIZE_FIELD).setMandatory(
709
                false);
710
            definition.addDynFieldObject(FRAMECOLOR_FIELD)
711
                .setClassOfValue(Color.class).setMandatory(false);
712
            definition.addDynFieldObject(TITLECOLOR_FIELD)
713
                .setClassOfValue(Color.class).setMandatory(false);
714
        }
715
    }
716

    
717
    @Override
718
    public void loadFromState(PersistentState state)
719
        throws PersistenceException {
720
        super.loadFromState(state);
721
        
722
        /*
723
         * field 's' is Rectangle but stored as Rectangle2D
724
         */
725
        Rectangle2D s_2d = (Rectangle2D) state.get(S_FIELD);
726
        s = new Rectangle(
727
            (int) s_2d.getX(),
728
            (int) s_2d.getY(),
729
            (int) s_2d.getWidth(),
730
            (int) s_2d.getHeight());
731
        
732
        /*
733
         * the text is an arraylist of strings
734
         */
735
        List text_list = state.getList(TEXT_FIELD);
736
        for (int i=0; i<text_list.size(); i++) {
737
            m_text.add((String) text_list.get(i));
738
        }
739

    
740
        m_isFixed = state.getBoolean(ISFIXED_FIELD);
741
        m_f = (Font) state.get(FONT_FIELD);
742
        m_pos = state.getInt(POS_FIELD);
743
        textColor = (Color) state.get(TEXTCOLOR_FIELD);
744
        transicionPixelsMilimetros =
745
            state.getBoolean(TRANSITIONPIXELSMILIMETERS_FIELD);
746
        cellPadding = state.getDouble(CELLPADDING_FIELD);
747
        fontSize = state.getInt(FONTSIZE_FIELD);
748
        fixedFontSize = state.getBoolean(FIXEDFONTSIZE_FIELD);
749
        surrounded = state.getBoolean(SURROUNDED_FIELD);
750
        hasTitle = state.getBoolean(HASTITLE_FIELD);
751
        title = state.getString(TITLE_FIELD);
752
        titleSize = state.getInt(TITLESIZE_FIELD);
753
        frameBorderSize = state.getDouble(FRAMEBORDERSIZE_FIELD);
754
        frameColor = (Color) state.get(FRAMECOLOR_FIELD);
755
        titleColor = (Color) state.get(TITLECOLOR_FIELD);
756
    }
757

    
758
    @Override
759
    public void saveToState(PersistentState state) throws PersistenceException {
760
        super.saveToState(state);
761

    
762
        /*
763
         * field 's' is Rectangle but stored as Rectangle2D
764
         */
765
        Rectangle2D s_2d = new Rectangle2D.Double(
766
            s.x, s.y, s.width, s.height);
767
        state.set(S_FIELD, s_2d);
768
        
769
        state.set(TEXT_FIELD, m_text);
770
        state.set(ISFIXED_FIELD, m_isFixed);
771
        state.set(FONT_FIELD, m_f);
772
        state.set(POS_FIELD, m_pos);
773
        state.set(TEXTCOLOR_FIELD, textColor);
774
        state.set(TRANSITIONPIXELSMILIMETERS_FIELD, transicionPixelsMilimetros);
775
        state.set(CELLPADDING_FIELD, cellPadding);
776
        state.set(FONTSIZE_FIELD, fontSize);
777
        state.set(FIXEDFONTSIZE_FIELD, fixedFontSize);
778
        state.set(SURROUNDED_FIELD, surrounded);
779
        state.set(HASTITLE_FIELD, hasTitle);
780
        state.set(TITLE_FIELD, title);
781
        state.set(TITLESIZE_FIELD, titleSize);
782
        state.set(FRAMEBORDERSIZE_FIELD, frameBorderSize);
783
        state.set(FRAMECOLOR_FIELD, frameColor);
784
        state.set(TITLECOLOR_FIELD, titleColor);
785
    }
786
}