svn-gvsig-desktop / tags / v2_0_0_Build_2021 / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / styling / LabelClass.java @ 34111
History | View | Annotate | Download (18.1 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: LabelClass.java 13953 2007-09-21 12:26:04Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.14 2007-09-21 12:26:04 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.13 2007/09/17 14:16:11 jaume
|
50 |
* multilayer symbols sizing bug fixed
|
51 |
*
|
52 |
* Revision 1.12 2007/08/22 09:48:13 jvidal
|
53 |
* javadoc
|
54 |
*
|
55 |
* Revision 1.11 2007/05/09 11:04:58 jaume
|
56 |
* refactored legend hierarchy
|
57 |
*
|
58 |
* Revision 1.10 2007/05/08 08:47:40 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.9 2007/04/26 11:41:00 jaume
|
62 |
* attempting to let defining size in world units
|
63 |
*
|
64 |
* Revision 1.8 2007/04/18 15:35:11 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.7 2007/04/12 14:28:43 jaume
|
68 |
* basic labeling support for lines
|
69 |
*
|
70 |
* Revision 1.6 2007/04/11 16:01:08 jaume
|
71 |
* maybe a label placer refactor
|
72 |
*
|
73 |
* Revision 1.5 2007/04/10 16:34:01 jaume
|
74 |
* towards a styled labeling
|
75 |
*
|
76 |
* Revision 1.4 2007/04/05 16:07:14 jaume
|
77 |
* Styled labeling stuff
|
78 |
*
|
79 |
* Revision 1.3 2007/04/02 16:34:56 jaume
|
80 |
* Styled labeling (start commiting)
|
81 |
*
|
82 |
* Revision 1.2 2007/03/09 08:33:43 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.1.2.6 2007/02/15 16:23:44 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.1.2.5 2007/02/09 07:47:05 jaume
|
89 |
* Isymbol moved
|
90 |
*
|
91 |
* Revision 1.1.2.4 2007/02/02 16:21:24 jaume
|
92 |
* start commiting labeling stuff
|
93 |
*
|
94 |
* Revision 1.1.2.3 2007/02/01 17:46:49 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.1.2.2 2007/02/01 11:42:47 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
101 |
* start commiting labeling stuff
|
102 |
*
|
103 |
*
|
104 |
*/
|
105 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling; |
106 |
|
107 |
import java.awt.Dimension; |
108 |
import java.awt.Graphics2D; |
109 |
import java.awt.Rectangle; |
110 |
import java.awt.Shape; |
111 |
import java.awt.geom.AffineTransform; |
112 |
import java.awt.geom.Point2D; |
113 |
import java.awt.geom.Rectangle2D; |
114 |
|
115 |
import org.gvsig.fmap.geom.Geometry; |
116 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
117 |
import org.gvsig.fmap.geom.GeometryLocator; |
118 |
import org.gvsig.fmap.geom.GeometryManager; |
119 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
120 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
121 |
import org.gvsig.fmap.mapcontext.ViewPort; |
122 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
123 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelLocationMetrics; |
124 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
125 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
126 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
127 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
128 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
129 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol; |
130 |
import org.gvsig.tools.ToolsLocator; |
131 |
import org.gvsig.tools.dynobject.DynStruct; |
132 |
import org.gvsig.tools.persistence.PersistenceManager; |
133 |
import org.gvsig.tools.persistence.PersistentState; |
134 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
135 |
import org.gvsig.tools.util.Callable; |
136 |
import org.slf4j.Logger; |
137 |
import org.slf4j.LoggerFactory; |
138 |
|
139 |
|
140 |
/**
|
141 |
*
|
142 |
* LabelClass is the model of the label in the new simbology of gvSIG. In this
|
143 |
* class is contained its definition, the expresion that defines the text which
|
144 |
* is going to be showed, if it will be visible or not, the text symbol that is
|
145 |
* going to paint the label and the style for its background.
|
146 |
*
|
147 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
148 |
*/
|
149 |
public class LabelClass implements ILabelClass { |
150 |
private static final String FIELD_REFERENCE_SYSTEM = "referenceSystem"; |
151 |
private static final String FIELD_UNIT = "unit"; |
152 |
private static final String FIELD_SQL_QUERY = "sqlQuery"; |
153 |
private static final String FIELD_SCALE = "scale"; |
154 |
private static final String FIELD_PRIORITY = "priority"; |
155 |
private static final String FIELD_TEXTS = "texts"; |
156 |
private static final String FIELD_LABEL_STYLE = "labelStyle"; |
157 |
private static final String FIELD_VISIBLE = "visible"; |
158 |
private static final String FIELD_LABEL_EXPRESSION = "labelExpression"; |
159 |
private static final String FIELD_TEXT_SYMBOL = "textSymbol"; |
160 |
private static final String FIELD_NAME = "name"; |
161 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
162 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
163 |
private static final String LABEL_CLASS_PERSISTENCE_DEFINITION_NAME = "LabelClass"; |
164 |
private String name; |
165 |
private ITextSymbol textSymbol;
|
166 |
private String labelExpression; |
167 |
private boolean isVisible = true; |
168 |
private ILabelStyle labelStyle;
|
169 |
private String[] texts; |
170 |
private int priority; |
171 |
private double scale = 1; |
172 |
private String sqlQuery; |
173 |
|
174 |
private int unit = CartographicSupportToolkit.DefaultMeasureUnit; |
175 |
private int referenceSystem = |
176 |
CartographicSupportToolkit.DefaultReferenceSystem; |
177 |
|
178 |
/**
|
179 |
* Returns true if the label will be showed in the map
|
180 |
*
|
181 |
* @return isVisible boolean
|
182 |
*/
|
183 |
public boolean isVisible() { |
184 |
return isVisible;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Sets the visibility of the label in the map.
|
189 |
*
|
190 |
* @param isVisible boolean
|
191 |
*/
|
192 |
public void setVisible(boolean isVisible) { |
193 |
this.isVisible = isVisible;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Returns the expression that defines the text which will be showed in
|
198 |
* the label
|
199 |
*
|
200 |
* @return labelExpression String
|
201 |
*/
|
202 |
public String getLabelExpression() { |
203 |
return labelExpression;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Stablishes the expresion that, when it is evaluated, returns the text
|
208 |
* which will be showed by the label.
|
209 |
*
|
210 |
* @param labelExpression String
|
211 |
*/
|
212 |
public void setLabelExpression(String labelExpression) { |
213 |
this.labelExpression = labelExpression;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Returns the text symbol that is being used for the text(the font,
|
218 |
* size,style,aligment)
|
219 |
*
|
220 |
* @return label ITextSymbol
|
221 |
*/
|
222 |
public ITextSymbol getTextSymbol() {
|
223 |
if (textSymbol == null) { |
224 |
textSymbol = new SimpleTextSymbol();
|
225 |
} |
226 |
return textSymbol;
|
227 |
} |
228 |
|
229 |
private Dimension getSize() { |
230 |
if (labelStyle == null) { |
231 |
if (texts!=null && texts.length >0) { |
232 |
String t = ""; |
233 |
for (int i = 0; i < texts.length; i++) { |
234 |
t += texts[i]; |
235 |
} |
236 |
getTextSymbol().setText(t); |
237 |
} |
238 |
|
239 |
Rectangle bounds = getTextSymbol().getBounds();
|
240 |
bounds.setLocation( |
241 |
(int) Math.round(bounds.getX()), |
242 |
(int) Math.round(bounds.getY()+bounds.getHeight())); |
243 |
return new Dimension(bounds.width, bounds.height); |
244 |
} else {
|
245 |
labelStyle.setTextFields(texts); |
246 |
return labelStyle.getSize();
|
247 |
} |
248 |
} |
249 |
/**
|
250 |
* Stablishes the text symbol that is going to be used for the text(the
|
251 |
* font,size,style,aligment)
|
252 |
*
|
253 |
* @param textSymbol ITextSymbol
|
254 |
*/
|
255 |
public void setTextSymbol(ITextSymbol textSymbol) { |
256 |
this.textSymbol = textSymbol;
|
257 |
if (textSymbol == null) { |
258 |
this.textSymbol = new SimpleTextSymbol(); |
259 |
} |
260 |
setReferenceSystem(referenceSystem); |
261 |
setUnit(unit); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Stablishes the style for the label.
|
266 |
*
|
267 |
* @param labelStyle ILabelStyle
|
268 |
*/
|
269 |
public void setLabelStyle(ILabelStyle labelStyle) { |
270 |
this.labelStyle = labelStyle;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* Returns the style of the label
|
275 |
*
|
276 |
*/
|
277 |
public ILabelStyle getLabelStyle() {
|
278 |
return this.labelStyle; |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Returns the name of the label
|
283 |
*
|
284 |
*/
|
285 |
public String getName() { |
286 |
return name;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* Stablishes the name of the label
|
291 |
* @param name
|
292 |
*/
|
293 |
public void setName(String name) { |
294 |
this.name = name;
|
295 |
} |
296 |
|
297 |
public String toString() { |
298 |
// for debugging
|
299 |
// return name+"{label expression="+labelExpression+", visible="+isVisible+", priority="+priority+"}";
|
300 |
return getName();
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* Sets the text for the label
|
305 |
*
|
306 |
* @param texts String[]
|
307 |
*/
|
308 |
public void setTexts(String[] texts) { |
309 |
this.texts = texts;
|
310 |
|
311 |
} |
312 |
|
313 |
/**
|
314 |
* Return the text for the label
|
315 |
*
|
316 |
* @param texts String[]
|
317 |
*/
|
318 |
public String[] getTexts() { |
319 |
return this.texts; |
320 |
} |
321 |
|
322 |
/**
|
323 |
* <p>
|
324 |
* LabelLocationMetrics, contains the anchor point, rotation, and some
|
325 |
* other geometric calculations computed by the PlacementManager.
|
326 |
* </p>
|
327 |
*
|
328 |
* <p>
|
329 |
* The shp argument is passed as an accessory for subclasses of this
|
330 |
* class in case they need futher geometric calculations
|
331 |
* </p>
|
332 |
* @param graphics, graphics to use to paint the label.
|
333 |
* @param llm, concrete settings of the placement of this layer
|
334 |
* @param shp, the Shape over whose the label is painted
|
335 |
*/
|
336 |
public void draw(Graphics2D graphics, ILabelLocationMetrics llm, Geometry geom) { |
337 |
if (scale == 0) |
338 |
return;
|
339 |
|
340 |
|
341 |
Dimension size = getSize();
|
342 |
int width = (int) Math.round(size.getWidth()*scale); |
343 |
if (width < 1) |
344 |
return;
|
345 |
|
346 |
int height = (int) Math.round(size.getHeight()*scale); |
347 |
if (height < 1) |
348 |
return;
|
349 |
|
350 |
Rectangle r = new Rectangle(0,0, width, height); |
351 |
org.gvsig.fmap.geom.primitive.Point anchor; |
352 |
try {
|
353 |
anchor = geomManager.createPoint(llm.getAnchor().getX(), llm.getAnchor().getY(), SUBTYPES.GEOM2D); |
354 |
double xAnchor = anchor.getX();
|
355 |
double yAnchor = anchor.getY();
|
356 |
double theta = llm.getRotation();
|
357 |
|
358 |
graphics.translate(xAnchor, yAnchor); |
359 |
graphics.rotate(theta); |
360 |
synchronized (this) { |
361 |
float fontSizeBefore = textSymbol.getFont().getSize2D();
|
362 |
try {
|
363 |
textSymbol.setFontSize(fontSizeBefore*scale); |
364 |
drawInsideRectangle(graphics, r); |
365 |
textSymbol.setFontSize(fontSizeBefore); |
366 |
} catch (SymbolDrawingException e) {
|
367 |
e.printStackTrace(); |
368 |
} |
369 |
} |
370 |
graphics.rotate(-theta); |
371 |
graphics.translate(-xAnchor, -yAnchor); |
372 |
} catch (CreateGeometryException e1) {
|
373 |
logger.error("Error creating a point", e1);
|
374 |
e1.printStackTrace(); |
375 |
} |
376 |
} |
377 |
|
378 |
private void relativeToAbsolute(double[] xy, Rectangle r, Dimension labelSz, double ratioLabel, double ratioViewPort) { |
379 |
int x;
|
380 |
int y;
|
381 |
if (ratioViewPort > ratioLabel) {
|
382 |
// size is defined by the viewport height
|
383 |
y = (int) (r.height*xy[1]); |
384 |
x = (int) ((0.5*r.width) - (0.5-xy[0])*(ratioLabel*r.height)); |
385 |
} else {
|
386 |
// size is defined by the viewport width
|
387 |
x = (int) (r.width * xy[0]); |
388 |
y = (int) ((0.5 * r.height) - (0.5-xy[1])*(r.width/ratioLabel)); |
389 |
} |
390 |
xy[0] = x;
|
391 |
xy[1] = y;
|
392 |
} |
393 |
|
394 |
/**
|
395 |
* Useful to render a Label with size inside little rectangles.
|
396 |
*
|
397 |
* @param graphics Graphics2D
|
398 |
* @param bounds Rectangle
|
399 |
* @throws SymbolDrawingException
|
400 |
*/
|
401 |
public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) throws SymbolDrawingException { |
402 |
if (labelStyle != null) { |
403 |
labelStyle.drawInsideRectangle(graphics, bounds); |
404 |
Rectangle2D[] textBounds = labelStyle.getTextBounds(); |
405 |
Dimension labelSz = getSize();
|
406 |
final double ratioLabel = labelSz.getWidth()/labelSz.getHeight(); |
407 |
final double ratioViewPort = bounds.getWidth() / bounds.getHeight(); |
408 |
final double[] xy = new double[2]; |
409 |
|
410 |
|
411 |
// draw the text fields
|
412 |
if (textBounds.length > 0 && texts!=null) { |
413 |
for (int i = 0; i < textBounds.length && i < texts.length; i++) { |
414 |
getTextSymbol().setText(texts[i]); |
415 |
Rectangle2D textFieldArea = textBounds[i];
|
416 |
xy[0] = textFieldArea.getX();
|
417 |
xy[1] = textFieldArea.getY();
|
418 |
relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort); |
419 |
int x = (int) Math.round(xy[0]); |
420 |
int y = (int) Math.round(xy[1]); |
421 |
|
422 |
xy[0] = textFieldArea.getMaxX();
|
423 |
xy[1] = textFieldArea.getMaxY();
|
424 |
relativeToAbsolute(xy, bounds, labelSz, ratioLabel, ratioViewPort); |
425 |
int width = (int) Math.round(xy[0]) -x; |
426 |
int height = (int) Math.round(xy[1] - y) ; |
427 |
|
428 |
Rectangle textRect = new Rectangle(x, y, width, height); |
429 |
Shape oldClip = graphics.getClip();
|
430 |
graphics.setClip(textRect); |
431 |
getTextSymbol().drawInsideRectangle(graphics, null, textRect, null); |
432 |
graphics.setClip(oldClip); |
433 |
} |
434 |
} |
435 |
} else {
|
436 |
|
437 |
if (texts != null && texts.length>0) |
438 |
getTextSymbol().setText(texts[0]);
|
439 |
getTextSymbol().drawInsideRectangle(graphics, null, bounds, null); |
440 |
} |
441 |
} |
442 |
|
443 |
public int getPriority() { |
444 |
return priority;
|
445 |
} |
446 |
|
447 |
public void setPriority(int priority) { |
448 |
this.priority = priority;
|
449 |
} |
450 |
|
451 |
public Geometry getShape(ILabelLocationMetrics llm) throws CreateGeometryException { |
452 |
if (llm==null) |
453 |
return null; |
454 |
Point2D anchor = llm.getAnchor();
|
455 |
org.gvsig.fmap.geom.primitive.Point p = geomManager.createPoint(anchor.getX(), anchor.getY(), SUBTYPES.GEOM2D); |
456 |
double theta = llm.getRotation();
|
457 |
|
458 |
// 2. calculate the container shape
|
459 |
Geometry returnedValue; |
460 |
Rectangle bounds = getBounds();
|
461 |
|
462 |
AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); |
463 |
at.concatenate(AffineTransform.getRotateInstance(theta));
|
464 |
returnedValue = geomManager.createSurface(new GeneralPathX(bounds
|
465 |
.getPathIterator(null)), SUBTYPES.GEOM2D);
|
466 |
|
467 |
returnedValue.transform(at); |
468 |
return returnedValue;
|
469 |
} |
470 |
|
471 |
public String getClassName() { |
472 |
return getClass().getName();
|
473 |
} |
474 |
|
475 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
476 |
Dimension sz = getSize();
|
477 |
double width = sz.getWidth();
|
478 |
double height = sz.getHeight();
|
479 |
return CartographicSupportToolkit.
|
480 |
getCartographicLength(this,
|
481 |
Math.max(width, height),
|
482 |
viewPort, |
483 |
dpi); |
484 |
} |
485 |
|
486 |
public int getReferenceSystem() { |
487 |
return referenceSystem;
|
488 |
} |
489 |
|
490 |
public int getUnit() { |
491 |
return unit;
|
492 |
} |
493 |
|
494 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
495 |
Dimension sz = getSize();
|
496 |
double width = sz.getWidth();
|
497 |
double height = sz.getHeight();
|
498 |
if (width >= height) {
|
499 |
scale = cartographicSize / width; |
500 |
} else {
|
501 |
scale = cartographicSize / height; |
502 |
} |
503 |
} |
504 |
|
505 |
public void setReferenceSystem(int referenceSystem) { |
506 |
this.referenceSystem = referenceSystem;
|
507 |
if (textSymbol != null && textSymbol instanceof CartographicSupport) { |
508 |
((CartographicSupport) textSymbol).setReferenceSystem(referenceSystem); |
509 |
} |
510 |
} |
511 |
|
512 |
public void setUnit(int unitIndex) { |
513 |
this.unit = unitIndex;
|
514 |
if (textSymbol != null && textSymbol instanceof CartographicSupport) { |
515 |
((CartographicSupport) textSymbol).setUnit(unitIndex); |
516 |
} |
517 |
} |
518 |
|
519 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
520 |
setCartographicSize(getCartographicSize( |
521 |
viewPort, |
522 |
dpi, |
523 |
geom), |
524 |
geom); |
525 |
return 0; |
526 |
} |
527 |
|
528 |
public Rectangle getBounds() { |
529 |
Dimension cBounds = getSize();
|
530 |
return new Rectangle( |
531 |
0,
|
532 |
0,
|
533 |
(int) Math.round(cBounds.width*scale), |
534 |
(int) Math.round(cBounds.height*scale)); |
535 |
} |
536 |
|
537 |
public String getSQLQuery() { |
538 |
if (sqlQuery == null) sqlQuery = ""; |
539 |
return sqlQuery;
|
540 |
} |
541 |
|
542 |
public void setSQLQuery(String sqlQuery) { |
543 |
this.sqlQuery = sqlQuery;
|
544 |
} |
545 |
|
546 |
/*
|
547 |
* (non-Javadoc)
|
548 |
*
|
549 |
* @seeorg.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.
|
550 |
* persistence.PersistentState)
|
551 |
*/
|
552 |
public void saveToState(PersistentState state) throws PersistenceException { |
553 |
state.set(FIELD_NAME, getName()); |
554 |
state.set(FIELD_TEXT_SYMBOL, getTextSymbol()); |
555 |
state.set(FIELD_LABEL_EXPRESSION, getLabelExpression()); |
556 |
state.set(FIELD_VISIBLE, isVisible()); |
557 |
state.set(FIELD_LABEL_STYLE, getLabelStyle()); |
558 |
state.set(FIELD_TEXTS, getTexts()); |
559 |
state.set(FIELD_PRIORITY, getPriority()); |
560 |
state.set(FIELD_SCALE, scale); |
561 |
state.set(FIELD_SQL_QUERY, getSQLQuery()); |
562 |
state.set(FIELD_UNIT, getUnit()); |
563 |
state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem()); |
564 |
} |
565 |
|
566 |
/*
|
567 |
* (non-Javadoc)
|
568 |
*
|
569 |
* @see
|
570 |
* org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.
|
571 |
* persistence.PersistentState)
|
572 |
*/
|
573 |
public void loadFromState(PersistentState state) |
574 |
throws PersistenceException {
|
575 |
setName(state.getString(FIELD_NAME)); |
576 |
setTextSymbol((ITextSymbol) state.get(FIELD_TEXT_SYMBOL)); |
577 |
setLabelExpression(state.getString(FIELD_LABEL_EXPRESSION)); |
578 |
setVisible(state.getBoolean(FIELD_VISIBLE)); |
579 |
setLabelStyle((ILabelStyle) state.get(FIELD_LABEL_STYLE)); |
580 |
setTexts((String[]) state.getArray(FIELD_TEXTS, String.class)); |
581 |
setPriority(state.getInt(FIELD_PRIORITY)); |
582 |
scale = state.getDouble(FIELD_SCALE); |
583 |
setSQLQuery(state.getString(FIELD_SQL_QUERY)); |
584 |
setUnit(state.getInt(FIELD_UNIT)); |
585 |
setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM)); |
586 |
} |
587 |
|
588 |
public static class RegisterPersistence implements Callable { |
589 |
|
590 |
public Object call() throws Exception { |
591 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
592 |
if( manager.getDefinition(LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)==null ) { |
593 |
DynStruct definition = manager.addDefinition( |
594 |
LabelClass.class, |
595 |
LABEL_CLASS_PERSISTENCE_DEFINITION_NAME, |
596 |
LABEL_CLASS_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
597 |
null,
|
598 |
null
|
599 |
); |
600 |
|
601 |
definition.addDynFieldString(FIELD_NAME).setMandatory(true);
|
602 |
definition.addDynFieldObject(FIELD_TEXT_SYMBOL).setMandatory(true).setClassOfValue(ITextSymbol.class);
|
603 |
definition.addDynFieldString(FIELD_LABEL_EXPRESSION).setMandatory(true);
|
604 |
definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(true);
|
605 |
definition.addDynFieldObject(FIELD_LABEL_STYLE).setMandatory(true).setClassOfValue(ILabelStyle.class);
|
606 |
definition.addDynFieldList(FIELD_TEXTS).setMandatory(true).setClassOfItems(String.class); |
607 |
definition.addDynFieldInt(FIELD_PRIORITY).setMandatory(true);
|
608 |
definition.addDynFieldDouble(FIELD_SCALE).setMandatory(true);
|
609 |
definition.addDynFieldString(FIELD_SQL_QUERY).setMandatory(true);
|
610 |
definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
|
611 |
definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
|
612 |
} |
613 |
return Boolean.TRUE; |
614 |
} |
615 |
|
616 |
} |
617 |
|
618 |
|
619 |
|
620 |
|
621 |
} |