Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / styling / LabelClass.java @ 42172

History | View | Annotate | Download (20.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
 *
26
 * $Id: LabelClass.java 13953 2007-09-21 12:26:04Z jaume $
27
 * $Log$
28
 * Revision 1.14  2007-09-21 12:26:04  jaume
29
 * cancellation support extended down to the IGeometry and ISymbol level
30
 *
31
 * Revision 1.13  2007/09/17 14:16:11  jaume
32
 * multilayer symbols sizing bug fixed
33
 *
34
 * Revision 1.12  2007/08/22 09:48:13  jvidal
35
 * javadoc
36
 *
37
 * Revision 1.11  2007/05/09 11:04:58  jaume
38
 * refactored legend hierarchy
39
 *
40
 * Revision 1.10  2007/05/08 08:47:40  jaume
41
 * *** empty log message ***
42
 *
43
 * Revision 1.9  2007/04/26 11:41:00  jaume
44
 * attempting to let defining size in world units
45
 *
46
 * Revision 1.8  2007/04/18 15:35:11  jaume
47
 * *** empty log message ***
48
 *
49
 * Revision 1.7  2007/04/12 14:28:43  jaume
50
 * basic labeling support for lines
51
 *
52
 * Revision 1.6  2007/04/11 16:01:08  jaume
53
 * maybe a label placer refactor
54
 *
55
 * Revision 1.5  2007/04/10 16:34:01  jaume
56
 * towards a styled labeling
57
 *
58
 * Revision 1.4  2007/04/05 16:07:14  jaume
59
 * Styled labeling stuff
60
 *
61
 * Revision 1.3  2007/04/02 16:34:56  jaume
62
 * Styled labeling (start commiting)
63
 *
64
 * Revision 1.2  2007/03/09 08:33:43  jaume
65
 * *** empty log message ***
66
 *
67
 * Revision 1.1.2.6  2007/02/15 16:23:44  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.1.2.5  2007/02/09 07:47:05  jaume
71
 * Isymbol moved
72
 *
73
 * Revision 1.1.2.4  2007/02/02 16:21:24  jaume
74
 * start commiting labeling stuff
75
 *
76
 * Revision 1.1.2.3  2007/02/01 17:46:49  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.1.2.2  2007/02/01 11:42:47  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.1.2.1  2007/01/30 18:10:45  jaume
83
 * start commiting labeling stuff
84
 *
85
 *
86
 */
87
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling;
88

    
89
import java.awt.Dimension;
90
import java.awt.Graphics2D;
91
import java.awt.Rectangle;
92
import java.awt.Shape;
93
import java.awt.geom.AffineTransform;
94
import java.awt.geom.Point2D;
95
import java.awt.geom.Rectangle2D;
96

    
97
import org.gvsig.fmap.geom.Geometry;
98
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
99
import org.gvsig.fmap.geom.GeometryLocator;
100
import org.gvsig.fmap.geom.GeometryManager;
101
import org.gvsig.fmap.geom.exception.CreateGeometryException;
102
import org.gvsig.fmap.geom.primitive.GeneralPathX;
103
import org.gvsig.fmap.mapcontext.ViewPort;
104
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass;
105
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelLocationMetrics;
106
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
107
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
108
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
109
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
110
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit;
111
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
112
import org.gvsig.tools.ToolsLocator;
113
import org.gvsig.tools.dynobject.DynStruct;
114
import org.gvsig.tools.persistence.PersistenceManager;
115
import org.gvsig.tools.persistence.Persistent;
116
import org.gvsig.tools.persistence.PersistentContext;
117
import org.gvsig.tools.persistence.PersistentState;
118
import org.gvsig.tools.persistence.exception.PersistenceException;
119
import org.gvsig.tools.persistence.spi.PersistentContextServices;
120
import org.gvsig.tools.util.Callable;
121
import org.slf4j.Logger;
122
import org.slf4j.LoggerFactory;
123

    
124

    
125
/**
126
 *
127
 * LabelClass is the model of the label in the new simbology of gvSIG. In this
128
 * class is contained its definition, the expresion that defines the text which
129
 * is going to be showed, if it will be visible or not, the text symbol that is
130
 * going to paint the label and the style for its background.
131
 *
132
 * @author jaume dominguez faus - jaume.dominguez@iver.es
133
 */
134
public class LabelClass implements ILabelClass {
135
        
136
        private static final String FIELD_REFERENCE_SYSTEM = "referenceSystem";
137
        private static final String FIELD_UNIT = "unit";
138
        private static final String FIELD_SQL_QUERY = "sqlQuery";
139
        private static final String FIELD_SCALE = "scale";
140
        private static final String FIELD_PRIORITY = "priority";
141
        private static final String FIELD_TEXTS = "texts";
142
        private static final String FIELD_LABEL_STYLE = "labelStyle";
143
        private static final String FIELD_VISIBLE = "visible";
144
        private static final String FIELD_LABEL_EXPRESSIONS = "labelExpressions";
145
        private static final String FIELD_TEXT_SYMBOL = "textSymbol";
146
        private static final String FIELD_NAME = "name";
147
        private static final String FIELD_IS_USESQL = "useSQL";
148
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
149
        private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
150
        private static final String LABEL_CLASS_PERSISTENCE_DEFINITION_NAME = "LabelClass";
151
        private String theName = "";
152
        private ITextSymbol textSymbol;
153
        private String[] labelExpressions = new String[0];
154
        private boolean isVisible = true;
155
        private ILabelStyle labelStyle;
156
        private String[] texts;
157
        private int priority;
158
        private double scale = 1;
159
        
160
        private String sqlQuery;
161
        private boolean usesSQL;
162

    
163
        private int unit = CartographicSupportToolkit.DefaultMeasureUnit;
164
        private int referenceSystem =
165
                        CartographicSupportToolkit.DefaultReferenceSystem;
166
        
167
        /**
168
         * Returns true if the label will be showed in the map
169
         *
170
         * @return isVisible boolean
171
         */
172
        public boolean isVisible() {
173
                return isVisible;
174
        }
175

    
176
        /**
177
         * Returns true if the label will be showed in the map
178
         *
179
         * @return isVisible boolean
180
         */
181
        public boolean isVisible(double scale) {
182
                return isVisible();
183
        }
184

    
185
        /**
186
         * Sets the visibility of the label in the map.
187
         *
188
         * @param isVisible boolean
189
         */
190
        public void setVisible(boolean isVisible) {
191
                this.isVisible = isVisible;
192
        }
193

    
194
        /**
195
         * Returns the expression that defines the text which will be showed in
196
         * the label
197
         *
198
         * @return labelExpression String
199
         */
200
        public String[] getLabelExpressions() {
201
                return labelExpressions;
202
        }
203

    
204
        /**
205
         * Stablishes the expresion that, when it is evaluated, returns the text
206
         * which will be showed by the label.
207
         *
208
         * @param labelExpression String
209
         */
210
        public void setLabelExpressions(String[] lbl_exps) {
211
                if (lbl_exps == null) {
212
                        this.labelExpressions = new String[0];
213
                } else {
214
                        this.labelExpressions = lbl_exps;
215
                }
216
                
217
        }
218

    
219
        /**
220
         * Returns the text symbol that is being used for the text(the font,
221
         * size,style,aligment)
222
         *
223
         * @return label ITextSymbol
224
         */
225
        public ITextSymbol getTextSymbol() {
226
                if (textSymbol == null) {
227
                        textSymbol = new SimpleTextSymbol();
228
                }
229
                return textSymbol;
230
        }
231

    
232
        private Dimension getSize() {
233
                if (labelStyle == null) {
234
                        if (texts!=null && texts.length >0) {
235
                                String t = "";
236
                                for (int i = 0; i < texts.length; i++) {
237
                                        t += texts[i];
238
                                }
239
                                getTextSymbol().setText(t);
240
                        }
241

    
242
                        Rectangle bounds = getTextSymbol().getBounds();
243
                        bounds.setLocation(
244
                                        (int) Math.round(bounds.getX()),
245
                                        (int) Math.round(bounds.getY()+bounds.getHeight()));
246
                        return new Dimension(bounds.width, bounds.height);
247
                } else {
248
                        labelStyle.setTextFields(texts);
249
                        return labelStyle.getSize();
250
                }
251
        }
252
        /**
253
         * Stablishes the text symbol that is going to be used for the text(the
254
         * font,size,style,aligment)
255
         *
256
         * @param textSymbol ITextSymbol
257
         */
258
        public void setTextSymbol(ITextSymbol textSymbol) {
259
                this.textSymbol = textSymbol;
260
                if (textSymbol == null) {
261
                        this.textSymbol = new SimpleTextSymbol();
262
                }
263
                setReferenceSystem(referenceSystem);
264
                setUnit(unit);
265
        }
266

    
267
        /**
268
         * Stablishes the style for the label.
269
         *
270
         * @param labelStyle ILabelStyle
271
         */
272
        public void setLabelStyle(ILabelStyle labelStyle) {
273
                this.labelStyle = labelStyle;
274
        }
275

    
276
        /**
277
         * Returns the style of the label
278
         *
279
         */
280
        public ILabelStyle getLabelStyle() {
281
                return this.labelStyle;
282
        }
283

    
284
        /**
285
         * Returns the name of the label
286
         *
287
         */
288
        public String getName() {
289
                return theName;
290
        }
291

    
292
        /**
293
         * Stablishes the name of the label
294
         * @param name
295
         */
296
        public void setName(String name) {
297
            if (name == null) {
298
            theName = "";
299
            } else {
300
                theName = name;
301
            }
302
        }
303

    
304
        public String toString() {
305
                // for debugging
306
                //                return name+"{label expression="+labelExpression+", visible="+isVisible+", priority="+priority+"}";
307
                return getName();
308
        }
309

    
310
        /**
311
         * Sets the text for the label
312
         *
313
         * @param texts String[]
314
         */
315
        public void setTexts(String[] texts) {
316
                this.texts = null;
317
                this.texts = texts;
318

    
319
        }
320

    
321
        /**
322
         * Return the text for the label
323
         *
324
         * @param texts String[]
325
         */
326
        public String[] getTexts() {
327
                return this.texts;
328
        }
329

    
330
        /**
331
         * <p>
332
         * LabelLocationMetrics, contains the anchor point, rotation, and some
333
         * other geometric calculations computed by the PlacementManager.
334
         * </p>
335
         *
336
         * <p>
337
         * The shp argument is passed as an accessory for subclasses of this
338
         * class in case they need futher geometric calculations
339
         * </p>
340
         * @param graphics, graphics to use to paint the label.
341
         * @param llm, concrete settings of the placement of this layer
342
         * @param shp, the Shape over whose the label is painted
343
         */
344
        public void draw(Graphics2D graphics, ILabelLocationMetrics llm, Geometry geom) {
345
                if (scale == 0)
346
                        return;
347

    
348

    
349
                Dimension size = getSize();
350
                int width = (int) Math.round(size.getWidth()*scale);
351
                if (width  < 1)
352
                        return;
353

    
354
                int height = (int) Math.round(size.getHeight()*scale);
355
                if (height < 1)
356
                        return;
357

    
358
                Rectangle r = new Rectangle(0,0, width, height);
359
                org.gvsig.fmap.geom.primitive.Point anchor;
360
                try {
361
                        anchor = geomManager.createPoint(llm.getAnchor().getX(), llm.getAnchor().getY(), SUBTYPES.GEOM2D);
362
                        double xAnchor = anchor.getX();
363
                        double yAnchor = anchor.getY();
364
                        double theta = llm.getRotation();
365

    
366
                        graphics.translate(xAnchor, yAnchor);
367
                        graphics.rotate(theta);
368
                        synchronized (this) {
369
                                float fontSizeBefore = textSymbol.getFont().getSize2D();
370
                                try {
371
                                        textSymbol.setFontSize(fontSizeBefore*scale);
372
                                        drawInsideRectangle(graphics, r);
373
                                        textSymbol.setFontSize(fontSizeBefore);
374
                                } catch (SymbolDrawingException e) {
375
                                        logger.warn("Error drawing", e);
376
                                }
377
                        }
378
                        graphics.rotate(-theta);
379
                        graphics.translate(-xAnchor, -yAnchor);
380
                } catch (CreateGeometryException e1) {
381
                        logger.warn("Error creating a point", e1);
382
                }
383
        }
384

    
385
        private void relativeToAbsolute(double[] xy, Rectangle r, Dimension labelSz, double ratioLabel, double ratioViewPort) {
386
                int x;
387
                int y;
388
                if (ratioViewPort > ratioLabel) {
389
                        // size is defined by the viewport height
390
                        y = (int) (r.height*xy[1]);
391
                        x = (int) ((0.5*r.width) - (0.5-xy[0])*(ratioLabel*r.height));
392
                } else {
393
                        // size is defined by the viewport width
394
                        x = (int) (r.width * xy[0]);
395
                        y = (int) ((0.5 * r.height) - (0.5-xy[1])*(r.width/ratioLabel));
396
                }
397
                xy[0] = x;
398
                xy[1] = y;
399
        }
400

    
401
        /**
402
         * Useful to render a Label with size inside little rectangles.
403
         *
404
         * @param graphics Graphics2D
405
         * @param bounds Rectangle
406
         * @throws SymbolDrawingException
407
         */
408
        public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) throws SymbolDrawingException {
409
                if (labelStyle != null) {
410
                        labelStyle.drawInsideRectangle(graphics, bounds);
411
                        Rectangle2D[] textBounds = labelStyle.getTextBounds();
412
                        Dimension labelSz = getSize();
413
                        final double ratioLabel = labelSz.getWidth()/labelSz.getHeight();
414
                        final double ratioViewPort = bounds.getWidth() / bounds.getHeight();
415
                        final double[] xy = new double[2];
416

    
417

    
418
                        // draw the text fields
419
                        if (textBounds.length > 0 && texts!=null) {
420
                                for (int i = 0; i < textBounds.length && i < texts.length; i++) {
421
                                        getTextSymbol().setText(texts[i]);
422
                                        Rectangle2D textFieldArea = textBounds[i];
423
                                        xy[0] = textFieldArea.getX();
424
                                        xy[1] = textFieldArea.getY();
425
                                        relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort);
426
                                        int x = (int) Math.round(xy[0]);
427
                                        int y = (int) Math.round(xy[1]);
428

    
429
                                        xy[0] = textFieldArea.getMaxX();
430
                                        xy[1] = textFieldArea.getMaxY();
431
                                        relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort);
432
                                        int width = (int) Math.round(xy[0]) -x;
433
                                        int height = (int) Math.round(xy[1] - y) ;
434

    
435
                                        Rectangle textRect = new Rectangle(x, y, width, height);
436
                                        Shape oldClip = graphics.getClip();
437
                                        graphics.setClip(textRect);
438
                                        getTextSymbol().drawInsideRectangle(graphics, null, textRect, null);
439
                                        graphics.setClip(oldClip);
440
                                }
441
                        }
442
                } else {
443

    
444
                        if (texts != null && texts.length>0){
445
                                String fullText = "";
446
                                for(int ig=0; ig<texts.length; ig++){
447
                                        fullText = fullText + texts[ig];
448
                                }
449
                                getTextSymbol().setText(fullText);
450
                        }
451
                        getTextSymbol().drawInsideRectangle(graphics, null, bounds, null);
452
                }
