Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / symbol / SmartTextSymbol.java @ 47790

History | View | Annotate | Download (20.1 KB)

1 40911 jldominguez
package org.gvsig.labeling.symbol;
2
3
import java.awt.BasicStroke;
4
import java.awt.Color;
5
import java.awt.Font;
6
import java.awt.Graphics2D;
7
import java.awt.Rectangle;
8
import java.awt.RenderingHints;
9
import java.awt.Shape;
10
import java.awt.font.FontRenderContext;
11
import java.awt.font.GlyphVector;
12
import java.awt.font.LineMetrics;
13
import java.awt.geom.AffineTransform;
14 41646 jjdelcerro
import org.apache.commons.lang3.StringUtils;
15 40911 jldominguez
import org.gvsig.compat.print.PrintAttributes;
16
import org.gvsig.fmap.dal.feature.Feature;
17
import org.gvsig.fmap.geom.Geometry;
18
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
19
import org.gvsig.fmap.geom.Geometry.TYPES;
20
import org.gvsig.fmap.geom.GeometryLocator;
21
import org.gvsig.fmap.geom.GeometryManager;
22
import org.gvsig.fmap.geom.exception.CreateGeometryException;
23
import org.gvsig.fmap.geom.primitive.Envelope;
24
import org.gvsig.fmap.geom.primitive.GeneralPathX;
25
import org.gvsig.fmap.geom.primitive.Point;
26
import org.gvsig.fmap.geom.primitive.Surface;
27
import org.gvsig.fmap.mapcontext.MapContextLocator;
28
import org.gvsig.fmap.mapcontext.ViewPort;
29
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints;
30
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
31
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
32
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
33
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
34
import org.gvsig.labeling.placements.PointPlacementConstraints;
35 47476 fdiaz
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.TextPath;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
37 40911 jldominguez
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DynStruct;
40
import org.gvsig.tools.persistence.PersistenceManager;
41
import org.gvsig.tools.persistence.PersistentState;
42
import org.gvsig.tools.persistence.exception.PersistenceException;
43
import org.gvsig.tools.task.Cancellable;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46
47 41646 jjdelcerro
48 40911 jldominguez
/**
49
 * Class used to create symbols composed using a text defined by
50
 * the user.This text can be edited (changing the color, the font of the characters, and
51
 * the rotation of the text)and has the property that can follow a path.If this path
52
 * does not exist, the text is treated as a simpletextsymbol (when is drawn).
53
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
54
 */
