[Schmitzm-commits] r1424 - in trunk: schmitzm-gt/src/main/java/de/schmitzm/geotools schmitzm-gt/src/main/java/de/schmitzm/geotools/data schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld schmitzm-gt/src/main/java/de/schmitzm/geotools/feature schmitzm-gt/src/main/java/de/schmitzm/geotools/gui schmitzm-gt/src/main/java/de/schmitzm/geotools/selection schmitzm-gt/src/main/java/de/schmitzm/geotools/styling schmitzm-gt/src/test/java/de/schmitzm/geotools/testing schmitzm-jfree-gt/src/main/java/de/schmitzm/jfree/feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 27 12:46:31 CET 2011
Author: mojays
Date: 2011-01-27 12:46:22 +0100 (Thu, 27 Jan 2011)
New Revision: 1424
Added:
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionTableModel.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureSourceInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeaturesInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReaderInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerStyle.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledRasterInterface.java
Removed:
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AbstractStyledLayer.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AttributeMetadataImplMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFS.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollection.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionTableModel.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureSourceInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeaturesInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverage.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReader.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReaderInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerStyle.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerUtil.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledRasterInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AbstractAttributeMetadata.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetaDataAttributeTypeFilter.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataImpl.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/RasterLegendData.java
Modified:
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledFeatureLayerSelectionModel.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledLayerSelectionModel.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java
trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java
trunk/schmitzm-jfree-gt/src/main/java/de/schmitzm/jfree/feature/style/FeatureChartUtil.java
Log:
new packages de.schmitzm.geotools.data.rld and .amd
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AbstractStyledLayer.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AbstractStyledLayer.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AbstractStyledLayer.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,282 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import javax.swing.ImageIcon;
-
-import org.apache.log4j.Logger;
-import org.geotools.styling.Style;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-import de.schmitzm.i8n.Translation;
-import de.schmitzm.lang.LangUtil;
-
-/**
- * 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 layer.
- * @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 layer.
- * @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 layer 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/schmitzm-gt/src/main/java/de/schmitzm/geotools/AttributeMetadataImplMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AttributeMetadataImplMap.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/AttributeMetadataImplMap.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,53 +0,0 @@
-package de.schmitzm.geotools;
-
-import java.util.List;
-
-import org.opengis.feature.type.Name;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-
-public class AttributeMetadataImplMap extends AttributeMetadataMap<AttributeMetadataImpl> {
-
- private static final long serialVersionUID = 6781939984242527498L;
-
-
- public AttributeMetadataImplMap(List<String> langs) {
- super(langs);
- }
-
- public AttributeMetadataImplMap() {
- super();
- }
-
- /**
- * Returns a deep-copy. @see {@link Copyable} interface
- */
- @Override
- public AttributeMetadataImplMap copy() {
- final AttributeMetadataImplMap copy = new AttributeMetadataImplMap(langs);
- return (AttributeMetadataImplMap) copyTo(copy);
- }
-
-
- /**
- * Returns the {@link AttributeMetadataImpl} for a given {@link Name}. Never returns
- * <code>null</code>, but rather creates a default {@link AttributeMetadataImpl} on the
- * fly.
- */
- @Override
- public AttributeMetadataImpl get(final Name name) {
- final AttributeMetadataImpl AttributeMetadataImpl = super.get(name);
- if (AttributeMetadataImpl == null && name != null
- && !name.getLocalPart().trim().isEmpty()) {
-
- put(name, new AttributeMetadataImpl(name, langs));
-
- return super.get(name);
- }
- return AttributeMetadataImpl;
- }
-
-
-}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -34,8 +34,10 @@
import org.geotools.map.MapLayer;
import org.geotools.map.event.MapLayerListListener;
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.RasterLegendData;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.styling.StyledFeatureCollectionInterface;
+import de.schmitzm.geotools.styling.StyledLayerInterface;
/**
* Implementations of this class can can be used to fill/insert/remove a mapContext
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFS.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFS.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFS.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,431 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Date;
-import java.util.Random;
-
-import javax.swing.ImageIcon;
-import javax.swing.JPanel;
-
-import org.apache.log4j.Logger;
-import org.geotools.data.FeatureSource;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.styling.Style;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.filter.Filter;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-import de.schmitzm.geotools.feature.FeatureUtil;
-import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-import de.schmitzm.geotools.io.GeoImportUtil;
-import de.schmitzm.geotools.styling.StylingUtil;
-import de.schmitzm.i8n.Translation;
-
-/**
- * This class enables a non Atlas context to use the Atlas LayerPanel
- * {@link JPanel} as a {@link MapContextManagerInterface}
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- *
- * TODO Rename to StyledShapefile
- */
-public class StyledFS implements StyledFeatureSourceInterface {
- private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
-
- private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
-
- /** Caching the CRS of the layer **/
- CoordinateReferenceSystem crs = null;
-
- /**
- * A unique ID which identifies the Layer in the Atlas. It's more important
- * than it should be ;-)
- */
- final private String id;
-
- private Style style;
-
- private Translation title;
-
- private Translation desc;
-
- private File sldFile;
-
- /** A map of simple attribute names to their meta-data **/
- private AttributeMetadataMap<AttributeMetadataImpl> attMap;
-
- private Filter filter = Filter.INCLUDE;
-
- /**
- * This class enables a non Atlas context to use the Atlas LayerPanel
- * {@link JPanel} as a {@link MapContextManagerInterface}
- *
- * @param fs
- * {@link FeatureSource} that is beeing styled.
- *
- * @param sldFile
- * may be <code>null</code>. Otherwise the SLD {@link File} to
- * import and associate with this {@link StyledFS}
- *
- * @param id
- * <code>null</code> is allowed and will autogenerate an id
- */
- public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
- File sldFile, String id) {
-
- this.fs = fs;
-
- if (id == null) {
- this.id = StyledFS.class.getSimpleName()
- + new Random(new Date().getTime()).nextInt(10000000);
- } else {
- this.id = id;
- }
-
- this.sldFile = sldFile;
-
- // datei existiert, dann lesen
- if (sldFile != null && sldFile.exists()) {
- try {
- style = StylingUtil.loadSLD(sldFile)[0];
- } catch (Exception e) {
- LOGGER.warn("Reading SLD failed: " + sldFile, e);
- style = null;
- }
- }
-
- title = new Translation();
- desc = new Translation();
-
- if (sldFile != null) {
- title.fromOneLine(sldFile.getName());
- desc.fromOneLine(sldFile.getAbsolutePath());
- }
-
- }
-
- public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
- this(fs, (File) null, null);
- }
-
- public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
- String id) {
- this(fs, null, id);
- }
-
- public void dispose() {
- }
-
- /**
- * Returns human readable {@link String} of the CRS natively used by this
- * {@link DpLayer}
- *
- * If CRS == null, it will call {@link #getGeoObject()}
- *
- */
- public String getCRSString() {
- if (getCrs() == null)
- return "CRS?";
-
- return getCrs().getName().getCode();
- }
-
- public CoordinateReferenceSystem getCrs() {
- if (crs == null) {
- crs = fs.getSchema().getCoordinateReferenceSystem();
- if (crs == null) {
-
- crs = fs.getSchema().getGeometryDescriptor()
- .getCoordinateReferenceSystem();
-
- if (crs == null) {
- LOGGER.warn("Could not determine the CRS of " + getTitle()
- + ". Using default "
- + GeoImportUtil.getDefaultCRS());
- crs = GeoImportUtil.getDefaultCRS();
- }
- }
- }
- return crs;
- }
-
- public Translation getDesc() {
- return desc;
- }
-
- public Envelope getEnvelope() {
- try {
- return fs.getBounds();
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public FeatureSource<SimpleFeatureType, SimpleFeature> getGeoObject() {
- return fs;
- }
-
- public String getId() {
- return id;
- }
-
- public ImageIcon getImageIcon() {
- return null;
- }
-
- public URL getInfoURL() {
- return null;
- }
-
- public Translation getKeywords() {
- return null;
- }
-
- public Style getStyle() {
- return style;
- }
-
- public Translation getTitle() {
- return title;
- }
-
- public boolean isDisposed() {
- return false;
- }
-
- /**
- * If true, this layer will not be shown in the legend. Default = false
- */
- /**
- *
- * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
- * verstecken/nicht verstecken gestellt werden können. Das sind
- * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
- * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
- * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
- * die Funktion genutzt.
- *
- * // public boolean isHideInLegend() { // return false; // }
- */
-
- public void setDesc(Translation dec) {
- this.desc = dec;
- }
-
- public void setImageIcon(ImageIcon icon) {
- }
-
- public void setKeywords(Translation keywords) {
- }
-
- public void setStyle(Style style) {
- this.style = style;
-
- }
-
- public void setTitle(Translation title) {
- this.title = title;
-
- }
-
- public void uncache() {
- }
-
- /**
- *
- */
- @Override
- public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() {
- if (attMap == null) {
- attMap = StyledLayerUtil
- .createDefaultAttributeMetadataMap(getSchema());
- }
- return attMap;
- }
-
- /**
- * @return The {@link File} where the SLD was loaded from or
- * <code>null</code> if there didn't exist a {@link File}.
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
- public File getSldFile() {
- return sldFile;
- }
-
- /**
- * Associates this .sld with the {@link FeatureSource}, but does not
- * automatically load the file. It must not even exist.
- *
- * @param sldFile
- */
- public void setSldFile(File sldFile) {
- this.sldFile = sldFile;
- }
-
- /**
- * Returns the features of the {@link FeatureSource}.
- *
- * @see {@link StyledFeaturesInterface}
- */
- @Override
- public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
- FeatureCollection<SimpleFeatureType, SimpleFeature> features;
- try {
- features = getGeoObject().getFeatures();
- } catch (IOException e) {
- throw new RuntimeException(
- "Error getting the features of the FeatureSource");
- }
- return features;
- }
-
- /**
- * Same as {@link #getGeoObject()} method, but complies to the
- * {@link StyledFeaturesInterface}
- *
- * @see {@link StyledFeaturesInterface}
- */
- @Override
- public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
- return getGeoObject();
- }
-
- @Override
- public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
- // final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
- // getFeatureCollection();
- // if (filter == Filter.EXCLUDE)
- // return new EmptyFeatureCollection(fc.getSchema());
- // if (filter == Filter.INCLUDE)
- // return fc;
- // return fc.subCollection(filter);
-
- try {
- if (filter != Filter.INCLUDE)
- return getFeatureSource().getFeatures(filter);
- else
- return getFeatureSource().getFeatures();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public Filter getFilter() {
- return filter;
- }
-
- @Override
- public void setFilter(Filter filter) {
- this.filter = filter;
- }
-
- @Override
- public SimpleFeatureType getSchema() {
- return getGeoObject().getSchema();
- }
-
- /**
- * Tries to load a style from the file denoted in {@link #getSldFile()}. If
- * the file doesn't exits, return <code>null</code>;
- *
- * @return <code>true</code> is style was loaded
- */
- public boolean loadStyle() {
- if (getSldFile() == null)
- return false;
-
- try {
- Style[] loadSLD = StylingUtil.loadSLD(getSldFile());
- setStyle(loadSLD[0]);
- return true;
- } catch (Exception e) {
- return false;
- }
-
- }
-
- public void setTitle(String title) {
- setTitle(new Translation(title));
- }
-
- public void setDesc(String desc) {
- setDesc(new Translation(desc));
- }
-
- public void setCRS(CoordinateReferenceSystem crs2) {
- crs = crs2;
- }
-
- @Override
- public ReferencedEnvelope getReferencedEnvelope() {
- return new ReferencedEnvelope(getEnvelope(), getCrs());
- }
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
- private GeometryForm geometryForm;
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
-
- @Override
- public GeometryForm getGeometryForm() {
- if (geometryForm == null) {
- geometryForm = FeatureUtil.getGeometryForm(getSchema());
- }
- return geometryForm;
- }
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
- public void setGeometryForm(GeometryForm geometryForm) {
- this.geometryForm = geometryForm;
- }
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollection.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollection.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollection.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,476 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.io.IOException;
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-
-import org.geotools.data.FeatureSource;
-import org.geotools.data.collection.CollectionDataStore;
-import org.geotools.data.store.EmptyFeatureCollection;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.feature.NameImpl;
-import org.geotools.feature.collection.SubFeatureCollection;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.styling.Style;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.filter.Filter;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-import de.schmitzm.geotools.feature.FeatureUtil;
-import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-import de.schmitzm.i8n.Translation;
-
-/**
- * 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.
- *
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
- * (University of Bonn/Germany)
- * @version 1.0
- */
-public class StyledFeatureCollection
- extends
- AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>>
- implements StyledFeatureCollectionInterface {
-
- /** Holds the meta data for displaying a legend. */
- protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaData = null;
-
- /**
- * We be filled with a "virtual" {@link FeatureSource} on demand.
- */
- private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
-
- /**
- * A Filter that will be applied internally applied to this
- * FeatureCollection
- **/
- private Filter filter = Filter.INCLUDE;
-
- /**
- * Creates a styled {@link FeatureCollection} with language-specific
- * informations.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the 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 (if {@code null}, a default style is created)
- * @param attrMetaData
- * meta data for displaying a legend
- * @param icon
- * an icon for the object (can be {@code null})
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- Translation title, Translation desc, Translation keywords,
- Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) {
- super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
- .getCoordinateReferenceSystem(), id, title, desc, keywords,
- style, icon);
- setAttributeMetaData(attrMetaData);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with language-specific
- * informations.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the 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 with attribute meta data information
- * @param icon
- * an icon for the object (can be {@code null})
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- Translation title, Translation desc, Translation keywords,
- StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
- super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
- .getCoordinateReferenceSystem(), id, title, desc, keywords,
- style != null ? style.getGeoObjectStyle() : null, icon);
- setAttributeMetaData(style != null ? style.getMetaData() : null);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with a language-specific
- * title, no long description, no keywords, default attribute meta data and
- * no icon.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- Translation title, Style style) {
- this(fc, id, title, null, null, style, null, null);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with non-translated
- * informations.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @param attrMetaData
- * meta data for displaying a legend
- * @param icon
- * an icon for the object (can be {@code null})
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- String title, String desc, String keywords, Style style,
- AttributeMetadataMap attrMetaData, ImageIcon icon) {
- this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
- setTitle(title);
- setDesc(desc);
- setKeywords(keywords);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with non-translated
- * informations.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style with attribute meta data information
- * @param icon
- * an icon for the object (can be {@code null})
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- String title, String desc, String keywords,
- StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
- this(fc, id, title, desc, keywords, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, icon);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with a non-translated title,
- * no long description, no keywords, default attribute meta data and no
- * icon.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- String title, Style style) {
- this(fc, id, title, null, null, style, null, null);
- }
-
- /**
- * Creates a styled {@link FeatureCollection} with a non-translated title,
- * no long description, no keywords, default attribute meta data and no
- * icon.
- *
- * @param fc
- * the {@link FeatureCollection}
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
- */
- public StyledFeatureCollection(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
- String title, StyledLayerStyle<AttributeMetadataMap> style) {
- this(fc, id, title, null, null, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, null);
- }
-
- /**
- * Creates a default style for the {@link FeatureCollection}.
- *
- * @see FeatureUtil#createDefaultStyle(FeatureCollection)
- */
- protected Style createDefaultStyle() {
- return FeatureUtil.createDefaultStyle(geoObject);
- }
-
- /**
- * Returns the meta data needed for displaying a legend.
- */
- public AttributeMetadataMap getAttributeMetaDataMap() {
- return attrMetaData;
- }
-
- /**
- * Sets the meta data needed for displaying a legend. If {@code legendData}
- * is {@code null} an empty map is set, so
- * {@link #getAttributeMetaDataMap()} never returns {@code null}.
- *
- * @param attrMetaData
- * map of attribute meta data
- */
- public void setAttributeMetaData(AttributeMetadataMap attrMetaData) {
- this.attrMetaData = (attrMetaData != null) ? attrMetaData
- : createDefaultAttributeMetaDataMap(geoObject);
- }
-
- /**
- * Creates non-translated default meta data for a {@link FeatureCollection}
- * with all attributes visible and no unit set.
- *
- * @param fc
- * a {@link FeatureCollection}
- */
- public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
- AttributeMetadataMap metaDataMap = new AttributeMetadataImplMap();
- SimpleFeatureType ftype = fc.getSchema();
- for (int i = 0; i < ftype.getAttributeCount(); i++) {
- AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
- if (!FeatureUtil.isGeometryAttribute(aDesc))
- metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl(
- new NameImpl(aDesc.getName().getNamespaceURI(), aDesc
- .getName().getLocalPart()), true, // visible
- new Translation(aDesc.getLocalName()), // Column name
- new Translation(aDesc.getLocalName()), // description
- "" // Unit
- ));
- }
- return metaDataMap;
- }
-
- /**
- * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
- * {@link #attrMetaData} to {@code null}.
- */
- public void dispose() {
- this.geoObject = null;
- this.envelope = null;
- this.crs = null;
- this.attrMetaData = null;
- }
-
- /**
- * Tests whether the geo object is disposed.
- */
- public boolean isDisposed() {
- return geoObject == null;
- }
-
- /**
- * Does nothing, because the {@link AbstractStyledLayer} bases on existing
- * objects (in memory) which can not be uncached and reloaded.
- */
- public void uncache() {
-
- /** It will be recreated on the next getFetureSource() **/
- featureSource = null;
-
- LOGGER.warn("Uncache onyl uncached any virtual FeatureSource. Object remains in memory.");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
- */
- public URL getInfoURL() {
- return null;
- }
-
- /**
- * Same as {@link #getGeoObject()} method, but complies to the
- * {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT
- * automatically applied.
- *
- * @see {@link StyledFeaturesInterface}
- * @see #getFeatureCollectionFiltered()
- */
- @Override
- public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
- return getGeoObject();
- }
-
- /**
- * Same as {@link #getGeoObject()} method, but complies to the
- * {@link StyledFeaturesInterface}. The associated {@link Filter} is
- * automatically applied by creating a {@link SubFeatureCollection}.
- *
- * @see {@link StyledFeaturesInterface}
- * @see #getFeatureCollectionFiltered()
- */
- @Override
- public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
- final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
- if (filter == Filter.EXCLUDE)
- return new EmptyFeatureCollection(fc.getSchema());
- if (filter == Filter.INCLUDE)
- return fc;
- return fc.subCollection(filter);
- }
-
- /**
- * Returns a virtual {@link FeatureSource} to access the
- * {@link FeatureCollection}. Once created, it will be reused until
- * {@link #uncache()} is called.<br/>
- *
- * @see {@link StyledFeaturesInterface}
- */
- @Override
- public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
- if (featureSource == null) {
- CollectionDataStore store = new CollectionDataStore(getGeoObject());
- try {
- featureSource = store.getFeatureSource(store.getTypeNames()[0]);
- } catch (IOException e) {
- throw new RuntimeException(
- "Could not create a FeatureSource from the CollectionDataStore:",
- e);
- }
- }
- return featureSource;
- }
-
- @Override
- public Filter getFilter() {
- return filter;
- }
-
- @Override
- public void setFilter(Filter filter) {
- this.filter = filter;
- }
-
- @Override
- public SimpleFeatureType getSchema() {
- return getGeoObject().getSchema();
- }
-
- @Override
- public ReferencedEnvelope getReferencedEnvelope() {
- return new ReferencedEnvelope(getEnvelope(), getCrs());
- }
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
- private GeometryForm geometryForm;
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
-
- @Override
- public GeometryForm getGeometryForm() {
- if (geometryForm == null) {
- geometryForm = FeatureUtil.getGeometryForm(getSchema());
- }
- return geometryForm;
- }
-
- /**
- * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
- * but can be set to override ANY.
- */
- public void setGeometryForm(GeometryForm geometryForm) {
- this.geometryForm = geometryForm;
- }
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import org.geotools.feature.FeatureCollection;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-/**
- * {@link StyledLayerInterface} which contains a {@link FeatureCollection} as geo object.<br>
- */
-public interface StyledFeatureCollectionInterface extends StyledFeaturesInterface<FeatureCollection<SimpleFeatureType, SimpleFeature>> {
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionTableModel.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureCollectionTableModel.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,286 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.geotools.data.DefaultQuery;
-import org.geotools.data.FeatureSource;
-import org.geotools.data.Query;
-import org.geotools.feature.FeatureCollection;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.Name;
-import org.opengis.filter.Filter;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataInterface;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-import de.schmitzm.geotools.feature.FeatureUtil;
-import de.schmitzm.geotools.gui.FeatureCollectionTableModel;
-
-/**
- * This class extends the the {@link FeatureCollectionTableModel} with the
- * functionalities of the {@link AttributeMetadataImpl}.
- * <ul>
- * <li>column names are translated according to
- * {@link AttributeMetadataImpl#getTitle()}</li>
- * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
- * <li>Any filter defined in the {@link StyledFeaturesInterface} will be
- * applied.</li>
- * </ul>
- *
- * @author Stefan A. Tzeggai
- */
-public class StyledFeatureCollectionTableModel extends
- FeatureCollectionTableModel {
- final static private Logger LOGGER = Logger
- .getLogger(StyledFeatureCollectionTableModel.class);
- /**
- * Contains the complete {@link AttributeMetadataImpl}-Map of the styled
- * layer.
- */
- protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null;
- /** Holds the current filter on the table */
- protected Filter filter = null;
- /** Holds the Bounds for all features. Only set once during the constructor **/
- protected Envelope bounds;
- /**
- * Tooltips für die Spaltennamen. Wird nur beim Aufruf von
- * {@link #reorganize} befuellt.
- */
- protected String[] colTooltips = null;
-
- /**
- * A cache for the #sortedValuesVisibleOnly(). WHen the amd is changed
- * externally, this object will stay the same
- **/
- protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null;
-
- /**
- * Creates a new table model for a styled layer.
- *
- * @param styledFeatures
- * the styled layer
- * @param filter
- * filter applied to the table
- */
- public StyledFeatureCollectionTableModel(
- StyledFeaturesInterface<?> styledFeatures) {
- setStyledFeatures(styledFeatures);
- }
-
- /**
- * This overwritten method filters the values for NODATA-values defined in
- * the {@link AttributeMetadataImpl}
- */
- @Override
- public Object getValueAt(int row, int col) {
- Object rawValue = super.getValueAt(row, col);
- return amdMapVisibleOnly.get(col).fiterNodata(rawValue);
- }
-
- /**
- * Sets a new data source for the table.
- *
- * @param fs
- * the feature source
- * @param amdm
- * {@link AttributeMetadataImpl}-Map to define the visible
- * attributes and translation
- */
- protected void setFeatureSource(
- FeatureSource<SimpleFeatureType, SimpleFeature> fs,
- AttributeMetadataMap<? extends AttributeMetadataInterface> amdm,
- Filter filter) throws Exception {
-
- if (filter == null)
- filter = Filter.INCLUDE;
-
- // this.featureSource = fs;
- this.filter = filter;
- this.amdMap = amdm;
- this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
-
- FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
- if (fs != null) {
-
- bounds = fs.getBounds();
-
- final SimpleFeatureType schema = fs.getSchema();
- Query query = new DefaultQuery(schema.getTypeName(), filter);
- if (amdm != null) {
- LinkedHashSet<String> visibleAttrNames = new LinkedHashSet<String>();
-
- // Add the column with the geometry (usually "the_geom") always
- visibleAttrNames.add(schema.getGeometryDescriptor()
- .getLocalName());
-
- // Add other visible attributes as ordered by weights
- for (AttributeMetadataInterface a : amdMapVisibleOnly) {
- visibleAttrNames.add(a.getLocalName());
- }
-
- // Tested with 2.6.x trunk from 2009-11-26 and it now works. So
- // we only request the properties we need!
- // /**
- // * I got NPEs when properties contained only [the_geom]
- // ?!??!!??
- // */
- // if (properties.length > 1) {
- query = new DefaultQuery(schema.getTypeName(), filter,
- visibleAttrNames.toArray(new String[] {}));
- // } else {
- // query = new DefaultQuery(schema.getTypeName(), filter);
- // }
- }
- fc = fs.getFeatures(query);
- }
- setFeatureCollection(fc);
- }
-
- /**
- * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
- * and sets this as the new data source for the table.
- *
- * @param fs
- * the feature source
- * @param amd
- * {@link AttributeMetadataImpl}-Map to define the visible
- * attributes and translation
- */
- public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
- try {
- if (styledFeatures == null)
- setFeatureSource(null, null, null);
- else {
- setFeatureSource(styledFeatures.getFeatureSource(),
- styledFeatures.getAttributeMetaDataMap(),
- styledFeatures.getFilter());
- }
- } catch (Exception err) {
- throw new RuntimeException(err);
- }
- }
-
- /**
- * After calling {@code super.reorganize(.)} this method replaced the column
- * descriptions with the titles of the {@code AttributeMetaData}.
- *
- * @param fireTableStructureChanged
- * indicates whether a table event is initiated after reorganize
- */
- @Override
- protected void reorganize(boolean fireTableStructureChanged) {
-
- featureArray = FeatureUtil.featuresToArray(featureTable);
- if (featureArray == null || featureArray.length == 0) {
- colNames = new String[0];
- colTooltips = new String[0]; // Only set and used in
- // StyledFeatureCollectionTableModel
- colClass = new Class[0];
- } else {
- // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
- SimpleFeatureType schema = featureArray[0].getFeatureType();
- // Pruefen, welche Attribute angezeigt werden
- attrTypes.clear();
- for (AttributeMetadataInterface amd : amdMapVisibleOnly) {
- Name name = amd.getName();
- AttributeDescriptor type = schema.getDescriptor(name);
- // if type can not be determined by complete name,
- // try only the local name
- if (type == null)
- type = schema.getDescriptor(name.getLocalPart());
- if (attrFilter == null || attrFilter.accept(type))
- attrTypes.add(type);
- }
- // Namen und Attribut-Indizes der angezeigten Spalten ermitteln
- colNames = new String[attrTypes.size()];
- colTooltips = new String[attrTypes.size()]; // Only set and used in
- // StyledFeatureCollectionTableModel
- colClass = new Class[attrTypes.size()];
- attrIdxForCol = new int[attrTypes.size()];
- for (int i = 0; i < colNames.length; i++) {
- Name name = amdMapVisibleOnly.get(i).getName();
- AttributeDescriptor descriptor = schema.getDescriptor(name);
- // if type can not be determined by complete name,
- // try only the local name
- if (descriptor == null)
- descriptor = schema.getDescriptor(name.getLocalPart());
-
- // Not so nice in 26: find the index of an attribute...
- int idx = schema.getAttributeDescriptors().indexOf(descriptor);
- attrIdxForCol[i] = idx;
-
- String attName = schema.getAttributeDescriptors().get(idx)
- .getLocalName();
- colNames[i] = amdMap.get(attName).getTitle().toString();
- AttributeMetadataInterface amd = amdMap.get(attName);
- colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
- + amd.getName() + "</html>";
- colClass[i] = schema.getAttributeDescriptors().get(idx)
- .getType().getBinding();
- }
- }
-
- // store feature indexes in HashMap to optimize findFeature(.)
- featureIdx = new HashMap<String, Integer>();
- for (int i = 0; i < featureArray.length; i++)
- if (featureArray[i] != null)
- featureIdx.put(featureArray[i].getID(), i);
- //
- // // translate the column names
- // if (amdMap != null) {
- // for (int i = 0; i < colNames.length; i++) {
- // colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
- // + "<br>" + colNames[i];
- // colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
- //
- // }
- // }
- if (fireTableStructureChanged)
- fireTableStructureChanged();
-
- }
-
- /**
- * @return Cached bounds for the whole dataset (without applying the filter)
- * or <code>null</code>
- */
- public Envelope getBounds() {
- return bounds;
- }
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureSourceInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureSourceInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeatureSourceInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import org.geotools.data.FeatureSource;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-/**
- * {@link StyledLayerInterface} which contains a {@link FeatureSource} as geo object.<br>
- */
-public interface StyledFeatureSourceInterface extends StyledFeaturesInterface<FeatureSource<SimpleFeatureType, SimpleFeature>> {
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeaturesInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeaturesInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledFeaturesInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,109 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import org.geotools.data.FeatureSource;
-import org.geotools.feature.FeatureCollection;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.filter.Filter;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-
-/**
- * This Interface combines all styled layers that are running on
- * {@link FeatureCollection} or {@link FeatureSource}
- *
- * @author Stefan A. Tzeggai
- *
- * @param <T>
- * The base Type returned in the getObject() method.
- */
-public interface StyledFeaturesInterface<T> extends StyledLayerInterface<T> {
-
- public abstract AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap();
-
- /**
- * @return The features of this layer as a {@link FeatureSource}. The filter
- * is NOT automatically applied.
- */
- public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource();
-
- /**
- * @return The features of this layer as a {@link FeatureCollection}. The
- * filter is NOT automatically applied.
- */
- public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection();
-
- /**
- * @return The features of this layer as a {@link FeatureCollection}. The
- * associated Filter is automatically applied.
- */
- public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered();
-
- /**
- * Stores Filter that is NOT automatically applied. <code>null</code> is not
- * allowed, use Filter.INCLUDE.
- */
- public void setFilter(Filter filter);
-
- /**
- * Returns the Filter a filter that is associated with this
- * {@link StyledFeaturesInterface} Never shall return <code>null</code>, but
- * rather Filter.INCLUDE.
- */
- public Filter getFilter();
-
- /**
- * Returns the underlying GeoTools Object. The filter is NOT applied.
- *
- * @throws RuntimeException
- *
- * @deprected Please use {@link #getFeatureSource()} or
- * {@link #getFeatureCollection()} so you save a cast
- */
- public T getGeoObject();
-
- /**
- * @return As the fastest way to get the Schema is depending on the
- * underlying geoObject (FeatureSource or FeatureCollection), this
- * method shall be implemented in the classes.
- */
- public abstract SimpleFeatureType getSchema();
-
- /**
- * @return can returns {@link GeometryForm#ANY} if the source is e.g. a GML
- * mixed geometry collection.
- */
- public abstract GeometryForm getGeometryForm();
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverage.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverage.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverage.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,328 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-
-import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.styling.Style;
-
-import de.schmitzm.geotools.data.RasterLegendData;
-import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
-
-/**
- * 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 AbstractStyledLayer<GridCoverage2D>
- implements StyledGridCoverageInterface {
-
- /** Holds the meta data for displaying a legend. */
- protected RasterLegendData legendData = null;
-
- /**
- * Creates a styled grid with language-specific informations.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the 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 (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @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, Style style,
- RasterLegendData legendData, ImageIcon icon) {
- super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
- .getCoordinateReferenceSystem(), id, title, desc, keywords,
- style, icon);
- setLegendMetaData(legendData);
- }
-
- /**
- * Creates a styled grid with language-specific informations.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the 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 with legend information
- * @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,
- 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);
- }
-
- /**
- * Creates a styled grid with a language-specific title, no long
- * description, no keywords and no icon.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
- Style style, RasterLegendData legendData) {
- this(gc, id, title, null, null, style, legendData, null);
- }
-
- /**
- * Creates a styled grid with non-translated informations.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @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, Style style,
- RasterLegendData legendData, ImageIcon icon) {
- this(gc, id, (Translation) null, null, null, style, legendData, icon);
- setTitle(title);
- setDesc(desc);
- setKeywords(keywords);
- }
-
- /**
- * Creates a styled grid with non-translated informations.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style with legend information
- * @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,
- StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
- this(gc, id, title, desc, keywords, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, icon);
- }
-
- /**
- * Creates a styled grid with a non-translated title, no long description,
- * no keywords and no icon.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledGridCoverage(GridCoverage2D gc, String id, String title,
- Style style, RasterLegendData legendData) {
- this(gc, id, title, null, null, style, legendData, null);
- }
-
- /**
- * Creates a styled grid with a non-translated title, no long description,
- * no keywords and no icon.
- *
- * @param gc
- * the grid
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @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,
- StyledLayerStyle<RasterLegendData> style) {
- this(gc, id, title, null, null, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, null);
- }
-
- /**
- * Creates a default style for a {@link GridCoverage2D}.
- *
- * @see GridUtil#createDefaultStyle()
- */
- protected Style createDefaultStyle() {
- return GridUtil.createDefaultStyle();
- }
-
- /**
- * Returns the meta data needed for displaying a legend.
- */
- public RasterLegendData getLegendMetaData() {
- return legendData;
- }
-
- /**
- * Sets the meta data needed for displaying a legend. If {@code legendData}
- * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
- * so {@link #getLegendMetaData()} never returns {@code null}.
- *
- * @param legendData
- * legend meta data
- */
- public void setLegendMetaData(RasterLegendData legendData) {
- this.legendData = (legendData != null) ? legendData
- : new RasterLegendData(false);
- }
-
- /**
- * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
- * {@link #legendData} to {@code null}.
- */
- public void dispose() {
- this.geoObject = null;
- this.envelope = null;
- this.crs = null;
- this.legendData = null;
- }
-
- /**
- * Tests whether the geo object is disposed.
- *
- * @return boolean
- */
- public boolean isDisposed() {
- return geoObject == null;
- }
-
- /**
- * Does nothing, because the {@link AbstractStyledLayer} bases on existing
- * objects (in memory) which can not be uncached and reloaded.
- */
- public void uncache() {
- LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
- */
- public URL getInfoURL() {
- return null;
- }
-
- /**
- * If true, this layer will not be shown in the legend. Default = false
- */
- /**
- *
- * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
- * verstecken/nicht verstecken gestellt werden können. Das sind
- * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
- * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
- * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
- * die Funktion genutzt.
- *
- * public boolean isHideInLegend() { return false; }
- */
- @Override
- public ReferencedEnvelope getReferencedEnvelope() {
- return new ReferencedEnvelope(getEnvelope(), getCrs());
- }
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-import org.geotools.coverage.grid.GridCoverage2D;
-
-/**
- * A {@link StyledRasterInterface} that is typed to wrap a {@link GridCoverage2D}
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
-public interface StyledGridCoverageInterface extends StyledRasterInterface<GridCoverage2D>{
-};
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReader.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReader.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReader.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,336 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-
-import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.styling.Style;
-
-import de.schmitzm.geotools.data.RasterLegendData;
-import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
-
-/**
- * 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
- AbstractStyledLayer<AbstractGridCoverage2DReader> implements
- StyledGridCoverageReaderInterface {
- @Override
- public ReferencedEnvelope getReferencedEnvelope() {
- return new ReferencedEnvelope(getEnvelope(), getCrs());
- }
-
- /** Holds the meta data for displaying a legend. */
- protected RasterLegendData legendData = null;
-
- /**
- * Creates a styled grid with language-specific informations.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the 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 (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @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, Style style, RasterLegendData legendData,
- ImageIcon icon) {
- super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
- .getCrs(), id, title, desc, keywords, style, icon);
- setLegendMetaData(legendData);
- }
-
- /**
- * Creates a styled grid with language-specific informations.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the 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 with legend information
- * @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, 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);
- }
-
- /**
- * Creates a styled grid with a language-specific title, no long
- * description, no keywords and no icon.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
- String id, Translation title, Style style,
- RasterLegendData legendData) {
- this(gcr, id, title, null, null, style, legendData, null);
- }
-
- /**
- * Creates a styled grid with non-translated informations.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @param legendData
- * meta data for displaying a legend
- * @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, Style style,
- RasterLegendData legendData, ImageIcon icon) {
- this(gcr, id, (Translation) null, null, null, style, legendData, icon);
- setTitle(title);
- setDesc(desc);
- setKeywords(keywords);
- }
-
- /**
- * Creates a styled grid with non-translated informations.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param desc
- * a long description
- * @param keywords
- * keywords for the geo objects
- * @param style
- * a display style with legend information
- * @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,
- StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
- this(gcr, id, title, desc, keywords, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, icon);
- }
-
- /**
- * Creates a styled grid with a non-translated title, no long description,
- * no keywords and no icon.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @param style
- * a display style (if {@code null}, a default style is created)
- * @exception IllegalArgumentException
- * if {@code null} is given as ID or geo object
- */
- public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
- String id, String title, Style style, RasterLegendData legendData) {
- this(gcr, id, title, null, null, style, legendData, null);
- }
-
- /**
- * Creates a styled grid with a non-translated title, no long description,
- * no keywords and no icon.
- *
- * @param gcr
- * the grid reader
- * @param id
- * a unique ID for the object
- * @param title
- * a short description
- * @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, StyledLayerStyle<RasterLegendData> style) {
- this(gcr, id, title, null, null, style != null ? style
- .getGeoObjectStyle() : null, style != null ? style
- .getMetaData() : null, null);
- }
-
- public StyledGridCoverageReader(AbstractGridCoverage2DReader reader) {
- this(reader, "", "", null, null);
- }
-
- /**
- * Creates a default style for a {@link GridCoverage2D}.
- *
- * @see GridUtil#createDefaultStyle()
- */
- protected Style createDefaultStyle() {
- return GridUtil.createDefaultStyle();
- }
-
- /**
- * Returns the meta data needed for displaying a legend.
- */
- public RasterLegendData getLegendMetaData() {
- return legendData;
- }
-
- /**
- * Sets the meta data needed for displaying a legend. If {@code legendData}
- * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
- * so {@link #getLegendMetaData()} never returns {@code null}.
- *
- * @param legendData
- * legend meta data
- */
- public void setLegendMetaData(RasterLegendData legendData) {
- this.legendData = (legendData != null) ? legendData
- : new RasterLegendData(false);
- }
-
- /**
- * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
- * {@link #legendData} to {@code null}.
- */
- public void dispose() {
- this.geoObject = null;
- this.envelope = null;
- this.crs = null;
- this.legendData = null;
- }
-
- /**
- * Tests whether the geo object is disposed.
- *
- * @return boolean
- */
- public boolean isDisposed() {
- return geoObject == null;
- }
-
- /**
- * Does nothing, because the {@link AbstractStyledLayer} bases on existing
- * objects (in memory) which can not be uncached and reloaded.
- */
- public void uncache() {
- LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
- */
- public URL getInfoURL() {
- return null;
- }
-
- /**
- * If true, this layer will not be shown in the legend. Default = false
- */
- /**
- *
- * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
- * verstecken/nicht verstecken gestellt werden können. Das sind
- * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
- * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
- * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
- * die Funktion genutzt.
- *
- * public boolean isHideInLegend() { return false; }
- */
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReaderInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReaderInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledGridCoverageReaderInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
-
-/**
- * A {@link StyledRasterInterface} that is typed to wrap a {@link AbstractGridCoverage2DReader}
- *
- * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
- */
-public interface StyledGridCoverageReaderInterface extends StyledRasterInterface<AbstractGridCoverage2DReader>{
-};
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-
-import org.geotools.feature.FeatureCollection;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.styling.Style;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Envelope;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataInterface;
-import de.schmitzm.geotools.data.RasterLegendData;
-import de.schmitzm.i8n.Translation;
-
-/**
- * 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 AttributeMetadataInterface}-Map must not return {@code
- * null}</li>
- * <li>static helper method to get a new {@link AttributeMetadataImpl}-map with the
- * visible attributes only</li>
- * <li>static helper method to create a "default" {@link AttributeMetadataImpl}-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 <code>null</code> is no CRS is available
- */
- public ReferencedEnvelope getReferencedEnvelope();
-
-
- /**
- * @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();
-// public String getLegendHtml();
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerStyle.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerStyle.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerStyle.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.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;
- }
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledLayerUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,1410 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.IndexColorModel;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.net.URL;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.BorderFactory;
-import javax.swing.ImageIcon;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-
-import net.miginfocom.swing.MigLayout;
-
-import org.apache.log4j.Logger;
-import org.geotools.coverage.grid.GeneralGridEnvelope;
-import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.coverage.grid.GridGeometry2D;
-import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
-import org.geotools.coverage.grid.io.AbstractGridFormat;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.feature.NameImpl;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.map.DefaultMapLayer;
-import org.geotools.map.MapLayer;
-import org.geotools.parameter.Parameter;
-import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
-import org.geotools.styling.ColorMap;
-import org.geotools.styling.ColorMapEntry;
-import org.geotools.styling.FeatureTypeStyle;
-import org.geotools.styling.RasterSymbolizer;
-import org.geotools.styling.Rule;
-import org.geotools.styling.Style;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.XMLOutputter;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.GeometryDescriptor;
-import org.opengis.feature.type.Name;
-import org.opengis.filter.FilterFactory2;
-import org.opengis.parameter.GeneralParameterValue;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataInterface;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
-import de.schmitzm.geotools.data.RasterLegendData;
-import de.schmitzm.geotools.feature.FeatureUtil;
-import de.schmitzm.geotools.styling.StylingUtil;
-import de.schmitzm.i8n.Translation;
-import de.schmitzm.io.IOUtil;
-import de.schmitzm.lang.LangUtil;
-import de.schmitzm.swing.ExceptionDialog;
-import de.schmitzm.swing.JPanel;
-import de.schmitzm.swing.SwingUtil;
-
-/**
- * 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();
-
- /**
- * Is appended to the name of a rule, this rule shall not be shown in the
- * legend
- */
- public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
-
- /** 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";
- private static FilterFactory2 ff = FilterUtil.FILTER_FAC2;
-
- /**
- * 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(final 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, final 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(
- final Object object, final 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(
- final Object object, final String title,
- final StyledLayerStyle style) {
- StyledLayerInterface<?> styledLayer = null;
-
- final 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
- *
- * TODO replace with
- * {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
- */
- public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData(
- final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap,
- final boolean visible) {
-
- final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap
- .clone();
- if (filteredMap.size() > 0) {
- filteredMap.clear(); // Just in case the close copies the contents
- }
-
- for (final AttributeMetadataInterface amd : amdMap.values())
- if (amd.isVisible() == visible)
- filteredMap.put(amd.getName(), amd);
-
- return filteredMap;
- }
-
- /**
- * Parses a {@link AttributeMetadataImpl} object from an JDOM-
- * {@link Element}. This method works like {@link
- * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
- *
- * TODO 20.11.2009, SK: There are some new attribute weight, functiona,
- * functionX and nodata in AttributeMetaData that should be parsed/exported
- * too. but this method is only used by ISDSS, which is not supporting that
- * stuff anyways.
- *
- * @param element
- * {@link Element} to parse
- */
- public static AttributeMetadataImpl parseAttributeMetaData(
- final Element element) {
- final String namespace = element.getAttributeValue("namespace");
- final String localname = element.getAttributeValue("localname");
- final NameImpl aName = new NameImpl(namespace, localname);
- 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 AttributeMetadataImpl(aName, visible, name, desc, unit);
- }
-
- /**
- * Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element}
- * with {@code <attribute>}-childs.
- *
- * @param element
- * {@link Element} to parse
- *
- * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
- * more attributes which are not used by Xulu/ISDSS. GP
- * exports/imports the AMD via AMLExporter and AMLImporter
- * classes. (SK, 3.2.2010) *
- */
- public static AttributeMetadataMap parseAttributeMetaDataMap(
- final Element element) {
- final AttributeMetadataMap metaData = new AttributeMetadataImplMap();
- final List<Element> attributesElements = element
- .getChildren(ELEM_NAME_ATTRIBUTE);
- for (final Element attibuteElement : attributesElements) {
- final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement);
- metaData.put(attrMetaData.getName(), attrMetaData);
- }
- return metaData;
- }
-
- /**
- * Loads a {@link AttributeMetadataImpl} object from an URL.
- *
- * @param documentUrl
- * {@link URL} to parse
- * @see #parseAttributeMetaData(Element)
- */
- public static AttributeMetadataMap loadAttributeMetaDataMap(
- final URL documentUrl) throws Exception {
- final Document document = SAX_BUILDER.build(documentUrl);
- return parseAttributeMetaDataMap(document.getRootElement());
- }
-
- /**
- * Creates an JDOM {@link Element} for the given
- * {@link AttributeMetadataImpl} object.
- *
- * @param amd
- * meta data for one attribute
- *
- * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
- * more attributes which are not used by Xulu/ISDSS. GP
- * exports/imports the AMD via AMLExporter and AMLImporter
- * classes. (SK, 3.2.2010)
- */
- public static Element createAttributeMetaDataElement(
- final AttributeMetadataInterface amd) {
- final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
- element.setAttribute("namespace",
- String.valueOf(amd.getName().getNamespaceURI()));
- element.setAttribute("localname", String.valueOf(amd.getLocalName()));
- 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 AttributeMetadataImpl} map.
- *
- * @param amdMap
- * map of attribute meta data
- */
- public static Element createAttributeMetaDataMapElement(
- final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) {
- final Element element = new Element(ELEM_NAME_AMD, AMLURI);
- for (final AttributeMetadataInterface amd : amdMap.values())
- element.addContent(createAttributeMetaDataElement(amd));
- return element;
- }
-
- /**
- * Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL.
- *
- * @param amdMap
- * map of {@link AttributeMetadataImpl}
- * @param documentUrl
- * {@link URL} to store the XML
- */
- public static void saveAttributeMetaDataMap(
- final AttributeMetadataMap 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(final Element element) {
-
- final boolean paintGaps = Boolean.valueOf(element
- .getAttributeValue("paintGaps"));
-
- final RasterLegendData rld = new RasterLegendData(paintGaps);
-
- for (final 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
- final 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 {
- final 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 (final Double key : rld.getSortedKeys()) {
- final 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(
- final ColorMap colorMap, final boolean paintGaps,
- final Integer digits) {
- final DecimalFormat decFormat = digits != null ? new DecimalFormat(
- SwingUtil.getNumberFormatPattern(digits)) : null;
- final RasterLegendData rld = new RasterLegendData(paintGaps);
- for (final ColorMapEntry cme : colorMap.getColorMapEntries()) {
- final 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(final Style style,
- final boolean paintGaps, final Integer digits) {
- final 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) {
- final 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(final String tagname,
- final Translation translation) {
- final 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 (final String lang : translation.keySet()) {
- final 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(
- final StyledLayerInterface styledObject,
- final StyledLayerStyle<?> style) {
- // set SLD style
- styledObject.setStyle(style.getGeoObjectStyle());
- // set meta data
- if (styledObject instanceof StyledGridCoverageInterface
- && (style.getMetaData() instanceof RasterLegendData || style
- .getMetaData() == null)) {
- final RasterLegendData sourceRld = (RasterLegendData) style
- .getMetaData();
- final 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)) {
- final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
- .getMetaData();
- final AttributeMetadataMap 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(
- final 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(
- final 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<AttributeMetadataMap> getStyledLayerStyle(
- final StyledFeatureCollectionInterface styledFC) {
- return new StyledLayerStyle<AttributeMetadataMap>(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(
- final URL geoObjectURL, final String sldExt, final String rldExt) {
- RasterLegendData metaData = null;
- Style sldStyle = null;
- try {
- final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
- geoObjectURL, sldExt));
- // SLD must be present
- if (styles == null || styles.length == 0)
- return null;
- sldStyle = styles[0];
- } catch (final Exception err) {
- // SLD must be present
- LangUtil.logDebugError(LOGGER, err);
- return null;
- }
-
- try {
- metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
- .changeUrlExt(geoObjectURL, rldExt));
- } catch (final FileNotFoundException err) {
- // ignore missing raster legend data
- } catch (final 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(
- final URL geoObjectURL) {
- return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
- }
-
- /**
- * Loads a {@linkplain Style SLD-Style} and a
- * {@linkplain AttributeMetadataImpl 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<AttributeMetadataMap> loadStyledFeatureStyle(
- final URL geoObjectURL, final String sldExt, final String rldExt) {
- AttributeMetadataMap metaData = null;
- Style sldStyle = null;
- try {
- final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
- geoObjectURL, sldExt));
- // SLD must be present
- if (styles == null || styles.length == 0)
- return null;
- sldStyle = styles[0];
- } catch (final Exception err) {
- // SLD must be present
- LangUtil.logDebugError(LOGGER, err);
- return null;
- }
-
- try {
- metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
- .changeUrlExt(geoObjectURL, rldExt));
- } catch (final FileNotFoundException err) {
- // ignore missing attribute meta data
- } catch (final Exception err) {
- // any other error during meta data creation leads to error
- LangUtil.logDebugError(LOGGER, err);
- return null;
- }
-
- return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, metaData);
- }
-
- /**
- * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
- * {@linkplain AttributeMetadataImpl 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<AttributeMetadataMap> loadStyledFeatureStyle(
- final 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(
- final StyledLayerStyle<T> style, final URL geoObjectURL,
- final String sldExt, final String mdExt) throws Exception {
- // Store the SLD
- final Style sldStyle = style.getGeoObjectStyle();
- if (sldStyle != null) {
- StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File(
- geoObjectURL.toURI()), sldExt));
- }
-
- // Store the meta data
- final 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((AttributeMetadataMap) 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 AttributeMetadataImpl}) 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(final StyledLayerStyle<?> style,
- final URL geoObjectURL) throws Exception {
- if (style.getMetaData() instanceof RasterLegendData)
- saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
- else
- saveStyledLayerStyle(style, geoObjectURL, "sld", "amd");
- }
-
- /**
- * Creates a {@link JPanel} that shows a legend for a list of
- * {@link FeatureTypeStyle}s and a targeted featureType
- *
- * @param style
- * The Style to presented in this legend
- * @param featureType
- * If this a legend for Point, Polygon or Line? Or ANY or NONE?
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
- public static JPanel createLegendSwingPanel(Style style,
- final SimpleFeatureType featureType, final int iconWidth,
- final int iconHeight) {
-
- if (featureType == null) {
- ExceptionDialog.show(new IllegalStateException(
- "featureType is null!"));
- return new JPanel();
- }
-
- final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
- if (style == null) {
- // No Style => no legend
- return panel;
- }
-
- // Reversing the list, because a point that is painted above a polygon
- // should be higher in the list.
- final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
- Collections.reverse(ftsList);
- for (final FeatureTypeStyle ftStyle : ftsList) {
-
- // // Try to import the FeatureType into an AtlasStyler RuleList to
- // // determine whether this RL is actually disabled.
- // StylingUtil.sldToString(ftStyle).contains(RL_DISABLED_FILTER.toString())
- // return;
-
- // One child-node for every rule
- final List<Rule> rules = ftStyle.rules();
- for (final Rule rule : rules) {
-
- // Check if this RULE shall actually appear in the legend
- if (rule.getName() != null
- && rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
- continue;
-
- /**
- * Let's not create a hbox for Rules that only contain
- * TextSymbolizers
- */
- if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
- .size() == rule.getSymbolizers().length)
- continue;
-
- final BufferedImage imageForRule = LegendIconFeatureRenderer
- .getInstance().createImageForRule(rule, featureType,
- new Dimension(iconWidth, iconHeight));
-
- final ImageIcon legendIcon = new ImageIcon(imageForRule);
-
- final JLabel iconLabel = new JLabel(legendIcon);
- panel.add(iconLabel, "sgx1");
- // hbox.setAlignmentX(0f);
- // hbox.add(iconLabel);
- // hbox.add(Box.createHorizontalStrut(3));
-
- final Translation labelT = new Translation();
- labelT.fromOneLine(rule.getDescription().getTitle().toString());
- final JLabel classTitleLabel = new JLabel(labelT.toString());
-
- panel.add(classTitleLabel, "sgx2");
- classTitleLabel.setLabelFor(iconLabel);
- }
- }
-
- return panel;
- }
-
- /**
- * Creates a {@link JComponent} that contains a legend for a given
- * {@link StyledRasterInterface} and a given {@link Style}.
- *
- * @param style
- * if <code>null</code>, the default {@link Style} is extracetd
- * from the {@link StyledRasterInterface}
- */
- public static JPanel createLegendSwingPanel(
- final StyledRasterInterface<?> styledRaster, Style style,
- final int iconWidth, final int iconHeight) {
-
- // If no style is given, we use the default style for this layer
- if (style == null)
- style = styledRaster.getStyle();
-
- /**
- * Determine whether a Style is responsible for the coloring
- */
- ColorModel colorModel = null;
- if (!isStyleable(styledRaster)
- || (isStyleable(styledRaster) && style == null)) {
- colorModel = getColorModel(styledRaster);
- }
-
- final RasterLegendData rasterLegendData = styledRaster
- .getLegendMetaData();
- final List<Double> legendRasterValues = rasterLegendData
- .getSortedKeys();
- final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
- .createSampleRasters();
-
- final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0"));
-
- for (final Double rValue : legendRasterValues) {
-
- // final Dimension ICON_SIZE = new Dimension(iconWidth,
- // new JLabel().getFontMetrics(new JLabel().getFont())
- // .getHeight() > 5 ? new JLabel().getFontMetrics(
- // new JLabel().getFont()).getHeight() : iconHeight);
-
- // ****************************************************************************
- // Create the actual icon
- // ****************************************************************************
- final BufferedImage buffImage = new BufferedImage(iconWidth,
- iconHeight, BufferedImage.TYPE_INT_ARGB);
-
- final Graphics2D graphics = buffImage.createGraphics();
-
- if (colorModel != null) {
- // The colors come from the ColorModel!
-
- try {
- Object inData = null;
- switch (colorModel.getTransferType()) {
- case DataBuffer.TYPE_BYTE:
- inData = new byte[] { rValue.byteValue() };
- break;
- case DataBuffer.TYPE_USHORT:
- inData = new short[] { rValue.shortValue() };
- break;
- case DataBuffer.TYPE_INT:
- inData = new int[] { rValue.intValue() };
- break;
- case DataBuffer.TYPE_SHORT:
- inData = new short[] { rValue.shortValue() };
- break;
- case DataBuffer.TYPE_FLOAT:
- inData = new float[] { rValue.floatValue() };
- break;
- case DataBuffer.TYPE_DOUBLE:
- inData = new double[] { rValue.doubleValue() };
- break;
- default:
- inData = rValue.intValue();
- }
- final Color color = new Color(colorModel.getRGB(inData));
- graphics.setBackground(color);
- graphics.setColor(color);
- graphics.fillRect(0, 0, iconWidth, iconHeight);
- } catch (final Exception e) {
- LOGGER.info(
- "Dann nehmen wir halt den GridCoverageRenderer", e);
- colorModel = null;
- }
- } else {
- // The colors come from the Style
-
- /**
- * The coverage contains only one value of value rValue
- */
- final GridCoverage2D sampleCov = sampleRasters.get(rValue);
- GridCoverageRenderer renderer;
- try {
- renderer = new GridCoverageRenderer(
- sampleCov.getCoordinateReferenceSystem(),
- JTSUtil.createEnvelope(sampleCov.getEnvelope()),
- new Rectangle(iconWidth, iconHeight),
- (AffineTransform) null);
- } catch (final Exception e1) {
- throw new RuntimeException(
- "Creating a GridCoverageRenderer failed:", e1);
- }
-
- /**
- * Iterate over all FeatureTypeStyles.
- */
- final List<RasterSymbolizer> rSymbols = StylingUtil
- .getRasterSymbolizers(style);
-
- for (final RasterSymbolizer symbolizer : rSymbols) {
- try {
- renderer.paint(graphics, sampleCov, symbolizer);
- } catch (final Exception ee) {
- LOGGER.error("Unable to paint " + symbolizer
- + " into the legend image", ee);
- }
- }
- }
-
- final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
- panel.add(iconLabel, "sgx1");
-
- final Translation labelT = rasterLegendData.get(rValue);
- final JLabel classTitleLabel = new JLabel(labelT.toString());
- panel.add(classTitleLabel, "sgx2"
- + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
- : ""));
- classTitleLabel.setLabelFor(iconLabel);
-
- if (rasterLegendData.isPaintGaps()) {
- iconLabel
- .setBorder(BorderFactory.createLineBorder(Color.black));
- }
-
- }
-
- return panel;
- }
-
- /**
- * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
- * return <code>null</code> if the geoobject can not be accessed.
- */
- @SuppressWarnings("unchecked")
- public static ColorModel getColorModel(
- final StyledRasterInterface<?> styledGrid) {
- ColorModel colorModel = null;
- try {
- final Object geoObject = styledGrid.getGeoObject();
- if (geoObject instanceof GridCoverage2D) {
- final GridCoverage2D cov = (GridCoverage2D) geoObject;
- colorModel = cov.getRenderedImage().getColorModel();
- } else if (styledGrid instanceof StyledGridCoverageReaderInterface) {
-
- final Parameter readGG = new Parameter(
- AbstractGridFormat.READ_GRIDGEOMETRY2D);
-
- final ReferencedEnvelope mapExtend = new ReferencedEnvelope(
- styledGrid.getEnvelope(), styledGrid.getCrs());
-
- readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
- new Rectangle(0, 0, 1, 1)), mapExtend));
-
- AbstractGridCoverage2DReader aReader;
- if (geoObject instanceof FeatureCollection) {
- final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
-
- aReader = (AbstractGridCoverage2DReader) FeatureUtil
- .getWrappedGeoObject(rFc);
-
- } else if (geoObject instanceof AbstractGridCoverage2DReader) {
- aReader = (AbstractGridCoverage2DReader) geoObject;
-
- } else
- throw new RuntimeException("need a reader...");
- //
-
- final GridCoverage2D cov = aReader
- .read(new GeneralParameterValue[] { readGG });
- colorModel = cov.getRenderedImage().getColorModel();
- }
- } catch (final Exception e) {
- LOGGER.error("Error reading the colormodel from " + styledGrid, e);
- return null;
- }
- return colorModel;
- }
-
- /**
- * @return <code>true</code> if a {@link RasterSymbolizer} can be applied
- * and will have an effect. Some rasters (e.g. GeoTIFF) can come
- * with their own {@link ColorModel} and will ignore any
- * {@link RasterSymbolizer} = SLD.
- */
- public static boolean isStyleable(
- final StyledRasterInterface<?> styledRaster) {
- final ColorModel colorModel = getColorModel(styledRaster);
-
- // LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
- // + colorModel != null ? colorModel.getClass().getSimpleName() :
- // "NULL");
-
- if (colorModel == null)
- return true;
- if (colorModel instanceof ComponentColorModel)
- return true;
- if (colorModel instanceof IndexColorModel)
- return true;
-
- return false;
- }
-
- /**
- * Set the given Style as the Style of the {@link MapLayer}, unless the
- * styles are the same (not comparing selection stuff). If the
- * {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
- * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
- * repaint, so only use it when needed.
- *
- * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has
- * been changed.
- */
- public static boolean updateMapLayerStyleIfChangedAndKeepSelection(
- MapLayer mapLayer, Style style2) {
-
- Style mapLayerStyleCleaned = StylingUtil
- .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
-
- Style newStyleCleaned = StylingUtil
- .removeSelectionFeatureTypeStyle(style2);
-
- if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) {
-
- // They are different when compared without SELECTION FTS!
-
- // Now let's copy any SELECTION FTS to the now style
- FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil
- .getSelectionFeatureTypeStyle(mapLayer.getStyle());
- if (selectionFeatureTypeStyle != null) {
- newStyleCleaned.featureTypeStyles().add(
- selectionFeatureTypeStyle);
- // newStyleCleaned is not so clean anymore... We just alled a
- // selcetion FTS
- }
-
- mapLayer.setStyle(newStyleCleaned);
-
- return true;
-
- } else {
- return false;
- }
- }
-
- /**
- * After loading an atlas, the AttribteMetaData contains whatever is written
- * in the XML. But the DBF may have changed! This method checks an
- * {@link AttributeMetadataMap} against a schema and also corrects
- * upperCase/lowerCase problems. It will also remove any geometry column
- * attribute metadata.
- */
- /**
- * After loading an atlas, the AttribteMetaData contains whatever is written
- * in the XML. But the DBF may have changed!
- */
- public static void checkAttribMetaData(
- AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
- SimpleFeatureType schema) {
-
- if (schema == null)
- throw new IllegalArgumentException("schmema may not be null!");
-
- ArrayList<Name> willRemove = new ArrayList<Name>();
-
- // 1. Check.. all attributes in the atm should be in the schema as well.
- // maybe correct some upperCase/loweCase stuff
-
- for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) {
-
- AttributeDescriptor foundDescr = schema
- .getDescriptor(atm.getName());
- if (foundDescr == null) {
- NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(
- schema, atm.getLocalName());
- if (bestMatch == null)
- willRemove.add(atm.getName());
- else
- atm.setName(bestMatch);
- } else if (foundDescr instanceof GeometryDescriptor) {
- // We don't want GeometryColumns in here
- willRemove.add(atm.getName());
- }
- }
-
- // Remove the ones that were not findable in the schema
- for (Name removeName : willRemove) {
- if (attributeMetaDataMap.remove(removeName) == null) {
- LOGGER.warn("removing the AMData didn't work");
- }
- }
-
- // 2. check... all attributes from the schema must have an ATM
- for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
- if (ad instanceof GeometryDescriptor)
- continue;
- if (!attributeMetaDataMap.containsKey(ad.getName())) {
- attributeMetaDataMap.put(new NameImpl(ad.getName()
- .getNamespaceURI(), ad.getName().getLocalPart()),
- new AttributeMetadataImpl(ad, schema
- .getAttributeDescriptors().indexOf(ad),
- attributeMetaDataMap.getLanguages()));
- }
- }
- }
-
- /**
- * Checks every attribute name in the {@link AttributeMetadataMap} for its
- * binding type. It the type is textual, add the mrpty string as a NODATA
- * value.
- *
- * @param attributeMetaDataMap
- * @param schema
- */
- public static void addEmptyStringToAllTextualAttributes(
- AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap,
- SimpleFeatureType schema) {
-
- for (Name name : attributeMetaDataMap.keySet()) {
- if (String.class.isAssignableFrom(schema.getDescriptor(name)
- .getType().getBinding())) {
- attributeMetaDataMap.get(name).getNodataValues().add("");
- }
- }
- }
-
- /**
- * @return a nicely formatted String containing all NODATA values of any
- * {@link AttributeMetadataInterface} object. Strings are quoted so
- * that any empty {@link String} can be seen.
- */
- public static String formatNoDataValues(Set<Object> nodataValuesList) {
- String nicelyFormatted = "";
- if (nodataValuesList != null) {
- if (nodataValuesList.size() == 0)
- nicelyFormatted = "";
- else {
- for (Object ndo : nodataValuesList) {
- if (ndo instanceof String)
- nicelyFormatted += "\"" + ndo + "\"";
- else
- nicelyFormatted += ndo.toString();
-
- nicelyFormatted += ",";
- }
- // Remove the extra comma
- nicelyFormatted = nicelyFormatted.substring(0,
- nicelyFormatted.length() - 1);
- }
- }
- return nicelyFormatted;
- }
-
- /**
- * Creates a new {@link AttributeMetadataMap} with instances of
- * {@link AttributeMetadataInterface} for every non-geometry attribute.
- * Default NODATA values (like "" for String) are set.
- */
- public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(
- SimpleFeatureType schema) {
- AttributeMetadataImplMap attMap = new AttributeMetadataImplMap();
-
- for (int i = 0; i < schema.getAttributeCount(); i++) {
- AttributeDescriptor attDesc = schema.getDescriptor(i);
-
- if (Geometry.class.isAssignableFrom(attDesc.getType().getBinding())) {
- // Ignore the Geometry column
- continue;
- }
-
- // TODO AttributeMetadataAS would be nicer, which would not work
- // with Translations ;-)
- AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
- new NameImpl(attDesc.getName().getNamespaceURI(), attDesc
- .getName().getLocalPart()), attMap.getLanguages());
-
- if (String.class.isAssignableFrom(attDesc.getType().getBinding())) {
- // For Strings we add the "" as NODATA values
- attMetaData.addNodataValue("");
- }
-
- attMap.put(attDesc.getName(), attMetaData);
- }
- return attMap;
- }
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledRasterInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledRasterInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/StyledRasterInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools;
-
-import de.schmitzm.geotools.data.RasterLegendData;
-
-/**
- * A {@link StyledLayerInterface} that is associated to a
- * {@link RasterLegendData}. The datatype is not yet defined.
- *
- * @see StyledGridCoverageInterface
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
-public interface StyledRasterInterface<E> extends StyledLayerInterface<E> {
-
- /**
- * @return A {@link RasterLegendData} object with pairs of value / label
- * information
- */
- RasterLegendData getLegendMetaData();
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AbstractAttributeMetadata.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AbstractAttributeMetadata.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AbstractAttributeMetadata.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,192 +0,0 @@
-package de.schmitzm.geotools.data;
-
-import java.util.HashSet;
-
-import org.geotools.feature.NameImpl;
-import org.opengis.feature.type.Name;
-
-import de.schmitzm.geotools.StyledLayerUtil;
-import de.schmitzm.i8n.Translation;
-
-public abstract class AbstractAttributeMetadata implements AttributeMetadataInterface {
-
- /** The Name of the attribute. This is the 'primary key' **/
- protected Name name;
-
- /** {@link Translation}s of the attribute's title **/
- protected Translation title = new Translation();
-
- /** {@link Translation}s of the attribute's description **/
- protected Translation desc = new Translation();
-
- /**
- * Allows to define general NODATA values for an attribute. e.g. -9999 can
- * be set and will always be interpreted as NULL internally and will usually
- * be ignored. This overcomes the problem, that
- **/
- protected HashSet<Object> nodataValues = new HashSet<Object>();
-
- /**
- * The unit append to all visualizations of values of this attribute (is not
- * null)
- **/
- protected String unit = "";
-
- /** Is the attribute visible to the user or ignored where possible **/
- protected boolean visible = true;
-
- @Override
- public Translation getTitle() {
- return title;
- }
-
- @Override
- public String getUnit() {
- return unit;
- }
-
- @Override
- public void setTitle(final String title) {
- this.title = new Translation(title);
- }
-
- @Override
- public void setDesc(final String desc) {
- this.desc = new Translation(desc);
- }
-
- /**
- * When listed, the attributes are listed according to their {@link #weight}
- * (heavier => further down)
- *
- * @see #compareTo(AttributeMetadataImpl)
- **/
- protected int weight = 0;
-
- @Override
- public double getWeight() {
- return weight;
- }
-
- @Override
- public void setWeight(double weight) {
- this.weight = new Double(weight).intValue();
- }
-
- /**
- * Will the end-user see this attribute?
- */
- @Override
- public boolean isVisible() {
- return visible;
- }
-
- @Override
- public void setDesc(final Translation desc) {
- this.desc = desc;
- }
-
- @Override
- public Translation getDesc() {
- return desc;
- }
-
- /**
- * The local name. E.g. the name of the DBF column as a {@link String}
- */
- @Override
- public String getLocalName() {
- return getName().getLocalPart();
- }
-
- /**
- * The fully qualified {@link Name} of the attribute, e.g.
- * <code>org.bla.plo:blub</code>
- */
- @Override
- public Name getName() {
- return name;
- }
-
- @Override
- public HashSet<Object> getNodataValues() {
- return nodataValues;
- }
-
- /**
- * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
- */
- @Override
- public void setLocalName(final String localName) {
- setName(new NameImpl(localName));
- }
-
- /**
- * The fully qualified {@link Name} of the attribute, e.g.
- * <code>org.bla.plo:blub</code>
- */
- @Override
- public void setName(final Name name) {
- this.name = name;
- }
-
- public void addNodataValue(Object nodataValue) {
- this.nodataValues.add(nodataValue);
- }
-
- public void removeNodataValue(Object nodataValue) {
- this.nodataValues.remove(nodataValue);
- }
-
- @Override
- public void setTitle(final Translation title) {
- this.title = title;
- }
-
- @Override
- public void setUnit(final String unit) {
- this.unit = unit;
- }
-
- @Override
- public void setVisible(final boolean visible) {
- this.visible = visible;
- }
-
- /**
- * For nicer debugging
- */
- @Override
- public String toString() {
- StringBuffer sb = new StringBuffer();
- if (name != null)
- sb.append(name.toString() + " ");
- sb.append("weight=" + weight + " ");
- sb.append("title=" + getTitle().toString());
- return sb.toString();
- }
-
-
- /**
- * Takes any value object and checks it against the NODATA values. If the
- * value equals a NODATA value, <code>null</code> is returned. Otherwise the
- * same object is returned.
- *
- * Note: This method is called often.
- */
- @Override
- public Object fiterNodata(final Object value) {
- if (nodataValues.contains(value))
- return null;
- return value;
- }
-
- /**
- * @return a nicely formatted String containing all NODATA values. Strings
- * are quoted so that any empty {@link String} can be seen.
- */
- @Override
- public String getNoDataValuesFormatted() {
- return StyledLayerUtil.formatNoDataValues(getNodataValues());
- }
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetaDataAttributeTypeFilter.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools.data;
-
-import org.opengis.feature.type.AttributeDescriptor;
-
-import de.schmitzm.geotools.AttributeMetadataImplMap;
-import de.schmitzm.geotools.feature.AttributeTypeFilter;
-
-/**
- * Implements an {@link AttributeTypeFilter} using the
- * {@linkplain AttributeMetadataImpl#isVisible() visible}-property of an
- * {@link AttributeMetadataImpl} map (or array).<br>
- * If this filter is created from a {@code null} map or {@code null} array,
- * the filter accepts ALL attributes except geometries.
- * @see AttributeTypeFilter#NO_GEOMETRY
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
- */
-public class AttributeMetaDataAttributeTypeFilter implements AttributeTypeFilter {
-
- /** The meta data of a set of attributes */
- protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaDataMap = null;
-
- /**
- * Creates a new filter.
- * @param attrMetaData the meta data of some attributes
- */
- public AttributeMetaDataAttributeTypeFilter(final AttributeMetadataImpl[] attrMetaData) {
- this.attrMetaDataMap = new AttributeMetadataImplMap();
- for (int i=0; attrMetaData!=null && i<attrMetaData.length; i++)
- this.attrMetaDataMap.put(attrMetaData[i].getName(), attrMetaData[i]);
- }
-
- /**
- * Creates a new filter.
- * @param attrMetaData the meta data of some attributes
- */
- public AttributeMetaDataAttributeTypeFilter(final AttributeMetadataMap attrMetaData) {
- this.attrMetaDataMap = attrMetaData;
- }
-
- /**
- * Returns {@code true} if the attribute meta data at index {@code idx} is
- * visible and the attribute is no geometry at all.
- */
- public boolean accept(final AttributeDescriptor type) {
- // if no meta data is given, all attributes (except Geometry)
- // are treated as visible
- if ( attrMetaDataMap == null )
- return NO_GEOMETRY.accept(type);
-
- // no geometry attributes at all
- if ( !NO_GEOMETRY.accept(type) )
- return false;
-
- // Auto-Insert-Behavior of AttributeMetaDataMapImpl.get(.) constrains
- // us to first check the containing of the attribute in the, so that we
- // do not accidentally insert an attribute to the map (especially
- // "the_geom"!!!)
- // --> if meta data is not specified, do not except it by the filter
- if ( !attrMetaDataMap.containsKey(type.getName()) )
- return false;
-
- // Check the visible property of meta data
- final AttributeMetadataImpl metaData = attrMetaDataMap.get(type.getName());
- return metaData.isVisible();
- }
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataImpl.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataImpl.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataImpl.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,263 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools.data;
-
-import java.util.HashSet;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.geotools.feature.NameImpl;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.Name;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.geotools.StyledLayerInterface;
-import de.schmitzm.i8n.I8NUtil;
-import de.schmitzm.i8n.Translation;
-
-/**
- * This class holds meta information about an attribute/column. This information
- * is used by {@link StyledLayerInterface} and many others.<br/>
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
-public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
- QualityQuantizable {
-
- static private final Logger LOGGER = Logger
- .getLogger(AttributeMetadataImpl.class);
-
- /**
- * For numerical attributes the value can be transformed by VALUE*X+A when
- * presented on screen. TODO not implemented yet
- **/
- protected Double functionA = 0.;
-
- /**
- * For numerical attributes the value can be transformed by VALUE*X+A when
- * presented on screen. TODO not implemented yet
- **/
- protected Double functionX = 1.;
-
- /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
- private AttributeMetadataImpl() {
- }
-
- public AttributeMetadataImpl(final AttributeDescriptor attDesc,
- final int weight, final List<String> langs) {
- this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
- setWeight(weight);
- }
-
- public AttributeMetadataImpl(final AttributeDescriptor attDesc,
- final List<String> langs) {
- this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
- }
-
- /**
- * Creates an {@link AttributeMetadataImpl} object with the following
- * information
- *
- * @param colIdx
- * The column index of this attribute in the underlying
- * table/dbf/etc...
- * @param visible
- * Shall this attribute be displayed or hidden from the user?
- * @param title
- * {@link Translation} for Name
- * @param desc
- * {@link Translation} for an attribute description
- * @param unit
- * {@link String} of the unit that the information is in
- */
- public AttributeMetadataImpl(final Name name, final Boolean visible,
- final Translation title, final Translation desc, final String unit) {
-
- this.setName(name);
- this.title = title;
- this.desc = desc;
- this.visible = visible;
- this.unit = unit;
- }
-
- /**
- * Creates an {@link AttributeMetadataImpl} object with the following
- * information
- *
- * @param colIdx
- * The column index of this attribute in the underlying
- * table/dbf/etc...
- * @param visible
- * Shall this attribute be displayed or hidden from the user?
- * @param unit
- * {@link String} of the unit that the information is in
- */
- public AttributeMetadataImpl(final Name name, final Boolean visible,
- final String unit) {
- this.setName(name);
- this.visible = visible;
- this.unit = unit;
- }
-
- /**
- * Creates a new visible {@link AttributeMetadataImpl}
- */
- public AttributeMetadataImpl(final Name name, final List<String> langs) {
- this(name, true, new Translation(langs, name.getLocalPart()),
- new Translation(), "");
- }
-
- /**
- * Creates a new visible {@link AttributeMetadataImpl}
- */
- public AttributeMetadataImpl(final Name name, final String defaultTitle,
- final List<String> langs) {
- this(name, true, new Translation(langs, defaultTitle),
- new Translation(), "");
- }
-
- /**
- * Creates an {@link AttributeMetadataImpl} object with the following
- * information
- *
- * @param visible
- * Shall this attribute be displayed or hidden from the user?
- * @param title
- * {@link Translation} for Name
- * @param desc
- * {@link Translation} for an attribute description
- * @param unit
- * {@link String} of the unit that the information is in
- */
- public AttributeMetadataImpl(final String localName, final Boolean visible,
- final Translation title, final Translation desc, final String unit) {
- this(new NameImpl(localName), true, title, desc, "");
- }
-
- /**
- * Creates a new visible {@link AttributeMetadataImpl} with default (no)
- * values.
- */
- public AttributeMetadataImpl(final String localName,
- final List<String> langs) {
- this(localName, true, new Translation(langs, localName),
- new Translation(), "");
- }
-
- /**
- * Creates a new visible {@link AttributeMetadataImpl}
- */
- public AttributeMetadataImpl(final String localName,
- final String defaultTitle, final List<String> langs) {
- this(localName, true, new Translation(langs, defaultTitle),
- new Translation(), "");
- }
-
- /**
- * Orders the attributes according to their {@link #weight}. Heavier =>
- * further down.
- */
- @Override
- public int compareTo(final AttributeMetadataInterface atm2) {
- return new Integer(weight).compareTo(new Double(atm2.getWeight())
- .intValue());
- }
-
- /**
- * @see Copyable inferface
- */
- @Override
- public AttributeMetadataInterface copy() {
- return copyTo(new AttributeMetadataImpl());
- }
-
- /**
- * @see Copyable inferface
- */
- @Override
- public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
- getTitle().copyTo(amd.getTitle());
- getDesc().copyTo(amd.getDesc());
- amd.setUnit(getUnit());
- amd.setVisible(isVisible());
- amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
- .getLocalPart()));
-
- amd.setWeight(getWeight());
-
- if (amd instanceof AttributeMetadataImpl) {
- AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
-
- amd_.setFunctionX(getFunctionX());
- amd_.setFunctionA(getFunctionA());
- amd_.setNodataValues(getNodataValues());
- }
-
- return amd;
- }
-
- // only to be used by copyTo()
- private void setNodataValues(HashSet<Object> nodataValues_) {
- nodataValues = nodataValues_;
- }
-
- public Double getFunctionA() {
- return functionA;
- }
-
- public Double getFunctionX() {
- return functionX;
- }
-
- /**
- * @return a number between 0 (bad) and 1 (good) that is calculated from the
- * amount of translation available. If this attribute is not
- * {@link #visible}, it will return 1.
- */
- @Override
- public double getQuality(final List<String> languages) {
-
- if (!isVisible())
- return 1.;
-
- return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
- .qmTranslation(languages, getDesc()) * 1.) / 3.;
- }
-
- public void setFunctionA(final Double functionA) {
- this.functionA = functionA;
- }
-
- public void setFunctionX(final Double functionX) {
- this.functionX = functionX;
- }
-
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,122 +0,0 @@
-package de.schmitzm.geotools.data;
-
-import java.util.HashSet;
-
-import org.opengis.feature.type.Name;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.i8n.Translation;
-
-public interface AttributeMetadataInterface extends Copyable<AttributeMetadataInterface>,
- Comparable<AttributeMetadataInterface> {
-
- /**
- * @return a translatable title for this attribute..
- */
- public Translation getTitle();
-
- /**
- * Set a translatable title for this attribute..
- */
- public void setTitle(Translation title);
-
- /**
- * Set an untranslated title for this attribute or pass a {@link Translation} encryped as a {@link String}
- */
- public void setTitle(String title);
-
- /**
- * @return a translatable description for this attribute
- */
- public Translation getDesc();
-
- /**
- * Set a translatable description for this attribute.
- */
- public void setDesc(Translation desc);
-
- /**
- * Set an untranslated description for this attribute or pass a {@link Translation} encryped as a {@link String}
- */
- public void setDesc(String desc);
-
-
- /**
- * The local name. E.g. the name of the DBF column as a {@link String}.
- */
- public String getLocalName();
-
- /**
- * A short form for #setName(new NameImpl(localName))
- */
- public void setLocalName(String localName);
-
- /**
- * The fully qualified {@link Name} of the attribute, e.g.
- * <code>org.bla.plo:blub</code>. The second part equals the
- * {@link #getLocalName()} value. The first may be <code>null</code> or
- * represent the layer name.
- */
- public Name getName();
-
- /**
- * set the fully qualified {@link Name} of this attribute.
- */
- public void setName(Name name);
-
- /**
- * A list og objects that represent NODATA-values for this attribute. The
- * objects are supporsed to be correctly casted already. That means that the
- * NODATA objects listed here have must have the same type as the values of
- * this object.
- */
- public HashSet<Object> getNodataValues();
-
- /**
- * Takes any value object and checks it against the NODATA values. If the
- * value equals a NODATA value, <code>null</code> is returned. Otherwise the
- * same object is returned.
- *
- * Note: This method is called often.
- */
- public Object fiterNodata(Object value);
-
- /**
- * @return a non-translatable unit {@link String} for this attribute values.
- */
- public String getUnit();
-
- /**
- * Set a unit {@link String} for this attribute values.
- */
- public void setUnit(String unit);
-
- /**
- * @return A value defining the position of this attribute whenever the
- * attributes are listed to an end-user. The higher the weight, the
- * lower the position. (heavy goes down, light goes up)
- */
- public double getWeight();
-
- /**
- * set a value defining the position of this attribute whenever the
- * attributes are listed to an end-user. The higher the weight, the lower
- * the position. (heavy goes down, light goes up)
- */
- public void setWeight(double weight);
-
- /**
- * @return <code>false</code> if this attribute should not be selectable or
- * shown to the end-user.
- */
- public boolean isVisible();
-
- /**
- * Set <code>false</code> if this attribute should not be shown to the
- * end-user.
- */
- public void setVisible(boolean visible);
-
- String getNoDataValuesFormatted();
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataMap.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/AttributeMetadataMap.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,175 +0,0 @@
-package de.schmitzm.geotools.data;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.log4j.Logger;
-import org.geotools.feature.NameImpl;
-import org.opengis.feature.type.Name;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.i8n.Translation;
-
-/**
- * The {@link AttributeMetadataMap} is a {@link Map} holding {@link AMD_IMPL}
- * object for {@link Name} keys. It's an extension of a {@link TreeMap}. It's
- * copyable in the sense of the {@link Copyable} interface.<br>
- * The {@link #get(Name)} and {@link #get(String)} methods will never return
- * <code>null</code>, but rather create a default {@link AMD_IMPL} on-the-fly.
- */
-public abstract class AttributeMetadataMap<AMD_IMPL extends AttributeMetadataInterface>
- extends TreeMap<Name, AMD_IMPL> implements
- Copyable<AttributeMetadataMap>, QualityQuantizable {
-
- private static final long serialVersionUID = 4936966916517396063L;
-
- protected static final Logger LOGGER = Logger
- .getLogger(AttributeMetadataMap.class);
-
- /**
- * A list of default languages used when creating default {@link AMD_IMPL}
- * on-the-fly. If not initialized by a constructor, it will be
- * {@link Translation#getActiveLang()} only.
- **/
- protected final List<String> langs;
-
- /**
- * AttributeMetadataMap is based on {@link Translation} and would like to
- * know how many languages are supported, so the needed defaults can be
- * created.<br/>
- * If you use this constructor, it will be initialized to only use one
- * language, which is {@link Translation.getActiveLang()}.
- */
- public AttributeMetadataMap() {
- langs = new ArrayList<String>();
- langs.add(Translation.getActiveLang());
- }
-
- /**
- * Creates an {@link AttributeMetadataMap} and sets the list of default
- * languages.
- */
- public AttributeMetadataMap(final List<String> defLanguages) {
- langs = defLanguages;
- }
-
- /**
- * Creates an {@link AttributeMetadataMap} and sets the list of default
- * languages.
- */
- public AttributeMetadataMap(final String[] langs) {
- this.langs = new ArrayList<String>(java.util.Arrays.asList(langs));
- }
-
- /**
- * Copies all its values to another {@link AttributeMetadataMap}. @see
- * {@link Copyable} interface.
- */
- @Override
- public AttributeMetadataMap<? extends AttributeMetadataInterface> copyTo(AttributeMetadataMap amdMap) {
-
- amdMap.clear();
-
- for (final Name key : keySet()) {
- final AMD_IMPL AMD_IMPL = get(key);
- amdMap.put(key, AMD_IMPL.copy());
- }
- return amdMap;
- }
-
- /**
- * Returns the {@link AMD_IMPL} for a given {@link NameImpl}. May return
- * <code>null</code> or create a default {@link AttributeMetadataInterface} depending
- * on whether this method is overwritten. fly.
- */
- public AMD_IMPL get(final Name name) {
- return super.get(name);
- }
-
- /**
- * @Deprecated use get(Name name) or get(String localName)
- */
- @Deprecated
- @Override
- public AMD_IMPL get(final Object key) {
- LOGGER.error("PLEASE DONT USE get(Object) any MORE!");
- return super.get(key);
- }
-
- /**
- * Returns the {@link AMD_IMPL} for a given {@link Name}. Never returns
- * <code>null</code>, but rather creates a default {@link AMD_IMPL} on the
- * fly.
- */
- public AMD_IMPL get(final String localName) {
- if (localName == null)
- return null;
- return this.get(new NameImpl(localName));
- }
-
- public List<String> getLanguages() {
- return langs;
- }
-
- /**
- * @return a number between 0. (bad) and 1. (good) that is calculated from
- * the amount of translation available in the visible attributes
- */
- @Override
- public double getQuality(final List<String> languages) {
- int allVisible = 0;
- double colQmSum = 0.;
- for (final AMD_IMPL oneCol : values()) {
-
- if (oneCol.isVisible() && oneCol instanceof QualityQuantizable) {
- allVisible++;
- colQmSum += ((QualityQuantizable) oneCol).getQuality(languages);
- }
- }
-
- if (allVisible > 0)
- return colQmSum / allVisible;
- else
- return 1.;
-
- }
-
- /**
- * @return List of {@link AMD_IMPL} objects ordered by their weight.
- * (heavier => further down)
- */
- public List<AMD_IMPL> sortedValues() {
- final List<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
- final Collection<AMD_IMPL> values = values();
- list.addAll(values);
- Collections.sort(list);
- return list;
- }
-
- /**
- * @return List of only the visible {@link AMD_IMPL} objects ordered by
- * their weight. (heavier => further down)
- */
- public List<AMD_IMPL> sortedValuesVisibleOnly() {
- final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
- for (final AMD_IMPL atm : sortedValues()) {
- if (atm.isVisible())
- list.add(atm);
- }
- return list;
- }
-
- /**
- * Just for debuggung. Simply returns {@code super.put(.)}.
- * TODO: remove this method.
- */
- @Override
- public AMD_IMPL put(Name key, AMD_IMPL value) {
- return super.put(key, value);
- };
-
-}
Deleted: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/RasterLegendData.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/RasterLegendData.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/RasterLegendData.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.geotools.data;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.log4j.Logger;
-import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.geometry.Envelope2D;
-import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.geotools.GTUtil;
-import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
-
-/**
- * Holds all the additional information needed to paint a Legend for a
- * RasterLayer. So far, only Legends for one-band raster layers are supported.
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- *
- * TODO implements {@link Copyable}
- */
-public class RasterLegendData extends TreeMap<Double, Translation> implements
- Copyable<RasterLegendData> {
- static private final Logger LOGGER = Logger
- .getLogger(RasterLegendData.class);
-
- private Boolean paintGaps = false;
-
- /**
- * Shall bigger gaps be painted between the raster images
- */
- public Boolean isPaintGaps() {
- return paintGaps;
- }
-
- public void setPaintGaps(boolean paintPaps) {
- this.paintGaps = paintPaps;
- }
-
- /**
- * {@link #paintGaps} defines, if gaps should be painted between the legends
- * colors, indicating nominal values in the raster (e.g. classifications)
- */
- public RasterLegendData(boolean paintGaps) {
- this.paintGaps = paintGaps;
- }
-
- /**
- * Returns a new list containing all {@link Double} values that shall apear
- * in the legend.
- */
- public List<Double> getSortedKeys() {
- Double[] array = keySet().toArray(new Double[] {});
-
- Arrays.sort(array);
-
- final LinkedList<Double> linkedList = new LinkedList<Double>();
- for (Double o : array) {
- linkedList.add(o);
- }
-
- return linkedList;
- }
-
- /**
- * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each legend
- * value. These rasters can be used to do visualize the legend item in the
- * corresponding color via {@link GridCoverageRenderer}.
- */
- public Map<Double, GridCoverage2D> createSampleRasters() {
- Map<Double, GridCoverage2D> sampleRaster = new HashMap<Double, GridCoverage2D>();
-
- for (Double rasterValue : keySet()) {
- GridCoverage2D grid = GridUtil.GRID_FAC.create("Legend_"
- + rasterValue,
- new float[][] { { rasterValue.floatValue() } },
- new Envelope2D(GTUtil.WGS84, 0, 0, 1, 1));
- sampleRaster.put(rasterValue, grid);
- }
- return sampleRaster;
- }
-
- /**
- * Creates a new {@link RasterLegendData} object with identical values
- */
- @Override
- public RasterLegendData copy() {
- RasterLegendData copy = (RasterLegendData) super.clone();
- return copyTo(copy);
- }
-
- /**
- * Deep-copies all values of this {@link RasterLegendData} to another
- * {@link RasterLegendData}
- */
- @Override
- public RasterLegendData copyTo(RasterLegendData target) {
- target.clear();
-
- target.setPaintGaps(isPaintGaps());
-
- for (Double o : keySet()) {
- target.put(new Double(o), get(o).copy());
- }
-
- return target;
- }
-}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,192 @@
+package de.schmitzm.geotools.data.amd;
+
+import java.util.HashSet;
+
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.Name;
+
+import de.schmitzm.geotools.styling.StyledLayerUtil;
+import de.schmitzm.i8n.Translation;
+
+public abstract class AbstractAttributeMetadata implements AttributeMetadataInterface {
+
+ /** The Name of the attribute. This is the 'primary key' **/
+ protected Name name;
+
+ /** {@link Translation}s of the attribute's title **/
+ protected Translation title = new Translation();
+
+ /** {@link Translation}s of the attribute's description **/
+ protected Translation desc = new Translation();
+
+ /**
+ * Allows to define general NODATA values for an attribute. e.g. -9999 can
+ * be set and will always be interpreted as NULL internally and will usually
+ * be ignored. This overcomes the problem, that
+ **/
+ protected HashSet<Object> nodataValues = new HashSet<Object>();
+
+ /**
+ * The unit append to all visualizations of values of this attribute (is not
+ * null)
+ **/
+ protected String unit = "";
+
+ /** Is the attribute visible to the user or ignored where possible **/
+ protected boolean visible = true;
+
+ @Override
+ public Translation getTitle() {
+ return title;
+ }
+
+ @Override
+ public String getUnit() {
+ return unit;
+ }
+
+ @Override
+ public void setTitle(final String title) {
+ this.title = new Translation(title);
+ }
+
+ @Override
+ public void setDesc(final String desc) {
+ this.desc = new Translation(desc);
+ }
+
+ /**
+ * When listed, the attributes are listed according to their {@link #weight}
+ * (heavier => further down)
+ *
+ * @see #compareTo(AttributeMetadataImpl)
+ **/
+ protected int weight = 0;
+
+ @Override
+ public double getWeight() {
+ return weight;
+ }
+
+ @Override
+ public void setWeight(double weight) {
+ this.weight = new Double(weight).intValue();
+ }
+
+ /**
+ * Will the end-user see this attribute?
+ */
+ @Override
+ public boolean isVisible() {
+ return visible;
+ }
+
+ @Override
+ public void setDesc(final Translation desc) {
+ this.desc = desc;
+ }
+
+ @Override
+ public Translation getDesc() {
+ return desc;
+ }
+
+ /**
+ * The local name. E.g. the name of the DBF column as a {@link String}
+ */
+ @Override
+ public String getLocalName() {
+ return getName().getLocalPart();
+ }
+
+ /**
+ * The fully qualified {@link Name} of the attribute, e.g.
+ * <code>org.bla.plo:blub</code>
+ */
+ @Override
+ public Name getName() {
+ return name;
+ }
+
+ @Override
+ public HashSet<Object> getNodataValues() {
+ return nodataValues;
+ }
+
+ /**
+ * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
+ */
+ @Override
+ public void setLocalName(final String localName) {
+ setName(new NameImpl(localName));
+ }
+
+ /**
+ * The fully qualified {@link Name} of the attribute, e.g.
+ * <code>org.bla.plo:blub</code>
+ */
+ @Override
+ public void setName(final Name name) {
+ this.name = name;
+ }
+
+ public void addNodataValue(Object nodataValue) {
+ this.nodataValues.add(nodataValue);
+ }
+
+ public void removeNodataValue(Object nodataValue) {
+ this.nodataValues.remove(nodataValue);
+ }
+
+ @Override
+ public void setTitle(final Translation title) {
+ this.title = title;
+ }
+
+ @Override
+ public void setUnit(final String unit) {
+ this.unit = unit;
+ }
+
+ @Override
+ public void setVisible(final boolean visible) {
+ this.visible = visible;
+ }
+
+ /**
+ * For nicer debugging
+ */
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ if (name != null)
+ sb.append(name.toString() + " ");
+ sb.append("weight=" + weight + " ");
+ sb.append("title=" + getTitle().toString());
+ return sb.toString();
+ }
+
+
+ /**
+ * Takes any value object and checks it against the NODATA values. If the
+ * value equals a NODATA value, <code>null</code> is returned. Otherwise the
+ * same object is returned.
+ *
+ * Note: This method is called often.
+ */
+ @Override
+ public Object fiterNodata(final Object value) {
+ if (nodataValues.contains(value))
+ return null;
+ return value;
+ }
+
+ /**
+ * @return a nicely formatted String containing all NODATA values. Strings
+ * are quoted so that any empty {@link String} can be seen.
+ */
+ @Override
+ public String getNoDataValuesFormatted() {
+ return StyledLayerUtil.formatNoDataValues(getNodataValues());
+ }
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.data.amd;
+
+import org.opengis.feature.type.AttributeDescriptor;
+
+import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
+import de.schmitzm.geotools.feature.AttributeTypeFilter;
+
+/**
+ * Implements an {@link AttributeTypeFilter} using the
+ * {@linkplain AttributeMetadataImpl#isVisible() visible}-property of an
+ * {@link AttributeMetadataImpl} map (or array).<br>
+ * If this filter is created from a {@code null} map or {@code null} array,
+ * the filter accepts ALL attributes except geometries.
+ * @see AttributeTypeFilter#NO_GEOMETRY
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class AttributeMetaDataAttributeTypeFilter implements AttributeTypeFilter {
+
+ /** The meta data of a set of attributes */
+ protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaDataMap = null;
+
+ /**
+ * Creates a new filter.
+ * @param attrMetaData the meta data of some attributes
+ */
+ public AttributeMetaDataAttributeTypeFilter(final AttributeMetadataImpl[] attrMetaData) {
+ this.attrMetaDataMap = new AttributeMetadataImplMap();
+ for (int i=0; attrMetaData!=null && i<attrMetaData.length; i++)
+ this.attrMetaDataMap.put(attrMetaData[i].getName(), attrMetaData[i]);
+ }
+
+ /**
+ * Creates a new filter.
+ * @param attrMetaData the meta data of some attributes
+ */
+ public AttributeMetaDataAttributeTypeFilter(final AttributeMetadataMap attrMetaData) {
+ this.attrMetaDataMap = attrMetaData;
+ }
+
+ /**
+ * Returns {@code true} if the attribute meta data at index {@code idx} is
+ * visible and the attribute is no geometry at all.
+ */
+ public boolean accept(final AttributeDescriptor type) {
+ // if no meta data is given, all attributes (except Geometry)
+ // are treated as visible
+ if ( attrMetaDataMap == null )
+ return NO_GEOMETRY.accept(type);
+
+ // no geometry attributes at all
+ if ( !NO_GEOMETRY.accept(type) )
+ return false;
+
+ // Auto-Insert-Behavior of AttributeMetaDataMapImpl.get(.) constrains
+ // us to first check the containing of the attribute in the, so that we
+ // do not accidentally insert an attribute to the map (especially
+ // "the_geom"!!!)
+ // --> if meta data is not specified, do not except it by the filter
+ if ( !attrMetaDataMap.containsKey(type.getName()) )
+ return false;
+
+ // Check the visible property of meta data
+ final AttributeMetadataImpl metaData = attrMetaDataMap.get(type.getName());
+ return metaData.isVisible();
+ }
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.data.amd;
+
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.Name;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.geotools.data.QualityQuantizable;
+import de.schmitzm.geotools.styling.StyledLayerInterface;
+import de.schmitzm.i8n.I8NUtil;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * This class holds meta information about an attribute/column. This information
+ * is used by {@link StyledLayerInterface} and many others.<br/>
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
+ QualityQuantizable {
+
+ static private final Logger LOGGER = Logger
+ .getLogger(AttributeMetadataImpl.class);
+
+ /**
+ * For numerical attributes the value can be transformed by VALUE*X+A when
+ * presented on screen. TODO not implemented yet
+ **/
+ protected Double functionA = 0.;
+
+ /**
+ * For numerical attributes the value can be transformed by VALUE*X+A when
+ * presented on screen. TODO not implemented yet
+ **/
+ protected Double functionX = 1.;
+
+ /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
+ private AttributeMetadataImpl() {
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final int weight, final List<String> langs) {
+ this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
+ setWeight(weight);
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final List<String> langs) {
+ this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataImpl} object with the following
+ * information
+ *
+ * @param colIdx
+ * The column index of this attribute in the underlying
+ * table/dbf/etc...
+ * @param visible
+ * Shall this attribute be displayed or hidden from the user?
+ * @param title
+ * {@link Translation} for Name
+ * @param desc
+ * {@link Translation} for an attribute description
+ * @param unit
+ * {@link String} of the unit that the information is in
+ */
+ public AttributeMetadataImpl(final Name name, final Boolean visible,
+ final Translation title, final Translation desc, final String unit) {
+
+ this.setName(name);
+ this.title = title;
+ this.desc = desc;
+ this.visible = visible;
+ this.unit = unit;
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataImpl} object with the following
+ * information
+ *
+ * @param colIdx
+ * The column index of this attribute in the underlying
+ * table/dbf/etc...
+ * @param visible
+ * Shall this attribute be displayed or hidden from the user?
+ * @param unit
+ * {@link String} of the unit that the information is in
+ */
+ public AttributeMetadataImpl(final Name name, final Boolean visible,
+ final String unit) {
+ this.setName(name);
+ this.visible = visible;
+ this.unit = unit;
+ }
+
+ /**
+ * Creates a new visible {@link AttributeMetadataImpl}
+ */
+ public AttributeMetadataImpl(final Name name, final List<String> langs) {
+ this(name, true, new Translation(langs, name.getLocalPart()),
+ new Translation(), "");
+ }
+
+ /**
+ * Creates a new visible {@link AttributeMetadataImpl}
+ */
+ public AttributeMetadataImpl(final Name name, final String defaultTitle,
+ final List<String> langs) {
+ this(name, true, new Translation(langs, defaultTitle),
+ new Translation(), "");
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataImpl} object with the following
+ * information
+ *
+ * @param visible
+ * Shall this attribute be displayed or hidden from the user?
+ * @param title
+ * {@link Translation} for Name
+ * @param desc
+ * {@link Translation} for an attribute description
+ * @param unit
+ * {@link String} of the unit that the information is in
+ */
+ public AttributeMetadataImpl(final String localName, final Boolean visible,
+ final Translation title, final Translation desc, final String unit) {
+ this(new NameImpl(localName), true, title, desc, "");
+ }
+
+ /**
+ * Creates a new visible {@link AttributeMetadataImpl} with default (no)
+ * values.
+ */
+ public AttributeMetadataImpl(final String localName,
+ final List<String> langs) {
+ this(localName, true, new Translation(langs, localName),
+ new Translation(), "");
+ }
+
+ /**
+ * Creates a new visible {@link AttributeMetadataImpl}
+ */
+ public AttributeMetadataImpl(final String localName,
+ final String defaultTitle, final List<String> langs) {
+ this(localName, true, new Translation(langs, defaultTitle),
+ new Translation(), "");
+ }
+
+ /**
+ * Orders the attributes according to their {@link #weight}. Heavier =>
+ * further down.
+ */
+ @Override
+ public int compareTo(final AttributeMetadataInterface atm2) {
+ return new Integer(weight).compareTo(new Double(atm2.getWeight())
+ .intValue());
+ }
+
+ /**
+ * @see Copyable inferface
+ */
+ @Override
+ public AttributeMetadataInterface copy() {
+ return copyTo(new AttributeMetadataImpl());
+ }
+
+ /**
+ * @see Copyable inferface
+ */
+ @Override
+ public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
+ getTitle().copyTo(amd.getTitle());
+ getDesc().copyTo(amd.getDesc());
+ amd.setUnit(getUnit());
+ amd.setVisible(isVisible());
+ amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
+ .getLocalPart()));
+
+ amd.setWeight(getWeight());
+
+ if (amd instanceof AttributeMetadataImpl) {
+ AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
+
+ amd_.setFunctionX(getFunctionX());
+ amd_.setFunctionA(getFunctionA());
+ amd_.setNodataValues(getNodataValues());
+ }
+
+ return amd;
+ }
+
+ // only to be used by copyTo()
+ private void setNodataValues(HashSet<Object> nodataValues_) {
+ nodataValues = nodataValues_;
+ }
+
+ public Double getFunctionA() {
+ return functionA;
+ }
+
+ public Double getFunctionX() {
+ return functionX;
+ }
+
+ /**
+ * @return a number between 0 (bad) and 1 (good) that is calculated from the
+ * amount of translation available. If this attribute is not
+ * {@link #visible}, it will return 1.
+ */
+ @Override
+ public double getQuality(final List<String> languages) {
+
+ if (!isVisible())
+ return 1.;
+
+ return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
+ .qmTranslation(languages, getDesc()) * 1.) / 3.;
+ }
+
+ public void setFunctionA(final Double functionA) {
+ this.functionA = functionA;
+ }
+
+ public void setFunctionX(final Double functionX) {
+ this.functionX = functionX;
+ }
+
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,53 @@
+package de.schmitzm.geotools.data.amd;
+
+import java.util.List;
+
+import org.opengis.feature.type.Name;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+
+public class AttributeMetadataImplMap extends AttributeMetadataMap<AttributeMetadataImpl> {
+
+ private static final long serialVersionUID = 6781939984242527498L;
+
+
+ public AttributeMetadataImplMap(List<String> langs) {
+ super(langs);
+ }
+
+ public AttributeMetadataImplMap() {
+ super();
+ }
+
+ /**
+ * Returns a deep-copy. @see {@link Copyable} interface
+ */
+ @Override
+ public AttributeMetadataImplMap copy() {
+ final AttributeMetadataImplMap copy = new AttributeMetadataImplMap(langs);
+ return (AttributeMetadataImplMap) copyTo(copy);
+ }
+
+
+ /**
+ * Returns the {@link AttributeMetadataImpl} for a given {@link Name}. Never returns
+ * <code>null</code>, but rather creates a default {@link AttributeMetadataImpl} on the
+ * fly.
+ */
+ @Override
+ public AttributeMetadataImpl get(final Name name) {
+ final AttributeMetadataImpl AttributeMetadataImpl = super.get(name);
+ if (AttributeMetadataImpl == null && name != null
+ && !name.getLocalPart().trim().isEmpty()) {
+
+ put(name, new AttributeMetadataImpl(name, langs));
+
+ return super.get(name);
+ }
+ return AttributeMetadataImpl;
+ }
+
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,122 @@
+package de.schmitzm.geotools.data.amd;
+
+import java.util.HashSet;
+
+import org.opengis.feature.type.Name;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.i8n.Translation;
+
+public interface AttributeMetadataInterface extends Copyable<AttributeMetadataInterface>,
+ Comparable<AttributeMetadataInterface> {
+
+ /**
+ * @return a translatable title for this attribute..
+ */
+ public Translation getTitle();
+
+ /**
+ * Set a translatable title for this attribute..
+ */
+ public void setTitle(Translation title);
+
+ /**
+ * Set an untranslated title for this attribute or pass a {@link Translation} encryped as a {@link String}
+ */
+ public void setTitle(String title);
+
+ /**
+ * @return a translatable description for this attribute
+ */
+ public Translation getDesc();
+
+ /**
+ * Set a translatable description for this attribute.
+ */
+ public void setDesc(Translation desc);
+
+ /**
+ * Set an untranslated description for this attribute or pass a {@link Translation} encryped as a {@link String}
+ */
+ public void setDesc(String desc);
+
+
+ /**
+ * The local name. E.g. the name of the DBF column as a {@link String}.
+ */
+ public String getLocalName();
+
+ /**
+ * A short form for #setName(new NameImpl(localName))
+ */
+ public void setLocalName(String localName);
+
+ /**
+ * The fully qualified {@link Name} of the attribute, e.g.
+ * <code>org.bla.plo:blub</code>. The second part equals the
+ * {@link #getLocalName()} value. The first may be <code>null</code> or
+ * represent the layer name.
+ */
+ public Name getName();
+
+ /**
+ * set the fully qualified {@link Name} of this attribute.
+ */
+ public void setName(Name name);
+
+ /**
+ * A list og objects that represent NODATA-values for this attribute. The
+ * objects are supporsed to be correctly casted already. That means that the
+ * NODATA objects listed here have must have the same type as the values of
+ * this object.
+ */
+ public HashSet<Object> getNodataValues();
+
+ /**
+ * Takes any value object and checks it against the NODATA values. If the
+ * value equals a NODATA value, <code>null</code> is returned. Otherwise the
+ * same object is returned.
+ *
+ * Note: This method is called often.
+ */
+ public Object fiterNodata(Object value);
+
+ /**
+ * @return a non-translatable unit {@link String} for this attribute values.
+ */
+ public String getUnit();
+
+ /**
+ * Set a unit {@link String} for this attribute values.
+ */
+ public void setUnit(String unit);
+
+ /**
+ * @return A value defining the position of this attribute whenever the
+ * attributes are listed to an end-user. The higher the weight, the
+ * lower the position. (heavy goes down, light goes up)
+ */
+ public double getWeight();
+
+ /**
+ * set a value defining the position of this attribute whenever the
+ * attributes are listed to an end-user. The higher the weight, the lower
+ * the position. (heavy goes down, light goes up)
+ */
+ public void setWeight(double weight);
+
+ /**
+ * @return <code>false</code> if this attribute should not be selectable or
+ * shown to the end-user.
+ */
+ public boolean isVisible();
+
+ /**
+ * Set <code>false</code> if this attribute should not be shown to the
+ * end-user.
+ */
+ public void setVisible(boolean visible);
+
+ String getNoDataValuesFormatted();
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,176 @@
+package de.schmitzm.geotools.data.amd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.Name;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.geotools.data.QualityQuantizable;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * The {@link AttributeMetadataMap} is a {@link Map} holding {@link AMD_IMPL}
+ * object for {@link Name} keys. It's an extension of a {@link TreeMap}. It's
+ * copyable in the sense of the {@link Copyable} interface.<br>
+ * The {@link #get(Name)} and {@link #get(String)} methods will never return
+ * <code>null</code>, but rather create a default {@link AMD_IMPL} on-the-fly.
+ */
+public abstract class AttributeMetadataMap<AMD_IMPL extends AttributeMetadataInterface>
+ extends TreeMap<Name, AMD_IMPL> implements
+ Copyable<AttributeMetadataMap>, QualityQuantizable {
+
+ private static final long serialVersionUID = 4936966916517396063L;
+
+ protected static final Logger LOGGER = Logger
+ .getLogger(AttributeMetadataMap.class);
+
+ /**
+ * A list of default languages used when creating default {@link AMD_IMPL}
+ * on-the-fly. If not initialized by a constructor, it will be
+ * {@link Translation#getActiveLang()} only.
+ **/
+ protected final List<String> langs;
+
+ /**
+ * AttributeMetadataMap is based on {@link Translation} and would like to
+ * know how many languages are supported, so the needed defaults can be
+ * created.<br/>
+ * If you use this constructor, it will be initialized to only use one
+ * language, which is {@link Translation.getActiveLang()}.
+ */
+ public AttributeMetadataMap() {
+ langs = new ArrayList<String>();
+ langs.add(Translation.getActiveLang());
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataMap} and sets the list of default
+ * languages.
+ */
+ public AttributeMetadataMap(final List<String> defLanguages) {
+ langs = defLanguages;
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataMap} and sets the list of default
+ * languages.
+ */
+ public AttributeMetadataMap(final String[] langs) {
+ this.langs = new ArrayList<String>(java.util.Arrays.asList(langs));
+ }
+
+ /**
+ * Copies all its values to another {@link AttributeMetadataMap}. @see
+ * {@link Copyable} interface.
+ */
+ @Override
+ public AttributeMetadataMap<? extends AttributeMetadataInterface> copyTo(AttributeMetadataMap amdMap) {
+
+ amdMap.clear();
+
+ for (final Name key : keySet()) {
+ final AMD_IMPL AMD_IMPL = get(key);
+ amdMap.put(key, AMD_IMPL.copy());
+ }
+ return amdMap;
+ }
+
+ /**
+ * Returns the {@link AMD_IMPL} for a given {@link NameImpl}. May return
+ * <code>null</code> or create a default {@link AttributeMetadataInterface} depending
+ * on whether this method is overwritten. fly.
+ */
+ public AMD_IMPL get(final Name name) {
+ return super.get(name);
+ }
+
+ /**
+ * @Deprecated use get(Name name) or get(String localName)
+ */
+ @Deprecated
+ @Override
+ public AMD_IMPL get(final Object key) {
+ LOGGER.error("PLEASE DONT USE get(Object) any MORE!");
+ return super.get(key);
+ }
+
+ /**
+ * Returns the {@link AMD_IMPL} for a given {@link Name}. Never returns
+ * <code>null</code>, but rather creates a default {@link AMD_IMPL} on the
+ * fly.
+ */
+ public AMD_IMPL get(final String localName) {
+ if (localName == null)
+ return null;
+ return this.get(new NameImpl(localName));
+ }
+
+ public List<String> getLanguages() {
+ return langs;
+ }
+
+ /**
+ * @return a number between 0. (bad) and 1. (good) that is calculated from
+ * the amount of translation available in the visible attributes
+ */
+ @Override
+ public double getQuality(final List<String> languages) {
+ int allVisible = 0;
+ double colQmSum = 0.;
+ for (final AMD_IMPL oneCol : values()) {
+
+ if (oneCol.isVisible() && oneCol instanceof QualityQuantizable) {
+ allVisible++;
+ colQmSum += ((QualityQuantizable) oneCol).getQuality(languages);
+ }
+ }
+
+ if (allVisible > 0)
+ return colQmSum / allVisible;
+ else
+ return 1.;
+
+ }
+
+ /**
+ * @return List of {@link AMD_IMPL} objects ordered by their weight.
+ * (heavier => further down)
+ */
+ public List<AMD_IMPL> sortedValues() {
+ final List<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
+ final Collection<AMD_IMPL> values = values();
+ list.addAll(values);
+ Collections.sort(list);
+ return list;
+ }
+
+ /**
+ * @return List of only the visible {@link AMD_IMPL} objects ordered by
+ * their weight. (heavier => further down)
+ */
+ public List<AMD_IMPL> sortedValuesVisibleOnly() {
+ final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
+ for (final AMD_IMPL atm : sortedValues()) {
+ if (atm.isVisible())
+ list.add(atm);
+ }
+ return list;
+ }
+
+ /**
+ * Just for debuggung. Simply returns {@code super.put(.)}.
+ * TODO: remove this method.
+ */
+ @Override
+ public AMD_IMPL put(Name key, AMD_IMPL value) {
+ return super.put(key, value);
+ };
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.data.rld;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.geometry.Envelope2D;
+import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.geotools.GTUtil;
+import de.schmitzm.geotools.grid.GridUtil;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * Holds all the additional information needed to paint a Legend for a
+ * RasterLayer. So far, only Legends for one-band raster layers are supported.
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ *
+ * TODO implements {@link Copyable}
+ */
+public class RasterLegendData extends TreeMap<Double, Translation> implements
+ Copyable<RasterLegendData> {
+ static private final Logger LOGGER = Logger
+ .getLogger(RasterLegendData.class);
+
+ private Boolean paintGaps = false;
+
+ /**
+ * Shall bigger gaps be painted between the raster images
+ */
+ public Boolean isPaintGaps() {
+ return paintGaps;
+ }
+
+ public void setPaintGaps(boolean paintPaps) {
+ this.paintGaps = paintPaps;
+ }
+
+ /**
+ * {@link #paintGaps} defines, if gaps should be painted between the legends
+ * colors, indicating nominal values in the raster (e.g. classifications)
+ */
+ public RasterLegendData(boolean paintGaps) {
+ this.paintGaps = paintGaps;
+ }
+
+ /**
+ * Returns a new list containing all {@link Double} values that shall apear
+ * in the legend.
+ */
+ public List<Double> getSortedKeys() {
+ Double[] array = keySet().toArray(new Double[] {});
+
+ Arrays.sort(array);
+
+ final LinkedList<Double> linkedList = new LinkedList<Double>();
+ for (Double o : array) {
+ linkedList.add(o);
+ }
+
+ return linkedList;
+ }
+
+ /**
+ * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each legend
+ * value. These rasters can be used to do visualize the legend item in the
+ * corresponding color via {@link GridCoverageRenderer}.
+ */
+ public Map<Double, GridCoverage2D> createSampleRasters() {
+ Map<Double, GridCoverage2D> sampleRaster = new HashMap<Double, GridCoverage2D>();
+
+ for (Double rasterValue : keySet()) {
+ GridCoverage2D grid = GridUtil.GRID_FAC.create("Legend_"
+ + rasterValue,
+ new float[][] { { rasterValue.floatValue() } },
+ new Envelope2D(GTUtil.WGS84, 0, 0, 1, 1));
+ sampleRaster.put(rasterValue, grid);
+ }
+ return sampleRaster;
+ }
+
+ /**
+ * Creates a new {@link RasterLegendData} object with identical values
+ */
+ @Override
+ public RasterLegendData copy() {
+ RasterLegendData copy = (RasterLegendData) super.clone();
+ return copyTo(copy);
+ }
+
+ /**
+ * Deep-copies all values of this {@link RasterLegendData} to another
+ * {@link RasterLegendData}
+ */
+ @Override
+ public RasterLegendData copyTo(RasterLegendData target) {
+ target.clear();
+
+ target.setPaintGaps(isPaintGaps());
+
+ for (Double o : keySet()) {
+ target.put(new Double(o), get(o).copy());
+ }
+
+ return target;
+ }
+}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -119,7 +119,7 @@
import de.schmitzm.geotools.FilterUtil;
import de.schmitzm.geotools.GTUtil;
-import de.schmitzm.geotools.StyledFeaturesInterface;
+import de.schmitzm.geotools.styling.StyledFeaturesInterface;
import de.schmitzm.io.IOUtil;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.lang.ResourceProvider;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -27,14 +27,14 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
-import de.schmitzm.geotools.StyledFeaturesInterface;
-import de.schmitzm.geotools.data.AttributeMetaDataAttributeTypeFilter;
-import de.schmitzm.geotools.data.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.AttributeMetadataInterface;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
+import de.schmitzm.geotools.data.amd.AttributeMetaDataAttributeTypeFilter;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
import de.schmitzm.geotools.feature.CQLFilterParser;
import de.schmitzm.geotools.feature.FeatureTypeTableModel;
import de.schmitzm.geotools.feature.FilterParser;
+import de.schmitzm.geotools.styling.StyledFeaturesInterface;
import de.schmitzm.i8n.I8NUtil;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.SwingUtil;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -69,11 +69,11 @@
import de.schmitzm.geotools.FilterUtil;
import de.schmitzm.geotools.gui.MapPaneToolBar;
-import de.schmitzm.geotools.StyledFeaturesInterface;
import de.schmitzm.geotools.gui.SelectableXMapPane;
import de.schmitzm.geotools.gui.XMapPaneEvent;
import de.schmitzm.geotools.map.event.FeatureSelectedEvent;
import de.schmitzm.geotools.map.event.JMapPaneListener;
+import de.schmitzm.geotools.styling.StyledFeaturesInterface;
import de.schmitzm.geotools.styling.StylingUtil;
import de.schmitzm.geotools.styling.StylingUtil.SelectionStylesTypes;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledFeatureLayerSelectionModel.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledFeatureLayerSelectionModel.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledFeatureLayerSelectionModel.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -45,10 +45,10 @@
import org.opengis.feature.simple.SimpleFeature;
-import de.schmitzm.geotools.StyledFeatureCollectionInterface;
-import de.schmitzm.geotools.StyledFeatureSourceInterface;
-import de.schmitzm.geotools.StyledFeaturesInterface;
-import de.schmitzm.geotools.StyledLayerInterface;
+import de.schmitzm.geotools.styling.StyledFeatureCollectionInterface;
+import de.schmitzm.geotools.styling.StyledFeatureSourceInterface;
+import de.schmitzm.geotools.styling.StyledFeaturesInterface;
+import de.schmitzm.geotools.styling.StyledLayerInterface;
/**
* This manager holds a set of {@link SimpleFeature Features} which are <i>selected</i>
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledLayerSelectionModel.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledLayerSelectionModel.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/selection/StyledLayerSelectionModel.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -54,7 +54,7 @@
import org.apache.log4j.Logger;
import org.opengis.feature.simple.SimpleFeature;
-import de.schmitzm.geotools.StyledLayerInterface;
+import de.schmitzm.geotools.styling.StyledLayerInterface;
import de.schmitzm.swing.event.PropertyChangeEmitter;
/**
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import javax.swing.ImageIcon;
+
+import org.apache.log4j.Logger;
+import org.geotools.styling.Style;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.schmitzm.i8n.Translation;
+import de.schmitzm.lang.LangUtil;
+
+/**
+ * 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 layer.
+ * @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 layer.
+ * @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 layer 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();
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,431 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Date;
+import java.util.Random;
+
+import javax.swing.ImageIcon;
+import javax.swing.JPanel;
+
+import org.apache.log4j.Logger;
+import org.geotools.data.FeatureSource;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.styling.Style;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.schmitzm.geotools.MapContextManagerInterface;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.feature.FeatureUtil;
+import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+import de.schmitzm.geotools.io.GeoImportUtil;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * This class enables a non Atlas context to use the Atlas LayerPanel
+ * {@link JPanel} as a {@link MapContextManagerInterface}
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ *
+ * TODO Rename to StyledShapefile
+ */
+public class StyledFS implements StyledFeatureSourceInterface {
+ private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
+
+ private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
+
+ /** Caching the CRS of the layer **/
+ CoordinateReferenceSystem crs = null;
+
+ /**
+ * A unique ID which identifies the Layer in the Atlas. It's more important
+ * than it should be ;-)
+ */
+ final private String id;
+
+ private Style style;
+
+ private Translation title;
+
+ private Translation desc;
+
+ private File sldFile;
+
+ /** A map of simple attribute names to their meta-data **/
+ private AttributeMetadataMap<AttributeMetadataImpl> attMap;
+
+ private Filter filter = Filter.INCLUDE;
+
+ /**
+ * This class enables a non Atlas context to use the Atlas LayerPanel
+ * {@link JPanel} as a {@link MapContextManagerInterface}
+ *
+ * @param fs
+ * {@link FeatureSource} that is beeing styled.
+ *
+ * @param sldFile
+ * may be <code>null</code>. Otherwise the SLD {@link File} to
+ * import and associate with this {@link StyledFS}
+ *
+ * @param id
+ * <code>null</code> is allowed and will autogenerate an id
+ */
+ public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
+ File sldFile, String id) {
+
+ this.fs = fs;
+
+ if (id == null) {
+ this.id = StyledFS.class.getSimpleName()
+ + new Random(new Date().getTime()).nextInt(10000000);
+ } else {
+ this.id = id;
+ }
+
+ this.sldFile = sldFile;
+
+ // datei existiert, dann lesen
+ if (sldFile != null && sldFile.exists()) {
+ try {
+ style = StylingUtil.loadSLD(sldFile)[0];
+ } catch (Exception e) {
+ LOGGER.warn("Reading SLD failed: " + sldFile, e);
+ style = null;
+ }
+ }
+
+ title = new Translation();
+ desc = new Translation();
+
+ if (sldFile != null) {
+ title.fromOneLine(sldFile.getName());
+ desc.fromOneLine(sldFile.getAbsolutePath());
+ }
+
+ }
+
+ public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
+ this(fs, (File) null, null);
+ }
+
+ public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
+ String id) {
+ this(fs, null, id);
+ }
+
+ public void dispose() {
+ }
+
+ /**
+ * Returns human readable {@link String} of the CRS natively used by this
+ * {@link DpLayer}
+ *
+ * If CRS == null, it will call {@link #getGeoObject()}
+ *
+ */
+ public String getCRSString() {
+ if (getCrs() == null)
+ return "CRS?";
+
+ return getCrs().getName().getCode();
+ }
+
+ public CoordinateReferenceSystem getCrs() {
+ if (crs == null) {
+ crs = fs.getSchema().getCoordinateReferenceSystem();
+ if (crs == null) {
+
+ crs = fs.getSchema().getGeometryDescriptor()
+ .getCoordinateReferenceSystem();
+
+ if (crs == null) {
+ LOGGER.warn("Could not determine the CRS of " + getTitle()
+ + ". Using default "
+ + GeoImportUtil.getDefaultCRS());
+ crs = GeoImportUtil.getDefaultCRS();
+ }
+ }
+ }
+ return crs;
+ }
+
+ public Translation getDesc() {
+ return desc;
+ }
+
+ public Envelope getEnvelope() {
+ try {
+ return fs.getBounds();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public FeatureSource<SimpleFeatureType, SimpleFeature> getGeoObject() {
+ return fs;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public ImageIcon getImageIcon() {
+ return null;
+ }
+
+ public URL getInfoURL() {
+ return null;
+ }
+
+ public Translation getKeywords() {
+ return null;
+ }
+
+ public Style getStyle() {
+ return style;
+ }
+
+ public Translation getTitle() {
+ return title;
+ }
+
+ public boolean isDisposed() {
+ return false;
+ }
+
+ /**
+ * If true, this layer will not be shown in the legend. Default = false
+ */
+ /**
+ *
+ * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
+ * verstecken/nicht verstecken gestellt werden können. Das sind
+ * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
+ * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
+ * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
+ * die Funktion genutzt.
+ *
+ * // public boolean isHideInLegend() { // return false; // }
+ */
+
+ public void setDesc(Translation dec) {
+ this.desc = dec;
+ }
+
+ public void setImageIcon(ImageIcon icon) {
+ }
+
+ public void setKeywords(Translation keywords) {
+ }
+
+ public void setStyle(Style style) {
+ this.style = style;
+
+ }
+
+ public void setTitle(Translation title) {
+ this.title = title;
+
+ }
+
+ public void uncache() {
+ }
+
+ /**
+ *
+ */
+ @Override
+ public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() {
+ if (attMap == null) {
+ attMap = StyledLayerUtil
+ .createDefaultAttributeMetadataMap(getSchema());
+ }
+ return attMap;
+ }
+
+ /**
+ * @return The {@link File} where the SLD was loaded from or
+ * <code>null</code> if there didn't exist a {@link File}.
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+ public File getSldFile() {
+ return sldFile;
+ }
+
+ /**
+ * Associates this .sld with the {@link FeatureSource}, but does not
+ * automatically load the file. It must not even exist.
+ *
+ * @param sldFile
+ */
+ public void setSldFile(File sldFile) {
+ this.sldFile = sldFile;
+ }
+
+ /**
+ * Returns the features of the {@link FeatureSource}.
+ *
+ * @see {@link StyledFeaturesInterface}
+ */
+ @Override
+ public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
+ FeatureCollection<SimpleFeatureType, SimpleFeature> features;
+ try {
+ features = getGeoObject().getFeatures();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Error getting the features of the FeatureSource");
+ }
+ return features;
+ }
+
+ /**
+ * Same as {@link #getGeoObject()} method, but complies to the
+ * {@link StyledFeaturesInterface}
+ *
+ * @see {@link StyledFeaturesInterface}
+ */
+ @Override
+ public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
+ return getGeoObject();
+ }
+
+ @Override
+ public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
+ // final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
+ // getFeatureCollection();
+ // if (filter == Filter.EXCLUDE)
+ // return new EmptyFeatureCollection(fc.getSchema());
+ // if (filter == Filter.INCLUDE)
+ // return fc;
+ // return fc.subCollection(filter);
+
+ try {
+ if (filter != Filter.INCLUDE)
+ return getFeatureSource().getFeatures(filter);
+ else
+ return getFeatureSource().getFeatures();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public Filter getFilter() {
+ return filter;
+ }
+
+ @Override
+ public void setFilter(Filter filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ public SimpleFeatureType getSchema() {
+ return getGeoObject().getSchema();
+ }
+
+ /**
+ * Tries to load a style from the file denoted in {@link #getSldFile()}. If
+ * the file doesn't exits, return <code>null</code>;
+ *
+ * @return <code>true</code> is style was loaded
+ */
+ public boolean loadStyle() {
+ if (getSldFile() == null)
+ return false;
+
+ try {
+ Style[] loadSLD = StylingUtil.loadSLD(getSldFile());
+ setStyle(loadSLD[0]);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+
+ }
+
+ public void setTitle(String title) {
+ setTitle(new Translation(title));
+ }
+
+ public void setDesc(String desc) {
+ setDesc(new Translation(desc));
+ }
+
+ public void setCRS(CoordinateReferenceSystem crs2) {
+ crs = crs2;
+ }
+
+ @Override
+ public ReferencedEnvelope getReferencedEnvelope() {
+ return new ReferencedEnvelope(getEnvelope(), getCrs());
+ }
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+ private GeometryForm geometryForm;
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+
+ @Override
+ public GeometryForm getGeometryForm() {
+ if (geometryForm == null) {
+ geometryForm = FeatureUtil.getGeometryForm(getSchema());
+ }
+ return geometryForm;
+ }
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+ public void setGeometryForm(GeometryForm geometryForm) {
+ this.geometryForm = geometryForm;
+ }
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,477 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.geotools.data.FeatureSource;
+import org.geotools.data.collection.CollectionDataStore;
+import org.geotools.data.store.EmptyFeatureCollection;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
+import org.geotools.feature.collection.SubFeatureCollection;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.styling.Style;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.filter.Filter;
+
+import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.feature.FeatureUtil;
+import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * 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.
+ *
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class StyledFeatureCollection
+ extends
+ AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>>
+ implements StyledFeatureCollectionInterface {
+
+ /** Holds the meta data for displaying a legend. */
+ protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaData = null;
+
+ /**
+ * We be filled with a "virtual" {@link FeatureSource} on demand.
+ */
+ private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
+
+ /**
+ * A Filter that will be applied internally applied to this
+ * FeatureCollection
+ **/
+ private Filter filter = Filter.INCLUDE;
+
+ /**
+ * Creates a styled {@link FeatureCollection} with language-specific
+ * informations.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the 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 (if {@code null}, a default style is created)
+ * @param attrMetaData
+ * meta data for displaying a legend
+ * @param icon
+ * an icon for the object (can be {@code null})
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ Translation title, Translation desc, Translation keywords,
+ Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) {
+ super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
+ .getCoordinateReferenceSystem(), id, title, desc, keywords,
+ style, icon);
+ setAttributeMetaData(attrMetaData);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with language-specific
+ * informations.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the 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 with attribute meta data information
+ * @param icon
+ * an icon for the object (can be {@code null})
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ Translation title, Translation desc, Translation keywords,
+ StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
+ super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
+ .getCoordinateReferenceSystem(), id, title, desc, keywords,
+ style != null ? style.getGeoObjectStyle() : null, icon);
+ setAttributeMetaData(style != null ? style.getMetaData() : null);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with a language-specific
+ * title, no long description, no keywords, default attribute meta data and
+ * no icon.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ Translation title, Style style) {
+ this(fc, id, title, null, null, style, null, null);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with non-translated
+ * informations.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @param attrMetaData
+ * meta data for displaying a legend
+ * @param icon
+ * an icon for the object (can be {@code null})
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ String title, String desc, String keywords, Style style,
+ AttributeMetadataMap attrMetaData, ImageIcon icon) {
+ this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
+ setTitle(title);
+ setDesc(desc);
+ setKeywords(keywords);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with non-translated
+ * informations.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style with attribute meta data information
+ * @param icon
+ * an icon for the object (can be {@code null})
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ String title, String desc, String keywords,
+ StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
+ this(fc, id, title, desc, keywords, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, icon);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with a non-translated title,
+ * no long description, no keywords, default attribute meta data and no
+ * icon.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ String title, Style style) {
+ this(fc, id, title, null, null, style, null, null);
+ }
+
+ /**
+ * Creates a styled {@link FeatureCollection} with a non-translated title,
+ * no long description, no keywords, default attribute meta data and no
+ * icon.
+ *
+ * @param fc
+ * the {@link FeatureCollection}
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
+ */
+ public StyledFeatureCollection(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
+ String title, StyledLayerStyle<AttributeMetadataMap> style) {
+ this(fc, id, title, null, null, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, null);
+ }
+
+ /**
+ * Creates a default style for the {@link FeatureCollection}.
+ *
+ * @see FeatureUtil#createDefaultStyle(FeatureCollection)
+ */
+ protected Style createDefaultStyle() {
+ return FeatureUtil.createDefaultStyle(geoObject);
+ }
+
+ /**
+ * Returns the meta data needed for displaying a legend.
+ */
+ public AttributeMetadataMap getAttributeMetaDataMap() {
+ return attrMetaData;
+ }
+
+ /**
+ * Sets the meta data needed for displaying a legend. If {@code legendData}
+ * is {@code null} an empty map is set, so
+ * {@link #getAttributeMetaDataMap()} never returns {@code null}.
+ *
+ * @param attrMetaData
+ * map of attribute meta data
+ */
+ public void setAttributeMetaData(AttributeMetadataMap attrMetaData) {
+ this.attrMetaData = (attrMetaData != null) ? attrMetaData
+ : createDefaultAttributeMetaDataMap(geoObject);
+ }
+
+ /**
+ * Creates non-translated default meta data for a {@link FeatureCollection}
+ * with all attributes visible and no unit set.
+ *
+ * @param fc
+ * a {@link FeatureCollection}
+ */
+ public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
+ AttributeMetadataMap metaDataMap = new AttributeMetadataImplMap();
+ SimpleFeatureType ftype = fc.getSchema();
+ for (int i = 0; i < ftype.getAttributeCount(); i++) {
+ AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
+ if (!FeatureUtil.isGeometryAttribute(aDesc))
+ metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl(
+ new NameImpl(aDesc.getName().getNamespaceURI(), aDesc
+ .getName().getLocalPart()), true, // visible
+ new Translation(aDesc.getLocalName()), // Column name
+ new Translation(aDesc.getLocalName()), // description
+ "" // Unit
+ ));
+ }
+ return metaDataMap;
+ }
+
+ /**
+ * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
+ * {@link #attrMetaData} to {@code null}.
+ */
+ public void dispose() {
+ this.geoObject = null;
+ this.envelope = null;
+ this.crs = null;
+ this.attrMetaData = null;
+ }
+
+ /**
+ * Tests whether the geo object is disposed.
+ */
+ public boolean isDisposed() {
+ return geoObject == null;
+ }
+
+ /**
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
+ * objects (in memory) which can not be uncached and reloaded.
+ */
+ public void uncache() {
+
+ /** It will be recreated on the next getFetureSource() **/
+ featureSource = null;
+
+ LOGGER.warn("Uncache onyl uncached any virtual FeatureSource. Object remains in memory.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
+ */
+ public URL getInfoURL() {
+ return null;
+ }
+
+ /**
+ * Same as {@link #getGeoObject()} method, but complies to the
+ * {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT
+ * automatically applied.
+ *
+ * @see {@link StyledFeaturesInterface}
+ * @see #getFeatureCollectionFiltered()
+ */
+ @Override
+ public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
+ return getGeoObject();
+ }
+
+ /**
+ * Same as {@link #getGeoObject()} method, but complies to the
+ * {@link StyledFeaturesInterface}. The associated {@link Filter} is
+ * automatically applied by creating a {@link SubFeatureCollection}.
+ *
+ * @see {@link StyledFeaturesInterface}
+ * @see #getFeatureCollectionFiltered()
+ */
+ @Override
+ public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
+ final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
+ if (filter == Filter.EXCLUDE)
+ return new EmptyFeatureCollection(fc.getSchema());
+ if (filter == Filter.INCLUDE)
+ return fc;
+ return fc.subCollection(filter);
+ }
+
+ /**
+ * Returns a virtual {@link FeatureSource} to access the
+ * {@link FeatureCollection}. Once created, it will be reused until
+ * {@link #uncache()} is called.<br/>
+ *
+ * @see {@link StyledFeaturesInterface}
+ */
+ @Override
+ public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
+ if (featureSource == null) {
+ CollectionDataStore store = new CollectionDataStore(getGeoObject());
+ try {
+ featureSource = store.getFeatureSource(store.getTypeNames()[0]);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Could not create a FeatureSource from the CollectionDataStore:",
+ e);
+ }
+ }
+ return featureSource;
+ }
+
+ @Override
+ public Filter getFilter() {
+ return filter;
+ }
+
+ @Override
+ public void setFilter(Filter filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ public SimpleFeatureType getSchema() {
+ return getGeoObject().getSchema();
+ }
+
+ @Override
+ public ReferencedEnvelope getReferencedEnvelope() {
+ return new ReferencedEnvelope(getEnvelope(), getCrs());
+ }
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+ private GeometryForm geometryForm;
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+
+ @Override
+ public GeometryForm getGeometryForm() {
+ if (geometryForm == null) {
+ geometryForm = FeatureUtil.getGeometryForm(getSchema());
+ }
+ return geometryForm;
+ }
+
+ /**
+ * Defaults to the GeometryForm determined with FeatureUtil.getGeometryForm,
+ * but can be set to override ANY.
+ */
+ public void setGeometryForm(GeometryForm geometryForm) {
+ this.geometryForm = geometryForm;
+ }
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import org.geotools.feature.FeatureCollection;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+/**
+ * {@link StyledLayerInterface} which contains a {@link FeatureCollection} as geo object.<br>
+ */
+public interface StyledFeatureCollectionInterface extends StyledFeaturesInterface<FeatureCollection<SimpleFeatureType, SimpleFeature>> {
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionTableModel.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollectionTableModel.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.geotools.data.DefaultQuery;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.Query;
+import org.geotools.feature.FeatureCollection;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.Name;
+import org.opengis.filter.Filter;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.feature.FeatureUtil;
+import de.schmitzm.geotools.gui.FeatureCollectionTableModel;
+
+/**
+ * This class extends the the {@link FeatureCollectionTableModel} with the
+ * functionalities of the {@link AttributeMetadataImpl}.
+ * <ul>
+ * <li>column names are translated according to
+ * {@link AttributeMetadataImpl#getTitle()}</li>
+ * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
+ * <li>Any filter defined in the {@link StyledFeaturesInterface} will be
+ * applied.</li>
+ * </ul>
+ *
+ * @author Stefan A. Tzeggai
+ */
+public class StyledFeatureCollectionTableModel extends
+ FeatureCollectionTableModel {
+ final static private Logger LOGGER = Logger
+ .getLogger(StyledFeatureCollectionTableModel.class);
+ /**
+ * Contains the complete {@link AttributeMetadataImpl}-Map of the styled
+ * layer.
+ */
+ protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null;
+ /** Holds the current filter on the table */
+ protected Filter filter = null;
+ /** Holds the Bounds for all features. Only set once during the constructor **/
+ protected Envelope bounds;
+ /**
+ * Tooltips für die Spaltennamen. Wird nur beim Aufruf von
+ * {@link #reorganize} befuellt.
+ */
+ protected String[] colTooltips = null;
+
+ /**
+ * A cache for the #sortedValuesVisibleOnly(). WHen the amd is changed
+ * externally, this object will stay the same
+ **/
+ protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null;
+
+ /**
+ * Creates a new table model for a styled layer.
+ *
+ * @param styledFeatures
+ * the styled layer
+ * @param filter
+ * filter applied to the table
+ */
+ public StyledFeatureCollectionTableModel(
+ StyledFeaturesInterface<?> styledFeatures) {
+ setStyledFeatures(styledFeatures);
+ }
+
+ /**
+ * This overwritten method filters the values for NODATA-values defined in
+ * the {@link AttributeMetadataImpl}
+ */
+ @Override
+ public Object getValueAt(int row, int col) {
+ Object rawValue = super.getValueAt(row, col);
+ return amdMapVisibleOnly.get(col).fiterNodata(rawValue);
+ }
+
+ /**
+ * Sets a new data source for the table.
+ *
+ * @param fs
+ * the feature source
+ * @param amdm
+ * {@link AttributeMetadataImpl}-Map to define the visible
+ * attributes and translation
+ */
+ protected void setFeatureSource(
+ FeatureSource<SimpleFeatureType, SimpleFeature> fs,
+ AttributeMetadataMap<? extends AttributeMetadataInterface> amdm,
+ Filter filter) throws Exception {
+
+ if (filter == null)
+ filter = Filter.INCLUDE;
+
+ // this.featureSource = fs;
+ this.filter = filter;
+ this.amdMap = amdm;
+ this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
+
+ FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
+ if (fs != null) {
+
+ bounds = fs.getBounds();
+
+ final SimpleFeatureType schema = fs.getSchema();
+ Query query = new DefaultQuery(schema.getTypeName(), filter);
+ if (amdm != null) {
+ LinkedHashSet<String> visibleAttrNames = new LinkedHashSet<String>();
+
+ // Add the column with the geometry (usually "the_geom") always
+ visibleAttrNames.add(schema.getGeometryDescriptor()
+ .getLocalName());
+
+ // Add other visible attributes as ordered by weights
+ for (AttributeMetadataInterface a : amdMapVisibleOnly) {
+ visibleAttrNames.add(a.getLocalName());
+ }
+
+ // Tested with 2.6.x trunk from 2009-11-26 and it now works. So
+ // we only request the properties we need!
+ // /**
+ // * I got NPEs when properties contained only [the_geom]
+ // ?!??!!??
+ // */
+ // if (properties.length > 1) {
+ query = new DefaultQuery(schema.getTypeName(), filter,
+ visibleAttrNames.toArray(new String[] {}));
+ // } else {
+ // query = new DefaultQuery(schema.getTypeName(), filter);
+ // }
+ }
+ fc = fs.getFeatures(query);
+ }
+ setFeatureCollection(fc);
+ }
+
+ /**
+ * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
+ * and sets this as the new data source for the table.
+ *
+ * @param fs
+ * the feature source
+ * @param amd
+ * {@link AttributeMetadataImpl}-Map to define the visible
+ * attributes and translation
+ */
+ public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
+ try {
+ if (styledFeatures == null)
+ setFeatureSource(null, null, null);
+ else {
+ setFeatureSource(styledFeatures.getFeatureSource(),
+ styledFeatures.getAttributeMetaDataMap(),
+ styledFeatures.getFilter());
+ }
+ } catch (Exception err) {
+ throw new RuntimeException(err);
+ }
+ }
+
+ /**
+ * After calling {@code super.reorganize(.)} this method replaced the column
+ * descriptions with the titles of the {@code AttributeMetaData}.
+ *
+ * @param fireTableStructureChanged
+ * indicates whether a table event is initiated after reorganize
+ */
+ @Override
+ protected void reorganize(boolean fireTableStructureChanged) {
+
+ featureArray = FeatureUtil.featuresToArray(featureTable);
+ if (featureArray == null || featureArray.length == 0) {
+ colNames = new String[0];
+ colTooltips = new String[0]; // Only set and used in
+ // StyledFeatureCollectionTableModel
+ colClass = new Class[0];
+ } else {
+ // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
+ SimpleFeatureType schema = featureArray[0].getFeatureType();
+ // Pruefen, welche Attribute angezeigt werden
+ attrTypes.clear();
+ for (AttributeMetadataInterface amd : amdMapVisibleOnly) {
+ Name name = amd.getName();
+ AttributeDescriptor type = schema.getDescriptor(name);
+ // if type can not be determined by complete name,
+ // try only the local name
+ if (type == null)
+ type = schema.getDescriptor(name.getLocalPart());
+ if (attrFilter == null || attrFilter.accept(type))
+ attrTypes.add(type);
+ }
+ // Namen und Attribut-Indizes der angezeigten Spalten ermitteln
+ colNames = new String[attrTypes.size()];
+ colTooltips = new String[attrTypes.size()]; // Only set and used in
+ // StyledFeatureCollectionTableModel
+ colClass = new Class[attrTypes.size()];
+ attrIdxForCol = new int[attrTypes.size()];
+ for (int i = 0; i < colNames.length; i++) {
+ Name name = amdMapVisibleOnly.get(i).getName();
+ AttributeDescriptor descriptor = schema.getDescriptor(name);
+ // if type can not be determined by complete name,
+ // try only the local name
+ if (descriptor == null)
+ descriptor = schema.getDescriptor(name.getLocalPart());
+
+ // Not so nice in 26: find the index of an attribute...
+ int idx = schema.getAttributeDescriptors().indexOf(descriptor);
+ attrIdxForCol[i] = idx;
+
+ String attName = schema.getAttributeDescriptors().get(idx)
+ .getLocalName();
+ colNames[i] = amdMap.get(attName).getTitle().toString();
+ AttributeMetadataInterface amd = amdMap.get(attName);
+ colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
+ + amd.getName() + "</html>";
+ colClass[i] = schema.getAttributeDescriptors().get(idx)
+ .getType().getBinding();
+ }
+ }
+
+ // store feature indexes in HashMap to optimize findFeature(.)
+ featureIdx = new HashMap<String, Integer>();
+ for (int i = 0; i < featureArray.length; i++)
+ if (featureArray[i] != null)
+ featureIdx.put(featureArray[i].getID(), i);
+ //
+ // // translate the column names
+ // if (amdMap != null) {
+ // for (int i = 0; i < colNames.length; i++) {
+ // colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
+ // + "<br>" + colNames[i];
+ // colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
+ //
+ // }
+ // }
+ if (fireTableStructureChanged)
+ fireTableStructureChanged();
+
+ }
+
+ /**
+ * @return Cached bounds for the whole dataset (without applying the filter)
+ * or <code>null</code>
+ */
+ public Envelope getBounds() {
+ return bounds;
+ }
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureSourceInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureSourceInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureSourceInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import org.geotools.data.FeatureSource;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+/**
+ * {@link StyledLayerInterface} which contains a {@link FeatureSource} as geo object.<br>
+ */
+public interface StyledFeatureSourceInterface extends StyledFeaturesInterface<FeatureSource<SimpleFeatureType, SimpleFeature>> {
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeaturesInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeaturesInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeaturesInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import org.geotools.data.FeatureSource;
+import org.geotools.feature.FeatureCollection;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
+
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+
+/**
+ * This Interface combines all styled layers that are running on
+ * {@link FeatureCollection} or {@link FeatureSource}
+ *
+ * @author Stefan A. Tzeggai
+ *
+ * @param <T>
+ * The base Type returned in the getObject() method.
+ */
+public interface StyledFeaturesInterface<T> extends StyledLayerInterface<T> {
+
+ public abstract AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap();
+
+ /**
+ * @return The features of this layer as a {@link FeatureSource}. The filter
+ * is NOT automatically applied.
+ */
+ public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource();
+
+ /**
+ * @return The features of this layer as a {@link FeatureCollection}. The
+ * filter is NOT automatically applied.
+ */
+ public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection();
+
+ /**
+ * @return The features of this layer as a {@link FeatureCollection}. The
+ * associated Filter is automatically applied.
+ */
+ public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered();
+
+ /**
+ * Stores Filter that is NOT automatically applied. <code>null</code> is not
+ * allowed, use Filter.INCLUDE.
+ */
+ public void setFilter(Filter filter);
+
+ /**
+ * Returns the Filter a filter that is associated with this
+ * {@link StyledFeaturesInterface} Never shall return <code>null</code>, but
+ * rather Filter.INCLUDE.
+ */
+ public Filter getFilter();
+
+ /**
+ * Returns the underlying GeoTools Object. The filter is NOT applied.
+ *
+ * @throws RuntimeException
+ *
+ * @deprected Please use {@link #getFeatureSource()} or
+ * {@link #getFeatureCollection()} so you save a cast
+ */
+ public T getGeoObject();
+
+ /**
+ * @return As the fastest way to get the Schema is depending on the
+ * underlying geoObject (FeatureSource or FeatureCollection), this
+ * method shall be implemented in the classes.
+ */
+ public abstract SimpleFeatureType getSchema();
+
+ /**
+ * @return can returns {@link GeometryForm#ANY} if the source is e.g. a GML
+ * mixed geometry collection.
+ */
+ public abstract GeometryForm getGeometryForm();
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,329 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.styling.Style;
+
+import de.schmitzm.geotools.JTSUtil;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.geotools.grid.GridUtil;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * 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 AbstractStyledLayer<GridCoverage2D>
+ implements StyledGridCoverageInterface {
+
+ /** Holds the meta data for displaying a legend. */
+ protected RasterLegendData legendData = null;
+
+ /**
+ * Creates a styled grid with language-specific informations.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the 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 (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @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, Style style,
+ RasterLegendData legendData, ImageIcon icon) {
+ super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
+ .getCoordinateReferenceSystem(), id, title, desc, keywords,
+ style, icon);
+ setLegendMetaData(legendData);
+ }
+
+ /**
+ * Creates a styled grid with language-specific informations.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the 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 with legend information
+ * @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,
+ 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);
+ }
+
+ /**
+ * Creates a styled grid with a language-specific title, no long
+ * description, no keywords and no icon.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
+ Style style, RasterLegendData legendData) {
+ this(gc, id, title, null, null, style, legendData, null);
+ }
+
+ /**
+ * Creates a styled grid with non-translated informations.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @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, Style style,
+ RasterLegendData legendData, ImageIcon icon) {
+ this(gc, id, (Translation) null, null, null, style, legendData, icon);
+ setTitle(title);
+ setDesc(desc);
+ setKeywords(keywords);
+ }
+
+ /**
+ * Creates a styled grid with non-translated informations.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style with legend information
+ * @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,
+ StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
+ this(gc, id, title, desc, keywords, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, icon);
+ }
+
+ /**
+ * Creates a styled grid with a non-translated title, no long description,
+ * no keywords and no icon.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledGridCoverage(GridCoverage2D gc, String id, String title,
+ Style style, RasterLegendData legendData) {
+ this(gc, id, title, null, null, style, legendData, null);
+ }
+
+ /**
+ * Creates a styled grid with a non-translated title, no long description,
+ * no keywords and no icon.
+ *
+ * @param gc
+ * the grid
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @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,
+ StyledLayerStyle<RasterLegendData> style) {
+ this(gc, id, title, null, null, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, null);
+ }
+
+ /**
+ * Creates a default style for a {@link GridCoverage2D}.
+ *
+ * @see GridUtil#createDefaultStyle()
+ */
+ protected Style createDefaultStyle() {
+ return GridUtil.createDefaultStyle();
+ }
+
+ /**
+ * Returns the meta data needed for displaying a legend.
+ */
+ public RasterLegendData getLegendMetaData() {
+ return legendData;
+ }
+
+ /**
+ * Sets the meta data needed for displaying a legend. If {@code legendData}
+ * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
+ * so {@link #getLegendMetaData()} never returns {@code null}.
+ *
+ * @param legendData
+ * legend meta data
+ */
+ public void setLegendMetaData(RasterLegendData legendData) {
+ this.legendData = (legendData != null) ? legendData
+ : new RasterLegendData(false);
+ }
+
+ /**
+ * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
+ * {@link #legendData} to {@code null}.
+ */
+ public void dispose() {
+ this.geoObject = null;
+ this.envelope = null;
+ this.crs = null;
+ this.legendData = null;
+ }
+
+ /**
+ * Tests whether the geo object is disposed.
+ *
+ * @return boolean
+ */
+ public boolean isDisposed() {
+ return geoObject == null;
+ }
+
+ /**
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
+ * objects (in memory) which can not be uncached and reloaded.
+ */
+ public void uncache() {
+ LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
+ */
+ public URL getInfoURL() {
+ return null;
+ }
+
+ /**
+ * If true, this layer will not be shown in the legend. Default = false
+ */
+ /**
+ *
+ * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
+ * verstecken/nicht verstecken gestellt werden können. Das sind
+ * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
+ * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
+ * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
+ * die Funktion genutzt.
+ *
+ * public boolean isHideInLegend() { return false; }
+ */
+ @Override
+ public ReferencedEnvelope getReferencedEnvelope() {
+ return new ReferencedEnvelope(getEnvelope(), getCrs());
+ }
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+import org.geotools.coverage.grid.GridCoverage2D;
+
+/**
+ * A {@link StyledRasterInterface} that is typed to wrap a {@link GridCoverage2D}
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+public interface StyledGridCoverageInterface extends StyledRasterInterface<GridCoverage2D>{
+};
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,337 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.styling.Style;
+
+import de.schmitzm.geotools.JTSUtil;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.geotools.grid.GridUtil;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * 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
+ AbstractStyledLayer<AbstractGridCoverage2DReader> implements
+ StyledGridCoverageReaderInterface {
+ @Override
+ public ReferencedEnvelope getReferencedEnvelope() {
+ return new ReferencedEnvelope(getEnvelope(), getCrs());
+ }
+
+ /** Holds the meta data for displaying a legend. */
+ protected RasterLegendData legendData = null;
+
+ /**
+ * Creates a styled grid with language-specific informations.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the 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 (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @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, Style style, RasterLegendData legendData,
+ ImageIcon icon) {
+ super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
+ .getCrs(), id, title, desc, keywords, style, icon);
+ setLegendMetaData(legendData);
+ }
+
+ /**
+ * Creates a styled grid with language-specific informations.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the 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 with legend information
+ * @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, 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);
+ }
+
+ /**
+ * Creates a styled grid with a language-specific title, no long
+ * description, no keywords and no icon.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
+ String id, Translation title, Style style,
+ RasterLegendData legendData) {
+ this(gcr, id, title, null, null, style, legendData, null);
+ }
+
+ /**
+ * Creates a styled grid with non-translated informations.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @param legendData
+ * meta data for displaying a legend
+ * @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, Style style,
+ RasterLegendData legendData, ImageIcon icon) {
+ this(gcr, id, (Translation) null, null, null, style, legendData, icon);
+ setTitle(title);
+ setDesc(desc);
+ setKeywords(keywords);
+ }
+
+ /**
+ * Creates a styled grid with non-translated informations.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param desc
+ * a long description
+ * @param keywords
+ * keywords for the geo objects
+ * @param style
+ * a display style with legend information
+ * @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,
+ StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
+ this(gcr, id, title, desc, keywords, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, icon);
+ }
+
+ /**
+ * Creates a styled grid with a non-translated title, no long description,
+ * no keywords and no icon.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @param style
+ * a display style (if {@code null}, a default style is created)
+ * @exception IllegalArgumentException
+ * if {@code null} is given as ID or geo object
+ */
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
+ String id, String title, Style style, RasterLegendData legendData) {
+ this(gcr, id, title, null, null, style, legendData, null);
+ }
+
+ /**
+ * Creates a styled grid with a non-translated title, no long description,
+ * no keywords and no icon.
+ *
+ * @param gcr
+ * the grid reader
+ * @param id
+ * a unique ID for the object
+ * @param title
+ * a short description
+ * @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, StyledLayerStyle<RasterLegendData> style) {
+ this(gcr, id, title, null, null, style != null ? style
+ .getGeoObjectStyle() : null, style != null ? style
+ .getMetaData() : null, null);
+ }
+
+ public StyledGridCoverageReader(AbstractGridCoverage2DReader reader) {
+ this(reader, "", "", null, null);
+ }
+
+ /**
+ * Creates a default style for a {@link GridCoverage2D}.
+ *
+ * @see GridUtil#createDefaultStyle()
+ */
+ protected Style createDefaultStyle() {
+ return GridUtil.createDefaultStyle();
+ }
+
+ /**
+ * Returns the meta data needed for displaying a legend.
+ */
+ public RasterLegendData getLegendMetaData() {
+ return legendData;
+ }
+
+ /**
+ * Sets the meta data needed for displaying a legend. If {@code legendData}
+ * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
+ * so {@link #getLegendMetaData()} never returns {@code null}.
+ *
+ * @param legendData
+ * legend meta data
+ */
+ public void setLegendMetaData(RasterLegendData legendData) {
+ this.legendData = (legendData != null) ? legendData
+ : new RasterLegendData(false);
+ }
+
+ /**
+ * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
+ * {@link #legendData} to {@code null}.
+ */
+ public void dispose() {
+ this.geoObject = null;
+ this.envelope = null;
+ this.crs = null;
+ this.legendData = null;
+ }
+
+ /**
+ * Tests whether the geo object is disposed.
+ *
+ * @return boolean
+ */
+ public boolean isDisposed() {
+ return geoObject == null;
+ }
+
+ /**
+ * Does nothing, because the {@link AbstractStyledLayer} bases on existing
+ * objects (in memory) which can not be uncached and reloaded.
+ */
+ public void uncache() {
+ LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
+ */
+ public URL getInfoURL() {
+ return null;
+ }
+
+ /**
+ * If true, this layer will not be shown in the legend. Default = false
+ */
+ /**
+ *
+ * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
+ * verstecken/nicht verstecken gestellt werden können. Das sind
+ * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
+ * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
+ * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
+ * die Funktion genutzt.
+ *
+ * public boolean isHideInLegend() { return false; }
+ */
+
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReaderInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReaderInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReaderInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+
+/**
+ * A {@link StyledRasterInterface} that is typed to wrap a {@link AbstractGridCoverage2DReader}
+ *
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ */
+public interface StyledGridCoverageReaderInterface extends StyledRasterInterface<AbstractGridCoverage2DReader>{
+};
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.geotools.feature.FeatureCollection;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.styling.Style;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.schmitzm.geotools.MapContextManagerInterface;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
+import de.schmitzm.i8n.Translation;
+
+/**
+ * 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 AttributeMetadataInterface}-Map must not return {@code
+ * null}</li>
+ * <li>static helper method to get a new {@link AttributeMetadataImpl}-map with the
+ * visible attributes only</li>
+ * <li>static helper method to create a "default" {@link AttributeMetadataImpl}-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 <code>null</code> is no CRS is available
+ */
+ public ReferencedEnvelope getReferencedEnvelope();
+
+
+ /**
+ * @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();
+// public String getLegendHtml();
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerStyle.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerStyle.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerStyle.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+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;
+ }
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,1413 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.IndexColorModel;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.net.URL;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+
+import net.miginfocom.swing.MigLayout;
+
+import org.apache.log4j.Logger;
+import org.geotools.coverage.grid.GeneralGridEnvelope;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.GridGeometry2D;
+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.coverage.grid.io.AbstractGridFormat;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.MapLayer;
+import org.geotools.parameter.Parameter;
+import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
+import org.geotools.styling.ColorMap;
+import org.geotools.styling.ColorMapEntry;
+import org.geotools.styling.FeatureTypeStyle;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Rule;
+import org.geotools.styling.Style;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.GeometryDescriptor;
+import org.opengis.feature.type.Name;
+import org.opengis.filter.FilterFactory2;
+import org.opengis.parameter.GeneralParameterValue;
+
+import com.vividsolutions.jts.geom.Geometry;
+
+import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
+import de.schmitzm.geotools.FilterUtil;
+import de.schmitzm.geotools.JTSUtil;
+import de.schmitzm.geotools.LegendIconFeatureRenderer;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.feature.FeatureUtil;
+import de.schmitzm.i8n.Translation;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.ExceptionDialog;
+import de.schmitzm.swing.JPanel;
+import de.schmitzm.swing.SwingUtil;
+
+/**
+ * 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();
+
+ /**
+ * Is appended to the name of a rule, this rule shall not be shown in the
+ * legend
+ */
+ public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
+
+ /** 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";
+ private static FilterFactory2 ff = FilterUtil.FILTER_FAC2;
+
+ /**
+ * 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(final 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, final 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(
+ final Object object, final 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(
+ final Object object, final String title,
+ final StyledLayerStyle style) {
+ StyledLayerInterface<?> styledLayer = null;
+
+ final 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
+ *
+ * TODO replace with
+ * {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
+ */
+ public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData(
+ final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap,
+ final boolean visible) {
+
+ final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap
+ .clone();
+ if (filteredMap.size() > 0) {
+ filteredMap.clear(); // Just in case the close copies the contents
+ }
+
+ for (final AttributeMetadataInterface amd : amdMap.values())
+ if (amd.isVisible() == visible)
+ filteredMap.put(amd.getName(), amd);
+
+ return filteredMap;
+ }
+
+ /**
+ * Parses a {@link AttributeMetadataImpl} object from an JDOM-
+ * {@link Element}. This method works like {@link
+ * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
+ *
+ * TODO 20.11.2009, SK: There are some new attribute weight, functiona,
+ * functionX and nodata in AttributeMetaData that should be parsed/exported
+ * too. but this method is only used by ISDSS, which is not supporting that
+ * stuff anyways.
+ *
+ * @param element
+ * {@link Element} to parse
+ */
+ public static AttributeMetadataImpl parseAttributeMetaData(
+ final Element element) {
+ final String namespace = element.getAttributeValue("namespace");
+ final String localname = element.getAttributeValue("localname");
+ final NameImpl aName = new NameImpl(namespace, localname);
+ 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 AttributeMetadataImpl(aName, visible, name, desc, unit);
+ }
+
+ /**
+ * Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element}
+ * with {@code <attribute>}-childs.
+ *
+ * @param element
+ * {@link Element} to parse
+ *
+ * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
+ * more attributes which are not used by Xulu/ISDSS. GP
+ * exports/imports the AMD via AMLExporter and AMLImporter
+ * classes. (SK, 3.2.2010) *
+ */
+ public static AttributeMetadataMap parseAttributeMetaDataMap(
+ final Element element) {
+ final AttributeMetadataMap metaData = new AttributeMetadataImplMap();
+ final List<Element> attributesElements = element
+ .getChildren(ELEM_NAME_ATTRIBUTE);
+ for (final Element attibuteElement : attributesElements) {
+ final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement);
+ metaData.put(attrMetaData.getName(), attrMetaData);
+ }
+ return metaData;
+ }
+
+ /**
+ * Loads a {@link AttributeMetadataImpl} object from an URL.
+ *
+ * @param documentUrl
+ * {@link URL} to parse
+ * @see #parseAttributeMetaData(Element)
+ */
+ public static AttributeMetadataMap loadAttributeMetaDataMap(
+ final URL documentUrl) throws Exception {
+ final Document document = SAX_BUILDER.build(documentUrl);
+ return parseAttributeMetaDataMap(document.getRootElement());
+ }
+
+ /**
+ * Creates an JDOM {@link Element} for the given
+ * {@link AttributeMetadataImpl} object.
+ *
+ * @param amd
+ * meta data for one attribute
+ *
+ * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
+ * more attributes which are not used by Xulu/ISDSS. GP
+ * exports/imports the AMD via AMLExporter and AMLImporter
+ * classes. (SK, 3.2.2010)
+ */
+ public static Element createAttributeMetaDataElement(
+ final AttributeMetadataInterface amd) {
+ final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
+ element.setAttribute("namespace",
+ String.valueOf(amd.getName().getNamespaceURI()));
+ element.setAttribute("localname", String.valueOf(amd.getLocalName()));
+ 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 AttributeMetadataImpl} map.
+ *
+ * @param amdMap
+ * map of attribute meta data
+ */
+ public static Element createAttributeMetaDataMapElement(
+ final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) {
+ final Element element = new Element(ELEM_NAME_AMD, AMLURI);
+ for (final AttributeMetadataInterface amd : amdMap.values())
+ element.addContent(createAttributeMetaDataElement(amd));
+ return element;
+ }
+
+ /**
+ * Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL.
+ *
+ * @param amdMap
+ * map of {@link AttributeMetadataImpl}
+ * @param documentUrl
+ * {@link URL} to store the XML
+ */
+ public static void saveAttributeMetaDataMap(
+ final AttributeMetadataMap 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(final Element element) {
+
+ final boolean paintGaps = Boolean.valueOf(element
+ .getAttributeValue("paintGaps"));
+
+ final RasterLegendData rld = new RasterLegendData(paintGaps);
+
+ for (final 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
+ final 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 {
+ final 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 (final Double key : rld.getSortedKeys()) {
+ final 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(
+ final ColorMap colorMap, final boolean paintGaps,
+ final Integer digits) {
+ final DecimalFormat decFormat = digits != null ? new DecimalFormat(
+ SwingUtil.getNumberFormatPattern(digits)) : null;
+ final RasterLegendData rld = new RasterLegendData(paintGaps);
+ for (final ColorMapEntry cme : colorMap.getColorMapEntries()) {
+ final 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(final Style style,
+ final boolean paintGaps, final Integer digits) {
+ final 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) {
+ final 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(final String tagname,
+ final Translation translation) {
+ final 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 (final String lang : translation.keySet()) {
+ final 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(
+ final StyledLayerInterface styledObject,
+ final StyledLayerStyle<?> style) {
+ // set SLD style
+ styledObject.setStyle(style.getGeoObjectStyle());
+ // set meta data
+ if (styledObject instanceof StyledGridCoverageInterface
+ && (style.getMetaData() instanceof RasterLegendData || style
+ .getMetaData() == null)) {
+ final RasterLegendData sourceRld = (RasterLegendData) style
+ .getMetaData();
+ final 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)) {
+ final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
+ .getMetaData();
+ final AttributeMetadataMap 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(
+ final 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(
+ final 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<AttributeMetadataMap> getStyledLayerStyle(
+ final StyledFeatureCollectionInterface styledFC) {
+ return new StyledLayerStyle<AttributeMetadataMap>(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(
+ final URL geoObjectURL, final String sldExt, final String rldExt) {
+ RasterLegendData metaData = null;
+ Style sldStyle = null;
+ try {
+ final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+ geoObjectURL, sldExt));
+ // SLD must be present
+ if (styles == null || styles.length == 0)
+ return null;
+ sldStyle = styles[0];
+ } catch (final Exception err) {
+ // SLD must be present
+ LangUtil.logDebugError(LOGGER, err);
+ return null;
+ }
+
+ try {
+ metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
+ .changeUrlExt(geoObjectURL, rldExt));
+ } catch (final FileNotFoundException err) {
+ // ignore missing raster legend data
+ } catch (final 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(
+ final URL geoObjectURL) {
+ return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
+ }
+
+ /**
+ * Loads a {@linkplain Style SLD-Style} and a
+ * {@linkplain AttributeMetadataImpl 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<AttributeMetadataMap> loadStyledFeatureStyle(
+ final URL geoObjectURL, final String sldExt, final String rldExt) {
+ AttributeMetadataMap metaData = null;
+ Style sldStyle = null;
+ try {
+ final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+ geoObjectURL, sldExt));
+ // SLD must be present
+ if (styles == null || styles.length == 0)
+ return null;
+ sldStyle = styles[0];
+ } catch (final Exception err) {
+ // SLD must be present
+ LangUtil.logDebugError(LOGGER, err);
+ return null;
+ }
+
+ try {
+ metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
+ .changeUrlExt(geoObjectURL, rldExt));
+ } catch (final FileNotFoundException err) {
+ // ignore missing attribute meta data
+ } catch (final Exception err) {
+ // any other error during meta data creation leads to error
+ LangUtil.logDebugError(LOGGER, err);
+ return null;
+ }
+
+ return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, metaData);
+ }
+
+ /**
+ * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
+ * {@linkplain AttributeMetadataImpl 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<AttributeMetadataMap> loadStyledFeatureStyle(
+ final 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(
+ final StyledLayerStyle<T> style, final URL geoObjectURL,
+ final String sldExt, final String mdExt) throws Exception {
+ // Store the SLD
+ final Style sldStyle = style.getGeoObjectStyle();
+ if (sldStyle != null) {
+ StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File(
+ geoObjectURL.toURI()), sldExt));
+ }
+
+ // Store the meta data
+ final 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((AttributeMetadataMap) 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 AttributeMetadataImpl}) 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(final StyledLayerStyle<?> style,
+ final URL geoObjectURL) throws Exception {
+ if (style.getMetaData() instanceof RasterLegendData)
+ saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
+ else
+ saveStyledLayerStyle(style, geoObjectURL, "sld", "amd");
+ }
+
+ /**
+ * Creates a {@link JPanel} that shows a legend for a list of
+ * {@link FeatureTypeStyle}s and a targeted featureType
+ *
+ * @param style
+ * The Style to presented in this legend
+ * @param featureType
+ * If this a legend for Point, Polygon or Line? Or ANY or NONE?
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+ public static JPanel createLegendSwingPanel(Style style,
+ final SimpleFeatureType featureType, final int iconWidth,
+ final int iconHeight) {
+
+ if (featureType == null) {
+ ExceptionDialog.show(new IllegalStateException(
+ "featureType is null!"));
+ return new JPanel();
+ }
+
+ final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
+ if (style == null) {
+ // No Style => no legend
+ return panel;
+ }
+
+ // Reversing the list, because a point that is painted above a polygon
+ // should be higher in the list.
+ final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
+ Collections.reverse(ftsList);
+ for (final FeatureTypeStyle ftStyle : ftsList) {
+
+ // // Try to import the FeatureType into an AtlasStyler RuleList to
+ // // determine whether this RL is actually disabled.
+ // StylingUtil.sldToString(ftStyle).contains(RL_DISABLED_FILTER.toString())
+ // return;
+
+ // One child-node for every rule
+ final List<Rule> rules = ftStyle.rules();
+ for (final Rule rule : rules) {
+
+ // Check if this RULE shall actually appear in the legend
+ if (rule.getName() != null
+ && rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
+ continue;
+
+ /**
+ * Let's not create a hbox for Rules that only contain
+ * TextSymbolizers
+ */
+ if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
+ .size() == rule.getSymbolizers().length)
+ continue;
+
+ final BufferedImage imageForRule = LegendIconFeatureRenderer
+ .getInstance().createImageForRule(rule, featureType,
+ new Dimension(iconWidth, iconHeight));
+
+ final ImageIcon legendIcon = new ImageIcon(imageForRule);
+
+ final JLabel iconLabel = new JLabel(legendIcon);
+ panel.add(iconLabel, "sgx1");
+ // hbox.setAlignmentX(0f);
+ // hbox.add(iconLabel);
+ // hbox.add(Box.createHorizontalStrut(3));
+
+ final Translation labelT = new Translation();
+ labelT.fromOneLine(rule.getDescription().getTitle().toString());
+ final JLabel classTitleLabel = new JLabel(labelT.toString());
+
+ panel.add(classTitleLabel, "sgx2");
+ classTitleLabel.setLabelFor(iconLabel);
+ }
+ }
+
+ return panel;
+ }
+
+ /**
+ * Creates a {@link JComponent} that contains a legend for a given
+ * {@link StyledRasterInterface} and a given {@link Style}.
+ *
+ * @param style
+ * if <code>null</code>, the default {@link Style} is extracetd
+ * from the {@link StyledRasterInterface}
+ */
+ public static JPanel createLegendSwingPanel(
+ final StyledRasterInterface<?> styledRaster, Style style,
+ final int iconWidth, final int iconHeight) {
+
+ // If no style is given, we use the default style for this layer
+ if (style == null)
+ style = styledRaster.getStyle();
+
+ /**
+ * Determine whether a Style is responsible for the coloring
+ */
+ ColorModel colorModel = null;
+ if (!isStyleable(styledRaster)
+ || (isStyleable(styledRaster) && style == null)) {
+ colorModel = getColorModel(styledRaster);
+ }
+
+ final RasterLegendData rasterLegendData = styledRaster
+ .getLegendMetaData();
+ final List<Double> legendRasterValues = rasterLegendData
+ .getSortedKeys();
+ final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
+ .createSampleRasters();
+
+ final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0"));
+
+ for (final Double rValue : legendRasterValues) {
+
+ // final Dimension ICON_SIZE = new Dimension(iconWidth,
+ // new JLabel().getFontMetrics(new JLabel().getFont())
+ // .getHeight() > 5 ? new JLabel().getFontMetrics(
+ // new JLabel().getFont()).getHeight() : iconHeight);
+
+ // ****************************************************************************
+ // Create the actual icon
+ // ****************************************************************************
+ final BufferedImage buffImage = new BufferedImage(iconWidth,
+ iconHeight, BufferedImage.TYPE_INT_ARGB);
+
+ final Graphics2D graphics = buffImage.createGraphics();
+
+ if (colorModel != null) {
+ // The colors come from the ColorModel!
+
+ try {
+ Object inData = null;
+ switch (colorModel.getTransferType()) {
+ case DataBuffer.TYPE_BYTE:
+ inData = new byte[] { rValue.byteValue() };
+ break;
+ case DataBuffer.TYPE_USHORT:
+ inData = new short[] { rValue.shortValue() };
+ break;
+ case DataBuffer.TYPE_INT:
+ inData = new int[] { rValue.intValue() };
+ break;
+ case DataBuffer.TYPE_SHORT:
+ inData = new short[] { rValue.shortValue() };
+ break;
+ case DataBuffer.TYPE_FLOAT:
+ inData = new float[] { rValue.floatValue() };
+ break;
+ case DataBuffer.TYPE_DOUBLE:
+ inData = new double[] { rValue.doubleValue() };
+ break;
+ default:
+ inData = rValue.intValue();
+ }
+ final Color color = new Color(colorModel.getRGB(inData));
+ graphics.setBackground(color);
+ graphics.setColor(color);
+ graphics.fillRect(0, 0, iconWidth, iconHeight);
+ } catch (final Exception e) {
+ LOGGER.info(
+ "Dann nehmen wir halt den GridCoverageRenderer", e);
+ colorModel = null;
+ }
+ } else {
+ // The colors come from the Style
+
+ /**
+ * The coverage contains only one value of value rValue
+ */
+ final GridCoverage2D sampleCov = sampleRasters.get(rValue);
+ GridCoverageRenderer renderer;
+ try {
+ renderer = new GridCoverageRenderer(
+ sampleCov.getCoordinateReferenceSystem(),
+ JTSUtil.createEnvelope(sampleCov.getEnvelope()),
+ new Rectangle(iconWidth, iconHeight),
+ (AffineTransform) null);
+ } catch (final Exception e1) {
+ throw new RuntimeException(
+ "Creating a GridCoverageRenderer failed:", e1);
+ }
+
+ /**
+ * Iterate over all FeatureTypeStyles.
+ */
+ final List<RasterSymbolizer> rSymbols = StylingUtil
+ .getRasterSymbolizers(style);
+
+ for (final RasterSymbolizer symbolizer : rSymbols) {
+ try {
+ renderer.paint(graphics, sampleCov, symbolizer);
+ } catch (final Exception ee) {
+ LOGGER.error("Unable to paint " + symbolizer
+ + " into the legend image", ee);
+ }
+ }
+ }
+
+ final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
+ panel.add(iconLabel, "sgx1");
+
+ final Translation labelT = rasterLegendData.get(rValue);
+ final JLabel classTitleLabel = new JLabel(labelT.toString());
+ panel.add(classTitleLabel, "sgx2"
+ + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
+ : ""));
+ classTitleLabel.setLabelFor(iconLabel);
+
+ if (rasterLegendData.isPaintGaps()) {
+ iconLabel
+ .setBorder(BorderFactory.createLineBorder(Color.black));
+ }
+
+ }
+
+ return panel;
+ }
+
+ /**
+ * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
+ * return <code>null</code> if the geoobject can not be accessed.
+ */
+ @SuppressWarnings("unchecked")
+ public static ColorModel getColorModel(
+ final StyledRasterInterface<?> styledGrid) {
+ ColorModel colorModel = null;
+ try {
+ final Object geoObject = styledGrid.getGeoObject();
+ if (geoObject instanceof GridCoverage2D) {
+ final GridCoverage2D cov = (GridCoverage2D) geoObject;
+ colorModel = cov.getRenderedImage().getColorModel();
+ } else if (styledGrid instanceof StyledGridCoverageReaderInterface) {
+
+ final Parameter readGG = new Parameter(
+ AbstractGridFormat.READ_GRIDGEOMETRY2D);
+
+ final ReferencedEnvelope mapExtend = new ReferencedEnvelope(
+ styledGrid.getEnvelope(), styledGrid.getCrs());
+
+ readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
+ new Rectangle(0, 0, 1, 1)), mapExtend));
+
+ AbstractGridCoverage2DReader aReader;
+ if (geoObject instanceof FeatureCollection) {
+ final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
+
+ aReader = (AbstractGridCoverage2DReader) FeatureUtil
+ .getWrappedGeoObject(rFc);
+
+ } else if (geoObject instanceof AbstractGridCoverage2DReader) {
+ aReader = (AbstractGridCoverage2DReader) geoObject;
+
+ } else
+ throw new RuntimeException("need a reader...");
+ //
+
+ final GridCoverage2D cov = aReader
+ .read(new GeneralParameterValue[] { readGG });
+ colorModel = cov.getRenderedImage().getColorModel();
+ }
+ } catch (final Exception e) {
+ LOGGER.error("Error reading the colormodel from " + styledGrid, e);
+ return null;
+ }
+ return colorModel;
+ }
+
+ /**
+ * @return <code>true</code> if a {@link RasterSymbolizer} can be applied
+ * and will have an effect. Some rasters (e.g. GeoTIFF) can come
+ * with their own {@link ColorModel} and will ignore any
+ * {@link RasterSymbolizer} = SLD.
+ */
+ public static boolean isStyleable(
+ final StyledRasterInterface<?> styledRaster) {
+ final ColorModel colorModel = getColorModel(styledRaster);
+
+ // LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
+ // + colorModel != null ? colorModel.getClass().getSimpleName() :
+ // "NULL");
+
+ if (colorModel == null)
+ return true;
+ if (colorModel instanceof ComponentColorModel)
+ return true;
+ if (colorModel instanceof IndexColorModel)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Set the given Style as the Style of the {@link MapLayer}, unless the
+ * styles are the same (not comparing selection stuff). If the
+ * {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
+ * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
+ * repaint, so only use it when needed.
+ *
+ * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has
+ * been changed.
+ */
+ public static boolean updateMapLayerStyleIfChangedAndKeepSelection(
+ MapLayer mapLayer, Style style2) {
+
+ Style mapLayerStyleCleaned = StylingUtil
+ .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
+
+ Style newStyleCleaned = StylingUtil
+ .removeSelectionFeatureTypeStyle(style2);
+
+ if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) {
+
+ // They are different when compared without SELECTION FTS!
+
+ // Now let's copy any SELECTION FTS to the now style
+ FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil
+ .getSelectionFeatureTypeStyle(mapLayer.getStyle());
+ if (selectionFeatureTypeStyle != null) {
+ newStyleCleaned.featureTypeStyles().add(
+ selectionFeatureTypeStyle);
+ // newStyleCleaned is not so clean anymore... We just alled a
+ // selcetion FTS
+ }
+
+ mapLayer.setStyle(newStyleCleaned);
+
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * After loading an atlas, the AttribteMetaData contains whatever is written
+ * in the XML. But the DBF may have changed! This method checks an
+ * {@link AttributeMetadataMap} against a schema and also corrects
+ * upperCase/lowerCase problems. It will also remove any geometry column
+ * attribute metadata.
+ */
+ /**
+ * After loading an atlas, the AttribteMetaData contains whatever is written
+ * in the XML. But the DBF may have changed!
+ */
+ public static void checkAttribMetaData(
+ AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
+ SimpleFeatureType schema) {
+
+ if (schema == null)
+ throw new IllegalArgumentException("schmema may not be null!");
+
+ ArrayList<Name> willRemove = new ArrayList<Name>();
+
+ // 1. Check.. all attributes in the atm should be in the schema as well.
+ // maybe correct some upperCase/loweCase stuff
+
+ for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) {
+
+ AttributeDescriptor foundDescr = schema
+ .getDescriptor(atm.getName());
+ if (foundDescr == null) {
+ NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(
+ schema, atm.getLocalName());
+ if (bestMatch == null)
+ willRemove.add(atm.getName());
+ else
+ atm.setName(bestMatch);
+ } else if (foundDescr instanceof GeometryDescriptor) {
+ // We don't want GeometryColumns in here
+ willRemove.add(atm.getName());
+ }
+ }
+
+ // Remove the ones that were not findable in the schema
+ for (Name removeName : willRemove) {
+ if (attributeMetaDataMap.remove(removeName) == null) {
+ LOGGER.warn("removing the AMData didn't work");
+ }
+ }
+
+ // 2. check... all attributes from the schema must have an ATM
+ for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
+ if (ad instanceof GeometryDescriptor)
+ continue;
+ if (!attributeMetaDataMap.containsKey(ad.getName())) {
+ attributeMetaDataMap.put(new NameImpl(ad.getName()
+ .getNamespaceURI(), ad.getName().getLocalPart()),
+ new AttributeMetadataImpl(ad, schema
+ .getAttributeDescriptors().indexOf(ad),
+ attributeMetaDataMap.getLanguages()));
+ }
+ }
+ }
+
+ /**
+ * Checks every attribute name in the {@link AttributeMetadataMap} for its
+ * binding type. It the type is textual, add the mrpty string as a NODATA
+ * value.
+ *
+ * @param attributeMetaDataMap
+ * @param schema
+ */
+ public static void addEmptyStringToAllTextualAttributes(
+ AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap,
+ SimpleFeatureType schema) {
+
+ for (Name name : attributeMetaDataMap.keySet()) {
+ if (String.class.isAssignableFrom(schema.getDescriptor(name)
+ .getType().getBinding())) {
+ attributeMetaDataMap.get(name).getNodataValues().add("");
+ }
+ }
+ }
+
+ /**
+ * @return a nicely formatted String containing all NODATA values of any
+ * {@link AttributeMetadataInterface} object. Strings are quoted so
+ * that any empty {@link String} can be seen.
+ */
+ public static String formatNoDataValues(Set<Object> nodataValuesList) {
+ String nicelyFormatted = "";
+ if (nodataValuesList != null) {
+ if (nodataValuesList.size() == 0)
+ nicelyFormatted = "";
+ else {
+ for (Object ndo : nodataValuesList) {
+ if (ndo instanceof String)
+ nicelyFormatted += "\"" + ndo + "\"";
+ else
+ nicelyFormatted += ndo.toString();
+
+ nicelyFormatted += ",";
+ }
+ // Remove the extra comma
+ nicelyFormatted = nicelyFormatted.substring(0,
+ nicelyFormatted.length() - 1);
+ }
+ }
+ return nicelyFormatted;
+ }
+
+ /**
+ * Creates a new {@link AttributeMetadataMap} with instances of
+ * {@link AttributeMetadataInterface} for every non-geometry attribute.
+ * Default NODATA values (like "" for String) are set.
+ */
+ public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(
+ SimpleFeatureType schema) {
+ AttributeMetadataImplMap attMap = new AttributeMetadataImplMap();
+
+ for (int i = 0; i < schema.getAttributeCount(); i++) {
+ AttributeDescriptor attDesc = schema.getDescriptor(i);
+
+ if (Geometry.class.isAssignableFrom(attDesc.getType().getBinding())) {
+ // Ignore the Geometry column
+ continue;
+ }
+
+ // TODO AttributeMetadataAS would be nicer, which would not work
+ // with Translations ;-)
+ AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
+ new NameImpl(attDesc.getName().getNamespaceURI(), attDesc
+ .getName().getLocalPart()), attMap.getLanguages());
+
+ if (String.class.isAssignableFrom(attDesc.getType().getBinding())) {
+ // For Strings we add the "" as NODATA values
+ attMetaData.addNodataValue("");
+ }
+
+ attMap.put(attDesc.getName(), attMetaData);
+ }
+ return attMap;
+ }
+}
Added: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledRasterInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledRasterInterface.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledRasterInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.geotools.styling;
+
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+
+/**
+ * A {@link StyledLayerInterface} that is associated to a
+ * {@link RasterLegendData}. The datatype is not yet defined.
+ *
+ * @see StyledGridCoverageInterface
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+public interface StyledRasterInterface<E> extends StyledLayerInterface<E> {
+
+ /**
+ * @return A {@link RasterLegendData} object with pairs of value / label
+ * information
+ */
+ RasterLegendData getLegendMetaData();
+
+}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -142,8 +142,6 @@
import com.vividsolutions.jts.geom.Polygon;
import de.schmitzm.geotools.FilterUtil;
-import de.schmitzm.geotools.StyledFeaturesInterface;
-import de.schmitzm.geotools.StyledRasterInterface;
import de.schmitzm.geotools.feature.FeatureUtil;
import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
import de.schmitzm.geotools.grid.GridUtil;
Modified: trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java
===================================================================
--- trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -27,9 +27,9 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
-import de.schmitzm.geotools.StyledFS;
-import de.schmitzm.geotools.StyledGridCoverageReader;
import de.schmitzm.geotools.io.GeoImportUtil;
+import de.schmitzm.geotools.styling.StyledFS;
+import de.schmitzm.geotools.styling.StyledGridCoverageReader;
import de.schmitzm.geotools.styling.StylingUtil;
import de.schmitzm.io.IOUtil;
import de.schmitzm.testing.TestingUtil;
Modified: trunk/schmitzm-jfree-gt/src/main/java/de/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/schmitzm-jfree-gt/src/main/java/de/schmitzm/jfree/feature/style/FeatureChartUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-jfree-gt/src/main/java/de/schmitzm/jfree/feature/style/FeatureChartUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
@@ -61,8 +61,8 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.Name;
-import de.schmitzm.geotools.data.AttributeMetadataInterface;
-import de.schmitzm.geotools.data.AttributeMetadataMap;
+import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
+import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
import de.schmitzm.geotools.feature.FeatureUtil;
import de.schmitzm.geotools.feature.PipedFeatureIterator;
import de.schmitzm.jfree.JFreeChartUtil;
More information about the Schmitzm-commits
mailing list