[Schmitzm-commits] r400 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 14 14:24:51 CEST 2009


Author: alfonx
Date: 2009-09-14 14:24:50 +0200 (Mon, 14 Sep 2009)
New Revision: 400

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
* Moving towards a better raster legend!

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-14 11:48:44 UTC (rev 399)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-14 12:24:50 UTC (rev 400)
@@ -66,7 +66,9 @@
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.GeometryAttributeType;
 import org.geotools.filter.ConstantExpression;
+import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
 import org.geotools.renderer.lite.RendererUtilities;
+import org.geotools.renderer.lite.gridcoverage2d.StyleVisitorAdapter;
 import org.geotools.resources.i18n.Vocabulary;
 import org.geotools.resources.i18n.VocabularyKeys;
 import org.geotools.styling.ColorMap;
@@ -92,6 +94,7 @@
 import org.geotools.styling.Style;
 import org.geotools.styling.StyleBuilder;
 import org.geotools.styling.StyleFactory;
+import org.geotools.styling.StyleVisitor;
 import org.geotools.styling.Symbolizer;
 import org.geotools.styling.TextSymbolizer;
 import org.geotools.styling.visitor.DuplicatingStyleVisitor;
@@ -1324,8 +1327,8 @@
 		try {
 			if (style != null) {
 
-				for (final FeatureTypeStyle fts : style.getFeatureTypeStyles()) {
-					for (final Rule r : fts.getRules()) {
+				for (final FeatureTypeStyle fts : style.featureTypeStyles()) {
+					for (final Rule r : fts.rules()) {
 						results.addAll(getTextSymbolizers(r.getSymbolizers()));
 					}
 				}
@@ -2052,6 +2055,34 @@
 		to.getFonts()[0].setFontStyle(ff2.literal(from.getFonts()[0]
 				.getFontStyle().toString()));
 	}
+
+	/**
+	 * Returns all {@link RasterSymbolizer} that are contained in this rule.
+	 */
+	public static List<RasterSymbolizer> getRasterSymbolizers(Style style) {
+		final List<RasterSymbolizer> rsList = new ArrayList<RasterSymbolizer>();
+//		
+//		final DuplicatingStyleVisitor collectRSVisitor = new DuplicatingStyleVisitor() {
+//			@Override
+//			public void visit(RasterSymbolizer rs) {
+//				rsList.add(rs);
+//			}; 
+//		};
+//		
+//		collectRSVisitor.visit(symb);
+		
+		for (FeatureTypeStyle fts : style.featureTypeStyles()) {
+			for (Rule r : fts.rules()) {
+				for (Symbolizer symb : r.getSymbolizers()){
+					if (symb instanceof RasterSymbolizer){
+						rsList.add((RasterSymbolizer) symb);
+					}
+				}
+			}
+		}
+		
+		return rsList;
+	}
 	
 	
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-09-14 11:48:44 UTC (rev 399)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-09-14 12:24:50 UTC (rev 400)
@@ -32,6 +32,9 @@
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -41,6 +44,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -55,6 +59,7 @@
 import org.geotools.feature.FeatureCollection;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.map.MapLayer;
+import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
 import org.geotools.styling.ColorMap;
 import org.geotools.styling.ColorMapEntry;
 import org.geotools.styling.FeatureTypeStyle;
@@ -67,6 +72,7 @@
 import org.jdom.output.XMLOutputter;
 import org.opengis.feature.simple.SimpleFeatureType;
 
+import schmitzm.geotools.JTSUtil;
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.io.IOUtil;
 import schmitzm.lang.LangUtil;
@@ -78,666 +84,791 @@
 /**
  * This class provides static helper methods for dealing with
  * {@link StyledLayerInterface} stuff.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *         (University of Bonn/Germany)
  * @version 1.0
  */
 public class StyledLayerUtil {
-  private static final Logger LOGGER = Logger.getLogger(StyledLayerUtil.class.getName());
-  private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
-  private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
+	private static final Logger LOGGER = Logger.getLogger(StyledLayerUtil.class
+			.getName());
+	private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
+	private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
 
-  /** URL for Atlas XML schema */
-  public static final String AMLURI = "http://www.wikisquare.de/AtlasML";
-  /** Name of the XML Element for the attribute meta data map */
-  public static final String ELEM_NAME_AMD = "attributeMetaData";
-  /** Name of the XML Element for the raster legend data */
-  public static final String ELEM_NAME_RLD = "rasterLegendData";
-  /** Name of the XML Element for an attribute meta data map entry */
-  public static final String ELEM_NAME_ATTRIBUTE = "dataAttribute";
-  /** Name of the XML Element for an raster legend data entry */
-  public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";
-  /** Name of the XML Element for a translation */
-  public static final String ELEM_NAME_TRANSLATION = "translation";
+	/** URL for Atlas XML schema */
+	public static final String AMLURI = "http://www.wikisquare.de/AtlasML";
+	/** Name of the XML Element for the attribute meta data map */
+	public static final String ELEM_NAME_AMD = "attributeMetaData";
+	/** Name of the XML Element for the raster legend data */
+	public static final String ELEM_NAME_RLD = "rasterLegendData";
+	/** Name of the XML Element for an attribute meta data map entry */
+	public static final String ELEM_NAME_ATTRIBUTE = "dataAttribute";
+	/** Name of the XML Element for an raster legend data entry */
+	public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";
+	/** Name of the XML Element for a translation */
+	public static final String ELEM_NAME_TRANSLATION = "translation";
 
-  /**
-   * Creates a Geotools {@link MapLayer} from an object. If the object is a
-   * {@link StyledLayerInterface} then its sytle is used. In case of direct
-   * Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},
-   * {@link FeatureCollection}) a default style is generated.
-   * @param object an Object
-   * @exception Exception if {@code null} is given as object or an error occurs during layer creation
-   */
-  public static MapLayer createMapLayer(Object object) throws Exception {
-    return createMapLayer(object,null);
-  }
+	/**
+	 * Creates a Geotools {@link MapLayer} from an object. If the object is a
+	 * {@link StyledLayerInterface} then its sytle is used. In case of direct
+	 * Geotools objects ({@link GridCoverage2D},
+	 * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
+	 * default style is generated.
+	 * 
+	 * @param object
+	 *            an Object
+	 * @exception Exception
+	 *                if {@code null} is given as object or an error occurs
+	 *                during layer creation
+	 */
+	public static MapLayer createMapLayer(Object object) throws Exception {
+		return createMapLayer(object, null);
+	}
 
-  /**
-   * Creates a Geotools {@link MapLayer} from an object. If the object is a
-   * {@link StyledLayerInterface} then its sytle is used. In case of direct
-   * Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},
-   * {@link FeatureCollection}) a default style is generated.
-   * @param object an Object
-   * @param forcedStyle (SLD-)Style to force for the object
-   * @exception Exception if {@code null} is given as object or an error occurs during layer creation
-   */
-  public static MapLayer createMapLayer(Object object, Style forcedStyle) throws Exception {
-    MapLayer layer     = null;
-    Style    style     = null;
-    if ( object instanceof StyledLayerInterface ) {
-      style =  ((StyledLayerInterface<?>)object).getStyle();
-      object = ((StyledLayerInterface<?>)object).getGeoObject();
-    }
-    if ( forcedStyle != null )
-      style = forcedStyle;
-    if ( style == null )
-      style = StylingUtil.createDefaultStyle(object);
+	/**
+	 * Creates a Geotools {@link MapLayer} from an object. If the object is a
+	 * {@link StyledLayerInterface} then its sytle is used. In case of direct
+	 * Geotools objects ({@link GridCoverage2D},
+	 * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
+	 * default style is generated.
+	 * 
+	 * @param object
+	 *            an Object
+	 * @param forcedStyle
+	 *            (SLD-)Style to force for the object
+	 * @exception Exception
+	 *                if {@code null} is given as object or an error occurs
+	 *                during layer creation
+	 */
+	public static MapLayer createMapLayer(Object object, Style forcedStyle)
+			throws Exception {
+		MapLayer layer = null;
+		Style style = null;
+		if (object instanceof StyledLayerInterface) {
+			style = ((StyledLayerInterface<?>) object).getStyle();
+			object = ((StyledLayerInterface<?>) object).getGeoObject();
+		}
+		if (forcedStyle != null)
+			style = forcedStyle;
+		if (style == null)
+			style = StylingUtil.createDefaultStyle(object);
 
-    if (object instanceof GridCoverage2D)
-      layer = new DefaultMapLayer( (GridCoverage2D) object, style);
-    if (object instanceof AbstractGridCoverage2DReader)
-      layer = new DefaultMapLayer( (AbstractGridCoverage2DReader) object, style);
-    if (object instanceof FeatureCollection)
-      layer = new DefaultMapLayer( (FeatureCollection) object, style);
+		if (object instanceof GridCoverage2D)
+			layer = new DefaultMapLayer((GridCoverage2D) object, style);
+		if (object instanceof AbstractGridCoverage2DReader)
+			layer = new DefaultMapLayer((AbstractGridCoverage2DReader) object,
+					style);
+		if (object instanceof FeatureCollection)
+			layer = new DefaultMapLayer((FeatureCollection) object, style);
 
-    if ( layer == null )
-      throw new Exception("Can not create MapLayer from "+(object == null ? "null" : object.getClass()));
+		if (layer == null)
+			throw new Exception("Can not create MapLayer from "
+					+ (object == null ? "null" : object.getClass()));
 
-    return layer;
-  }
+		return layer;
+	}
 
-  /**
-   * Creates an default instance of {@link StyledLayerInterface} for a Geotools
-   * object ({@link GridCoverage2D}, {@link FeatureCollection}) with a default
-   * style.
-   * @param object an Object
-   * @param title  title for the object
-   * @exception UnsupportedOperationException if {@code null} is given as object or an error occurs during creation
-   */
-  public static StyledLayerInterface<?> createStyledLayer(Object object, String title) {
-     return createStyledLayer(object, title, null);
-  }
+	/**
+	 * Creates an default instance of {@link StyledLayerInterface} for a
+	 * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
+	 * a default style.
+	 * 
+	 * @param object
+	 *            an Object
+	 * @param title
+	 *            title for the object
+	 * @exception UnsupportedOperationException
+	 *                if {@code null} is given as object or an error occurs
+	 *                during creation
+	 */
+	public static StyledLayerInterface<?> createStyledLayer(Object object,
+			String title) {
+		return createStyledLayer(object, title, null);
+	}
 
-  /**
-   * Creates an default instance of {@link StyledLayerInterface} for a Geotools
-   * object ({@link GridCoverage2D}, {@link FeatureCollection}) with a given
-   * style.
-   * @param object an Object
-   * @param title  title for the object
-   * @param style  style and meta data for the object
-   * @exception UnsupportedOperationException if {@code null} is given as object or an error occurs during creation
-   */
-  public static StyledLayerInterface<?> createStyledLayer(Object object, String title, StyledLayerStyle style) {
-    StyledLayerInterface<?> styledLayer = null;
+	/**
+	 * Creates an default instance of {@link StyledLayerInterface} for a
+	 * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
+	 * a given style.
+	 * 
+	 * @param object
+	 *            an Object
+	 * @param title
+	 *            title for the object
+	 * @param style
+	 *            style and meta data for the object
+	 * @exception UnsupportedOperationException
+	 *                if {@code null} is given as object or an error occurs
+	 *                during creation
+	 */
+	public static StyledLayerInterface<?> createStyledLayer(Object object,
+			String title, StyledLayerStyle style) {
+		StyledLayerInterface<?> styledLayer = null;
 
-    String id = (title != null) ? title : "defaultID";
+		String id = (title != null) ? title : "defaultID";
 
-    if ( object instanceof GridCoverage2D )
-      styledLayer = new StyledGridCoverage(
-          (GridCoverage2D)object,
-          id,
-          title,
-          style
-      );
-    else if ( object instanceof AbstractGridCoverage2DReader )
-           styledLayer = new StyledGridCoverageReader(
-               (AbstractGridCoverage2DReader)object,
-               id,
-               title,
-               style
-           );
-    else if ( object instanceof FeatureCollection )
-      styledLayer = new StyledFeatureCollection(
-          (FeatureCollection)object,
-          id,
-          title,
-          style
-      );
-    
-    if ( styledLayer == null )
-      throw new UnsupportedOperationException("Can not create StyledLayerInterface object from "+(object == null ? "null" : object.getClass()));
+		if (object instanceof GridCoverage2D)
+			styledLayer = new StyledGridCoverage((GridCoverage2D) object, id,
+					title, style);
+		else if (object instanceof AbstractGridCoverage2DReader)
+			styledLayer = new StyledGridCoverageReader(
+					(AbstractGridCoverage2DReader) object, id, title, style);
+		else if (object instanceof FeatureCollection)
+			styledLayer = new StyledFeatureCollection(
+					(FeatureCollection) object, id, title, style);
 
-    return styledLayer;
-  }
+		if (styledLayer == null)
+			throw new UnsupportedOperationException(
+					"Can not create StyledLayerInterface object from "
+							+ (object == null ? "null" : object.getClass()));
 
-  /**
-   * Return only the visible or invisible entries of an AttributeMetaData-Map.
-   * @param amdMap AttributeMetaData-Map
-   * @param visible indicated whether the visible or invisible entries are
-   *                returned 
-   */
-  public static SortedMap<Integer,AttributeMetaData> getVisibleAttributeMetaData(Map<Integer,AttributeMetaData> amdMap, boolean visible) {
-    SortedMap<Integer,AttributeMetaData> filteredMap = new TreeMap<Integer,AttributeMetaData>();
-    for (AttributeMetaData amd : amdMap.values())
-      if ( amd.isVisible() )
-        filteredMap.put(amd.getColIdx(), amd);
-    
-    return filteredMap;
-  }
-  
-  
-  /**
-   * Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}.
-   * This method works like {@link AMLImport#parseDataAttribute(org.w3c.dom.Node},
-   * but for JDOM.
-   * @param element {@link Element} to parse
-   */
-  public static AttributeMetaData parseAttributeMetaData(final Element element) {
-    final Integer col = Integer.valueOf(element.getAttributeValue("col"));
-    final Boolean visible = Boolean.valueOf(element.getAttributeValue("visible"));
-    final String unit = element.getAttributeValue("unit");
+		return styledLayer;
+	}
 
-    Translation name = new Translation();
-    Translation desc = new Translation();
-    for (final Element childElement : (List<Element>)element.getChildren()) {
-      if (childElement.getName() == null)
-        continue;
+	/**
+	 * Return only the visible or invisible entries of an AttributeMetaData-Map.
+	 * 
+	 * @param amdMap
+	 *            AttributeMetaData-Map
+	 * @param visible
+	 *            indicated whether the visible or invisible entries are
+	 *            returned
+	 */
+	public static SortedMap<Integer, AttributeMetaData> getVisibleAttributeMetaData(
+			Map<Integer, AttributeMetaData> amdMap, boolean visible) {
+		SortedMap<Integer, AttributeMetaData> filteredMap = new TreeMap<Integer, AttributeMetaData>();
+		for (AttributeMetaData amd : amdMap.values())
+			if (amd.isVisible())
+				filteredMap.put(amd.getColIdx(), amd);
 
-      if (childElement.getName().equals("name"))
-        name = parseTranslation(childElement);
-      else if (childElement.getName().equals("desc"))
-        desc = parseTranslation(childElement);
-    }
-    return new AttributeMetaData(col, visible, name, desc, unit);
-  }
+		return filteredMap;
+	}
 
-  /**
-   * Parses a {@link AttributeMetaData} map from an JDOM-{@link Element}
-   * with {@code <attribute>}-childs.
-   * @param element {@link Element} to parse
-   */
-  public static Map<Integer,AttributeMetaData> parseAttributeMetaDataMap(final Element element) {
-    HashMap<Integer,AttributeMetaData> metaData = new HashMap<Integer,AttributeMetaData>();
-    List<Element> attributesElements = element.getChildren( ELEM_NAME_ATTRIBUTE );
-    for (Element attibuteElement : attributesElements)
-    {
-      AttributeMetaData attrMetaData = parseAttributeMetaData( attibuteElement );
-      metaData.put( attrMetaData.getColIdx(), attrMetaData );
-    }
-    return metaData;
-  }
+	/**
+	 * Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}.
+	 * This method works like {@link
+	 * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
+	 * 
+	 * @param element
+	 *            {@link Element} to parse
+	 */
+	public static AttributeMetaData parseAttributeMetaData(final Element element) {
+		final Integer col = Integer.valueOf(element.getAttributeValue("col"));
+		final Boolean visible = Boolean.valueOf(element
+				.getAttributeValue("visible"));
+		final String unit = element.getAttributeValue("unit");
 
-  /**
-   * Loads a {@link AttributeMetaData} object from an URL.
-   * @param documentUrl {@link URL} to parse
-   * @see #parseAttributeMetaData(Element)
-   */
-  public static Map<Integer,AttributeMetaData> loadAttributeMetaDataMap(final URL documentUrl) throws Exception {
-    Document document = SAX_BUILDER.build(documentUrl);
-    return parseAttributeMetaDataMap( document.getRootElement() );
-  }
+		Translation name = new Translation();
+		Translation desc = new Translation();
+		for (final Element childElement : (List<Element>) element.getChildren()) {
+			if (childElement.getName() == null)
+				continue;
 
-  /**
-   * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
-   * object.
-   * @param amd meta data for one attribute
-   */
-  public static Element createAttributeMetaDataElement(final AttributeMetaData amd) {
-    final Element element = new Element( ELEM_NAME_ATTRIBUTE , AMLURI);
-    element.setAttribute("col", String.valueOf( amd.getColIdx() ) );
-    element.setAttribute("visible", String.valueOf( amd.isVisible() ) );
-    element.setAttribute("unit", amd.getUnit() );
-    // Creating a aml:name tag...
-    element.addContent( createTranslationElement("name", amd.getTitle()) );
-    // Creating a aml:desc tag...
-    element.addContent( createTranslationElement("desc", amd.getDesc()) );
-    return element;
-  }
+			if (childElement.getName().equals("name"))
+				name = parseTranslation(childElement);
+			else if (childElement.getName().equals("desc"))
+				desc = parseTranslation(childElement);
+		}
+		return new AttributeMetaData(col, visible, name, desc, unit);
+	}
 
-  /**
-   * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
-   * map.
-   * @param amdMap map of attribute meta data
-   */
-  public static Element createAttributeMetaDataMapElement(final Map<Integer,AttributeMetaData> amdMap) {
-    final Element element = new Element( ELEM_NAME_AMD , AMLURI);
-    for (AttributeMetaData amd : amdMap.values())
-      element.addContent( createAttributeMetaDataElement( amd ) );
-    return element;
-  }
+	/**
+	 * Parses a {@link AttributeMetaData} map from an JDOM-{@link Element} with
+	 * {@code <attribute>}-childs.
+	 * 
+	 * @param element
+	 *            {@link Element} to parse
+	 */
+	public static Map<Integer, AttributeMetaData> parseAttributeMetaDataMap(
+			final Element element) {
+		HashMap<Integer, AttributeMetaData> metaData = new HashMap<Integer, AttributeMetaData>();
+		List<Element> attributesElements = element
+				.getChildren(ELEM_NAME_ATTRIBUTE);
+		for (Element attibuteElement : attributesElements) {
+			AttributeMetaData attrMetaData = parseAttributeMetaData(attibuteElement);
+			metaData.put(attrMetaData.getColIdx(), attrMetaData);
+		}
+		return metaData;
+	}
 
-  /**
-   * Saves a {@link AttributeMetaData AttributeMetaData-Map} to an URL.
-   * @param amdMap map of {@link AttributeMetaData}
-   * @param documentUrl {@link URL} to store the XML
-   */
-  public static void saveAttributeMetaDataMap(final Map<Integer,AttributeMetaData> amdMap, final URL documentUrl) throws Exception {
-    // Create XML-Document
-    final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );
-    XML_OUTPUTTER.output(
-      createAttributeMetaDataMapElement(amdMap),
-      out
-    );
-    out.flush();
-    out.close();
-  }
+	/**
+	 * Loads a {@link AttributeMetaData} object from an URL.
+	 * 
+	 * @param documentUrl
+	 *            {@link URL} to parse
+	 * @see #parseAttributeMetaData(Element)
+	 */
+	public static Map<Integer, AttributeMetaData> loadAttributeMetaDataMap(
+			final URL documentUrl) throws Exception {
+		Document document = SAX_BUILDER.build(documentUrl);
+		return parseAttributeMetaDataMap(document.getRootElement());
+	}
 
+	/**
+	 * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
+	 * object.
+	 * 
+	 * @param amd
+	 *            meta data for one attribute
+	 */
+	public static Element createAttributeMetaDataElement(
+			final AttributeMetaData amd) {
+		final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
+		element.setAttribute("col", String.valueOf(amd.getColIdx()));
+		element.setAttribute("visible", String.valueOf(amd.isVisible()));
+		element.setAttribute("unit", amd.getUnit());
+		// Creating a aml:name tag...
+		element.addContent(createTranslationElement("name", amd.getTitle()));
+		// Creating a aml:desc tag...
+		element.addContent(createTranslationElement("desc", amd.getDesc()));
+		return element;
+	}
 
+	/**
+	 * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
+	 * map.
+	 * 
+	 * @param amdMap
+	 *            map of attribute meta data
+	 */
+	public static Element createAttributeMetaDataMapElement(
+			final Map<Integer, AttributeMetaData> amdMap) {
+		final Element element = new Element(ELEM_NAME_AMD, AMLURI);
+		for (AttributeMetaData amd : amdMap.values())
+			element.addContent(createAttributeMetaDataElement(amd));
+		return element;
+	}
 
-  /**
-   * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}.
-   * This method works like {@link AMLImport#parseRasterLegendData(org.w3c.dom.Node},
-   * but for JDOM.
-   * @param element {@link Element} to parse
-   */
-  public static RasterLegendData parseRasterLegendData(Element element) {
+	/**
+	 * Saves a {@link AttributeMetaData AttributeMetaData-Map} to an URL.
+	 * 
+	 * @param amdMap
+	 *            map of {@link AttributeMetaData}
+	 * @param documentUrl
+	 *            {@link URL} to store the XML
+	 */
+	public static void saveAttributeMetaDataMap(
+			final Map<Integer, AttributeMetaData> amdMap, final URL documentUrl)
+			throws Exception {
+		// Create XML-Document
+		final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
+		XML_OUTPUTTER.output(createAttributeMetaDataMapElement(amdMap), out);
+		out.flush();
+		out.close();
+	}
 
-    final boolean paintGaps = Boolean.valueOf( element.getAttributeValue("paintGaps") );
+	/**
+	 * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}.
+	 * This method works like {@link
+	 * AMLImport#parseRasterLegendData(org.w3c.dom.Node}, but for JDOM.
+	 * 
+	 * @param element
+	 *            {@link Element} to parse
+	 */
+	public static RasterLegendData parseRasterLegendData(Element element) {
 
-    RasterLegendData rld = new RasterLegendData(paintGaps);
+		final boolean paintGaps = Boolean.valueOf(element
+				.getAttributeValue("paintGaps"));
 
-    for ( Element childElement : (List<Element>)element.getChildren() ) {
-      final String name = childElement.getName();
-      // Cancel if it's an attribute
-      if ( childElement.getChildren().size() == 0 )
-        continue;
+		RasterLegendData rld = new RasterLegendData(paintGaps);
 
-      if (name.equals( ELEM_NAME_RASTERLEGEND )) {
-        final String valueAttr = childElement.getAttributeValue("value");
-        if ( valueAttr == null )
-          throw new UnsupportedOperationException("Attribute 'value' missing for definition of <"+ELEM_NAME_RASTERLEGEND+">");
-        final double value = Double.valueOf(valueAttr);
+		for (Element childElement : (List<Element>) element.getChildren()) {
+			final String name = childElement.getName();
+			// Cancel if it's an attribute
+			if (childElement.getChildren().size() == 0)
+				continue;
 
-        // first and only item should be the label
-        final Element labelElement = childElement.getChild("label");
-        // id label element is missing, the translation is searched directly
-        // as childs of the rasterLegendItem element
-        Translation label = parseTranslation( labelElement != null ? labelElement : childElement );
-        rld.put(value, label);
-      }
-    }
+			if (name.equals(ELEM_NAME_RASTERLEGEND)) {
+				final String valueAttr = childElement
+						.getAttributeValue("value");
+				if (valueAttr == null)
+					throw new UnsupportedOperationException(
+							"Attribute 'value' missing for definition of <"
+									+ ELEM_NAME_RASTERLEGEND + ">");
+				final double value = Double.valueOf(valueAttr);
 
-    return rld;
-  }
+				// first and only item should be the label
+				final Element labelElement = childElement.getChild("label");
+				// id label element is missing, the translation is searched
+				// directly
+				// as childs of the rasterLegendItem element
+				Translation label = parseTranslation(labelElement != null ? labelElement
+						: childElement);
+				rld.put(value, label);
+			}
+		}
 
-  /**
-   * Loads a {@link RasterLegendData} object from an URL.
-   * @param documentUrl {@link URL} to parse
-   * @see #parseAttributeMetaData(Element)
-   */
-  public static RasterLegendData loadRasterLegendData(final URL documentUrl) throws Exception {
-    Document document = SAX_BUILDER.build(documentUrl);
-    return parseRasterLegendData( document.getRootElement() );
-  }
+		return rld;
+	}
 
- /**
-   * Creates an JDOM {@link Element} for the given {@link RasterLegendData}
-   * map.
-   * @param rld raster legend data
-   */
-  public static Element createRasterLegendDataElement(final RasterLegendData rld) {
-    final Element element = new Element( ELEM_NAME_RLD , AMLURI);
-    element.setAttribute("paintGaps", rld.isPaintGaps().toString());
-    for (Double key : rld.getSortedKeys()) {
-      Element item = new Element( ELEM_NAME_RASTERLEGEND, AMLURI);
-      item.setAttribute("value", key.toString());
-      item.addContent( createTranslationElement("label", rld.get(key)) );
-      element.addContent(item);
-    }
-    return element;
-  }
+	/**
+	 * Loads a {@link RasterLegendData} object from an URL.
+	 * 
+	 * @param documentUrl
+	 *            {@link URL} to parse
+	 * @see #parseAttributeMetaData(Element)
+	 */
+	public static RasterLegendData loadRasterLegendData(final URL documentUrl)
+			throws Exception {
+		Document document = SAX_BUILDER.build(documentUrl);
+		return parseRasterLegendData(document.getRootElement());
+	}
 
-  /**
-   * Creates {@link RasterLegendData} from a {@link ColorMap}.
-   * @param colorMap  a color map
-   * @param paintGaps indicated whether gaps are painted between the legend items 
-   * @param digits    number of digits the grid value classes (and legend) are
-   *                  rounded to (null means no round; >= 0 means digits after comma;
-   *                  < 0 means digits before comma)    */
-  public static RasterLegendData generateRasterLegendData(ColorMap colorMap, boolean paintGaps, Integer digits) {
-    DecimalFormat    decFormat = digits != null ? new DecimalFormat( SwingUtil.getNumberFormatPattern(digits) ) : null;
-    RasterLegendData rld       = new RasterLegendData(paintGaps);
-    for (ColorMapEntry cme : colorMap.getColorMapEntries())
-    {
-      double value = StylingUtil.getQuantityFromColorMapEntry(cme);
-      String label = cme.getLabel();
-      // if no label is set (e.g. quantitative style),
-      // use the value as label
-      if ( label == null || label.equals("") )
-        if ( digits == null )
-          label = String.valueOf(value);
-        else
-          label = decFormat.format( LangUtil.round(value, digits) ); 
-      rld.put( value, new Translation("   "+label) );
-    }
-    return rld;
-  }
+	/**
+	 * Creates an JDOM {@link Element} for the given {@link RasterLegendData}
+	 * map.
+	 * 
+	 * @param rld
+	 *            raster legend data
+	 */
+	public static Element createRasterLegendDataElement(
+			final RasterLegendData rld) {
+		final Element element = new Element(ELEM_NAME_RLD, AMLURI);
+		element.setAttribute("paintGaps", rld.isPaintGaps().toString());
+		for (Double key : rld.getSortedKeys()) {
+			Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI);
+			item.setAttribute("value", key.toString());
+			item.addContent(createTranslationElement("label", rld.get(key)));
+			element.addContent(item);
+		}
+		return element;
+	}
 
-  /**
-   * Creates {@link RasterLegendData} from the {@link ColorMap} of a style.
-   * @param style     a raster style (must contain a  {@link RasterSymbolizer})
-   * @param paintGaps indicated whether gaps are painted between the legend items 
-   * @param digits    number of digits the grid value classes (and legend) are
-   *                  rounded to (null means no round; >= 0 means digits after comma;
-   *                  < 0 means digits before comma)    */
-  public static RasterLegendData generateRasterLegendData(Style style, boolean paintGaps, Integer digits) {
-    ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
-    if ( colorMap == null)
-      throw new IllegalArgumentException("Color map can not be determined from style!");
-    return generateRasterLegendData(colorMap, paintGaps, digits);
-  }
+	/**
+	 * Creates {@link RasterLegendData} from a {@link ColorMap}.
+	 * 
+	 * @param colorMap
+	 *            a color map
+	 * @param paintGaps
+	 *            indicated whether gaps are painted between the legend items
+	 * @param digits
+	 *            number of digits the grid value classes (and legend) are
+	 *            rounded to (null means no round; >= 0 means digits after
+	 *            comma; < 0 means digits before comma)
+	 */
+	public static RasterLegendData generateRasterLegendData(ColorMap colorMap,
+			boolean paintGaps, Integer digits) {
+		DecimalFormat decFormat = digits != null ? new DecimalFormat(SwingUtil
+				.getNumberFormatPattern(digits)) : null;
+		RasterLegendData rld = new RasterLegendData(paintGaps);
+		for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
+			double value = StylingUtil.getQuantityFromColorMapEntry(cme);
+			String label = cme.getLabel();
+			// if no label is set (e.g. quantitative style),
+			// use the value as label
+			if (label == null || label.equals(""))
+				if (digits == null)
+					label = String.valueOf(value);
+				else
+					label = decFormat.format(LangUtil.round(value, digits));
+			rld.put(value, new Translation("   " + label));
+		}
+		return rld;
+	}
 
-  /**
-   * Saves a {@link RasterLegendData} to an URL.
-   * @param rld raster legend data
-   * @param documentUrl {@link URL} to store the XML
-   */
-  public static void saveRasterLegendData(final RasterLegendData rld, final URL documentUrl) throws Exception {
-    // Create XML-Document
-    final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );
-    XML_OUTPUTTER.output(
-      createRasterLegendDataElement(rld),
-      out
-    );
-    out.flush();
-    out.close();
-  }
+	/**
+	 * Creates {@link RasterLegendData} from the {@link ColorMap} of a style.
+	 * 
+	 * @param style
+	 *            a raster style (must contain a {@link RasterSymbolizer})
+	 * @param paintGaps
+	 *            indicated whether gaps are painted between the legend items
+	 * @param digits
+	 *            number of digits the grid value classes (and legend) are
+	 *            rounded to (null means no round; >= 0 means digits after
+	 *            comma; < 0 means digits before comma)
+	 */
+	public static RasterLegendData generateRasterLegendData(Style style,
+			boolean paintGaps, Integer digits) {
+		ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
+		if (colorMap == null)
+			throw new IllegalArgumentException(
+					"Color map can not be determined from style!");
+		return generateRasterLegendData(colorMap, paintGaps, digits);
+	}
 
