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 @ 40711

History | View | Annotate | Download (18.9 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.PersistentState;
116
import org.gvsig.tools.persistence.exception.PersistenceException;
117
import org.gvsig.tools.util.Callable;
118
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
120

    
121

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

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

    
173
        /**
174
         * Sets the visibility of the label in the map.
175
         *
176
         * @param isVisible boolean
177
         */
178
        public void setVisible(boolean isVisible) {
179
                this.isVisible = isVisible;
180
        }
181

    
182
        /**
183
         * Returns the expression that defines the text which will be showed in
184
         * the label
185
         *
186
         * @return labelExpression String
187
         */
188
        public String[] getLabelExpressions() {
189
                return labelExpressions;
190
        }
191

    
192
        /**
193
         * Stablishes the expresion that, when it is evaluated, returns the text
194
         * which will be showed by the label.
195
         *
196
         * @param labelExpression String
197
         */
198
        public void setLabelExpressions(String[] lbl_exps) {
199
                if (lbl_exps == null) {
200
                        this.labelExpressions = new String[0];
201
                } else {
202
                        this.labelExpressions = lbl_exps;
203
                }
204
                
205
        }
206

    
207
        /**
208
         * Returns the text symbol that is being used for the text(the font,
209
         * size,style,aligment)
210
         *
211
         * @return label ITextSymbol
212
         */
213
        public ITextSymbol getTextSymbol() {
214
                if (textSymbol == null) {
215
                        textSymbol = new SimpleTextSymbol();
216
                }
217
                return textSymbol;
218
        }
219

    
220
        private Dimension getSize() {
221
                if (labelStyle == null) {
222
                        if (texts!=null && texts.length >0) {
223
                                String t = "";
224
                                for (int i = 0; i < texts.length; i++) {
225
                                        t += texts[i];
226
                                }
227
                                getTextSymbol().setText(t);
228
                        }
229

    
230
                        Rectangle bounds = getTextSymbol().getBounds();
231
                        bounds.setLocation(
232
                                        (int) Math.round(bounds.getX()),
233
                                        (int) Math.round(bounds.getY()+bounds.getHeight()));
234
                        return new Dimension(bounds.width, bounds.height);
235
                } else {
236
                        labelStyle.setTextFields(texts);
237
                        return labelStyle.getSize();
238
                }
239
        }
240
        /**
241
         * Stablishes the text symbol that is going to be used for the text(the
242
         * font,size,style,aligment)
243
         *
244
         * @param textSymbol ITextSymbol
245
         */
246
        public void setTextSymbol(ITextSymbol textSymbol) {
247
                this.textSymbol = textSymbol;
248
                if (textSymbol == null) {
249
                        this.textSymbol = new SimpleTextSymbol();
250
                }
251
                setReferenceSystem(referenceSystem);
252
                setUnit(unit);
253
        }
254

    
255
        /**
256
         * Stablishes the style for the label.
257
         *
258
         * @param labelStyle ILabelStyle
259
         */
260
        public void setLabelStyle(ILabelStyle labelStyle) {
261
                this.labelStyle = labelStyle;
262
        }
263

    
264
        /**
265
         * Returns the style of the label
266
         *
267
         */
268
        public ILabelStyle getLabelStyle() {
269
                return this.labelStyle;
270
        }
271

    
272
        /**
273
         * Returns the name of the label
274
         *
275
         */
276
        public String getName() {
277
                return name;
278
        }
279

    
280
        /**
281
         * Stablishes the name of the label
282
         * @param name
283
         */
284
        public void setName(String name) {
285
                this.name = name;
286
        }
287

    
288
        public String toString() {
289
                // for debugging
290
                //                return name+"{label expression="+labelExpression+", visible="+isVisible+", priority="+priority+"}";
291
                return getName();
292
        }
293

    
294
        /**
295
         * Sets the text for the label
296
         *
297
         * @param texts String[]
298
         */
299
        public void setTexts(String[] texts) {
300
                this.texts = texts;
301

    
302
        }
303

    
304
        /**
305
         * Return the text for the label
306
         *
307
         * @param texts String[]
308
         */
309
        public String[] getTexts() {
310
                return this.texts;
311
        }
312

    
313
        /**
314
         * <p>
315
         * LabelLocationMetrics, contains the anchor point, rotation, and some
316
         * other geometric calculations computed by the PlacementManager.
317
         * </p>
318
         *
319
         * <p>
320
         * The shp argument is passed as an accessory for subclasses of this
321
         * class in case they need futher geometric calculations
322
         * </p>
323
         * @param graphics, graphics to use to paint the label.
324
         * @param llm, concrete settings of the placement of this layer
325
         * @param shp, the Shape over whose the label is painted
326
         */
327
        public void draw(Graphics2D graphics, ILabelLocationMetrics llm, Geometry geom) {
328
                if (scale == 0)
329
                        return;
330

    
331

    
332
                Dimension size = getSize();
333
                int width = (int) Math.round(size.getWidth()*scale);
334
                if (width  < 1)
335
                        return;
336

    
337
                int height = (int) Math.round(size.getHeight()*scale);
338
                if (height < 1)
339
                        return;
340

    
341
                Rectangle r = new Rectangle(0,0, width, height);
342
                org.gvsig.fmap.geom.primitive.Point anchor;
343
                try {
344
                        anchor = geomManager.createPoint(llm.getAnchor().getX(), llm.getAnchor().getY(), SUBTYPES.GEOM2D);
345
                        double xAnchor = anchor.getX();
346
                        double yAnchor = anchor.getY();
347
                        double theta = llm.getRotation();
348

    
349
                        graphics.translate(xAnchor, yAnchor);
350
                        graphics.rotate(theta);
351
                        synchronized (this) {
352
                                float fontSizeBefore = textSymbol.getFont().getSize2D();
353
                                try {
354
                                        textSymbol.setFontSize(fontSizeBefore*scale);
355
                                        drawInsideRectangle(graphics, r);
356
                                        textSymbol.setFontSize(fontSizeBefore);
357
                                } catch (SymbolDrawingException e) {
358
                                        e.printStackTrace();
359
                                }
360
                        }
361
                        graphics.rotate(-theta);
362
                        graphics.translate(-xAnchor, -yAnchor);
363
                } catch (CreateGeometryException e1) {
364
                        logger.error("Error creating a point", e1);
365
                        e1.printStackTrace();
366
                }
367
        }
368

    
369
        private void relativeToAbsolute(double[] xy, Rectangle r, Dimension labelSz, double ratioLabel, double ratioViewPort) {
370
                int x;
371
                int y;
372
                if (ratioViewPort > ratioLabel) {
373
                        // size is defined by the viewport height
374
                        y = (int) (r.height*xy[1]);
375
                        x = (int) ((0.5*r.width) - (0.5-xy[0])*(ratioLabel*r.height));
376
                } else {
377
                        // size is defined by the viewport width
378
                        x = (int) (r.width * xy[0]);
379
                        y = (int) ((0.5 * r.height) - (0.5-xy[1])*(r.width/ratioLabel));
380
                }
381
                xy[0] = x;
382
                xy[1] = y;
383
        }
384

    
385
        /**
386
         * Useful to render a Label with size inside little rectangles.
387
         *
388
         * @param graphics Graphics2D
389
         * @param bounds Rectangle
390
         * @throws SymbolDrawingException
391
         */
392
        public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) throws SymbolDrawingException {
393
                if (labelStyle != null) {
394
                        labelStyle.drawInsideRectangle(graphics, bounds);
395
                        Rectangle2D[] textBounds = labelStyle.getTextBounds();
396
                        Dimension labelSz = getSize();
397
                        final double ratioLabel = labelSz.getWidth()/labelSz.getHeight();
398
                        final double ratioViewPort = bounds.getWidth() / bounds.getHeight();
399
                        final double[] xy = new double[2];
400

    
401

    
402
                        // draw the text fields
403
                        if (textBounds.length > 0 && texts!=null) {
404
                                for (int i = 0; i < textBounds.length && i < texts.length; i++) {
405
                                        getTextSymbol().setText(texts[i]);
406
                                        Rectangle2D textFieldArea = textBounds[i];
407
                                        xy[0] = textFieldArea.getX();
408
                                        xy[1] = textFieldArea.getY();
409
                                        relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort);
410
                                        int x = (int) Math.round(xy[0]);
411
                                        int y = (int) Math.round(xy[1]);
412

    
413
                                        xy[0] = textFieldArea.getMaxX();
414
                                        xy[1] = textFieldArea.getMaxY();
415
                                        relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort);
416
                                        int width = (int) Math.round(xy[0]) -x;
417
                                        int height = (int) Math.round(xy[1] - y) ;
418

    
419
                                        Rectangle textRect = new Rectangle(x, y, width, height);
420
                                        Shape oldClip = graphics.getClip();
421
                                        graphics.setClip(textRect);
422
                                        getTextSymbol().drawInsideRectangle(graphics, null, textRect, null);
423
                                        graphics.setClip(oldClip);
424
                                }
425
                        }
