--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/14 22:48:50 472 +++ trunk/src/skrueger/AttributeMetadata.java 2010/03/21 11:36:11 770 @@ -1,228 +1,112 @@ -/******************************************************************************* - * 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 org.apache.log4j.Logger; +import java.util.HashSet; + 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.Translation; -/** - * This class holds meta information about an attribute/column. This information - * is used by {@link StyledLayerInterface}. - * - * @author Stefan Alfons Krüger - */ -public class AttributeMetadata implements Copyable { - static private final Logger LOGGER = Logger - .getLogger(AttributeMetadata.class); - - protected Translation title = new Translation(); - protected Translation desc = new Translation(); - protected boolean visible = true; - protected String unit = ""; - protected int colIdx; - private Name name; +public interface AttributeMetadata extends Copyable, + Comparable { /** - * 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 - */ - public AttributeMetadata(final Name name, final Boolean visible, - final Translation title, final Translation desc, final String unit) { - - this.setName(name); - this.title = title; - this.desc = desc; - - // The THE_GEOM and shall never be visible! - if (name.getLocalPart().equalsIgnoreCase("the_geom")) - this.visible = false; - else - this.visible = visible; - - this.unit = unit; - } + * @return a translatable title for this attribute.. + */ + public Translation getTitle(); /** - * 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 + * Set a translatable title for this attribute.. */ - 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 void setTitle(Translation title); /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * @return a translatable description for this attribute */ - public AttributeMetadata(final String localName, final String defaultTitle) { - this(localName, true, new Translation(defaultTitle), new Translation(), - ""); - } + public Translation getDesc(); /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * Set a translatable description for this attribute. */ - public AttributeMetadata(final Name name, final String defaultTitle) { - this(name, true, new Translation(defaultTitle), new Translation(), ""); - } + public void setDesc(Translation desc); /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * The local name. E.g. the name of the DBF column as a {@link String}. */ - public AttributeMetadata(final Name name) { - this(name, true, new Translation(name.getLocalPart()), - new Translation(), ""); - } + 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) { - this(localName, true, new Translation(localName), new Translation(), ""); - } - - /** Only used for {@link Copyable#copy()} **/ - private AttributeMetadata() { - } - - public AttributeMetadata(AttributeDescriptor attDesc) { - this(attDesc.getName()); - } + public void setLocalName(String localName); - public boolean isVisible() { - return visible; - } - - public void setVisible(final Boolean visible) { - this.visible = visible; - } - - // - // /** @return the index of this attribute in the underlying table/dbf **/ - // public int getColIdx() { - // return colIdx; - // } - - public Translation getTitle() { - return title; - } - - public void setTitle(final Translation title) { - this.title = title; - } - - public Translation getDesc() { - return desc; - } - - public void setDesc(final Translation desc) { - this.desc = desc; - } + /** + * The fully qualified {@link Name} of the attribute, e.g. + * org.bla.plo:blub. The second part equals the + * {@link #getLocalName()} value. The first may be null or + * represent the layer name. + */ + public NameImpl getName(); - public String getUnit() { - return unit; - } + /** + * set the fully qualified {@link Name} of this attribute. + */ + public void setName(NameImpl name); - public void setUnit(final String unit) { - this.unit = unit; - } + /** + * 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 getNodataValues(); - @Override - public AttributeMetadata copyTo(AttributeMetadata amd) { - getTitle().copyTo(amd.getTitle()); - getDesc().copyTo(amd.getDesc()); - amd.setUnit(getUnit()); - amd.setVisible(isVisible()); - amd.setName(new NameImpl(getName().getNamespaceURI(), getName() - .getLocalPart())); + /** + * Takes any value object and checks it against the NODATA values. If the + * value equals a NODATA value, null is returned. Otherwise the + * same object is returned. + * + * Note: This method is called often. + */ + public Object fiterNodata(Object value); - return amd; - } + /** + * @return a non-translatable unit {@link String} for this attribute values. + */ + public String getUnit(); - @Override - public AttributeMetadata copy() { - return copyTo(new AttributeMetadata()); - } + /** + * Set a unit {@link String} for this attribute values. + */ + public void setUnit(String unit); /** - * The local Name. E.g. the name of the DBF column as a String + * @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 String getLocalName() { - return getName().getLocalPart(); - } + public double getWeight(); /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub + * 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 Name getName() { - return name; - } + public void setWeight(double weight); /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub + * @return false if this attribute should not be selectable or + * shown to the end-user. */ - public void setName(org.opengis.feature.type.Name name) { - this.name = name; - } + public boolean isVisible(); /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub + * Set false if this attribute should not be shown to the + * end-user. */ - public void setLocalName(String localName) { - this.name = new NameImpl(localName); - } + public void setVisible(boolean visible); + + String getNoDataValuesFormatted(); + }