-  /**
-   * Parses a {@link Translation} object from an JDOM-{@link Element}.
-   * This method works like {@link AMLImport#parseTranslation(org.w3c.dom.Node},
-   * but for JDOM.
-   * @param element {@link Element} to parse
-   */
-  public final static Translation parseTranslation(final Element element) {
-    Translation trans = new Translation();
+	/**
+	 * Saves a {@link RasterLegendData} to an URL.
+	 * 
+	 * @param rld
+	 *            raster legend data
+	 * @param documentUrl
+	 *            {@link URL} to store the XML
+	 */
+	public static void saveRasterLegendData(final RasterLegendData rld,
+			final URL documentUrl) throws Exception {
+		// Create XML-Document
+		final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
+		XML_OUTPUTTER.output(createRasterLegendDataElement(rld), out);
+		out.flush();
+		out.close();
+	}
 
-    if (element == null)
-     return trans;
+	/**
+	 * Parses a {@link Translation} object from an JDOM-{@link Element}. This
+	 * method works like {@link AMLImport#parseTranslation(org.w3c.dom.Node},
+	 * but for JDOM.
+	 * 
+	 * @param element
+	 *            {@link Element} to parse
+	 */
+	public final static Translation parseTranslation(final Element element) {
+		Translation trans = new Translation();
 
-    for (final Element translationElement : (List<Element>)element.getChildren()) {
-      final String name = translationElement.getName();
-      if (name == null)
-        continue;
+		if (element == null)
+			return trans;
 
-      // lang attribute
-      String lang = translationElement.getAttributeValue("lang");
-      // set the default, if no language code is set
-      if ( lang == null )
-        lang = Translation.DEFAULT_KEY;
+		for (final Element translationElement : (List<Element>) element
+				.getChildren()) {
+			final String name = translationElement.getName();
+			if (name == null)
+				continue;
 
-      final String translationText = translationElement.getValue();
-      if (translationText == null)
-        trans.put(lang, "");
-      else
-        trans.put(lang, translationText);
-    }
+			// lang attribute
+			String lang = translationElement.getAttributeValue("lang");
+			// set the default, if no language code is set
+			if (lang == null)
+				lang = Translation.DEFAULT_KEY;
 
-    // if no <translation> is given, the value of the node should
-    // be used as a default translation
-    if (trans.size() == 0)
-      trans.put( Translation.DEFAULT_KEY, element.getValue() );
-    //     trans = new Translation( ((List<Element>)element.getChildren()).get(0).getValue() );
+			final String translationText = translationElement.getValue();
+			if (translationText == null)
+				trans.put(lang, "");
+			else
+				trans.put(lang, translationText);
+		}
 
-    return trans;
-  }
+		// if no <translation> is given, the value of the node should
+		// be used as a default translation
+		if (trans.size() == 0)
+			trans.put(Translation.DEFAULT_KEY, element.getValue());
+		// trans = new Translation(
+		// ((List<Element>)element.getChildren()).get(0).getValue() );
 
-  /**
-   * Creates an JDOM {@link Element} for the given {@link Translation}.
-   * @param tagname Name of the Element
-   * @param translation Translation to store in the Element
-   */
-  public final static Element createTranslationElement(String tagname, Translation translation) {
-    Element element = new Element(tagname, AMLURI);
-    if ( translation == null )
-      throw new UnsupportedOperationException("Translation element can not be created from null!");
+		return trans;
+	}
 
-    // If only a default translation is set, the <translation lang="..">..</tranlation>
-    // part is not used
-    if (translation.keySet().size() == 1 && translation.get(Translation.DEFAULT_KEY) != null) {
-      element.addContent( translation.get(Translation.DEFAULT_KEY) );
-      return element;
-    }
+	/**
+	 * Creates an JDOM {@link Element} for the given {@link Translation}.
+	 * 
+	 * @param tagname
+	 *            Name of the Element
+	 * @param translation
+	 *            Translation to store in the Element
+	 */
+	public final static Element createTranslationElement(String tagname,
+			Translation translation) {
+		Element element = new Element(tagname, AMLURI);
+		if (translation == null)
+			throw new UnsupportedOperationException(
+					"Translation element can not be created from null!");
 
-    // add a <translation lang="..">..</tranlation> part to the element for
-    // all languages
-    for (String lang : translation.keySet()) {
-      Element translationElement = new Element( ELEM_NAME_TRANSLATION , AMLURI);
-      translationElement.setAttribute("lang", lang);
-      String translationString = translation.get(lang);
-      if (translationString == null)
-       translationString = "";
-      translationElement.addContent( translationString );
-      element.addContent(translationElement);
-    }
+		// If only a default translation is set, the <translation
+		// lang="..">..</tranlation>
+		// part is not used
+		if (translation.keySet().size() == 1
+				&& translation.get(Translation.DEFAULT_KEY) != null) {
+			element.addContent(translation.get(Translation.DEFAULT_KEY));
+			return element;
+		}
 
-    return element;
-  }
+		// add a <translation lang="..">..</tranlation> part to the element for
+		// all languages
+		for (String lang : translation.keySet()) {
+			Element translationElement = new Element(ELEM_NAME_TRANSLATION,
+					AMLURI);
+			translationElement.setAttribute("lang", lang);
+			String translationString = translation.get(lang);
+			if (translationString == null)
+				translationString = "";
+			translationElement.addContent(translationString);
+			element.addContent(translationElement);
+		}
 
+		return element;
+	}
 
