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 / CharacterMarkerSymbol.java @ 40911

History | View | Annotate | Download (22.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
 *
44
 * $Id: CharacterMarkerSymbol.java 14501 2007-10-08 15:47:31Z jdominguez $
45
 * $Log$
46
 * Revision 1.27  2007-09-21 12:25:32  jaume
47
 * cancellation support extended down to the IGeometry and ISymbol level
48
 *
49
 * Revision 1.26  2007/08/09 07:20:03  jvidal
50
 * javadoc
51
 *
52
 * Revision 1.25  2007/07/23 06:52:25  jaume
53
 * default selection color refactored, moved to MapContext
54
 *
55
 * Revision 1.24  2007/07/18 06:54:34  jaume
56
 * continuing with cartographic support
57
 *
58
 * Revision 1.23  2007/07/03 10:58:29  jaume
59
 * first refactor on CartographicSupport
60
 *
61
 * Revision 1.22  2007/06/29 13:07:01  jaume
62
 * +PictureLineSymbol
63
 *
64
 * Revision 1.21  2007/06/07 06:50:40  jaume
65
 * *** empty log message ***
66
 *
67
 * Revision 1.20  2007/05/29 15:46:37  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.19  2007/05/28 15:36:42  jaume
71
 * *** empty log message ***
72
 *
73
 * Revision 1.18  2007/05/17 09:32:06  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.17  2007/05/09 16:07:26  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.16  2007/05/09 11:05:28  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.15  2007/05/08 08:47:40  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.14  2007/04/26 11:41:00  jaume
86
 * attempting to let defining size in world units
87
 *
88
 * Revision 1.13  2007/04/20 07:11:11  jaume
89
 * *** empty log message ***
90
 *
91
 * Revision 1.12  2007/04/19 16:01:27  jaume
92
 * *** empty log message ***
93
 *
94
 * Revision 1.11  2007/04/19 14:21:30  jaume
95
 * *** empty log message ***
96
 *
97
 * Revision 1.10  2007/03/26 14:24:13  jaume
98
 * implemented Print
99
 *
100
 * Revision 1.9  2007/03/21 11:37:00  jaume
101
 * *** empty log message ***
102
 *
103
 * Revision 1.8  2007/03/21 11:02:17  jaume
104
 * *** empty log message ***
105
 *
106
 * Revision 1.7  2007/03/09 11:20:56  jaume
107
 * Advanced symbology (start committing)
108
 *
109
 * Revision 1.5.2.8  2007/02/21 07:34:09  jaume
110
 * labeling starts working
111
 *
112
 * Revision 1.5.2.7  2007/02/16 10:54:12  jaume
113
 * multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
114
 *
115
 * Revision 1.5.2.6  2007/02/15 16:23:44  jaume
116
 * *** empty log message ***
117
 *
118
 * Revision 1.5.2.5  2007/02/14 09:58:37  jaume
119
 * *** empty log message ***
120
 *
121
 * Revision 1.5.2.4  2007/02/12 15:15:20  jaume
122
 * refactored interval legend and added graduated symbol legend
123
 *
124
 * Revision 1.5.2.3  2007/02/09 07:47:04  jaume
125
 * Isymbol moved
126
 *
127
 * Revision 1.5.2.2  2007/02/05 14:59:04  jaume
128
 * *** empty log message ***
129
 *
130
 * Revision 1.5.2.1  2007/01/30 18:10:45  jaume
131
 * start commiting labeling stuff
132
 *
133
 * Revision 1.5  2007/01/25 16:25:23  jaume
134
 * *** empty log message ***
135
 *
136
 * Revision 1.4  2007/01/24 17:58:22  jaume
137
 * new features and architecture error fixes
138
 *
139
 * Revision 1.3  2007/01/16 11:50:44  jaume
140
 * *** empty log message ***
141
 *
142
 * Revision 1.2  2007/01/10 16:39:41  jaume
143
 * ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
144
 *
145
 * Revision 1.1  2007/01/10 16:31:36  jaume
146
 * *** empty log message ***
147
 *
148
 * Revision 1.6  2006/12/04 17:13:39  fjp
149
 * *** empty log message ***
150
 *
151
 * Revision 1.5  2006/11/14 11:10:27  jaume
152
 * *** empty log message ***
153
 *
154
 * Revision 1.4  2006/11/09 18:39:05  jaume
155
 * *** empty log message ***
156
 *
157
 * Revision 1.3  2006/11/08 10:56:47  jaume
158
 * *** empty log message ***
159
 *
160
 * Revision 1.2  2006/11/06 17:08:45  jaume
161
 * *** empty log message ***
162
 *
163
 * Revision 1.1  2006/10/31 16:16:34  jaume
164
 * *** empty log message ***
165
 *
166
 * Revision 1.4  2006/10/30 19:30:35  jaume
167
 * *** empty log message ***
168
 *
169
 * Revision 1.3  2006/10/29 23:53:49  jaume
170
 * *** empty log message ***
171
 *
172
 * Revision 1.2  2006/10/26 16:27:33  jaume
173
 * support for composite marker symbols (not tested)
174
 *
175
 * Revision 1.1  2006/10/25 10:50:41  jaume
176
 * movement of classes and gui stuff
177
 *
178
 * Revision 1.3  2006/10/24 19:54:16  jaume
179
 * added IPersistence
180
 *
181
 * Revision 1.2  2006/10/24 08:02:51  jaume
182
 * *** empty log message ***
183
 *
184
 * Revision 1.1  2006/10/18 07:54:06  jaume
185
 * *** empty log message ***
186
 *
187
 *
188
 */
189
package org.gvsig.labeling.symbol;
190

    
191
import java.awt.Color;
192
import java.awt.Font;
193
import java.awt.Graphics2D;
194
import java.awt.Rectangle;
195
import java.awt.Shape;
196
import java.awt.font.FontRenderContext;
197
import java.awt.font.GlyphVector;
198
import java.awt.geom.AffineTransform;
199
import java.awt.geom.Point2D;
200
import java.awt.image.BufferedImage;
201

    
202
import org.gvsig.compat.print.PrintAttributes;
203
import org.gvsig.fmap.dal.feature.Feature;
204
import org.gvsig.fmap.geom.Geometry;
205
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
206
import org.gvsig.fmap.geom.Geometry.TYPES;
207
import org.gvsig.fmap.geom.GeometryLocator;
208
import org.gvsig.fmap.geom.GeometryManager;
209
import org.gvsig.fmap.geom.exception.CreateGeometryException;
210
import org.gvsig.fmap.geom.primitive.Envelope;
211
import org.gvsig.fmap.mapcontext.MapContext;
212
import org.gvsig.fmap.mapcontext.ViewPort;
213
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
214
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
215
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
216
import org.gvsig.labeling.lang.LabelClassUtils;
217
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
218
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask;
219
import org.gvsig.tools.ToolsLocator;
220
import org.gvsig.tools.dynobject.DynStruct;
221
import org.gvsig.tools.persistence.PersistenceManager;
222
import org.gvsig.tools.persistence.PersistentState;
223
import org.gvsig.tools.persistence.exception.PersistenceException;
224
import org.gvsig.tools.task.Cancellable;
225
import org.slf4j.Logger;
226
import org.slf4j.LoggerFactory;
227

    
228
/**
229
 * Allows to use a source of TrueType characters  to define the marker that will
230
 * substitute the symbol.If the picture is defined in a source, the performance is
231
 * more agile.
232
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
233
 */
234
public class CharacterMarkerSymbol implements IMarkerSymbol {
235
        
236
        private static Logger logger =
237
                        LoggerFactory.getLogger(CharacterMarkerSymbol.class);
238
        
239
        public static final String CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME =
240
                        "CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME";
241
        
242
        private Font font = new Font("Arial", Font.PLAIN, 20);
243
        private int unicode;
244
        private ISymbol selectionSymbol;
245
        private VisualCorrection visualCorrection;
246
        private double size;
247
        
248
        private boolean isShapeVisible = true;
249
        private String desc = "";
250
        
251
        private IMask mask;
252
        private int unit = -1;
253
        private int referenceSystem = CartographicSupport.WORLD;
254
        
255
        private int alpha = 255;
256
        private Point2D offset = new Point2D.Double();
257
        
258
        /*
259
         * 
260
         */
261
        private double rotation_radians = 0;
262
        private Color color = Color.BLACK;
263
        
264
        private static GeometryManager geoman = GeometryLocator.getGeometryManager();
265

    
266
        /**
267
         * Creates a new instance of CharacterMarker with default values
268
         *
269
         */
270
        public CharacterMarkerSymbol() {
271
                super();
272
        }
273

    
274
        /**
275
         * Creates a new instance of CharacterMarker specifying the marker source
276
         * font, the character code corresponding to the symbol, and the color that
277
         * will be used in rendering time.
278
         *
279
         * @param font -
280
         *            src Font
281
         * @param charCode -
282
         *            character code of the symbol for this font
283
         * @param color -
284
         *            color to be used in when rendering.
285
         */
286
        public CharacterMarkerSymbol(Font font, int charCode, Color color) {
287
                super();
288
                this.font = font;
289
                unicode = charCode;
290
                setColor(color);
291
        }
292
        /**
293
         * Returns the font that will be used to define the symbol
294
         * @return font
295
         */
296
        public Font getFont() {
297
                return font;
298
        }
299
        /**
300
         * Sets the font that will be used to define the symbol
301
         * @return font
302
         */
303
        public void setFont(Font font) {
304
                this.font = font;
305
        }
306

    
307
        public ISymbol getSymbolForSelection() {
308
                if (selectionSymbol == null) {
309
                        selectionSymbol = (ISymbol) LabelClassUtils.clone(this);
310
                        selectionSymbol.setColor(MapContext.getSelectionColor());
311
                }
312
                return selectionSymbol;
313
        }
314
        
315
        
316
        public void draw(Graphics2D g,
317
                        AffineTransform affineTransform, Geometry geom,
318
                        Feature feat, Cancellable cancel) {
319
                
320
                g.setColor(getColor());
321
                double theta = getRotation();
322

    
323
                int xOffset = (int) getOffset().getX(); // * multiplicador d'unitats;
324
                int yOffset = (int) getOffset().getY(); // * multiplicador d'unitats
325

    
326
                double size = getSize();
327
                if (size < 0.0001) {
328
                        return;
329
                }
330
                
331
                org.gvsig.fmap.geom.primitive.Point cen = null;
332
                try {
333
                        cen = geom.centroid();
334
                } catch (Exception e) {
335
                        logger.error("While getting centroid", e);
336
                }
337
                
338
                Point2D p = new Point2D.Double(cen.getX(), cen.getY());
339

    
340
                if (isVisuallyCorrected()) {
341
                        size *= visualCorrection.sizeScale;
342
                        p.setLocation(p.getX() - xOffset*size*visualCorrection.xOffsetScale, p.getY() - yOffset*size*visualCorrection.yOffsetScale);
343

    
344
                }
345
                g.setFont(getFont().deriveFont((float)size));
346

    
347
                g.translate((int) (p.getX() + xOffset), (int) (p.getY()  + yOffset));
348
                if (theta != 0)        g.rotate(theta);
349

    
350
                char[] text = new char[] { (char) unicode };
351

    
352
                IMask mask = getMask();
353
                if (mask != null) {
354
                        FontRenderContext frc = g.getFontRenderContext();
355

    
356
                        GlyphVector gv = font.createGlyphVector(frc, text );
357

    
358
                        Shape markerShape = gv.getOutline(0, 0);
359
                        mask.getFillSymbol().
360
                                         draw(g, null, mask.getHaloShape(markerShape), feat, cancel);
361

    
362
                }
363
                g.drawChars(text, 0, text.length, - (int) (size*0.4), (int) (size*0.4));
364

    
365

    
366
                if (theta!=0) g.rotate(-theta);
367
                g.translate(-(int) (p.getX() + xOffset), - (int) (p.getY() + yOffset));
368
        }
369

    
370

    
371

    
372
        
373

    
374
        /**
375
         * Sets the unicode for a symbol represented by a character
376
         * @param symbol, int
377
         */
378
        public void setUnicode(int symbol) {
379
                this.unicode = symbol;
380
        }
381

    
382
        /**
383
         * Obtains the unicode for a symbol
384
         * @return unicode, int
385
         */
386
        public int getUnicode() {
387
                return unicode;
388
        }
389

    
390

    
391

    
392
        /*
393
        public void setXMLEntity(XMLEntity xml) {
394
                setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
395
                Point p = new Point();
396
                p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset"));
397

398
                setDescription(xml.getStringProperty("desc"));
399
                size = xml.getDoubleProperty("size");
400
                font = new Font(xml.getStringProperty("font"),
401
                                xml.getIntProperty("fontStyle"),
402
                                (int) size);
403
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
404
                unicode = xml.getIntProperty("symbolCode");
405
                setOffset(p);
406
                setRotation(xml.getDoubleProperty("rotation"));
407
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
408
                setUnit(xml.getIntProperty("unit"));
409
        }
410
        */
411

    
412

    
413
        public double getSize() {
414
                return size;
415
        }
416

    
417
        public void setSize(double size) {
418
                this.size = size;
419
                font = new Font(font.getName(), font.getStyle(), (int) Math.round(size));
420
        }
421
        /**
422
         * Returns true of false depending if the character marker symbol selected is visually
423
         * corrected.That is, if the character has been properly scaled to use a specific number
424
         * of pixels to be represented.
425
         *
426
         * @return boolean
427
         */
428
        public boolean isVisuallyCorrected() {
429
                return visualCorrection != null;
430
        }
431
        /**
432
         * Sets the visual correction for a character in order to scale it if it is necessary.
433
         *
434
         * @return boolean
435
         */
436
        public void setVisuallyCorrected(boolean visuallyCorrected) {
437
                if (visuallyCorrected && visualCorrection == null) {
438
                        CharacterMarkerSymbol clone =
439
                                        (CharacterMarkerSymbol) LabelClassUtils.clone(this);
440
                        int frameSize = 200;
441
                        double symbolSize = 100;
442
                        BufferedImage bi = new BufferedImage(frameSize, frameSize, BufferedImage.TYPE_INT_ARGB);
443
                        Graphics2D aGraphics = bi.createGraphics();
444
                        clone.setOffset(new Point2D.Double(0,0));
445
                        clone.setSize(symbolSize);
446
                        clone.setColor(Color.PINK);
447

    
448

    
449
                        // draw it at center of the image
450
                        org.gvsig.fmap.geom.primitive.Point pCenter = null;
451
                        try {
452
                                pCenter = geoman.createPoint(
453
                                                frameSize/2,frameSize/2, SUBTYPES.GEOM2D);
454
                        } catch (Exception e) {
455
                                logger.error("While creating point", e);
456
                        }
457
                        clone.draw(aGraphics, new AffineTransform(), pCenter, null, null);
458

    
459
                        int realTop    = -1;
460
                        int realBottom = -1;
461
                        int realLeft   = -1;
462
                        int realRight  = -1;
463

    
464
                        // let's see where the highest pixel is in Y-axis
465
                        boolean done = false;
466
                        for (int j = 0; !done && j < bi.getHeight(); j++) {
467
                                for (int i = 0; !done && i < bi.getWidth(); i++) {
468
                                        if (bi.getRGB(i, j) != 0) {
469
                                                realTop = j;
470
                                                done = true;
471
                                        }
472
                                }
473
                        }
474

    
475
                        // let's see where the lowest pixel is in Y-axis
476
                        done = false;
477
                        for (int j =  bi.getHeight()-1; !done &&  j >= 0; j--) {
478
                                for (int i = 0; !done &&  i < bi.getWidth(); i++) {
479
                                        if (bi.getRGB(i, j) != 0) {
480
                                                realBottom = i;
481
                                                done = true;
482
                                        }
483
                                }
484
                        }
485

    
486
                        // let's see where the first pixel at left is in X-axis
487
                        done = false;
488
                        for (int i = 0; !done &&  i < bi.getWidth(); i++) {
489
                                for (int j = 0; !done &&  j < bi.getHeight(); j++) {
490
                                        if (bi.getRGB(i, j) != 0) {
491
                                                realLeft = i;
492
                                                done = true;
493
                                        }
494
                                }
495
                        }
496

    
497
                        // let's see where the first pixel at right is in X-axis
498
                        done = false;
499
                        for (int i = bi.getWidth()-1; !done &&  i >=0 ; i--) {
500
                                for (int j = 0; !done &&  j < bi.getHeight(); j++) {
501
                                        if (bi.getRGB(i, j) != 0) {
502
                                                realRight = i;
503
                                                done = true;
504
                                        }
505
                                }
506
                        }
507
                        
508
                        int realWidth = bi.getWidth() - realRight-realLeft;
509
                        int realHeight = bi.getHeight() - realBottom - realTop;
510

    
511
                        visualCorrection = new VisualCorrection();
512
                        
513
                        if (realBottom!=-1 && realTop!=-1 && realLeft!=-1 && realRight != -1) {
514
                                double correctingSize = Math.max(realHeight, realWidth);
515
                                visualCorrection.sizeScale = clone.getSize() / correctingSize;
516
                        }
517

    
518
                        if (realLeft!=-1 && realRight!=-1) {
519
                                double correctingCenterX = (((realWidth)*0.5)+realLeft);
520
                                double correctingCenterY = (((realHeight)*0.5)+realBottom);
521
                                visualCorrection.xOffsetScale = (pCenter.getX() - correctingCenterX) / frameSize;
522
                                visualCorrection.yOffsetScale = (pCenter.getY() - correctingCenterY) / frameSize;
523
                        }
524
                } else {
525
                        visualCorrection = null;
526
                }
527
        }
528
        
529
        
530
        public Object clone() throws CloneNotSupportedException {
531
                return LabelClassUtils.clone(this);
532
        }
533
        
534
        
535
        public void getPixExtentPlus(
536
                        Geometry geom, float[] distances,
537
                        ViewPort viewPort, int dpi) {
538
                
539
                float cs = (float) getCartographicSize(viewPort, dpi, geom);
540
                distances[0] = cs;
541
                distances[1] = cs;
542
        }
543

    
544
        public boolean isOneDotOrPixel(Geometry geom,
545
                        double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
546

    
547
                int type = geom.getType();
548
                switch (type) {
549
                case Geometry.TYPES.NULL:
550
                case Geometry.TYPES.POINT:
551
                case Geometry.TYPES.MULTIPOINT:
552
                        return false;
553
                default:
554
                        org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom
555
                        .getEnvelope();
556

    
557
                        double dist1Pixel = viewPort.getDist1pixel();
558

    
559
                        float[] distances = new float[2];
560
                        this.getPixExtentPlus(geom, distances, viewPort, dpi);
561

    
562
                        boolean onePoint =
563
                                        (geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds
564
                                        .getLength(1)
565
                                        + distances[1] <= dist1Pixel);
566

    
567
                        if (onePoint) {
568
                                Envelope bounds = geom.getEnvelope();
569
                                positionOfDotOrPixel[0] = bounds.getMinimum(0);
570
                                positionOfDotOrPixel[1] = bounds.getMinimum(1);
571
                        }
572
                        return onePoint;
573
                }
574
        }
575
        
576
        public int getOnePointRgb() {
577
                return this.getColor().getRGB();
578
        }
579

    
580
        public String getDescription() {
581
                return desc;
582
        }
583

    
584
        public boolean isShapeVisible() {
585
                return isShapeVisible;
586
        }
587

    
588
        public void setDescription(String d) {
589
                desc = d;
590
        }
591

    
592
        public int getSymbolType() {
593
                return Geometry.TYPES.POINT;
594
        }
595

    
596
        public boolean isSuitableFor(Geometry geom) {
597
                return geom.getType() == Geometry.TYPES.POINT
598
                                || geom.getType() == Geometry.TYPES.MULTIPOINT;
599
        }
600

    
601
        public void drawInsideRectangle(Graphics2D g,
602
                        AffineTransform scaleInstance, Rectangle r,
603
                        PrintAttributes properties) throws SymbolDrawingException {
604
                
605
                
606
                org.gvsig.fmap.geom.primitive.Point center = null;
607
                try {
608
                        center = geoman.createPoint(
609
                                        r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D);
610
                } catch (CreateGeometryException e) {
611
                        throw new SymbolDrawingException(TYPES.POINT);
612
                }
613

    
614
                if (properties==null) {
615
                        draw(g, scaleInstance, center, null, null);
616
                } else {
617
                        double originalSize = getSize();
618
                        double size=originalSize;
619
                        int pq = properties.getPrintQuality();
620
                        if (pq == PrintAttributes.PRINT_QUALITY_HIGH) {
621
                                size *= (double) 600/72;
622
                        } else {
623
                                if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
624
                                        size *= (double) 300/72;
625
                                } else {
626
//                                        unitFactor *= 72; (which is the same than doing nothing)
627
                                }
628
                        }
629
                        setSize(size);
630
                        print(g, scaleInstance, center, properties);
631
                        setSize(originalSize);
632
                }
633
                
634
        }
635

    
636

    
637
        public void print(Graphics2D g, AffineTransform at, Geometry geom,
638
                        PrintAttributes properties) {
639

    
640
                /* TODO Use this?
641
                double dpi = 100;
642
                int pq = properties.getPrintQuality();
643
                if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
644
                        dpi = 300;
645
                } else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){
646
                        dpi = 600;
647
                } else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){
648
                        dpi = 72;
649
                }
650
                */
651

    
652
                draw(g,at,geom,null,null);        
653
        }
654

    
655
        public void setUnit(int unitIndex) {
656
                unit = unitIndex;
657
        }
658

    
659
        public int getUnit() {
660
                return unit;
661
        }
662

    
663
        public int getReferenceSystem() {
664
                return this.referenceSystem;
665
        }
666

    
667
        public void setReferenceSystem(int rs) {
668
                this.referenceSystem = rs;
669
        }
670

    
671
        public double toCartographicSize(ViewPort viewPort, double dpi,
672
                        Geometry geom) {
673
                
674
                double oldSize = getSize();
675
                setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom);
676
                return oldSize;        }