55 47476 fdiaz
public class SmartTextSymbol extends AbstractSymbol implements ISimpleTextSymbol {
56 40911 jldominguez
57
        private static final Logger logger = LoggerFactory.getLogger(
58
                        SmartTextSymbol.class);
59
        // ===========================
60
        public static final String SMART_TEXT_SYMBOL_PERSISTENCE_DEFINITION_NAME =
61
                        "SMART_TEXT_SYMBOL_PERSISTENCE_DEFINITION_NAME";
62
63
        private static final String FIELD_UNIT = "unit";
64
        private static final String FIELD_REFERENCE_SYSTEM = "referenceSystem";
65
        private static final String FIELD_IS_SHAPE_VISIBLE = "isShapeVisible";
66
        private static final String FIELD_DESCRIPTION = "description";
67
        private static final String FIELD_TEXT = "text";
68
        private static final String FIELD_FONT = "font";
69
        private static final String FIELD_TEXT_COLOR = "textColor";
70
        private static final String FIELD_ROTATION = "rotation";
71
        private static final String FIELD_AUTO_RESIZE = "autoResize";
72
        // ====================================
73
        private static final String FIELD_HAS_HALO = "hasHalo";
74
        private static final String FIELD_HALO_COLOR = "haloColor";
75
        private static final String FIELD_HALO_WIDTH = "haloWidth";
76
        // ====================================
77 41131 jldominguez
        /*
78 40911 jldominguez
        public static final int SYMBOL_STYLE_TEXTALIGNMENT_LEFT = 0;
79
        public static final int SYMBOL_STYLE_TEXTALIGNMENT_RIGHT = 1;
80
        public static final int SYMBOL_STYLE_TEXTALIGNMENT_CENTERED = 2;
81 41131 jldominguez
        */
82 40911 jldominguez
83
        // ===========================
84
        private static GeometryManager geoman = GeometryLocator.getGeometryManager();
85
86
        private String text;
87
        private FontRenderContext frc = new FontRenderContext(
88
                        new AffineTransform(), false, true);
89
90
        private double characterSpacing;
91
        private double characterWidth;
92
        private double leading;
93
        private double wordSpacing;
94
        private boolean rightToLeft;
95
        private double margin;
96
        private int alignment;
97
        private boolean kerning = false;
98
        private TextPath tp;
99 47476 fdiaz
        private final IPlacementConstraints constraints;
100 40911 jldominguez
        private double rotation = 0;
101
        private Color textColor = Color.BLACK;
102
        private Font font;
103
        private boolean autoresize = false;
104
105
        // =======================
106
107
        private boolean hasHalo = false;
108
        private Color haloColor = Color.WHITE;
109
        private float haloWidth = 3;
110
        private BasicStroke haloStroke = new BasicStroke(
111
                        6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
112
113
        // =======================
114
115
116
        public SmartTextSymbol(ITextSymbol sym, IPlacementConstraints constraints) {
117
118
//                if(sym instanceof SimpleTextSymbol){
119
//                        SimpleTextSymbol mySym = (SimpleTextSymbol)sym;
120
121
                        this.setAutoresizeEnabled(sym.isAutoresizeEnabled());
122
                        this.setDescription(sym.getDescription());
123
                        this.setFont(sym.getFont());
124
                        this.setFontSize(sym.getFont().getSize());
125
                        this.setIsShapeVisible(sym.isShapeVisible());
126
                        this.setText(sym.getText());
127
                        this.setTextColor(sym.getTextColor());
128
129
                        this.setDrawWithHalo(sym.isDrawWithHalo());
130
                        this.setHaloColor(sym.getHaloColor());
131
                        this.setHaloWidth(sym.getHaloWidth());
132
133
                        this.constraints = constraints;
134
135
                        setCharacterSpacing(2); //???
136
                        setWordSpacing(TextPath.DEFAULT_WORD_SPACING);
137
                        boolean rtl = false; // right to left text
138
                        if (constraints.isAtTheBeginingOfLine()) {
139
                                if (rtl) {
140 41131 jldominguez
141
                                        setAlignment(ITextSymbol.SYMBOL_STYLE_ALIGNMENT_RIGHT);
142 40911 jldominguez
                                }
143
                                else {
144 41131 jldominguez
                                        setAlignment(ITextSymbol.SYMBOL_STYLE_ALIGNMENT_LEFT);
145 40911 jldominguez
                                }
146
                        }
147
                        else if (constraints.isAtTheEndOfLine()) {
148
                                if (rtl) {
149 41131 jldominguez
                                        setAlignment(ITextSymbol.SYMBOL_STYLE_ALIGNMENT_LEFT);
150 40911 jldominguez
                                }
151
                                else {
152 41131 jldominguez
                                        setAlignment(ITextSymbol.SYMBOL_STYLE_ALIGNMENT_RIGHT);
153 40911 jldominguez
                                }
154
                        }
155
                        else { //constraints.isInTheMiddleOfLine() or constraints.isAtBestOfLine()
156 41131 jldominguez
                                setAlignment(ITextSymbol.SYMBOL_STYLE_ALIGNMENT_CENTERED);
157 40911 jldominguez
                        }
158
                        setKerning(false);
159
                        setRightToLeft(rtl);
160
                // }
161
        }
162
163
164 47476 fdiaz
//        public void setIsShapeVisible(boolean v) {
165
//                this.shapeVisible = v;
166
//        }
167
//
168
//        public boolean isShapeVisible() {
169
//                return shapeVisible;
170
//        }
171 40911 jldominguez
172
173
174
        public SmartTextSymbol() {
175
                PointPlacementConstraints pc = new PointPlacementConstraints();
176
                this.constraints = pc;
177
178
                SymbolPreferences preferences =
179
                                MapContextLocator.getSymbolManager().getSymbolPreferences();
180
                font = preferences.getDefaultSymbolFont();
181
                textColor = preferences.getDefaultSymbolColor();
182
        }
183
184
        /**
185
         * Draws the text according. If this symbol has the text path set, then
186
         * it is used as the text line, otherwise shp <b>must be an FPoint2D</b>
187
         * indicating the starting point of the text and then the text will
188
         * be rendered from there and following the rotation previously set.
189
         */
190
191
        public void draw(Graphics2D g, AffineTransform affineTransform,
192
                        Geometry geom, Feature f, Cancellable cancel) {
193 47476 fdiaz
            draw(g, affineTransform, geom, f, cancel, null);
194
        }
195
196
        public void draw(Graphics2D g, AffineTransform affineTransform,
197
                        Geometry geom, Feature f, Cancellable cancel, Rectangle r) {
198 40911 jldominguez
199 47476 fdiaz
                if (!isShapeVisible()){
200
                    return;
201
                }
202
203
                if(r != null) {
204
                    geom = getSampleGeometry(r);
205
                }
206 40911 jldominguez
207
                setMargin(0);
208 41646 jjdelcerro
                if ( StringUtils.isEmpty(text) ) {
209
                    return;
210
                }
211 40911 jldominguez
212
                char[] text_chars = text.toCharArray();
213
                tp = new TextPath(g, geom, text_chars, getFont(),
214
                                (float) characterSpacing, (float) characterWidth, kerning,
215
                                (float) leading, alignment, (float) wordSpacing, (float) margin, rightToLeft);
216
                Font font = getFont();
217
                g.setFont(font);
218
                FontRenderContext frc = g.getFontRenderContext();
219
                LineMetrics lineMetrics = font.getLineMetrics(getText(), frc);
220
221
//                GlyphVector glyph =  font.layoutGlyphVector(frc, charText, 0, charText.length, Font.LAYOUT_NO_START_CONTEXT);
222
                double cons = 0;
223
224
                /* Repartimos el leading (espacio de separaci?n entre lineas)
225
                 * arriba y abajo para que exista la misma separaci?n entre la
226
                 * caja de la letra y la linea tanto si se dibuja por abajo como
227
                 * si se dibuja por arriba.
228
                 */
229
                if(this.constraints.isAboveTheLine()) {
230
                        cons = lineMetrics.getDescent()+lineMetrics.getLeading()/2;
231
                }
232
                else if (this.constraints.isBelowTheLine()) {
233
                        cons = -(lineMetrics.getAscent()+lineMetrics.getLeading()/2);
234
                }
235
                /* Dibujamos la letra de tal manera que el centro de la caja de letra
236
                 * coincida con la linea
237
                 */
238
                else if(this.constraints.isOnTheLine()) {
239
//                        cons = lineMetrics.getDescent()+(lineMetrics.getLeading()/2)-(lineMetrics.getHeight()/2);
240
                        cons = lineMetrics.getDescent()+lineMetrics.getLeading()-(lineMetrics.getHeight()/2);
241
                }
242
243 41131 jldominguez
                double[] coords = null; // tp.nextPosForGlyph(0);
244 40911 jldominguez
245
                for (int i = 0; i < tp.getGlyphCount(); i++) {
246
                        coords = tp.nextPosForGlyph(i);
247
                        if (coords[0] == TextPath.NO_POS || coords[1] == TextPath.NO_POS)
248
                                continue;
249
250
                        // move the label 'cons" units above/below the line
251
                        double xOffset = cons * Math.sin(coords[2]);
252
                        double yOffset = cons * Math.cos(coords[2]);
253
254
                        g.translate(coords[0]+xOffset, coords[1]-yOffset);
255
                        g.rotate(coords[2]);
256
257
                        char[] aux = new char[1];
258
                        aux[0] = text_chars[i];
259
                        if (isDrawWithHalo()) {
260
                                GlyphVector glyph = font.createGlyphVector(frc, aux);
261
                                Shape outlineChar = glyph.getOutline();
262
                                g.setStroke(haloStroke);
263
                                g.setColor(getHaloColor());
264
265
                                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
266
                                                RenderingHints.VALUE_ANTIALIAS_ON);
267
                                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
268
                                                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
269
                                // =============================
270
                                g.draw(outlineChar);
271
                                // =============================
272
                                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
273
                                                RenderingHints.VALUE_ANTIALIAS_OFF);
274
                        }
275
276
                        g.setColor(this.getTextColor());
277
                        g.drawString(String.valueOf(text_chars[i]), 0, 0);
278
                        g.rotate(-coords[2]);
279
                        g.translate(-coords[0]-xOffset, -coords[1]+yOffset);
280
                }
281
        }