-  /**
-   * Sets a style to {@link StyledLayerInterface}.
-   * @param styledObject a styled object
-   * @param style a Style
-   */
-  public static void setStyledLayerStyle(StyledLayerInterface styledObject, StyledLayerStyle<?> style) {
-    // set SLD style
-    styledObject.setStyle( style.getGeoObjectStyle() );
-    // set meta data
-    if ( styledObject        instanceof StyledGridCoverageInterface &&
-         (style.getMetaData() instanceof RasterLegendData || style.getMetaData() == null) ) {
-      RasterLegendData sourceRld = (RasterLegendData)style.getMetaData();
-      RasterLegendData destRld = ((StyledGridCoverageInterface)styledObject).getLegendMetaData();
-      if ( destRld != null && sourceRld != null ) {
-        destRld.setPaintGaps(sourceRld.isPaintGaps());
-        destRld.clear();
-        destRld.putAll( sourceRld );
-      }
-      return;
-    }
-    if ( styledObject        instanceof StyledFeatureCollectionInterface &&
-         (style.getMetaData() instanceof Map || style.getMetaData() == null) ) {
-      Map<Integer, AttributeMetaData> sourceAmd = (Map<Integer, AttributeMetaData>)style.getMetaData();
-      Map<Integer, AttributeMetaData> destAmd   = ((StyledFeatureCollectionInterface)styledObject).getAttributeMetaDataMap();
-      if ( destAmd != null && sourceAmd != null ) {
-        destAmd.clear();
-        destAmd.putAll( sourceAmd );
-      }
-      return;
-    }
+	/**
+	 * Sets a style to {@link StyledLayerInterface}.
+	 * 
+	 * @param styledObject
+	 *            a styled object
+	 * @param style
+	 *            a Style
+	 */
+	public static void setStyledLayerStyle(StyledLayerInterface styledObject,
+			StyledLayerStyle<?> style) {
+		// set SLD style
+		styledObject.setStyle(style.getGeoObjectStyle());
+		// set meta data
+		if (styledObject instanceof StyledGridCoverageInterface
+				&& (style.getMetaData() instanceof RasterLegendData || style
+						.getMetaData() == null)) {
+			RasterLegendData sourceRld = (RasterLegendData) style.getMetaData();
+			RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject)
+					.getLegendMetaData();
+			if (destRld != null && sourceRld != null) {
+				destRld.setPaintGaps(sourceRld.isPaintGaps());
+				destRld.clear();
+				destRld.putAll(sourceRld);
+			}
+			return;
+		}
+		if (styledObject instanceof StyledFeatureCollectionInterface
+				&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) {
+			Map<Integer, AttributeMetaData> sourceAmd = (Map<Integer, AttributeMetaData>) style
+					.getMetaData();
+			Map<Integer, AttributeMetaData> destAmd = ((StyledFeatureCollectionInterface) styledObject)
+					.getAttributeMetaDataMap();
+			if (destAmd != null && sourceAmd != null) {
+				destAmd.clear();
+				destAmd.putAll(sourceAmd);
+			}
+			return;
+		}
 
-    throw new UnsupportedOperationException("Style is not compatible to object: " +
-                                            (style.getMetaData() == null ? null : style.getMetaData().getClass().getSimpleName()) +
-                                            " <-> " +
-                                            (styledObject == null ? null : styledObject.getClass().getSimpleName()));
-  }
+		throw new UnsupportedOperationException(
+				"Style is not compatible to object: "
+						+ (style.getMetaData() == null ? null : style
+								.getMetaData().getClass().getSimpleName())
+						+ " <-> "
+						+ (styledObject == null ? null : styledObject
+								.getClass().getSimpleName()));
+	}
 
