46 |
import java.util.ArrayList; |
import java.util.ArrayList; |
47 |
import java.util.List; |
import java.util.List; |
48 |
import java.util.Map; |
import java.util.Map; |
49 |
|
import java.util.Set; |
50 |
|
|
51 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
52 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
92 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
93 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
94 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
95 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadataImpl; |
96 |
|
import skrueger.AttributeMetadataInterface; |
97 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
98 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
99 |
|
|
254 |
* TODO replace with |
* TODO replace with |
255 |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
256 |
*/ |
*/ |
257 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData( |
258 |
final AttributeMetadataMap amdMap, final boolean visible) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
259 |
|
final boolean visible) { |
260 |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap( |
|
261 |
amdMap.getLanguages()); |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone(); |
262 |
for (final AttributeMetadata amd : amdMap.values()) |
if (filteredMap.size() > 0 ) { |
263 |
|
filteredMap.clear(); // Just in case the close copies the contents |
264 |
|
} |
265 |
|
|
266 |
|
for (final AttributeMetadataInterface amd : amdMap.values()) |
267 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
268 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
269 |
|
|
271 |
} |
} |
272 |
|
|
273 |
/** |
/** |
274 |
* Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}. |
* Parses a {@link AttributeMetadataImpl} object from an JDOM- |
275 |
* This method works like {@link |
* {@link Element}. This method works like {@link |
276 |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
277 |
* |
* |
278 |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
283 |
* @param element |
* @param element |
284 |
* {@link Element} to parse |
* {@link Element} to parse |
285 |
*/ |
*/ |
286 |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
public static AttributeMetadataImpl parseAttributeMetaData( |
287 |
|
final Element element) { |
288 |
final String namespace = String.valueOf(element |
final String namespace = String.valueOf(element |
289 |
.getAttributeValue("namespace")); |
.getAttributeValue("namespace")); |
290 |
final String localname = String.valueOf(element |
final String localname = String.valueOf(element |
291 |
.getAttributeValue("localname")); |
.getAttributeValue("localname")); |
292 |
final Name aName = new NameImpl(namespace, localname); |
final NameImpl aName = new NameImpl(namespace, localname); |
293 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
294 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
295 |
final String unit = element.getAttributeValue("unit"); |
final String unit = element.getAttributeValue("unit"); |
305 |
else if (childElement.getName().equals("desc")) |
else if (childElement.getName().equals("desc")) |
306 |
desc = parseTranslation(childElement); |
desc = parseTranslation(childElement); |
307 |
} |
} |
308 |
return new AttributeMetadata(aName, visible, name, desc, unit); |
return new AttributeMetadataImpl(aName, visible, name, desc, unit); |
309 |
} |
} |
310 |
|
|
311 |
/** |
/** |
312 |
* Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with |
* Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element} |
313 |
* {@code <attribute>}-childs. |
* with {@code <attribute>}-childs. |
314 |
* |
* |
315 |
* @param element |
* @param element |
316 |
* {@link Element} to parse |
* {@link Element} to parse |
317 |
* |
* |
318 |
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
319 |
* attributes which are not used by Xulu/ISDSS. GP |
* more attributes which are not used by Xulu/ISDSS. GP |
320 |
* exports/imports the AMD via AMLExporter and AMLImporter |
* exports/imports the AMD via AMLExporter and AMLImporter |
321 |
* classes. (SK, 3.2.2010) * |
* classes. (SK, 3.2.2010) * |
322 |
*/ |
*/ |
323 |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
324 |
final Element element) { |
final Element element) { |
325 |
final AttributeMetadataMap metaData = new AttributeMetadataMap(); |
final AttributeMetadataMap metaData = new AttributeMetadataImplMap(); |
326 |
final List<Element> attributesElements = element |
final List<Element> attributesElements = element |
327 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
328 |
for (final Element attibuteElement : attributesElements) { |
for (final Element attibuteElement : attributesElements) { |
329 |
final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement); |
330 |
metaData.put(attrMetaData.getName(), attrMetaData); |
metaData.put(attrMetaData.getName(), attrMetaData); |
331 |
} |
} |
332 |
return metaData; |
return metaData; |
333 |
} |
} |
334 |
|
|
335 |
/** |
/** |
336 |
* Loads a {@link AttributeMetadata} object from an URL. |
* Loads a {@link AttributeMetadataImpl} object from an URL. |
337 |
* |
* |
338 |
* @param documentUrl |
* @param documentUrl |
339 |
* {@link URL} to parse |
* {@link URL} to parse |
346 |
} |
} |
347 |
|
|
348 |
/** |
/** |
349 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
350 |
* object. |
* {@link AttributeMetadataImpl} object. |
351 |
* |
* |
352 |
* @param amd |
* @param amd |
353 |
* meta data for one attribute |
* meta data for one attribute |
354 |
* |
* |
355 |
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
356 |
* attributes which are not used by Xulu/ISDSS. GP |
* more attributes which are not used by Xulu/ISDSS. GP |
357 |
* exports/imports the AMD via AMLExporter and AMLImporter |
* exports/imports the AMD via AMLExporter and AMLImporter |
358 |
* classes. (SK, 3.2.2010) |
* classes. (SK, 3.2.2010) |
359 |
*/ |
*/ |
360 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
361 |
final AttributeMetadata amd) { |
final AttributeMetadataInterface amd) { |
362 |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
363 |
element.setAttribute("namespace", String.valueOf(amd.getName() |
element.setAttribute("namespace", String.valueOf(amd.getName() |
364 |
.getNamespaceURI())); |
.getNamespaceURI())); |
373 |
} |
} |
374 |
|
|
375 |
/** |
/** |
376 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
377 |
* map. |
* {@link AttributeMetadataImpl} map. |
378 |
* |
* |
379 |
* @param amdMap |
* @param amdMap |
380 |
* map of attribute meta data |
* map of attribute meta data |
381 |
*/ |
*/ |
382 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
383 |
final AttributeMetadataMap amdMap) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) { |
384 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
385 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
386 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
387 |
return element; |
return element; |
388 |
} |
} |
389 |
|
|
390 |
/** |
/** |
391 |
* Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL. |
* Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL. |
392 |
* |
* |
393 |
* @param amdMap |
* @param amdMap |
394 |
* map of {@link AttributeMetadata} |
* map of {@link AttributeMetadataImpl} |
395 |
* @param documentUrl |
* @param documentUrl |
396 |
* {@link URL} to store the XML |
* {@link URL} to store the XML |
397 |
*/ |
*/ |
798 |
} |
} |
799 |
|
|
800 |
/** |
/** |
801 |
* Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata |
* Loads a {@linkplain Style SLD-Style} and a |
802 |
* AttributeMetaData-Map} for a given geo-object (feature) source. The SLD |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given |
803 |
* file must be present. A missing attribute meta-data file is tolerated. |
* geo-object (feature) source. The SLD file must be present. A missing |
804 |
|
* attribute meta-data file is tolerated. |
805 |
* |
* |
806 |
* @param geoObjectURL |
* @param geoObjectURL |
807 |
* URL of the (already read) feature object |
* URL of the (already read) feature object |
844 |
|
|
845 |
/** |
/** |
846 |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
847 |
* {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd} |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a {@code |
848 |
* file for a given geo-object (feature) source. The SLD file must be |
* .amd} file for a given geo-object (feature) source. The SLD file must be |
849 |
* present. A missing attribute meta-data file is tolerated. |
* present. A missing attribute meta-data file is tolerated. |
850 |
* |
* |
851 |
* @param geoObjectURL |
* @param geoObjectURL |
905 |
|
|
906 |
/** |
/** |
907 |
* Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the |
* Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the |
908 |
* meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a |
* meta data ({@link RasterLegendData} or {@link AttributeMetadataImpl}) to |
909 |
* {@code .rld} or {@code .amd} file. for a given geo-object source. |
* a {@code .rld} or {@code .amd} file. for a given geo-object source. |
910 |
* |
* |
911 |
* @param style |
* @param style |
912 |
* style to save |
* style to save |
922 |
} |
} |
923 |
|
|
924 |
/** |
/** |
925 |
|
* *If appended to the name of a rule, this rule shall not be shown in the |
926 |
|
* legend |
927 |
|
*/ |
928 |
|
public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND"; |
929 |
|
|
930 |
|
/** |
931 |
* Creates a {@link JPanel} that shows a legend for a list of |
* Creates a {@link JPanel} that shows a legend for a list of |
932 |
* {@link FeatureTypeStyle}s and a targeted featureType |
* {@link FeatureTypeStyle}s and a targeted featureType |
933 |
* |
* |
958 |
final List<Rule> rules = ftStyle.rules(); |
final List<Rule> rules = ftStyle.rules(); |
959 |
for (final Rule rule : rules) { |
for (final Rule rule : rules) { |
960 |
|
|
961 |
|
// Check if this RULE shall actually appear in the legend |
962 |
|
if (rule.getName() != null |
963 |
|
&& rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT)) |
964 |
|
continue; |
965 |
|
|
966 |
/** |
/** |
967 |
* Let's not create a hbox for Rules that only contain |
* Let's not create a hbox for Rules that only contain |
968 |
* TextSymbolizers |
* TextSymbolizers |
1248 |
* After loading an atlas, the AttribteMetaData contains whatever is written |
* After loading an atlas, the AttribteMetaData contains whatever is written |
1249 |
* in the XML. But the DBF may have changed! |
* in the XML. But the DBF may have changed! |
1250 |
*/ |
*/ |
1251 |
public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap, |
public static void checkAttribMetaData( |
1252 |
|
AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap, |
1253 |
SimpleFeatureType schema) { |
SimpleFeatureType schema) { |
1254 |
|
|
1255 |
|
if (schema == null) |
1256 |
|
throw new IllegalArgumentException("schmema may not be null!"); |
1257 |
|
|
1258 |
ArrayList<Name> willRemove = new ArrayList<Name>(); |
ArrayList<Name> willRemove = new ArrayList<Name>(); |
1259 |
|
|
1260 |
// 1. Check.. all attributes in the atm should be in the schema as well. |
// 1. Check.. all attributes in the atm should be in the schema as well. |
1261 |
// maybe correct some upperCase/loweCase stuff |
// maybe correct some upperCase/loweCase stuff |
1262 |
|
|
1263 |
for (AttributeMetadata atm : attributeMetaDataMap.values()) { |
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1264 |
|
|
1265 |
AttributeDescriptor foundDescr = schema |
AttributeDescriptor foundDescr = schema |
1266 |
.getDescriptor(atm.getName()); |
.getDescriptor(atm.getName()); |
1267 |
if (foundDescr == null) { |
if (foundDescr == null) { |
1268 |
Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
1269 |
atm.getLocalName()); |
atm.getLocalName()); |
1270 |
if (bestMatch == null) |
if (bestMatch == null) |
1271 |
willRemove.add(atm.getName()); |
willRemove.add(atm.getName()); |
1279 |
|
|
1280 |
// Remove the ones that were not findable in the schema |
// Remove the ones that were not findable in the schema |
1281 |
for (Name removeName : willRemove) { |
for (Name removeName : willRemove) { |
1282 |
if (attributeMetaDataMap.remove(removeName) == null){ |
if (attributeMetaDataMap.remove(removeName) == null) { |
1283 |
LOGGER.warn("removing the AMData didn't work"); |
LOGGER.warn("removing the AMData didn't work"); |
1284 |
} |
} |
1285 |
} |
} |
1289 |
if (ad instanceof GeometryDescriptor) |
if (ad instanceof GeometryDescriptor) |
1290 |
continue; |
continue; |
1291 |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1292 |
attributeMetaDataMap.put(ad.getName(), new AttributeMetadata( |
attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()), |
1293 |
ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap |
new AttributeMetadataImpl(ad, schema |
1294 |
.getLanguages())); |
.getAttributeDescriptors().indexOf(ad), |
1295 |
|
attributeMetaDataMap.getLanguages())); |
1296 |
} |
} |
1297 |
} |
} |
1298 |
|
} |
1299 |
|
|
1300 |
|
/** |
1301 |
|
* Checks every attribute name in the {@link AttributeMetadataMap} for its |
1302 |
|
* binding type. It the type is textual, add the mrpty string as a NODATA |
1303 |
|
* value. |
1304 |
|
* |
1305 |
|
* @param attributeMetaDataMap |
1306 |
|
* @param schema |
1307 |
|
*/ |
1308 |
|
public static void addEmptyStringToAllTextualAttributes( |
1309 |
|
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1310 |
|
SimpleFeatureType schema) { |
1311 |
|
|
1312 |
|
for (Name name : attributeMetaDataMap.keySet()) { |
1313 |
|
if (String.class.isAssignableFrom(schema.getDescriptor(name) |
1314 |
|
.getType().getBinding())) { |
1315 |
|
attributeMetaDataMap.get(name).getNodataValues().add(""); |
1316 |
|
} |
1317 |
|
} |
1318 |
} |
} |
1319 |
|
|
1320 |
|
/** |
1321 |
|
* @return a nicely formatted String containing all NODATA values of any |
1322 |
|
* {@link AttributeMetadataInterface} object. Strings are quoted so that any |
1323 |
|
* empty {@link String} can be seen. |
1324 |
|
*/ |
1325 |
|
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
1326 |
|
String nicelyFormatted = ""; |
1327 |
|
if (nodataValuesList != null) { |
1328 |
|
if (nodataValuesList.size() == 0) |
1329 |
|
nicelyFormatted = ""; |
1330 |
|
else { |
1331 |
|
for (Object ndo : nodataValuesList) { |
1332 |
|
if (ndo instanceof String) |
1333 |
|
nicelyFormatted += "\"" + ndo + "\""; |
1334 |
|
else |
1335 |
|
nicelyFormatted += ndo.toString(); |
1336 |
|
|
1337 |
|
nicelyFormatted += ","; |
1338 |
|
} |
1339 |
|
// Remove the extra comma |
1340 |
|
nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted |
1341 |
|
.length() - 1); |
1342 |
|
} |
1343 |
|
} |
1344 |
|
return nicelyFormatted; |
1345 |
|
} |
1346 |
} |
} |