--- trunk/src/skrueger/AttributeMetaData.java 2009/02/24 22:43:52 2
+++ trunk/src/skrueger/AttributeMetadataImpl.java 2010/03/21 11:02:34 769
@@ -1,88 +1,263 @@
-package skrueger;
-
-import org.apache.log4j.Logger;
-
-import skrueger.geotools.StyledMapInterface;
-import skrueger.i8n.Translation;
-
-/**
- * This class holds meta information about an attribute/column. This
- * information is used by {@link StyledMapInterface}.
- *
- * @author Stefan Alfons Krüger
- */
-public class AttributeMetaData {
- static private final Logger LOGGER = Logger
- .getLogger(AttributeMetaData.class);
- protected Translation title = new Translation();
- protected Translation desc = new Translation();
- protected boolean visible = false;
- protected String unit = "";
- protected int colIdx;
-
- /**
- * 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 int colIdx, final Boolean visible,
- final Translation title, final Translation desc, final String unit) {
-
- this.colIdx = colIdx;
- this.title = title;
- this.desc = desc;
- if (colIdx == 0){
- // The first attribut is THE_GEOM and shall never be visible!
- this.visible = false;
- }else
- this.visible = visible;
- this.unit = unit;
- }
-
- /**
- * Creates a {@link AttributeMetaData} with default (no) values.
- */
- public AttributeMetaData(final Integer col, final String defaultName) {
- this(col, true, new Translation(defaultName), new Translation(""), "");
- }
-
- 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;
- }
-
- public String getUnit() {
- return unit;
- }
-
- public void setUnit(final String unit) {
- this.unit = unit;
- }
-}
+/*******************************************************************************
+ * 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.
+ *
+ * @author Stefan Alfons Krüger
+ */
+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#copy()} **/
+ private AttributeMetadataImpl() {
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final int weight, final List langs) {
+ this(attDesc.getName(), langs);
+ setWeight(weight);
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final List 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 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 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 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 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