-  /**
-   * Returns the style a {@link StyledLayerInterface} as a {@link StyledLayerStyle}.
-   * @param styledObject a styled object
-   * @return {@code StyledLayerStyle<RasterLegendData>} for {@link StyledGridCoverageInterface}
-   *         or {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
-   *         {@link StyledFeatureCollectionInterface}
-   */
-  public static StyledLayerStyle<?> getStyledLayerStyle(StyledLayerInterface styledObject) {
-    if ( styledObject instanceof StyledGridCoverageInterface )
-      return getStyledLayerStyle( (StyledGridCoverageInterface)styledObject );
-    if ( styledObject instanceof StyledFeatureCollectionInterface )
-      return getStyledLayerStyle( (StyledFeatureCollectionInterface)styledObject );
-    throw new UnsupportedOperationException("Unknown type of StyledLayerInterface: "+(styledObject == null ? null : styledObject.getClass().getSimpleName()));
-  }
+	/**
+	 * Returns the style a {@link StyledLayerInterface} as a
+	 * {@link StyledLayerStyle}.
+	 * 
+	 * @param styledObject
+	 *            a styled object
+	 * @return {@code StyledLayerStyle<RasterLegendData>} for
+	 *         {@link StyledGridCoverageInterface} or {@code
+	 *         StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
+	 *         {@link StyledFeatureCollectionInterface}
+	 */
+	public static StyledLayerStyle<?> getStyledLayerStyle(
+			StyledLayerInterface styledObject) {
+		if (styledObject instanceof StyledGridCoverageInterface)
+			return getStyledLayerStyle((StyledGridCoverageInterface) styledObject);
+		if (styledObject instanceof StyledFeatureCollectionInterface)
+			return getStyledLayerStyle((StyledFeatureCollectionInterface) styledObject);
+		throw new UnsupportedOperationException(
+				"Unknown type of StyledLayerInterface: "
+						+ (styledObject == null ? null : styledObject
+								.getClass().getSimpleName()));
+	}
 