453
        }
454

    
455
        public int getPriority() {
456
                return priority;
457
        }
458

    
459
        public void setPriority(int priority) {
460
                this.priority = priority;
461
        }
462

    
463
        public Geometry getShape(ILabelLocationMetrics llm) throws CreateGeometryException {
464
                if (llm==null)
465
                        return null;
466
                Point2D anchor = llm.getAnchor();
467
                org.gvsig.fmap.geom.primitive.Point p = geomManager.createPoint(anchor.getX(), anchor.getY(), SUBTYPES.GEOM2D);
468
                double theta = llm.getRotation();
469

    
470
                // 2. calculate the container shape
471
                Geometry returnedValue;
472
                Rectangle bounds = getBounds();
473

    
474
                AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
475
                at.concatenate(AffineTransform.getRotateInstance(theta));
476
                returnedValue = geomManager.createSurface(new GeneralPathX(bounds
477
                                .getPathIterator(null)), SUBTYPES.GEOM2D);
478

    
479
                returnedValue.transform(at);
480
                return returnedValue;
481
        }
482

    
483
        public String getClassName() {
484
                return getClass().getName();
485
        }
486

    
487
        public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
488
                Dimension sz = getSize();
489
                double width = sz.getWidth();
490
                double height = sz.getHeight();
