/[schmitzm]/trunk/src/skrueger/AttributeMetadataInterface.java
ViewVC logotype

Diff of /trunk/src/skrueger/AttributeMetadataInterface.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/2.0-RC1/src/skrueger/AttributeMetadata.java revision 604 by alfonx, Wed Dec 9 14:15:53 2009 UTC trunk/src/skrueger/AttributeMetadata.java revision 769 by alfonx, Sun Mar 21 11:02:34 2010 UTC
# Line 1  Line 1 
 /*******************************************************************************  
  * 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  
  ******************************************************************************/  
1  package skrueger;  package skrueger;
2    
3  import java.util.ArrayList;  import java.util.HashSet;
 import java.util.List;  
4    
 import org.apache.log4j.Logger;  
 import org.geotools.feature.NameImpl;  
 import org.opengis.feature.type.AttributeDescriptor;  
5  import org.opengis.feature.type.Name;  import org.opengis.feature.type.Name;
6    
7  import skrueger.geotools.Copyable;  import skrueger.geotools.Copyable;
 import skrueger.geotools.StyledLayerInterface;  
 import skrueger.i8n.I8NUtil;  
8  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
9    
10  /**  public interface AttributeMetadata extends Copyable<AttributeMetadata>,
  * This class holds meta information about an attribute/column. This information  
  * is used by {@link StyledLayerInterface} and many others.<br/>  
  *  
  * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>  
  */  
 public class AttributeMetadata implements Copyable<AttributeMetadata>,  
11                  Comparable<AttributeMetadata> {                  Comparable<AttributeMetadata> {
           
         static private final Logger LOGGER = Logger  
                         .getLogger(AttributeMetadata.class);  
   
         /** Translation of the attribute's description **/  
         protected Translation desc = new Translation();  
   
         /**  
          * 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.;  
   
         /** The Name of the attribute **/  
         private Name name;  
12    
13          /**          /**
14           * Allows to define general NODATA values for an attribute. e.g. -9999 can           * @return a translatable title for this attribute..
15           * be set and will always be interpreted as NULL internally and will usually           */
16           * be ignored. TODO not implemented yet          public Translation getTitle();
          **/  
         protected List<Object> nodataValues = new ArrayList<Object>();  
   
         /** Translation of the attribute's title **/  
         protected Translation title = new Translation();  
   
         /**  
          * The unit append to all visualizations of values of this attribute (is not  
          * null)  
          **/  
         protected String unit = "";  
   
         /** Is the attribute visible to the user or ignored where possible **/  
         protected boolean visible = true;  
17    
18          /**          /**
19           * When listed, the attributes are listed according to their {@link #weight} (heavier           * Set a translatable title for this attribute..
20           * => further down)           */
21           * @see #compareTo(AttributeMetadata)          public void setTitle(Translation title);
          **/  
         protected int weight = 0;  
   
         /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/  
         private AttributeMetadata() {  
         }  
   
         public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,  
                         final List<String> langs) {  
                 this(attDesc.getName(), langs);  
                 setWeight(weight);  
         }  
   
         public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {  
                 this(attDesc.getName(), langs);  
         }  
22    
23          /**          /**
24           * Creates an {@link AttributeMetadata} object with the following           * @return a translatable description for this attribute
25           * information           */
26           *          public Translation getDesc();
          * @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;  
                 this.visible = visible;  
                 this.unit = unit;  
         }  
   
         /**  
          * Creates a new visible {@link AttributeMetadata}  
          */  
         public AttributeMetadata(final Name name, final List<String> langs) {  
                 this(name, true, new Translation(langs, name.getLocalPart()),  
                                 new Translation(), "");  
         }  
   
         /**  
          * Creates a new visible {@link AttributeMetadata}  
          */  
         public AttributeMetadata(final Name name, final String defaultTitle,  
                         final List<String> langs) {  
                 this(name, true, new Translation(langs, defaultTitle),  
                                 new Translation(), "");  
         }  
27    
28          /**          /**
29           * Creates an {@link AttributeMetadata} object with the following           * Set a translatable description for this attribute.
          * 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  
30           */           */
31          public AttributeMetadata(final String localName, final Boolean visible,          public void setDesc(Translation desc);
                         final Translation title, final Translation desc, final String unit) {  
                 this(new NameImpl(localName), true, title, desc, "");  
         }  
32    
33          /**          /**
34           * 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}.
35           */           */
36          public AttributeMetadata(final String localName, final List<String> langs) {          public String getLocalName();
                 this(localName, true, new Translation(langs, localName),  
                                 new Translation(), "");  
         }  
37    
38          /**          /**
39           * Creates a new visible {@link AttributeMetadata}           * A short form for #setName(new NameImpl(localName))
40           */           */
41          public AttributeMetadata(final String localName, final String defaultTitle,          public void setLocalName(String localName);
                         final List<String> langs) {  
                 this(localName, true, new Translation(langs, defaultTitle),  
                                 new Translation(), "");  
         }  
42    
43          /**          /**
44           * Orders the attributes according to their {@link #weight}. Heavier =>           * The fully qualified {@link Name} of the attribute, e.g.
45           * further down.           * <code>org.bla.plo:blub</code>. The second part equals the
46             * {@link #getLocalName()} value. The first may be <code>null</code> or
47             * represent the layer name.
48           */           */
49          @Override          public Name getName();
         public int compareTo(final AttributeMetadata atm2) {  
                 return new Integer(weight).compareTo(atm2.getWeight());  
         }  
