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 / symbol / marker / impl / AbstractMarkerSymbol.java @ 47593
History | View | Annotate | Download (17.8 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl; |
||
25 | |||
26 | import java.awt.Color; |
||
27 | import java.awt.Point; |
||
28 | import java.awt.Rectangle; |
||
29 | import java.awt.geom.Point2D; |
||
30 | 45523 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
31 | import org.gvsig.expressionevaluator.ExpressionUtils; |
||
32 | import org.gvsig.expressionevaluator.SymbolTable; |
||
33 | import org.gvsig.fmap.dal.DALLocator; |
||
34 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
35 | import org.gvsig.fmap.dal.feature.Feature; |
||
36 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
37 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
38 | import org.gvsig.fmap.geom.GeometryLocator; |
||
39 | import org.gvsig.fmap.geom.GeometryManager; |
||
40 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
41 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
42 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
43 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol; |
||
44 | 47476 | fdiaz | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol_v2; |
45 | 40435 | jjdelcerro | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
46 | import org.gvsig.tools.ToolsLocator; |
||
47 | import org.gvsig.tools.dynobject.DynStruct; |
||
48 | import org.gvsig.tools.persistence.PersistenceManager; |
||
49 | import org.gvsig.tools.persistence.PersistentState; |
||
50 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
51 | import org.gvsig.tools.util.Callable; |
||
52 | |||
53 | /**
|
||
54 | * Abstract class that any MARKER SYMBOL should extend.
|
||
55 | 45518 | jjdelcerro | *
|
56 | * @author gvSIG team
|
||
57 | 40435 | jjdelcerro | */
|
58 | 45523 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
59 | 45527 | jjdelcerro | public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol_v2 { |
60 | 45518 | jjdelcerro | |
61 | public static final String MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME = "MarkerSymbol"; |
||
62 | |||
63 | 40435 | jjdelcerro | private static final String FIELD_COLOR = "color"; |
64 | private static final String FIELD_ROTATION = "rotation"; |
||
65 | private static final String FIELD_OFFSET = "offset"; |
||
66 | private static final String FIELD_SIZE = "size"; |
||
67 | private static final String FIELD_MASK = "mask"; |
||
68 | 45527 | jjdelcerro | private static final String FIELD_LINETOOFFSETCOLOR = "lineToOffsetColor"; |
69 | private static final String FIELD_DRAWLINETOOFFSET = "drawLineToOffset"; |
||
70 | private static final String FIELD_SIZE_EXPRESSION = "sizeExpression"; |
||
71 | 45523 | jjdelcerro | private static final String FIELD_OFFSETX_EXPRESSION = "offsetXExpression"; |
72 | private static final String FIELD_OFFSETY_EXPRESSION = "offsetYExpression"; |
||
73 | private static final String FIELD_ROTATION_EXPRESSION = "rotationExpression"; |
||
74 | private static final String FIELD_LINETOOFFSETCOLOR_EXPRESSION = "lineToOffsetColorExpression"; |
||
75 | 40435 | jjdelcerro | |
76 | 45518 | jjdelcerro | private static final GeometryManager GEOMETRY_MANAGER = GeometryLocator.getGeometryManager(); |
77 | 47476 | fdiaz | |
78 | 45518 | jjdelcerro | private Color color; |
79 | 47593 | jjdelcerro | private double rotationDegrees; |
80 | 45518 | jjdelcerro | private Point2D offset = new Point2D.Double(); |
81 | private double size = 4d; |
||
82 | private IMask mask;
|
||
83 | 40435 | jjdelcerro | |
84 | 45527 | jjdelcerro | private Color lineToOffsetColor; |
85 | 45523 | jjdelcerro | private boolean drawLineToOffset; |
86 | |||
87 | 45527 | jjdelcerro | private String sizeExpression; |
88 | 45523 | jjdelcerro | private String offsetXExpression; |
89 | private String offsetYExpression; |
||
90 | private String rotationExpression; |
||
91 | private String lineToOffsetColorExpression; |
||
92 | 47476 | fdiaz | |
93 | 45527 | jjdelcerro | private transient org.gvsig.fmap.geom.primitive.Point point; |
94 | 45523 | jjdelcerro | |
95 | 45518 | jjdelcerro | public AbstractMarkerSymbol() {
|
96 | super();
|
||
97 | color = MapContextLocator.getSymbolManager() |
||
98 | .getSymbolPreferences() |
||
99 | .getDefaultSymbolFillColor(); |
||
100 | 45527 | jjdelcerro | this.lineToOffsetColor = Color.BLACK; |
101 | try {
|
||
102 | this.point = GEOMETRY_MANAGER.createPoint(0, 0, SUBTYPES.GEOM2D); |
||
103 | } catch (CreateGeometryException ex) {
|
||
104 | 47476 | fdiaz | |
105 | 45527 | jjdelcerro | } |
106 | 45518 | jjdelcerro | } |
107 | 40435 | jjdelcerro | |
108 | 45527 | jjdelcerro | protected org.gvsig.fmap.geom.primitive.Point getPoint(double x, double y) { |
109 | this.point.setX(x);
|
||
110 | this.point.setY(y);
|
||
111 | return this.point; |
||
112 | } |
||
113 | 47476 | fdiaz | |
114 | 45518 | jjdelcerro | @Override
|
115 | public final int getSymbolType() { |
||
116 | return Geometry.TYPES.POINT;
|
||
117 | } |
||
118 | 47476 | fdiaz | |
119 | 45518 | jjdelcerro | @Override
|
120 | public double getRotation() { |
||
121 | 47593 | jjdelcerro | return this.getRotationInDegrees(); |
122 | 45518 | jjdelcerro | } |
123 | 40435 | jjdelcerro | |
124 | 45518 | jjdelcerro | @Override
|
125 | public void setRotation(double r) { |
||
126 | 47593 | jjdelcerro | this.setRotationInDegrees(r);
|
127 | } |
||
128 | |||
129 | public double getRotationInDegrees() { |
||
130 | return rotationDegrees;
|
||
131 | } |
||
132 | |||
133 | public void setRotationInDegrees(double r) { |
||
134 | this.rotationDegrees = r;
|
||
135 | 47464 | fdiaz | this.setRotationExpression(null); |
136 | 45518 | jjdelcerro | } |
137 | 40435 | jjdelcerro | |
138 | 47593 | jjdelcerro | public double getRotationInRadians() { |
139 | return Math.toRadians(rotationDegrees); |
||
140 | } |
||
141 | |||
142 | public void setRotationInRadians(double r) { |
||
143 | this.rotationDegrees = Math.toDegrees(r); |
||
144 | this.setRotationExpression(null); |
||
145 | } |
||
146 | |||
147 | 45518 | jjdelcerro | @Override
|
148 | public Point2D getOffset() { |
||
149 | if (offset == null) { |
||
150 | offset = new Point(); |
||
151 | } |
||
152 | return offset;
|
||
153 | } |
||
154 | 40435 | jjdelcerro | |
155 | 45518 | jjdelcerro | @Override
|
156 | public void setOffset(Point2D offset) { |
||
157 | this.offset = offset;
|
||
158 | } |
||
159 | 40435 | jjdelcerro | |
160 | 45523 | jjdelcerro | private FeatureSymbolTable symbolTable = null; |
161 | 47476 | fdiaz | |
162 | 45527 | jjdelcerro | protected SymbolTable getSymbolTable(Feature f) {
|
163 | 47476 | fdiaz | if (symbolTable == null) { |
164 | 45523 | jjdelcerro | this.symbolTable = DALLocator.getManager().createFeatureSymbolTable();
|
165 | 45528 | jjdelcerro | this.symbolTable.addSymbolTable(ExpressionUtils.createSymbolTable());
|
166 | 45523 | jjdelcerro | } |
167 | symbolTable.setFeature(f); |
||
168 | return symbolTable;
|
||
169 | } |
||
170 | 47476 | fdiaz | |
171 | 45527 | jjdelcerro | @Override
|
172 | public Color getLineToOffsetColor() { |
||
173 | return this.lineToOffsetColor; |
||
174 | } |
||
175 | |||
176 | @Override
|
||
177 | public void setLineToOffsetColor(Color color) { |
||
178 | this.lineToOffsetColor = color;
|
||
179 | } |
||
180 | |||
181 | @Override
|
||
182 | public boolean isDrawLineToOffset() { |
||
183 | return this.drawLineToOffset; |
||
184 | } |
||
185 | |||
186 | @Override
|
||
187 | public void setDrawLineToOffset(boolean drawLineToOffset) { |
||
188 | this.drawLineToOffset = drawLineToOffset;
|
||
189 | } |
||
190 | |||
191 | @Override
|
||
192 | 45523 | jjdelcerro | public String getOffsetXExpression() { |
193 | return offsetXExpression;
|
||
194 | } |
||
195 | |||
196 | 45527 | jjdelcerro | @Override
|
197 | 45523 | jjdelcerro | public void setOffsetXExpression(String offsetXExpression) { |
198 | this.offsetXExpression = StringUtils.trimToNull(offsetXExpression);
|
||
199 | } |
||
200 | |||
201 | 45527 | jjdelcerro | @Override
|
202 | 45523 | jjdelcerro | public String getOffsetYExpression() { |
203 | return offsetYExpression;
|
||
204 | } |
||
205 | |||
206 | 45527 | jjdelcerro | @Override
|
207 | 45523 | jjdelcerro | public void setOffsetYExpression(String offsetYExpression) { |
208 | this.offsetYExpression = StringUtils.trimToNull(offsetYExpression);
|
||
209 | } |
||
210 | |||
211 | 45527 | jjdelcerro | @Override
|
212 | 45523 | jjdelcerro | public String getRotationExpression() { |
213 | return rotationExpression;
|
||
214 | } |
||
215 | |||
216 | 45527 | jjdelcerro | @Override
|
217 | 45523 | jjdelcerro | public void setRotationExpression(String rotationExpression) { |
218 | this.rotationExpression = StringUtils.trimToNull(rotationExpression);
|
||
219 | } |
||
220 | |||
221 | 45527 | jjdelcerro | @Override
|
222 | public String getSizeExpression() { |
||
223 | return sizeExpression;
|
||
224 | 45523 | jjdelcerro | } |
225 | |||
226 | 45527 | jjdelcerro | @Override
|
227 | public void setSizeExpression(String sizeExpression) { |
||
228 | this.sizeExpression = StringUtils.trimToNull(sizeExpression);
|
||
229 | 45523 | jjdelcerro | } |
230 | |||
231 | 45527 | jjdelcerro | @Override
|
232 | 45523 | jjdelcerro | public String getLineToOffsetColorExpression() { |
233 | return this.lineToOffsetColorExpression; |
||
234 | } |
||
235 | |||
236 | 45527 | jjdelcerro | @Override
|
237 | 45523 | jjdelcerro | public void setLineToOffsetColorExpression(String lineToOffsetColorExpression) { |
238 | this.lineToOffsetColorExpression = StringUtils.trimToNull(lineToOffsetColorExpression);
|
||
239 | } |
||
240 | |||
241 | 45527 | jjdelcerro | @Override
|
242 | 45523 | jjdelcerro | public Point2D getEfectiveOffset(Feature f) { |
243 | 47476 | fdiaz | if (f == null) { |
244 | 45527 | jjdelcerro | f = this.getFeature();
|
245 | } |
||
246 | 45529 | fdiaz | Point2D p;
|
247 | 47476 | fdiaz | if (f == null || StringUtils.isBlank(this.offsetXExpression) || StringUtils.isBlank(this.offsetYExpression)) { |
248 | 45529 | fdiaz | p = this.getOffset();
|
249 | p = new Point2D.Double( |
||
250 | 47476 | fdiaz | toCartographicUnits(p.getX()), |
251 | 45529 | fdiaz | toCartographicUnits(p.getY()) |
252 | ); |
||
253 | } else {
|
||
254 | double offsetX = toCartographicUnits(ExpressionUtils.parseDouble(
|
||
255 | 47476 | fdiaz | this.getSymbolTable(f),
|
256 | offsetXExpression, |
||
257 | 45529 | fdiaz | (int) this.getOffset().getX() |
258 | )); |
||
259 | double offsetY = toCartographicUnits(ExpressionUtils.parseDouble(
|
||
260 | 47476 | fdiaz | this.getSymbolTable(f),
|
261 | offsetYExpression, |
||
262 | 45529 | fdiaz | (int) this.getOffset().getY() |
263 | )); |
||
264 | p = new Point2D.Double(offsetX, offsetY); |
||
265 | 45523 | jjdelcerro | } |
266 | return p;
|
||
267 | } |
||
268 | |||
269 | 45527 | jjdelcerro | @Override
|
270 | public double getEfectiveRotationInDegres(Feature f) { |
||
271 | 47476 | fdiaz | if (StringUtils.isBlank(this.rotationExpression)) { |
272 | 47593 | jjdelcerro | return this.getRotationInDegrees(); |
273 | 47464 | fdiaz | } |
274 | 45527 | jjdelcerro | // Por defecto vedra en grados.
|
275 | 47476 | fdiaz | if (f == null) { |
276 | 45527 | jjdelcerro | f = this.getFeature();
|
277 | } |
||
278 | 47476 | fdiaz | if (f == null) { |
279 | 47593 | jjdelcerro | return this.getRotationInDegrees(); |
280 | 45523 | jjdelcerro | } |
281 | 45527 | jjdelcerro | double r = ExpressionUtils.parseDouble(
|
282 | 47476 | fdiaz | this.getSymbolTable(f),
|
283 | rotationExpression, |
||
284 | 47593 | jjdelcerro | this.getRotationInDegrees()
|
285 | 45527 | jjdelcerro | ); |
286 | 45523 | jjdelcerro | return r;
|
287 | } |
||
288 | |||
289 | 45518 | jjdelcerro | @Override
|
290 | 45527 | jjdelcerro | public double getEfectiveRotationInRadians(Feature f) { |
291 | // Pillamos el valor por defecto que es en grados y lo transformamos a radianes.
|
||
292 | 47476 | fdiaz | if (StringUtils.isBlank(this.rotationExpression)) { |
293 | 47593 | jjdelcerro | return this.getRotationInRadians(); |
294 | 47464 | fdiaz | } |
295 | 45527 | jjdelcerro | double r = this.getEfectiveRotationInDegres(f); |
296 | 47476 | fdiaz | if (r == 0) { |
297 | 45527 | jjdelcerro | return 0; |
298 | } |
||
299 | r = Math.toRadians(r);
|
||
300 | return r;
|
||
301 | } |
||
302 | |||
303 | @Override
|
||
304 | public Color getEfectiveLineToOffsetColor(Feature f) { |
||
305 | 47476 | fdiaz | if (f == null) { |
306 | 45527 | jjdelcerro | f = this.getFeature();
|
307 | } |
||
308 | 47476 | fdiaz | if (f == null || StringUtils.isBlank(this.lineToOffsetColorExpression)) { |
309 | 45527 | jjdelcerro | return this.getLineToOffsetColor(); |
310 | } |
||
311 | Color theColor = ExpressionUtils.parseColor(
|
||
312 | 47476 | fdiaz | this.getSymbolTable(f),
|
313 | this.lineToOffsetColorExpression,
|
||
314 | 45527 | jjdelcerro | this.getLineToOffsetColor()
|
315 | ); |
||
316 | return theColor;
|
||
317 | } |
||
318 | |||
319 | @Override
|
||
320 | public double getEfectiveSize(Feature f) { |
||
321 | 47476 | fdiaz | if (StringUtils.isBlank(this.sizeExpression)) { |
322 | return this.getCartographicSize(); |
||
323 | 47464 | fdiaz | } |
324 | 47476 | fdiaz | if (f == null) { |
325 | 45527 | jjdelcerro | f = this.getFeature();
|
326 | } |
||
327 | 47476 | fdiaz | if (f == null) { |
328 | return this.getCartographicSize(); |
||
329 | 45527 | jjdelcerro | } |
330 | double sz = ExpressionUtils.parseDouble(
|
||
331 | 47476 | fdiaz | this.getSymbolTable(f),
|
332 | this.sizeExpression,
|
||
333 | 45529 | fdiaz | -1
|
334 | 45527 | jjdelcerro | ); |
335 | 47476 | fdiaz | if (sz < 0) { |
336 | return this.getCartographicSize(); |
||
337 | 45529 | fdiaz | } |
338 | return toCartographicUnits(sz);
|
||
339 | 45527 | jjdelcerro | } |
340 | |||
341 | @Override
|
||
342 | 45518 | jjdelcerro | public boolean isSuitableFor(Geometry geom) { |
343 | return geom.getType() == Geometry.TYPES.POINT;
|
||
344 | } |
||
345 | 40435 | jjdelcerro | |
346 | 47476 | fdiaz | // @Override
|
347 | // public int getOnePointRgb() {
|
||
348 | // return color.getRGB();
|
||
349 | // }
|
||
350 | 40435 | jjdelcerro | |
351 | 45518 | jjdelcerro | @Override
|
352 | public double getSize() { |
||
353 | return size;
|
||
354 | } |
||
355 | 40435 | jjdelcerro | |
356 | 42811 | jjdelcerro | @Override
|
357 | 45518 | jjdelcerro | public void setSize(double size) { |
358 | this.size = size;
|
||
359 | 47464 | fdiaz | this.setSizeExpression(null); |
360 | 45518 | jjdelcerro | } |
361 | 40435 | jjdelcerro | |
362 | 45518 | jjdelcerro | @Override
|
363 | public Color getColor() { |
||
364 | return color;
|
||
365 | } |
||
366 | 40435 | jjdelcerro | |
367 | 45518 | jjdelcerro | @Override
|
368 | public void setColor(Color color) { |
||
369 | this.color = color;
|
||
370 | } |
||
371 | 40435 | jjdelcerro | |
372 | 45518 | jjdelcerro | @Override
|
373 | public void setAlpha(int outlineAlpha) { |
||
374 | Color theColor = getColor();
|
||
375 | setColor(new Color(theColor.getRed(), theColor.getGreen(), theColor.getBlue(), |
||
376 | outlineAlpha)); |
||
377 | } |
||
378 | 40435 | jjdelcerro | |
379 | 47476 | fdiaz | // @Override
|
380 | // public void getPixExtentPlus(Geometry geom, float[] distances, ViewPort viewPort, int dpi) {
|
||
381 | // setCartographicContext(viewPort, dpi, geom);
|
||
382 | // float cs = (float) getCartographicSize();
|
||
383 | // distances[0] = cs;
|
||
384 | // distances[1] = cs;
|
||
385 | // }
|
||
386 | 40435 | jjdelcerro | |
387 | 45518 | jjdelcerro | @Override
|
388 | public final IMask getMask() { |
||
389 | return mask;
|
||
390 | } |
||
391 | 40435 | jjdelcerro | |
392 | 45518 | jjdelcerro | @Override
|
393 | public final void setMask(IMask mask) { |
||
394 | this.mask = mask;
|
||
395 | } |
||
396 | 40435 | jjdelcerro | |
397 | 47476 | fdiaz | protected double getCartographicSize() { |
398 | return toCartographicUnits(getSize());
|
||
399 | 45518 | jjdelcerro | } |
400 | 40435 | jjdelcerro | |
401 | 45518 | jjdelcerro | @Override
|
402 | public Object clone() throws CloneNotSupportedException { |
||
403 | AbstractMarkerSymbol copy = (AbstractMarkerSymbol) super.clone();
|
||
404 | 40435 | jjdelcerro | |
405 | 45518 | jjdelcerro | // Clone the offset
|
406 | if (offset != null) { |
||
407 | copy.offset = (Point2D) offset.clone();
|
||
408 | } |
||
409 | 40435 | jjdelcerro | |
410 | 45518 | jjdelcerro | // clone the mask
|
411 | if (mask != null) { |
||
412 | copy.mask = (IMask) mask.clone(); |
||
413 | } |
||
414 | return copy;
|
||
415 | } |
||
416 | 40435 | jjdelcerro | |
417 | 45518 | jjdelcerro | @Override
|
418 | public void loadFromState(PersistentState state) |
||
419 | throws PersistenceException {
|
||
420 | // Set parent symbol properties
|
||
421 | super.loadFromState(state);
|
||
422 | // Set own properties
|
||
423 | setColor((Color) state.get(FIELD_COLOR));
|
||
424 | setMask((IMask) state.get(FIELD_MASK)); |
||
425 | setOffset((Point2D) state.get(FIELD_OFFSET));
|
||
426 | setRotation(state.getDouble(FIELD_ROTATION)); |
||
427 | setSize(state.getDouble(FIELD_SIZE)); |
||
428 | 45526 | fdiaz | setDrawLineToOffset(state.getBoolean(FIELD_DRAWLINETOOFFSET, false));
|
429 | 45527 | jjdelcerro | setLineToOffsetColor((Color) state.get(FIELD_LINETOOFFSETCOLOR));
|
430 | 47476 | fdiaz | |
431 | 45527 | jjdelcerro | setSizeExpression(state.getString(FIELD_SIZE_EXPRESSION)); |
432 | 45523 | jjdelcerro | setOffsetXExpression(state.getString(FIELD_OFFSETX_EXPRESSION)); |
433 | setOffsetYExpression(state.getString(FIELD_OFFSETY_EXPRESSION)); |
||
434 | setRotationExpression(state.getString(FIELD_ROTATION_EXPRESSION)); |
||
435 | setLineToOffsetColorExpression(state.getString(FIELD_LINETOOFFSETCOLOR_EXPRESSION)); |
||
436 | 45518 | jjdelcerro | } |
437 | 40435 | jjdelcerro | |
438 | 45518 | jjdelcerro | @Override
|
439 | public void saveToState(PersistentState state) throws PersistenceException { |
||
440 | // Save parent symbol properties
|
||
441 | super.saveToState(state);
|
||
442 | // Save own properties
|
||
443 | state.set(FIELD_COLOR, getColor()); |
||
444 | state.set(FIELD_MASK, getMask()); |
||
445 | state.set(FIELD_OFFSET, getOffset()); |
||
446 | state.set(FIELD_ROTATION, getRotation()); |
||
447 | state.set(FIELD_SIZE, getSize()); |
||
448 | 45527 | jjdelcerro | state.set(FIELD_LINETOOFFSETCOLOR, getLineToOffsetColor()); |
449 | state.set(FIELD_DRAWLINETOOFFSET, isDrawLineToOffset()); |
||
450 | 45523 | jjdelcerro | |
451 | state.set(FIELD_OFFSETX_EXPRESSION, getOffsetXExpression()); |
||
452 | state.set(FIELD_OFFSETY_EXPRESSION, getOffsetYExpression()); |
||
453 | 45527 | jjdelcerro | state.set(FIELD_SIZE_EXPRESSION, getSizeExpression()); |
454 | 45523 | jjdelcerro | state.set(FIELD_ROTATION_EXPRESSION, getRotationExpression()); |
455 | state.set(FIELD_LINETOOFFSETCOLOR_EXPRESSION, getLineToOffsetColorExpression()); |
||
456 | 45518 | jjdelcerro | } |
457 | 40435 | jjdelcerro | |
458 | 45518 | jjdelcerro | public static class RegisterPersistence implements Callable { |
459 | 40435 | jjdelcerro | |
460 | 45518 | jjdelcerro | @Override
|
461 | public Object call() throws Exception { |
||
462 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
463 | if (manager.getDefinition(MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) { |
||
464 | DynStruct definition = manager.addDefinition( |
||
465 | AbstractMarkerSymbol.class, |
||
466 | MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
||
467 | MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
|
||
468 | null,
|
||
469 | null
|
||
470 | ); |
||
471 | 40435 | jjdelcerro | |
472 | 45518 | jjdelcerro | // Extend the Symbol base definition
|
473 | definition.extend(manager.getDefinition(SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
||
474 | 40435 | jjdelcerro | |
475 | 45518 | jjdelcerro | // Color
|
476 | definition.addDynFieldObject(FIELD_COLOR).setMandatory(false).setClassOfValue(Color.class); |
||
477 | // Mask
|
||
478 | definition.addDynFieldObject(FIELD_MASK).setMandatory(false).setClassOfValue(IMask.class);
|
||
479 | 40435 | jjdelcerro | |
480 | 45518 | jjdelcerro | // Offset
|
481 | definition.addDynFieldObject(FIELD_OFFSET).setMandatory(false).setClassOfValue(Point2D.class); |
||
482 | 40435 | jjdelcerro | |
483 | 45518 | jjdelcerro | // Rotation
|
484 | 45526 | fdiaz | definition.addDynFieldDouble(FIELD_ROTATION).setMandatory(false);
|
485 | 40435 | jjdelcerro | |
486 | 45518 | jjdelcerro | // Size
|
487 | 45527 | jjdelcerro | definition.addDynFieldDouble(FIELD_SIZE).setMandatory(false);
|
488 | 45523 | jjdelcerro | |
489 | definition.addDynFieldBoolean(FIELD_DRAWLINETOOFFSET).setMandatory(false);
|
||
490 | 45527 | jjdelcerro | definition.addDynFieldObject(FIELD_LINETOOFFSETCOLOR).setClassOfValue(Color.class).setMandatory(false); |
491 | 47476 | fdiaz | |
492 | 45523 | jjdelcerro | definition.addDynFieldString(FIELD_OFFSETX_EXPRESSION).setMandatory(false);
|
493 | definition.addDynFieldString(FIELD_OFFSETY_EXPRESSION).setMandatory(false);
|
||
494 | definition.addDynFieldString(FIELD_LINETOOFFSETCOLOR_EXPRESSION).setMandatory(false);
|
||
495 | definition.addDynFieldString(FIELD_ROTATION_EXPRESSION).setMandatory(false);
|
||
496 | 45527 | jjdelcerro | definition.addDynFieldString(FIELD_SIZE_EXPRESSION).setMandatory(false);
|
497 | 45518 | jjdelcerro | } |
498 | return true; |
||
499 | } |
||
500 | 40435 | jjdelcerro | |
501 | 45518 | jjdelcerro | } |
502 | |||
503 | 47476 | fdiaz | protected double getAdjustedSize(Rectangle r, double size) { |
504 | if (r == null) { |
||
505 | return size;
|
||
506 | } |
||
507 | double min = Math.min(r.getHeight(), r.getWidth()); |
||
508 | if (size > min) {
|
||
509 | size = min; |
||
510 | } |
||
511 | return size;
|
||
512 | } |
||
513 | |||
514 | protected Geometry getSampleGeometry(Rectangle r) { |
||
515 | GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
516 | try {
|
||
517 | return geomManager.createEnvelope(
|
||
518 | r.x + 1,
|
||
519 | r.y + 1,
|
||
520 | r.x + r.width - 2,
|
||
521 | r.y + r.height - 2,
|
||
522 | Geometry.SUBTYPES.GEOM2D).getGeometry(); |
||
523 | } catch (Exception e) { |
||
524 | throw new RuntimeException("Can't create smple geometry.", e); |
||
525 | } |
||
526 | |||
527 | } |
||
528 | |||
529 | 40435 | jjdelcerro | } |