Revision 102
org.gvsig.legend.proportionalsymbols.app.mainplugin/trunk/org.gvsig.legend.proportionalsymbols.app.mainplugin/src/main/java/org/gvsig/symbology/fmap/rendering/ProportionalSymbolsLegend.java | ||
---|---|---|
86 | 86 |
private static Logger logger = LoggerFactory.getLogger(ProportionalSymbolsLegend.class); |
87 | 87 |
public static final String |
88 | 88 |
PROPORTIONAL_SYMBOL_LEGEND_NAME = |
89 |
"PROPORTIONAL_SYMBOL_LEGEND";
|
|
89 |
"PROPORTIONAL_SYMBOL_LEGEND"; |
|
90 | 90 |
public static final String |
91 | 91 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME = |
92 |
"PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION";
|
|
93 |
|
|
92 |
"PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION"; |
|
93 |
|
|
94 | 94 |
public void setClassifyingFieldNames(String[] fNames) { |
95 | 95 |
super.setClassifyingFieldNames(fNames); |
96 | 96 |
valueField = fNames[0]; |
... | ... | |
113 | 113 |
} |
114 | 114 |
|
115 | 115 |
public ISymbol getSymbolByFeature(Feature feat) { |
116 |
|
|
116 |
|
|
117 | 117 |
ISymbol theSymbol = getDefaultSymbol(); |
118 | 118 |
ISymbol auxSymbol; |
119 |
|
|
119 |
|
|
120 | 120 |
double value = 0; |
121 | 121 |
double normValue = 0; |
122 | 122 |
double size; |
123 | 123 |
double separation = maxSize-minSize; |
124 |
|
|
124 |
|
|
125 | 125 |
if (separation == 0) { |
126 | 126 |
separation = 1; |
127 | 127 |
} |
... | ... | |
130 | 130 |
|
131 | 131 |
value = feat.getDouble(this.valueField); |
132 | 132 |
if (useNormalization) { |
133 |
|
|
133 |
|
|
134 | 134 |
normValue = feat.getDouble(this.normalizationField); |
135 | 135 |
if (normValue == 0) { |
136 | 136 |
size = (value >= 0) ? |
137 | 137 |
Double.POSITIVE_INFINITY : |
138 |
Double.NEGATIVE_INFINITY;
|
|
138 |
Double.NEGATIVE_INFINITY; |
|
139 | 139 |
} else { |
140 | 140 |
value = value / normValue; |
141 | 141 |
size = minSize + (value * separation) ; |
142 | 142 |
} |
143 |
|
|
143 |
|
|
144 | 144 |
} else { |
145 | 145 |
double difFeat = maxFeature - minFeature; |
146 | 146 |
double step = difFeat/separation; |
... | ... | |
154 | 154 |
|
155 | 155 |
if (size == Double.NaN || size == Double.POSITIVE_INFINITY |
156 | 156 |
|| size == Double.NEGATIVE_INFINITY) { |
157 |
|
|
157 |
|
|
158 | 158 |
// logger.info("The symbol size is NaN or INFINITE."); |
159 | 159 |
return null; |
160 | 160 |
} |
161 | 161 |
|
162 | 162 |
Geometry defgeom = feat.getDefaultGeometry(); |
163 | 163 |
int def_geom_type = defgeom.getGeometryType().getType(); |
164 |
|
|
164 |
|
|
165 | 165 |
if (isPolygonal(def_geom_type) && theSymbol instanceof IMarkerSymbol) { |
166 |
|
|
166 |
|
|
167 | 167 |
MarkerFillSymbol aux = new MarkerFillSymbol(); |
168 | 168 |
((IMarkerSymbol) theSymbol).setSize(size); |
169 | 169 |
aux.setMarker((IMarkerSymbol) theSymbol); |
... | ... | |
173 | 173 |
theSymbol = aux; |
174 | 174 |
} |
175 | 175 |
else if (isLinear(def_geom_type)) { |
176 |
|
|
176 |
|
|
177 | 177 |
ILineSymbol line = (ILineSymbol) theSymbol; |
178 | 178 |
line.setLineWidth(size); |
179 | 179 |
theSymbol = line; |
... | ... | |
183 | 183 |
marker.setSize(size); |
184 | 184 |
theSymbol = marker; |
185 | 185 |
} |
186 |
|
|
186 |
|
|
187 | 187 |
if (backgroundSymbol != null) { |
188 | 188 |
MultiLayerFillSymbol multi = new MultiLayerFillSymbol() ; |
189 | 189 |
multi.addLayer(backgroundSymbol); |
... | ... | |
221 | 221 |
return false; |
222 | 222 |
} |
223 | 223 |
} |
224 |
|
|
224 |
|
|
225 | 225 |
public static boolean isPoint(int ty) { |
226 | 226 |
if (ty == Geometry.TYPES.POINT |
227 | 227 |
|| ty == Geometry.TYPES.MULTIPOINT |
... | ... | |
233 | 233 |
} |
234 | 234 |
|
235 | 235 |
|
236 |
|
|
236 |
|
|
237 | 237 |
/** |
238 | 238 |
* Gets the background symbol which only can appear when the shapetype of the layer |
239 | 239 |
* is polygonal |
... | ... | |
251 | 251 |
* Obtains the classifying field name to be used to calculate the size of the symbol |
252 | 252 |
* |
253 | 253 |
* @return String the name of the field |
254 |
* @throws ReadDriverException
|
|
254 |
* @throws ReadDriverException |
|
255 | 255 |
*/ |
256 | 256 |
public String getValueField() { |
257 | 257 |
// try { |
... | ... | |
325 | 325 |
* @param templateShapeType shape type for the template symbol |
326 | 326 |
*/ |
327 | 327 |
public void setTemplateShapeType(int tst) { |
328 |
|
|
328 |
|
|
329 | 329 |
if (isPolygonal(getShapeType())) { |
330 | 330 |
if (isPoint(tst) || isPolygonal(tst)) { |
331 | 331 |
this.templateShapeType = tst; |
332 | 332 |
} |
333 | 333 |
} else { |
334 |
|
|
334 |
|
|
335 | 335 |
if ((isPoint(tst) && isPoint(getShapeType())) |
336 | 336 |
|| (isLinear(tst) && isLinear(getShapeType()))) { |
337 | 337 |
// || (getShapeType() == Geometry.TYPES.NULL)) { |
338 |
|
|
338 |
|
|
339 | 339 |
this.templateShapeType = tst; |
340 | 340 |
} |
341 | 341 |
} |
342 | 342 |
} |
343 |
|
|
343 |
|
|
344 | 344 |
/** |
345 | 345 |
* Obtains the boolean which is true if the user wants to calculate the size of the |
346 | 346 |
* symbol using a normalization field. |
... | ... | |
532 | 532 |
} |
533 | 533 |
} |
534 | 534 |
|
535 |
|
|
535 |
|
|
536 | 536 |
public void loadFromState(PersistentState state) |
537 | 537 |
throws PersistenceException { |
538 |
|
|
538 |
|
|
539 | 539 |
int[] ft = state.getIntArray("fieldTypes"); |
540 | 540 |
this.setClassifyingFieldTypes(ft); |
541 |
|
|
541 |
|
|
542 | 542 |
this.valueField = state.getString("valueField"); |
543 | 543 |
this.normalizationField = state.getString("normalizationField"); |
544 | 544 |
this.templateShapeType = state.getInt("templateShapeType"); |
... | ... | |
547 | 547 |
this.maxFeature = state.getDouble("maxFeature"); |
548 | 548 |
this.minFeature = state.getDouble("minFeature"); |
549 | 549 |
this.useNormalization = state.getBoolean("useNormalization"); |
550 |
|
|
550 |
|
|
551 | 551 |
ISymbol sym = (ISymbol) state.get("defaultSymbol"); |
552 | 552 |
this.setDefaultSymbol(sym); |
553 |
|
|
553 |
|
|
554 | 554 |
sym = (ISymbol) state.get("backgroundSymbol"); |
555 | 555 |
this.setBackgroundSymbol(sym); |
556 |
|
|
556 |
|
|
557 | 557 |
String[] fieldNames = new String[2]; |
558 | 558 |
fieldNames[0]= valueField; |
559 | 559 |
if (normalizationField.compareTo(Messages.getText("none")) == 0) { |
... | ... | |
586 | 586 |
public static class RegisterPersistence implements Callable { |
587 | 587 |
|
588 | 588 |
public Object call() throws Exception { |
589 |
|
|
589 |
|
|
590 | 590 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
591 | 591 |
if (manager |
592 | 592 |
.getDefinition(PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) { |
... | ... | |
597 | 597 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME, |
598 | 598 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME |
599 | 599 |
+ " Persistence definition", null, null); |
600 |
|
|
600 |
|
|
601 | 601 |
definition.addDynFieldString("valueField").setMandatory(true); |
602 | 602 |
definition.addDynFieldString("normalizationField").setMandatory(true); |
603 | 603 |
definition.addDynFieldInt("templateShapeType").setMandatory(true); |
604 |
definition.addDynFieldArray("fieldTypes").setMandatory(true); |
|
604 |
definition.addDynFieldArray("fieldTypes").setClassOfItems(Integer.class).setMandatory(true);
|
|
605 | 605 |
definition.addDynFieldDouble("maxSize").setMandatory(true); |
606 | 606 |
definition.addDynFieldDouble("minSize").setMandatory(true); |
607 | 607 |
definition.addDynFieldDouble("maxFeature").setMandatory(true); |
608 | 608 |
definition.addDynFieldDouble("minFeature").setMandatory(true); |
609 | 609 |
definition.addDynFieldBoolean("useNormalization").setMandatory(true); |
610 |
|
|
610 |
|
|
611 | 611 |
definition.addDynFieldObject("defaultSymbol") |
612 | 612 |
.setClassOfValue(ISymbol.class).setMandatory(true); |
613 | 613 |
definition.addDynFieldObject("backgroundSymbol") |
Also available in: Unified diff