-  /**
-   * Returns the style and raster meta data of a {@link StyledGridCoverageInterface}
-   * as a {@link StyledLayerStyle}.
-   * @param styledGC a styled grid coverage
-   */
-  public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(StyledGridCoverageInterface styledGC) {
-    return new StyledLayerStyle<RasterLegendData>(
-      styledGC.getStyle(),
-      styledGC.getLegendMetaData()
-    );
-  }
+	/**
+	 * Returns the style and raster meta data of a
+	 * {@link StyledGridCoverageInterface} as a {@link StyledLayerStyle}.
+	 * 
+	 * @param styledGC
+	 *            a styled grid coverage
+	 */
+	public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(
+			StyledGridCoverageInterface styledGC) {
+		return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(),
+				styledGC.getLegendMetaData());
+	}
 
-  /**
-   * Returns the style and attribute meta data of a {@link StyledFeatureCollectionInterface}
-   * as a {@link StyledLayerStyle}.
-   * @param styledFC a styled feature collection
-   */
-  public static StyledLayerStyle<Map<Integer,AttributeMetaData>> getStyledLayerStyle(StyledFeatureCollectionInterface styledFC) {
-    return new StyledLayerStyle<Map<Integer,AttributeMetaData>>(
-      styledFC.getStyle(),
-      styledFC.getAttributeMetaDataMap()
-    );
-  }
+	/**
+	 * Returns the style and attribute meta data of a
+	 * {@link StyledFeatureCollectionInterface} as a {@link StyledLayerStyle}.
+	 * 
+	 * @param styledFC
+	 *            a styled feature collection
+	 */
+	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> getStyledLayerStyle(
+			StyledFeatureCollectionInterface styledFC) {
+		return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(styledFC
+				.getStyle(), styledFC.getAttributeMetaDataMap());
+	}
 
