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 @ 41085
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 |
logger.warn("Error drawing", e);
|
359 |
} |
360 |
} |
361 |
graphics.rotate(-theta); |
362 |
graphics.translate(-xAnchor, -yAnchor); |
363 |
} catch (CreateGeometryException e1) {
|
364 |
logger.warn("Error creating a point", e1);
|
365 |
} |
366 |
} |
367 |
|
368 |
private void relativeToAbsolute(double[] xy, Rectangle r, Dimension labelSz, double ratioLabel, double ratioViewPort) { |
369 |
int x;
|
370 |
int y;
|
371 |
if (ratioViewPort > ratioLabel) {
|
372 |
// size is defined by the viewport height
|
373 |
y = (int) (r.height*xy[1]); |
374 |
x = (int) ((0.5*r.width) - (0.5-xy[0])*(ratioLabel*r.height)); |
375 |
} else {
|
376 |
// size is defined by the viewport width
|
377 |
x = (int) (r.width * xy[0]); |
378 |
y = (int) ((0.5 * r.height) - (0.5-xy[1])*(r.width/ratioLabel)); |
379 |
} |
380 |
xy[0] = x;
|
381 |
xy[1] = y;
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* Useful to render a Label with size inside little rectangles.
|
386 |
*
|
387 |
* @param graphics Graphics2D
|
388 |
* @param bounds Rectangle
|
389 |
* @throws SymbolDrawingException
|
390 |
*/
|
391 |
public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) throws SymbolDrawingException { |
392 |
if (labelStyle != null) { |
393 |
labelStyle.drawInsideRectangle(graphics, bounds); |
394 |
Rectangle2D[] textBounds = labelStyle.getTextBounds(); |
395 |
Dimension labelSz = getSize();
|
396 |
final double ratioLabel = labelSz.getWidth()/labelSz.getHeight(); |
397 |
final double ratioViewPort = bounds.getWidth() / bounds.getHeight(); |
398 |
final double[] xy = new double[2]; |
399 |
|
400 |
|
401 |
// draw the text fields
|
402 |
if (textBounds.length > 0 && texts!=null) { |
403 |
for (int i = 0; i < textBounds.length && i < texts.length; i++) { |
404 |
getTextSymbol().setText(texts[i]); |
405 |
Rectangle2D textFieldArea = textBounds[i];
|
406 |
xy[0] = textFieldArea.getX();
|
407 |
xy[1] = textFieldArea.getY();
|
408 |
relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort); |
409 |
int x = (int) Math.round(xy[0]); |
410 |
int y = (int) Math.round(xy[1]); |
411 |
|
412 |
xy[0] = textFieldArea.getMaxX();
|
413 |
xy[1] = textFieldArea.getMaxY();
|
414 |
relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort); |
415 |
int width = (int) Math.round(xy[0]) -x; |
416 |
int height = (int) Math.round(xy[1] - y) ; |
417 |
|
418 |
Rectangle textRect = new Rectangle(x, y, width, height); |
419 |
Shape oldClip = graphics.getClip();
|
420 |
graphics.setClip(textRect); |
421 |
getTextSymbol().drawInsideRectangle(graphics, null, textRect, null); |
422 |
graphics.setClip(oldClip); |
423 |
} |
424 |
} |
425 |
} else {
|
426 |
|
427 |
if (texts != null && texts.length>0) |
428 |
getTextSymbol().setText(texts[0]);
|
429 |
getTextSymbol().drawInsideRectangle(graphics, null, bounds, null); |
430 |
} |
431 |
} |
432 |
|
433 |
public int getPriority() { |
434 |
return priority;
|
435 |
} |
436 |
|
437 |
public void setPriority(int priority) { |
438 |
this.priority = priority;
|
439 |
} |
440 |
|
441 |
public Geometry getShape(ILabelLocationMetrics llm) throws CreateGeometryException { |
442 |
if (llm==null) |
443 |
return null; |
444 |
Point2D anchor = llm.getAnchor();
|
445 |
org.gvsig.fmap.geom.primitive.Point p = geomManager.createPoint(anchor.getX(), anchor.getY(), SUBTYPES.GEOM2D); |
446 |
double theta = llm.getRotation();
|
447 |
|
448 |
// 2. calculate the container shape
|
449 |
Geometry returnedValue; |
450 |
Rectangle bounds = getBounds();
|
451 |
|
452 |
AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); |
453 |
at.concatenate(AffineTransform.getRotateInstance(theta));
|
454 |
returnedValue = geomManager.createSurface(new GeneralPathX(bounds
|
455 |
.getPathIterator(null)), SUBTYPES.GEOM2D);
|
456 |
|
457 |
returnedValue.transform(at); |
458 |
return returnedValue;
|
459 |
} |
460 |
|
461 |
public String getClassName() { |
462 |
return getClass().getName();
|
463 |
} |
464 |
|
465 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
466 |
Dimension sz = getSize();
|
467 |
double width = sz.getWidth();
|
468 |
double height = sz.getHeight();
|
469 |
return CartographicSupportToolkit.
|
470 |
getCartographicLength(this,
|
471 |
Math.max(width, height),
|
472 |
viewPort, |
473 |
dpi); |
474 |
} |
475 |
|
476 |
public int getReferenceSystem() { |
477 |
return referenceSystem;
|
478 |
} |
479 |
|
480 |
public int getUnit() { |
481 |
return unit;
|
482 |
} |
483 |
|
484 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
485 |
Dimension sz = getSize();
|
486 |
double width = sz.getWidth();
|
487 |
double height = sz.getHeight();
|
488 |
if (width >= height) {
|
489 |
scale = cartographicSize / width; |
490 |
} else {
|
491 |
scale = cartographicSize / height; |
492 |
} |
493 |
} |
494 |
|
495 |
public void setReferenceSystem(int referenceSystem) { |
496 |
this.referenceSystem = referenceSystem;
|
497 |
if (textSymbol != null && textSymbol instanceof CartographicSupport) { |
498 |
((CartographicSupport) textSymbol).setReferenceSystem(referenceSystem); |
499 |
} |
500 |
} |
501 |
|
502 |
public void setUnit(int unitIndex) { |
503 |
this.unit = unitIndex;
|
504 |
if (textSymbol != null && textSymbol instanceof CartographicSupport) { |
505 |
((CartographicSupport) textSymbol).setUnit(unitIndex); |
506 |
} |
507 |
} |
508 |
|
509 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
510 |
setCartographicSize(getCartographicSize( |
511 |
viewPort, |
512 |
dpi, |
513 |
geom), |
514 |
geom); |
515 |
return 0; |
516 |
} |
517 |
|
518 |
public Rectangle getBounds() { |
519 |
Dimension cBounds = getSize();
|
520 |
return new Rectangle( |
521 |
0,
|
522 |
0,
|
523 |
(int) Math.round(cBounds.width*scale), |
524 |
(int) Math.round(cBounds.height*scale)); |
525 |
} |
526 |
|
527 |
public String getSQLQuery() { |
528 |
if (sqlQuery == null) sqlQuery = ""; |
529 |
return sqlQuery;
|
530 |
} |
531 |
|
532 |
public void setSQLQuery(String sqlQuery) { |
533 |
this.sqlQuery = sqlQuery;
|
534 |
} |
535 |
|
536 |
/*
|
537 |
* (non-Javadoc)
|
538 |
*
|
539 |
* @seeorg.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.
|
540 |
* persistence.PersistentState)
|
541 |
*/
|
542 |
public void saveToState(PersistentState state) throws PersistenceException { |
543 |
state.set(FIELD_NAME, getName()); |
544 |
state.set(FIELD_TEXT_SYMBOL, getTextSymbol()); |
545 |
state.set(FIELD_LABEL_EXPRESSIONS, getLabelExpressions()); |
546 |
state.set(FIELD_VISIBLE, isVisible()); |
547 |
|
548 |
ILabelStyle sty = getLabelStyle(); |
549 |
if (sty != null) { |
550 |
state.set(FIELD_LABEL_STYLE, getLabelStyle()); |
551 |
} |
552 |
|
553 |
state.set(FIELD_TEXTS, getTexts()); |
554 |
state.set(FIELD_PRIORITY, getPriority()); |
555 |
|
556 |
state.set(FIELD_SCALE, scale); |
557 |
state.set(FIELD_SQL_QUERY, getSQLQuery()); |
558 |
state.set(FIELD_IS_USESQL, isUseSqlQuery()); |
559 |
|
560 |
state.set(FIELD_UNIT, getUnit()); |
561 |
state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem()); |
562 |
} |
563 |
|
564 |
/*
|
565 |
* (non-Javadoc)
|
566 |
*
|
567 |
* @see
|
568 |
* org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.
|
569 |
* persistence.PersistentState)
|
570 |
*/
|
571 |
public void loadFromState(PersistentState state) |
572 |
throws PersistenceException {
|
573 |
setName(state.getString(FIELD_NAME)); |
574 |
setTextSymbol((ITextSymbol) state.get(FIELD_TEXT_SYMBOL)); |
575 |
setLabelExpressions(state.getStringArray(FIELD_LABEL_EXPRESSIONS)); |
576 |
setVisible(state.getBoolean(FIELD_VISIBLE)); |
577 |
|
578 |
if (state.hasValue(FIELD_LABEL_STYLE)) {
|
579 |
setLabelStyle((ILabelStyle) state.get(FIELD_LABEL_STYLE)); |
580 |
} |
581 |
|
582 |
setTexts((String[]) state.getArray(FIELD_TEXTS, String.class)); |
583 |
setPriority(state.getInt(FIELD_PRIORITY)); |
584 |
scale = state.getDouble(FIELD_SCALE); |
585 |
|
586 |
setUseSqlQuery(state.getBoolean(FIELD_IS_USESQL)); |
587 |
setSQLQuery(state.getString(FIELD_SQL_QUERY)); |
588 |
|
589 |
setUnit(state.getInt(FIELD_UNIT)); |
590 |
setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM)); |
591 |
} |
592 |
|
593 |
public static class RegisterPersistence implements Callable { |
594 |
|
595 |
public Object call() throws Exception { |
596 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
597 |
if( manager.getDefinition(LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)==null ) { |
598 |
DynStruct definition = manager.addDefinition( |
599 |
LabelClass.class, |
600 |
LABEL_CLASS_PERSISTENCE_DEFINITION_NAME, |
601 |
LABEL_CLASS_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
602 |
null,
|
603 |
null
|
604 |
); |
605 |
|
606 |
definition.addDynFieldString(FIELD_NAME).setMandatory(true);
|
607 |
definition.addDynFieldObject(FIELD_TEXT_SYMBOL).setMandatory(true).setClassOfValue(ITextSymbol.class);
|
608 |
|
609 |
definition.addDynFieldArray(FIELD_LABEL_EXPRESSIONS) |
610 |
.setClassOfItems(String.class).setMandatory(true); |
611 |
|
612 |
definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(true);
|
613 |
|
614 |
definition.addDynFieldObject(FIELD_LABEL_STYLE).setMandatory(false)
|
615 |
.setClassOfValue(ILabelStyle.class); |
616 |
|
617 |
definition.addDynFieldList(FIELD_TEXTS).setMandatory(true).setClassOfItems(String.class); |
618 |
definition.addDynFieldInt(FIELD_PRIORITY).setMandatory(true);
|
619 |
definition.addDynFieldDouble(FIELD_SCALE).setMandatory(true);
|
620 |
definition.addDynFieldString(FIELD_SQL_QUERY).setMandatory(true);
|
621 |
definition.addDynFieldBoolean(FIELD_IS_USESQL).setMandatory(true);
|
622 |
definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
|
623 |
definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
|
624 |
} |
625 |
return Boolean.TRUE; |
626 |
} |
627 |
|
628 |
} |
629 |
|
630 |
public void setUseSqlQuery(boolean use_sql) { |
631 |
this.usesSQL = use_sql;
|
632 |
} |
633 |
|
634 |
public boolean isUseSqlQuery() { |
635 |
return this.usesSQL; |
636 |
} |
637 |
|
638 |
public String getStringLabelExpression(){ |
639 |
String expr = ""; |
640 |
|
641 |
if(labelExpressions != null && labelExpressions.length > 0) { |
642 |
|
643 |
for (int i = 0; i < labelExpressions.length-1; i++) { |
644 |
expr += (String) labelExpressions[i] + ":";//EOFIELD |
645 |
} |
646 |
expr += labelExpressions[labelExpressions.length - 1];
|
647 |
|
648 |
} else {
|
649 |
expr = "";
|
650 |
} |
651 |
return expr;
|
652 |
} |
653 |
|
654 |
|
655 |
|
656 |
} |