491
                return CartographicSupportToolkit.
492
                getCartographicLength(this,
493
                                Math.max(width, height),
494
                                viewPort,
495
                                dpi);
496
        }
497

    
498
        public int getReferenceSystem() {
499
                return referenceSystem;
500
        }
501

    
502
        public int getUnit() {
503
                return unit;
504
        }
505

    
506
        public void setCartographicSize(double cartographicSize, Geometry geom) {
507
                Dimension sz = getSize();
508
                double width = sz.getWidth();
509
                double height = sz.getHeight();
510
                if (width >= height) {
511
                        scale = cartographicSize / width;
512
                } else {
513
                        scale = cartographicSize / height;
514
                }
515
        }
516

    
517
        public void setReferenceSystem(int referenceSystem) {
518
                this.referenceSystem = referenceSystem;
519
                if (textSymbol != null && textSymbol instanceof CartographicSupport) {
520
                        ((CartographicSupport) textSymbol).setReferenceSystem(referenceSystem);
521
                }
522
        }
523

    
524
        public void setUnit(int unitIndex) {
525
                this.unit = unitIndex;
526
                if (textSymbol != null && textSymbol instanceof CartographicSupport) {
527
                        ((CartographicSupport) textSymbol).setUnit(unitIndex);
528
                }
529
        }
