Revision 44249
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/impl/DefaultSymbologyManager.java | ||
---|---|---|
70 | 70 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicSymbol; |
71 | 71 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicLabelingStrategy; |
72 | 72 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicVectorLegend; |
73 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicLabelingStrategy;
|
|
73 |
import org.gvsig.labeling.dynamiclabeling.DynamicLabelingStrategy;
|
|
74 | 74 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicSymbol; |
75 | 75 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicVectorLegend; |
76 | 76 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendWriter; |
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/LabelingFactory.java | ||
---|---|---|
73 | 73 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
74 | 74 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
75 | 75 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
76 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicLabelingStrategy; |
|
77 |
import org.gvsig.labeling.dynamiclabeling.DynamicLabelingStrategy; |
|
76 | 78 |
import org.slf4j.Logger; |
77 | 79 |
import org.slf4j.LoggerFactory; |
78 | 80 |
|
... | ... | |
107 | 109 |
|
108 | 110 |
} |
109 | 111 |
|
112 |
public static DynamicLabelingStrategy createDynamicLabelingStrategy() { |
|
113 |
return new DefaultDynamicLabelingStrategy(); |
|
114 |
} |
|
115 |
|
|
110 | 116 |
/** |
111 | 117 |
* Creates a default labeling strategy from an XMLEntity. |
112 | 118 |
* @param layer |
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/impl/AbstractVectorialLegend.java | ||
---|---|---|
159 | 159 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
160 | 160 |
FeatureStore featureStore, FeatureQuery fquery, PrintAttributes properties) |
161 | 161 |
throws LegendException { |
162 |
|
|
162 | 163 |
double dpi = 72; |
163 | 164 |
|
164 | 165 |
int resolution = properties.getPrintQuality(); |
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/dynamiclegend/DefaultDynamicLabelingStrategy.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend; |
7 | 7 |
|
8 |
import org.gvsig.labeling.dynamiclabeling.DynamicLabelingStrategy; |
|
8 | 9 |
import java.awt.Color; |
9 | 10 |
import java.awt.Font; |
10 | 11 |
import java.awt.Graphics2D; |
11 | 12 |
import java.awt.image.BufferedImage; |
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
import org.cresques.cts.ICoordTrans; |
|
16 |
import org.cresques.cts.IProjection; |
|
12 | 17 |
import org.gvsig.compat.print.PrintAttributes; |
18 |
import org.gvsig.expressionevaluator.Expression; |
|
19 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
20 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
21 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
22 |
import org.gvsig.fmap.dal.DALLocator; |
|
13 | 23 |
import org.gvsig.fmap.dal.exception.ReadException; |
24 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
25 |
import org.gvsig.fmap.dal.feature.Feature; |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
27 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
28 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
14 | 30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
34 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
35 |
import org.gvsig.fmap.geom.primitive.Point; |
|
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
15 | 37 |
import org.gvsig.fmap.mapcontext.ViewPort; |
16 | 38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
40 |
import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory; |
|
17 | 41 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
18 | 42 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
19 | 43 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
20 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
|
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy; |
|
45 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy.MIN_TEXT_SIZE; |
|
46 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
|
47 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol; |
|
48 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
49 |
import org.gvsig.tools.evaluator.Evaluator; |
|
50 |
import org.gvsig.tools.exception.BaseException; |
|
21 | 51 |
import org.gvsig.tools.persistence.PersistentState; |
22 | 52 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
23 | 53 |
import org.gvsig.tools.task.Cancellable; |
54 |
import org.slf4j.Logger; |
|
55 |
import org.slf4j.LoggerFactory; |
|
24 | 56 |
|
25 | 57 |
/** |
26 | 58 |
* |
... | ... | |
28 | 60 |
*/ |
29 | 61 |
public class DefaultDynamicLabelingStrategy extends DynamicLabelingStrategy { |
30 | 62 |
|
31 |
public DefaultDynamicLabelingStrategy() { |
|
32 |
super(); |
|
63 |
private Feature feature; |
|
64 |
public String LROTATION = "LROTATION"; |
|
65 |
public String LTEXT = "LTEXT"; |
|
66 |
public String LHEIGHT = "LHEIGHT"; |
|
67 |
public String LCOLOR = "LCOLOR"; |
|
68 |
public String LFONT = "LFONT"; |
|
69 |
public String LFONTSTYLE = "LFONTS"; |
|
70 |
private MutableSymbolTable symbolTable = null; |
|
71 |
private FLyrVect layer; |
|
72 |
private List<Geometry> drawnGeometryLabels; |
|
73 |
private boolean printMode = false; |
|
74 |
private IZoomConstraints zoom = null; |
|
75 |
private static final Logger logger = LoggerFactory.getLogger(AttrInTableLabelingStrategy.class); |
|
76 |
private int referenceSystem; |
|
77 |
private String textField; |
|
78 |
|
|
79 |
public SymbolTable getFeatureSymbolTable() { |
|
80 |
if (symbolTable == null) { |
|
81 |
MutableSymbolTable s = ExpressionEvaluatorLocator.getManager().createSymbolTable(); |
|
82 |
FeatureSymbolTable fst = DALLocator.getDataManager().createFeatureSymbolTable(); |
|
83 |
s.addSymbolTable(fst); |
|
84 |
fst.setFeature(feature); |
|
85 |
symbolTable = s; |
|
86 |
} |
|
87 |
return symbolTable; |
|
88 |
|
|
33 | 89 |
} |
34 | 90 |
|
91 |
private Expression getExpressionFromString(String value) { |
|
92 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
93 |
expression.setPhrase(value); |
|
94 |
return expression; |
|
95 |
} |
|
96 |
|
|
97 |
private Object getValueFromExpression(Expression exp) { |
|
98 |
if (exp == null) { |
|
99 |
return null; |
|
100 |
} |
|
101 |
Object value = exp.execute(getFeatureSymbolTable()); |
|
102 |
return value; |
|
103 |
} |
|
104 |
|
|
105 |
public Object getComputedValue(String field) { |
|
106 |
Object value; |
|
107 |
value = feature.get(field); |
|
108 |
|
|
109 |
return value; |
|
110 |
} |
|
111 |
|
|
35 | 112 |
@Override |
36 |
public String getRotation() { |
|
37 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
113 |
public Expression getRotation() { |
|
114 |
String value = feature.get(LROTATION).toString(); |
|
115 |
Expression exp = getExpressionFromString(value); |
|
116 |
return exp; |
|
38 | 117 |
} |
39 | 118 |
|
40 | 119 |
@Override |
41 |
public String getText() { |
|
42 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
120 |
public int getComputedRotation() { |
|
121 |
Integer value = (Integer) getValueFromExpression(getRotation()); |
|
122 |
return value; |
|
43 | 123 |
} |
44 | 124 |
|
45 | 125 |
@Override |
46 |
public String getHeight() { |
|
47 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
126 |
public Expression getText() { |
|
127 |
if (feature == null) { |
|
128 |
return null; |
|
129 |
} |
|
130 |
String value = feature.get(LTEXT).toString(); |
|
131 |
Expression exp = getExpressionFromString(value); |
|
132 |
return exp; |
|
48 | 133 |
} |
49 | 134 |
|
50 | 135 |
@Override |
51 |
public String getColor() { |
|
52 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
136 |
public String getComputedText() { |
|
137 |
String value = (String) getValueFromExpression(getText()); |
|
138 |
return value; |
|
53 | 139 |
} |
54 | 140 |
|
55 | 141 |
@Override |
56 |
public double getFixedSize() { |
|
57 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
142 |
public Expression getHeight() { |
|
143 |
String value = feature.get(LHEIGHT).toString(); |
|
144 |
Expression exp = getExpressionFromString(value); |
|
145 |
return exp; |
|
58 | 146 |
} |
59 | 147 |
|
60 | 148 |
@Override |
149 |
public int getComputedHeight() { |
|
150 |
int value = (int) getValueFromExpression(getHeight()); |
|
151 |
return value; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public Expression getColor() { |
|
156 |
String value = feature.get(LCOLOR).toString(); |
|
157 |
Expression exp = getExpressionFromString(value); |
|
158 |
return exp; |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public Color getComputedColor() { |
|
163 |
int rgbcolor = (int) getColor().execute(getFeatureSymbolTable()); |
|
164 |
Color color = new Color(rgbcolor, true); |
|
165 |
return color; |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public Expression getFixedSize() { |
|
170 |
String value = feature.get(LHEIGHT).toString(); |
|
171 |
Expression exp = getExpressionFromString(value); |
|
172 |
return exp; |
|
173 |
} |
|
174 |
|
|
175 |
@Override |
|
176 |
public double getComputedFixedSize() { |
|
177 |
double value = (double) getValueFromExpression(getFixedSize()); |
|
178 |
return value; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public int getComputedUnit() { |
|
183 |
int value = (int) getValueFromExpression(getUnitExp()); |
|
184 |
return value; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
61 | 188 |
public void setTextField(String textFieldName) { |
62 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
189 |
this.LTEXT=textFieldName;
|
|
63 | 190 |
} |
64 | 191 |
|
65 | 192 |
@Override |
66 | 193 |
public void setRotationField(String rotationFieldName) { |
67 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
194 |
this.LROTATION=rotationFieldName;
|
|
68 | 195 |
} |
69 | 196 |
|
70 | 197 |
@Override |
71 | 198 |
public void setHeightField(String heightFieldName) { |
72 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
199 |
this.LHEIGHT=heightFieldName;
|
|
73 | 200 |
} |
74 | 201 |
|
75 | 202 |
@Override |
76 | 203 |
public void setColorField(String colorFieldName) { |
77 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
204 |
this.LCOLOR=colorFieldName;
|
|
78 | 205 |
} |
79 | 206 |
|
80 | 207 |
@Override |
... | ... | |
84 | 211 |
|
85 | 212 |
@Override |
86 | 213 |
public boolean usesFixedSize() { |
87 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
214 |
return false;
|
|
88 | 215 |
} |
89 | 216 |
|
90 | 217 |
@Override |
... | ... | |
99 | 226 |
|
100 | 227 |
@Override |
101 | 228 |
public boolean usesFixedColor() { |
102 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
229 |
return true;
|
|
103 | 230 |
} |
104 | 231 |
|
105 | 232 |
@Override |
106 |
public Color getFixedColor() { |
|
107 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
233 |
public Expression getFixedColor() { |
|
234 |
String value = feature.get(LCOLOR).toString(); |
|
235 |
Expression exp = getExpressionFromString(value); |
|
236 |
return exp; |
|
108 | 237 |
} |
109 | 238 |
|
110 | 239 |
@Override |
240 |
public Color getComputedFixedColor() { |
|
241 |
int rgbcolor = (int) getFixedColor().execute(getFeatureSymbolTable()); |
|
242 |
Color color = new Color(rgbcolor, true); |
|
243 |
return color; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
111 | 247 |
public void setFixedColor(Color fixedColor) { |
112 | 248 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
113 | 249 |
} |
114 | 250 |
|
115 | 251 |
@Override |
116 |
public Color getColorFont() { |
|
117 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
252 |
public Expression getColorFont() { |
|
253 |
String value = feature.get(LCOLOR).toString(); |
|
254 |
Expression exp = getExpressionFromString(value); |
|
255 |
return exp; |
|
118 | 256 |
} |
119 | 257 |
|
120 | 258 |
@Override |
259 |
public Color getComputedColorFont() { |
|
260 |
int rgbcolor = (int) getColorFont().execute(getFeatureSymbolTable()); |
|
261 |
Color color = new Color(rgbcolor, true); |
|
262 |
return color; |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
121 | 266 |
public void setColorFont(Color colorFont) { |
122 | 267 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
123 | 268 |
} |
124 | 269 |
|
125 | 270 |
@Override |
126 |
public Font getFont() { |
|
127 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
271 |
public Expression getFont() { |
|
272 |
String value = feature.get(LFONT).toString(); |
|
273 |
Expression exp = getExpressionFromString(value); |
|
274 |
return exp; |
|
128 | 275 |
} |
129 | 276 |
|
130 | 277 |
@Override |
278 |
public Font getComputedFont() { |
|
279 |
String value = (String) getFont().execute(getFeatureSymbolTable()); |
|
280 |
Font font = new Font(value, getComputedFontStyle(), getComputedHeight()); |
|
281 |
return font; |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
131 | 285 |
public void setFont(Font selFont) { |
132 | 286 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
133 | 287 |
} |
134 | 288 |
|
289 |
@Override |
|
290 |
public Expression getFontStyle() { |
|
291 |
String value = feature.get(LFONTSTYLE).toString(); |
|
292 |
Expression exp = getExpressionFromString(value); |
|
293 |
return exp; |
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
297 |
public int getComputedFontStyle() { |
|
298 |
int value = (int) getFontStyle().execute(getFeatureSymbolTable()); |
|
299 |
return value; |
|
300 |
} |
|
301 |
|
|
302 |
@Override |
|
303 |
public void setFontStyle(int selFont) { |
|
304 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
305 |
} |
|
306 |
|
|
307 |
public void setFeature(Feature f) { |
|
308 |
feature = f; |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public ILabelingMethod getLabelingMethod() { |
|
313 |
throw new UnsupportedOperationException("Not supported yet."); |
|
314 |
} |
|
315 |
|
|
316 |
@Override |
|
317 |
public void setLabelingMethod(ILabelingMethod method) { |
|
318 |
throw new UnsupportedOperationException("Not supported yet."); |
|
319 |
} |
|
320 |
|
|
321 |
@Override |
|
322 |
public IPlacementConstraints getPlacementConstraints() { |
|
323 |
throw new UnsupportedOperationException("Not supported yet."); |
|
324 |
} |
|
325 |
|
|
326 |
@Override |
|
327 |
public void setPlacementConstraints(IPlacementConstraints constraints) { |
|
328 |
throw new UnsupportedOperationException("Not supported yet."); |
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public IZoomConstraints getZoomConstraints() { |
|
333 |
throw new UnsupportedOperationException("Not supported yet."); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
public void setZoomConstraints(IZoomConstraints constraints) { |
|
338 |
throw new UnsupportedOperationException("Not supported yet."); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public Expression getUnitExp() { |
|
343 |
String value = "-1"; |
|
344 |
Expression exp = getExpressionFromString(value); |
|
345 |
return exp; |
|
346 |
} |
|
347 |
|
|
348 |
public Expression getReferenceSystemExp() { |
|
349 |
String value = "0"; |
|
350 |
Expression exp = getExpressionFromString(value); |
|
351 |
return exp; |
|
352 |
} |
|
353 |
|
|
354 |
private org.gvsig.fmap.geom.primitive.Point createLabelPoint(org.gvsig.fmap.geom.Geometry geom) |
|
355 |
throws CreateGeometryException { |
|
356 |
|
|
357 |
try { |
|
358 |
return geom.centroid(); |
|
359 |
} catch (GeometryOperationNotSupportedException e) { |
|
360 |
return null; |
|
361 |
} catch (GeometryOperationException e) { |
|
362 |
return null; |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
366 |
@Override |
|
367 |
public void draw(BufferedImage mapImage, Graphics2D mapGraphics, double scale, ViewPort viewPort, Cancellable cancel, double dpi) throws ReadException { |
|
368 |
// double scale = getScale(viewPort, props); |
|
369 |
PrintAttributes props = null; |
|
370 |
if (layer == null) { |
|
371 |
return; |
|
372 |
} |
|
373 |
|
|
374 |
if (zoom == null |
|
375 |
|| (zoom.isUserDefined() && (scale >= zoom.getMaxScale()) |
|
376 |
&& (scale <= zoom.getMinScale()))) { |
|
377 |
FeatureSet set = null; |
|
378 |
DisposableIterator iterator = null; |
|
379 |
try { |
|
380 |
// AttrInTableLabelingStrategy.FilteredLogger logger = new AttrInTableLabelingStrategy.FilteredLogger(AttrInTableLabelingStrategy.logger, 10); |
|
381 |
|
|
382 |
// limit the labeling to the visible extent |
|
383 |
List<String> fields = new ArrayList<String>(); |
|
384 |
|
|
385 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
386 |
ICoordTrans ct = layer.getCoordTrans(); |
|
387 |
|
|
388 |
String geomName = featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(); |
|
389 |
fields.add(LCOLOR); |
|
390 |
fields.add(LFONT); |
|
391 |
fields.add(LFONTSTYLE); |
|
392 |
fields.add(LHEIGHT); |
|
393 |
fields.add(LROTATION); |
|
394 |
fields.add(LTEXT); |
|
395 |
fields.add(geomName); |
|
396 |
|
|
397 |
FeatureQuery featureQuery = layer.createFeatureQuery(); |
|
398 |
|
|
399 |
if (viewPort.getAdjustedEnvelope().contains( |
|
400 |
layer.getFullEnvelope())) { |
|
401 |
/* |
|
402 |
* viewport contains layer completely |
|
403 |
*/ |
|
404 |
set = featureStore.getFeatureSet(featureQuery); |
|
405 |
} else { |
|
406 |
/* |
|
407 |
* view port does not contain layer completely |
|
408 |
*/ |
|
409 |
Evaluator iee = null; |
|
410 |
|
|
411 |
IProjection data_proj = null; |
|
412 |
Envelope env_in_store_crs = null; |
|
413 |
|
|
414 |
if (ct == null) { |
|
415 |
env_in_store_crs = viewPort.getAdjustedEnvelope(); |
|
416 |
data_proj = viewPort.getProjection(); |
|
417 |
} else { |
|
418 |
env_in_store_crs = viewPort.getAdjustedEnvelope().convert( |
|
419 |
ct.getInverted()); |
|
420 |
data_proj = ct.getPOrig(); |
|
421 |
} |
|
422 |
iee = SpatialEvaluatorsFactory.getInstance().intersects( |
|
423 |
env_in_store_crs, |
|
424 |
data_proj, |
|
425 |
featureStore |
|
426 |
); |
|
427 |
featureQuery.setAttributeNames((String[]) fields.toArray(new String[fields.size()])); |
|
428 |
featureQuery.setFilter(iee); |
|
429 |
set = featureStore.getFeatureSet(featureQuery); |
|
430 |
} |
|
431 |
|
|
432 |
/* |
|
433 |
* 'set' now has the features that have to be labeled |
|
434 |
*/ |
|
435 |
FeatureSelection selection = this.layer.getFeatureStore().getFeatureSelection(); |
|
436 |
iterator = set.fastIterator(); |
|
437 |
while (iterator.hasNext()) { |
|
438 |
if (cancel.isCanceled()) { |
|
439 |
return; |
|
440 |
} |
|
441 |
try { |
|
442 |
Feature feat = (Feature) iterator.next(); |
|
443 |
Geometry geom = feat.getDefaultGeometry(); |
|
444 |
if (geom == null) { |
|
445 |
continue; |
|
446 |
} |
|
447 |
|
|
448 |
double size = 0; |
|
449 |
Color color = null; |
|
450 |
this.setFeature(feat); |
|
451 |
if ("".equals(getComputedText())) { |
|
452 |
continue; |
|
453 |
} else if (getComputedText() == null) { |
|
454 |
continue; |
|
455 |
} |
|
456 |
|
|
457 |
SimpleTextSymbol sym = new SimpleTextSymbol(); |
|
458 |
sym.setFont(getComputedFont()); |
|
459 |
sym.setUnit(getComputedUnit()); |
|
460 |
sym.setReferenceSystem(getComputedReferenceSystemExp()); |
|
461 |
if (this.usesFixedSize()) { //(useFixedSize) { |
|
462 |
// uses fixed size |
|
463 |
size = getComputedFixedSize();// * fontScaleFactor; |
|
464 |
} else if (true) { //(getComputedHeight() ) { |
|
465 |
// text size is defined in the table |
|
466 |
size = getComputedHeight(); |
|
467 |
} else { |
|
468 |
// otherwise will use the size in the symbol |
|
469 |
size = sym.getFont().getSize(); |
|
470 |
} |
|
471 |
|
|
472 |
double the_dpi = viewPort.getDPI(); |
|
473 |
if (props != null) { |
|
474 |
int len = PrintAttributes.PRINT_QUALITY_DPI.length; |
|
475 |
int priq = props.getPrintQuality(); |
|
476 |
if (priq < 0 || priq >= len) { |
|
477 |
throw new ReadException(featureStore.getName(), |
|
478 |
new Exception("Bad print quality value: " + priq)); |
|
479 |
} else { |
|
480 |
the_dpi = PrintAttributes.PRINT_QUALITY_DPI[priq]; |
|
481 |
} |
|
482 |
} |
|
483 |
|
|
484 |
size = CartographicSupportToolkit.getCartographicLength(this, |
|
485 |
size, |
|
486 |
viewPort, |
|
487 |
the_dpi); |
|
488 |
if (size <= MIN_TEXT_SIZE) { |
|
489 |
// label is too small to be readable, will be skipped |
|
490 |
// this speeds up the rendering in wider zooms |
|
491 |
continue; |
|
492 |
} |
|
493 |
|
|
494 |
/* |
|
495 |
* ym.setFontSize(int) assumes dpi = 72 |
|
496 |
*/ |
|
497 |
double font_size = size * 72 / the_dpi; |
|
498 |
sym.setFontSize(font_size); |
|
499 |
|
|
500 |
// if (false) { //useFixedColor) { |
|
501 |
// color = getComputedFixedColor(); |
|
502 |
// } else if (true) { //colorFieldName != null) { |
|
503 |
// // text size is defined in the table |
|
504 |
if (selection.isSelected(feat)) { |
|
505 |
color = MapContext.getSelectionColor(); |
|
506 |
} else { |
|
507 |
color = getComputedColorFont(); |
|
508 |
} |
|
509 |
|
|
510 |
sym.setTextColor(color); |
|
511 |
|
|
512 |
if (ct != null) { |
|
513 |
/* |
|
514 |
* Reproject from store CRS to view CRS |
|
515 |
*/ |
|
516 |
geom = geom.cloneGeometry(); |
|
517 |
geom.reProject(ct); |
|
518 |
} |
|
519 |
|
|
520 |
Point p = null; |
|
521 |
// text rotation is defined in the table |
|
522 |
double rotation = -Math.toRadians(((Number) getComputedRotation()).doubleValue()); |
|
523 |
p = createLabelPoint(geom); |
|
524 |
|
|
525 |
sym.setText(getComputedText()); |
|
526 |
sym.setRotation(rotation); |
|
527 |
|
|
528 |
if (p != null) { |
|
529 |
if (props == null) { |
|
530 |
sym.draw(mapGraphics, viewPort.getAffineTransform(), p, feat, cancel); |
|
531 |
} else { |
|
532 |
sym.print(mapGraphics, viewPort.getAffineTransform(), p, props); |
|
533 |
} |
|
534 |
} |
|
535 |
} catch (Exception ex) { |
|
536 |
logger.warn("", ex); |
|
537 |
} |
|
538 |
} |
|
539 |
|
|
540 |
} catch (BaseException e) { |
|
541 |
throw new ReadException( |
|
542 |
"Could not draw annotation in the layer.", e); |
|
543 |
} finally { |
|
544 |
if (iterator != null) { |
|
545 |
iterator.dispose(); |
|
546 |
} |
|
547 |
if (set != null) { |
|
548 |
set.dispose(); |
|
549 |
} |
|
550 |
|
|
551 |
} |
|
552 |
|
|
553 |
} |
|
554 |
|
|
555 |
} |
|
556 |
|
|
557 |
@Override |
|
558 |
public void print(Graphics2D g, double scale, ViewPort viewPort, Cancellable cancel, PrintAttributes properties) throws ReadException { |
|
559 |
throw new UnsupportedOperationException("Not supported yet."); |
|
560 |
} |
|
561 |
|
|
562 |
@Override |
|
563 |
public String[] getUsedFields() { |
|
564 |
throw new UnsupportedOperationException("Not supported yet."); |
|
565 |
} |
|
566 |
|
|
567 |
@Override |
|
568 |
public void setLayer(FLayer flayer) { |
|
569 |
layer = (FLyrVect) flayer; |
|
570 |
} |
|
571 |
|
|
572 |
@Override |
|
573 |
public boolean shouldDrawLabels(double scale) { |
|
574 |
return true; |
|
575 |
} |
|
576 |
|
|
577 |
@Override |
|
578 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
579 |
throw new UnsupportedOperationException("Not supported yet."); |
|
580 |
} |
|
581 |
|
|
582 |
@Override |
|
583 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
584 |
throw new UnsupportedOperationException("Not supported yet."); |
|
585 |
} |
|
586 |
|
|
587 |
@Override |
|
588 |
public void setUnit(int unitIndex) { |
|
589 |
throw new UnsupportedOperationException("Not supported yet."); |
|
590 |
} |
|
591 |
|
|
592 |
@Override |
|
593 |
public int getUnit() { |
|
594 |
return getComputedUnitExp(); |
|
595 |
} |
|
596 |
|
|
597 |
public int getComputedUnitExp() { |
|
598 |
int value = (int) getValueFromExpression(getUnitExp()); |
|
599 |
return value; |
|
600 |
} |
|
601 |
|
|
602 |
public int getComputedReferenceSystemExp() { |
|
603 |
int value = (int) getValueFromExpression(getReferenceSystemExp()); |
|
604 |
return value; |
|
605 |
} |
|
606 |
|
|
607 |
@Override |
|
608 |
public int getReferenceSystem() { |
|
609 |
return 0; |
|
610 |
} |
|
611 |
|
|
612 |
@Override |
|
613 |
public void setReferenceSystem(int referenceSystem) { |
|
614 |
this.referenceSystem = referenceSystem; |
|
615 |
} |
|
616 |
|
|
617 |
@Override |
|
618 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
619 |
throw new UnsupportedOperationException("Not supported yet."); |
|
620 |
} |
|
621 |
|
|
622 |
@Override |
|
623 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
|
624 |
throw new UnsupportedOperationException("Not supported yet."); |
|
625 |
} |
|
626 |
|
|
627 |
@Override |
|
628 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
629 |
throw new UnsupportedOperationException("Not supported yet."); |
|
630 |
} |
|
631 |
|
|
632 |
@Override |
|
633 |
public void setFontField(String fontField) { |
|
634 |
this.LFONT = fontField; |
|
635 |
} |
|
636 |
|
|
637 |
@Override |
|
638 |
public void setFontStyleField(String field) { |
|
639 |
this.LFONTSTYLE=field; |
|
640 |
} |
|
641 |
|
|
135 | 642 |
} |
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/dynamiclegend/DefaultDynamicVectorLegend.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend; |
7 | 7 |
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
10 |
import java.util.logging.Level; |
|
11 |
import org.gvsig.expressionevaluator.Expression; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
8 | 13 |
import org.gvsig.fmap.dal.exception.DataException; |
9 | 14 |
import org.gvsig.fmap.dal.feature.Feature; |
10 | 15 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 | 16 |
import org.gvsig.fmap.geom.Geometry; |
12 |
import org.gvsig.fmap.geom.type.GeometryType;
|
|
13 |
import org.gvsig.fmap.mapcontext.MapContextException;
|
|
17 |
import org.gvsig.fmap.geom.GeometryLocator;
|
|
18 |
import org.gvsig.fmap.geom.primitive.Point;
|
|
14 | 19 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
15 | 20 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
16 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
17 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
18 | 21 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
19 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
20 | 22 |
import org.gvsig.symbology.SymbologyLocator; |
21 | 23 |
import org.gvsig.symbology.SymbologyManager; |
22 | 24 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
... | ... | |
44 | 46 |
public static final String LEGEND_NAME = "DynamicSymbol"; |
45 | 47 |
private ISymbol defaultSymbol; |
46 | 48 |
private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono |
49 |
public static final String FIELD_OUTLINECOLOR = "COUTLINE"; |
|
50 |
public static final String FIELD_FILLCOLOR = "CFILL"; |
|
51 |
public static final String FIELD_SIZE = "CSIZE"; |
|
52 |
public static final String FIELD_ROTATION = "CROTATION"; |
|
47 | 53 |
|
48 | 54 |
/** |
49 | 55 |
* Constructor method, needed by persistence. |
50 | 56 |
*/ |
51 | 57 |
public DefaultDynamicVectorLegend() { |
52 |
|
|
58 |
|
|
53 | 59 |
} |
54 | 60 |
|
55 | 61 |
/** |
... | ... | |
58 | 64 |
* @param style S?mbolo. |
59 | 65 |
*/ |
60 | 66 |
public DefaultDynamicVectorLegend(ISymbol style) { |
61 |
|
|
67 |
|
|
62 | 68 |
setDefaultSymbol(style); |
63 | 69 |
} |
64 | 70 |
|
... | ... | |
100 | 106 |
} |
101 | 107 |
} |
102 | 108 |
|
109 |
private Expression getExpressionFromString(String value) { |
|
110 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
111 |
expression.setPhrase(value); |
|
112 |
return expression; |
|
113 |
} |
|
114 |
|
|
103 | 115 |
@Override |
104 | 116 |
public ISymbol getSymbolByFeature(Feature feat) { |
105 | 117 |
DynamicSymbol symbol = (DynamicSymbol) getDefaultSymbol(); |
118 |
|
|
119 |
String fillcolor = feat.get(FIELD_FILLCOLOR).toString(); |
|
120 |
Expression expFill = getExpressionFromString(fillcolor); |
|
121 |
symbol.setFillColor(expFill); |
|
122 |
|
|
123 |
String outlinecolor = feat.get(FIELD_OUTLINECOLOR).toString(); |
|
124 |
Expression expOutlinecolor = getExpressionFromString(outlinecolor); |
|
125 |
symbol.setOutlineColor(expOutlinecolor); |
|
126 |
|
|
127 |
String size = feat.get(FIELD_SIZE).toString(); |
|
128 |
Expression expSize = getExpressionFromString(size); |
|
129 |
symbol.setSize(expSize); |
|
130 |
|
|
131 |
String rotation = feat.get(FIELD_ROTATION).toString(); |
|
132 |
Expression expRotation = getExpressionFromString(rotation); |
|
133 |
symbol.setRotation(expRotation); |
|
134 |
|
|
135 |
//OFFSET TODO |
|
136 |
Point pointOffset = null; |
|
137 |
String value = ""; |
|
138 |
try { |
|
139 |
pointOffset = GeometryLocator.getGeometryManager().createPoint(0, 0, Geometry.SUBTYPES.GEOM2D); |
|
140 |
value = pointOffset.convertToWKT(); |
|
141 |
} catch (Exception ex) { |
|
142 |
java.util.logging.Logger.getLogger(DefaultDynamicSymbol.class.getName()).log(Level.SEVERE, null, ex); |
|
143 |
} |
|
144 |
|
|
145 |
Expression offset = getExpressionFromString(value); |
|
146 |
symbol.setOffset(offset); |
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
List<String> requiredAttributes = new ArrayList<>(); |
|
151 |
requiredAttributes.add(FIELD_OUTLINECOLOR); |
|
152 |
requiredAttributes.add(FIELD_FILLCOLOR); |
|
153 |
requiredAttributes.add(FIELD_ROTATION); |
|
154 |
requiredAttributes.add(FIELD_SIZE); |
|
155 |
symbol.setRequiredFeatureAttributesNames(requiredAttributes); |
|
156 |
|
|
106 | 157 |
symbol.setFeature(feat); |
107 | 158 |
return symbol; |
108 |
|
|
109 | 159 |
} |
110 | 160 |
|
111 | 161 |
@Override |
112 | 162 |
public void useDefaultSymbol(boolean b) { |
113 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
|
163 |
LOG.warn("TODO: DefaultDynamicVectorLegend.useDefaultSymbol");
|
|
114 | 164 |
} |
115 | 165 |
|
116 | 166 |
public String[] getUsedFields() { |
... | ... | |
133 | 183 |
} |
134 | 184 |
|
135 | 185 |
public void setFeatureStore(FeatureStore fs) throws DataException { |
136 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
|
186 |
LOG.warn("TODO: DefaultDynamicVectorLegend.useDefaultSymbol");
|
|
137 | 187 |
} |
138 | 188 |
|
139 | 189 |
@Override |
... | ... | |
151 | 201 |
// if (defaultSymbol != null) { |
152 | 202 |
// clone.defaultSymbol = (ISymbol) defaultSymbol.clone(); |
153 | 203 |
// } |
154 |
|
|
155 | 204 |
return clone; |
156 | 205 |
} |
157 | 206 |
|
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/dynamiclegend/DefaultDynamicSymbol.java | ||
---|---|---|
9 | 9 |
import java.awt.Color; |
10 | 10 |
import java.awt.Graphics2D; |
11 | 11 |
import java.awt.Rectangle; |
12 |
import java.awt.Stroke; |
|
13 | 12 |
import java.awt.geom.AffineTransform; |
14 | 13 |
import java.util.ArrayList; |
15 | 14 |
import java.util.List; |
... | ... | |
18 | 17 |
import org.gvsig.compat.print.PrintAttributes; |
19 | 18 |
import org.gvsig.expressionevaluator.Expression; |
20 | 19 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
21 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
22 | 20 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
23 | 21 |
import org.gvsig.expressionevaluator.SymbolTable; |
24 | 22 |
import org.gvsig.fmap.dal.DALLocator; |
25 | 23 |
import org.gvsig.fmap.dal.exception.DataException; |
26 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
27 | 24 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
28 | 25 |
import org.gvsig.fmap.dal.feature.Feature; |
29 | 26 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
... | ... | |
32 | 29 |
import org.gvsig.fmap.geom.GeometryManager; |
33 | 30 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
34 | 31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
35 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
36 | 32 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
38 | 33 |
import org.gvsig.fmap.mapcontext.MapContext; |
39 | 34 |
import org.gvsig.fmap.mapcontext.ViewPort; |
40 | 35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
... | ... | |
42 | 37 |
import org.gvsig.symbology.SymbologyLocator; |
43 | 38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol; |
44 | 39 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
46 | 40 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ISimpleLineSymbol; |
47 | 41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
48 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.CIRCLE_STYLE; |
|
49 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.CROSS_STYLE; |
|
50 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.DIAMOND_STYLE; |
|
51 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.SQUARE_STYLE; |
|
52 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.STAR_STYLE; |
|
53 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.TRIANGLE_STYLE; |
|
54 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.VERTICAL_LINE_STYLE; |
|
55 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.X_STYLE; |
|
56 | 42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
57 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle; |
|
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ILineStyle; |
|
59 | 43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ISimpleLineStyle; |
60 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.Line2DOffset; |
|
61 |
import org.gvsig.tools.evaluator.Evaluator; |
|
62 | 44 |
import org.gvsig.tools.persistence.PersistentState; |
63 | 45 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
64 | 46 |
import org.gvsig.tools.task.Cancellable; |
... | ... | |
66 | 48 |
|
67 | 49 |
public class DefaultDynamicSymbol implements DynamicSymbol { |
68 | 50 |
|
69 |
private Feature feature; |
|
51 |
private Feature feature = null;
|
|
70 | 52 |
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(SimpleFillSymbol.class); |
71 | 53 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
72 | 54 |
|
73 |
public static final String OUTLINECOLOR = "COUTLINE";
|
|
74 |
public static final String FILLCOLOR = "CFILL";
|
|
75 |
public static final String SIZE = "CSIZE";
|
|
76 |
private MutableSymbolTable symbolTable;
|
|
55 |
public static Expression eOutlineColor = null;
|
|
56 |
public static Expression eFillColor = null;
|
|
57 |
public static Expression eSize = null;
|
|
58 |
public static Expression eRotation = null;
|
|
77 | 59 |
|
78 | 60 |
private final boolean isShapeVisible = true; |
79 | 61 |
private ISimpleMarkerSymbol pointSymbol = null; |
80 | 62 |
private ISimpleLineSymbol lineSymbol = null; |
81 | 63 |
private ISimpleFillSymbol polygonSymbol = null; |
64 |
public FeatureSymbolTable featureSymbolTable = null; |
|
65 |
public SymbolTable symbolTable = null; |
|
66 |
private Expression eOffset; |
|
67 |
private List<String> listRequiredAttributeNames; |
|
82 | 68 |
|
83 | 69 |
public DefaultDynamicSymbol() { |
84 |
feature = null; |
|
70 |
symbolTable = ExpressionEvaluatorLocator.getManager().createSymbolTable(); |
|
71 |
featureSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable(); |
|
72 |
symbolTable.addSymbolTable(featureSymbolTable); |
|
73 |
|
|
85 | 74 |
} |
86 | 75 |
|
87 | 76 |
@Override |
88 | 77 |
public void setFeature(Feature feat) { |
89 | 78 |
feature = feat; |
79 |
featureSymbolTable.setFeature(feat); |
|
90 | 80 |
} |
91 | 81 |
|
92 | 82 |
@Override |
... | ... | |
94 | 84 |
return null; |
95 | 85 |
} |
96 | 86 |
|
97 |
private DynamicSymbol symbolForSelection; |
|
98 |
|
|
99 | 87 |
@Override |
100 | 88 |
public ISymbol getSymbolForSelection() { |
101 |
if (symbolForSelection == null) { |
|
102 |
DynamicSymbol selectionSymbol; |
|
103 |
try { |
|
104 |
selectionSymbol = (DynamicSymbol) this.clone(); |
|
105 |
if (selectionSymbol != null) { |
|
106 |
// selectionSymbol.setHasFill(true); |
|
107 |
// setSymbolForSelection(selectionSymbol); |
|
108 |
} |
|
109 |
} catch (CloneNotSupportedException ex) { |
|
110 |
// Logger.getLogger(DefaultDynamicSymbol.class.getName()).log(Level.SEVERE, null, ex); |
|
111 |
} |
|
112 |
|
|
113 |
} else { |
|
114 |
symbolForSelection.setColor(MapContext.getSelectionColor()); |
|
89 |
int typeGeom = feature.getDefaultGeometry().getGeometryType().getType(); |
|
90 |
switch (typeGeom) { |
|
91 |
case Geometry.TYPES.POINT: |
|
92 |
case Geometry.TYPES.MULTIPOINT: |
|
93 |
setPointSymbolValues(); |
|
94 |
pointSymbol.setColor(MapContext.getSelectionColor()); |
|
95 |
pointSymbol.setOutlineColor(MapContext.getSelectionColor()); |
|
96 |
return pointSymbol; |
|
97 |
case Geometry.TYPES.LINE: |
|
98 |
case Geometry.TYPES.MULTILINE: |
|
99 |
setLineSymbolValues(); |
|
100 |
lineSymbol.setColor(MapContext.getSelectionColor()); |
|
101 |
return lineSymbol; |
|
102 |
case Geometry.TYPES.POLYGON: |
|
103 |
case Geometry.TYPES.ELLIPSE: |
|
104 |
case Geometry.TYPES.CIRCLE: |
|
105 |
case Geometry.TYPES.MULTIPOLYGON: |
|
106 |
setPolygonSymbolValues(); |
|
107 |
polygonSymbol.setFillColor(MapContext.getSelectionColor()); |
|
108 |
return polygonSymbol; |
|
109 |
default: |
|
110 |
break; |
|
115 | 111 |
} |
116 |
return symbolForSelection;
|
|
112 |
return null;
|
|
117 | 113 |
} |
118 | 114 |
|
119 | 115 |
@Override |
120 | 116 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) { |
121 | 117 |
Color c = getColor(); //TODO |
122 | 118 |
int typeGeom = geom.getGeometryType().getType(); |
123 |
if (typeGeom == Geometry.TYPES.POINT || typeGeom == Geometry.TYPES.MULTIPOINT) { |
|
124 |
drawPoint(g, affineTransform, geom, f, cancel); |
|
125 |
} else if (typeGeom == Geometry.TYPES.LINE || typeGeom == Geometry.TYPES.MULTILINE) { |
|
126 |
drawLine(g, affineTransform, geom, f, cancel); |
|
127 |
} else if (typeGeom == Geometry.TYPES.POLYGON || typeGeom == Geometry.TYPES.MULTIPOLYGON) { |
|
128 |
drawPolygon(g, affineTransform, geom, f, cancel); |
|
129 |
} else if (true) { |
|
130 |
// Optimiza el pintado de geometrias grandes. |
|
131 |
try { |
|
132 |
Geometry env = geom.getEnvelope().getGeometry(); |
|
133 |
env.transform(affineTransform); |
|
134 |
Envelope env2 = env.getEnvelope(); |
|
135 |
if (env2.getLength(0) < 1.5 && env2.getLength(1) < 1.5) { |
|
136 |
geom = env2.getUpperCorner(); |
|
119 |
switch (typeGeom) { |
|
120 |
case Geometry.TYPES.POINT: |
|
121 |
case Geometry.TYPES.MULTIPOINT: |
|
122 |
drawPoint(g, affineTransform, geom, f, cancel); |
|
123 |
break; |
|
124 |
case Geometry.TYPES.LINE: |
|
125 |
case Geometry.TYPES.MULTILINE: |
|
126 |
drawLine(g, affineTransform, geom, f, cancel); |
|
127 |
break; |
|
128 |
case Geometry.TYPES.POLYGON: |
|
129 |
case Geometry.TYPES.ELLIPSE: |
|
130 |
case Geometry.TYPES.CIRCLE: |
|
131 |
case Geometry.TYPES.MULTIPOLYGON: |
|
132 |
drawPolygon(g, affineTransform, geom, f, cancel); |
|
133 |
break; |
|
134 |
default: |
|
135 |
// Optimiza el pintado de geometrias grandes. |
|
136 |
try { |
|
137 |
Geometry env = geom.getEnvelope().getGeometry(); |
|
138 |
env.transform(affineTransform); |
|
139 |
Envelope env2 = env.getEnvelope(); |
|
140 |
if (env2.getLength(0) < 1.5 && env2.getLength(1) < 1.5) { |
|
141 |
geom = env2.getUpperCorner(); |
|
142 |
} |
|
143 |
} catch (Exception ex) { |
|
144 |
LOG.warn("Error optimizing the drawing of the geometry. Continues with normal drawing.", ex); |
|
145 |
// Do nothing, continue with the draw of the original geometry |
|
137 | 146 |
} |
138 |
} catch (Exception ex) { |
|
139 |
LOG.warn("Error optimizing the drawing of the geometry. Continues with normal drawing.", ex); |
|
140 |
// Do nothing, continue with the draw of the original geometry |
|
141 |
} |
|
142 |
|
|
143 |
g.setColor(c); |
|
144 |
g.fill(geom.getShape(affineTransform)); |
|
145 |
g.draw(geom.getShape(affineTransform)); |
|
146 |
|
|
147 |
g.setColor(c); |
|
148 |
g.fill(geom.getShape(affineTransform)); |
|
149 |
g.draw(geom.getShape(affineTransform)); |
|
150 |
break; |
|
147 | 151 |
} |
148 | 152 |
} |
149 | 153 |
|
150 | 154 |
protected void drawPolygon(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) { |
155 |
setPolygonSymbolValues(); |
|
156 |
polygonSymbol.draw(g, affineTransform, geom, f, cancel); |
|
157 |
} |
|
158 |
|
|
159 |
protected void setPolygonSymbolValues() { |
|
151 | 160 |
if (polygonSymbol == null) { |
152 | 161 |
polygonSymbol = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol(); |
153 | 162 |
} |
... | ... | |
158 | 167 |
polygonSymbol.setFillColor(getComputedFillColor()); |
159 | 168 |
polygonSymbol.setHasOutline(true); |
160 | 169 |
polygonSymbol.setHasFill(true); |
161 |
|
|
162 |
polygonSymbol.draw(g, affineTransform, geom, f, cancel); |
|
163 | 170 |
} |
164 | 171 |
|
165 | 172 |
protected void setLineSymbolValues() { |
... | ... | |
183 | 190 |
lineSymbol.draw(g, affineTransform, geom, f, cancel); |
184 | 191 |
} |
185 | 192 |
|
186 |
protected void drawPoint(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
|
|
193 |
protected void setPointSymbolValues() {
|
|
187 | 194 |
if (pointSymbol == null) { |
188 | 195 |
pointSymbol = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol(); |
189 | 196 |
} |
... | ... | |
194 | 201 |
pointSymbol.setOutlined(true); |
195 | 202 |
pointSymbol.setOutlineSize(2); |
196 | 203 |
pointSymbol.setOutlineColor(getComputedOutlineColor()); |
204 |
} |
|
205 |
|
|
206 |
protected void drawPoint(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) { |
|
207 |
setPointSymbolValues(); |
|
197 | 208 |
pointSymbol.draw(g, affineTransform, geom, f, cancel); |
198 | 209 |
} |
199 | 210 |
|
... | ... | |
264 | 275 |
} |
265 | 276 |
|
266 | 277 |
public Expression getComputedColor() { |
267 |
String value = feature.get(FILLCOLOR).toString(); |
|
268 |
Expression expression = getExpressionFromString(value); |
|
269 |
return expression; |
|
278 |
return eFillColor; |
|
270 | 279 |
} |
271 | 280 |
|
272 | 281 |
public Expression getOutlineColor() { |
273 |
String value = feature.get(OUTLINECOLOR).toString(); |
|
274 |
Expression expression = getExpressionFromString(value); |
|
275 |
return expression; |
|
282 |
return eOutlineColor; |
|
276 | 283 |
} |
277 | 284 |
|
278 | 285 |
public Color getComputedOutlineColor() { |
... | ... | |
280 | 287 |
} |
281 | 288 |
|
282 | 289 |
public void setOutlineColor(Expression exp) { |
283 |
|
|
290 |
eOutlineColor = exp; |
|
284 | 291 |
} |
285 | 292 |
|
286 | 293 |
public Expression getFillColor() { |
287 |
String value = feature.get(FILLCOLOR).toString(); |
|
288 |
Expression expression = getExpressionFromString(value); |
|
289 |
return expression; |
|
294 |
return eFillColor; |
|
290 | 295 |
} |
291 | 296 |
|
292 | 297 |
public Color getComputedFillColor() { |
... | ... | |
294 | 299 |
} |
295 | 300 |
|
296 | 301 |
public void setFillColor(Expression exp) { |
297 |
|
|
302 |
eFillColor = exp; |
|
298 | 303 |
} |
299 | 304 |
|
300 | 305 |
public Expression getSize() { |
301 |
String value = feature.get(SIZE).toString(); |
|
302 |
Expression expression = getExpressionFromString(value); |
|
303 |
return expression; |
|
306 |
return eSize; |
|
304 | 307 |
} |
305 | 308 |
|
306 | 309 |
public int getComputedSize() { |
... | ... | |
310 | 313 |
} |
311 | 314 |
|
312 | 315 |
public void setSize(Expression exp) { |
313 |
|
|
316 |
eSize = exp; |
|
314 | 317 |
} |
315 | 318 |
|
316 | 319 |
public Expression getOffset() { |
317 |
// TODO |
|
318 |
Point pointOffset = null; |
|
319 |
String value = ""; |
|
320 |
try { |
|
321 |
pointOffset = GeometryLocator.getGeometryManager().createPoint(0, 0, Geometry.SUBTYPES.GEOM2D); |
|
322 |
value = pointOffset.convertToWKT(); |
|
323 |
} catch (Exception ex) { |
|
324 |
Logger.getLogger(DefaultDynamicSymbol.class.getName()).log(Level.SEVERE, null, ex); |
|
325 |
} |
|
326 |
|
|
327 |
Expression expression = getExpressionFromString(value); |
|
328 |
return expression; |
|
320 |
return eOffset; |
|
329 | 321 |
} |
322 |
|
|
323 |
public void setOffset(Expression offset) { |
|
324 |
eOffset = offset; |
|
325 |
} |
|
330 | 326 |
|
331 | 327 |
public Point getComputedOffset() { |
332 | 328 |
// Expression exp = getSize(); |
... | ... | |
340 | 336 |
return pointOffset; |
341 | 337 |
} |
342 | 338 |
|
343 |
public void setOffset(Expression exp) { |
|
344 | 339 |
|
345 |
} |
|
346 |
|
|
347 | 340 |
public Expression getRotation() { |
348 |
// String value = feature.get(SIZE).toString(); |
|
349 |
String value = "0"; |
|
350 |
Expression expression = getExpressionFromString(value); |
|
351 |
return expression; |
|
341 |
return eRotation; |
|
352 | 342 |
} |
353 | 343 |
|
354 | 344 |
public int getComputedRotation() { |
... | ... | |
358 | 348 |
} |
359 | 349 |
|
360 | 350 |
public void setRotation(Expression exp) { |
361 |
|
|
351 |
eRotation = exp; |
|
362 | 352 |
} |
363 | 353 |
|
364 |
private Expression getExpressionFromString(String value) { |
|
365 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
366 |
expression.setPhrase(value); |
|
367 |
return expression; |
|
368 |
} |
|
369 | 354 |
|
355 |
|
|
370 | 356 |
private Color getColorFromExpression(Expression exp) { |
371 | 357 |
Integer rgbcolor = (Integer) exp.execute(getFeatureSymbolTable()); |
372 | 358 |
Color color = new Color(rgbcolor, true); |
373 | 359 |
return color; |
374 | 360 |
} |
375 | 361 |
|
376 |
public Object getComputedValue(String field) { |
|
377 |
Object value; |
|
378 |
value = feature.get(field); |
|
379 |
|
|
380 |
return value; |
|
381 |
} |
|
382 |
|
|
362 |
// public Object getComputedValue(String field) { |
|
363 |
// Object value; |
|
364 |
// value = feature.get(field); |
|
365 |
// |
|
366 |
// return value; |
|
367 |
// } |
|
383 | 368 |
@Override |
384 | 369 |
public void setColor(Color color) { |
385 | 370 |
|
... | ... | |
387 | 372 |
|
388 | 373 |
@Override |
389 | 374 |
public void setColor(Expression color) { |
375 |
eOutlineColor = color; |
|
390 | 376 |
|
391 | 377 |
} |
392 | 378 |
|
... | ... | |
438 | 424 |
|
439 | 425 |
@Override |
440 | 426 |
public List<String> getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException { |
441 |
List<String> myList = new ArrayList<>(); |
|
442 |
myList.add(OUTLINECOLOR); |
|
443 |
myList.add(FILLCOLOR); |
|
444 |
myList.add(SIZE); |
|
445 |
return myList; |
|
427 |
return this.listRequiredAttributeNames; |
|
428 |
|
|
446 | 429 |
} |
430 |
|
|
431 |
public void setRequiredFeatureAttributesNames(List<String> listRequiredAttributeNames) { |
|
432 |
this.listRequiredAttributeNames = listRequiredAttributeNames; |
|
433 |
|
|
434 |
} |
|
435 |
|
|
447 | 436 |
|
448 | 437 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.api/src/main/java/org/gvsig/symbology/SymbologyManager.java | ||
---|---|---|
52 | 52 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ISimpleLineStyle; |
53 | 53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
54 | 54 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicLabelingStrategy; |
|
56 | 55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicSymbol; |
57 | 56 |
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicVectorLegend; |
58 | 57 |
|
... | ... | |
73 | 72 |
|
74 | 73 |
DynamicVectorLegend createDynamicVectorLegend(); |
75 | 74 |
|
76 |
DynamicLabelingStrategy createDynamicLabelingStrategy(); |
|
77 |
|
|
78 | 75 |
DynamicSymbol createDynamicSymbol(); |
79 | 76 |
|
80 | 77 |
IInterval createInterval(double min, double max); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.api/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/dynamiclegend/DynamicSymbol.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
public List<String> getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException; |
22 | 22 |
// public Expression getColor(); |
23 |
|
|
23 | 24 |
public void setColor(Expression color); |
25 |
|
|
24 | 26 |
public void setFeature(Feature feat); |
27 |
|
|
28 |
public Expression getOutlineColor(); |
|
29 |
|
|
30 |
public void setOutlineColor(Expression exp); |
|
31 |
|
|
32 |
public Expression getFillColor(); |
|
33 |
|
|
34 |
public void setFillColor(Expression exp); |
|
35 |
|
|
36 |
public Expression getRotation(); |
|
37 |
|
|
38 |
public void setRotation(Expression exp); |
|
39 |
|
|
40 |
public Expression getSize(); |
|
41 |
|
|
42 |
public void setSize(Expression exp); |
|
43 |
|
|
44 |
public Expression getOffset(); |
|
45 |
|
|
46 |
public void setOffset(Expression offset); |
|
47 |
|
|
48 |
public void setRequiredFeatureAttributesNames(List<String> listRequiredAttributeNames); |
|
25 | 49 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.api/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/dynamiclegend/DynamicLabelingStrategy.java | ||
---|---|---|
3 | 3 |
* To change this template file, choose Tools | Templates |
4 | 4 |
* and open the template in the editor. |
5 | 5 |
*/ |
6 |
package org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend;
|
|
6 |
package org.gvsig.labeling.dynamiclabeling;
|
|
7 | 7 |
|
8 | 8 |
import java.awt.Color; |
9 | 9 |
import java.awt.Font; |
10 |
import org.gvsig.expressionevaluator.Expression; |
|
11 |
import org.gvsig.fmap.dal.feature.Feature; |
|
12 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
13 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
|
10 | 14 |
|
11 | 15 |
/** |
12 | 16 |
* |
13 | 17 |
* @author osc |
14 | 18 |
*/ |
15 |
public abstract class DynamicLabelingStrategy { |
|
19 |
public abstract class DynamicLabelingStrategy implements ILabelingStrategy, CartographicSupport {
|
|
16 | 20 |
|
17 |
public abstract String getRotation();
|
|
21 |
public abstract void setFeature(Feature f);
|
|
18 | 22 |
|
19 |
public abstract String getText();
|
|
23 |
public abstract Expression getRotation();
|
|
20 | 24 |
|
21 |
public abstract String getHeight();
|
|
25 |
public abstract int getComputedRotation();
|
|
22 | 26 |
|
23 |
public abstract String getColor();
|
|
27 |
public abstract Expression getUnitExp();
|
|
24 | 28 |
|
25 |
public abstract double getFixedSize(); |
|
29 |
public abstract int getComputedUnit(); |
|
30 |
|
|
31 |
public abstract Expression getText(); |
|
32 |
|
|
33 |
public abstract String getComputedText(); |
|
34 |
|
|
35 |
public abstract Expression getHeight(); |
|
36 |
|
|
37 |
public abstract int getComputedHeight(); |
|
38 |
|
|
39 |
public abstract Expression getColor(); |
|
40 |
|
|
41 |
public abstract Color getComputedColor(); |
|
42 |
|
|
43 |
public abstract Expression getFixedSize(); |
|
44 |
|
|
45 |
public abstract double getComputedFixedSize(); |
|
46 |
|
|
47 |
public abstract Expression getFontStyle(); |
|
48 |
|
|
49 |
public abstract int getComputedFontStyle(); |
|
26 | 50 |
|
51 |
public abstract void setFontStyle(int style); |
|
27 | 52 |
|
28 |
|
|
53 |
public abstract void setFontStyleField(String field); |
|
54 |
|
|
29 | 55 |
public abstract void setTextField(String textFieldName); |
30 | 56 |
|
31 | 57 |
public abstract void setRotationField(String rotationFieldName); |
... | ... | |
45 | 71 |
|
46 | 72 |
public abstract boolean usesFixedSize(); |
47 | 73 |
|
48 |
|
|
49 |
|
|
50 | 74 |
public abstract void setFixedSize(double fixedSize); |
51 | 75 |
|
52 | 76 |
public abstract void setUsesFixedColor(boolean b); |
53 | 77 |
|
54 | 78 |
public abstract boolean usesFixedColor(); |
55 | 79 |
|
56 |
public abstract Color getFixedColor();
|
|
80 |
public abstract Expression getFixedColor();
|
|
57 | 81 |
|
82 |
public abstract Color getComputedFixedColor(); |
|
83 |
|
|
58 | 84 |
public abstract void setFixedColor(Color fixedColor); |
59 | 85 |
|
60 |
public abstract Color getColorFont();
|
|
86 |
public abstract Expression getColorFont();
|
|
61 | 87 |
|
88 |
public abstract Color getComputedColorFont(); |
|
89 |
|
|
62 | 90 |
public abstract void setColorFont(Color colorFont); |
63 | 91 |
|
64 |
public abstract Font getFont();
|
|
92 |
public abstract Expression getFont();
|
|
65 | 93 |
|
94 |
public abstract Font getComputedFont(); |
|
95 |
|
|
66 | 96 |
public abstract void setFont(Font selFont); |
97 |
|
|
98 |
public abstract void setFontField(String fontField); |
|
67 | 99 |
|
68 | 100 |
} |
Also available in: Unified diff