282
283
        public void getPixExtentPlus(
284
                        Geometry shp, float[] distances, ViewPort viewPort, int dpi) {
285
286
                /*
287
                 * TODO Is this used?
288
                 */
289
                distances[0] = 0;
290
                distances[1] = 0;
291
                // throw new RuntimeException("Not yet implemented!");
292
        }
293
294
        public int getOnePointRgb() {
295
                return getTextColor().getRGB();
296
        }
297
298
        /*
299
        public XMLEntity getXMLEntity() {
300
                XMLEntity xml = new XMLEntity();
301
                xml.putProperty("className", getClassName());
302
                xml.putProperty("desc", getDescription());
303
                xml.putProperty("isShapeVisible", isShapeVisible());
304
                return xml;
305
        }
306
        */
307
308
        public int getSymbolType() {
309
                return Geometry.TYPES.GEOMETRY;
310
        }
311
312
        public boolean isSuitableFor(Geometry geom) {
313
                return geom.getGeometryType().isTypeOf(TYPES.CURVE);
314
        }
315 47476 fdiaz
316
    public Geometry getSampleGeometry(Rectangle r) {
317
        Surface surf = null;
318
        try {
319
            surf = geoman.createSurface(SUBTYPES.GEOM2D);
320
        } catch (CreateGeometryException e) {
321
            logger.warn("Error while creating surface.", e);
322
            throw new RuntimeException("Can't create sample geometry.", e);
323
        }
324
        surf.addVertex(r.getX(), r.getY());
325
        surf.addVertex(r.getX() + r.getWidth(), r.getY());
326
        return surf;
327
328
    }
