25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
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; |
|
import skrueger.AttributeMetadata; |
|
95 |
import skrueger.AttributeMetadataImpl; |
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<? extends AttributeMetadata > getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData( |
258 |
final AttributeMetadataMap<? extends AttributeMetadata> amdMap, |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
259 |
final boolean visible) { |
final boolean visible) { |
260 |
|
|
261 |
final AttributeMetadataMap<AttributeMetadata> filteredMap = (AttributeMetadataMap<AttributeMetadata>) amdMap.clone(); |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone(); |
262 |
if (filteredMap.size() > 0 ) { |
if (filteredMap.size() > 0 ) { |
263 |
filteredMap.clear(); // Just in case the close copies the contents |
filteredMap.clear(); // Just in case the close copies the contents |
264 |
} |
} |
265 |
|
|
266 |
for (final AttributeMetadata amd : amdMap.values()) |
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 |
|
|
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"); |
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())); |
380 |
* map of attribute meta data |
* map of attribute meta data |
381 |
*/ |
*/ |
382 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
383 |
final AttributeMetadataMap<? extends AttributeMetadata> 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 |
} |
} |
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 |
* |
* |
934 |
|
* @param style |
935 |
|
* The Style to presented in this legend |
936 |
* @param featureType |
* @param featureType |
937 |
* If this a legend for Point, Polygon or Line? |
* If this a legend for Point, Polygon or Line? |
|
* @param list |
|
|
* The Styles to presented in this legend |
|
938 |
* |
* |
939 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
940 |
* Krüger</a> |
* Krüger</a> |
941 |
*/ |
*/ |
942 |
public static JPanel createLegendPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
943 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
944 |
final int iconHeight) { |
final int iconHeight) { |
945 |
|
|
995 |
return panel; |
return panel; |
996 |
} |
} |
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
/** |
/** |
1002 |
* Creates a {@link JComponent} that contains a legend for a given |
* Creates a {@link JComponent} that contains a legend for a given |
1003 |
* rasterLayer and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
1004 |
* |
* |
1005 |
* @param style |
* @param style |
1006 |
* if <code>null</code>, the default {@link Style} is extracetd |
* if <code>null</code>, the default {@link Style} is extracetd |
1007 |
* from the {@link StyledRasterInterface} |
* from the {@link StyledRasterInterface} |
1008 |
*/ |
*/ |
1009 |
public static JPanel createLegendPanel( |
public static JPanel createLegendSwingPanel( |
1010 |
final StyledRasterInterface<?> styledRaster, Style style, |
final StyledRasterInterface<?> styledRaster, Style style, |
1011 |
final int iconWidth, final int iconHeight) { |
final int iconWidth, final int iconHeight) { |
1012 |
|
|
1137 |
|
|
1138 |
return panel; |
return panel; |
1139 |
} |
} |
1140 |
|
|
1141 |
|
|
1142 |
|
|
1143 |
/** |
/** |
1144 |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
1265 |
// 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. |
1266 |
// maybe correct some upperCase/loweCase stuff |
// maybe correct some upperCase/loweCase stuff |
1267 |
|
|
1268 |
for (AttributeMetadata atm : attributeMetaDataMap.values()) { |
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1269 |
|
|
1270 |
AttributeDescriptor foundDescr = schema |
AttributeDescriptor foundDescr = schema |
1271 |
.getDescriptor(atm.getName()); |
.getDescriptor(atm.getName()); |
1272 |
if (foundDescr == null) { |
if (foundDescr == null) { |
1273 |
Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
1274 |
atm.getLocalName()); |
atm.getLocalName()); |
1275 |
if (bestMatch == null) |
if (bestMatch == null) |
1276 |
willRemove.add(atm.getName()); |
willRemove.add(atm.getName()); |
1294 |
if (ad instanceof GeometryDescriptor) |
if (ad instanceof GeometryDescriptor) |
1295 |
continue; |
continue; |
1296 |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1297 |
attributeMetaDataMap.put(ad.getName(), |
attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()), |
1298 |
new AttributeMetadataImpl(ad, schema |
new AttributeMetadataImpl(ad, schema |
1299 |
.getAttributeDescriptors().indexOf(ad), |
.getAttributeDescriptors().indexOf(ad), |
1300 |
attributeMetaDataMap.getLanguages())); |
attributeMetaDataMap.getLanguages())); |
1311 |
* @param schema |
* @param schema |
1312 |
*/ |
*/ |
1313 |
public static void addEmptyStringToAllTextualAttributes( |
public static void addEmptyStringToAllTextualAttributes( |
1314 |
AttributeMetadataMap<? extends AttributeMetadata> attributeMetaDataMap, |
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1315 |
SimpleFeatureType schema) { |
SimpleFeatureType schema) { |
1316 |
|
|
1317 |
for (Name name : attributeMetaDataMap.keySet()) { |
for (Name name : attributeMetaDataMap.keySet()) { |
1324 |
|
|
1325 |
/** |
/** |
1326 |
* @return a nicely formatted String containing all NODATA values of any |
* @return a nicely formatted String containing all NODATA values of any |
1327 |
* {@link AttributeMetadata} object. Strings are quoted so that any |
* {@link AttributeMetadataInterface} object. Strings are quoted so that any |
1328 |
* empty {@link String} can be seen. |
* empty {@link String} can be seen. |
1329 |
*/ |
*/ |
1330 |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |