--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/14 16:20:26 470
+++ trunk/src/skrueger/AttributeMetadataImpl.java 2010/05/22 01:24:46 862
@@ -25,10 +25,13 @@
*
* Contributors:
* Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Krüger - additional utility classes
+ * Stefan A. Tzeggai - 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;
@@ -36,27 +39,50 @@
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}.
+ * is used by {@link StyledLayerInterface} and many others.
*
* @author Stefan Alfons Krüger
*/
-public class AttributeMetadata implements Copyable {
+public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
+ QualityQuantizable {
+
static private final Logger LOGGER = Logger
- .getLogger(AttributeMetadata.class);
+ .getLogger(AttributeMetadataImpl.class);
- protected Translation title = new Translation();
- protected Translation desc = new Translation();
- protected boolean visible = true;
- protected String unit = "";
- protected int colIdx;
- private Name name;
+ /**
+ * For numerical attributes the value can be transformed by VALUE*X+A when
+ * presented on screen. TODO not implemented yet
+ **/
+ protected Double functionA = 0.;
/**
- * Creates an {@link AttributeMetadata} object with the following
+ * 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( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
+ setWeight(weight);
+ }
+
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final List langs) {
+ this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataImpl} object with the following
* information
*
* @param colIdx
@@ -71,21 +97,54 @@
* @param unit
* {@link String} of the unit that the information is in
*/
- public AttributeMetadata(final Name name, final Boolean visible,
+ 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;
-
- // The THE_GEOM and shall never be visible!
- if (name.getLocalPart().equalsIgnoreCase("the_geom")) this.visible = false;
-
+ 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 an {@link AttributeMetadata} object with the following
+ * 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
@@ -97,127 +156,108 @@
* @param unit
* {@link String} of the unit that the information is in
*/
- public AttributeMetadata(final String localName, final Boolean visible,
+ 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 AttributeMetadata} with default (no) values.
+ * Creates a new visible {@link AttributeMetadataImpl} with default (no)
+ * values.
*/
- public AttributeMetadata(final String localName, final String defaultTitle) {
- this(localName, true, new Translation(defaultTitle), new Translation(),
- "");
+ public AttributeMetadataImpl(final String localName,
+ final List langs) {
+ this(localName, true, new Translation(langs, localName),
+ new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * Creates a new visible {@link AttributeMetadataImpl}
*/
- public AttributeMetadata(final Name name, final String defaultTitle) {
- this(name, true, new Translation(defaultTitle), new Translation(), "");
+ public AttributeMetadataImpl(final String localName,
+ final String defaultTitle, final List langs) {
+ this(localName, true, new Translation(langs, defaultTitle),
+ new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * Orders the attributes according to their {@link #weight}. Heavier =>
+ * further down.
*/
- public AttributeMetadata(final Name name) {
- this(name, true, new Translation(name.getLocalPart()),
- new Translation(), "");
+ @Override
+ public int compareTo(final AttributeMetadataInterface atm2) {
+ return new Integer(weight).compareTo(new Double(atm2.getWeight())
+ .intValue());
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * @see Copyable inferface
*/
- 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());
+ @Override
+ public AttributeMetadataInterface copy() {
+ return copyTo(new AttributeMetadataImpl());
}
- public boolean isVisible() {
- return visible;
- }
+ /**
+ * @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()));
- 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;
-// }
+ amd.setWeight(getWeight());
- public Translation getTitle() {
- return title;
- }
+ if (amd instanceof AttributeMetadataImpl) {
+ AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
- public void setTitle(final Translation title) {
- this.title = title;
- }
+ amd_.setFunctionX(getFunctionX());
+ amd_.setFunctionA(getFunctionA());
+ amd_.setNodataValues(getNodataValues());
+ }
- public Translation getDesc() {
- return desc;
+ return amd;
}
- public void setDesc(final Translation desc) {
- this.desc = desc;
+ // only to be used by copyTo()
+ private void setNodataValues(HashSet