677

    
678
        public void setCartographicSize(double cartographicSize, Geometry geom) {
679
                setSize(cartographicSize);
680
        }
681

    
682
        public double getCartographicSize(ViewPort viewPort, double dpi,
683
                        Geometry geom) {
684
                
685
                return SymbolUtils.getCartographicLength(this,
686
                                                                          getSize(),
687
                                                                          viewPort,
688
                                                                          dpi);
689
        }
690

    
691
        public double getRotation() {
692
                return rotation_radians;
693
        }
694

    
695
        public void setRotation(double rot) {
696
                rotation_radians = rot;
697
        }
698

    
699
        public Point2D getOffset() {
700
                return offset;
701
        }
702

    
703
        public void setOffset(Point2D off) {
704
                offset = off;
705
        }
706

    
707
        public Color getColor() {
708
                return color;
709
        }
710

    
711
        public void setColor(Color co) {
712
                color = co;
713
        }
714

    
715
        public void setAlpha(int a) {
716
                alpha = a;
717
        }
718

    
719
        public IMask getMask() {
720
                return mask;
721
        }
722

    
723
        public void setMask(IMask m) {
724
                mask = m;
725
        }
726
        
727
        // =========================================
728
        
729
        public void loadFromState(PersistentState state) throws PersistenceException {
730
                
731
                if (state.hasValue("vc_xOffsetScale")) {
732
                        this.visualCorrection = new VisualCorrection();
733
                        this.visualCorrection.xOffsetScale = state.getDouble("vc_xOffsetScale");
734
                        this.visualCorrection.yOffsetScale = state.getDouble("vc_yOffsetScale");
735
                        this.visualCorrection.sizeScale = state.getDouble("vc_sizeScale");
736
                } else {
737
                        this.visualCorrection = null;
738
                }
739
                if (state.hasValue("mask")) {
740
                        this.mask = (IMask) state.get("mask");
741
                } else {
742
                        this.mask = null;
743
                }
744
                // ==============================================
745
                this.color = (Color) state.get("color");
746
                this.font = (Font) state.get("font");
747
                
748
                double aux = state.getDouble("size");
749
                this.setSize(aux);
750
                
751
                this.unicode = state.getInt("unicode");
752
                this.desc = state.getString("desc");
753
                this.isShapeVisible = state.getBoolean("isShapeVisible");
754
                
755
                double x = state.getDouble("xOffset");
756
                double y = state.getDouble("yOffset");
757
                this.offset = new Point2D.Double(x, y);
758
                
759
                this.rotation_radians = state.getDouble("rotation");
760
                this.unit = state.getInt("unit");
761
                this.referenceSystem = state.getInt("referenceSystem");                
762
        }
