[Schmitzm-commits] r224 - in trunk: dist src/skrueger src/skrueger/geotools src/skrueger/geotools/selection
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Jul 14 17:57:30 CEST 2009
Author: alfonx
Date: 2009-07-14 17:57:19 +0200 (Tue, 14 Jul 2009)
New Revision: 224
Added:
trunk/src/skrueger/geotools/AbstractStyledLayer.java
trunk/src/skrueger/geotools/StyledLayerInterface.java
trunk/src/skrueger/geotools/StyledLayerStyle.java
trunk/src/skrueger/geotools/StyledLayerUtil.java
Removed:
trunk/src/skrueger/geotools/AbstractStyledMap.java
trunk/src/skrueger/geotools/StyledMapInterface.java
trunk/src/skrueger/geotools/StyledMapStyle.java
trunk/src/skrueger/geotools/StyledMapUtil.java
Modified:
trunk/dist/schmitzm-src.zip
trunk/dist/schmitzm.jar
trunk/src/skrueger/AttributeMetaData.java
trunk/src/skrueger/geotools/AttributeTableJDialog.java
trunk/src/skrueger/geotools/MapContextManagerInterface.java
trunk/src/skrueger/geotools/StyledFeatureCollection.java
trunk/src/skrueger/geotools/StyledFeatureCollectionInterface.java
trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
trunk/src/skrueger/geotools/StyledFeatureSourceInterface.java
trunk/src/skrueger/geotools/StyledFeaturesInterface.java
trunk/src/skrueger/geotools/StyledGridCoverage.java
trunk/src/skrueger/geotools/StyledGridCoverageReader.java
trunk/src/skrueger/geotools/StyledRasterInterface.java
trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
trunk/src/skrueger/geotools/selection/StyledFeatureLayerSelectionModel.java
trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
Log:
* big biG BIG refactoring: StyledMap[Interface,Util,Style] never dealt with Maps (=Orchestrations of layers), but always only with single Layers. Now it has been refactored to StyledLayer[Interface,Util,Style].
* Some variable names and methodNames have been corrected also, but many will still be missing.
* New JARs committed
Modified: trunk/dist/schmitzm-src.zip
===================================================================
(Binary files differ)
Modified: trunk/dist/schmitzm.jar
===================================================================
(Binary files differ)
Modified: trunk/src/skrueger/AttributeMetaData.java
===================================================================
--- trunk/src/skrueger/AttributeMetaData.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/AttributeMetaData.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -2,12 +2,12 @@
import org.apache.log4j.Logger;
-import skrueger.geotools.StyledMapInterface;
+import skrueger.geotools.StyledLayerInterface;
import skrueger.i8n.Translation;
/**
* This class holds meta information about an attribute/column. This
- * information is used by {@link StyledMapInterface}.
+ * information is used by {@link StyledLayerInterface}.
*
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
*/
Copied: trunk/src/skrueger/geotools/AbstractStyledLayer.java (from rev 215, trunk/src/skrueger/geotools/AbstractStyledMap.java)
===================================================================
--- trunk/src/skrueger/geotools/AbstractStyledMap.java 2009-07-13 19:05:15 UTC (rev 215)
+++ trunk/src/skrueger/geotools/AbstractStyledLayer.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -0,0 +1,253 @@
+package skrueger.geotools;
+
+import javax.swing.ImageIcon;
+
+import org.apache.log4j.Logger;
+import org.geotools.styling.Style;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import schmitzm.lang.LangUtil;
+import skrueger.i8n.Translation;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+/**
+ * This class is a default implementation of {@link StyledLayerInterface}.
+ * {@link StyledLayerInterface#dispose()} and {@link StyledLayerInterface#uncache()}
+ * must be implemented by the sub class. This class only implements the "hold"
+ * of an geo object of type {@code <E>}.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public abstract class AbstractStyledLayer<E> implements StyledLayerInterface<E> {
+ /** Logger for warning- and error messages. */
+ protected Logger LOGGER = LangUtil.createLogger(this);
+
+ /** Holds the unique ID of the geo object. */
+ protected String id = null;
+ /** Holds a short (language-specific) description of the geo object. */
+ protected Translation title = null;
+ /** Holds a long (language-specific) description of the geo object. */
+ protected Translation desc = null;
+ /** Holds the (language-specific) keywords to describe the geo object. */
+ protected Translation keywords = null;
+ /** Holds an icon to represent the geo object */
+ protected ImageIcon icon = null;
+ /** Holds the geo object represeneted by the map */
+ protected E geoObject = null;
+ /** Holds the CRS of the geo object */
+ protected CoordinateReferenceSystem crs = null;
+ /** Holds the bounds of the geo object */
+ protected Envelope envelope = null;
+ /** Holds the display style for the geo object */
+ protected Style style = null;
+
+ /**
+ * Creates a language specific styled map.
+ * @param geoObject the geo object
+ * @param envelope the bounds of the geo object
+ * @param crs the CRS of the geo object
+ * @param id a unique ID for the geo object
+ * @param title a (language-specific) short description
+ * @param desc a (language-specific) long description
+ * @param keywords (language-specific) keywords for the geo objects
+ * @param style a display style
+ * @param icon an icon for the object
+ * @exception IllegalArgumentException if {@code null} is given as ID or
+ * geo object
+ */
+ public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) {
+ if ( id == null )
+ throw new IllegalArgumentException("ID is not allowed to be null!");
+ if ( geoObject == null )
+ throw new IllegalArgumentException("The GeoObject is not allowed to be null!");
+ this.id = id;
+ this.geoObject = geoObject;
+ this.crs = crs;
+ this.envelope = envelope;
+ setTitle( title );
+ setDesc( desc );
+ setKeywords( keywords );
+ setStyle( style );
+ setImageIcon( icon );
+ }
+
+ /**
+ * Creates a non-translated styled map.
+ * @param geoObject the geo object
+ * @param envelope the bounds of the geo object
+ * @param crs the CRS of the geo object
+ * @param id a unique ID for the geo object
+ * @param title a short description
+ * @param desc a long description
+ * @param keywords keywords for the geo objects
+ * @param style a display style
+ * @param icon an icon for the object
+ * @exception IllegalArgumentException if {@code null} is given as ID
+ */
+ public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, String title, String desc, String keywords, Style style, ImageIcon icon ) {
+ this(geoObject, envelope, crs, id, (Translation)null, null, null, style, icon);
+ setTitle( title );
+ setDesc( desc );
+ setKeywords( keywords );
+ }
+
+ /**
+ * Returns a ID for the geo object. The ID should be unique in a map ob
+ * {@linkplain StyledLayerInterface styled map objects}
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Returns a short (language-specific) description of the geo object.
+ */
+ public Translation getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets a short (language-specific) description of the geo object.
+ * If {@code title} is {@code null} an untranslated default title is set, so
+ * {@link #getTitle()} never returns {@code null}.
+ * @param title new description for the geo object
+ */
+ public void setTitle(Translation title) {
+ this.title = (title != null) ? title : new Translation("untitled");
+ }
+
+ /**
+ * Sets a short (non-translated) description of the geo object.
+ * If {@code title} is {@code null} an untranslated default title is set, so
+ * {@link #getTitle()} never returns {@code null}.
+ * @param title new description for the geo object
+ */
+ public void setTitle(String title) {
+ setTitle( title != null ? new Translation(title): (Translation)null );
+ }
+
+ /**
+ * Returns a long (language-specific) description of the object.
+ */
+ public Translation getDesc() {
+ return desc;
+ }
+
+ /**
+ * Sets a long (language-specific) description of the object.
+ * If {@code desc} is {@code null} an (untranslated) empty description is set, so
+ * {@link #getDesc()} never returns {@code null}.
+ * @param desc new description for the geo object
+ */
+ public void setDesc(Translation desc) {
+ this.desc = (desc != null) ? desc : new Translation("");
+ }
+
+ /**
+ * Sets a long (non-translated) description of the object.
+ * If {@code desc} is {@code null} an (untranslated) empty description is set, so
+ * {@link #getDesc()} never returns {@code null}.
+ * @param desc new description for the geo object
+ */
+ public void setDesc(String desc) {
+ setDesc( desc != null ? new Translation(desc) : (Translation)null);
+ }
+
+ /**
+ * Returns a (language-specific) key word sequence for the geo object.
+ */
+ public Translation getKeywords() {
+ return keywords;
+ }
+
+ /**
+ * Sets a (language-specific) key word sequence for the geo object.
+ * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
+ * {@link #getKeywords()} never returns {@code null}.
+ * @param keywords Keywords
+ */
+ public void setKeywords(Translation keywords) {
+ this.keywords = (keywords != null) ? keywords : new Translation("");
+ }
+
+ /**
+ * Sets a (non-translated) key word sequence for the geo object.
+ * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
+ * {@link #getKeywords()} never returns {@code null}.
+ * @param keywords Keywords
+ */
+ public void setKeywords(String keywords) {
+ setKeywords( keywords != null ? new Translation(keywords) : (Translation)null);
+ }
+
+ /**
+ * Returns the geo object representet in the map. Sub classes must override
+ * this method to implement "late loading" on first call.
+ * @return {@link #geoObject}
+ */
+ public E getGeoObject() {
+ return geoObject;
+ }
+
+ /**
+ * Returns the bounds of the geo object.
+ */
+ public Envelope getEnvelope() {
+ return envelope;
+ }
+
+ /**
+ * Returns the {@link CoordinateReferenceSystem} of the geo object.
+ */
+ public CoordinateReferenceSystem getCrs() {
+ return crs;
+ }
+
+ /**
+ * Returns {@link #crs CoordinateReferenceSystem.toString()}. This method
+ * can be overriden to create a "nicer" description.
+ */
+ public String getCRSString() {
+ return crs.toString();
+ }
+
+ /**
+ * Returns an icon, which represents the geo object.
+ */
+ public ImageIcon getImageIcon() {
+ return null;
+ }
+
+ /**
+ * Sets an icon, which represents the geo object.
+ * @param icon an icon
+ */
+ public void setImageIcon(ImageIcon icon) {
+ this.icon = icon;
+ }
+
+ /**
+ * Returns the display style for the geo object.
+ */
+ public Style getStyle() {
+ return style;
+ }
+
+ /**
+ * Sets the display style for the geo object.
+ * If {@code style} is {@code null} an default style is set, so
+ * {@link #getStyle()} never returns {@code null}.
+ * @see #createDefaultStyle()
+ */
+ public void setStyle(Style style) {
+ this.style = (style != null) ? style : createDefaultStyle();
+ }
+
+ /**
+ * Creates a default style for the geo object. This style is used whenever
+ * the style is set to {@code null}.
+ * @see #setStyle(Style)
+ */
+ protected abstract Style createDefaultStyle();
+}
Deleted: trunk/src/skrueger/geotools/AbstractStyledMap.java
===================================================================
--- trunk/src/skrueger/geotools/AbstractStyledMap.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/AbstractStyledMap.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -1,253 +0,0 @@
-package skrueger.geotools;
-
-import javax.swing.ImageIcon;
-
-import org.apache.log4j.Logger;
-import org.geotools.styling.Style;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import schmitzm.lang.LangUtil;
-import skrueger.i8n.Translation;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-/**
- * This class is a default implementation of {@link StyledMapInterface}.
- * {@link StyledMapInterface#dispose()} and {@link StyledMapInterface#uncache()}
- * must be implemented by the sub class. This class only implements the "hold"
- * of an geo object of type {@code <E>}.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
- */
-public abstract class AbstractStyledMap<E> implements StyledMapInterface<E> {
- /** Logger for warning- and error messages. */
- protected Logger LOGGER = LangUtil.createLogger(this);
-
- /** Holds the unique ID of the geo object. */
- protected String id = null;
- /** Holds a short (language-specific) description of the geo object. */
- protected Translation title = null;
- /** Holds a long (language-specific) description of the geo object. */
- protected Translation desc = null;
- /** Holds the (language-specific) keywords to describe the geo object. */
- protected Translation keywords = null;
- /** Holds an icon to represent the geo object */
- protected ImageIcon icon = null;
- /** Holds the geo object represeneted by the map */
- protected E geoObject = null;
- /** Holds the CRS of the geo object */
- protected CoordinateReferenceSystem crs = null;
- /** Holds the bounds of the geo object */
- protected Envelope envelope = null;
- /** Holds the display style for the geo object */
- protected Style style = null;
-
- /**
- * Creates a language specific styled map.
- * @param geoObject the geo object
- * @param envelope the bounds of the geo object
- * @param crs the CRS of the geo object
- * @param id a unique ID for the geo object
- * @param title a (language-specific) short description
- * @param desc a (language-specific) long description
- * @param keywords (language-specific) keywords for the geo objects
- * @param style a display style
- * @param icon an icon for the object
- * @exception IllegalArgumentException if {@code null} is given as ID or
- * geo object
- */
- public AbstractStyledMap(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) {
- if ( id == null )
- throw new IllegalArgumentException("ID is not allowed to be null!");
- if ( geoObject == null )
- throw new IllegalArgumentException("The GeoObject is not allowed to be null!");
- this.id = id;
- this.geoObject = geoObject;
- this.crs = crs;
- this.envelope = envelope;
- setTitle( title );
- setDesc( desc );
- setKeywords( keywords );
- setStyle( style );
- setImageIcon( icon );
- }
-
- /**
- * Creates a non-translated styled map.
- * @param geoObject the geo object
- * @param envelope the bounds of the geo object
- * @param crs the CRS of the geo object
- * @param id a unique ID for the geo object
- * @param title a short description
- * @param desc a long description
- * @param keywords keywords for the geo objects
- * @param style a display style
- * @param icon an icon for the object
- * @exception IllegalArgumentException if {@code null} is given as ID
- */
- public AbstractStyledMap(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, String title, String desc, String keywords, Style style, ImageIcon icon ) {
- this(geoObject, envelope, crs, id, (Translation)null, null, null, style, icon);
- setTitle( title );
- setDesc( desc );
- setKeywords( keywords );
- }
-
- /**
- * Returns a ID for the geo object. The ID should be unique in a map ob
- * {@linkplain StyledMapInterface styled map objects}
- */
- public String getId() {
- return id;
- }
-
- /**
- * Returns a short (language-specific) description of the geo object.
- */
- public Translation getTitle() {
- return title;
- }
-
- /**
- * Sets a short (language-specific) description of the geo object.
- * If {@code title} is {@code null} an untranslated default title is set, so
- * {@link #getTitle()} never returns {@code null}.
- * @param title new description for the geo object
- */
- public void setTitle(Translation title) {
- this.title = (title != null) ? title : new Translation("untitled");
- }
-
- /**
- * Sets a short (non-translated) description of the geo object.
- * If {@code title} is {@code null} an untranslated default title is set, so
- * {@link #getTitle()} never returns {@code null}.
- * @param title new description for the geo object
- */
- public void setTitle(String title) {
- setTitle( title != null ? new Translation(title): (Translation)null );
- }
-
- /**
- * Returns a long (language-specific) description of the object.
- */
- public Translation getDesc() {
- return desc;
- }
-
- /**
- * Sets a long (language-specific) description of the object.
- * If {@code desc} is {@code null} an (untranslated) empty description is set, so
- * {@link #getDesc()} never returns {@code null}.
- * @param desc new description for the geo object
- */
- public void setDesc(Translation desc) {
- this.desc = (desc != null) ? desc : new Translation("");
- }
-
- /**
- * Sets a long (non-translated) description of the object.
- * If {@code desc} is {@code null} an (untranslated) empty description is set, so
- * {@link #getDesc()} never returns {@code null}.
- * @param desc new description for the geo object
- */
- public void setDesc(String desc) {
- setDesc( desc != null ? new Translation(desc) : (Translation)null);
- }
-
- /**
- * Returns a (language-specific) key word sequence for the geo object.
- */
- public Translation getKeywords() {
- return keywords;
- }
-
- /**
- * Sets a (language-specific) key word sequence for the geo object.
- * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
- * {@link #getKeywords()} never returns {@code null}.
- * @param keywords Keywords
- */
- public void setKeywords(Translation keywords) {
- this.keywords = (keywords != null) ? keywords : new Translation("");
- }
-
- /**
- * Sets a (non-translated) key word sequence for the geo object.
- * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
- * {@link #getKeywords()} never returns {@code null}.
- * @param keywords Keywords
- */
- public void setKeywords(String keywords) {
- setKeywords( keywords != null ? new Translation(keywords) : (Translation)null);
- }
-
- /**
- * Returns the geo object representet in the map. Sub classes must override
- * this method to implement "late loading" on first call.
- * @return {@link #geoObject}
- */
- public E getGeoObject() {
- return geoObject;
- }
-
- /**
- * Returns the bounds of the geo object.
- */
- public Envelope getEnvelope() {
- return envelope;
- }
-
- /**
- * Returns the {@link CoordinateReferenceSystem} of the geo object.
- */
- public CoordinateReferenceSystem getCrs() {
- return crs;
- }
-
- /**
- * Returns {@link #crs CoordinateReferenceSystem.toString()}. This method
- * can be overriden to create a "nicer" description.
- */
- public String getCRSString() {
- return crs.toString();
- }
-
- /**
- * Returns an icon, which represents the geo object.
- */
- public ImageIcon getImageIcon() {
- return null;
- }
-
- /**
- * Sets an icon, which represents the geo object.
- * @param icon an icon
- */
- public void setImageIcon(ImageIcon icon) {
- this.icon = icon;
- }
-
- /**
- * Returns the display style for the geo object.
- */
- public Style getStyle() {
- return style;
- }
-
- /**
- * Sets the display style for the geo object.
- * If {@code style} is {@code null} an default style is set, so
- * {@link #getStyle()} never returns {@code null}.
- * @see #createDefaultStyle()
- */
- public void setStyle(Style style) {
- this.style = (style != null) ? style : createDefaultStyle();
- }
-
- /**
- * Creates a default style for the geo object. This style is used whenever
- * the style is set to {@code null}.
- * @see #setStyle(Style)
- */
- protected abstract Style createDefaultStyle();
-}
Modified: trunk/src/skrueger/geotools/AttributeTableJDialog.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeTableJDialog.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/AttributeTableJDialog.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -25,8 +25,8 @@
//
///**
// * A dialog to show the attribute table of a vector layer. This class implements
-// * a {@link PropertyChangeListener} which is connected to the {@link StyledMapInterface
-// * StyledMapInterface's} {@link StyledLayerSelectionModel} to keep the table selection
+// * a {@link PropertyChangeListener} which is connected to the {@link StyledLayerInterface
+// * StyledLayerInterface's} {@link StyledLayerSelectionModel} to keep the table selection
// * synchronized to other component's selection (e.g. Map or chart).
// */
//public class AttributeTableJDialog extends JDialog {
@@ -43,10 +43,10 @@
//
// protected final MapLayer mapLayer;
//
-// private final StyledMapInterface styledObj;
+// private final StyledLayerInterface styledObj;
//
// private AttributeTableJDialog(Window owner, MapLayer mapLayer,
-// final StyledMapInterface styledObj, LayerPanel layerPanel) {
+// final StyledLayerInterface styledObj, LayerPanel layerPanel) {
// super(owner);
// this.styledObj = styledObj;
//// setTitle(RES("AttributeTable.dialog.title", styledObj
@@ -132,7 +132,7 @@
// }
//
// /**
-// * This class manages itself, that there is always only one instance for any {@link StyledMapInterface}
+// * This class manages itself, that there is always only one instance for any {@link StyledLayerInterface}
// *
// * @param dpLayer
// * The source for the attribute table
@@ -145,7 +145,7 @@
// * appear.
// */
// public static AttributeTableJDialog getInstanceFor(Component comp,
-// MapLayer mapLayer, final StyledMapInterface<?> styledObj,
+// MapLayer mapLayer, final StyledLayerInterface<?> styledObj,
// LayerPanel layerPanel) {
//
// AttributeTableJDialog atlasAttributeTableJDialog = dialogCache
Modified: trunk/src/skrueger/geotools/MapContextManagerInterface.java
===================================================================
--- trunk/src/skrueger/geotools/MapContextManagerInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/MapContextManagerInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -11,7 +11,7 @@
/**
* Implementations of this class can can be used to fill/insert/remove a mapContext
- * with {@link StyledMapInterface} objects.
+ * with {@link StyledLayerInterface} objects.
*
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
*
@@ -19,24 +19,24 @@
public interface MapContextManagerInterface {
/**
- * Add a {@link StyledMapInterface} object into the underlying {@link MapContext}
+ * Add a {@link StyledLayerInterface} object into the underlying {@link MapContext}
* as the topmost layer
*
- * @param styledMapObject Obejct to add to the layer
+ * @param styledLayer Layer to add to the map
*/
- boolean addStyledLayer (StyledMapInterface<?> styledMapObject);
+ boolean addStyledLayer (StyledLayerInterface<?> styledLayer);
/**
- * @param mapContextIdx Index in the mapcontext, bottom first
- * @return sucessful?
+ * @param mapContextIdx Index in the {@link MapContext}, bottom first
+ * @return successful?
*/
boolean removeStyledLayer (int mapContextIdx);
/**
- * Inserts a {@link StyledMapInterface} object into the underlying {@link MapContext}
+ * Inserts a {@link StyledLayerInterface} object into the underlying {@link MapContext}
* at the given position
*/
- boolean insertStyledLayer (StyledMapInterface<?> styledMapObject, int mapContextIdx);
+ boolean insertStyledLayer (StyledLayerInterface<?> styledLayer, int mapContextIdx);
/** Add {@link MapLayerListener} */
void addMapLayerListListener( MapLayerListListener listener);
@@ -52,36 +52,36 @@
/**
* Returns a ordered list of the layers that are contained in the underlying {@link MapContext}
*/
- List<StyledMapInterface<?>> getStyledObjects();
+ List<StyledLayerInterface<?>> getStyledObjects();
/**
* Returns a list of {@link AttributeMetaData} that shall be shown (e.g. when the Mouse clicked into the map)
* Returns an empty list if the layer doesn't exist or is not backed by a {@link StyledFeatureCollectionInterface}
*/
- List<AttributeMetaData> getVisibleAttribsFor(MapLayer layer);
+ List<AttributeMetaData> getVisibleAttribsFor(MapLayer mapLayer);
/**
* Returns the title of the layer
- * @param layer {@link MapLayer}
- * @return null, if the layer is unknown
+ * @param mapLayer {@link MapLayer}
+ * @return <code>null</code>, if the layer is unknown
*/
- String getTitleFor(MapLayer layer);
+ String getTitleFor(MapLayer mapLayer);
/**
* Returns the description of the layer
- * @param layer {@link MapLayer}
- * @return null, if the layer is unknown. Empty String if the description is empty
+ * @param mapLayer {@link MapLayer}
+ * @return <code>null</code>, if the layer is unknown. Empty String if the description is empty
*/
- String getDescFor(MapLayer layer);
+ String getDescFor(MapLayer mapLayer);
/**
* Returns the {@link RasterLegendData} object for the layer.
* @return null, if the layer is not found or of type raster
*/
- RasterLegendData getLegendMetaData(MapLayer layer);
+ RasterLegendData getLegendMetaData(MapLayer mapLayer);
/**
- * Ruturns the {@link StyledMapInterface} object that is associated with the layer or NULL if the layer can't be found.
+ * Returns the {@link StyledLayerInterface} object that is associated with the layer or NULL if the layer can't be found.
*/
- StyledMapInterface<?> getStyledObjectFor(MapLayer layer);
+ StyledLayerInterface<?> getStyledObjectFor(MapLayer layer);
}
Modified: trunk/src/skrueger/geotools/StyledFeatureCollection.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollection.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledFeatureCollection.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -19,7 +19,7 @@
import skrueger.i8n.Translation;
/**
- * This class provides a simple implementation of {@link StyledMapInterface} for
+ * This class provides a simple implementation of {@link StyledLayerInterface} for
* {@link FeatureCollection}. The uncache functionality is not supported,
* because this class bases on an existing {@link FeatureCollection} object in
* memory.
@@ -29,7 +29,7 @@
* @version 1.0
*/
public class StyledFeatureCollection extends
- AbstractStyledMap<FeatureCollection> implements
+ AbstractStyledLayer<FeatureCollection> implements
StyledFeatureCollectionInterface {
/** Holds the meta data for displaying a legend. */
@@ -95,7 +95,7 @@
*/
public StyledFeatureCollection(FeatureCollection fc, String id,
Translation title, Translation desc, Translation keywords,
- StyledMapStyle<Map<Integer, AttributeMetaData>> style,
+ StyledLayerStyle<Map<Integer, AttributeMetaData>> style,
ImageIcon icon) {
super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry()
.getCoordinateSystem(), id, title, desc, keywords,
@@ -180,7 +180,7 @@
*/
public StyledFeatureCollection(FeatureCollection fc, String id,
String title, String desc, String keywords,
- StyledMapStyle<Map<Integer, AttributeMetaData>> style,
+ StyledLayerStyle<Map<Integer, AttributeMetaData>> style,
ImageIcon icon) {
this(fc, id, title, desc, keywords, style != null ? style
.getGeoObjectStyle() : null, style != null ? style
@@ -227,7 +227,7 @@
* @see #createDefaultAttributeMetaDataMap(FeatureCollection)
*/
public StyledFeatureCollection(FeatureCollection fc, String id,
- String title, StyledMapStyle<Map<Integer, AttributeMetaData>> style) {
+ String title, StyledLayerStyle<Map<Integer, AttributeMetaData>> style) {
this(fc, id, title, null, null, style != null ? style
.getGeoObjectStyle() : null, style != null ? style
.getMetaData() : null, null);
@@ -306,7 +306,7 @@
}
/**
- * Does nothing, because the {@link AbstractStyledMap} bases on existing
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
* objects (in memory) which can not be uncached and reloaded.
*/
public void uncache() {
@@ -321,7 +321,7 @@
/*
* (non-Javadoc)
*
- * @see skrueger.geotools.StyledMapInterface#getInfoURL()
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
*/
public URL getInfoURL() {
return null;
Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -7,10 +7,8 @@
import skrueger.AttributeMetaData;
/**
- * {@link StyledMapInterface} which contains a {@link FeatureCollection} as geo object.<br>
+ * {@link StyledLayerInterface} which contains a {@link FeatureCollection} as geo object.<br>
*/
public interface StyledFeatureCollectionInterface extends StyledFeaturesInterface<FeatureCollection> {
- public abstract Map<Integer,AttributeMetaData> getAttributeMetaDataMap();
-
}
Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -33,7 +33,7 @@
/**
* This class extends the the {@link FeatureCollectionTableModel} with the
* functionalities of the {@link AttributeMetaData} of
- * {@linkplain StyledMapInterface styled objects}.
+ * {@linkplain StyledLayerInterface styled objects}.
* <ul>
* <li>column names are translated according to
* {@link AttributeMetaData#getTitle()}</li>
@@ -48,7 +48,7 @@
final static private Logger LOGGER = Logger
.getLogger(StyledFeatureCollectionTableModel.class);
/** Holds the data source as styled map. */
- protected StyledMapInterface<?> map = null;
+ protected StyledLayerInterface<?> layer = null;
/** Contains only the visible elements of the {@link AttributeMetaData}-Map */
protected Map<Integer, AttributeMetaData> visibleAMD = null;
/** Holds the data source for the table as {@code FeatureSource}. */
@@ -60,53 +60,56 @@
/** Holds the Bounds for all features. Only set once during the constructor **/
protected Envelope bounds;
+
+
/**
* Creates a new table model for a styled map.
*
- * @param map
- * the styled map
+ * @param layer
+ * the styled layer
*/
public StyledFeatureCollectionTableModel(
- StyledFeatureCollectionInterface map) {
- this(map, Filter.INCLUDE);
+ StyledFeatureCollectionInterface layer) {
+ this(layer, Filter.INCLUDE);
}
/**
* Creates a new table model for a styled map.
*
- * @param map
- * the styled map
+ * @param layer
+ * the styled layer
* @param filter
* filter applied to the table
*/
public StyledFeatureCollectionTableModel(
- StyledFeatureCollectionInterface map, Filter filter) {
+ StyledFeatureCollectionInterface layer, Filter filter) {
super();
- setFeatureCollection(map, filter);
+ setFeatureCollection(layer, filter);
}
+
/**
* Creates a new table model for a styled map.
*
- * @param map
- * the styled map
+ * @param layer
+ * the styled layer
*/
- public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
- this(map, Filter.INCLUDE);
+ public StyledFeatureCollectionTableModel(StyledFeaturesInterface layer) {
+ this(layer, Filter.INCLUDE);
}
/**
* Creates a new table model for a styled map.
*
- * @param map
- * the styled map
+ * @param layer
+ * the styled layer
* @param filter
* filter applied to the table
*/
- public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map,
+ public StyledFeatureCollectionTableModel(StyledFeaturesInterface layer,
Filter filter) {
super();
- setFeatureCollection(map, filter);
+ setFeatureCollection(layer, filter);
}
/**
@@ -137,7 +140,7 @@
Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
if (amd != null) {
// determine the names of the visible Attributes
- this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(
+ this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData(
amd, true);
Vector<String> visibleAttrNames = new Vector<String>();
// Add the column with the geometry (usually "the_geom")
@@ -197,18 +200,18 @@
* {@link AttributeMetaData}-Map to define the visible attributes
* and translation
*/
- public void setFeatureCollection(StyledFeatureCollectionInterface map,
+ public void setFeatureCollection(StyledFeaturesInterface layer,
Filter filter) {
- this.map = map;
+ this.layer = layer;
try {
- if (map == null)
+ if (layer == null)
setFeatureSource(null, null, null);
else {
- FeatureCollection fc = map.getGeoObject();
+ FeatureCollection fc = layer.getFeatureCollection();
String fcName = fc.getSchema().getTypeName();
FeatureSource fs = new MemoryDataStore(fc)
.getFeatureSource(fcName);
- setFeatureSource(fs, map.getAttributeMetaDataMap(), filter);
+ setFeatureSource(fs, layer.getAttributeMetaDataMap(), filter);
}
} catch (Exception err) {
throw new RuntimeException(err);
@@ -225,14 +228,14 @@
* {@link AttributeMetaData}-Map to define the visible attributes
* and translation
*/
- public void setFeatureCollection(StyledFeatureSourceInterface map,
+ public void setFeatureCollection(StyledFeatureSourceInterface layer,
Filter filter) {
- this.map = map;
+ this.layer = layer;
try {
- if (map == null)
+ if (layer == null)
setFeatureSource(null, null, null);
else
- setFeatureSource(map.getGeoObject(), map
+ setFeatureSource(layer.getGeoObject(), layer
.getAttributeMetaDataMap(), filter);
} catch (Exception err) {
throw new RuntimeException(err);
Modified: trunk/src/skrueger/geotools/StyledFeatureSourceInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureSourceInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledFeatureSourceInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -7,7 +7,7 @@
import skrueger.AttributeMetaData;
/**
- * {@link StyledMapInterface} which contains a {@link FeatureSource} as geo object.<br>
+ * {@link StyledLayerInterface} which contains a {@link FeatureSource} as geo object.<br>
*/
public interface StyledFeatureSourceInterface extends StyledFeaturesInterface<FeatureSource> {
Modified: trunk/src/skrueger/geotools/StyledFeaturesInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeaturesInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledFeaturesInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -1,8 +1,12 @@
package skrueger.geotools;
+import java.util.Map;
+
import org.geotools.data.FeatureSource;
import org.opengis.feature.FeatureCollection;
+import skrueger.AttributeMetaData;
+
/**
* This Interface combines all styled layers that are running on {@link FeatureCollection} or {@link FeatureSource}
*
@@ -10,8 +14,10 @@
*
* @param <T> The base Type returned in the getObject() method.
*/
-public interface StyledFeaturesInterface<T> extends StyledMapInterface<T>{
+public interface StyledFeaturesInterface<T> extends StyledLayerInterface<T>{
+ public abstract Map<Integer,AttributeMetaData> getAttributeMetaDataMap();
+
/**
* @return The features of this layer as a {@link FeatureSource}.
*/
Modified: trunk/src/skrueger/geotools/StyledGridCoverage.java
===================================================================
--- trunk/src/skrueger/geotools/StyledGridCoverage.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledGridCoverage.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -13,14 +13,14 @@
import skrueger.i8n.Translation;
/**
- * This class provides a simple implementation of {@link StyledMapInterface}
+ * This class provides a simple implementation of {@link StyledLayerInterface}
* for {@link GridCoverage2D}. The uncache functionality is not supported,
* because this class bases on an existing {@link GridCoverage2D} object in
* memory.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
*/
-public class StyledGridCoverage extends AbstractStyledMap<GridCoverage2D> implements StyledGridCoverageInterface {
+public class StyledGridCoverage extends AbstractStyledLayer<GridCoverage2D> implements StyledGridCoverageInterface {
/** Holds the meta data for displaying a legend. */
protected RasterLegendData legendData = null;
@@ -53,7 +53,7 @@
* @param icon an icon for the object (can be {@code null})
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {
+ public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc.getCoordinateReferenceSystem(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);
setLegendMetaData( style != null ? style.getMetaData() : null );
}
@@ -102,7 +102,7 @@
* @param icon an icon for the object (can be {@code null})
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {
+ public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
this(gc,
id,
title,
@@ -136,7 +136,7 @@
* @param style a display style with legend information
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverage(GridCoverage2D gc, String id, String title, StyledMapStyle<RasterLegendData> style) {
+ public StyledGridCoverage(GridCoverage2D gc, String id, String title, StyledLayerStyle<RasterLegendData> style) {
this(gc,
id,
title,
@@ -193,7 +193,7 @@
}
/**
- * Does nothing, because the {@link AbstractStyledMap} bases on existing
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
* objects (in memory) which can not be uncached and reloaded.
*/
public void uncache() {
@@ -202,7 +202,7 @@
/*
* (non-Javadoc)
- * @see skrueger.geotools.StyledMapInterface#getInfoURL()
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
*/
public URL getInfoURL() {
return null;
Modified: trunk/src/skrueger/geotools/StyledGridCoverageReader.java
===================================================================
--- trunk/src/skrueger/geotools/StyledGridCoverageReader.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledGridCoverageReader.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -14,14 +14,14 @@
import skrueger.i8n.Translation;
/**
- * This class provides a simple implementation of {@link StyledMapInterface}
+ * This class provides a simple implementation of {@link StyledLayerInterface}
* for {@link AbstractGridCoverage2DReader}. The uncache functionality is not supported,
* because if the coverage is read once this class bases on an existing {@link GridCoverage2D}
* object in memory.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
*/
-public class StyledGridCoverageReader extends AbstractStyledMap<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface {
+public class StyledGridCoverageReader extends AbstractStyledLayer<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface {
/** Holds the meta data for displaying a legend. */
protected RasterLegendData legendData = null;
@@ -54,7 +54,7 @@
* @param icon an icon for the object (can be {@code null})
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);
setLegendMetaData( style != null ? style.getMetaData() : null );
}
@@ -103,7 +103,7 @@
* @param icon an icon for the object (can be {@code null})
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
this(gcr,
id,
title,
@@ -137,7 +137,7 @@
* @param style a display style with legend information
* @exception IllegalArgumentException if {@code null} is given as ID or geo object
*/
- public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledMapStyle<RasterLegendData> style) {
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledLayerStyle<RasterLegendData> style) {
this(gcr,
id,
title,
@@ -194,7 +194,7 @@
}
/**
- * Does nothing, because the {@link AbstractStyledMap} bases on existing
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
* objects (in memory) which can not be uncached and reloaded.
*/
public void uncache() {
@@ -203,7 +203,7 @@
/*
* (non-Javadoc)
- * @see skrueger.geotools.StyledMapInterface#getInfoURL()
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
*/
public URL getInfoURL() {
return null;
Copied: trunk/src/skrueger/geotools/StyledLayerInterface.java (from rev 215, trunk/src/skrueger/geotools/StyledMapInterface.java)
===================================================================
--- trunk/src/skrueger/geotools/StyledMapInterface.java 2009-07-13 19:05:15 UTC (rev 215)
+++ trunk/src/skrueger/geotools/StyledLayerInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -0,0 +1,132 @@
+package skrueger.geotools;
+
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.geotools.feature.FeatureCollection;
+import org.geotools.styling.Style;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import skrueger.AttributeMetaData;
+import skrueger.RasterLegendData;
+import skrueger.i8n.Translation;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+/**
+ * This class is the top interface for styled objects to be managed in
+ * {@link MapContextManagerInterface}. The (rough) classe structure is the
+ * following:
+ * <ul>
+ * <li><b>{@link StyledLayerInterface StyledLayerInterface<E>}</b>
+ * <ul>
+ * <li>{@link #getId()} -> String</li>
+ * <li>{@link #getKeywords() get/setKeywords()} -> {@link Translation}</li>
+ * <li>{@link #getTitle() set/getTitle()} -> {@link Translation} (short
+ * description for layer list)</li>
+ * <li>{@link #getDesc() set/getDesc()} -> {@link Translation} (long description
+ * for details)</li>
+ * <li>{@link #getCrs()} -> {@link CoordinateReferenceSystem}</li>
+ * <li>{@link #getCRSString()} -> String (readable description of CRS)</li>
+ * <li>{@link #getEnvelope()} -> {@link Envelope} (JTS-Envelope)</li>
+ * <li>{@link #getGeoObject()} -> E (GridCoverage/FeatureCollection/...)</li>
+ * <li>{@link #getStyle() set/getStyle()} -> {@link Style}</li>
+ * <li>{@link #uncache()}</li>
+ * <li>{@link #dispose()}</li>
+ * </ul>
+ * </li>
+ * <li><b>{@link StyledFeatureCollectionInterface} extends
+ * {@link StyledLayerInterface StyledLayerInterface<FeatureCollection>}</b>
+ * <ul>
+ * <li>{@link StyledFeatureCollectionInterface#getAttributeMetaDataMap()} ->
+ * Map<Integer,AttributeMetaData></li>
+ * </ul>
+ * </li>
+ * <li><b>{@link StyledRasterInterface} extends {@link StyledLayerInterface
+ * StyledLayerInterface<GridCoverage2D>}</b>
+ * <ul>
+ * <li>{@link StyledRasterInterface#getLegendMetaData()} ->
+ * {@link RasterLegendData}</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * <br>
+ * <b>Restrictions:</b>
+ * <ul>
+ * <li>layer list only depends on {@link StyledLayerInterface}</li>
+ * <li>methods returning {@link Translation} must not return {@code null}</li>
+ * <li>methods returning {@link AttributeMetaData}-Map must not return {@code
+ * null}</li>
+ * <li>static helper method to get a new {@link AttributeMetaData}-map withe the
+ * visible attributes only</li>
+ * <li>static helper method to create a "default" {@link AttributeMetaData}-map
+ * for a {@link FeatureCollection} with all attributes visible and without real
+ * translations, but the attribute name as description.</li>
+ * </ul>
+ */
+public interface StyledLayerInterface<E> {
+ public String getId();
+
+ public Translation getTitle();
+
+ public void setTitle(Translation title);
+
+ public Translation getDesc();
+
+ public void setDesc(Translation dec);
+
+ public Translation getKeywords();
+
+ public void setKeywords(Translation keywords);
+
+ public CoordinateReferenceSystem getCrs();
+
+ public String getCRSString();
+
+ public Envelope getEnvelope();
+
+ /**
+ * @return return an ImageIcon - <code>null</code> is valid and no icon or a
+ * default icon will then be shown
+ */
+ public ImageIcon getImageIcon();
+
+ public void setImageIcon(ImageIcon icon);
+
+ /**
+ * Returns the underlying GeoTools Object
+ *
+ * @throws RuntimeException
+ */
+ public E getGeoObject();
+
+ public Style getStyle();
+
+ public void setStyle(Style style);
+
+ /**
+ * Returns the {@link URL} to a (HTML) file that provides more information
+ * about this layer. If no HTML if associated with this
+ * {@link StyledLayerInterface}, then <code>null</code> will be returned.
+ *
+ * @return null or an {@link URL}
+ */
+ public URL getInfoURL();
+
+ /**
+ * Should be called when this Object is not needed anymore.
+ */
+ public void dispose();
+
+ /** Is the object already disposed? * */
+ public boolean isDisposed();
+
+ /**
+ * Clears any caches. For example the GeoObject could be released, and
+ * reread on next call of getGeoObject()
+ */
+ public void uncache();
+
+
+}
Copied: trunk/src/skrueger/geotools/StyledLayerStyle.java (from rev 215, trunk/src/skrueger/geotools/StyledMapStyle.java)
===================================================================
--- trunk/src/skrueger/geotools/StyledMapStyle.java 2009-07-13 19:05:15 UTC (rev 215)
+++ trunk/src/skrueger/geotools/StyledLayerStyle.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -0,0 +1,58 @@
+package skrueger.geotools;
+
+import org.geotools.styling.Style;
+
+/**
+ * This class combines a Geotools visualisation {@link Style} with additional
+ * meta data needed for visualisation (for example legend data).
+ * The class {@code E} defines the type of the meta data.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class StyledLayerStyle<E> {
+ /** Holds the Geotools {@link Style} for the geo object visualisation. */
+ protected Style geoObjectStyle = null;
+ /** Holds the additional meta data for object visualisation (for example
+ * legend information). */
+ protected E metaData = null;
+
+ /**
+ * Creates a new style for a {@link StyledLayerInterface}.
+ * @param style Style
+ * @param metaData E
+ */
+ public StyledLayerStyle(Style style, E metaData) {
+ setGeoObjectStyle(style);
+ setMetaData(metaData);
+ }
+
+ /**
+ * Returns the additional meta data needed for object visualisation.
+ */
+ public E getMetaData() {
+ return metaData;
+ }
+
+ /**
+ * Sets the additional meta data needed for object visualisation.
+ * @param metaData the meta data
+ */
+ public void setMetaData(E metaData) {
+ this.metaData = metaData;
+ }
+
+ /**
+ * Returns the Geotools style for the object visualisation.
+ */
+ public Style getGeoObjectStyle() {
+ return geoObjectStyle;
+ }
+
+ /**
+ * Sets the Geotools style for the object visualisation.
+ * @param style a Geotools visualisation style
+ */
+ public void setGeoObjectStyle(Style style) {
+ this.geoObjectStyle = style;
+ }
+}
Copied: trunk/src/skrueger/geotools/StyledLayerUtil.java (from rev 215, trunk/src/skrueger/geotools/StyledMapUtil.java)
===================================================================
--- trunk/src/skrueger/geotools/StyledMapUtil.java 2009-07-13 19:05:15 UTC (rev 215)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -0,0 +1,699 @@
+package skrueger.geotools;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.net.URL;
+import java.text.DecimalFormat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.MapLayer;
+import org.geotools.styling.ColorMap;
+import org.geotools.styling.ColorMapEntry;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Style;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+
+import schmitzm.geotools.styling.StylingUtil;
+import schmitzm.io.IOUtil;
+import schmitzm.lang.LangUtil;
+import schmitzm.swing.SwingUtil;
+import skrueger.AttributeMetaData;
+import skrueger.RasterLegendData;
+import skrueger.i8n.Translation;
+
+/**
+ * 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)
+ * @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();
+
+ /** 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
+ * @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 ( layer == null )
+ throw new Exception("Can not create MapLayer from "+(object == null ? "null" : object.getClass()));
+
+ 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 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";
+
+ 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()));
+
+ return styledLayer;
+ }
+
+ /**
+ * 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");
+
+ Translation name = new Translation();
+ Translation desc = new Translation();
+ for (final Element childElement : (List<Element>)element.getChildren()) {
+ if (childElement.getName() == null)
+ continue;
+
+ 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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();
+ }
+
+
+
+ /**
+ * 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) {
+
+ final boolean paintGaps = Boolean.valueOf( element.getAttributeValue("paintGaps") );
+
+ RasterLegendData rld = new RasterLegendData(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;
+
+ 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);
+
+ // 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);
+ }
+ }
+
+ return rld;
+ }
+
+ /**
+ * 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 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 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 {@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);
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * 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();
+
+ if (element == null)
+ return trans;
+
+ for (final Element translationElement : (List<Element>)element.getChildren()) {
+ final String name = translationElement.getName();
+ if (name == null)
+ continue;
+
+ // lang attribute
+ String lang = translationElement.getAttributeValue("lang");
+ // set the default, if no language code is set
+ if ( lang == null )
+ lang = Translation.DEFAULT_KEY;
+
+ final String translationText = translationElement.getValue();
+ if (translationText == null)
+ trans.put(lang, "");
+ else
+ trans.put(lang, translationText);
+ }
+
+ // 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() );
+
+ return trans;
+ }
+
+ /**
+ * 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!");
+
+ // 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;
+ }
+
+ // 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;
+ }
+
+ 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 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()
+ );
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ 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);
+ }
+
+ /**
+ * 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
+ )
+ );
+ }
+
+ // 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");
+ }
+
+}
Deleted: trunk/src/skrueger/geotools/StyledMapInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledMapInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledMapInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -1,132 +0,0 @@
-package skrueger.geotools;
-
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-
-import org.geotools.feature.FeatureCollection;
-import org.geotools.styling.Style;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import skrueger.AttributeMetaData;
-import skrueger.RasterLegendData;
-import skrueger.i8n.Translation;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-/**
- * This class is the top interface for styled objects to be managed in
- * {@link MapContextManagerInterface}. The (rough) classe structure is the
- * following:
- * <ul>
- * <li><b>{@link StyledMapInterface StyledMapInterface<E>}</b>
- * <ul>
- * <li>{@link #getId()} -> String</li>
- * <li>{@link #getKeywords() get/setKeywords()} -> {@link Translation}</li>
- * <li>{@link #getTitle() set/getTitle()} -> {@link Translation} (short
- * description for layer list)</li>
- * <li>{@link #getDesc() set/getDesc()} -> {@link Translation} (long description
- * for details)</li>
- * <li>{@link #getCrs()} -> {@link CoordinateReferenceSystem}</li>
- * <li>{@link #getCRSString()} -> String (readable description of CRS)</li>
- * <li>{@link #getEnvelope()} -> {@link Envelope} (JTS-Envelope)</li>
- * <li>{@link #getGeoObject()} -> E (GridCoverage/FeatureCollection/...)</li>
- * <li>{@link #getStyle() set/getStyle()} -> {@link Style}</li>
- * <li>{@link #uncache()}</li>
- * <li>{@link #dispose()}</li>
- * </ul>
- * </li>
- * <li><b>{@link StyledFeatureCollectionInterface} extends
- * {@link StyledMapInterface StyledMapInterface<FeatureCollection>}</b>
- * <ul>
- * <li>{@link StyledFeatureCollectionInterface#getAttributeMetaDataMap()} ->
- * Map<Integer,AttributeMetaData></li>
- * </ul>
- * </li>
- * <li><b>{@link StyledRasterInterface} extends {@link StyledMapInterface
- * StyledMapInterface<GridCoverage2D>}</b>
- * <ul>
- * <li>{@link StyledRasterInterface#getLegendMetaData()} ->
- * {@link RasterLegendData}</li>
- * </ul>
- * </li>
- * </ul>
- * <br>
- * <b>Restrictions:</b>
- * <ul>
- * <li>layer list only depends on {@link StyledMapInterface}</li>
- * <li>methods returning {@link Translation} must not return {@code null}</li>
- * <li>methods returning {@link AttributeMetaData}-Map must not return {@code
- * null}</li>
- * <li>static helper method to get a new {@link AttributeMetaData}-map withe the
- * visible attributes only</li>
- * <li>static helper method to create a "default" {@link AttributeMetaData}-map
- * for a {@link FeatureCollection} with all attributes visible and without real
- * translations, but the attribute name as description.</li>
- * </ul>
- */
-public interface StyledMapInterface<E> {
- public String getId();
-
- public Translation getTitle();
-
- public void setTitle(Translation title);
-
- public Translation getDesc();
-
- public void setDesc(Translation dec);
-
- public Translation getKeywords();
-
- public void setKeywords(Translation keywords);
-
- public CoordinateReferenceSystem getCrs();
-
- public String getCRSString();
-
- public Envelope getEnvelope();
-
- /**
- * @return return an ImageIcon - <code>null</code> is valid and no icon or a
- * default icon will then be shown
- */
- public ImageIcon getImageIcon();
-
- public void setImageIcon(ImageIcon icon);
-
- /**
- * Returns the underlying GeoTools Object
- *
- * @throws RuntimeException
- */
- public E getGeoObject();
-
- public Style getStyle();
-
- public void setStyle(Style style);
-
- /**
- * Returns the {@link URL} to a (HTML) file that provides more information
- * about this layer. If no HTML if associated with this
- * {@link StyledMapInterface}, then <code>null</code> will be returned.
- *
- * @return null or an {@link URL}
- */
- public URL getInfoURL();
-
- /**
- * Should be called when this Object is not needed anymore.
- */
- public void dispose();
-
- /** Is the object already disposed? * */
- public boolean isDisposed();
-
- /**
- * Clears any caches. For example the GeoObject could be released, and
- * reread on next call of getGeoObject()
- */
- public void uncache();
-
-
-}
Deleted: trunk/src/skrueger/geotools/StyledMapStyle.java
===================================================================
--- trunk/src/skrueger/geotools/StyledMapStyle.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledMapStyle.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -1,58 +0,0 @@
-package skrueger.geotools;
-
-import org.geotools.styling.Style;
-
-/**
- * This class combines a Geotools visualisation {@link Style} with additional
- * meta data needed for visualisation (for example legend data).
- * The class {@code E} defines the type of the meta data.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
- */
-public class StyledMapStyle<E> {
- /** Holds the Geotools {@link Style} for the geo object visualisation. */
- protected Style geoObjectStyle = null;
- /** Holds the additional meta data for object visualisation (for example
- * legend information). */
- protected E metaData = null;
-
- /**
- * Creates a new style for a {@link StyledMapInterface}.
- * @param style Style
- * @param metaData E
- */
- public StyledMapStyle(Style style, E metaData) {
- setGeoObjectStyle(style);
- setMetaData(metaData);
- }
-
- /**
- * Returns the additional meta data needed for object visualisation.
- */
- public E getMetaData() {
- return metaData;
- }
-
- /**
- * Sets the additional meta data needed for object visualisation.
- * @param metaData the meta data
- */
- public void setMetaData(E metaData) {
- this.metaData = metaData;
- }
-
- /**
- * Returns the Geotools style for the object visualisation.
- */
- public Style getGeoObjectStyle() {
- return geoObjectStyle;
- }
-
- /**
- * Sets the Geotools style for the object visualisation.
- * @param style a Geotools visualisation style
- */
- public void setGeoObjectStyle(Style style) {
- this.geoObjectStyle = style;
- }
-}
Deleted: trunk/src/skrueger/geotools/StyledMapUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledMapUtil.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledMapUtil.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -1,699 +0,0 @@
-package skrueger.geotools;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.net.URL;
-import java.text.DecimalFormat;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.log4j.Logger;
-import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.map.DefaultMapLayer;
-import org.geotools.map.MapLayer;
-import org.geotools.styling.ColorMap;
-import org.geotools.styling.ColorMapEntry;
-import org.geotools.styling.RasterSymbolizer;
-import org.geotools.styling.Style;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.XMLOutputter;
-
-import schmitzm.geotools.styling.StylingUtil;
-import schmitzm.io.IOUtil;
-import schmitzm.lang.LangUtil;
-import schmitzm.swing.SwingUtil;
-import skrueger.AttributeMetaData;
-import skrueger.RasterLegendData;
-import skrueger.i8n.Translation;
-
-/**
- * This class provides static helper methods for dealing with
- * {@link StyledMapInterface} stuff.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
- */
-public class StyledMapUtil {
- private static final Logger LOGGER = Logger.getLogger(StyledMapUtil.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";
-
- /**
- * Creates a Geotools {@link MapLayer} from an object. If the object is a
- * {@link StyledMapInterface} 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 StyledMapInterface} 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 StyledMapInterface ) {
- style = ((StyledMapInterface<?>)object).getStyle();
- object = ((StyledMapInterface<?>)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 ( layer == null )
- throw new Exception("Can not create MapLayer from "+(object == null ? "null" : object.getClass()));
-
- return layer;
- }
-
- /**
- * Creates an default instance of {@link StyledMapInterface} 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 StyledMapInterface<?> createStyledMap(Object object, String title) {
- return createStyledMap(object, title, null);
- }
-
- /**
- * Creates an default instance of {@link StyledMapInterface} 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 StyledMapInterface<?> createStyledMap(Object object, String title, StyledMapStyle style) {
- StyledMapInterface<?> styledObject = null;
-
- String id = (title != null) ? title : "defaultID";
-
- if ( object instanceof GridCoverage2D )
- styledObject = new StyledGridCoverage(
- (GridCoverage2D)object,
- id,
- title,
- style
- );
- else if ( object instanceof AbstractGridCoverage2DReader )
- styledObject = new StyledGridCoverageReader(
- (AbstractGridCoverage2DReader)object,
- id,
- title,
- style
- );
- else if ( object instanceof FeatureCollection )
- styledObject = new StyledFeatureCollection(
- (FeatureCollection)object,
- id,
- title,
- style
- );
-
- if ( styledObject == null )
- throw new UnsupportedOperationException("Can not create StyledMapInterface object from "+(object == null ? "null" : object.getClass()));
-
- return styledObject;
- }
-
- /**
- * 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");
-
- Translation name = new Translation();
- Translation desc = new Translation();
- for (final Element childElement : (List<Element>)element.getChildren()) {
- if (childElement.getName() == null)
- continue;
-
- 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);
- }
-
- /**
- * 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;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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();
- }
-
-
-
- /**
- * 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) {
-
- final boolean paintGaps = Boolean.valueOf( element.getAttributeValue("paintGaps") );
-
- RasterLegendData rld = new RasterLegendData(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;
-
- 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);
-
- // 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);
- }
- }
-
- return rld;
- }
-
- /**
- * 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 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 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 {@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);
- }
-
- /**
- * 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();
- }
-
- /**
- * 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();
-
- if (element == null)
- return trans;
-
- for (final Element translationElement : (List<Element>)element.getChildren()) {
- final String name = translationElement.getName();
- if (name == null)
- continue;
-
- // lang attribute
- String lang = translationElement.getAttributeValue("lang");
- // set the default, if no language code is set
- if ( lang == null )
- lang = Translation.DEFAULT_KEY;
-
- final String translationText = translationElement.getValue();
- if (translationText == null)
- trans.put(lang, "");
- else
- trans.put(lang, translationText);
- }
-
- // 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() );
-
- return trans;
- }
-
- /**
- * 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!");
-
- // 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;
- }
-
- // 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 StyledMapInterface}.
- * @param styledObject a styled object
- * @param style a Style
- */
- public static void setStyledMapStyle(StyledMapInterface styledObject, StyledMapStyle<?> 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()));
- }
-
- /**
- * Returns the style a {@link StyledMapInterface} as a {@link StyledMapStyle}.
- * @param styledObject a styled object
- * @return {@code StyledMapStyle<RasterLegendData>} for {@link StyledGridCoverageInterface}
- * or {@code StyledMapStyle<Map<Integer,AttributeMetaData>>} for
- * {@link StyledFeatureCollectionInterface}
- */
- public static StyledMapStyle<?> getStyledMapStyle(StyledMapInterface styledObject) {
- if ( styledObject instanceof StyledGridCoverageInterface )
- return getStyledMapStyle( (StyledGridCoverageInterface)styledObject );
- if ( styledObject instanceof StyledFeatureCollectionInterface )
- return getStyledMapStyle( (StyledFeatureCollectionInterface)styledObject );
- throw new UnsupportedOperationException("Unknown type of StyledMapInterface: "+(styledObject == null ? null : styledObject.getClass().getSimpleName()));
- }
-
- /**
- * Returns the style and raster meta data of a {@link StyledGridCoverageInterface}
- * as a {@link StyledMapStyle}.
- * @param styledGC a styled grid coverage
- */
- public static StyledMapStyle<RasterLegendData> getStyledMapStyle(StyledGridCoverageInterface styledGC) {
- return new StyledMapStyle<RasterLegendData>(
- styledGC.getStyle(),
- styledGC.getLegendMetaData()
- );
- }
-
- /**
- * Returns the style and attribute meta data of a {@link StyledFeatureCollectionInterface}
- * as a {@link StyledMapStyle}.
- * @param styledFC a styled feature collection
- */
- public static StyledMapStyle<Map<Integer,AttributeMetaData>> getStyledMapStyle(StyledFeatureCollectionInterface styledFC) {
- return new StyledMapStyle<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 StyledMapStyle<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 = StyledMapUtil.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 StyledMapStyle<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 StyledMapStyle<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 StyledMapStyle<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 = StyledMapUtil.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 StyledMapStyle<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 StyledMapStyle<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 saveStyledMapStyle(StyledMapStyle<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());
- }
- }
-
- /**
- * 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 saveStyledMapStyle(StyledMapStyle<?> style, URL geoObjectURL) throws Exception {
- if ( style.getMetaData() instanceof RasterLegendData )
- saveStyledMapStyle(style,geoObjectURL, "sld", "rld");
- else
- saveStyledMapStyle(style,geoObjectURL, "sld", "amd");
- }
-
-}
Modified: trunk/src/skrueger/geotools/StyledRasterInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledRasterInterface.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/StyledRasterInterface.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -3,13 +3,13 @@
import skrueger.RasterLegendData;
/**
- * A {@link StyledMapInterface} that is associated to a {@link RasterLegendData}. The datatype is not yet defined.
+ * A {@link StyledLayerInterface} that is associated to a {@link RasterLegendData}. The datatype is not yet defined.
*
* @see StyledGridCoverageInterface
*
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
*/
-public interface StyledRasterInterface<E> extends StyledMapInterface<E> {
+public interface StyledRasterInterface<E> extends StyledLayerInterface<E> {
/**
* @return A {@link RasterLegendData} object with pairs of value / label information
Modified: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -39,7 +39,7 @@
import schmitzm.geotools.styling.StylingUtil;
import schmitzm.lang.LangUtil;
import skrueger.geotools.MapPaneToolBar;
-import skrueger.geotools.StyledMapInterface;
+import skrueger.geotools.StyledLayerInterface;
/**
* This class keeps the selection of a (feature) {@link JTable} synchronized
@@ -68,7 +68,7 @@
* model.
*/
protected final MapLayer mapLayer;
- protected final StyledMapInterface<?> styledMapLayer;
+ protected final StyledLayerInterface<?> styledLayer;
protected final JMapPane mapPane;
private final MapPaneToolBar toolBar;
@@ -84,11 +84,11 @@
*/
public FeatureMapLayerSelectionSynchronizer(
StyledFeatureLayerSelectionModel layerSelModel,
- StyledMapInterface<?> styledMapLayer, MapLayer mapLayer,
+ StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
JMapPane mapPane, MapPaneToolBar toolBar) {
super(layerSelModel);
- this.styledMapLayer = styledMapLayer;
+ this.styledLayer = styledLayer;
this.mapLayer = mapLayer;
this.mapPane = mapPane;
@@ -145,16 +145,16 @@
try {
if (newSelection.isEmpty()) {
- selectionMapStyle = styledMapLayer.getStyle();
+ selectionMapStyle = styledLayer.getStyle();
// LOGGER.debug("NO SELECTION .. set to original style directly");
} else {
LOGGER.debug("SELECTION .. change style");
// We take Style from the MapLayer that is displayed at the
- // moment. We do not use the styledMapLayer.getStyle, because in
+ // moment. We do not use the styledLayer.getStyle, because in
// the atlas, this always return the default style, but
- // additionaly styles might be selected.
+ // additional styles might be selected.
// Taking the style from the mapLayer indicated, that we have to
// remove any selection rules first.
Style originalStyle = mapLayer.getStyle();
@@ -162,9 +162,9 @@
// TODO The default style is not good here. We need
// .createSelectionStyle(normalStyle, geoObj);
selectionMapStyle = StylingUtil
- .createSelectionStyle(styledMapLayer.getGeoObject());
+ .createSelectionStyle(styledLayer.getGeoObject());
// selectionMapStyle = StylingUtil
- // .createDefaultStyle(styledMapLayer.getGeoObject());
+ // .createDefaultStyle(styledLayer.getGeoObject());
selectionMapStyle.getFeatureTypeStyles()[0]
.setName(SELECTION_STYLING);
Modified: trunk/src/skrueger/geotools/selection/StyledFeatureLayerSelectionModel.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledFeatureLayerSelectionModel.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/selection/StyledFeatureLayerSelectionModel.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -18,29 +18,29 @@
import skrueger.geotools.StyledFeatureCollectionInterface;
import skrueger.geotools.StyledFeatureSourceInterface;
-import skrueger.geotools.StyledMapInterface;
+import skrueger.geotools.StyledLayerInterface;
/**
* This manager holds a set of {@link Feature Features} which are <i>selected</i>
- * in a {@link StyledMapInterface} ({@link StyledFeatureCollectionInterface} or
+ * in a {@link StyledLayerInterface} ({@link StyledFeatureCollectionInterface} or
* {@link StyledFeatureSourceInterface}).
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
*/
public class StyledFeatureLayerSelectionModel extends StyledLayerSelectionModel<String> {
/**
* Creates a new selection model.
- * @param styledMap styled map the selection is controlled of
+ * @param styledLayer styled map the selection is controlled of
*/
- public StyledFeatureLayerSelectionModel(StyledFeatureCollectionInterface styledMap) {
- super(styledMap);
+ public StyledFeatureLayerSelectionModel(StyledFeatureCollectionInterface styledLayer) {
+ super(styledLayer);
}
/**
* Creates a new selection model.
- * @param styledMap styled map the selection is controlled of
+ * @param styledLayer styled map the selection is controlled of
*/
- public StyledFeatureLayerSelectionModel(StyledFeatureSourceInterface styledMap) {
- super(styledMap);
+ public StyledFeatureLayerSelectionModel(StyledFeatureSourceInterface styledLayer) {
+ super(styledLayer);
}
Modified: trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java 2009-07-14 15:01:57 UTC (rev 223)
+++ trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java 2009-07-14 15:57:19 UTC (rev 224)
@@ -26,10 +26,10 @@
import org.geotools.feature.Feature;
import schmitzm.swing.event.PropertyChangeEmitter;
-import skrueger.geotools.StyledMapInterface;
+import skrueger.geotools.StyledLayerInterface;
/**
- * This manager holds a set of objects which are <i>selected</i> for a {@link StyledMapInterface}.
+ * This manager holds a set of objects which are <i>selected</i> for a {@link StyledLayerInterface}.
* Several components can connect to this model to keep their selection synchronized.
* @see #addSelectionListener(java.beans.PropertyChangeListener)
* @see StyledLayerSelectionModelSynchronizer
@@ -50,7 +50,7 @@
protected final HashSet<E> selectionObjects;
/** Holds the styled map whose selection is managed by this class. */
- protected final StyledMapInterface<?> styledMap;
+ protected final StyledLayerInterface<?> styledLayer;
/** Indicates whether a selection change is a part of multiple
@@ -61,11 +61,11 @@
/**
* Creates a new selection model.
- * @param styledMap styled map the selection is controlled of
+ * @param styledLayer styled layer the selection is controlled of
*/
- public StyledLayerSelectionModel(StyledMapInterface<?> styledMap) {
+ public StyledLayerSelectionModel(StyledLayerInterface<?> styledLayer) {
this.selectionObjects = new HashSet<E>();
- this.styledMap = styledMap;
+ this.styledLayer = styledLayer;
}
/**
More information about the Schmitzm-commits
mailing list