426
                } else {
427

    
428
                        if (texts != null && texts.length>0)
429
                                getTextSymbol().setText(texts[0]);
430
                        getTextSymbol().drawInsideRectangle(graphics, null, bounds, null);
431
                }
432
        }
433

    
434
        public int getPriority() {
435
                return priority;
436
        }
437

    
438
        public void setPriority(int priority) {
439
                this.priority = priority;
440
        }
441

    
442
        public Geometry getShape(ILabelLocationMetrics llm) throws CreateGeometryException {
443
                if (llm==null)
444
                        return null;
445
                Point2D anchor = llm.getAnchor();
446
                org.gvsig.fmap.geom.primitive.Point p = geomManager.createPoint(anchor.getX(), anchor.getY(), SUBTYPES.GEOM2D);
447
                double theta = llm.getRotation();
448

    
449
                // 2. calculate the container shape
450
                Geometry returnedValue;
451
                Rectangle bounds = getBounds();
452

    
453
                AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
454
                at.concatenate(AffineTransform.getRotateInstance(theta));
455
                returnedValue = geomManager.createSurface(new GeneralPathX(bounds
456
                                .getPathIterator(null)), SUBTYPES.GEOM2D);
457

    
458
                returnedValue.transform(at);
459
                return returnedValue;
460
        }
