/[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

branches/2.0-RC2/src/skrueger/geotools/StyledLayerUtil.java revision 658 by alfonx, Wed Feb 3 15:32:21 2010 UTC trunk/src/skrueger/geotools/StyledLayerUtil.java revision 1225 by alfonx, Wed Nov 3 17:05:42 2010 UTC
# Line 25  Line 25 
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    
# Line 38  import java.awt.image.BufferedImage; Line 38  import java.awt.image.BufferedImage;
38  import java.awt.image.ColorModel;  import java.awt.image.ColorModel;
39  import java.awt.image.ComponentColorModel;  import java.awt.image.ComponentColorModel;
40  import java.awt.image.DataBuffer;  import java.awt.image.DataBuffer;
41    import java.awt.image.IndexColorModel;
42  import java.io.File;  import java.io.File;
43  import java.io.FileNotFoundException;  import java.io.FileNotFoundException;
44  import java.io.FileWriter;  import java.io.FileWriter;
# Line 46  import java.text.DecimalFormat; Line 47  import java.text.DecimalFormat;
47  import java.util.ArrayList;  import java.util.ArrayList;
48  import java.util.List;  import java.util.List;
49  import java.util.Map;  import java.util.Map;
50    import java.util.Set;
51    
52  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
53  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
# Line 89  import schmitzm.geotools.feature.Feature Line 91  import schmitzm.geotools.feature.Feature
91  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
92  import schmitzm.io.IOUtil;  import schmitzm.io.IOUtil;
93  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
94    import schmitzm.swing.ExceptionDialog;
95  import schmitzm.swing.JPanel;  import schmitzm.swing.JPanel;
96  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
97  import skrueger.AttributeMetadata;  import skrueger.AttributeMetadataImpl;
98    import skrueger.AttributeMetadataInterface;
99  import skrueger.RasterLegendData;  import skrueger.RasterLegendData;
100  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
101    
# Line 252  public class StyledLayerUtil { Line 256  public class StyledLayerUtil {
256           *            TODO replace with           *            TODO replace with
257           *            {@link AttributeMetadataMap#sortedValuesVisibleOnly()}           *            {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
258           */           */
259          public static AttributeMetadataMap getVisibleAttributeMetaData(          public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData(
260                          final AttributeMetadataMap amdMap, final boolean visible) {                          final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap,
261                            final boolean visible) {
262    
263                  final AttributeMetadataMap filteredMap = new AttributeMetadataMap(                  final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap
264                                  amdMap.getLanguages());                                  .clone();
265                  for (final AttributeMetadata amd : amdMap.values())                  if (filteredMap.size() > 0) {
266                            filteredMap.clear(); // Just in case the close copies the contents
267                    }
268    
269                    for (final AttributeMetadataInterface amd : amdMap.values())
270                          if (amd.isVisible() == visible)                          if (amd.isVisible() == visible)
271                                  filteredMap.put(amd.getName(), amd);                                  filteredMap.put(amd.getName(), amd);
272    
# Line 265  public class StyledLayerUtil { Line 274  public class StyledLayerUtil {
274          }          }
275    
276          /**          /**
277           * Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}.           * Parses a {@link AttributeMetadataImpl} object from an JDOM-
278           * This method works like {@link           * {@link Element}. This method works like {@link
279           * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.           * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
280           *           *
281           * 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 286  public class StyledLayerUtil {
286           * @param element           * @param element
287           *            {@link Element} to parse           *            {@link Element} to parse
288           */           */
289          public static AttributeMetadata parseAttributeMetaData(final Element element) {          public static AttributeMetadataImpl parseAttributeMetaData(
290                  final String namespace = String.valueOf(element                          final Element element) {
291                                  .getAttributeValue("namespace"));                  final String namespace = element.getAttributeValue("namespace");
292                  final String localname = String.valueOf(element                  final String localname = element.getAttributeValue("localname");
293                                  .getAttributeValue("localname"));                  final NameImpl aName = new NameImpl(namespace, localname);
                 final Name aName = new NameImpl(namespace, localname);  
294                  final Boolean visible = Boolean.valueOf(element                  final Boolean visible = Boolean.valueOf(element
295                                  .getAttributeValue("visible"));                                  .getAttributeValue("visible"));
296                  final String unit = element.getAttributeValue("unit");                  final String unit = element.getAttributeValue("unit");
# Line 298  public class StyledLayerUtil { Line 306  public class StyledLayerUtil {
306                          else if (childElement.getName().equals("desc"))                          else if (childElement.getName().equals("desc"))
307                                  desc = parseTranslation(childElement);                                  desc = parseTranslation(childElement);
308                  }                  }
309                  return new AttributeMetadata(aName, visible, name, desc, unit);                  return new AttributeMetadataImpl(aName, visible, name, desc, unit);
310          }          }
311    
312          /**          /**
313           * Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with           * Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element}
314           * {@code <attribute>}-childs.           * with {@code <attribute>}-childs.
315           *           *
316           * @param element           * @param element
317           *            {@link Element} to parse           *            {@link Element} to parse
318           *                       *
319           *            TODO Since GP 1.3 the {@link AttributeMetadata} class has more           *            TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
320           *            attributes which are not used by Xulu/ISDSS. GP           *            more attributes which are not used by Xulu/ISDSS. GP
321           *            exports/imports the AMD via AMLExporter and AMLImporter           *            exports/imports the AMD via AMLExporter and AMLImporter
322           *            classes. (SK, 3.2.2010)    *                       *            classes. (SK, 3.2.2010) *
323           */           */
324          public static AttributeMetadataMap parseAttributeMetaDataMap(          public static AttributeMetadataMap parseAttributeMetaDataMap(
325                          final Element element) {                          final Element element) {
326                  final AttributeMetadataMap metaData = new AttributeMetadataMap();                  final AttributeMetadataMap metaData = new AttributeMetadataImplMap();
327                  final List<Element> attributesElements = element                  final List<Element> attributesElements = element
328                                  .getChildren(ELEM_NAME_ATTRIBUTE);                                  .getChildren(ELEM_NAME_ATTRIBUTE);
329                  for (final Element attibuteElement : attributesElements) {                  for (final Element attibuteElement : attributesElements) {
330                          final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);                          final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement);
331                          metaData.put(attrMetaData.getName(), attrMetaData);                          metaData.put(attrMetaData.getName(), attrMetaData);
332                  }                  }
333                  return metaData;                  return metaData;
334          }          }
335    
336          /**          /**
337           * Loads a {@link AttributeMetadata} object from an URL.           * Loads a {@link AttributeMetadataImpl} object from an URL.
338           *           *
339           * @param documentUrl           * @param documentUrl
340           *            {@link URL} to parse           *            {@link URL} to parse
# Line 339  public class StyledLayerUtil { Line 347  public class StyledLayerUtil {
347          }          }
348    
349          /**          /**
350           * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}           * Creates an JDOM {@link Element} for the given
351           * object.           * {@link AttributeMetadataImpl} object.
352           *           *
353           * @param amd           * @param amd
354           *            meta data for one attribute           *            meta data for one attribute
355           *           *
356           *            TODO Since GP 1.3 the {@link AttributeMetadata} class has more           *            TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
357           *            attributes which are not used by Xulu/ISDSS. GP           *            more attributes which are not used by Xulu/ISDSS. GP
358           *            exports/imports the AMD via AMLExporter and AMLImporter           *            exports/imports the AMD via AMLExporter and AMLImporter
359           *            classes. (SK, 3.2.2010)           *            classes. (SK, 3.2.2010)
360           */           */
361          public static Element createAttributeMetaDataElement(          public static Element createAttributeMetaDataElement(
362                          final AttributeMetadata amd) {                          final AttributeMetadataInterface amd) {
363                  final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);                  final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
364                  element.setAttribute("namespace", String.valueOf(amd.getName()                  element.setAttribute("namespace",
365                                  .getNamespaceURI()));                                  String.valueOf(amd.getName().getNamespaceURI()));
366                  element.setAttribute("localname", String.valueOf(amd.getLocalName()));                  element.setAttribute("localname", String.valueOf(amd.getLocalName()));
367                  element.setAttribute("visible", String.valueOf(amd.isVisible()));                  element.setAttribute("visible", String.valueOf(amd.isVisible()));
368                  element.setAttribute("unit", amd.getUnit());                  element.setAttribute("unit", amd.getUnit());
# Line 366  public class StyledLayerUtil { Line 374  public class StyledLayerUtil {
374          }          }
375    
376          /**          /**
377           * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}           * Creates an JDOM {@link Element} for the given
378           * map.           * {@link AttributeMetadataImpl} map.
379           *           *
380           * @param amdMap           * @param amdMap
381           *            map of attribute meta data           *            map of attribute meta data
382           */           */
383          public static Element createAttributeMetaDataMapElement(          public static Element createAttributeMetaDataMapElement(
384                          final AttributeMetadataMap amdMap) {                          final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) {
385                  final Element element = new Element(ELEM_NAME_AMD, AMLURI);                  final Element element = new Element(ELEM_NAME_AMD, AMLURI);
386                  for (final AttributeMetadata amd : amdMap.values())                  for (final AttributeMetadataInterface amd : amdMap.values())
387                          element.addContent(createAttributeMetaDataElement(amd));                          element.addContent(createAttributeMetaDataElement(amd));
388                  return element;                  return element;
389          }          }
390    
391          /**          /**
392           * Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL.           * Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL.
393           *           *
394           * @param amdMap           * @param amdMap
395           *            map of {@link AttributeMetadata}           *            map of {@link AttributeMetadataImpl}
396           * @param documentUrl           * @param documentUrl
397           *            {@link URL} to store the XML           *            {@link URL} to store the XML
398           */           */
# Line 686  public class StyledLayerUtil { Line 694  public class StyledLayerUtil {
694           * @param styledObject           * @param styledObject
695           *            a styled object           *            a styled object
696           * @return {@code StyledLayerStyle<RasterLegendData>} for           * @return {@code StyledLayerStyle<RasterLegendData>} for
697           *         {@link StyledGridCoverageInterface} or {@code           *         {@link StyledGridCoverageInterface} or
698           *         StyledLayerStyle<Map<Integer,AttributeMetaData>>} for           *         {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
699           *         {@link StyledFeatureCollectionInterface}           *         {@link StyledFeatureCollectionInterface}
700           */           */
701          public static StyledLayerStyle<?> getStyledLayerStyle(          public static StyledLayerStyle<?> getStyledLayerStyle(
# Line 791  public class StyledLayerUtil { Line 799  public class StyledLayerUtil {
799          }          }
800    
801          /**          /**
802           * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata           * Loads a {@linkplain Style SLD-Style} and a
803           * AttributeMetaData-Map} for a given geo-object (feature) source. The SLD           * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given
804           * file must be present. A missing attribute meta-data file is tolerated.           * geo-object (feature) source. The SLD file must be present. A missing
805             * attribute meta-data file is tolerated.
806           *           *
807           * @param geoObjectURL           * @param geoObjectURL
808           *            URL of the (already read) feature object           *            URL of the (already read) feature object
# Line 836  public class StyledLayerUtil { Line 845  public class StyledLayerUtil {
845    
846          /**          /**
847           * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and           * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
848           * {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd}           * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a
849           * file for a given geo-object (feature) source. The SLD file must be           * {@code .amd} file for a given geo-object (feature) source. The SLD file
850           * present. A missing attribute meta-data file is tolerated.           * must be present. A missing attribute meta-data file is tolerated.
851           *           *
852           * @param geoObjectURL           * @param geoObjectURL
853           *            URL of the (already read) feature object           *            URL of the (already read) feature object
# Line 872  public class StyledLayerUtil { Line 881  public class StyledLayerUtil {
881                  // Store the SLD                  // Store the SLD
882                  final Style sldStyle = style.getGeoObjectStyle();                  final Style sldStyle = style.getGeoObjectStyle();
883                  if (sldStyle != null) {                  if (sldStyle != null) {
884                          StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File(                          StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File(
885                                          geoObjectURL.toURI()), sldExt));                                          geoObjectURL.toURI()), sldExt));
886                  }                  }
887    
# Line 880  public class StyledLayerUtil { Line 889  public class StyledLayerUtil {
889                  final T metaData = style.getMetaData();                  final T metaData = style.getMetaData();
890                  if (metaData != null) {                  if (metaData != null) {
891                          if (metaData instanceof RasterLegendData) {                          if (metaData instanceof RasterLegendData) {
892                                  saveRasterLegendData((RasterLegendData) metaData, IOUtil                                  saveRasterLegendData((RasterLegendData) metaData,
893                                                  .changeUrlExt(geoObjectURL, mdExt));                                                  IOUtil.changeUrlExt(geoObjectURL, mdExt));
894                                  // } else if ( metaData instanceof                                  // } else if ( metaData instanceof
895                                  // Map<Integer,AttributeMetaData> ) { // LEIDER NICHT                                  // Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
896                                  // KOMPILIERBAR!!                                  // KOMPILIERBAR!!
# Line 897  public class StyledLayerUtil { Line 906  public class StyledLayerUtil {
906    
907          /**          /**
908           * 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
909           * meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a           * meta data ({@link RasterLegendData} or {@link AttributeMetadataImpl}) to
910           * {@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.
911           *           *
912           * @param style           * @param style
913           *            style to save           *            style to save
# Line 914  public class StyledLayerUtil { Line 923  public class StyledLayerUtil {
923          }          }
924    
925          /**          /**
926             * *If appended to the name of a rule, this rule shall not be shown in the
927             * legend
928             */
929            public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
930    
931            /**
932           * Creates a {@link JPanel} that shows a legend for a list of           * Creates a {@link JPanel} that shows a legend for a list of
933           * {@link FeatureTypeStyle}s and a targeted featureType           * {@link FeatureTypeStyle}s and a targeted featureType
934           *           *
935             * @param style
936             *            The Style to presented in this legend
937           * @param featureType           * @param featureType
938           *            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  
939           *           *
940           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a>
          *         Kr&uuml;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    
946                    if (featureType == null) {
947                            ExceptionDialog.show(new IllegalStateException(
948                                            "featureType is null!"));
949                            return new JPanel();
950                    }
951    
952                  final List<FeatureTypeStyle> list = style.featureTypeStyles();                  final List<FeatureTypeStyle> list = style.featureTypeStyles();
953    
954                  final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));                  final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
# Line 944  public class StyledLayerUtil { Line 964  public class StyledLayerUtil {
964                          final List<Rule> rules = ftStyle.rules();                          final List<Rule> rules = ftStyle.rules();
965                          for (final Rule rule : rules) {                          for (final Rule rule : rules) {
966    
967                                    // Check if this RULE shall actually appear in the legend
968                                    if (rule.getName() != null
969                                                    && rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))
970                                            continue;
971    
972                                  /**                                  /**
973                                   * Let's not create a hbox for Rules that only contain                                   * Let's not create a hbox for Rules that only contain
974                                   * TextSymbolizers                                   * TextSymbolizers
# Line 978  public class StyledLayerUtil { Line 1003  public class StyledLayerUtil {
1003    
1004          /**          /**
1005           * Creates a {@link JComponent} that contains a legend for a given           * Creates a {@link JComponent} that contains a legend for a given
1006           * rasterLayer and a given {@link Style}.           * {@link StyledRasterInterface} and a given {@link Style}.
1007           *           *
1008           * @param style           * @param style
1009           *            if <code>null</code>, the default {@link Style} is extracetd           *            if <code>null</code>, the default {@link Style} is extracetd
1010           *            from the {@link StyledRasterInterface}           *            from the {@link StyledRasterInterface}
1011           */           */
1012          public static JPanel createLegendPanel(          public static JPanel createLegendSwingPanel(
1013                          final StyledRasterInterface<?> styledRaster, Style style,                          final StyledRasterInterface<?> styledRaster, Style style,
1014                          final int iconWidth, final int iconHeight) {                          final int iconWidth, final int iconHeight) {
1015    
# Line 1070  public class StyledLayerUtil { Line 1095  public class StyledLayerUtil {
1095                                  final GridCoverage2D sampleCov = sampleRasters.get(rValue);                                  final GridCoverage2D sampleCov = sampleRasters.get(rValue);
1096                                  GridCoverageRenderer renderer;                                  GridCoverageRenderer renderer;
1097                                  try {                                  try {
1098                                          renderer = new GridCoverageRenderer(sampleCov                                          renderer = new GridCoverageRenderer(
1099                                                          .getCoordinateReferenceSystem(), JTSUtil                                                          sampleCov.getCoordinateReferenceSystem(),
1100                                                          .createEnvelope(sampleCov.getEnvelope()),                                                          JTSUtil.createEnvelope(sampleCov.getEnvelope()),
1101                                                          new Rectangle(iconWidth, iconHeight),                                                          new Rectangle(iconWidth, iconHeight),
1102                                                          (AffineTransform) null);                                                          (AffineTransform) null);
1103                                  } catch (final Exception e1) {                                  } catch (final Exception e1) {
# Line 1129  public class StyledLayerUtil { Line 1154  public class StyledLayerUtil {
1154                          if (geoObject instanceof GridCoverage2D) {                          if (geoObject instanceof GridCoverage2D) {
1155                                  final GridCoverage2D cov = (GridCoverage2D) geoObject;                                  final GridCoverage2D cov = (GridCoverage2D) geoObject;
1156                                  colorModel = cov.getRenderedImage().getColorModel();                                  colorModel = cov.getRenderedImage().getColorModel();
1157                          } else if (styledGrid instanceof StyledRasterPyramidInterface) {                          } else if (styledGrid instanceof StyledGridCoverageReaderInterface) {
1158    
1159                                  final Parameter readGG = new Parameter(                                  final Parameter readGG = new Parameter(
1160                                                  AbstractGridFormat.READ_GRIDGEOMETRY2D);                                                  AbstractGridFormat.READ_GRIDGEOMETRY2D);
1161    
1162                                  final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope(                                  final ReferencedEnvelope mapExtend = new ReferencedEnvelope(
1163                                                  styledGrid.getEnvelope(), styledGrid.getCrs());                                                  styledGrid.getEnvelope(), styledGrid.getCrs());
1164    
1165                                  readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(                                  readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
1166                                                  new Rectangle(0, 0, 1, 1)), mapExtend));                                                  new Rectangle(0, 0, 1, 1)), mapExtend));
1167    
1168                                  final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;                                  AbstractGridCoverage2DReader aReader;
1169                                    if (geoObject instanceof FeatureCollection) {
1170                                            final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
1171    
1172                                            aReader = (AbstractGridCoverage2DReader) FeatureUtil
1173                                                            .getWrappedGeoObject(rFc);
1174    
1175                                    } else if (geoObject instanceof AbstractGridCoverage2DReader) {
1176                                            aReader = (AbstractGridCoverage2DReader) geoObject;
1177    
1178                                    } else
1179                                            throw new RuntimeException("need a reader...");
1180                                    //
1181    
                                 final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil  
                                                 .getWrappedGeoObject(rFc);  
1182                                  final GridCoverage2D cov = (GridCoverage2D) aReader                                  final GridCoverage2D cov = (GridCoverage2D) aReader
1183                                                  .read(new GeneralParameterValue[] { readGG });                                                  .read(new GeneralParameterValue[] { readGG });
1184                                  colorModel = cov.getRenderedImage().getColorModel();                                  colorModel = cov.getRenderedImage().getColorModel();
# Line 1173  public class StyledLayerUtil { Line 1208  public class StyledLayerUtil {
1208                          return true;                          return true;
1209                  if (colorModel instanceof ComponentColorModel)                  if (colorModel instanceof ComponentColorModel)
1210                          return true;                          return true;
1211                    if (colorModel instanceof IndexColorModel)
1212                            return true;
1213    
1214                  return false;                  return false;
1215          }          }
1216    
# Line 1229  public class StyledLayerUtil { Line 1267  public class StyledLayerUtil {
1267           * After loading an atlas, the AttribteMetaData contains whatever is written           * After loading an atlas, the AttribteMetaData contains whatever is written
1268           * in the XML. But the DBF may have changed!           * in the XML. But the DBF may have changed!
1269           */           */
1270          public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap,          public static void checkAttribMetaData(
1271                            AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
1272                          SimpleFeatureType schema) {                          SimpleFeatureType schema) {
1273    
1274                    if (schema == null)
1275                            throw new IllegalArgumentException("schmema may not be null!");
1276    
1277                  ArrayList<Name> willRemove = new ArrayList<Name>();                  ArrayList<Name> willRemove = new ArrayList<Name>();
1278    
1279                  // 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.
1280                  // maybe correct some upperCase/loweCase stuff                  // maybe correct some upperCase/loweCase stuff
1281    
1282                  for (AttributeMetadata atm : attributeMetaDataMap.values()) {                  for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) {
1283    
1284                          AttributeDescriptor foundDescr = schema                          AttributeDescriptor foundDescr = schema
1285                                          .getDescriptor(atm.getName());                                          .getDescriptor(atm.getName());
1286                          if (foundDescr == null) {                          if (foundDescr == null) {
1287                                  Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,                                  NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(
1288                                                  atm.getLocalName());                                                  schema, atm.getLocalName());
1289                                  if (bestMatch == null)                                  if (bestMatch == null)
1290                                          willRemove.add(atm.getName());                                          willRemove.add(atm.getName());
1291                                  else                                  else
# Line 1256  public class StyledLayerUtil { Line 1298  public class StyledLayerUtil {
1298    
1299                  // Remove the ones that were not findable in the schema                  // Remove the ones that were not findable in the schema
1300                  for (Name removeName : willRemove) {                  for (Name removeName : willRemove) {
1301                          if (attributeMetaDataMap.remove(removeName) == null){                          if (attributeMetaDataMap.remove(removeName) == null) {
1302                                  LOGGER.warn("removing the AMData didn't work");                                  LOGGER.warn("removing the AMData didn't work");
1303                          }                          }
1304                  }                  }
# Line 1266  public class StyledLayerUtil { Line 1308  public class StyledLayerUtil {
1308                          if (ad instanceof GeometryDescriptor)                          if (ad instanceof GeometryDescriptor)
1309                                  continue;                                  continue;
1310                          if (!attributeMetaDataMap.containsKey(ad.getName())) {                          if (!attributeMetaDataMap.containsKey(ad.getName())) {
1311                                  attributeMetaDataMap.put(ad.getName(), new AttributeMetadata(                                  attributeMetaDataMap.put(new NameImpl(ad.getName()
1312                                                  ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap                                                  .getNamespaceURI(), ad.getName().getLocalPart()),
1313                                                                  .getLanguages()));                                                  new AttributeMetadataImpl(ad, schema
1314                                                                    .getAttributeDescriptors().indexOf(ad),
1315                                                                    attributeMetaDataMap.getLanguages()));
1316                          }                          }
1317                  }                  }
1318            }
1319    
1320            /**
1321             * Checks every attribute name in the {@link AttributeMetadataMap} for its
1322             * binding type. It the type is textual, add the mrpty string as a NODATA
1323             * value.
1324             *
1325             * @param attributeMetaDataMap
1326             * @param schema
1327             */
1328            public static void addEmptyStringToAllTextualAttributes(
1329                            AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap,
1330                            SimpleFeatureType schema) {
1331    
1332                    for (Name name : attributeMetaDataMap.keySet()) {
1333                            if (String.class.isAssignableFrom(schema.getDescriptor(name)
1334                                            .getType().getBinding())) {
1335                                    attributeMetaDataMap.get(name).getNodataValues().add("");
1336                            }
1337                    }
1338          }          }
1339    
1340            /**
1341             * @return a nicely formatted String containing all NODATA values of any
1342             *         {@link AttributeMetadataInterface} object. Strings are quoted so
1343             *         that any empty {@link String} can be seen.
1344             */
1345            public static String formatNoDataValues(Set<Object> nodataValuesList) {
1346                    String nicelyFormatted = "";
1347                    if (nodataValuesList != null) {
1348                            if (nodataValuesList.size() == 0)
1349                                    nicelyFormatted = "";
1350                            else {
1351                                    for (Object ndo : nodataValuesList) {
1352                                            if (ndo instanceof String)
1353                                                    nicelyFormatted += "\"" + ndo + "\"";
1354                                            else
1355                                                    nicelyFormatted += ndo.toString();
1356    
1357                                            nicelyFormatted += ",";
1358                                    }
1359                                    // Remove the extra comma
1360                                    nicelyFormatted = nicelyFormatted.substring(0,
1361                                                    nicelyFormatted.length() - 1);
1362                            }
1363                    }
1364                    return nicelyFormatted;
1365            }
1366  }  }

Legend:
Removed from v.658  
changed lines
  Added in v.1225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26