[Schmitzm-commits] r769 - in trunk/src: schmitzm/geotools/gui skrueger skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Mar 21 12:02:37 CET 2010
Author: alfonx
Date: 2010-03-21 12:02:34 +0100 (Sun, 21 Mar 2010)
New Revision: 769
Added:
trunk/src/skrueger/AbstractAttributeMetadata.java
trunk/src/skrueger/AttributeMetadataImpl.java
trunk/src/skrueger/QualityQuantizable.java
trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
Modified:
trunk/src/schmitzm/geotools/gui/XMapPane.java
trunk/src/skrueger/AttributeMetaDataAttributeTypeFilter.java
trunk/src/skrueger/AttributeMetadata.java
trunk/src/skrueger/geotools/AttributeMetadataMap.java
trunk/src/skrueger/geotools/MapContextManagerInterface.java
trunk/src/skrueger/geotools/StyledFS.java
trunk/src/skrueger/geotools/StyledFeatureCollection.java
trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
trunk/src/skrueger/geotools/StyledFeaturesInterface.java
trunk/src/skrueger/geotools/StyledLayerInterface.java
trunk/src/skrueger/geotools/StyledLayerUtil.java
Log:
Made an interface and a Abstract class for AttributeMetaData
Modified: trunk/src/schmitzm/geotools/gui/XMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPane.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/schmitzm/geotools/gui/XMapPane.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -2121,19 +2121,6 @@
this.rendererHints = rendererHints;
}
- // @Deprecated
- // public void setState(final int state) {
- // this.state = state;
- //
- // // throw new RuntimeException("Old concept.. migrate to new concept!");
- //
- // // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
- // // || state == ZOOM_OUT || state == PAN));
- //
- // // Je nach Aktion den Cursor umsetzen
- // updateCursor();
- // }
-
public void configureMouse(MouseInputType type, XMapPaneAction action) {
xMapPaneMouseListener.putAction(type, action);
}
@@ -2150,23 +2137,6 @@
setCursor(tool.getCursor());
}
- // /**
- // * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion
- // (Zoom,
- // * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
- // * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
- // * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
- // * {@code null} als Parameter uebergeben werden
- // *
- // * @param cursor
- // * Cursor
- // */
- // public void setStaticCursor(final Cursor cursor) {
- // this.staticCursor = cursor;
- // if (cursor != null)
- // super.setCursor(cursor);
- // }
-
/**
* Starts rendering on one or two threads
*/
@@ -2201,16 +2171,6 @@
if (getBgContext() != null) {
bgRenderer.setJava2DHints(getJava2dHints());
bgRenderer.setRendererHints(getRendererHints());
-
- // bgExecuter = new RenderingExecutor();
- // LOGGER.debug("starting bg renderer:");
- // // /* System.out.println("rendering"); */
- // final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
- // bgContext, getRendererHints());
- // createGTRenderer.setJava2DHints(getJava2dHints());
- // bgExecuter.submit(getBgContext().getAreaOfInterest(),
- // curPaintArea,
- // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);
}
if (getMapContext() != null) {
@@ -2254,14 +2214,9 @@
final double px, final double py) {
final AffineTransform at = getWorldToScreenTransform();
Point2D geoO;
- // try {
geoO = at.transform(new Point2D.Double(ox, oy), null);
final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
- // } catch (final NoninvertibleTransformException e) {
- // LOGGER.error(e);
- // return new Envelope(ox, oy, px, py);
- // }
}
/**
@@ -2323,44 +2278,13 @@
repaint();
}
}
- //
- // //
- // // wenn manueller Cursor gesetzt ist, dann diesen verwenden
- // (unabhaengig
- // // von der aktuellen Aktion
- // if (this.staticCursor != null) {
- // setCursor(staticCursor);
- // return;
- // }
- //
+
if (getCursor() == SwingUtil.PANNING_CURSOR) {
// This cursor will reset itself
return;
}
setCursor(tool.getCursor());
-
- //
- // // Set the cursor depending on what tool is in use...
- // switch (state) {
- // case SELECT_TOP:
- // case SELECT_ONE_FROM_TOP:
- // case SELECT_ALL:
- // setCursor(SwingUtil.CROSSHAIR_CURSOR);
- // break;
- // case ZOOM_IN:
- // setCursor(SwingUtil.ZOOMIN_CURSOR);
- // break;
- // case ZOOM_OUT:
- // setCursor(SwingUtil.ZOOMOUT_CURSOR);
- // break;
- // case PAN:
- // setCursor(SwingUtil.PAN_CURSOR);
- // break;
- // default:
- // setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- // break;
- // }
}
/**
Added: trunk/src/skrueger/AbstractAttributeMetadata.java
===================================================================
--- trunk/src/skrueger/AbstractAttributeMetadata.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/AbstractAttributeMetadata.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -0,0 +1,182 @@
+package skrueger;
+
+import java.util.HashSet;
+
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.Name;
+
+import skrueger.geotools.StyledLayerUtil;
+import skrueger.i8n.Translation;
+
+public abstract class AbstractAttributeMetadata implements AttributeMetadata {
+
+ /** 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;
+ }
+
+ /**
+ * 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());
+ }
+}
Property changes on: trunk/src/skrueger/AbstractAttributeMetadata.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/AttributeMetaDataAttributeTypeFilter.java
===================================================================
--- trunk/src/skrueger/AttributeMetaDataAttributeTypeFilter.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/AttributeMetaDataAttributeTypeFilter.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -32,12 +32,13 @@
import org.opengis.feature.type.AttributeDescriptor;
import schmitzm.geotools.feature.AttributeTypeFilter;
+import skrueger.geotools.AttributeMetadataImplMap;
import skrueger.geotools.AttributeMetadataMap;
/**
* Implements an {@link AttributeTypeFilter} using the
- * {@linkplain AttributeMetadata#isVisible() visible}-property of an
- * {@link AttributeMetadata} map (or array).<br>
+ * {@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
@@ -47,14 +48,14 @@
public class AttributeMetaDataAttributeTypeFilter implements AttributeTypeFilter {
/** The meta data of a set of attributes */
- protected AttributeMetadataMap attrMetaDataMap = null;
+ protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaDataMap = null;
/**
* Creates a new filter.
* @param attrMetaData the meta data of some attributes
*/
- public AttributeMetaDataAttributeTypeFilter(final AttributeMetadata[] attrMetaData) {
- this.attrMetaDataMap = new AttributeMetadataMap();
+ 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]);
}
@@ -77,7 +78,7 @@
if ( attrMetaDataMap == null )
return NO_GEOMETRY.accept(type);
- final AttributeMetadata metaData = attrMetaDataMap.get(type.getName());
+ final AttributeMetadataImpl metaData = attrMetaDataMap.get(type.getName());
return NO_GEOMETRY.accept(type) // no geometry attributes at all
&& metaData != null // meta data must be present for column
&& metaData.isVisible(); // attribute must be visible
Modified: trunk/src/skrueger/AttributeMetadata.java
===================================================================
--- trunk/src/skrueger/AttributeMetadata.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/AttributeMetadata.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -1,447 +1,111 @@
-/*******************************************************************************
- * 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. Krüger - additional utility classes
- ******************************************************************************/
package skrueger;
import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.log4j.Logger;
-import org.geotools.feature.NameImpl;
-import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.Name;
import skrueger.geotools.Copyable;
-import skrueger.geotools.StyledLayerInterface;
-import skrueger.i8n.I8NUtil;
import skrueger.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:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- */
-public class AttributeMetadata implements Copyable<AttributeMetadata>,
+public interface AttributeMetadata extends Copyable<AttributeMetadata>,
Comparable<AttributeMetadata> {
- static private final Logger LOGGER = Logger
- .getLogger(AttributeMetadata.class);
-
- /** Translation of the attribute's description **/
- protected Translation desc = new Translation();
-
/**
- * 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.;
-
- /** The Name of the attribute **/
- private Name name;
-
- /**
- * 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>();
-
- /** Translation of the attribute's title **/
- protected Translation title = new Translation();
-
- /**
- * 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;
-
- /**
- * When listed, the attributes are listed according to their {@link #weight}
- * (heavier => further down)
- *
- * @see #compareTo(AttributeMetadata)
- **/
- protected int weight = 0;
-
- /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
- private AttributeMetadata() {
- }
-
- public AttributeMetadata(final AttributeDescriptor attDesc,
- final int weight, final List<String> langs) {
- this(attDesc.getName(), langs);
- setWeight(weight);
- }
-
- public AttributeMetadata(final AttributeDescriptor attDesc,
- final List<String> langs) {
- this(attDesc.getName(), langs);
- }
-
- /**
- * Creates an {@link AttributeMetadata} 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
+ * @return a translatable title for this attribute..
*/
- public AttributeMetadata(final Name name, final Boolean visible,
- final Translation title, final Translation desc, final String unit) {
+ public Translation getTitle();
- this.setName(name);
- this.title = title;
- this.desc = desc;
- this.visible = visible;
- this.unit = unit;
- }
-
/**
- * Creates an {@link AttributeMetadata} 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
+ * Set a translatable title for this attribute..
*/
- public AttributeMetadata(final Name name, final Boolean visible,
- final String unit) {
- this.setName(name);
- this.visible = visible;
- this.unit = unit;
- }
+ public void setTitle(Translation title);
/**
- * Creates a new visible {@link AttributeMetadata}
+ * @return a translatable description for this attribute
*/
- public AttributeMetadata(final Name name, final List<String> langs) {
- this(name, true, new Translation(langs, name.getLocalPart()),
- new Translation(), "");
- }
+ public Translation getDesc();
/**
- * Creates a new visible {@link AttributeMetadata}
+ * Set a translatable description for this attribute.
*/
- public AttributeMetadata(final Name name, final String defaultTitle,
- final List<String> langs) {
- this(name, true, new Translation(langs, defaultTitle),
- new Translation(), "");
- }
+ public void setDesc(Translation desc);
/**
- * Creates an {@link AttributeMetadata} 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
+ * The local name. E.g. the name of the DBF column as a {@link String}.
*/
- public AttributeMetadata(final String localName, final Boolean visible,
- final Translation title, final Translation desc, final String unit) {
- this(new NameImpl(localName), true, title, desc, "");
- }
+ public String getLocalName();
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * A short form for #setName(new NameImpl(localName))
*/
- public AttributeMetadata(final String localName, final List<String> langs) {
- this(localName, true, new Translation(langs, localName),
- new Translation(), "");
- }
+ public void setLocalName(String localName);
/**
- * Creates a new visible {@link AttributeMetadata}
- */
- public AttributeMetadata(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 AttributeMetadata atm2) {
- return new Integer(weight).compareTo(atm2.getWeight());
- }
-
- /**
- * @see Copyable inferface
- */
- @Override
- public AttributeMetadata copy() {
- return copyTo(new AttributeMetadata());
- }
-
- /**
- * @see Copyable inferface
- */
- @Override
- public AttributeMetadata copyTo(final AttributeMetadata 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());
- amd.setFunctionX(getFunctionX());
- amd.setFunctionA(getFunctionA());
-
- amd.setNodataValues(getNodataValues());
-
- return amd;
- }
-
- // only to be used by copyTo()
- private void setNodataValues(HashSet<Object> nodataValues2) {
- nodataValues = nodataValues2;
- }
-
- public Translation getDesc() {
- return desc;
- }
-
- public Double getFunctionA() {
- return functionA;
- }
-
- public Double getFunctionX() {
- return functionX;
- }
-
- /**
- * The local name. E.g. the name of the DBF column as a {@link String}
- */
- public String getLocalName() {
- return getName().getLocalPart();
- }
-
- /**
* The fully qualified {@link Name} of the attribute, e.g.
- * <code>org.bla.plo:blub</code>
+ * <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() {
- return name;
- }
+ public Name getName();
- public HashSet<Object> getNodataValues() {
- return nodataValues;
- }
-
/**
- * @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.
+ * set the fully qualified {@link Name} of this attribute.
*/
- public double getQuality(final List<String> languages) {
+ public void setName(Name name);
- if (!isVisible())
- return 1.;
-
- return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
- .qmTranslation(languages, getDesc()) * 1.) / 3.;
- }
-
- public Translation getTitle() {
- return title;
- }
-
- public String getUnit() {
- return unit;
- }
-
- public int getWeight() {
- return weight;
- }
-
/**
- * Will the end-user see this attribute?
+ * 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 boolean isVisible() {
- return visible;
- }
+ public HashSet<Object> getNodataValues();
- public void setDesc(final Translation desc) {
- this.desc = desc;
- }
-
- public void setFunctionA(final Double functionA) {
- this.functionA = functionA;
- }
-
- public void setFunctionX(final Double functionX) {
- this.functionX = functionX;
- }
-
/**
- * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
+ * 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 void setLocalName(final String localName) {
- this.name = new NameImpl(localName);
- }
+ public Object fiterNodata(Object value);
/**
- * The fully qualified {@link Name} of the attribute, e.g.
- * <code>org.bla.plo:blub</code>
+ * @return a non-translatable unit {@link String} for this attribute values.
*/
- public void setName(final Name name) {
- this.name = name;
- }
+ public String getUnit();
- public void addNodataValue(Object nodataValue) {
- this.nodataValues.add(nodataValue);
- }
-
- public void removeNodataValue(Object nodataValue) {
- this.nodataValues.remove(nodataValue);
- }
-
- public void setTitle(final Translation title) {
- this.title = title;
- }
-
- public void setUnit(final String unit) {
- this.unit = unit;
- }
-
- public void setVisible(final boolean visible) {
- this.visible = visible;
- }
-
/**
- * Shall the end-user see this attribute?
- *
- * @param visible
+ * Set a unit {@link String} for this attribute values.
*/
- public void setVisible(final Boolean visible) {
- // // The THE_GEOM and shall never be visible!
- // if (name.getLocalPart().equalsIgnoreCase("the_geom"))
- // this.visible = false;
- // else
- // this.visible = visible;
+ public void setUnit(String unit);
- this.visible = visible;
- }
-
- public void setWeight(final int weight) {
- this.weight = weight;
- }
-
/**
- * For nicer debugging
+ * @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)
*/
- @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();
- }
+ public double getWeight();
/**
- * 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.
+ * 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 Object fiterNodata(final Object value) {
- if (nodataValues.contains(value))
- return null;
- return value;
- }
+ public void setWeight(double weight);
/**
- * @return a nicely formatted String containing all NODATA values. Strings
- * are quoted fo that the empty String can be seen.
+ * @return <code>false</code> if this attribute should not be selectable or
+ * shown to the end-user.
*/
- public String getNoDataValuesFormatted() {
- return formatNoDataValues(getNodataValues());
- }
+ public boolean isVisible();
/**
- * @return a nicely formatted String containing all NODATA values. Strings
- * are quoted fo that the empty String can be seen.
+ * Set <code>false</code> if this attribute should not be shown to the
+ * end-user.
*/
- public static String formatNoDataValues(Set<Object> list) {
- String nicelyFormatted = "";
- if (list != null) {
- if (list.size() == 0)
- nicelyFormatted = "";
- else {
- for (Object ndo : list) {
- if (ndo instanceof String)
- nicelyFormatted += "\"" + ndo + "\"";
- else
- nicelyFormatted += ndo.toString();
+ public void setVisible(boolean visible);
- nicelyFormatted += ",";
- }
- // Remove the extra comma
- nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted
- .length() - 1);
- }
- }
- return nicelyFormatted;
- }
+ String getNoDataValuesFormatted();
+
}
Copied: trunk/src/skrueger/AttributeMetadataImpl.java (from rev 768, trunk/src/skrueger/AttributeMetadata.java)
===================================================================
--- trunk/src/skrueger/AttributeMetadata.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/AttributeMetadataImpl.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -0,0 +1,263 @@
+/*******************************************************************************
+ * 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. Krüger - additional utility classes
+ ******************************************************************************/
+package skrueger;
+
+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 skrueger.geotools.Copyable;
+import skrueger.geotools.StyledLayerInterface;
+import skrueger.i8n.I8NUtil;
+import skrueger.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:skpublic at wikisquare.de">Stefan Alfons Krüger</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(attDesc.getName(), langs);
+ setWeight(weight);
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final List<String> langs) {
+ this(attDesc.getName(), 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 AttributeMetadata atm2) {
+ return new Integer(weight).compareTo(new Double(atm2.getWeight())
+ .intValue());
+ }
+
+ /**
+ * @see Copyable inferface
+ */
+ @Override
+ public AttributeMetadata copy() {
+ return copyTo(new AttributeMetadataImpl());
+ }
+
+ /**
+ * @see Copyable inferface
+ */
+ @Override
+ public AttributeMetadata copyTo(final AttributeMetadata 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/src/skrueger/QualityQuantizable.java
===================================================================
--- trunk/src/skrueger/QualityQuantizable.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/QualityQuantizable.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -0,0 +1,20 @@
+package skrueger;
+
+import java.util.List;
+
+/**
+ * This interface provides methods to request this objects "quality index", a
+ * number between <code>0</code> and <code>1</code>. If quality is
+ * <code>1</code>, translations (=inputs) exist for every supported language.
+ *
+ * @author Stefan A. Tzeggai
+ */
+public interface QualityQuantizable {
+
+ /**
+ * @return a number between <code>0</code> (bad) and <code>1</code> (good)
+ * that is calculated from the amount of translation available.
+ */
+ double getQuality(List<String> languages);
+
+}
Property changes on: trunk/src/skrueger/QualityQuantizable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Added: trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataImplMap.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/AttributeMetadataImplMap.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -0,0 +1,48 @@
+package skrueger.geotools;
+
+import java.util.List;
+
+import org.opengis.feature.type.Name;
+
+import skrueger.AttributeMetadataImpl;
+
+public class AttributeMetadataImplMap extends AttributeMetadataMap<AttributeMetadataImpl> {
+
+ 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;
+ }
+
+
+}
Property changes on: trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataMap.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/AttributeMetadataMap.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -10,34 +10,40 @@
import org.geotools.feature.NameImpl;
import org.opengis.feature.type.Name;
+import skrueger.AbstractAttributeMetadata;
import skrueger.AttributeMetadata;
+import skrueger.QualityQuantizable;
import skrueger.i8n.Translation;
/**
- * The {@link AttributeMetadataMap} is a {@link Map} holding
- * {@link AttributeMetadata} 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 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 AttributeMetadata}
- * on-the-fly.
+ * <code>null</code>, but rather create a default {@link AMD_IMPL} on-the-fly.
*/
-public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
- implements Copyable<AttributeMetadataMap> {
- static private final Logger LOGGER = Logger
+public abstract class AttributeMetadataMap<AMD_IMPL extends AttributeMetadata>
+ 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 AttributeMetadata} on-the-fly. If not initialized by a
- * constructor, it will be {@link Translation#getActiveLang()} only.
+ * 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.
**/
- private final List<String> langs;
+ protected final List<String> langs;
/**
- @Deprecated Use another constructor. AttributeMetadataMap is based on {@link Translation} and
- * would like to know how many languages are supported, so the
- * needed defaults can be created.
+ * 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>();
@@ -56,48 +62,33 @@
* Creates an {@link AttributeMetadataMap} and sets the list of default
* languages.
*/
- public AttributeMetadataMap(final String[] strings) {
- langs = new ArrayList<String>(java.util.Arrays.asList(strings));
+ public AttributeMetadataMap(final String[] langs) {
+ this.langs = new ArrayList<String>(java.util.Arrays.asList(langs));
}
/**
- * Returns a deep-copy. @see {@link Copyable} interface
- */
- @Override
- public AttributeMetadataMap copy() {
- final AttributeMetadataMap copy = new AttributeMetadataMap(langs);
- return copyTo(copy);
- }
-
- /**
* Copies all its values to another {@link AttributeMetadataMap}. @see
* {@link Copyable} interface.
*/
@Override
- public AttributeMetadataMap copyTo(final AttributeMetadataMap amdMap) {
+ public AttributeMetadataMap<? extends AttributeMetadata> copyTo(AttributeMetadataMap amdMap) {
amdMap.clear();
for (final Name key : keySet()) {
- final AttributeMetadata attributeMetaData = get(key);
- amdMap.put(key, attributeMetaData.copy());
+ final AMD_IMPL AMD_IMPL = get(key);
+ amdMap.put(key, AMD_IMPL.copy());
}
return amdMap;
}
/**
- * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
- * returns <code>null</code>, but rather creates a default
- * {@link AttributeMetadata} on the fly.
+ * Returns the {@link AMD_IMPL} for a given {@link Name}. May return
+ * <code>null</code> or create a default {@link AttributeMetadata} depending
+ * on whether this method is overwritten. fly.
*/
- public AttributeMetadata get(final Name name) {
- final AttributeMetadata attributeMetadata = super.get(name);
- if (attributeMetadata == null && name != null
- && !name.getLocalPart().trim().isEmpty()) {
- put(name, new AttributeMetadata(name, langs));
- return super.get(name);
- }
- return attributeMetadata;
+ public AMD_IMPL get(final Name name) {
+ return super.get(name);
}
/**
@@ -105,20 +96,19 @@
*/
@Override
@Deprecated
- public AttributeMetadata get(final Object key) {
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+ public AMD_IMPL get(final Object key) {
+ LOGGER.error("PLEASE DONT USE get(Object) any MORE!");
return super.get(key);
}
/**
- * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
- * returns <code>null</code>, but rather creates a default
- * {@link AttributeMetadata} on the fly.
+ * 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 AttributeMetadata get(final String localName) {
- if (localName == null) return null;
+ public AMD_IMPL get(final String localName) {
+ if (localName == null)
+ return null;
return this.get(new NameImpl(localName));
}
@@ -130,14 +120,15 @@
* @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 AttributeMetadata oneCol : values()) {
+ for (final AMD_IMPL oneCol : values()) {
- if (oneCol.isVisible()) {
+ if (oneCol.isVisible() && oneCol instanceof QualityQuantizable) {
allVisible++;
- colQmSum += oneCol.getQuality(languages);
+ colQmSum += ((QualityQuantizable) oneCol).getQuality(languages);
}
}
@@ -148,25 +139,24 @@
}
-
/**
- * @return List of {@link AttributeMetadata} objects ordered by their
- * weight. (heavier => further down)
+ * @return List of {@link AMD_IMPL} objects ordered by their weight.
+ * (heavier => further down)
*/
- public List<AttributeMetadata> sortedValues() {
- final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
+ public List<AMD_IMPL> sortedValues() {
+ final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
list.addAll(values());
Collections.sort(list);
return list;
}
/**
- * @return List of only the visible {@link AttributeMetadata} objects
- * ordered by their weight. (heavier => further down)
+ * @return List of only the visible {@link AMD_IMPL} objects ordered by
+ * their weight. (heavier => further down)
*/
- public List<AttributeMetadata> sortedValuesVisibleOnly() {
- final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
- for (final AttributeMetadata atm : sortedValues()) {
+ 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);
}
Modified: trunk/src/skrueger/geotools/MapContextManagerInterface.java
===================================================================
--- trunk/src/skrueger/geotools/MapContextManagerInterface.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/MapContextManagerInterface.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -34,7 +34,7 @@
import org.geotools.map.MapLayer;
import org.geotools.map.event.MapLayerListListener;
-import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import skrueger.RasterLegendData;
/**
@@ -83,10 +83,10 @@
List<StyledLayerInterface<?>> getStyledObjects();
/**
- * Returns a list of {@link AttributeMetadata} that shall be shown (e.g. when the Mouse clicked into the map)
+ * Returns a list of {@link AttributeMetadataImpl} that shall be shown (e.g. when the Mouse clicked into the map)
* Returns an empty list if the layer doesn't exist or is not backed by a {@link StyledFeatureCollectionInterface}
*/
- List<AttributeMetadata> getVisibleAttribsFor(MapLayer mapLayer);
+ List<AttributeMetadataImpl> getVisibleAttribsFor(MapLayer mapLayer);
/**
* Returns the title of the layer
Modified: trunk/src/skrueger/geotools/StyledFS.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFS.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledFS.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -50,7 +50,7 @@
import schmitzm.geotools.io.GeoImportUtil;
import schmitzm.geotools.styling.StylingUtil;
-import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import skrueger.i8n.Translation;
import com.vividsolutions.jts.geom.Envelope;
@@ -253,14 +253,13 @@
public AttributeMetadataMap getAttributeMetaDataMap() {
if (map == null) {
- map = new AttributeMetadataMap(new String[] { Translation
- .getActiveLang() });
+ map = new AttributeMetadataImplMap();
// Leaving out the first one, it will be the_geom
for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
- AttributeMetadata attMetaData = new AttributeMetadata(attDesc
+ AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(attDesc
.getName(), map.getLanguages());
map.put(attDesc.getName(), attMetaData);
}
Modified: trunk/src/skrueger/geotools/StyledFeatureCollection.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollection.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledFeatureCollection.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -46,7 +46,7 @@
import org.opengis.filter.Filter;
import schmitzm.geotools.feature.FeatureUtil;
-import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import skrueger.i8n.Translation;
/**
@@ -65,7 +65,7 @@
implements StyledFeatureCollectionInterface {
/** Holds the meta data for displaying a legend. */
- protected AttributeMetadataMap attrMetaData = null;
+ protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaData = null;
/**
* We be filled with a "virtual" {@link FeatureSource} on demand.
@@ -314,12 +314,12 @@
*/
public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
- AttributeMetadataMap metaDataMap = new AttributeMetadataMap();
+ AttributeMetadataMap metaDataMap = new AttributeMetadataImplMap();
SimpleFeatureType ftype = fc.getSchema();
for (int i = 0; i < ftype.getAttributeCount(); i++) {
AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
if (aDesc != ftype.getGeometryDescriptor())
- metaDataMap.put(aDesc.getName(), new AttributeMetadata(aDesc.getName(),
+ metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl(aDesc.getName(),
true, // visible
new Translation(aDesc.getLocalName()), // Column name
new Translation(aDesc.getLocalName()), // description
Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -46,15 +46,16 @@
import schmitzm.geotools.feature.FeatureUtil;
import schmitzm.geotools.gui.FeatureCollectionTableModel;
import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import com.vividsolutions.jts.geom.Envelope;
/**
* This class extends the the {@link FeatureCollectionTableModel} with the
- * functionalities of the {@link AttributeMetadata}.
+ * functionalities of the {@link AttributeMetadataImpl}.
* <ul>
* <li>column names are translated according to
- * {@link AttributeMetadata#getTitle()}</li>
+ * {@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>
@@ -66,8 +67,8 @@
FeatureCollectionTableModel {
final static private Logger LOGGER = Logger
.getLogger(StyledFeatureCollectionTableModel.class);
- /** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */
- protected AttributeMetadataMap amdMap = null;
+ /** Contains the complete {@link AttributeMetadataImpl}-Map of the styled layer. */
+ protected AttributeMetadataMap<? extends AttributeMetadata> 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 **/
@@ -79,7 +80,7 @@
protected String[] colTooltips = null;
/** A cache for the #sortedValuesVisibleOnly() **/
- protected List<AttributeMetadata> amdMapVisibleOnly = null;
+ protected List<? extends AttributeMetadata> amdMapVisibleOnly = null;
/**
* Creates a new table model for a styled layer.
@@ -96,7 +97,7 @@
/**
* This overwritten method filters the values for NODATA-values defined in
- * the {@link AttributeMetadata}
+ * the {@link AttributeMetadataImpl}
*/
@Override
public Object getValueAt(int row, int col) {
@@ -110,12 +111,12 @@
* @param fs
* the feature source
* @param amdm
- * {@link AttributeMetadata}-Map to define the visible attributes
+ * {@link AttributeMetadataImpl}-Map to define the visible attributes
* and translation
*/
protected void setFeatureSource(
FeatureSource<SimpleFeatureType, SimpleFeature> fs,
- AttributeMetadataMap amdm, Filter filter) throws Exception {
+ AttributeMetadataMap<? extends AttributeMetadata> amdm, Filter filter) throws Exception {
if (filter == null)
filter = Filter.INCLUDE;
@@ -169,7 +170,7 @@
* @param fs
* the feature source
* @param amd
- * {@link AttributeMetadata}-Map to define the visible attributes
+ * {@link AttributeMetadataImpl}-Map to define the visible attributes
* and translation
*/
public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
Modified: trunk/src/skrueger/geotools/StyledFeaturesInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeaturesInterface.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledFeaturesInterface.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -35,6 +35,8 @@
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
+import skrueger.AttributeMetadataImpl;
+
/**
* This Interface combines all styled layers that are running on
* {@link FeatureCollection} or {@link FeatureSource}
@@ -46,7 +48,7 @@
*/
public interface StyledFeaturesInterface<T> extends StyledLayerInterface<T> {
- public abstract AttributeMetadataMap getAttributeMetaDataMap();
+ public abstract AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap();
/**
* @return The features of this layer as a {@link FeatureSource}. The filter
Modified: trunk/src/skrueger/geotools/StyledLayerInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerInterface.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledLayerInterface.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -37,7 +37,7 @@
import org.geotools.styling.Style;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import skrueger.RasterLegendData;
import skrueger.i8n.Translation;
@@ -85,11 +85,11 @@
* <ul>
* <li>layer list only depends on {@link StyledLayerInterface}</li>
* <li>methods returning {@link Translation} must not return {@code null}</li>
- * <li>methods returning {@link AttributeMetadata}-Map must not return {@code
+ * <li>methods returning {@link AttributeMetadataImpl}-Map must not return {@code
* null}</li>
- * <li>static helper method to get a new {@link AttributeMetadata}-map withe the
+ * <li>static helper method to get a new {@link AttributeMetadataImpl}-map withe the
* visible attributes only</li>
- * <li>static helper method to create a "default" {@link AttributeMetadata}-map
+ * <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>
Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java 2010-03-18 10:31:23 UTC (rev 768)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java 2010-03-21 11:02:34 UTC (rev 769)
@@ -46,6 +46,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
@@ -92,6 +93,7 @@
import schmitzm.swing.JPanel;
import schmitzm.swing.SwingUtil;
import skrueger.AttributeMetadata;
+import skrueger.AttributeMetadataImpl;
import skrueger.RasterLegendData;
import skrueger.i8n.Translation;
@@ -252,11 +254,15 @@
* TODO replace with
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
*/
- public static AttributeMetadataMap getVisibleAttributeMetaData(
- final AttributeMetadataMap amdMap, final boolean visible) {
+ public static AttributeMetadataMap<? extends AttributeMetadata > getVisibleAttributeMetaData(
+ final AttributeMetadataMap<? extends AttributeMetadata> amdMap,
+ final boolean visible) {
- final AttributeMetadataMap filteredMap = new AttributeMetadataMap(
- amdMap.getLanguages());
+ final AttributeMetadataMap<AttributeMetadata> filteredMap = (AttributeMetadataMap<AttributeMetadata>) amdMap.clone();
+ if (filteredMap.size() > 0 ) {
+ filteredMap.clear(); // Just in case the close copies the contents
+ }
+
for (final AttributeMetadata amd : amdMap.values())
if (amd.isVisible() == visible)
filteredMap.put(amd.getName(), amd);
@@ -265,8 +271,8 @@
}
/**
- * Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}.
- * This method works like {@link
+ * 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,
@@ -277,7 +283,8 @@
* @param element
* {@link Element} to parse
*/
- public static AttributeMetadata parseAttributeMetaData(final Element element) {
+ public static AttributeMetadataImpl parseAttributeMetaData(
+ final Element element) {
final String namespace = String.valueOf(element
.getAttributeValue("namespace"));
final String localname = String.valueOf(element
@@ -298,35 +305,35 @@
else if (childElement.getName().equals("desc"))
desc = parseTranslation(childElement);
}
- return new AttributeMetadata(aName, visible, name, desc, unit);
+ return new AttributeMetadataImpl(aName, visible, name, desc, unit);
}
/**
- * Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with
- * {@code <attribute>}-childs.
+ * 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 AttributeMetadata} class has more
- * attributes which are not used by Xulu/ISDSS. GP
+ * 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 AttributeMetadataMap();
+ final AttributeMetadataMap metaData = new AttributeMetadataImplMap();
final List<Element> attributesElements = element
.getChildren(ELEM_NAME_ATTRIBUTE);
for (final Element attibuteElement : attributesElements) {
- final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);
+ final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement);
metaData.put(attrMetaData.getName(), attrMetaData);
}
return metaData;
}
/**
- * Loads a {@link AttributeMetadata} object from an URL.
+ * Loads a {@link AttributeMetadataImpl} object from an URL.
*
* @param documentUrl
* {@link URL} to parse
@@ -339,14 +346,14 @@
}
/**
- * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
- * object.
+ * 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 AttributeMetadata} class has more
- * attributes which are not used by Xulu/ISDSS. GP
+ * 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)
*/
@@ -366,14 +373,14 @@
}
/**
- * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
- * map.
+ * Creates an JDOM {@link Element} for the given
+ * {@link AttributeMetadataImpl} map.
*
* @param amdMap
* map of attribute meta data
*/
public static Element createAttributeMetaDataMapElement(
- final AttributeMetadataMap amdMap) {
+ final AttributeMetadataMap<? extends AttributeMetadata> amdMap) {
final Element element = new Element(ELEM_NAME_AMD, AMLURI);
for (final AttributeMetadata amd : amdMap.values())
element.addContent(createAttributeMetaDataElement(amd));
@@ -381,10 +388,10 @@
}
/**
- * Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL.
+ * Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL.
*
* @param amdMap
- * map of {@link AttributeMetadata}
+ * map of {@link AttributeMetadataImpl}
* @param documentUrl
* {@link URL} to store the XML
*/
@@ -791,9 +798,10 @@
}
/**
- * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata
- * AttributeMetaData-Map} for a given geo-object (feature) source. The SLD
- * file must be present. A missing attribute meta-data file is tolerated.
+ * 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
@@ -836,8 +844,8 @@
/**
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
- * {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd}
- * file for a given geo-object (feature) source. The SLD file must be
+ * {@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
@@ -897,8 +905,8 @@
/**
* Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the
- * meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a
- * {@code .rld} or {@code .amd} file. for a given geo-object source.
+ * 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
@@ -951,7 +959,8 @@
for (final Rule rule : rules) {
// Check if this RULE shall actually appear in the legend
- if (rule.getName() != null && rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))
+ if (rule.getName() != null
+ && rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))
continue;
/**
@@ -1240,10 +1249,12 @@
* in the XML. But the DBF may have changed!
*/
public static void checkAttribMetaData(
- AttributeMetadataMap attributeMetaDataMap, SimpleFeatureType schema) {
-
- if (schema == null) throw new IllegalArgumentException("schmema may not be null!");
+ 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.
@@ -1278,9 +1289,10 @@
if (ad instanceof GeometryDescriptor)
continue;
if (!attributeMetaDataMap.containsKey(ad.getName())) {
- attributeMetaDataMap.put(ad.getName(), new AttributeMetadata(
- ad, schema.getAttributeDescriptors().indexOf(ad),
- attributeMetaDataMap.getLanguages()));
+ attributeMetaDataMap.put(ad.getName(),
+ new AttributeMetadataImpl(ad, schema
+ .getAttributeDescriptors().indexOf(ad),
+ attributeMetaDataMap.getLanguages()));
}
}
}
@@ -1294,7 +1306,8 @@
* @param schema
*/
public static void addEmptyStringToAllTextualAttributes(
- AttributeMetadataMap attributeMetaDataMap, SimpleFeatureType schema) {
+ AttributeMetadataMap<? extends AttributeMetadata> attributeMetaDataMap,
+ SimpleFeatureType schema) {
for (Name name : attributeMetaDataMap.keySet()) {
if (String.class.isAssignableFrom(schema.getDescriptor(name)
@@ -1303,4 +1316,31 @@
}
}
}
+
+ /**
+ * @return a nicely formatted String containing all NODATA values of any
+ * {@link AttributeMetadata} 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;
+ }
}
More information about the Schmitzm-commits
mailing list