Revision 11704 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/VectorialUniqueValueLegend.java
VectorialUniqueValueLegend.java | ||
---|---|---|
45 | 45 |
import java.util.ArrayList; |
46 | 46 |
import java.util.Comparator; |
47 | 47 |
import java.util.TreeMap; |
48 |
import java.util.logging.Logger; |
|
48 | 49 |
|
49 |
import org.geotools.filter.ExpressionBuilder; |
|
50 |
import org.geotools.filter.Filter; |
|
51 |
import org.geotools.styling.FeatureTypeStyle; |
|
52 |
import org.geotools.styling.NamedLayer; |
|
53 |
import org.geotools.styling.Rule; |
|
54 |
import org.geotools.styling.SLDTransformer; |
|
55 |
import org.geotools.styling.Style; |
|
56 |
import org.geotools.styling.StyleBuilder; |
|
57 |
import org.geotools.styling.StyleFactory; |
|
58 |
import org.geotools.styling.StyledLayerDescriptor; |
|
59 |
import org.geotools.styling.Symbolizer; |
|
60 |
|
|
61 | 50 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
62 | 51 |
import com.hardcode.gdbms.engine.data.DataSource; |
63 | 52 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
... | ... | |
71 | 60 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
72 | 61 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
73 | 62 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
74 |
import com.iver.cit.gvsig.fmap.core.SLDUtils; |
|
75 | 63 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
76 | 64 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
77 | 65 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
... | ... | |
84 | 72 |
*/ |
85 | 73 |
public class VectorialUniqueValueLegend implements IVectorialUniqueValueLegend { |
86 | 74 |
private boolean sorter=true; |
75 |
private static final Logger log = Logger.getAnonymousLogger(); |
|
87 | 76 |
|
88 | 77 |
private TreeMap symbols = new TreeMap(new Comparator() { |
89 | 78 |
public int compare(Object o1, Object o2) { |
... | ... | |
144 | 133 |
} |
145 | 134 |
}); // Para poder ordenar |
146 | 135 |
private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice |
147 |
private String fieldName;
|
|
136 |
private String[] fieldNames;
|
|
148 | 137 |
protected int fieldId = -1; |
149 | 138 |
private String labelFieldName; |
150 | 139 |
private String labelFieldHeight; |
... | ... | |
155 | 144 |
private String valueType = NullValue.class.getName(); |
156 | 145 |
private boolean useDefaultSymbol = false; |
157 | 146 |
|
147 |
|
|
158 | 148 |
/** |
159 | 149 |
* Crea un nuevo VectorialUniqueValueLegend. |
160 | 150 |
*/ |
161 | 151 |
public VectorialUniqueValueLegend() { |
162 |
// defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL; |
|
163 | 152 |
} |
164 | 153 |
|
165 | 154 |
/** |
... | ... | |
177 | 166 |
*/ |
178 | 167 |
public void setShapeType(int shapeType) { |
179 | 168 |
if (this.shapeType != shapeType) { |
180 |
/*switch (shapeType) { |
|
181 |
case FShape.POINT: |
|
182 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT); |
|
183 |
|
|
184 |
break; |
|
185 |
|
|
186 |
case FShape.LINE: |
|
187 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE); |
|
188 |
|
|
189 |
break; |
|
190 |
|
|
191 |
case FShape.POLYGON: |
|
192 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL); |
|
193 |
|
|
194 |
break; |
|
195 |
|
|
196 |
default: |
|
197 |
defaultSymbol = new FSymbol(shapeType); |
|
198 |
}*/ |
|
199 | 169 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
200 | 170 |
this.shapeType = shapeType; |
201 | 171 |
} |
... | ... | |
224 | 194 |
resul = symbols.put(key, symbol); |
225 | 195 |
|
226 | 196 |
if (resul != null) { |
227 |
System.err.println("Error: la clave " + key +
|
|
197 |
log.warning("Error: la clave " + key +
|
|
228 | 198 |
" ya exist?a. Resul = " + resul); |
229 |
System.err.println("symbol nuevo:" + symbol.getDescription() +
|
|
199 |
log.warning("symbol nuevo:" + symbol.getDescription() +
|
|
230 | 200 |
" Sviejo= " + ((ISymbol) resul).getDescription()); |
231 | 201 |
} else { |
232 | 202 |
keys.add(key); |
... | ... | |
264 | 234 |
* @return |
265 | 235 |
* @uml.property name="fieldName" |
266 | 236 |
*/ |
267 |
public String getFieldName() {
|
|
268 |
return fieldName; |
|
237 |
public String[] getFieldNames() {
|
|
238 |
return fieldNames;
|
|
269 | 239 |
} |
270 | 240 |
|
271 | 241 |
/** |
... | ... | |
288 | 258 |
* @param str |
289 | 259 |
* @uml.property name="fieldName" |
290 | 260 |
*/ |
291 |
public void setFieldName(String str) {
|
|
292 |
fieldName = str;
|
|
261 |
public void setFieldNames(String[] fNames) {
|
|
262 |
fieldNames = fNames;
|
|
293 | 263 |
} |
294 | 264 |
|
295 | 265 |
/** |
... | ... | |
341 | 311 |
return defaultSymbol; |
342 | 312 |
} |
343 | 313 |
|
344 |
/** |
|
345 |
* @deprecated |
|
346 |
* Writes and SLD using GEOTOOLS objetcs. |
|
347 |
* @see com.iver.cit.gvsig.fmap.rendering.ILegend#getSLDString() |
|
348 |
*/ |
|
349 |
public String getSLDString_() |
|
350 |
{ |
|
351 |
try{ |
|
352 |
StyledLayerDescriptor sld = new StyledLayerDescriptor(); |
|
353 |
StyleFactory styleFactory = StyleFactory.createStyleFactory(); |
|
354 |
StyleBuilder sb = new StyleBuilder(); |
|
355 |
Style style = sb.createStyle(); |
|
356 |
style.setName("default"); |
|
357 |
Filter filter = null; |
|
358 |
Rule rule = null; |
|
314 |
// /** |
|
315 |
// * @deprecated |
|
316 |
// * Writes and SLD using GEOTOOLS objetcs. |
|
317 |
// * @see com.iver.cit.gvsig.fmap.rendering.ILegend#getSLDString() |
|
318 |
// */ |
|
319 |
// public String getSLDString_() |
|
320 |
// { |
|
321 |
// try{ |
|
322 |
// StyledLayerDescriptor sld = new StyledLayerDescriptor(); |
|
323 |
// StyleFactory styleFactory = StyleFactory.createStyleFactory(); |
|
324 |
// StyleBuilder sb = new StyleBuilder(); |
|
325 |
// Style style = sb.createStyle(); |
|
326 |
// style.setName("default"); |
|
327 |
// Filter filter = null; |
|
328 |
// Rule rule = null; |
|
329 |
// |
|
330 |
// FeatureTypeStyle featStyle = styleFactory.createFeatureTypeStyle(); |
|
331 |
// featStyle.setFeatureTypeName(fieldName); |
|
332 |
// |
|
333 |
// ISymbol[] symbols = this.getSymbols(); |
|
334 |
// Symbolizer[] theSymbolizers = new Symbolizer[symbols.length]; |
|
335 |
// Object[] values = this.getValues(); |
|
336 |
// String valueStr = null; |
|
337 |
// String condition = null; |
|
338 |
// |
|
339 |
// for(int i = 0; i < symbols.length; i++ ) |
|
340 |
// { |
|
341 |
// valueStr = values[i].toString(); |
|
342 |
// //if(this.valueType == "") |
|
343 |
// condition = fieldName +"='"+valueStr+"'"; |
|
344 |
// //else |
|
345 |
// // condition = fieldName +"="+values[i]; |
|
346 |
// filter = (Filter)ExpressionBuilder.parse(condition); |
|
347 |
// theSymbolizers[0] = SLDUtils.toGeotoolsSymbol(symbols[i]); |
|
348 |
// rule = styleFactory.createRule(); |
|
349 |
// rule.setName(valueStr); |
|
350 |
// rule.setTitle(valueStr); |
|
351 |
// rule.setFilter(filter); |
|
352 |
// rule.setSymbolizers((Symbolizer[])theSymbolizers.clone()); |
|
353 |
// featStyle.addRule(rule); |
|
354 |
// } |
|
355 |
// style.addFeatureTypeStyle(featStyle); |
|
356 |
// SLDTransformer st = new SLDTransformer(); |
|
357 |
// NamedLayer namedLayer = new NamedLayer(); |
|
358 |
// namedLayer.setName("comunidades"); |
|
359 |
// namedLayer.addStyle(style); |
|
360 |
// sld.addStyledLayer(namedLayer); |
|
361 |
// return st.transform(style); |
|
362 |
// |
|
363 |
// }catch(Exception e) |
|
364 |
// { |
|
365 |
// e.printStackTrace(); |
|
366 |
// return null; |
|
367 |
// } |
|
368 |
// } |
|
359 | 369 |
|
360 |
FeatureTypeStyle featStyle = styleFactory.createFeatureTypeStyle(); |
|
361 |
featStyle.setFeatureTypeName(fieldName); |
|
362 |
|
|
363 |
ISymbol[] symbols = this.getSymbols(); |
|
364 |
Symbolizer[] theSymbolizers = new Symbolizer[symbols.length]; |
|
365 |
Object[] values = this.getValues(); |
|
366 |
String valueStr = null; |
|
367 |
String condition = null; |
|
368 |
|
|
369 |
for(int i = 0; i < symbols.length; i++ ) |
|
370 |
{ |
|
371 |
valueStr = values[i].toString(); |
|
372 |
//if(this.valueType == "") |
|
373 |
condition = fieldName +"='"+valueStr+"'"; |
|
374 |
//else |
|
375 |
// condition = fieldName +"="+values[i]; |
|
376 |
filter = (Filter)ExpressionBuilder.parse(condition); |
|
377 |
theSymbolizers[0] = SLDUtils.toGeotoolsSymbol(symbols[i]); |
|
378 |
rule = styleFactory.createRule(); |
|
379 |
rule.setName(valueStr); |
|
380 |
rule.setTitle(valueStr); |
|
381 |
rule.setFilter(filter); |
|
382 |
rule.setSymbolizers((Symbolizer[])theSymbolizers.clone()); |
|
383 |
featStyle.addRule(rule); |
|
384 |
} |
|
385 |
style.addFeatureTypeStyle(featStyle); |
|
386 |
SLDTransformer st = new SLDTransformer(); |
|
387 |
NamedLayer namedLayer = new NamedLayer(); |
|
388 |
namedLayer.setName("comunidades"); |
|
389 |
namedLayer.addStyle(style); |
|
390 |
sld.addStyledLayer(namedLayer); |
|
391 |
return st.transform(style); |
|
392 |
|
|
393 |
}catch(Exception e) |
|
394 |
{ |
|
395 |
e.printStackTrace(); |
|
396 |
return null; |
|
397 |
} |
|
398 |
} |
|
399 |
|
|
400 | 370 |
public String getSLDString(String name) |
401 | 371 |
{ |
402 | 372 |
try{ |
... | ... | |
421 | 391 |
xmlBuilder.writeTag(SLDTags.NAME, valueStr); |
422 | 392 |
xmlBuilder.openTag(SLDTags.FILTER); |
423 | 393 |
xmlBuilder.openTag(SLDTags.PROPERTYISEQUALTO); |
424 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName);
|
|
394 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME, fieldNames[0]);
|
|
425 | 395 |
xmlBuilder.writeTag(SLDTags.LITERAL, valueStr); |
426 | 396 |
xmlBuilder.closeTag(); |
427 | 397 |
xmlBuilder.closeTag(); |
... | ... | |
452 | 422 |
public XMLEntity getXMLEntity() { |
453 | 423 |
XMLEntity xml = new XMLEntity(); |
454 | 424 |
xml.putProperty("className", this.getClass().getName()); |
455 |
xml.putProperty("fieldName", fieldName);
|
|
425 |
xml.putProperty("fieldNames", fieldNames[0]);
|
|
456 | 426 |
xml.putProperty("labelfield", labelFieldName); |
457 | 427 |
xml.putProperty("labelFieldHeight", labelFieldHeight); |
458 | 428 |
xml.putProperty("labelFieldRotation", labelFieldRotation); |
... | ... | |
502 | 472 |
|
503 | 473 |
public void setXMLEntity03(XMLEntity xml) { |
504 | 474 |
clear(); |
505 |
setFieldName(xml.getStringProperty("fieldName"));
|
|
475 |
setFieldNames(new String[] {xml.getStringProperty("fieldName")});
|
|
506 | 476 |
setLabelField(xml.getStringProperty("labelfield")); |
507 | 477 |
|
508 | 478 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
... | ... | |
546 | 516 |
|
547 | 517 |
public void setXMLEntity(XMLEntity xml) { |
548 | 518 |
clear(); |
549 |
setFieldName(xml.getStringProperty("fieldName")); |
|
519 |
if (xml.contains("fieldName")) |
|
520 |
setFieldNames(new String[] {xml.getStringProperty("fieldName")}); |
|
521 |
else |
|
522 |
setFieldNames(xml.getStringArrayProperty("fieldNames")); |
|
550 | 523 |
setLabelField(xml.getStringProperty("labelfield")); |
551 | 524 |
|
552 | 525 |
if (xml.contains("labelFieldHeight")) { |
... | ... | |
560 | 533 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol"); |
561 | 534 |
if (xml.contains("sorter")) |
562 | 535 |
sorter = xml.getBooleanProperty("sorter"); |
563 |
setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
|
|
536 |
setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
|
|
564 | 537 |
|
565 | 538 |
// FJP: Esto no es necesario ya. Para comprobar si tenemos un campo de altura, miramos |
566 | 539 |
// si getLabelHeightField devuelve null o no. |
... | ... | |
600 | 573 |
} |
601 | 574 |
|
602 | 575 |
// (substituir la de baix per esta) ISymbol sym = SymbolFactory.createFromXML(xml.getChild(i + 1), null); |
603 |
ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
|
|
576 |
ISymbol sym = SymbologyFactory.createSymbolFromXML(xml.getChild(i + 1), null);
|
|
604 | 577 |
symbols.put(auxValue2, sym); |
605 | 578 |
keys.add(auxValue); |
606 | 579 |
} |
... | ... | |
709 | 682 |
ReadDriverException { |
710 | 683 |
dataSource = ds; |
711 | 684 |
ds.start(); |
712 |
fieldId = ds.getFieldIndexByName(fieldName); |
|
685 |
fieldId = ds.getFieldIndexByName(fieldNames[0]);
|
|
713 | 686 |
ds.stop(); |
714 | 687 |
} |
715 | 688 |
|
716 | 689 |
/* |
717 |
* (non-Javadoc)
|
|
718 |
*
|
|
719 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
|
720 |
*/
|
|
721 |
public ISymbol getSymbolByValue(Value key) {
|
|
690 |
* (non-Javadoc)
|
|
691 |
*
|
|
692 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
|
693 |
*/
|
|
694 |
public ISymbol getSymbolByValue(Value key) { |
|
722 | 695 |
boolean auxSorted=sorter; |
723 | 696 |
sorter=true; |
724 |
ISymbol symbol=(ISymbol) symbols.get(key);
|
|
725 |
sorter=auxSorted;
|
|
726 |
if (symbol!=null) {
|
|
727 |
return symbol;
|
|
728 |
} else if (useDefaultSymbol) {
|
|
729 |
return getDefaultSymbol();
|
|
730 |
}
|
|
731 |
return null;
|
|
697 |
ISymbol symbol=(ISymbol) symbols.get(key);
|
|
698 |
sorter=auxSorted;
|
|
699 |
if (symbol!=null) {
|
|
700 |
return symbol;
|
|
701 |
} else if (useDefaultSymbol) {
|
|
702 |
return getDefaultSymbol();
|
|
703 |
}
|
|
704 |
return null;
|
|
732 | 705 |
|
733 | 706 |
} |
734 | 707 |
|
... | ... | |
776 | 749 |
|
777 | 750 |
public String[] getUsedFields() { |
778 | 751 |
ArrayList usedFields = new ArrayList(); |
779 |
if (getFieldName() != null) |
|
780 |
usedFields.add(getFieldName()); |
|
752 |
if (getFieldNames() != null)
|
|
753 |
usedFields.add(getFieldNames());
|
|
781 | 754 |
if (getLabelField() != null) |
782 | 755 |
usedFields.add(getLabelField()); |
783 | 756 |
if (getLabelHeightField() != null) |
... | ... | |
796 | 769 |
public boolean isSorter() { |
797 | 770 |
return sorter; |
798 | 771 |
} |
772 |
|
|
773 |
|
|
799 | 774 |
} |
Also available in: Unified diff