--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/13 13:22:31 464 +++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/11/18 09:54:52 523 @@ -29,6 +29,9 @@ ******************************************************************************/ package skrueger; +import java.util.ArrayList; +import java.util.List; + import org.apache.log4j.Logger; import org.geotools.feature.NameImpl; import org.opengis.feature.type.AttributeDescriptor; @@ -36,24 +39,109 @@ 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 AttributeMetadata implements Copyable, + Comparable { static private final Logger LOGGER = Logger .getLogger(AttributeMetadata.class); + // public class WeightComparator implements Comparator + // { + // + // @Override + // public int compare(AttributeDescriptor o1, AttributeDescriptor o2) { + // // TODO Auto-generated method stub + // return 0; + // } + // + // }; + + /** Translation of the attribute's title **/ protected Translation title = new Translation(); + + /** Translation of the attribute's description **/ protected Translation desc = new Translation(); + + /** Is the attribute visible to the user or ignored where possible **/ protected boolean visible = true; + + /** + * The unit append to all visualizations of values of this attribute (is not + * null) + **/ protected String unit = ""; - protected int colIdx; - private org.opengis.feature.type.Name name; + + /** The Name of the attribute **/ + private Name name; + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public List getNodataValues() { + return nodataValues; + } + + public void setNodataValues(List nodataValues) { + this.nodataValues = nodataValues; + } + + public Double getFunctionX() { + return functionX; + } + + public void setFunctionX(Double functionX) { + this.functionX = functionX; + } + + public Double getFunctionA() { + return functionA; + } + + public void setFunctionA(Double functionA) { + this.functionA = functionA; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + /** + * When listed, the attributes are listed according to their weight (heavier + * => further down) + **/ + protected int weight = 0; + + /** + * 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. + **/ + protected List nodataValues = new ArrayList(); + + /** + * For numerical attributes the value can be transformed by VALUE*X+A when + * presented on screen + **/ + protected Double functionX = 1.; + + /** + * For numerical attributes the value can be transformed by VALUE*X+A when + * presented on screen + **/ + protected Double functionA = 0.; /** * Creates an {@link AttributeMetadata} object with the following @@ -77,10 +165,13 @@ 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; - + if (name.getLocalPart().equalsIgnoreCase("the_geom")) + this.visible = false; + else + this.visible = visible; + this.unit = unit; } @@ -140,18 +231,25 @@ this(attDesc.getName()); } + public AttributeMetadata(AttributeDescriptor attDesc, int weight) { + this(attDesc.getName()); + setWeight(weight); + } + public boolean isVisible() { return visible; } public void setVisible(final Boolean visible) { + + // The THE_GEOM and shall never be visible! // TODO MAKE BETTER + if (name.getLocalPart().equalsIgnoreCase("the_geom")) + this.visible = false; + else + this.visible = 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; @@ -183,14 +281,23 @@ getDesc().copyTo(amd.getDesc()); amd.setUnit(getUnit()); amd.setVisible(isVisible()); - amd.setName(new NameImpl(getName().getNamespaceURI(), getName().getLocalPart())); + amd.setName(new NameImpl(getName().getNamespaceURI(), getName() + .getLocalPart())); + + amd.setWeight(getWeight()); + amd.setFunctionX(getFunctionX()); + amd.setFunctionA(getFunctionA()); + + for (Object nodataValue : getNodataValues()) { + amd.getNodataValues().add(nodataValue); + } return amd; } @Override public AttributeMetadata copy() { - return copyTo( new AttributeMetadata()); + return copyTo(new AttributeMetadata()); } /** @@ -220,4 +327,22 @@ public void setLocalName(String localName) { this.name = new NameImpl(localName); } + + /** + * Orders the Attributes according to their weight. Heavier => further down. + */ + @Override + public int compareTo(AttributeMetadata atm2) { + // Double double1 = new Double(1./weight); + // double double2 = 1./atm2.getWeight(); + return new Integer(weight).compareTo(atm2.getWeight()); + } + + /** + * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes + */ + public double getQuality(List languages) { + return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil + .qmTranslation(languages, getDesc()) * 1.) / 3.; + } }