50    
51          /**          /**
52           * @see Copyable inferface           * set the fully qualified {@link Name} of this attribute.
53           */           */
54          @Override          public void setName(Name name);
         public AttributeMetadata copy() {  
                 return copyTo(new AttributeMetadata());  
         }  
55    
56          /**          /**
57           * @see Copyable inferface           * A list og objects that represent NODATA-values for this attribute. The
58             * objects are supporsed to be correctly casted already. That means that the
59             * NODATA objects listed here have must have the same type as the values of
60             * this object.
61           */           */
62          @Override          public HashSet<Object> getNodataValues();
         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());  
                 amd.setFunctionX(getFunctionX());  
                 amd.setFunctionA(getFunctionA());  
   
                 for (final Object nodataValue : getNodataValues()) {  
                         amd.getNodataValues().add(nodataValue);  
                 }  
   
                 return amd;  
         }  
   
         public Translation getDesc() {  
                 return desc;  
         }  
   
         public Double getFunctionA() {  
                 return functionA;  
         }  
   
         public Double getFunctionX() {  
                 return functionX;  
         }  
63    
64          /**          /**
65           * The local name. E.g. the name of the DBF column as a {@link String}           * Takes any value object and checks it against the NODATA values. If the
66             * value equals a NODATA value, <code>null</code> is returned. Otherwise the
67             * same object is returned.
68             *
69             * Note: This method is called often.
70           */           */
71          public String getLocalName() {          public Object fiterNodata(Object value);
                 return getName().getLocalPart();  
         }  
72    
73          /**          /**
74           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>           * @return a non-translatable unit {@link String} for this attribute values.
75           */           */
76          public Name getName() {          public String getUnit();
                 return name;  
         }  
   
         public List<Object> getNodataValues() {  
                 return nodataValues;  
         }  
77    
78          /**          /**
79           * @return a number between 0 (bad) and 1 (good) that is calculated from the           * Set a unit {@link String} for this attribute values.
          *         amount of translation available. If this attribute is not  
          *         {@link #visible}, it will return 1.  
80           */           */
81          public double getQuality(final List<String> languages) {          public void setUnit(String unit);
   
                 if (!isVisible())  
                         return 1.;  
   
                 return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil  
                                 .qmTranslation(languages, getDesc()) * 1.) / 3.;  
         }  
   
         public Translation getTitle() {  
                 return title;  
         }  
   
         public String getUnit() {  
                 return unit;  
         }  
   
         public int getWeight() {  
                 return weight;  
         }  
82    
83          /**          /**
84           * Will the end-user see this attribute?           * @return A value defining the position of this attribute whenever the
85             *         attributes are listed to an end-user. The higher the weight, the
86             *         lower the position. (heavy goes down, light goes up)
87           */           */
88          public boolean isVisible() {          public double getWeight();
                 return visible;  
         }  
   
         public void setDesc(final Translation desc) {  
                 this.desc = desc;  
         }  
   
         public void setFunctionA(final Double functionA) {  
                 this.functionA = functionA;  
         }  
   
         public void setFunctionX(final Double functionX) {  
                 this.functionX = functionX;  
         }  
89    
90          /**          /**
91           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * set a value defining the position of this attribute whenever the
92             * attributes are listed to an end-user. The higher the weight, the lower
93             * the position. (heavy goes down, light goes up)
94           */           */
95          public void setLocalName(final String localName) {          public void setWeight(double weight);
                 this.name = new NameImpl(localName);  
         }  
96    
97          /**          /**
98           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>           * @return <code>false</code> if this attribute should not be selectable or
99             *         shown to the end-user.
100           */           */
101          public void setName(final Name name) {          public boolean isVisible();
                 this.name = name;  
         }  
   
         public void setNodataValues(final List<Object> nodataValues) {  
                 this.nodataValues = nodataValues;  
         }  
   
         public void setTitle(final Translation title) {  
                 this.title = title;  
         }  
   
         public void setUnit(final String unit) {  
                 this.unit = unit;  
         }  
   
         public void setVisible(final boolean visible) {  
                 this.visible = visible;  
         }  
102    
103          /**          /**
104           * Shall the end-user see this attribute?           * Set <code>false</code> if this attribute should not be shown to the
105           * @param visible           * end-user.
106           */           */
107          public void setVisible(final Boolean visible) {          public void setVisible(boolean visible);
 //              // The THE_GEOM and shall never be visible!  
 //              if (name.getLocalPart().equalsIgnoreCase("the_geom"))  
 //                      this.visible = false;  
 //              else  
 //                      this.visible = visible;  
108    
109                  this.visible = visible;          String getNoDataValuesFormatted();
         }  
110    
         public void setWeight(final int weight) {  
                 this.weight = weight;  
         }  
           
         /**  
          * For nicer debugging  
          */  
         @Override  
         public String toString() {  
                 StringBuffer sb = new StringBuffer();  
                 if (name != null) sb.append(name.toString()+" ");  
                 sb.append("weight="+weight+" ");  
                 sb.append("title="+getTitle().toString());  
                 return sb.toString();  
         }  
111  }  }

Legend:
Removed from v.604  
changed lines
  Added in v.769

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26