--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/13 13:22:31 464 +++ trunk/src/skrueger/AttributeMetadataImpl.java 2010/03/21 11:02:34 769 @@ -29,6 +29,9 @@ ******************************************************************************/ 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); + + /** + * 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); + } - protected Translation title = new Translation(); - protected Translation desc = new Translation(); - protected boolean visible = true; - protected String unit = ""; - protected int colIdx; - private org.opengis.feature.type.Name name; + public AttributeMetadataImpl(final AttributeDescriptor attDesc, + final List langs) { + this(attDesc.getName(), langs); + } /** - * Creates an {@link AttributeMetadata} object with the following + * 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 AttributeMetadata} object with the following + * 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 @@ -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 AttributeMetadata 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() { + @Override + public AttributeMetadata copy() { + return copyTo(new AttributeMetadataImpl()); } - public AttributeMetadata(AttributeDescriptor attDesc) { - this(attDesc.getName()); - } + /** + * @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())); - public boolean isVisible() { - return visible; - } + amd.setWeight(getWeight()); - 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; -// } + if (amd instanceof AttributeMetadataImpl) { + AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd; - public Translation getTitle() { - return title; - } + amd_.setFunctionX(getFunctionX()); + amd_.setFunctionA(getFunctionA()); + amd_.setNodataValues(getNodataValues()); + } - public void setTitle(final Translation title) { - this.title = title; + return amd; } - public Translation getDesc() { - return desc; + // only to be used by copyTo() + private void setNodataValues(HashSet nodataValues_) { + nodataValues = nodataValues_; } - public void setDesc(final Translation desc) { - this.desc = desc; + public Double getFunctionA() { + return functionA; } - public String getUnit() { - return unit; - } - - public void setUnit(final String unit) { - this.unit = unit; + 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 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())); + public double getQuality(final List languages) { - return amd; - } + if (!isVisible()) + return 1.; - @Override - public AttributeMetadata copy() { - return copyTo( new AttributeMetadata()); + return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil + .qmTranslation(languages, getDesc()) * 1.) / 3.; } - /** - * The local Name. E.g. the name of the DBF column as a String - */ - public String getLocalName() { - return getName().getLocalPart(); + public void setFunctionA(final Double functionA) { + this.functionA = functionA; } - /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub - */ - public Name getName() { - return name; + public void setFunctionX(final Double functionX) { + this.functionX = functionX; } - /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub - */ - public void setName(org.opengis.feature.type.Name name) { - this.name = name; - } - /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub - */ - public void setLocalName(String localName) { - this.name = new NameImpl(localName); - } }