329 40911 jldominguez
330
        public void drawInsideRectangle(
331
                        Graphics2D g,
332
                        AffineTransform scaleInstance,
333 47476 fdiaz
                        Rectangle r) throws SymbolDrawingException {
334
//                // let's take the bottom segment of the rectangle as the line
335
//
336
//                Surface surf = null;
337
//                try {
338
//                        surf = geoman.createSurface(SUBTYPES.GEOM2D);
339
//                } catch (CreateGeometryException e) {
340
//                        logger.info("Error while creating surface.", e);
341
//                        throw new SymbolDrawingException(
342
//                                        SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
343
//                }
344
//                surf.addVertex(r.getX(), r.getY());
345
//                surf.addVertex(r.getX() + r.getWidth(), r.getY());
346
//
347
//                if (properties == null) {
348
//                        draw(g, scaleInstance, surf, null, null);
349
//                } else {
350
//                        print(g, scaleInstance, surf, properties);
351
//                }
352
                draw(g, scaleInstance, null, null, null, r);
353 40911 jldominguez
        }
354
355
356
        /*
357
        public void setXMLEntity(XMLEntity xml) {
358
                setFont(new Font("Arial", Font.PLAIN, 18));
359
                setText("this is my TEST text that follows a line");
360
                setDescription(xml.getStringProperty("desc"));
361
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
362

363
        }
364
        */
365
366
        public void setText(String txt) {
367
                this.text = txt;
368
        }
369
370
        public String getText() {
371
                return text;
372
        }
373
374
        public void setCharacterSpacing(double charSpacing) {
375
                this.characterSpacing = charSpacing;
376
        }
377
378
        public void setWordSpacing(double wordSpacing) {
379
                this.wordSpacing = wordSpacing;
380
        }
381
382
        public void setAlignment(int alignment) {
383
                this.alignment = alignment;
384
        }
385
386
        public void setKerning(boolean kerning) {
387
                this.kerning = kerning;
388
        }
389
390
        public void setMargin(double margin) {
391
                this.margin = margin;
392
        }
393
394
        public void setRightToLeft(boolean rightToLeft) {
395
                this.rightToLeft = rightToLeft;
396
        }
397
398
        // ==============================================
399
        // ==============================================
400
        // ==============================================
401
402
403
        public ISymbol getSymbolForSelection() {
404
                return this;
405
        }
406
407
        public boolean isOneDotOrPixel(Geometry geom,
408
                        double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
409
410
                int type = geom.getType();
411
                switch (type) {
412
                case Geometry.TYPES.NULL:
413
                case Geometry.TYPES.POINT:
414
                case Geometry.TYPES.MULTIPOINT:
415
                        return false;
416
                default:
417
                        Envelope geomBounds = geom.getEnvelope();
418
                        double dist1Pixel = viewPort.getDist1pixel();
419
420
                        float[] distances = new float[2];
421
                        this.getPixExtentPlus(geom, distances, viewPort, dpi);
422
423
                        boolean onePoint =
424
                                        ((geomBounds.getLength(0) + distances[0] <= dist1Pixel)
425
                                        && (geomBounds.getLength(1) + distances[1] <= dist1Pixel));
426
427
                        if (onePoint) {
428
                                positionOfDotOrPixel[0] = geomBounds.getMinimum(0);
429
                                positionOfDotOrPixel[1] = geomBounds.getMinimum(1);
430
                        }
431
                        return onePoint;
432
                }
433
        }