461

    
462
        public String getClassName() {
463
                return getClass().getName();
464
        }
465

    
466
        public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
467
                Dimension sz = getSize();
468
                double width = sz.getWidth();
469
                double height = sz.getHeight();
470
                return CartographicSupportToolkit.
471
                getCartographicLength(this,
472
                                Math.max(width, height),
473
                                viewPort,
474
                                dpi);
475
        }
476

    
477
        public int getReferenceSystem() {
478
                return referenceSystem;
479
        }
480

    
481
        public int getUnit() {
482
                return unit;
483
        }
484

    
485
        public void setCartographicSize(double cartographicSize, Geometry geom) {
486
                Dimension sz = getSize();
487
                double width = sz.getWidth();
488
                double height = sz.getHeight();
489
                if (width >= height) {
490
                        scale = cartographicSize / width;
491
                } else {
492
                        scale = cartographicSize / height;
493
                }
494
        }
495

    
496
        public void setReferenceSystem(int referenceSystem) {
497
                this.referenceSystem = referenceSystem;
498
                if (textSymbol != null && textSymbol instanceof CartographicSupport) {
499
                        ((CartographicSupport) textSymbol).setReferenceSystem(referenceSystem);
500
                }
501
        }
502

    
503
        public void setUnit(int unitIndex) {
504
                this.unit = unitIndex;
505
                if (textSymbol != null && textSymbol instanceof CartographicSupport) {
506
                        ((CartographicSupport) textSymbol).setUnit(unitIndex);
507
                }
508
        }
509

    
510
        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
511
                setCartographicSize(getCartographicSize(
512
                                viewPort,
513
                                dpi,
514
                                geom),
515
                                geom);
516
                return 0;
517
        }
518

    
519
        public Rectangle getBounds() {
520
                Dimension cBounds = getSize();
521
                return new Rectangle(
522
                                0,
523
                                0,
524
                                (int) Math.round(cBounds.width*scale),
525
                                (int) Math.round(cBounds.height*scale));
526
        }
527

    
528
        public String getSQLQuery() {
529
                if (sqlQuery == null) sqlQuery = "";
530
                return sqlQuery;
531
        }
532

    
533
        public void setSQLQuery(String sqlQuery) {
534
                this.sqlQuery = sqlQuery;
535
        }
536

    
537
        /*
538
         * (non-Javadoc)
539
         * 
540
         * @seeorg.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.
541
         * persistence.PersistentState)
542
         */