-  /**
-   * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData}
-   * for a given geo-object (raster) source. The SLD file must be present. A missing
-   * raster legend-data file is tolerated.
-   * @param geoObjectURL URL of the (already read) raster object
-   * @param sldExt file extention for the SLD file
-   * @param rldExt file extention for the raster legend-data file
-   * @return {@code null} in case of any error
-   */
-  public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL, String sldExt, String rldExt) {
-    RasterLegendData metaData = null;
-    Style sldStyle = null;
-    try {
-      Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));
-      // SLD must be present
-      if ( styles == null || styles.length == 0 )
-        return null;
-      sldStyle = styles[0];
-    }
-    catch (Exception err) {
-      // SLD must be present
-      LangUtil.logDebugError(LOGGER,err);
-      return null;
-    }
+	/**
+	 * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
+	 * Raster-LegendData} for a given geo-object (raster) source. The SLD file
+	 * must be present. A missing raster legend-data file is tolerated.
+	 * 
+	 * @param geoObjectURL
+	 *            URL of the (already read) raster object
+	 * @param sldExt
+	 *            file extention for the SLD file
+	 * @param rldExt
+	 *            file extention for the raster legend-data file
+	 * @return {@code null} in case of any error
+	 */
+	public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
+			URL geoObjectURL, String sldExt, String rldExt) {
+		RasterLegendData metaData = null;
+		Style sldStyle = null;
+		try {
+			Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+					geoObjectURL, sldExt));
+			// SLD must be present
+			if (styles == null || styles.length == 0)
+				return null;
+			sldStyle = styles[0];
+		} catch (Exception err) {
+			// SLD must be present
+			LangUtil.logDebugError(LOGGER, err);
+			return null;
+		}
 
-    try {
-      metaData = StyledLayerUtil.loadRasterLegendData( IOUtil.changeUrlExt(geoObjectURL,rldExt) );
-    } catch (FileNotFoundException err) {
-      // ignore missing raster legend data
-    } catch (Exception err) {
-      // any other error during legend data creation leads to error
-      LangUtil.logDebugError(LOGGER,err);
-      return null;
-    }
-    return new StyledLayerStyle<RasterLegendData>(sldStyle, metaData);
-  }
+		try {
+			metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
+					.changeUrlExt(geoObjectURL, rldExt));
+		} catch (FileNotFoundException err) {
+			// ignore missing raster legend data
+		} catch (Exception err) {
+			// any other error during legend data creation leads to error
+			LangUtil.logDebugError(LOGGER, err);
+			return null;
+		}
+		return new StyledLayerStyle<RasterLegendData>(sldStyle, metaData);
+	}
 