434
435
436
437 47476 fdiaz
//        public String getDescription() {
438
//                return desc;
439
//        }
440
//
441
//
442
//        public void setDescription(String d) {
443
//                desc = d;
444
//        }
445 40911 jldominguez
446
447
        public Color getColor() {
448
                return this.getTextColor();
449
        }
450
451
452
        public void setColor(Color color) {
453
                this.setTextColor(color);
454
        }
455
456
457
        public void print(Graphics2D g, AffineTransform at, Geometry geom,
458
                        PrintAttributes properties) {
459 47476 fdiaz
                this.draw(g,  at, geom, null, null, null);
460 40911 jldominguez
        }
461
462
463
        public void setFont(Font fnt) {
464
                this.font = fnt;
465
        }
466
467
468
        public Font getFont() {
469
                return font;
470
        }
471
472
473
        public Color getTextColor() {
474
                return this.textColor;
475
        }
476
477
478
        public void setTextColor(Color color) {
479
                this.textColor = color;
480
        }
481
482
483
        public void setFontSize(double d) {
484
                Font newFont = new Font(
485
                                font.getName(),
486
                                font.getStyle(),
487
                                Math.round((float) d));
488
                this.font = newFont;
489
        }
490
491
492
        public Geometry getTextWrappingShape(Point p) {
493
494
                Font font = getFont();
495
                GlyphVector gv = font.createGlyphVector(frc, text);
496
497
                Shape shape = gv.getOutline((float) p.getX(), (float) p.getY());
498
                Geometry myFShape;
499
                try {
500
                        myFShape = geoman.createSurface(new GeneralPathX(shape
501
                                        .getBounds2D().getPathIterator(null)), SUBTYPES.GEOM2D);
502
                        myFShape.transform(AffineTransform.getTranslateInstance(p.getX(), p.getY()));
503
504
                        if (rotation != 0) {
505
                                myFShape.transform(AffineTransform.getRotateInstance(rotation));
506
                        }
507
                        return myFShape;
508
                } catch (CreateGeometryException e) {
509
                        logger.error("Error creating a surface", e);
510
                }
511
                return null;
512
        }
513
514
515
        public Rectangle getBounds() {
516
517
                Rectangle bounds = null;
518
                try {
519
                        Geometry aux = getTextWrappingShape(geoman.createPoint(0,0, SUBTYPES.GEOM2D));
520
                        Envelope env = aux.getEnvelope();
521
                        bounds = new Rectangle(
522
                                        (int) env.getMinimum(0),
523
                                        (int) env.getMinimum(1),
524
                                        (int) env.getLength(0),
525
                                        (int) env.getLength(1));
526
                } catch (CreateGeometryException e) {
527
                        logger.error("Error creating a point", e);
528
                }
529
                return bounds;
530
        }
531
532
        public double getRotation() {
533
                return this.rotation;
534
        }
535
536
537
        public void setRotation(double rot) {
538
                this.rotation = rot;
539
        }
540
541
        public void setAutoresizeEnabled(boolean ar) {
542
                autoresize = ar;
543
        }
544
545
546
        public boolean isAutoresizeEnabled() {
547
                return autoresize;
548
        }
549
550
551
        public Color getHaloColor() {
552
                return this.haloColor;
553
        }
554
555
556
        public void setHaloColor(Color co) {
557
                this.haloColor = co;
558
        }
559
560
561
        public float getHaloWidth() {
562
                return this.haloWidth;
563
        }