530

    
531
        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
532
                setCartographicSize(getCartographicSize(
533
                                viewPort,
534
                                dpi,
535
                                geom),
536
                                geom);
537
                return 0;
538
        }
539

    
540
        public Rectangle getBounds() {
541
                Dimension cBounds = getSize();
542
                return new Rectangle(
543
                                0,
544
                                0,
545
                                (int) Math.round(cBounds.width*scale),
546
                                (int) Math.round(cBounds.height*scale));
547
        }
548

    
549
        public String getSQLQuery() {
550
                if (sqlQuery == null) sqlQuery = "";
551
                return sqlQuery;
552
        }
553

    
554
        public void setSQLQuery(String sqlQuery) {
555
                this.sqlQuery = sqlQuery;
556
        }
557

    
558
        /*
559
         * (non-Javadoc)
560
         * 
561
         * @seeorg.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.
562
         * persistence.PersistentState)
563
         */
564
        public void saveToState(PersistentState state) throws PersistenceException {
565
                state.set(FIELD_NAME, getName());
566
                state.set(FIELD_TEXT_SYMBOL, getTextSymbol());
567
                state.set(FIELD_LABEL_EXPRESSIONS, getLabelExpressions());
568
                state.set(FIELD_VISIBLE, isVisible());
569
                
570
                ILabelStyle sty = getLabelStyle();
571
                if (sty != null) {
572
                        state.set(FIELD_LABEL_STYLE, getLabelStyle());
573
                }
574
                
575
                state.set(FIELD_TEXTS, getTexts());
576
                state.set(FIELD_PRIORITY, getPriority());
577

    
578
                state.set(FIELD_SCALE, scale);
579
                state.set(FIELD_SQL_QUERY, getSQLQuery());
580
                state.set(FIELD_IS_USESQL, isUseSqlQuery());
581
                
582
                state.set(FIELD_UNIT, getUnit());
583
                state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem());