-  /**
-   * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
-   * {@linkplain RasterLegendData Raster-LegendData} from a {@code .rld} file
-   * for a given geo-object (raster) source. The SLD file must be present. A missing
-   * raster legend-data file is tolerated.
-   * @param geoObjectURL URL of the (already read) raster object
-   * @param sldExt file extention for the SLD file
-   * @param rldExt file extention for the raster legend-data file
-   * @return {@code null} in case of any error
-   */
-  public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL) {
-    return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
-  }
+	/**
+	 * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
+	 * {@linkplain RasterLegendData Raster-LegendData} from a {@code .rld} file
+	 * for a given geo-object (raster) source. The SLD file must be present. A
+	 * missing raster legend-data file is tolerated.
+	 * 
+	 * @param geoObjectURL
+	 *            URL of the (already read) raster object
+	 * @param sldExt
+	 *            file extention for the SLD file
+	 * @param rldExt
+	 *            file extention for the raster legend-data file
+	 * @return {@code null} in case of any error
+	 */
+	public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
+			URL geoObjectURL) {
+		return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
+	}
 
-  /**
-   * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetaData AttributeMetaData-Map}
-   * for a given geo-object (feature) source. The SLD file must be present. A missing
-   * attribute meta-data file is tolerated.
-   * @param geoObjectURL URL of the (already read) feature object
-   * @param sldExt file extention for the SLD file
-   * @param rldExt file extention for the raster legend-data file
-   * @return {@code null} in case of any error
-   */
-  public static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL, String sldExt, String rldExt) {
-    Map<Integer,AttributeMetaData> metaData = null;
-    Style                          sldStyle = null;
-    try {
-      Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));
-      // SLD must be present
-      if ( styles == null || styles.length == 0 )
-        return null;
-      sldStyle = styles[0];
-    } catch (Exception err) {
-      // SLD must be present
-      LangUtil.logDebugError(LOGGER,err);
-      return null;
-    }
+	/**
+	 * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetaData
+	 * AttributeMetaData-Map} for a given geo-object (feature) source. The SLD
+	 * file must be present. A missing attribute meta-data file is tolerated.
+	 * 
+	 * @param geoObjectURL
+	 *            URL of the (already read) feature object
+	 * @param sldExt
+	 *            file extention for the SLD file
+	 * @param rldExt
+	 *            file extention for the raster legend-data file
+	 * @return {@code null} in case of any error
+	 */
+	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle(
+			URL geoObjectURL, String sldExt, String rldExt) {
+		Map<Integer, AttributeMetaData> metaData = null;
+		Style sldStyle = null;
+		try {
+			Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+					geoObjectURL, sldExt));
+			// SLD must be present
+			if (styles == null || styles.length == 0)
+				return null;
+			sldStyle = styles[0];
+		} catch (Exception err) {
+			// SLD must be present
+			LangUtil.logDebugError(LOGGER, err);
+			return null;
+		}
 
-    try {
-      metaData = StyledLayerUtil.loadAttributeMetaDataMap( IOUtil.changeUrlExt(geoObjectURL,rldExt) );
-    } catch (FileNotFoundException err) {
-      // ignore missing attribute meta data
-    } catch (Exception err) {
-      // any other error during meta data creation leads to error
-      LangUtil.logDebugError(LOGGER,err);
-      return null;
-    }
+		try {
+			metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
+					.changeUrlExt(geoObjectURL, rldExt));
+		} catch (FileNotFoundException err) {
+			// ignore missing attribute meta data
+		} catch (Exception err) {
+			// any other error during meta data creation leads to error
+			LangUtil.logDebugError(LOGGER, err);
+			return null;
+		}
 
-    return new StyledLayerStyle<Map<Integer,AttributeMetaData>>(sldStyle, metaData);
-  }
+		return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(sldStyle,
+				metaData);
+	}
 
-  /**
-   * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
-   * {@linkplain AttributeMetaData AttributeMetaData-Map} from a {@code .amd} file
-   * for a given geo-object (feature) source. The SLD file must be present. A missing
-   * attribute meta-data file is tolerated.
-   * @param geoObjectURL URL of the (already read) feature object
-   * @param sldExt file extention for the SLD file
-   * @param rldExt file extention for the raster legend-data file
-   * @return {@code null} in case of any error
-   */
-  public static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL) {
-    return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
-  }
+	/**
+	 * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
+	 * {@linkplain AttributeMetaData AttributeMetaData-Map} from a {@code .amd}
+	 * file for a given geo-object (feature) source. The SLD file must be
+	 * present. A missing attribute meta-data file is tolerated.
+	 * 
+	 * @param geoObjectURL
+	 *            URL of the (already read) feature object
+	 * @param sldExt
+	 *            file extention for the SLD file
+	 * @param rldExt
+	 *            file extention for the raster legend-data file
+	 * @return {@code null} in case of any error
+	 */
+	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle(
+			URL geoObjectURL) {
+		return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
+	}
 
-  /**
-   * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData}
-   * for a given geo-object (raster) source.
-   * @param style  style to save
-   * @param geoObjectURL URL of the raster object
-   * @param sldExt file extention for the SLD file
-   * @param mdExt file extention for the meta-data file
-   */
-  public static <T> void saveStyledLayerStyle(StyledLayerStyle<T> style, URL geoObjectURL, String sldExt, String mdExt) throws Exception {
-    // Store the SLD
-    Style sldStyle = style.getGeoObjectStyle();
-    if ( sldStyle != null ) {
-      StylingUtil.saveStyleToSLD(
-         sldStyle,
-         IOUtil.changeFileExt(
-              new File(geoObjectURL.toURI()),
-              sldExt
-         )
-      );
-    }
+	/**
+	 * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
+	 * Raster-LegendData} for a given geo-object (raster) source.
+	 * 
+	 * @param style
+	 *            style to save
+	 * @param geoObjectURL
+	 *            URL of the raster object
+	 * @param sldExt
+	 *            file extention for the SLD file
+	 * @param mdExt
+	 *            file extention for the meta-data file
+	 */
+	public static <T> void saveStyledLayerStyle(StyledLayerStyle<T> style,
+			URL geoObjectURL, String sldExt, String mdExt) throws Exception {
+		// Store the SLD
+		Style sldStyle = style.getGeoObjectStyle();
+		if (sldStyle != null) {
+			StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File(
+					geoObjectURL.toURI()), sldExt));
+		}
 
-    // Store the meta data
-    T metaData = style.getMetaData();
-    if ( metaData != null ) {
-      if ( metaData instanceof RasterLegendData ) {
-        saveRasterLegendData(
-            (RasterLegendData)metaData,
-            IOUtil.changeUrlExt(geoObjectURL,mdExt)
-        );
-//      } else if ( metaData instanceof Map<Integer,AttributeMetaData> ) { // LEIDER NICHT KOMPILIERBAR!!
-      } else if ( metaData instanceof Map ) {
-        saveAttributeMetaDataMap(
-            (Map<Integer,AttributeMetaData>)metaData,
-            IOUtil.changeUrlExt(geoObjectURL,mdExt)
-        );
-      } else
-        throw new UnsupportedOperationException("Export for meta data not yet supported: "+metaData.getClass().getSimpleName());
-    }
-  }
+		// Store the meta data
+		T metaData = style.getMetaData();
+		if (metaData != null) {
+			if (metaData instanceof RasterLegendData) {
+				saveRasterLegendData((RasterLegendData) metaData, IOUtil
+						.changeUrlExt(geoObjectURL, mdExt));
+				// } else if ( metaData instanceof
+				// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
+				// KOMPILIERBAR!!
+			} else if (metaData instanceof Map) {
+				saveAttributeMetaDataMap(
+						(Map<Integer, AttributeMetaData>) metaData, IOUtil
+								.changeUrlExt(geoObjectURL, mdExt));
+			} else
+				throw new UnsupportedOperationException(
+						"Export for meta data not yet supported: "
+								+ metaData.getClass().getSimpleName());
+		}
+	}
 