564
565
566
        public void setHaloWidth(float w) {
567
                this.haloWidth = w;
568
                this.haloStroke = new BasicStroke(
569
                                2*haloWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
570
        }
571
572
573
        public boolean isDrawWithHalo() {
574
                return this.hasHalo;
575
        }
576
577
578
        public void setDrawWithHalo(boolean h) {
579
                this.hasHalo = h;
580
        }
581
582
        // ==============================
583
584
585 47476 fdiaz
//        public void setUnit(int unitIndex) {
586
//                unit = unitIndex;
587
//        }
588
//
589
//
590
//        public int getUnit() {
591
//                return unit;
592
//        }
593
//
594
//
595
//        public int getReferenceSystem() {
596
//                return this.referenceSystem;
597
//        }
598
//
599
//
600
//        public void setReferenceSystem(int rs) {
601
//                this.referenceSystem = rs;
602
//        }
603 40911 jldominguez
604
605 47476 fdiaz
//        public void setCartographicSize(double cartographicSize, Geometry geom) {
606
//                setFontSize(cartographicSize);
607
//        }
608
//
609
//        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
610
//                double oldSize = getFont().getSize();
611
//                setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom);
612
//                return oldSize;
613
//        }
614
//
615
//        public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
616
//                return SymbolUtils.        getCartographicLength(
617
//                                this, getFont().getSize(), viewPort, dpi);
618
//        }
619 40911 jldominguez
620
        // ========================
621
622
        public Object clone() throws CloneNotSupportedException {
623
                return super.clone();
624
        }
625
626
        // ==========================
627
628
        public static void registerPersistent() {
629
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
630
                if( manager.getDefinition(SMART_TEXT_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
631
                        DynStruct definition = manager.addDefinition(
632
                                        SmartTextSymbol.class,
633
                                        SMART_TEXT_SYMBOL_PERSISTENCE_DEFINITION_NAME,
634
                                        SMART_TEXT_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
635
                                        null,
636
                                        null
637
                        );
638
639
                        definition.addDynFieldString(FIELD_DESCRIPTION).setMandatory(true);
640
                        definition.addDynFieldBoolean(FIELD_IS_SHAPE_VISIBLE).setMandatory(true);
641
                        definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
642
                        definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
643
                        definition.addDynFieldBoolean(FIELD_AUTO_RESIZE).setMandatory(true);
644
                        definition.addDynFieldObject(FIELD_FONT).setClassOfValue(Font.class).setMandatory(true);
645
                        definition.addDynFieldDouble(FIELD_ROTATION).setMandatory(true);
646
                        definition.addDynFieldString(FIELD_TEXT).setMandatory(true);
647
                        definition.addDynFieldObject(FIELD_TEXT_COLOR).setClassOfValue(Color.class).setMandatory(true);
648
                        // halo
649
                        definition.addDynFieldBoolean(FIELD_HAS_HALO).setMandatory(true);
650
                        definition.addDynFieldObject(FIELD_HALO_COLOR).setClassOfValue(
651
                                        Color.class).setMandatory(true);
652
                        definition.addDynFieldFloat(FIELD_HALO_WIDTH).setMandatory(true);
653
                }
654
655
        }
656
657
        public void loadFromState(PersistentState state)
658
                        throws PersistenceException {
659
                setDescription(state.getString(FIELD_DESCRIPTION));
660
                setIsShapeVisible(state.getBoolean(FIELD_IS_SHAPE_VISIBLE));
661
                setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM));
662
                setUnit(state.getInt(FIELD_UNIT));
663
664
                setAutoresizeEnabled(state.getBoolean(FIELD_AUTO_RESIZE));
665
                setFont((Font) state.get(FIELD_FONT));
666
                setRotation(state.getDouble(FIELD_ROTATION));
667
                setText(state.getString(FIELD_TEXT));
668
                setTextColor((Color) state.get(FIELD_TEXT_COLOR));
669
                // halo
670
                this.setDrawWithHalo(state.getBoolean(FIELD_HAS_HALO));
671
                this.setHaloColor((Color) state.get(FIELD_HALO_COLOR));
672
                this.setHaloWidth(state.getFloat(FIELD_HALO_WIDTH));
673
        }
674
675
        public void saveToState(PersistentState state) throws PersistenceException {
676
                state.set(FIELD_DESCRIPTION, getDescription());
677
                state.set(FIELD_IS_SHAPE_VISIBLE, isShapeVisible());
678
                state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem());
679
                state.set(FIELD_UNIT, getUnit());
680
681
                state.set(FIELD_AUTO_RESIZE, isAutoresizeEnabled());
682
                state.set(FIELD_FONT, getFont());
683
                state.set(FIELD_ROTATION, getRotation());
684
                state.set(FIELD_TEXT, getText());
685
                state.set(FIELD_TEXT_COLOR, getTextColor());
686
                // halo
687
                state.set(FIELD_HAS_HALO, this.isDrawWithHalo());
688
                state.set(FIELD_HALO_COLOR, this.getHaloColor());
689
                state.set(FIELD_HALO_WIDTH, this.getHaloWidth());
690
        }
691
692
693
694
695
696
}