Revision 45527 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
AbstractMarkerSymbol.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl; |
25 | 25 |
|
26 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol_v2; |
|
26 | 27 |
import java.awt.Color; |
27 | 28 |
import java.awt.Graphics2D; |
28 | 29 |
import java.awt.Point; |
... | ... | |
31 | 32 |
import java.awt.geom.Point2D; |
32 | 33 |
import org.apache.commons.lang3.StringUtils; |
33 | 34 |
import org.gvsig.compat.print.PrintAttributes; |
34 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
35 | 35 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
36 | 36 |
import org.gvsig.expressionevaluator.SymbolTable; |
37 | 37 |
import org.gvsig.fmap.dal.DALLocator; |
... | ... | |
48 | 48 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
49 | 49 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol; |
50 | 50 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
51 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
52 | 51 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
53 | 52 |
import org.gvsig.tools.ToolsLocator; |
54 | 53 |
import org.gvsig.tools.dynobject.DynStruct; |
... | ... | |
63 | 62 |
* @author gvSIG team |
64 | 63 |
*/ |
65 | 64 |
@SuppressWarnings("UseSpecificCatch") |
66 |
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol { |
|
65 |
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol_v2 {
|
|
67 | 66 |
|
68 | 67 |
public static final String MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME = "MarkerSymbol"; |
69 | 68 |
|
... | ... | |
72 | 71 |
private static final String FIELD_OFFSET = "offset"; |
73 | 72 |
private static final String FIELD_SIZE = "size"; |
74 | 73 |
private static final String FIELD_MASK = "mask"; |
74 |
private static final String FIELD_LINETOOFFSETCOLOR = "lineToOffsetColor"; |
|
75 |
private static final String FIELD_DRAWLINETOOFFSET = "drawLineToOffset"; |
|
76 |
private static final String FIELD_SIZE_EXPRESSION = "sizeExpression"; |
|
75 | 77 |
private static final String FIELD_OFFSETX_EXPRESSION = "offsetXExpression"; |
76 | 78 |
private static final String FIELD_OFFSETY_EXPRESSION = "offsetYExpression"; |
77 | 79 |
private static final String FIELD_ROTATION_EXPRESSION = "rotationExpression"; |
78 |
private static final String FIELD_DRAWLINETOOFFSET = "drawLineToOffsetExpression"; |
|
79 | 80 |
private static final String FIELD_LINETOOFFSETCOLOR_EXPRESSION = "lineToOffsetColorExpression"; |
80 | 81 |
|
81 | 82 |
private static final GeometryManager GEOMETRY_MANAGER = GeometryLocator.getGeometryManager(); |
83 |
|
|
82 | 84 |
private Color color; |
83 | 85 |
private double rotation; |
84 | 86 |
private Point2D offset = new Point2D.Double(); |
85 | 87 |
private double size = 4d; |
86 | 88 |
private IMask mask; |
87 | 89 |
|
90 |
private Color lineToOffsetColor; |
|
88 | 91 |
private boolean drawLineToOffset; |
89 | 92 |
|
93 |
private String sizeExpression; |
|
90 | 94 |
private String offsetXExpression; |
91 | 95 |
private String offsetYExpression; |
92 | 96 |
private String rotationExpression; |
93 | 97 |
private String lineToOffsetColorExpression; |
98 |
|
|
99 |
private transient org.gvsig.fmap.geom.primitive.Point point; |
|
94 | 100 |
|
95 | 101 |
public AbstractMarkerSymbol() { |
96 | 102 |
super(); |
97 | 103 |
color = MapContextLocator.getSymbolManager() |
98 | 104 |
.getSymbolPreferences() |
99 | 105 |
.getDefaultSymbolFillColor(); |
106 |
this.lineToOffsetColor = Color.BLACK; |
|
107 |
try { |
|
108 |
this.point = GEOMETRY_MANAGER.createPoint(0, 0, SUBTYPES.GEOM2D); |
|
109 |
} catch (CreateGeometryException ex) { |
|
110 |
|
|
111 |
} |
|
100 | 112 |
} |
101 | 113 |
|
114 |
protected org.gvsig.fmap.geom.primitive.Point getPoint(double x, double y) { |
|
115 |
this.point.setX(x); |
|
116 |
this.point.setY(y); |
|
117 |
return this.point; |
|
118 |
} |
|
119 |
|
|
102 | 120 |
@Override |
103 | 121 |
public final int getSymbolType() { |
104 | 122 |
return Geometry.TYPES.POINT; |
105 | 123 |
} |
106 |
|
|
124 |
|
|
107 | 125 |
@Override |
108 | 126 |
public double getRotation() { |
109 | 127 |
return rotation; |
... | ... | |
129 | 147 |
|
130 | 148 |
private FeatureSymbolTable symbolTable = null; |
131 | 149 |
|
132 |
private SymbolTable getSymbolTable(Feature f) {
|
|
150 |
protected SymbolTable getSymbolTable(Feature f) {
|
|
133 | 151 |
if( symbolTable==null ) { |
134 | 152 |
this.symbolTable = DALLocator.getManager().createFeatureSymbolTable(); |
135 | 153 |
} |
... | ... | |
137 | 155 |
return symbolTable; |
138 | 156 |
} |
139 | 157 |
|
158 |
@Override |
|
159 |
public Color getLineToOffsetColor() { |
|
160 |
return this.lineToOffsetColor; |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public void setLineToOffsetColor(Color color) { |
|
165 |
this.lineToOffsetColor = color; |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public boolean isDrawLineToOffset() { |
|
170 |
return this.drawLineToOffset; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public void setDrawLineToOffset(boolean drawLineToOffset) { |
|
175 |
this.drawLineToOffset = drawLineToOffset; |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
140 | 179 |
public String getOffsetXExpression() { |
141 | 180 |
return offsetXExpression; |
142 | 181 |
} |
143 | 182 |
|
183 |
@Override |
|
144 | 184 |
public void setOffsetXExpression(String offsetXExpression) { |
145 | 185 |
this.offsetXExpression = StringUtils.trimToNull(offsetXExpression); |
146 | 186 |
} |
147 | 187 |
|
188 |
@Override |
|
148 | 189 |
public String getOffsetYExpression() { |
149 | 190 |
return offsetYExpression; |
150 | 191 |
} |
151 | 192 |
|
193 |
@Override |
|
152 | 194 |
public void setOffsetYExpression(String offsetYExpression) { |
153 | 195 |
this.offsetYExpression = StringUtils.trimToNull(offsetYExpression); |
154 | 196 |
} |
155 | 197 |
|
198 |
@Override |
|
156 | 199 |
public String getRotationExpression() { |
157 | 200 |
return rotationExpression; |
158 | 201 |
} |
159 | 202 |
|
203 |
@Override |
|
160 | 204 |
public void setRotationExpression(String rotationExpression) { |
161 | 205 |
this.rotationExpression = StringUtils.trimToNull(rotationExpression); |
162 | 206 |
} |
163 | 207 |
|
164 |
public Color getLineToOffsetColor() { |
|
165 |
return this.getLineToOffsetColor(null); |
|
208 |
@Override |
|
209 |
public String getSizeExpression() { |
|
210 |
return sizeExpression; |
|
166 | 211 |
} |
167 | 212 |
|
168 |
public Color getLineToOffsetColor(Feature f) { |
|
169 |
return ExpressionUtils.parseColor(this.getSymbolTable(f), this.lineToOffsetColorExpression, Color.BLACK); |
|
213 |
@Override |
|
214 |
public void setSizeExpression(String sizeExpression) { |
|
215 |
this.sizeExpression = StringUtils.trimToNull(sizeExpression); |
|
170 | 216 |
} |
171 | 217 |
|
218 |
@Override |
|
172 | 219 |
public String getLineToOffsetColorExpression() { |
173 | 220 |
return this.lineToOffsetColorExpression; |
174 | 221 |
} |
175 | 222 |
|
223 |
@Override |
|
176 | 224 |
public void setLineToOffsetColorExpression(String lineToOffsetColorExpression) { |
177 | 225 |
this.lineToOffsetColorExpression = StringUtils.trimToNull(lineToOffsetColorExpression); |
178 | 226 |
} |
179 | 227 |
|
180 |
public void setLineToOffsetColor(Color lineToOffsetColor) { |
|
181 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
182 |
this.lineToOffsetColorExpression = StringUtils.trimToNull(builder.color(color).toString()); |
|
183 |
} |
|
184 |
|
|
185 |
public boolean isDrawLineToOffset() { |
|
186 |
return this.isDrawLineToOffset(null); |
|
187 |
} |
|
188 |
|
|
189 |
public boolean isDrawLineToOffset(Feature f) { |
|
190 |
return this.drawLineToOffset; |
|
191 |
} |
|
192 |
|
|
193 |
public void setDrawLineToOffset(boolean drawLineToOffset) { |
|
194 |
this.drawLineToOffset = drawLineToOffset; |
|
195 |
} |
|
196 |
|
|
228 |
@Override |
|
197 | 229 |
public Point2D getEfectiveOffset(Feature f) { |
230 |
if( f == null ) { |
|
231 |
f = this.getFeature(); |
|
232 |
} |
|
198 | 233 |
if( f==null || StringUtils.isBlank(this.offsetXExpression) || StringUtils.isBlank(this.offsetYExpression) ) { |
199 | 234 |
return this.getOffset(); |
200 | 235 |
} |
201 |
int offsetX = ExpressionUtils.parseInt(this.getSymbolTable(f), offsetXExpression, (int) this.getOffset().getX()); |
|
202 |
int offsetY = ExpressionUtils.parseInt(this.getSymbolTable(f), offsetYExpression, (int) this.getOffset().getY()); |
|
236 |
int offsetX = ExpressionUtils.parseInt( |
|
237 |
this.getSymbolTable(f), |
|
238 |
offsetXExpression, |
|
239 |
(int) this.getOffset().getX() |
|
240 |
); |
|
241 |
int offsetY = ExpressionUtils.parseInt( |
|
242 |
this.getSymbolTable(f), |
|
243 |
offsetYExpression, |
|
244 |
(int) this.getOffset().getY() |
|
245 |
); |
|
203 | 246 |
Point p = new Point(offsetX, offsetY); |
204 | 247 |
return p; |
205 | 248 |
} |
206 | 249 |
|
207 |
public double getEfectiveRotation(Feature f) { |
|
250 |
@Override |
|
251 |
public double getEfectiveRotationInDegres(Feature f) { |
|
252 |
// Por defecto vedra en grados. |
|
253 |
if( f == null ) { |
|
254 |
f = this.getFeature(); |
|
255 |
} |
|
208 | 256 |
if( f==null || StringUtils.isBlank(this.rotationExpression) ) { |
209 | 257 |
return this.getRotation(); |
210 | 258 |
} |
211 |
double r = ExpressionUtils.parseDouble(this.getSymbolTable(f), rotationExpression, this.getRotation()); |
|
259 |
double r = ExpressionUtils.parseDouble( |
|
260 |
this.getSymbolTable(f), |
|
261 |
rotationExpression, |
|
262 |
this.getRotation() |
|
263 |
); |
|
212 | 264 |
return r; |
213 | 265 |
} |
214 | 266 |
|
215 | 267 |
@Override |
268 |
public double getEfectiveRotationInRadians(Feature f) { |
|
269 |
// Pillamos el valor por defecto que es en grados y lo transformamos a radianes. |
|
270 |
double r = this.getEfectiveRotationInDegres(f); |
|
271 |
if( r == 0 ) { |
|
272 |
return 0; |
|
273 |
} |
|
274 |
r = Math.toRadians(r); |
|
275 |
return r; |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public Color getEfectiveLineToOffsetColor(Feature f) { |
|
280 |
if( f == null ) { |
|
281 |
f = this.getFeature(); |
|
282 |
} |
|
283 |
if( f==null || StringUtils.isBlank(this.lineToOffsetColorExpression) ) { |
|
284 |
return this.getLineToOffsetColor(); |
|
285 |
} |
|
286 |
Color theColor = ExpressionUtils.parseColor( |
|
287 |
this.getSymbolTable(f), |
|
288 |
this.lineToOffsetColorExpression, |
|
289 |
this.getLineToOffsetColor() |
|
290 |
); |
|
291 |
return theColor; |
|
292 |
} |
|
293 |
|
|
294 |
@Override |
|
295 |
public double getEfectiveSize(Feature f) { |
|
296 |
if( f == null ) { |
|
297 |
f = this.getFeature(); |
|
298 |
} |
|
299 |
if( f==null || StringUtils.isBlank(this.sizeExpression) ) { |
|
300 |
return this.getSize(); |
|
301 |
} |
|
302 |
double sz = ExpressionUtils.parseDouble( |
|
303 |
this.getSymbolTable(f), |
|
304 |
this.sizeExpression, |
|
305 |
this.getSize() |
|
306 |
); |
|
307 |
return sz; |
|
308 |
} |
|
309 |
|
|
310 |
@Override |
|
216 | 311 |
public boolean isSuitableFor(Geometry geom) { |
217 | 312 |
return geom.getType() == Geometry.TYPES.POINT; |
218 | 313 |
} |
... | ... | |
258 | 353 |
|
259 | 354 |
@Override |
260 | 355 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintAttributes properties) { |
261 |
double originalSize = getSize();
|
|
356 |
double originalSize = getEfectiveSize(getFeature());
|
|
262 | 357 |
double theSize = originalSize; |
263 | 358 |
// scale it to size |
264 | 359 |
int pq = properties.getPrintQuality(); |
... | ... | |
276 | 371 |
break; |
277 | 372 |
} |
278 | 373 |
// setSize(theSize); |
279 |
draw(g, at, geom, null, null);
|
|
374 |
draw(g, at, geom, getFeature(), null);
|
|
280 | 375 |
// setSize(originalSize); |
281 | 376 |
} |
282 | 377 |
|
... | ... | |
289 | 384 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException { |
290 | 385 |
try { |
291 | 386 |
if (properties == null) { |
292 |
draw(g, scaleInstance, GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null, null); |
|
387 |
draw( |
|
388 |
g, |
|
389 |
scaleInstance, |
|
390 |
this.getPoint(r.getCenterX(), r.getCenterY()), |
|
391 |
// GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), |
|
392 |
this.getFeature(), |
|
393 |
null |
|
394 |
); |
|
293 | 395 |
} else { |
294 |
double originalSize = getSize();
|
|
396 |
double originalSize = getEfectiveSize(getFeature());
|
|
295 | 397 |
double theSize = originalSize; |
296 | 398 |
int pq = properties.getPrintQuality(); |
297 | 399 |
switch (pq) { |
... | ... | |
308 | 410 |
break; |
309 | 411 |
} |
310 | 412 |
setSize(theSize); |
311 |
print(g, scaleInstance, GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties); |
|
413 |
print( |
|
414 |
g, |
|
415 |
scaleInstance, |
|
416 |
this.getPoint(r.getCenterX(), r.getCenterY()), |
|
417 |
// GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), |
|
418 |
properties |
|
419 |
); |
|
312 | 420 |
setSize(originalSize); |
313 | 421 |
} |
314 | 422 |
|
315 |
} catch (CreateGeometryException e) {
|
|
423 |
} catch (Exception e) { |
|
316 | 424 |
throw new SymbolDrawingException(TYPES.POINT); |
317 | 425 |
} |
318 | 426 |
} |
... | ... | |
329 | 437 |
|
330 | 438 |
@Override |
331 | 439 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
332 |
double oldSize = getSize();
|
|
440 |
double oldSize = getEfectiveSize(getFeature());
|
|
333 | 441 |
setCartographicSize(getCartographicSize( |
334 | 442 |
viewPort, |
335 | 443 |
dpi, |
... | ... | |
374 | 482 |
setOffset((Point2D) state.get(FIELD_OFFSET)); |
375 | 483 |
setRotation(state.getDouble(FIELD_ROTATION)); |
376 | 484 |
setSize(state.getDouble(FIELD_SIZE)); |
377 |
|
|
378 | 485 |
setDrawLineToOffset(state.getBoolean(FIELD_DRAWLINETOOFFSET, false)); |
486 |
setLineToOffsetColor((Color) state.get(FIELD_LINETOOFFSETCOLOR)); |
|
487 |
|
|
488 |
setSizeExpression(state.getString(FIELD_SIZE_EXPRESSION)); |
|
379 | 489 |
setOffsetXExpression(state.getString(FIELD_OFFSETX_EXPRESSION)); |
380 | 490 |
setOffsetYExpression(state.getString(FIELD_OFFSETY_EXPRESSION)); |
381 | 491 |
setRotationExpression(state.getString(FIELD_ROTATION_EXPRESSION)); |
... | ... | |
392 | 502 |
state.set(FIELD_OFFSET, getOffset()); |
393 | 503 |
state.set(FIELD_ROTATION, getRotation()); |
394 | 504 |
state.set(FIELD_SIZE, getSize()); |
505 |
state.set(FIELD_LINETOOFFSETCOLOR, getLineToOffsetColor()); |
|
506 |
state.set(FIELD_DRAWLINETOOFFSET, isDrawLineToOffset()); |
|
395 | 507 |
|
396 | 508 |
state.set(FIELD_OFFSETX_EXPRESSION, getOffsetXExpression()); |
397 | 509 |
state.set(FIELD_OFFSETY_EXPRESSION, getOffsetYExpression()); |
510 |
state.set(FIELD_SIZE_EXPRESSION, getSizeExpression()); |
|
398 | 511 |
state.set(FIELD_ROTATION_EXPRESSION, getRotationExpression()); |
399 |
state.set(FIELD_DRAWLINETOOFFSET, isDrawLineToOffset()); |
|
400 | 512 |
state.set(FIELD_LINETOOFFSETCOLOR_EXPRESSION, getLineToOffsetColorExpression()); |
401 | 513 |
} |
402 | 514 |
|
... | ... | |
429 | 541 |
definition.addDynFieldDouble(FIELD_ROTATION).setMandatory(false); |
430 | 542 |
|
431 | 543 |
// Size |
432 |
definition.addDynFieldDouble(FIELD_SIZE).setMandatory(true);
|
|
544 |
definition.addDynFieldDouble(FIELD_SIZE).setMandatory(false);
|
|
433 | 545 |
|
434 | 546 |
|
435 | 547 |
definition.addDynFieldBoolean(FIELD_DRAWLINETOOFFSET).setMandatory(false); |
548 |
definition.addDynFieldObject(FIELD_LINETOOFFSETCOLOR).setClassOfValue(Color.class).setMandatory(false); |
|
549 |
|
|
436 | 550 |
definition.addDynFieldString(FIELD_OFFSETX_EXPRESSION).setMandatory(false); |
437 | 551 |
definition.addDynFieldString(FIELD_OFFSETY_EXPRESSION).setMandatory(false); |
438 | 552 |
definition.addDynFieldString(FIELD_LINETOOFFSETCOLOR_EXPRESSION).setMandatory(false); |
439 | 553 |
definition.addDynFieldString(FIELD_ROTATION_EXPRESSION).setMandatory(false); |
554 |
definition.addDynFieldString(FIELD_SIZE_EXPRESSION).setMandatory(false); |
|
440 | 555 |
} |
441 | 556 |
return true; |
442 | 557 |
} |
Also available in: Unified diff