763

    
764
        public void saveToState(PersistentState state) throws PersistenceException {
765
                
766
                if (this.visualCorrection != null) {
767
                        state.set("vc_xOffsetScale", this.visualCorrection.xOffsetScale);
768
                        state.set("vc_yOffsetScale", this.visualCorrection.yOffsetScale);
769
                        state.set("vc_sizeScale", this.visualCorrection.sizeScale);
770
                }
771
                if (this.mask != null) {
772
                        state.set("mask", this.mask);
773
                }
774
                // ==================================================
775
                state.set("color", this.color);
776
                state.set("font", this.font);
777
                state.set("size", this.size);
778
                state.set("unicode", this.unicode);
779
                state.set("desc", this.desc);
780
                state.set("isShapeVisible", this.isShapeVisible);
781
                state.set("xOffset", this.offset.getX());
782
                state.set("yOffset", this.offset.getY());
783
                state.set("rotation", this.rotation_radians);
784
                state.set("unit", this.unit);
785
                state.set("referenceSystem", this.referenceSystem);                
786
        }
787
        
788
        public static void registerPersistent() {
789
                
790
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
791
                if( manager.getDefinition(CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME)==null ) {
792
                        DynStruct definition = manager.addDefinition(
793
                                        CharacterMarkerSymbol.class,
794
                                        CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME,
795
                                        CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME+" Persistence definition",
796
                                        null, 
797
                                        null
798
                        );
799
                        
800
                        definition.addDynFieldObject("color").setClassOfValue(Color.class).setMandatory(true);
801
                        definition.addDynFieldObject("font").setClassOfValue(Font.class).setMandatory(true);
802
                        definition.addDynFieldDouble("size").setMandatory(true);
803
                        definition.addDynFieldInt("unicode").setMandatory(true);
804
                        definition.addDynFieldString("desc").setMandatory(true);
805
                        definition.addDynFieldBoolean("isShapeVisible").setMandatory(true);
806
                        definition.addDynFieldDouble("xOffset").setMandatory(true);
807
                        definition.addDynFieldDouble("yOffset").setMandatory(true);
808
                        definition.addDynFieldDouble("rotation").setMandatory(true);
809
                        definition.addDynFieldInt("unit").setMandatory(true);
810
                        definition.addDynFieldInt("referenceSystem").setMandatory(true);
811
                        definition.addDynFieldObject("mask").setClassOfValue(IMask.class).setMandatory(false);
812
                        // =====================
813
                        definition.addDynFieldDouble("vc_xOffsetScale").setMandatory(false);
814
                        definition.addDynFieldDouble("vc_yOffsetScale").setMandatory(false);
815
                        definition.addDynFieldDouble("vc_sizeScale").setMandatory(false);
816
                }                
817
        }
818

    
819

    
820
        /**
821
         * Class to be used for the methods that control the visual correction of a character.
822
         * This visual correction has the responsibility of modify the dimensions of the
823
         * character to be used as a symbol(in case that the user wants to use more or less
824
         * pixels to represent it )
825
         *
826
         */
827
        private class VisualCorrection {
828
                double xOffsetScale = 1;
829
                double yOffsetScale = 1;
830
                double sizeScale = 1;
831
        }
832
                
833
}