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

trunk/src/skrueger/geotools/StyledMapUtil.java revision 127 by mojays, Sat May 30 14:29:58 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java revision 534 by alfonx, Fri Nov 20 10:28:01 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.io.File;   *
4  import java.io.FileNotFoundException;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.io.FileWriter;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import java.net.URL;   * and the Geotools library.
7  import java.text.DecimalFormat;   *
8  import java.util.HashMap;   * The SCHMITZM project is hosted at:
9  import java.util.List;   * http://wald.intevation.org/projects/schmitzm/
10  import java.util.Map;   *
11  import java.util.SortedMap;   * This program is free software; you can redistribute it and/or
12  import java.util.TreeMap;   * modify it under the terms of the GNU Lesser General Public License
13     * as published by the Free Software Foundation; either version 3
14  import org.apache.log4j.Logger;   * of the License, or (at your option) any later version.
15  import org.geotools.coverage.grid.GridCoverage2D;   *
16  import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;   * This program is distributed in the hope that it will be useful,
17  import org.geotools.feature.FeatureCollection;   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  import org.geotools.map.DefaultMapLayer;   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  import org.geotools.map.MapLayer;   * GNU General Public License for more details.
20  import org.geotools.styling.ColorMap;   *
21  import org.geotools.styling.ColorMapEntry;   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  import org.geotools.styling.RasterSymbolizer;   * along with this program; if not, write to the Free Software
23  import org.geotools.styling.Style;   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  import org.jdom.Document;   * or try this link: http://www.gnu.org/licenses/lgpl.html
25  import org.jdom.Element;   *
26  import org.jdom.input.SAXBuilder;   * Contributors:
27  import org.jdom.output.XMLOutputter;   *     Martin O. J. Schmitz - initial API and implementation
28     *     Stefan A. Krüger - additional utility classes
29  import schmitzm.geotools.styling.StylingUtil;   ******************************************************************************/
30  import schmitzm.io.IOUtil;  package skrueger.geotools;
31  import schmitzm.lang.LangUtil;  
32  import schmitzm.swing.SwingUtil;  import java.awt.Color;
33  import skrueger.AttributeMetaData;  import java.awt.Dimension;
34  import skrueger.RasterLegendData;  import java.awt.Graphics2D;
35  import skrueger.i8n.Translation;  import java.awt.Rectangle;
36    import java.awt.geom.AffineTransform;
37  /**  import java.awt.image.BufferedImage;
38   * This class provides static helper methods for dealing with  import java.awt.image.ColorModel;
39   * {@link StyledMapInterface} stuff.  import java.awt.image.ComponentColorModel;
40   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)  import java.awt.image.DataBuffer;
41   * @version 1.0  import java.io.File;
42   */  import java.io.FileNotFoundException;
43  public class StyledMapUtil {  import java.io.FileWriter;
44    private static final Logger LOGGER = Logger.getLogger(StyledMapUtil.class.getName());  import java.net.URL;
45    private static final SAXBuilder SAX_BUILDER = new SAXBuilder();  import java.text.DecimalFormat;
46    private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();  import java.util.List;
47    import java.util.Map;
48    /** URL for Atlas XML schema */  
49    public static final String AMLURI = "http://www.wikisquare.de/AtlasML";  import javax.swing.BorderFactory;
50    /** Name of the XML Element for the attribute meta data map */  import javax.swing.ImageIcon;
51    public static final String ELEM_NAME_AMD = "attributeMetaData";  import javax.swing.JComponent;
52    /** Name of the XML Element for the raster legend data */  import javax.swing.JLabel;
53    public static final String ELEM_NAME_RLD = "rasterLegendData";  
54    /** Name of the XML Element for an attribute meta data map entry */  import net.miginfocom.swing.MigLayout;
55    public static final String ELEM_NAME_ATTRIBUTE = "dataAttribute";  
56    /** Name of the XML Element for an raster legend data entry */  import org.apache.log4j.Logger;
57    public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";  import org.geotools.coverage.grid.GeneralGridEnvelope;
58    /** Name of the XML Element for a translation */  import org.geotools.coverage.grid.GridCoverage2D;
59    public static final String ELEM_NAME_TRANSLATION = "translation";  import org.geotools.coverage.grid.GridGeometry2D;
60    import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
61    /**  import org.geotools.coverage.grid.io.AbstractGridFormat;
62     * Creates a Geotools {@link MapLayer} from an object. If the object is a  import org.geotools.feature.FeatureCollection;
63     * {@link StyledMapInterface} then its sytle is used. In case of direct  import org.geotools.feature.NameImpl;
64     * Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},  import org.geotools.geometry.jts.ReferencedEnvelope;
65     * {@link FeatureCollection}) a default style is generated.  import org.geotools.map.DefaultMapLayer;
66     * @param object an Object  import org.geotools.map.MapLayer;
67     * @exception Exception if {@code null} is given as object or an error occurs during layer creation  import org.geotools.parameter.Parameter;
68     */  import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
69    public static MapLayer createMapLayer(Object object) throws Exception {  import org.geotools.styling.ColorMap;
70      return createMapLayer(object,null);  import org.geotools.styling.ColorMapEntry;
71    }  import org.geotools.styling.FeatureTypeStyle;
72    import org.geotools.styling.RasterSymbolizer;
73    /**  import org.geotools.styling.Rule;
74     * Creates a Geotools {@link MapLayer} from an object. If the object is a  import org.geotools.styling.Style;
75     * {@link StyledMapInterface} then its sytle is used. In case of direct  import org.jdom.Document;
76     * Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},  import org.jdom.Element;
77     * {@link FeatureCollection}) a default style is generated.  import org.jdom.input.SAXBuilder;
78     * @param object an Object  import org.jdom.output.XMLOutputter;
79     * @param forcedStyle (SLD-)Style to force for the object  import org.opengis.feature.simple.SimpleFeature;
80     * @exception Exception if {@code null} is given as object or an error occurs during layer creation  import org.opengis.feature.simple.SimpleFeatureType;
81     */  import org.opengis.feature.type.Name;
82    public static MapLayer createMapLayer(Object object, Style forcedStyle) throws Exception {  import org.opengis.parameter.GeneralParameterValue;
83      MapLayer layer     = null;  
84      Style    style     = null;  import schmitzm.geotools.JTSUtil;
85      if ( object instanceof StyledMapInterface ) {  import schmitzm.geotools.feature.FeatureUtil;
86        style =  ((StyledMapInterface<?>)object).getStyle();  import schmitzm.geotools.styling.StylingUtil;
87        object = ((StyledMapInterface<?>)object).getGeoObject();  import schmitzm.io.IOUtil;
88      }  import schmitzm.lang.LangUtil;
89      if ( forcedStyle != null )  import schmitzm.swing.JPanel;
90        style = forcedStyle;  import schmitzm.swing.SwingUtil;
91      if ( style == null )  import skrueger.AttributeMetadata;
92        style = StylingUtil.createDefaultStyle(object);  import skrueger.RasterLegendData;
93    import skrueger.i8n.Translation;
94      if (object instanceof GridCoverage2D)  
95        layer = new DefaultMapLayer( (GridCoverage2D) object, style);  /**
96      if (object instanceof AbstractGridCoverage2DReader)   * This class provides static helper methods for dealing with
97        layer = new DefaultMapLayer( (AbstractGridCoverage2DReader) object, style);   * {@link StyledLayerInterface} stuff.
98      if (object instanceof FeatureCollection)   *
99        layer = new DefaultMapLayer( (FeatureCollection) object, style);   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
100     *         (University of Bonn/Germany)
101      if ( layer == null )   * @version 1.0
102        throw new Exception("Can not create MapLayer from "+(object == null ? "null" : object.getClass()));   */
103    public class StyledLayerUtil {
104      return layer;          private static final Logger LOGGER = Logger.getLogger(StyledLayerUtil.class
105    }                          .getName());
106            private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
107    /**          private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
108     * Creates an default instance of {@link StyledMapInterface} for a Geotools  
109     * object ({@link GridCoverage2D}, {@link FeatureCollection}) with a default          /** URL for Atlas XML schema */
110     * style.          public static final String AMLURI = "http://www.wikisquare.de/AtlasML";
111     * @param object an Object          /** Name of the XML Element for the attribute meta data map */
112     * @param title  title for the object          public static final String ELEM_NAME_AMD = "attributeMetaData";
113     * @exception UnsupportedOperationException if {@code null} is given as object or an error occurs during creation          /** Name of the XML Element for the raster legend data */
114     */          public static final String ELEM_NAME_RLD = "rasterLegendData";
115    public static StyledMapInterface<?> createStyledMap(Object object, String title) {          /** Name of the XML Element for an attribute meta data map entry */
116       return createStyledMap(object, title, null);          public static final String ELEM_NAME_ATTRIBUTE = "dataAttribute";
117    }          /** Name of the XML Element for an raster legend data entry */
118            public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";
119    /**          /** Name of the XML Element for a translation */
120     * Creates an default instance of {@link StyledMapInterface} for a Geotools          public static final String ELEM_NAME_TRANSLATION = "translation";
121     * object ({@link GridCoverage2D}, {@link FeatureCollection}) with a given  
122     * style.          /**
123     * @param object an Object           * Creates a Geotools {@link MapLayer} from an object. If the object is a
124     * @param title  title for the object           * {@link StyledLayerInterface} then its sytle is used. In case of direct
125     * @param style  style and meta data for the object           * Geotools objects ({@link GridCoverage2D},
126     * @exception UnsupportedOperationException if {@code null} is given as object or an error occurs during creation           * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
127     */           * default style is generated.
128    public static StyledMapInterface<?> createStyledMap(Object object, String title, StyledMapStyle style) {           *
129      StyledMapInterface<?> styledObject = null;           * @param object
130             *            an Object
131      String id = (title != null) ? title : "defaultID";           * @exception Exception
132             *                if {@code null} is given as object or an error occurs
133      if ( object instanceof GridCoverage2D )           *                during layer creation
134        styledObject = new StyledGridCoverage(           */
135            (GridCoverage2D)object,          public static MapLayer createMapLayer(final Object object) throws Exception {
136            id,                  return createMapLayer(object, null);
137            title,          }
138            style  
139        );          /**
140      else if ( object instanceof AbstractGridCoverage2DReader )           * Creates a Geotools {@link MapLayer} from an object. If the object is a
141             styledObject = new StyledGridCoverageReader(           * {@link StyledLayerInterface} then its sytle is used. In case of direct
142                 (AbstractGridCoverage2DReader)object,           * Geotools objects ({@link GridCoverage2D},
143                 id,           * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
144                 title,           * default style is generated.
145                 style           *
146             );           * @param object
147      else if ( object instanceof FeatureCollection )           *            an Object
148        styledObject = new StyledFeatureCollection(           * @param forcedStyle
149            (FeatureCollection)object,           *            (SLD-)Style to force for the object
150            id,           * @exception Exception
151            title,           *                if {@code null} is given as object or an error occurs
152            style           *                during layer creation
153        );           */
154                public static MapLayer createMapLayer(Object object, final Style forcedStyle)
155      if ( styledObject == null )                          throws Exception {
156        throw new UnsupportedOperationException("Can not create StyledMapInterface object from "+(object == null ? "null" : object.getClass()));                  MapLayer layer = null;
157                    Style style = null;
158      return styledObject;                  if (object instanceof StyledLayerInterface) {
159    }                          style = ((StyledLayerInterface<?>) object).getStyle();
160                            object = ((StyledLayerInterface<?>) object).getGeoObject();
161    /**                  }
162     * Return only the visible or invisible entries of an AttributeMetaData-Map.                  if (forcedStyle != null)
163     * @param amdMap AttributeMetaData-Map                          style = forcedStyle;
164     * @param visible indicated whether the visible or invisible entries are                  if (style == null)
165     *                returned                          style = StylingUtil.createDefaultStyle(object);
166     */  
167    public static SortedMap<Integer,AttributeMetaData> getVisibleAttributeMetaData(Map<Integer,AttributeMetaData> amdMap, boolean visible) {                  if (object instanceof GridCoverage2D)
168      SortedMap<Integer,AttributeMetaData> filteredMap = new TreeMap<Integer,AttributeMetaData>();                          layer = new DefaultMapLayer((GridCoverage2D) object, style);
169      for (AttributeMetaData amd : amdMap.values())                  if (object instanceof AbstractGridCoverage2DReader)
170        if ( amd.isVisible() )                          layer = new DefaultMapLayer((AbstractGridCoverage2DReader) object,
171          filteredMap.put(amd.getColIdx(), amd);                                          style);
172                        if (object instanceof FeatureCollection)
173      return filteredMap;                          layer = new DefaultMapLayer((FeatureCollection) object, style);
174    }  
175                      if (layer == null)
176                              throw new Exception("Can not create MapLayer from "
177    /**                                          + (object == null ? "null" : object.getClass()));
178     * Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}.  
179     * This method works like {@link AMLImport#parseDataAttribute(org.w3c.dom.Node},                  return layer;
180     * but for JDOM.          }
181     * @param element {@link Element} to parse  
182     */          /**
183    public static AttributeMetaData parseAttributeMetaData(final Element element) {           * Creates an default instance of {@link StyledLayerInterface} for a
184      final Integer col = Integer.valueOf(element.getAttributeValue("col"));           * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
185      final Boolean visible = Boolean.valueOf(element.getAttributeValue("visible"));           * a default style.
186      final String unit = element.getAttributeValue("unit");           *
187             * @param object
188      Translation name = new Translation();           *            an Object
189      Translation desc = new Translation();           * @param title
190      for (final Element childElement : (List<Element>)element.getChildren()) {           *            title for the object
191        if (childElement.getName() == null)           * @exception UnsupportedOperationException
192          continue;           *                if {@code null} is given as object or an error occurs
193             *                during creation
194        if (childElement.getName().equals("name"))           */
195          name = parseTranslation(childElement);          public static StyledLayerInterface<?> createStyledLayer(
196        else if (childElement.getName().equals("desc"))                          final Object object, final String title) {
197          desc = parseTranslation(childElement);                  return createStyledLayer(object, title, null);
198      }          }
199      return new AttributeMetaData(col, visible, name, desc, unit);  
200    }          /**
201             * Creates an default instance of {@link StyledLayerInterface} for a
202    /**           * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
203     * Parses a {@link AttributeMetaData} map from an JDOM-{@link Element}           * a given style.
204     * with {@code <attribute>}-childs.           *
205     * @param element {@link Element} to parse           * @param object
206     */           *            an Object
207    public static Map<Integer,AttributeMetaData> parseAttributeMetaDataMap(final Element element) {           * @param title
208      HashMap<Integer,AttributeMetaData> metaData = new HashMap<Integer,AttributeMetaData>();           *            title for the object
209      List<Element> attributesElements = element.getChildren( ELEM_NAME_ATTRIBUTE );           * @param style
210      for (Element attibuteElement : attributesElements)           *            style and meta data for the object
211      {           * @exception UnsupportedOperationException
212        AttributeMetaData attrMetaData = parseAttributeMetaData( attibuteElement );           *                if {@code null} is given as object or an error occurs
213        metaData.put( attrMetaData.getColIdx(), attrMetaData );           *                during creation
214      }           */
215      return metaData;          public static StyledLayerInterface<?> createStyledLayer(
216    }                          final Object object, final String title,
217                            final StyledLayerStyle style) {
218    /**                  StyledLayerInterface<?> styledLayer = null;
219     * Loads a {@link AttributeMetaData} object from an URL.  
220     * @param documentUrl {@link URL} to parse                  final String id = (title != null) ? title : "defaultID";
221     * @see #parseAttributeMetaData(Element)  
222     */                  if (object instanceof GridCoverage2D)
223    public static Map<Integer,AttributeMetaData> loadAttributeMetaDataMap(final URL documentUrl) throws Exception {                          styledLayer = new StyledGridCoverage((GridCoverage2D) object, id,
224      Document document = SAX_BUILDER.build(documentUrl);                                          title, style);
225      return parseAttributeMetaDataMap( document.getRootElement() );                  else if (object instanceof AbstractGridCoverage2DReader)
226    }                          styledLayer = new StyledGridCoverageReader(
227                                            (AbstractGridCoverage2DReader) object, id, title, style);
228    /**                  else if (object instanceof FeatureCollection)
229     * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}                          styledLayer = new StyledFeatureCollection(
230     * object.                                          (FeatureCollection) object, id, title, style);
231     * @param amd meta data for one attribute  
232     */                  if (styledLayer == null)
233    public static Element createAttributeMetaDataElement(final AttributeMetaData amd) {                          throw new UnsupportedOperationException(
234      final Element element = new Element( ELEM_NAME_ATTRIBUTE , AMLURI);                                          "Can not create StyledLayerInterface object from "
235      element.setAttribute("col", String.valueOf( amd.getColIdx() ) );                                                          + (object == null ? "null" : object.getClass()));
236      element.setAttribute("visible", String.valueOf( amd.isVisible() ) );  
237      element.setAttribute("unit", amd.getUnit() );                  return styledLayer;
238      // Creating a aml:name tag...          }
239      element.addContent( createTranslationElement("name", amd.getTitle()) );  
240      // Creating a aml:desc tag...          /**
241      element.addContent( createTranslationElement("desc", amd.getDesc()) );           * Return only the visible or invisible entries of an AttributeMetaData-Map.
242      return element;           *
243    }           * @param amdMap
244             *            AttributeMetaData-Map
245    /**           * @param visible
246     * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}           *            indicated whether the visible or invisible entries are
247     * map.           *            returned
248     * @param amdMap map of attribute meta data           *            
249     */           * TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
250    public static Element createAttributeMetaDataMapElement(final Map<Integer,AttributeMetaData> amdMap) {           */
251      final Element element = new Element( ELEM_NAME_AMD , AMLURI);          public static AttributeMetadataMap getVisibleAttributeMetaData(
252      for (AttributeMetaData amd : amdMap.values())                          final AttributeMetadataMap amdMap, final boolean visible) {
253        element.addContent( createAttributeMetaDataElement( amd ) );  
254      return element;                  final AttributeMetadataMap filteredMap = new AttributeMetadataMap(amdMap.getLanguages());
255    }                  for (final AttributeMetadata amd : amdMap.values())
256                            if (amd.isVisible() == visible)
257    /**                                  filteredMap.put(amd.getName(), amd);
258     * Saves a {@link AttributeMetaData AttributeMetaData-Map} to an URL.  
259     * @param amdMap map of {@link AttributeMetaData}                  return filteredMap;
260     * @param documentUrl {@link URL} to store the XML          }
261     */  
262    public static void saveAttributeMetaDataMap(final Map<Integer,AttributeMetaData> amdMap, final URL documentUrl) throws Exception {          /**
263      // Create XML-Document           * Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}.
264      final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );           * This method works like {@link
265      XML_OUTPUTTER.output(           * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
266        createAttributeMetaDataMapElement(amdMap),           *
267        out           * TODO 20.11.2009, SK: There are some new attribute weight, functiona,
268      );           * functionX and nodata in AttributeMetaData that should be parsed/exported
269      out.flush();           * too. but this method is only used by ISDSS, which is not supporting that
270      out.close();           * stuff anyways.
271    }           *
272             * @param element
273             *            {@link Element} to parse
274             */
275    /**          public static AttributeMetadata parseAttributeMetaData(final Element element) {
276     * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}.                  final String namespace = String.valueOf(element
277     * This method works like {@link AMLImport#parseRasterLegendData(org.w3c.dom.Node},                                  .getAttributeValue("namespace"));
278     * but for JDOM.                  final String localname = String.valueOf(element
279     * @param element {@link Element} to parse                                  .getAttributeValue("localname"));
280     */                  final Name aName = new NameImpl(namespace, localname);
281    public static RasterLegendData parseRasterLegendData(Element element) {                  final Boolean visible = Boolean.valueOf(element
282                                    .getAttributeValue("visible"));
283      final boolean paintGaps = Boolean.valueOf( element.getAttributeValue("paintGaps") );                  final String unit = element.getAttributeValue("unit");
284    
285      RasterLegendData rld = new RasterLegendData(paintGaps);                  Translation name = new Translation();
286                    Translation desc = new Translation();
287      for ( Element childElement : (List<Element>)element.getChildren() ) {                  for (final Element childElement : (List<Element>) element.getChildren()) {
288        final String name = childElement.getName();                          if (childElement.getName() == null)
289        // Cancel if it's an attribute                                  continue;
290        if ( childElement.getChildren().size() == 0 )  
291          continue;                          if (childElement.getName().equals("name"))
292                                    name = parseTranslation(childElement);
293        if (name.equals( ELEM_NAME_RASTERLEGEND )) {                          else if (childElement.getName().equals("desc"))
294          final String valueAttr = childElement.getAttributeValue("value");                                  desc = parseTranslation(childElement);
295          if ( valueAttr == null )                  }
296            throw new UnsupportedOperationException("Attribute 'value' missing for definition of <"+ELEM_NAME_RASTERLEGEND+">");                  return new AttributeMetadata(aName, visible, name, desc, unit);
297          final double value = Double.valueOf(valueAttr);          }
298    
299          // first and only item should be the label          /**
300          final Element labelElement = childElement.getChild("label");           * Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with
301          // id label element is missing, the translation is searched directly           * {@code <attribute>}-childs.
302          // as childs of the rasterLegendItem element           *
303          Translation label = parseTranslation( labelElement != null ? labelElement : childElement );           * @param element
304          rld.put(value, label);           *            {@link Element} to parse
305        }           */
306      }          public static AttributeMetadataMap parseAttributeMetaDataMap(
307                            final Element element) {
308      return rld;                  final AttributeMetadataMap metaData = new AttributeMetadataMap();
309    }                  final List<Element> attributesElements = element
310                                    .getChildren(ELEM_NAME_ATTRIBUTE);
311    /**                  for (final Element attibuteElement : attributesElements) {
312     * Loads a {@link RasterLegendData} object from an URL.                          final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);
313     * @param documentUrl {@link URL} to parse                          metaData.put(attrMetaData.getName(), attrMetaData);
314     * @see #parseAttributeMetaData(Element)                  }
315     */                  return metaData;
316    public static RasterLegendData loadRasterLegendData(final URL documentUrl) throws Exception {          }
317      Document document = SAX_BUILDER.build(documentUrl);  
318      return parseRasterLegendData( document.getRootElement() );          /**
319    }           * Loads a {@link AttributeMetadata} object from an URL.
320             *
321   /**           * @param documentUrl
322     * Creates an JDOM {@link Element} for the given {@link RasterLegendData}           *            {@link URL} to parse
323     * map.           * @see #parseAttributeMetaData(Element)
324     * @param rld raster legend data           */
325     */          public static AttributeMetadataMap loadAttributeMetaDataMap(
326    public static Element createRasterLegendDataElement(final RasterLegendData rld) {                          final URL documentUrl) throws Exception {
327      final Element element = new Element( ELEM_NAME_RLD , AMLURI);                  final Document document = SAX_BUILDER.build(documentUrl);
328      element.setAttribute("paintGaps", rld.isPaintGaps().toString());                  return parseAttributeMetaDataMap(document.getRootElement());
329      for (Double key : rld.getSortedKeys()) {          }
330        Element item = new Element( ELEM_NAME_RASTERLEGEND, AMLURI);  
331        item.setAttribute("value", key.toString());          /**
332        item.addContent( createTranslationElement("label", rld.get(key)) );           * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
333        element.addContent(item);           * object.
334      }           *
335      return element;           * @param amd
336    }           *            meta data for one attribute
337             */
338    /**          public static Element createAttributeMetaDataElement(
339     * Creates {@link RasterLegendData} from a {@link ColorMap}.                          final AttributeMetadata amd) {
340     * @param colorMap  a color map                  final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
341     * @param paintGaps indicated whether gaps are painted between the legend items                  element.setAttribute("namespace", String.valueOf(amd.getName()
342     * @param digits    number of digits the grid value classes (and legend) are                                  .getNamespaceURI()));
343     *                  rounded to (null means no round; >= 0 means digits after comma;                  element.setAttribute("localname", String.valueOf(amd.getLocalName()));
344     *                  < 0 means digits before comma)    */                  element.setAttribute("visible", String.valueOf(amd.isVisible()));
345    public static RasterLegendData generateRasterLegendData(ColorMap colorMap, boolean paintGaps, Integer digits) {                  element.setAttribute("unit", amd.getUnit());
346      DecimalFormat    decFormat = digits != null ? new DecimalFormat( SwingUtil.getNumberFormatPattern(digits) ) : null;                  // Creating a aml:name tag...
347      RasterLegendData rld       = new RasterLegendData(paintGaps);                  element.addContent(createTranslationElement("name", amd.getTitle()));
348      for (ColorMapEntry cme : colorMap.getColorMapEntries())                  // Creating a aml:desc tag...
349      {                  element.addContent(createTranslationElement("desc", amd.getDesc()));
350        double value = StylingUtil.getQuantityFromColorMapEntry(cme);                  return element;
351        String label = cme.getLabel();          }
352        // if no label is set (e.g. quantitative style),  
353        // use the value as label          /**
354        if ( label == null || label.equals("") )           * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
355          if ( digits == null )           * map.
356            label = String.valueOf(value);           *
357          else           * @param amdMap
358            label = decFormat.format( LangUtil.round(value, digits) );           *            map of attribute meta data
359        rld.put( value, new Translation("   "+label) );           */
360      }          public static Element createAttributeMetaDataMapElement(
361      return rld;                          final AttributeMetadataMap amdMap) {
362    }                  final Element element = new Element(ELEM_NAME_AMD, AMLURI);
363                    for (final AttributeMetadata amd : amdMap.values())
364    /**                          element.addContent(createAttributeMetaDataElement(amd));
365     * Creates {@link RasterLegendData} from the {@link ColorMap} of a style.                  return element;
366     * @param style     a raster style (must contain a  {@link RasterSymbolizer})          }
367     * @param paintGaps indicated whether gaps are painted between the legend items  
368     * @param digits    number of digits the grid value classes (and legend) are          /**
369     *                  rounded to (null means no round; >= 0 means digits after comma;           * Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL.
370     *                  < 0 means digits before comma)    */           *
371    public static RasterLegendData generateRasterLegendData(Style style, boolean paintGaps, Integer digits) {           * @param amdMap
372      ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);           *            map of {@link AttributeMetadata}
373      if ( colorMap == null)           * @param documentUrl
374        throw new IllegalArgumentException("Color map can not be determined from style!");           *            {@link URL} to store the XML
375      return generateRasterLegendData(colorMap, paintGaps, digits);           */
376    }          public static void saveAttributeMetaDataMap(
377                            final AttributeMetadataMap amdMap, final URL documentUrl)
378    /**                          throws Exception {
379     * Saves a {@link RasterLegendData} to an URL.                  // Create XML-Document
380     * @param rld raster legend data                  final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
381     * @param documentUrl {@link URL} to store the XML                  XML_OUTPUTTER.output(createAttributeMetaDataMapElement(amdMap), out);
382     */                  out.flush();
383    public static void saveRasterLegendData(final RasterLegendData rld, final URL documentUrl) throws Exception {                  out.close();
384      // Create XML-Document          }
385      final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );  
386      XML_OUTPUTTER.output(          /**
387        createRasterLegendDataElement(rld),           * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}.
388        out           * This method works like {@link
389      );           * AMLImport#parseRasterLegendData(org.w3c.dom.Node}, but for JDOM.
390      out.flush();           *
391      out.close();           * @param element
392    }           *            {@link Element} to parse
393             */
394    /**          public static RasterLegendData parseRasterLegendData(final Element element) {
395     * Parses a {@link Translation} object from an JDOM-{@link Element}.  
396     * This method works like {@link AMLImport#parseTranslation(org.w3c.dom.Node},                  final boolean paintGaps = Boolean.valueOf(element
397     * but for JDOM.                                  .getAttributeValue("paintGaps"));
398     * @param element {@link Element} to parse  
399     */                  final RasterLegendData rld = new RasterLegendData(paintGaps);
400    public final static Translation parseTranslation(final Element element) {  
401      Translation trans = new Translation();                  for (final Element childElement : (List<Element>) element.getChildren()) {
402                            final String name = childElement.getName();
403      if (element == null)                          // Cancel if it's an attribute
404       return trans;                          if (childElement.getChildren().size() == 0)
405                                    continue;
406      for (final Element translationElement : (List<Element>)element.getChildren()) {  
407        final String name = translationElement.getName();                          if (name.equals(ELEM_NAME_RASTERLEGEND)) {
408        if (name == null)                                  final String valueAttr = childElement
409          continue;                                                  .getAttributeValue("value");
410                                    if (valueAttr == null)
411        // lang attribute                                          throw new UnsupportedOperationException(
412        String lang = translationElement.getAttributeValue("lang");                                                          "Attribute 'value' missing for definition of <"
413        // set the default, if no language code is set                                                                          + ELEM_NAME_RASTERLEGEND + ">");
414        if ( lang == null )                                  final double value = Double.valueOf(valueAttr);
415          lang = Translation.DEFAULT_KEY;  
416                                    // first and only item should be the label
417        final String translationText = translationElement.getValue();                                  final Element labelElement = childElement.getChild("label");
418        if (translationText == null)                                  // id label element is missing, the translation is searched
419          trans.put(lang, "");                                  // directly
420        else                                  // as childs of the rasterLegendItem element
421          trans.put(lang, translationText);                                  final Translation label = parseTranslation(labelElement != null ? labelElement
422      }                                                  : childElement);
423                                    rld.put(value, label);
424      // if no <translation> is given, the value of the node should                          }
425      // be used as a default translation                  }
426      if (trans.size() == 0)  
427        trans.put( Translation.DEFAULT_KEY, element.getValue() );                  return rld;
428      //     trans = new Translation( ((List<Element>)element.getChildren()).get(0).getValue() );          }
429    
430      return trans;          /**
431    }           * Loads a {@link RasterLegendData} object from an URL.
432             *
433    /**           * @param documentUrl
434     * Creates an JDOM {@link Element} for the given {@link Translation}.           *            {@link URL} to parse
435     * @param tagname Name of the Element           * @see #parseAttributeMetaData(Element)
436     * @param translation Translation to store in the Element           */
437     */          public static RasterLegendData loadRasterLegendData(final URL documentUrl)
438    public final static Element createTranslationElement(String tagname, Translation translation) {                          throws Exception {
439      Element element = new Element(tagname, AMLURI);                  final Document document = SAX_BUILDER.build(documentUrl);
440      if ( translation == null )                  return parseRasterLegendData(document.getRootElement());
441        throw new UnsupportedOperationException("Translation element can not be created from null!");          }
442    
443      // If only a default translation is set, the <translation lang="..">..</tranlation>          /**
444      // part is not used           * Creates an JDOM {@link Element} for the given {@link RasterLegendData}
445      if (translation.keySet().size() == 1 && translation.get(Translation.DEFAULT_KEY) != null) {           * map.
446        element.addContent( translation.get(Translation.DEFAULT_KEY) );           *
447        return element;           * @param rld
448      }           *            raster legend data
449             */
450      // add a <translation lang="..">..</tranlation> part to the element for          public static Element createRasterLegendDataElement(
451      // all languages                          final RasterLegendData rld) {
452      for (String lang : translation.keySet()) {                  final Element element = new Element(ELEM_NAME_RLD, AMLURI);
453        Element translationElement = new Element( ELEM_NAME_TRANSLATION , AMLURI);                  element.setAttribute("paintGaps", rld.isPaintGaps().toString());
454        translationElement.setAttribute("lang", lang);                  for (final Double key : rld.getSortedKeys()) {
455        String translationString = translation.get(lang);                          final Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI);
456        if (translationString == null)                          item.setAttribute("value", key.toString());
457         translationString = "";                          item.addContent(createTranslationElement("label", rld.get(key)));
458        translationElement.addContent( translationString );                          element.addContent(item);
459        element.addContent(translationElement);                  }
460      }                  return element;
461            }
462      return element;  
463    }          /**
464             * Creates {@link RasterLegendData} from a {@link ColorMap}.
465             *
466    /**           * @param colorMap
467     * Sets a style to {@link StyledMapInterface}.           *            a color map
468     * @param styledObject a styled object           * @param paintGaps
469     * @param style a Style           *            indicated whether gaps are painted between the legend items
470     */           * @param digits
471    public static void setStyledMapStyle(StyledMapInterface styledObject, StyledMapStyle<?> style) {           *            number of digits the grid value classes (and legend) are
472      // set SLD style           *            rounded to (null means no round; >= 0 means digits after
473      styledObject.setStyle( style.getGeoObjectStyle() );           *            comma; < 0 means digits before comma)
474      // set meta data           */
475      if ( styledObject        instanceof StyledGridCoverageInterface &&          public static RasterLegendData generateRasterLegendData(
476           (style.getMetaData() instanceof RasterLegendData || style.getMetaData() == null) ) {                          final ColorMap colorMap, final boolean paintGaps,
477        RasterLegendData sourceRld = (RasterLegendData)style.getMetaData();                          final Integer digits) {
478        RasterLegendData destRld = ((StyledGridCoverageInterface)styledObject).getLegendMetaData();                  final DecimalFormat decFormat = digits != null ? new DecimalFormat(
479        if ( destRld != null && sourceRld != null ) {                                  SwingUtil.getNumberFormatPattern(digits)) : null;
480          destRld.setPaintGaps(sourceRld.isPaintGaps());                  final RasterLegendData rld = new RasterLegendData(paintGaps);
481          destRld.clear();                  for (final ColorMapEntry cme : colorMap.getColorMapEntries()) {
482          destRld.putAll( sourceRld );                          final double value = StylingUtil.getQuantityFromColorMapEntry(cme);
483        }                          String label = cme.getLabel();
484        return;                          // if no label is set (e.g. quantitative style),
485      }                          // use the value as label
486      if ( styledObject        instanceof StyledFeatureCollectionInterface &&                          if (label == null || label.equals(""))
487           (style.getMetaData() instanceof Map || style.getMetaData() == null) ) {                                  if (digits == null)
488        Map<Integer, AttributeMetaData> sourceAmd = (Map<Integer, AttributeMetaData>)style.getMetaData();                                          label = String.valueOf(value);
489        Map<Integer, AttributeMetaData> destAmd   = ((StyledFeatureCollectionInterface)styledObject).getAttributeMetaDataMap();                                  else
490        if ( destAmd != null && sourceAmd != null ) {                                          label = decFormat.format(LangUtil.round(value, digits));
491          destAmd.clear();                          rld.put(value, new Translation("   " + label));
492          destAmd.putAll( sourceAmd );                  }
493        }                  return rld;
494        return;          }
495      }  
496            /**
497      throw new UnsupportedOperationException("Style is not compatible to object: " +           * Creates {@link RasterLegendData} from the {@link ColorMap} of a style.
498                                              (style.getMetaData() == null ? null : style.getMetaData().getClass().getSimpleName()) +           *
499                                              " <-> " +           * @param style
500                                              (styledObject == null ? null : styledObject.getClass().getSimpleName()));           *            a raster style (must contain a {@link RasterSymbolizer})
501    }           * @param paintGaps
502             *            indicated whether gaps are painted between the legend items
503    /**           * @param digits
504     * Returns the style a {@link StyledMapInterface} as a {@link StyledMapStyle}.           *            number of digits the grid value classes (and legend) are
505     * @param styledObject a styled object           *            rounded to (null means no round; >= 0 means digits after
506     * @return {@code StyledMapStyle<RasterLegendData>} for {@link StyledGridCoverageInterface}           *            comma; < 0 means digits before comma)
507     *         or {@code StyledMapStyle<Map<Integer,AttributeMetaData>>} for           */
508     *         {@link StyledFeatureCollectionInterface}          public static RasterLegendData generateRasterLegendData(final Style style,
509     */                          final boolean paintGaps, final Integer digits) {
510    public static StyledMapStyle<?> getStyledMapStyle(StyledMapInterface styledObject) {                  final ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
511      if ( styledObject instanceof StyledGridCoverageInterface )                  if (colorMap == null)
512        return getStyledMapStyle( (StyledGridCoverageInterface)styledObject );                          throw new IllegalArgumentException(
513      if ( styledObject instanceof StyledFeatureCollectionInterface )                                          "Color map can not be determined from style!");
514        return getStyledMapStyle( (StyledFeatureCollectionInterface)styledObject );                  return generateRasterLegendData(colorMap, paintGaps, digits);
515      throw new UnsupportedOperationException("Unknown type of StyledMapInterface: "+(styledObject == null ? null : styledObject.getClass().getSimpleName()));          }
516    }  
517            /**
518    /**           * Saves a {@link RasterLegendData} to an URL.
519     * Returns the style and raster meta data of a {@link StyledGridCoverageInterface}           *
520     * as a {@link StyledMapStyle}.           * @param rld
521     * @param styledGC a styled grid coverage           *            raster legend data
522     */           * @param documentUrl
523    public static StyledMapStyle<RasterLegendData> getStyledMapStyle(StyledGridCoverageInterface styledGC) {           *            {@link URL} to store the XML
524      return new StyledMapStyle<RasterLegendData>(           */
525        styledGC.getStyle(),          public static void saveRasterLegendData(final RasterLegendData rld,
526        styledGC.getLegendMetaData()                          final URL documentUrl) throws Exception {
527      );                  // Create XML-Document
528    }                  final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
529                    XML_OUTPUTTER.output(createRasterLegendDataElement(rld), out);
530    /**                  out.flush();
531     * Returns the style and attribute meta data of a {@link StyledFeatureCollectionInterface}                  out.close();
532     * as a {@link StyledMapStyle}.          }
533     * @param styledFC a styled feature collection  
534     */          /**
535    public static StyledMapStyle<Map<Integer,AttributeMetaData>> getStyledMapStyle(StyledFeatureCollectionInterface styledFC) {           * Parses a {@link Translation} object from an JDOM-{@link Element}. This
536      return new StyledMapStyle<Map<Integer,AttributeMetaData>>(           * method works like {@link AMLImport#parseTranslation(org.w3c.dom.Node},
537        styledFC.getStyle(),           * but for JDOM.
538        styledFC.getAttributeMetaDataMap()           *
539      );           * @param element
540    }           *            {@link Element} to parse
541             */
542    /**          public final static Translation parseTranslation(final Element element) {
543     * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData}                  final Translation trans = new Translation();
544     * for a given geo-object (raster) source. The SLD file must be present. A missing  
545     * raster legend-data file is tolerated.                  if (element == null)
546     * @param geoObjectURL URL of the (already read) raster object                          return trans;
547     * @param sldExt file extention for the SLD file  
548     * @param rldExt file extention for the raster legend-data file                  for (final Element translationElement : (List<Element>) element
549     * @return {@code null} in case of any error                                  .getChildren()) {
550     */                          final String name = translationElement.getName();
551    public static StyledMapStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL, String sldExt, String rldExt) {                          if (name == null)
552      RasterLegendData metaData = null;                                  continue;
553      Style sldStyle = null;  
554      try {                          // lang attribute
555        Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));                          String lang = translationElement.getAttributeValue("lang");
556        // SLD must be present                          // set the default, if no language code is set
557        if ( styles == null || styles.length == 0 )                          if (lang == null)
558          return null;                                  lang = Translation.DEFAULT_KEY;
559        sldStyle = styles[0];  
560      }                          final String translationText = translationElement.getValue();
561      catch (Exception err) {                          if (translationText == null)
562        // SLD must be present                                  trans.put(lang, "");
563        LangUtil.logDebugError(LOGGER,err);                          else
564        return null;                                  trans.put(lang, translationText);
565      }                  }
566    
567      try {                  // if no <translation> is given, the value of the node should
568        metaData = StyledMapUtil.loadRasterLegendData( IOUtil.changeUrlExt(geoObjectURL,rldExt) );                  // be used as a default translation
569      } catch (FileNotFoundException err) {                  if (trans.size() == 0)
570        // ignore missing raster legend data                          trans.put(Translation.DEFAULT_KEY, element.getValue());
571      } catch (Exception err) {                  // trans = new Translation(
572        // any other error during legend data creation leads to error                  // ((List<Element>)element.getChildren()).get(0).getValue() );
573        LangUtil.logDebugError(LOGGER,err);  
574        return null;                  return trans;
575      }          }
576      return new StyledMapStyle<RasterLegendData>(sldStyle, metaData);  
577    }          /**
578             * Creates an JDOM {@link Element} for the given {@link Translation}.
579    /**           *
580     * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and           * @param tagname
581     * {@linkplain RasterLegendData Raster-LegendData} from a {@code .rld} file           *            Name of the Element
582     * for a given geo-object (raster) source. The SLD file must be present. A missing           * @param translation
583     * raster legend-data file is tolerated.           *            Translation to store in the Element
584     * @param geoObjectURL URL of the (already read) raster object           */
585     * @param sldExt file extention for the SLD file          public final static Element createTranslationElement(final String tagname,
586     * @param rldExt file extention for the raster legend-data file                          final Translation translation) {
587     * @return {@code null} in case of any error                  final Element element = new Element(tagname, AMLURI);
588     */                  if (translation == null)
589    public static StyledMapStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL) {                          throw new UnsupportedOperationException(
590      return loadStyledRasterStyle(geoObjectURL, "sld", "rld");                                          "Translation element can not be created from null!");
591    }  
592                    // If only a default translation is set, the <translation
593    /**                  // lang="..">..</tranlation>
594     * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetaData AttributeMetaData-Map}                  // part is not used
595     * for a given geo-object (feature) source. The SLD file must be present. A missing                  if (translation.keySet().size() == 1
596     * attribute meta-data file is tolerated.                                  && translation.get(Translation.DEFAULT_KEY) != null) {
597     * @param geoObjectURL URL of the (already read) feature object                          element.addContent(translation.get(Translation.DEFAULT_KEY));
598     * @param sldExt file extention for the SLD file                          return element;
599     * @param rldExt file extention for the raster legend-data file                  }
600     * @return {@code null} in case of any error  
601     */                  // add a <translation lang="..">..</tranlation> part to the element for
602    public static StyledMapStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL, String sldExt, String rldExt) {                  // all languages
603      Map<Integer,AttributeMetaData> metaData = null;                  for (final String lang : translation.keySet()) {
604      Style                          sldStyle = null;                          final Element translationElement = new Element(
605      try {                                          ELEM_NAME_TRANSLATION, AMLURI);
606        Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));                          translationElement.setAttribute("lang", lang);
607        // SLD must be present                          String translationString = translation.get(lang);
608        if ( styles == null || styles.length == 0 )                          if (translationString == null)
609          return null;                                  translationString = "";
610        sldStyle = styles[0];                          translationElement.addContent(translationString);
611      } catch (Exception err) {                          element.addContent(translationElement);
612        // SLD must be present                  }
613        LangUtil.logDebugError(LOGGER,err);  
614        return null;                  return element;
615      }          }
616    
617      try {          /**
618        metaData = StyledMapUtil.loadAttributeMetaDataMap( IOUtil.changeUrlExt(geoObjectURL,rldExt) );           * Sets a style to {@link StyledLayerInterface}.
619      } catch (FileNotFoundException err) {           *
620        // ignore missing attribute meta data           * @param styledObject
621      } catch (Exception err) {           *            a styled object
622        // any other error during meta data creation leads to error           * @param style
623        LangUtil.logDebugError(LOGGER,err);           *            a Style
624        return null;           */
625      }          public static void setStyledLayerStyle(
626                            final StyledLayerInterface styledObject,
627      return new StyledMapStyle<Map<Integer,AttributeMetaData>>(sldStyle, metaData);                          final StyledLayerStyle<?> style) {
628    }                  // set SLD style
629                    styledObject.setStyle(style.getGeoObjectStyle());
630    /**                  // set meta data
631     * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and                  if (styledObject instanceof StyledGridCoverageInterface
632     * {@linkplain AttributeMetaData AttributeMetaData-Map} from a {@code .amd} file                                  && (style.getMetaData() instanceof RasterLegendData || style
633     * for a given geo-object (feature) source. The SLD file must be present. A missing                                                  .getMetaData() == null)) {
634     * attribute meta-data file is tolerated.                          final RasterLegendData sourceRld = (RasterLegendData) style
635     * @param geoObjectURL URL of the (already read) feature object                                          .getMetaData();
636     * @param sldExt file extention for the SLD file                          final RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject)
637     * @param rldExt file extention for the raster legend-data file                                          .getLegendMetaData();
638     * @return {@code null} in case of any error                          if (destRld != null && sourceRld != null) {
639     */                                  destRld.setPaintGaps(sourceRld.isPaintGaps());
640    public static StyledMapStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL) {                                  destRld.clear();
641      return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");                                  destRld.putAll(sourceRld);
642    }                          }
643                            return;
644    /**                  }
645     * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData}                  if (styledObject instanceof StyledFeatureCollectionInterface
646     * for a given geo-object (raster) source.                                  && (style.getMetaData() instanceof Map || style.getMetaData() == null)) {
647     * @param style  style to save                          final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
648     * @param geoObjectURL URL of the raster object                                          .getMetaData();
649     * @param sldExt file extention for the SLD file                          final AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject)
650     * @param mdExt file extention for the meta-data file                                          .getAttributeMetaDataMap();
651     */                          if (destAmd != null && sourceAmd != null) {
652    public static <T> void saveStyledMapStyle(StyledMapStyle<T> style, URL geoObjectURL, String sldExt, String mdExt) throws Exception {                                  destAmd.clear();
653      // Store the SLD                                  destAmd.putAll(sourceAmd);
654      Style sldStyle = style.getGeoObjectStyle();                          }
655      if ( sldStyle != null ) {                          return;
656        StylingUtil.saveStyleToSLD(                  }
657           sldStyle,  
658           IOUtil.changeFileExt(                  throw new UnsupportedOperationException(
659                new File(geoObjectURL.toURI()),                                  "Style is not compatible to object: "
660                sldExt                                                  + (style.getMetaData() == null ? null : style
661           )                                                                  .getMetaData().getClass().getSimpleName())
662        );                                                  + " <-> "
663      }                                                  + (styledObject == null ? null : styledObject
664                                                                    .getClass().getSimpleName()));
665      // Store the meta data          }
666      T metaData = style.getMetaData();  
667      if ( metaData != null ) {          /**
668        if ( metaData instanceof RasterLegendData ) {           * Returns the style a {@link StyledLayerInterface} as a
669          saveRasterLegendData(           * {@link StyledLayerStyle}.
670              (RasterLegendData)metaData,           *
671              IOUtil.changeUrlExt(geoObjectURL,mdExt)           * @param styledObject
672          );           *            a styled object
673  //      } else if ( metaData instanceof Map<Integer,AttributeMetaData> ) { // LEIDER NICHT KOMPILIERBAR!!           * @return {@code StyledLayerStyle<RasterLegendData>} for
674        } else if ( metaData instanceof Map ) {           *         {@link StyledGridCoverageInterface} or {@code
675          saveAttributeMetaDataMap(           *         StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
676              (Map<Integer,AttributeMetaData>)metaData,           *         {@link StyledFeatureCollectionInterface}
677              IOUtil.changeUrlExt(geoObjectURL,mdExt)           */
678          );          public static StyledLayerStyle<?> getStyledLayerStyle(
679        } else                          final StyledLayerInterface styledObject) {
680          throw new UnsupportedOperationException("Export for meta data not yet supported: "+metaData.getClass().getSimpleName());                  if (styledObject instanceof StyledGridCoverageInterface)
681      }                          return getStyledLayerStyle((StyledGridCoverageInterface) styledObject);
682    }                  if (styledObject instanceof StyledFeatureCollectionInterface)
683                            return getStyledLayerStyle((StyledFeatureCollectionInterface) styledObject);
684    /**                  throw new UnsupportedOperationException(
685     * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and                                  "Unknown type of StyledLayerInterface: "
686     * the meta data ({@link RasterLegendData} or {@link AttributeMetaData})                                                  + (styledObject == null ? null : styledObject
687     * to a {@code .rld} or {@code .amd} file.                                                                  .getClass().getSimpleName()));
688     * for a given geo-object source.          }
689     * @param style  style to save  
690     * @param geoObjectURL URL of the (already read) raster object          /**
691     */           * Returns the style and raster meta data of a
692    public static void saveStyledMapStyle(StyledMapStyle<?> style, URL geoObjectURL) throws Exception {           * {@link StyledGridCoverageInterface} as a {@link StyledLayerStyle}.
693      if ( style.getMetaData() instanceof RasterLegendData )           *
694        saveStyledMapStyle(style,geoObjectURL, "sld", "rld");           * @param styledGC
695      else           *            a styled grid coverage
696        saveStyledMapStyle(style,geoObjectURL, "sld", "amd");           */
697    }          public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(
698                            final StyledGridCoverageInterface styledGC) {
699  }                  return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(),
700                                    styledGC.getLegendMetaData());
701            }
702    
703            /**
704             * Returns the style and attribute meta data of a
705             * {@link StyledFeatureCollectionInterface} as a {@link StyledLayerStyle}.
706             *
707             * @param styledFC
708             *            a styled feature collection
709             */
710            public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle(
711                            final StyledFeatureCollectionInterface styledFC) {
712                    return new StyledLayerStyle<AttributeMetadataMap>(styledFC.getStyle(),
713                                    styledFC.getAttributeMetaDataMap());
714            }
715    
716            /**
717             * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
718             * Raster-LegendData} for a given geo-object (raster) source. The SLD file
719             * must be present. A missing raster legend-data file is tolerated.
720             *
721             * @param geoObjectURL
722             *            URL of the (already read) raster object
723             * @param sldExt
724             *            file extention for the SLD file
725             * @param rldExt
726             *            file extention for the raster legend-data file
727             * @return {@code null} in case of any error
728             */
729            public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
730                            final URL geoObjectURL, final String sldExt, final String rldExt) {
731                    RasterLegendData metaData = null;
732                    Style sldStyle = null;
733                    try {
734                            final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
735                                            geoObjectURL, sldExt));
736                            // SLD must be present
737                            if (styles == null || styles.length == 0)
738                                    return null;
739                            sldStyle = styles[0];
740                    } catch (final Exception err) {
741                            // SLD must be present
742                            LangUtil.logDebugError(LOGGER, err);
743                            return null;
744                    }
745    
746                    try {
747                            metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
748                                            .changeUrlExt(geoObjectURL, rldExt));
749                    } catch (final FileNotFoundException err) {
750                            // ignore missing raster legend data
751                    } catch (final Exception err) {
752                            // any other error during legend data creation leads to error
753                            LangUtil.logDebugError(LOGGER, err);
754                            return null;
755                    }
756                    return new StyledLayerStyle<RasterLegendData>(sldStyle, metaData);
757            }
758    
759            /**
760             * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
761             * {@linkplain RasterLegendData Raster-LegendData} from a {@code .rld} file
762             * for a given geo-object (raster) source. The SLD file must be present. A
763             * missing raster legend-data file is tolerated.
764             *
765             * @param geoObjectURL
766             *            URL of the (already read) raster object
767             * @param sldExt
768             *            file extention for the SLD file
769             * @param rldExt
770             *            file extention for the raster legend-data file
771             * @return {@code null} in case of any error
772             */
773            public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
774                            final URL geoObjectURL) {
775                    return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
776            }
777    
778            /**
779             * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata
780             * AttributeMetaData-Map} for a given geo-object (feature) source. The SLD
781             * file must be present. A missing attribute meta-data file is tolerated.
782             *
783             * @param geoObjectURL
784             *            URL of the (already read) feature object
785             * @param sldExt
786             *            file extention for the SLD file
787             * @param rldExt
788             *            file extention for the raster legend-data file
789             * @return {@code null} in case of any error
790             */
791            public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
792                            final URL geoObjectURL, final String sldExt, final String rldExt) {
793                    AttributeMetadataMap metaData = null;
794                    Style sldStyle = null;
795                    try {
796                            final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
797                                            geoObjectURL, sldExt));
798                            // SLD must be present
799                            if (styles == null || styles.length == 0)
800                                    return null;
801                            sldStyle = styles[0];
802                    } catch (final Exception err) {
803                            // SLD must be present
804                            LangUtil.logDebugError(LOGGER, err);
805                            return null;
806                    }
807    
808                    try {
809                            metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
810                                            .changeUrlExt(geoObjectURL, rldExt));
811                    } catch (final FileNotFoundException err) {
812                            // ignore missing attribute meta data
813                    } catch (final Exception err) {
814                            // any other error during meta data creation leads to error
815                            LangUtil.logDebugError(LOGGER, err);
816                            return null;
817                    }
818    
819                    return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, metaData);
820            }
821    
822            /**
823             * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
824             * {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd}
825             * file for a given geo-object (feature) source. The SLD file must be
826             * present. A missing attribute meta-data file is tolerated.
827             *
828             * @param geoObjectURL
829             *            URL of the (already read) feature object
830             * @param sldExt
831             *            file extention for the SLD file
832             * @param rldExt
833             *            file extention for the raster legend-data file
834             * @return {@code null} in case of any error
835             */
836            public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
837                            final URL geoObjectURL) {
838                    return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
839            }
840    
841            /**
842             * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
843             * Raster-LegendData} for a given geo-object (raster) source.
844             *
845             * @param style
846             *            style to save
847             * @param geoObjectURL
848             *            URL of the raster object
849             * @param sldExt
850             *            file extention for the SLD file
851             * @param mdExt
852             *            file extention for the meta-data file
853             */
854            public static <T> void saveStyledLayerStyle(
855                            final StyledLayerStyle<T> style, final URL geoObjectURL,
856                            final String sldExt, final String mdExt) throws Exception {
857                    // Store the SLD
858                    final Style sldStyle = style.getGeoObjectStyle();
859                    if (sldStyle != null) {
860                            StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File(
861                                            geoObjectURL.toURI()), sldExt));
862                    }
863    
864                    // Store the meta data
865                    final T metaData = style.getMetaData();
866                    if (metaData != null) {
867                            if (metaData instanceof RasterLegendData) {
868                                    saveRasterLegendData((RasterLegendData) metaData, IOUtil
869                                                    .changeUrlExt(geoObjectURL, mdExt));
870                                    // } else if ( metaData instanceof
871                                    // Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
872                                    // KOMPILIERBAR!!
873                            } else if (metaData instanceof Map) {
874                                    saveAttributeMetaDataMap((AttributeMetadataMap) metaData,
875                                                    IOUtil.changeUrlExt(geoObjectURL, mdExt));
876                            } else
877                                    throw new UnsupportedOperationException(
878                                                    "Export for meta data not yet supported: "
879                                                                    + metaData.getClass().getSimpleName());
880                    }
881            }
882    
883            /**
884             * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the
885             * meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a
886             * {@code .rld} or {@code .amd} file. for a given geo-object source.
887             *
888             * @param style
889             *            style to save
890             * @param geoObjectURL
891             *            URL of the (already read) raster object
892             */
893            public static void saveStyledLayerStyle(final StyledLayerStyle<?> style,
894                            final URL geoObjectURL) throws Exception {
895                    if (style.getMetaData() instanceof RasterLegendData)
896                            saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
897                    else
898                            saveStyledLayerStyle(style, geoObjectURL, "sld", "amd");
899            }
900    
901            /**
902             * Creates a {@link JPanel} that shows a legend for a list of
903             * {@link FeatureTypeStyle}s and a targeted featureType
904             *
905             * @param featureType
906             *            If this a legend for Point, Polygon or Line?
907             * @param list
908             *            The Styles to presented in this legend
909             *
910             * @author <a href="mailto:[email protected]">Stefan Alfons
911             *         Kr&uuml;ger</a>
912             */
913            public static JPanel createLegendPanel(Style style,
914                            final SimpleFeatureType featureType, final int iconWidth,
915                            final int iconHeight) {
916    
917                    final List<FeatureTypeStyle> list = style.featureTypeStyles();
918    
919                    final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
920    
921                    if (style == null) {
922                            // No Style => no legend
923                            return panel;
924                    }
925    
926                    for (final FeatureTypeStyle ftStyle : list) {
927    
928                            // One child-node for every rule
929                            final List<Rule> rules = ftStyle.rules();
930                            for (final Rule rule : rules) {
931    
932                                    /**
933                                     * Let's not create a hbox for Rules that only contain
934                                     * TextSymbolizers
935                                     */
936                                    if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
937                                                    .size() == rule.getSymbolizers().length)
938                                            continue;
939    
940                                    final BufferedImage imageForRule = LegendIconFeatureRenderer
941                                                    .getInstance().createImageForRule(rule, featureType,
942                                                                    new Dimension(iconWidth, iconHeight));
943    
944                                    final ImageIcon legendIcon = new ImageIcon(imageForRule);
945    
946                                    final JLabel iconLabel = new JLabel(legendIcon);
947                                    panel.add(iconLabel, "sgx1");
948                                    // hbox.setAlignmentX(0f);
949                                    // hbox.add(iconLabel);
950                                    // hbox.add(Box.createHorizontalStrut(3));
951    
952                                    final Translation labelT = new Translation();
953                                    labelT.fromOneLine(rule.getDescription().getTitle());
954                                    final JLabel classTitleLabel = new JLabel(labelT.toString());
955    
956                                    panel.add(classTitleLabel, "sgx2");
957                                    classTitleLabel.setLabelFor(iconLabel);
958                            }
959                    }
960    
961                    return panel;
962            }
963    
964            /**
965             * Creates a {@link JComponent} that contains a legend for a given
966             * rasterLayer and a given {@link Style}.
967             *
968             * @param style
969             *            if <code>null</code>, the default {@link Style} is extracetd
970             *            from the {@link StyledRasterInterface}
971             */
972            public static JPanel createLegendPanel(
973                            final StyledRasterInterface<?> styledRaster, Style style,
974                            final int iconWidth, final int iconHeight) {
975    
976                    // If no style is given, we use the default style for this layer
977                    if (style == null)
978                            style = styledRaster.getStyle();
979    
980                    /**
981                     * Determine whether a Style is responsible for the coloring
982                     */
983                    ColorModel colorModel = null;
984                    if (!isStyleable(styledRaster)
985                                    || (isStyleable(styledRaster) && style == null)) {
986                            colorModel = getColorModel(styledRaster);
987                    }
988    
989                    final RasterLegendData rasterLegendData = styledRaster
990                                    .getLegendMetaData();
991                    final List<Double> legendRasterValues = rasterLegendData
992                                    .getSortedKeys();
993                    final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
994                                    .createSampleRasters();
995    
996                    final JPanel panel = new JPanel(new MigLayout("wrap 2"));
997    
998                    for (final Double rValue : legendRasterValues) {
999    
1000                            // final Dimension ICON_SIZE = new Dimension(iconWidth,
1001                            // new JLabel().getFontMetrics(new JLabel().getFont())
1002                            // .getHeight() > 5 ? new JLabel().getFontMetrics(
1003                            // new JLabel().getFont()).getHeight() : iconHeight);
1004    
1005                            // ****************************************************************************
1006                            // Create the actual icon
1007                            // ****************************************************************************
1008                            final BufferedImage buffImage = new BufferedImage(iconWidth,
1009                                            iconHeight, BufferedImage.TYPE_INT_ARGB);
1010    
1011                            final Graphics2D graphics = buffImage.createGraphics();
1012    
1013                            if (colorModel != null) {
1014                                    // The colors come from the ColorModel!
1015    
1016                                    try {
1017                                            Object inData = null;
1018                                            switch (colorModel.getTransferType()) {
1019                                            case DataBuffer.TYPE_BYTE:
1020                                                    inData = new byte[] { rValue.byteValue() };
1021                                                    break;
1022                                            case DataBuffer.TYPE_USHORT:
1023                                                    inData = new short[] { rValue.shortValue() };
1024                                                    break;
1025                                            case DataBuffer.TYPE_INT:
1026                                                    inData = new int[] { rValue.intValue() };
1027                                                    break;
1028                                            case DataBuffer.TYPE_SHORT:
1029                                                    inData = new short[] { rValue.shortValue() };
1030                                                    break;
1031                                            case DataBuffer.TYPE_FLOAT:
1032                                                    inData = new float[] { rValue.floatValue() };
1033                                                    break;
1034                                            case DataBuffer.TYPE_DOUBLE:
1035                                                    inData = new double[] { rValue.doubleValue() };
1036                                                    break;
1037                                            default:
1038                                                    inData = rValue.intValue();
1039                                            }
1040                                            final Color color = new Color(colorModel.getRGB(inData));
1041                                            graphics.setBackground(color);
1042                                            graphics.setColor(color);
1043                                            graphics.fillRect(0, 0, iconWidth, iconHeight);
1044                                    } catch (final Exception e) {
1045                                            LOGGER.info(
1046                                                            "Dann nehmen wir halt den GridCoverageRenderer", e);
1047                                            colorModel = null;
1048                                    }
1049                            } else {
1050                                    // The colors come from the Style
1051    
1052                                    /**
1053                                     * The coverage contains only one value of value rValue
1054                                     */
1055                                    final GridCoverage2D sampleCov = sampleRasters.get(rValue);
1056                                    GridCoverageRenderer renderer;
1057                                    try {
1058                                            renderer = new GridCoverageRenderer(sampleCov
1059                                                            .getCoordinateReferenceSystem(), JTSUtil
1060                                                            .createEnvelope(sampleCov.getEnvelope()),
1061                                                            new Rectangle(iconWidth, iconHeight),
1062                                                            (AffineTransform) null);
1063                                    } catch (final Exception e1) {
1064                                            throw new RuntimeException(
1065                                                            "Creating a GridCoverageRenderer failed:", e1);
1066                                    }
1067    
1068                                    /**
1069                                     * Iterate over all FeatureTypeStyles.
1070                                     */
1071                                    final List<RasterSymbolizer> rSymbols = StylingUtil
1072                                                    .getRasterSymbolizers(style);
1073    
1074                                    for (final RasterSymbolizer symbolizer : rSymbols) {
1075                                            try {
1076                                                    renderer.paint(graphics, sampleCov, symbolizer);
1077                                            } catch (final Exception ee) {
1078                                                    LOGGER.error("Unable to paint " + symbolizer
1079                                                                    + " into the legend image", ee);
1080                                            }
1081                                    }
1082                            }
1083    
1084                            final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
1085                            // hbox.setAlignmentX(0f);
1086                            panel.add(iconLabel, "sgx1");
1087                            // hbox.add(Box.createHorizontalStrut(3));
1088    
1089                            final Translation labelT = rasterLegendData.get(rValue);
1090                            final JLabel classTitleLabel = new JLabel(labelT.toString());
1091                            panel.add(classTitleLabel, "sgx2"
1092                                            + (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : ""));
1093                            classTitleLabel.setLabelFor(iconLabel);
1094    
1095                            // box.add(hbox);
1096    
1097                            if (rasterLegendData.getPaintGaps()) {
1098                                    iconLabel
1099                                                    .setBorder(BorderFactory.createLineBorder(Color.black));
1100                            }
1101    
1102                    }
1103    
1104                    return panel;
1105            }
1106    
1107            /**
1108             * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
1109             * return <code>null</code> if the geoobject can not be accessed.
1110             */
1111            @SuppressWarnings("unchecked")
1112            public static ColorModel getColorModel(
1113                            final StyledRasterInterface<?> styledGrid) {
1114                    ColorModel colorModel = null;
1115                    try {
1116                            final Object geoObject = styledGrid.getGeoObject();
1117                            if (geoObject instanceof GridCoverage2D) {
1118                                    final GridCoverage2D cov = (GridCoverage2D) geoObject;
1119                                    colorModel = cov.getRenderedImage().getColorModel();
1120                            } else if (styledGrid instanceof StyledRasterPyramidInterface) {
1121    
1122                                    final Parameter readGG = new Parameter(
1123                                                    AbstractGridFormat.READ_GRIDGEOMETRY2D);
1124    
1125                                    final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope(
1126                                                    styledGrid.getEnvelope(), styledGrid.getCrs());
1127    
1128                                    readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
1129                                                    new Rectangle(0, 0, 1, 1)), mapExtend));
1130    
1131                                    final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
1132    
1133                                    final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil
1134                                                    .getWrappedGeoObject(rFc);
1135                                    final GridCoverage2D cov = (GridCoverage2D) aReader
1136                                                    .read(new GeneralParameterValue[] { readGG });
1137                                    colorModel = cov.getRenderedImage().getColorModel();
1138                            }
1139                    } catch (final Exception e) {
1140                            LOGGER.error("Error reading the colormodel from " + styledGrid, e);
1141                            return null;
1142                    }
1143                    return colorModel;
1144            }
1145    
1146            /**
1147             * @return <code>true</code> if a {@link RasterSymbolizer} can be applied
1148             *         and will have an effect. Some rasters (e.g. GeoTIFF) can come
1149             *         with their own {@link ColorModel} and will ignore any
1150             *         {@link RasterSymbolizer} = SLD.
1151             */
1152            public static boolean isStyleable(
1153                            final StyledRasterInterface<?> styledRaster) {
1154                    final ColorModel colorModel = getColorModel(styledRaster);
1155                    
1156    //              LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
1157    //                              + colorModel != null ? colorModel.getClass().getSimpleName() : "NULL");
1158    
1159                    if (colorModel == null)
1160                            return true;
1161                    if (colorModel instanceof ComponentColorModel)
1162                            return true;
1163                    return false;
1164            }
1165    
1166            /**
1167             * Set the given Style as the Style of the {@link MapLayer}, unless the
1168             * styles are the same (not comparing selection stuff). If the
1169             * {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
1170             * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
1171             * repaint, so only use it when needed.
1172             *
1173             * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed.
1174             */
1175            public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer,
1176                            Style style2) {
1177    
1178                    Style mapLayerStyleCleaned = StylingUtil
1179                                                    .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
1180                    
1181                    Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2);
1182                    
1183                    if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned,
1184                                    newStyleCleaned)) {
1185                            
1186                            // They are different when compared without SELECTION FTS!
1187                            
1188                            // Now let's copy any SELECTION FTS to the now style
1189                            FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() );
1190                            if (selectionFeatureTypeStyle != null) {
1191                                    newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle);
1192                                    // newStyleCleaned is not so clean anymore... We just alled a selcetion FTS
1193                            }  
1194                            
1195                            mapLayer.setStyle(newStyleCleaned);
1196                            
1197                            return true;
1198                            
1199                    } else {
1200                            return false;
1201                    }
1202            }
1203    
1204    }

Legend:
Removed from v.127  
changed lines
  Added in v.534

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26