543
        public void saveToState(PersistentState state) throws PersistenceException {
544
                state.set(FIELD_NAME, getName());
545
                state.set(FIELD_TEXT_SYMBOL, getTextSymbol());
546
                state.set(FIELD_LABEL_EXPRESSIONS, getLabelExpressions());
547
                state.set(FIELD_VISIBLE, isVisible());
548
                
549
                ILabelStyle sty = getLabelStyle();
550
                if (sty != null) {
551
                        state.set(FIELD_LABEL_STYLE, getLabelStyle());
552
                }
553
                
554
                state.set(FIELD_TEXTS, getTexts());
555
                state.set(FIELD_PRIORITY, getPriority());
556

    
557
                state.set(FIELD_SCALE, scale);
558
                state.set(FIELD_SQL_QUERY, getSQLQuery());
559
                state.set(FIELD_IS_USESQL, isUseSqlQuery());
560
                
561
                state.set(FIELD_UNIT, getUnit());
562
                state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem());
563
        }
564

    
565
        /*
566
         * (non-Javadoc)
567
         * 
568
         * @see
569
         * org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.
570
         * persistence.PersistentState)
571
         */
572
        public void loadFromState(PersistentState state)
573
                        throws PersistenceException {
574
                setName(state.getString(FIELD_NAME));
575
                setTextSymbol((ITextSymbol) state.get(FIELD_TEXT_SYMBOL));
576
                setLabelExpressions(state.getStringArray(FIELD_LABEL_EXPRESSIONS));
577
                setVisible(state.getBoolean(FIELD_VISIBLE));
578
                
579
                if (state.hasValue(FIELD_LABEL_STYLE)) {
580
                        setLabelStyle((ILabelStyle) state.get(FIELD_LABEL_STYLE));                        
581
                }
582
                
583
                setTexts((String[]) state.getArray(FIELD_TEXTS, String.class));
584
                setPriority(state.getInt(FIELD_PRIORITY));
585
                scale = state.getDouble(FIELD_SCALE);
586
                
587
                setUseSqlQuery(state.getBoolean(FIELD_IS_USESQL));
588
                setSQLQuery(state.getString(FIELD_SQL_QUERY));
589
                
590
                setUnit(state.getInt(FIELD_UNIT));
591
                setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM));
592
        }
593

    
594
        public static class RegisterPersistence implements Callable {
595

    
596
                public Object call() throws Exception {
597
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
598
                        if( manager.getDefinition(LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)==null ) {
599
                                DynStruct definition = manager.addDefinition(
600
                                                LabelClass.class,
601
                                                LABEL_CLASS_PERSISTENCE_DEFINITION_NAME,
602
                                                LABEL_CLASS_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
603
                                                null, 
604
                                                null
605
                                );
606

    
607
                                definition.addDynFieldString(FIELD_NAME).setMandatory(true);
608
                                definition.addDynFieldObject(FIELD_TEXT_SYMBOL).setMandatory(true).setClassOfValue(ITextSymbol.class);
609
                                
610
                                definition.addDynFieldArray(FIELD_LABEL_EXPRESSIONS)
611
                                .setClassOfItems(String.class).setMandatory(true);
612
                                
613
                                definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(true);
614
                                
615
                                definition.addDynFieldObject(FIELD_LABEL_STYLE).setMandatory(false)
616
                                .setClassOfValue(ILabelStyle.class);
617
                                
618
                                definition.addDynFieldList(FIELD_TEXTS).setMandatory(true).setClassOfItems(String.class);
619
                                definition.addDynFieldInt(FIELD_PRIORITY).setMandatory(true);
620
                                definition.addDynFieldDouble(FIELD_SCALE).setMandatory(true);
621
                                definition.addDynFieldString(FIELD_SQL_QUERY).setMandatory(true);
622
                                definition.addDynFieldBoolean(FIELD_IS_USESQL).setMandatory(true);
623
                                definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
624
                                definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
625
                        }
626
                        return Boolean.TRUE;
627
                }
628
                
629
        }
630

    
631
        public void setUseSqlQuery(boolean use_sql) {
632
                this.usesSQL = use_sql;
633
        }
634

    
635
        public boolean isUseSqlQuery() {
636
                return this.usesSQL;
637
        }
638

    
639
        public String getStringLabelExpression(){
640
                String expr = "";
641

    
642
                if(labelExpressions != null && labelExpressions.length > 0) {
643

    
644
                        for (int i = 0; i < labelExpressions.length-1; i++) {
645
                                expr += (String) labelExpressions[i] +  ":";//EOFIELD
646
                        }
647
                        expr += labelExpressions[labelExpressions.length - 1];
648

    
649
                } else {
650
                        expr = "";
651
                }
652
                return expr;
653
        }
654

    
655

    
656
        
657
}