584
        }
585

    
586
        /*
587
         * (non-Javadoc)
588
         * 
589
         * @see
590
         * org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.
591
         * persistence.PersistentState)
592
         */
593
        public void loadFromState(PersistentState state)
594
                        throws PersistenceException {
595
                setName(state.getString(FIELD_NAME));
596
                setTextSymbol((ITextSymbol) state.get(FIELD_TEXT_SYMBOL));
597
                setLabelExpressions(state.getStringArray(FIELD_LABEL_EXPRESSIONS));
598
                setVisible(state.getBoolean(FIELD_VISIBLE));
599
                
600
                if (state.hasValue(FIELD_LABEL_STYLE)) {
601
                        setLabelStyle((ILabelStyle) state.get(FIELD_LABEL_STYLE));                        
602
                }
603
                
604
                setTexts((String[]) state.getArray(FIELD_TEXTS, String.class));
605
                setPriority(state.getInt(FIELD_PRIORITY));
606
                scale = state.getDouble(FIELD_SCALE);
607
                
608
                setUseSqlQuery(state.getBoolean(FIELD_IS_USESQL));
609
                setSQLQuery(state.getString(FIELD_SQL_QUERY));
610
                
611
                setUnit(state.getInt(FIELD_UNIT));
612
                setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM));
