/[schmitzm]/trunk/src/skrueger/geotools/StyledLayerUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledLayerUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 694 by alfonx, Fri Feb 12 11:28:41 2010 UTC revision 769 by alfonx, Sun Mar 21 11:02:34 2010 UTC
# Line 46  import java.text.DecimalFormat; Line 46  import java.text.DecimalFormat;
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;
# Line 92  import schmitzm.lang.LangUtil; Line 93  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.AttributeMetadata;
96    import skrueger.AttributeMetadataImpl;
97  import skrueger.RasterLegendData;  import skrueger.RasterLegendData;
98  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
99    
# Line 252  public class StyledLayerUtil { Line 254  public class StyledLayerUtil {
254           *            TODO replace with           *            TODO replace with
255           *            {@link AttributeMetadataMap#sortedValuesVisibleOnly()}           *            {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
256           */           */
257          public static AttributeMetadataMap getVisibleAttributeMetaData(          public static AttributeMetadataMap<? extends AttributeMetadata > getVisibleAttributeMetaData(
258                          final AttributeMetadataMap amdMap, final boolean visible) {                          final AttributeMetadataMap<? extends AttributeMetadata> amdMap,
259                            final boolean visible) {
260                  final AttributeMetadataMap filteredMap = new AttributeMetadataMap(  
261                                  amdMap.getLanguages());                  final AttributeMetadataMap<AttributeMetadata> filteredMap = (AttributeMetadataMap<AttributeMetadata>) amdMap.clone();
262                    if (filteredMap.size() > 0 ) {
263                            filteredMap.clear(); // Just in case the close copies the contents
264                    }
265                    
266                  for (final AttributeMetadata amd : amdMap.values())                  for (final AttributeMetadata amd : amdMap.values())
267                          if (amd.isVisible() == visible)                          if (amd.isVisible() == visible)
268                                  filteredMap.put(amd.getName(), amd);                                  filteredMap.put(amd.getName(), amd);
# Line 265  public class StyledLayerUtil { Line 271  public class StyledLayerUtil {
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,
# Line 277  public class StyledLayerUtil { Line 283  public class StyledLayerUtil {
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
# Line 298  public class StyledLayerUtil { Line 305  public class StyledLayerUtil {
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
# Line 339  public class StyledLayerUtil { Line 346  public class StyledLayerUtil {
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           */           */
# Line 366  public class StyledLayerUtil { Line 373  public class StyledLayerUtil {
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 AttributeMetadata> 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 AttributeMetadata amd : amdMap.values())
386                          element.addContent(createAttributeMetaDataElement(amd));                          element.addContent(createAttributeMetaDataElement(amd));
# Line 381  public class StyledLayerUtil { Line 388  public class StyledLayerUtil {
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           */           */
# Line 791  public class StyledLayerUtil { Line 798  public class StyledLayerUtil {
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
# Line 836  public class StyledLayerUtil { Line 844  public class StyledLayerUtil {
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
# Line 897  public class StyledLayerUtil { Line 905  public class StyledLayerUtil {
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
# Line 951  public class StyledLayerUtil { Line 959  public class StyledLayerUtil {
959                          for (final Rule rule : rules) {                          for (final Rule rule : rules) {
960    
961                                  // Check if this RULE shall actually appear in the legend                                  // Check if this RULE shall actually appear in the legend
962                                  if (rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))                                  if (rule.getName() != null
963                                                    && rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))
964                                          continue;                                          continue;
965    
966                                  /**                                  /**
# Line 1240  public class StyledLayerUtil { Line 1249  public class StyledLayerUtil {
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(          public static void checkAttribMetaData(
1252                          AttributeMetadataMap attributeMetaDataMap, SimpleFeatureType schema) {                          AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
1253                            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    
# Line 1276  public class StyledLayerUtil { Line 1289  public class StyledLayerUtil {
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(ad.getName(),
1293                                                  ad, schema.getAttributeDescriptors().indexOf(ad),                                                  new AttributeMetadataImpl(ad, schema
1294                                                  attributeMetaDataMap.getLanguages()));                                                                  .getAttributeDescriptors().indexOf(ad),
1295                                                                    attributeMetaDataMap.getLanguages()));
1296                          }                          }
1297                  }                  }
1298          }          }
# Line 1292  public class StyledLayerUtil { Line 1306  public class StyledLayerUtil {
1306           * @param schema           * @param schema
1307           */           */
1308          public static void addEmptyStringToAllTextualAttributes(          public static void addEmptyStringToAllTextualAttributes(
1309                          AttributeMetadataMap attributeMetaDataMap, SimpleFeatureType schema) {                          AttributeMetadataMap<? extends AttributeMetadata> attributeMetaDataMap,
1310                            SimpleFeatureType schema) {
1311    
1312                  for (Name name : attributeMetaDataMap.keySet()) {                  for (Name name : attributeMetaDataMap.keySet()) {
1313                          if (String.class.isAssignableFrom(schema.getDescriptor(name)                          if (String.class.isAssignableFrom(schema.getDescriptor(name)
# Line 1301  public class StyledLayerUtil { Line 1316  public class StyledLayerUtil {
1316                          }                          }
1317                  }                  }
1318          }          }
1319    
1320            /**
1321             * @return a nicely formatted String containing all NODATA values of any
1322             *         {@link AttributeMetadata} 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  }  }

Legend:
Removed from v.694  
changed lines
  Added in v.769

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26