-  /**
-   * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and
-   * the meta data ({@link RasterLegendData} or {@link AttributeMetaData})
-   * to a {@code .rld} or {@code .amd} file.
-   * for a given geo-object source.
-   * @param style  style to save
-   * @param geoObjectURL URL of the (already read) raster object
-   */
-  public static void saveStyledLayerStyle(StyledLayerStyle<?> style, URL geoObjectURL) throws Exception {
-    if ( style.getMetaData() instanceof RasterLegendData )
-      saveStyledLayerStyle(style,geoObjectURL, "sld", "rld");
-    else
-      saveStyledLayerStyle(style,geoObjectURL, "sld", "amd");
-  }
-  
-  
+	/**
+	 * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the
+	 * meta data ({@link RasterLegendData} or {@link AttributeMetaData}) to a
+	 * {@code .rld} or {@code .amd} file. for a given geo-object source.
+	 * 
+	 * @param style
+	 *            style to save
+	 * @param geoObjectURL
+	 *            URL of the (already read) raster object
+	 */
+	public static void saveStyledLayerStyle(StyledLayerStyle<?> style,
+			URL geoObjectURL) throws Exception {
+		if (style.getMetaData() instanceof RasterLegendData)
+			saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
+		else
+			saveStyledLayerStyle(style, geoObjectURL, "sld", "amd");
+	}
 
 	/**
 	 * Creates a {@link Box} that shows a legend for a list of
@@ -797,9 +928,6 @@
 					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
 					 * Screenshot gemacht wird) wird. Dann werden wird der
 					 * Hintergrund auf WEISS gesetzt.
-					 * 
-					 * @author <a href="mailto:skpublic at wikisquare.de">Stefan
-					 *         Alfons Kr&uuml;ger</a>
 					 */
 					@Override
 					public void print(Graphics g) {
@@ -821,7 +949,7 @@
 				 */
 				final int fontHeight = new JLabel().getFontMetrics(
 						new JLabel().getFont()).getHeight();
-				
+
 				final Dimension ICON_SIZE = new Dimension(iconWidth,
 						fontHeight > 5 ? fontHeight : iconHeight);
 
@@ -848,14 +976,15 @@
 				// ****************************************************************************
 				// final String rawText =
 				// rule.getDescription().getTitle().toString();
-				final String rawText = rule.getDescription().getTitle().toString();
+				final String rawText = rule.getDescription().getTitle()
+						.toString();
 
 				Translation labelT = new Translation();
 				labelT.fromOneLine(rawText);
 
 				final JLabel classTitleLabel = new JLabel(labelT.toString());
 				hbox.add(classTitleLabel);
-				classTitleLabel.setLabelFor(iconLabel); 
+				classTitleLabel.setLabelFor(iconLabel);
 
 				box.add(hbox);
 
@@ -865,17 +994,136 @@
 		return box;
 	}
 
-
 	/**
-	 * Creates a 
+	 * Creates a
+	 * 
 	 * @param styledGrid
-	 * @param iconHeight 
-	 * @param iconWidth 
+	 * @param iconHeight
+	 * @param iconWidth
 	 * @return
 	 */
-	public static Box createLegendPanel(StyledRasterInterface<?> styledGrid, int iconWidth, int iconHeight) {
-		throw new RuntimeException("Not yet...");
+	public static Box createLegendPanel(StyledRasterInterface<?> styledGrid,
+			int iconWidth, int iconHeight) {
+		RasterLegendData rasterLegendData = styledGrid.getLegendMetaData();
+		Set<Double> legendRasterValues = rasterLegendData.keySet();
+		Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
+				.createSampleRasters();
+
+		Box box = new Box(BoxLayout.Y_AXIS) {
+
+			/**
+			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
+			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
+			 * gesetzt.
+			 */
+			@Override
+			public void print(Graphics g) {
+				final Color orig = getBackground();
+				setBackground(Color.WHITE);
+				// wrap in try/finally so that we always restore the state
+				try {
+					super.print(g);
+				} finally {
+					setBackground(orig);
+				}
+			}
+		};
+
+		for (Double rValue : legendRasterValues) {
+
+			/**
+			 * The coverage contains only one value of value rValue
+			 */
+			GridCoverage2D sampleCov = sampleRasters.get(rValue);
+			GridCoverageRenderer renderer;
+			try {
+				renderer = new GridCoverageRenderer(sampleCov
+						.getCoordinateReferenceSystem(), JTSUtil
+						.createEnvelope(sampleCov.getEnvelope()),
+						new Rectangle(iconWidth, iconHeight),
+						(AffineTransform) null);
+			} catch (Exception e1) {
+				throw new RuntimeException(
+						"Creating the GridCoverageRenderer:", e1);
+			}
+
+			/**
+			 * 
+			 */
+			Box hbox = new Box(BoxLayout.X_AXIS) {
+
+				/**
+				 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
+				 * Screenshot gemacht wird) wird. Dann werden wird der
+				 * Hintergrund auf WEISS gesetzt.
+				 */
+				@Override
+				public void print(Graphics g) {
+					final Color orig = getBackground();
+					setBackground(Color.WHITE);
+					// wrap in try/finally so that we always restore the
+					// state
+					try {
+						super.print(g);
+					} finally {
+						setBackground(orig);
+					}
+				}
+			};
+
+			final Dimension ICON_SIZE = new Dimension(iconWidth,
+					new JLabel().getFontMetrics(new JLabel().getFont())
+							.getHeight() > 5 ? new JLabel().getFontMetrics(
+							new JLabel().getFont()).getHeight() : iconHeight);
+
+			// ****************************************************************************
+			// Create the actual icon
+			// ****************************************************************************
+			BufferedImage buffImage = new BufferedImage(ICON_SIZE.width,
+					ICON_SIZE.height, BufferedImage.TYPE_INT_ARGB);
+			Graphics2D graphics = buffImage.createGraphics();
+
+			/**
+			 * Iterate over all FeatureTypeStyles.
+			 */
+			// for (FeatureTypeStyle ftStyle : styledGrid.getStyle()
+			// .featureTypeStyles()) {
+			// One child-node for every rule
+			// List<Rule> rules = ftStyle.rules();
+
+			// for (Rule rule : rules) {
+			List<RasterSymbolizer> rSymbols = StylingUtil
+					.getRasterSymbolizers(styledGrid.getStyle());
+
+			for (RasterSymbolizer symbolizer : rSymbols) {
+				// LOGGER.debug("Creating a new Legend Image for RUle name =
+				// "+rule.getName());
+				try {
+					renderer.paint(graphics, sampleCov, symbolizer);
+				} catch (Exception e) {
+					LOGGER.error("Unable to paint " + symbolizer
+							+ " into the legend image", e);
+				}
+				// }
+				// }
+			}
+
+			ImageIcon legendIcon = new ImageIcon(buffImage);
+
+			final JLabel iconLabel = new JLabel(legendIcon);
+			hbox.setAlignmentX(0f);
+			hbox.add(iconLabel);
+			hbox.add(Box.createHorizontalStrut(3));
+
+			Translation labelT = rasterLegendData.get(rValue);
+			final JLabel classTitleLabel = new JLabel(labelT.toString());
+			hbox.add(classTitleLabel);
+			classTitleLabel.setLabelFor(iconLabel);
+
+			box.add(hbox);
+		}
+
+		return box;
 	}
 
-
 }



More information about the Schmitzm-commits mailing list