613
        }
614

    
615
        public static class RegisterPersistence implements Callable {
616

    
617
                public Object call() throws Exception {
618
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
619
                        if( manager.getDefinition(LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)==null ) {
620
                                DynStruct definition = manager.addDefinition(
621
                                                LabelClass.class,
622
                                                LABEL_CLASS_PERSISTENCE_DEFINITION_NAME,
623
                                                LABEL_CLASS_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
624
                                                null, 
625
                                                null
626
                                );
627

    
628
                                definition.addDynFieldString(FIELD_NAME).setMandatory(true);
629
                                definition.addDynFieldObject(FIELD_TEXT_SYMBOL).setMandatory(true).setClassOfValue(ITextSymbol.class);
630
                                
631
                                definition.addDynFieldArray(FIELD_LABEL_EXPRESSIONS)
632
                                .setClassOfItems(String.class).setMandatory(true);
633
                                
634
                                definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(true);
635
                                
636
                                definition.addDynFieldObject(FIELD_LABEL_STYLE).setMandatory(false)
637
                                .setClassOfValue(ILabelStyle.class);
638
                                
639
                                definition.addDynFieldList(FIELD_TEXTS).setMandatory(true).setClassOfItems(String.class);
640
                                definition.addDynFieldInt(FIELD_PRIORITY).setMandatory(true);
641
                                definition.addDynFieldDouble(FIELD_SCALE).setMandatory(true);
642
                                definition.addDynFieldString(FIELD_SQL_QUERY).setMandatory(true);
643
                                definition.addDynFieldBoolean(FIELD_IS_USESQL).setMandatory(true);
644
                                definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
645
                                definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
646
                        }
647
                        return Boolean.TRUE;
648
                }
649
                
650
        }
651

    
652
        public void setUseSqlQuery(boolean use_sql) {
653
                this.usesSQL = use_sql;
654
        }
655

    
656
        public boolean isUseSqlQuery() {
657
                return this.usesSQL;
658
        }
659

    
660
        public String getStringLabelExpression(){
661
                String expr = "";
662

    
663
                if(labelExpressions != null && labelExpressions.length > 0) {
664

    
665
                        for (int i = 0; i < labelExpressions.length-1; i++) {
666
                                expr += (String) labelExpressions[i] +  ":";//EOFIELD
667
                        }
668
                        expr += labelExpressions[labelExpressions.length - 1];
669

    
670
                } else {
671
                        expr = "";
672
                }
673
                return expr;
674
        }
675

    
676
    public Object clone() throws CloneNotSupportedException {
677

    
678
        PersistenceManager persman = ToolsLocator.getPersistenceManager();
679

    
680
        PersistentContext context = null;
681
        Object resp = null;
682
        PersistentState state = null;
683
        try {
684
            state = persman.getState(this, true);
685
        } catch (PersistenceException e) {
686
            logger.warn("Can't clone, return me !!!!!!!!!!!!!!", e);
687
            return this;
688
        }
689
        context = state.getContext();
690
        if (context instanceof PersistentContextServices) {
691
            /*
692
             * Ensure that previous instances are not used,
693
             * so objects are recreated
694
             */
695
            ((PersistentContextServices) context).clear();
696
        }
697
        try {
698
            resp = persman.create(state);
699
        } catch (Exception e) {
700
            logger.warn("Can't clone, return me !!!!!!!!!!!!!!", e);
701
            return this;
702
        }
703
        return resp;
704

    
705
    }
706

    
707
        
708

    
709
        
710
}