/[schmitzm]/branches/2.1/src/skrueger/AttributeMetadataInterface.java
ViewVC logotype

Diff of /branches/2.1/src/skrueger/AttributeMetadataInterface.java

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

branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java revision 533 by alfonx, Thu Nov 19 17:27:01 2009 UTC trunk/src/skrueger/AttributeMetadataInterface.java revision 797 by alfonx, Sat Apr 10 16:12:40 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;  
5  import org.geotools.feature.NameImpl;  import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.AttributeDescriptor;  
6  import org.opengis.feature.type.Name;  import org.opengis.feature.type.Name;
7    
8  import skrueger.geotools.Copyable;  import skrueger.geotools.Copyable;
 import skrueger.geotools.StyledLayerInterface;  
 import skrueger.i8n.I8NUtil;  
9  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
10    
11  /**  public interface AttributeMetadataInterface extends Copyable<AttributeMetadataInterface>,
12   * This class holds meta information about an attribute/column. This information                  Comparable<AttributeMetadataInterface> {
  * 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>,  
                 Comparable<AttributeMetadata> {  
         static private final Logger LOGGER = Logger  
                         .getLogger(AttributeMetadata.class);  
   
         // public class WeightComparator implements Comparator<AttributeDescriptor>  
         // {  
         //  
         // @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 = "";  
   
         /** The Name of the attribute **/  
         private Name name;  
   
         public int getWeight() {  
                 return weight;  
         }  
   
         public void setWeight(int weight) {  
                 this.weight = weight;  
         }  
   
         public List<Object> getNodataValues() {  
                 return nodataValues;  
         }  
   
         public void setNodataValues(List<Object> 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<Object> nodataValues = new ArrayList<Object>();  
   
         /**  
          * 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.;  
13    
14          /**          /**
15           * Creates an {@link AttributeMetadata} object with the following           * @return a translatable title for this attribute..
16           * information           */
17           *          public Translation getTitle();
          * @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;  
   
                 // The THE_GEOM and shall never be visible!  
                 if (name.getLocalPart().equalsIgnoreCase("the_geom"))  
                         this.visible = false;  
                 else  
                         this.visible = visible;  
   
                 this.unit = unit;  
         }  
18    
19          /**          /**
20           * Creates an {@link AttributeMetadata} object with the following           * Set a translatable title 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  
21           */           */
22          public AttributeMetadata(final String localName, final Boolean visible,          public void setTitle(Translation title);
23                          final Translation title, final Translation desc, final String unit) {          
                 this(new NameImpl(localName), true, title, desc, "");  
         }  
   
24          /**          /**
25           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Set an untranslated title for this attribute or pass a {@link Translation} encryped as a {@link String}
26           */           */
27          public AttributeMetadata(final String localName, final String defaultTitle, List<String> langs) {          public void setTitle(String title);
                 this(localName, true, new Translation(langs, defaultTitle), new Translation(),  
                                 "");  
         }  
28    
29          /**          /**
30           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * @return a translatable description for this attribute
31           */           */
32          public AttributeMetadata(final Name name, final String defaultTitle, List<String> langs) {          public Translation getDesc();
                 this(name, true, new Translation(langs, defaultTitle), new Translation(), "");  
         }  
33    
34          /**          /**
35           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Set a translatable description for this attribute.
36           */           */
37          public AttributeMetadata(final Name name, List<String> langs) {          public void setDesc(Translation desc);
                 this(name, true, new Translation(langs, name.getLocalPart()),  
                                 new Translation(), "");  
         }  
38    
39          /**          /**
40           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Set an untranslated description for this attribute or pass a {@link Translation} encryped as a {@link String}  
41           */           */
42          public AttributeMetadata(final String localName, List<String> langs) {          public void setDesc(String desc);
                 this(localName, true, new Translation(langs, localName), new Translation(), "");  
         }  
   
         /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/  
         private AttributeMetadata() {  
         }  
   
         public AttributeMetadata(AttributeDescriptor attDesc, List<String> langs) {  
                 this(attDesc.getName(), langs);  
         }  
   
         public AttributeMetadata(AttributeDescriptor attDesc, int weight, List<String> langs) {  
                 this(attDesc.getName(), langs);  
                 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;  
         }  
   
         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;  
         }  
43    
         public String getUnit() {  
                 return unit;  
         }  
44    
45          public void setUnit(final String unit) {          /**
46                  this.unit = unit;           * The local name. E.g. the name of the DBF column as a {@link String}.
47          }           */
48            public String getLocalName();
49    
50          @Override          /**
51          public AttributeMetadata copyTo(AttributeMetadata amd) {           * A short form for #setName(new NameImpl(localName))
52                  getTitle().copyTo(amd.getTitle());           */
53                  getDesc().copyTo(amd.getDesc());          public void setLocalName(String localName);
                 amd.setUnit(getUnit());  
                 amd.setVisible(isVisible());  
                 amd.setName(new NameImpl(getName().getNamespaceURI(), getName()  
                                 .getLocalPart()));  
54    
55                  amd.setWeight(getWeight());          /**
56                  amd.setFunctionX(getFunctionX());           * The fully qualified {@link Name} of the attribute, e.g.
57                  amd.setFunctionA(getFunctionA());           * <code>org.bla.plo:blub</code>. The second part equals the
58             * {@link #getLocalName()} value. The first may be <code>null</code> or
59             * represent the layer name.
60             */
61            public Name getName();
62    
63                  for (Object nodataValue : getNodataValues()) {          /**
64                          amd.getNodataValues().add(nodataValue);           * set the fully qualified {@link Name} of this attribute.
65                  }           */
66            public void setName(Name name);
67    
68                  return amd;          /**
69          }           * A list og objects that represent NODATA-values for this attribute. The
70             * objects are supporsed to be correctly casted already. That means that the
71             * NODATA objects listed here have must have the same type as the values of
72             * this object.
73             */
74            public HashSet<Object> getNodataValues();
75    
76          @Override          /**
77          public AttributeMetadata copy() {           * Takes any value object and checks it against the NODATA values. If the
78                  return copyTo(new AttributeMetadata());           * value equals a NODATA value, <code>null</code> is returned. Otherwise the
79          }           * same object is returned.
80             *
81             * Note: This method is called often.
82             */
83            public Object fiterNodata(Object value);
84    
85          /**          /**
86           * The local Name. E.g. the name of the DBF column as a String           * @return a non-translatable unit {@link String} for this attribute values.
87           */           */
88          public String getLocalName() {          public String getUnit();
                 return getName().getLocalPart();  
         }  
89    
90          /**          /**
91           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * Set a unit {@link String} for this attribute values.
92           */           */
93          public Name getName() {          public void setUnit(String unit);
                 return name;  
         }  
94    
95          /**          /**
96           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * @return A value defining the position of this attribute whenever the
97             *         attributes are listed to an end-user. The higher the weight, the
98             *         lower the position. (heavy goes down, light goes up)
99           */           */
100          public void setName(org.opengis.feature.type.Name name) {          public double getWeight();
                 this.name = name;  
         }  
101    
102          /**          /**
103           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * set a value defining the position of this attribute whenever the
104             * attributes are listed to an end-user. The higher the weight, the lower
105             * the position. (heavy goes down, light goes up)
106           */           */
107          public void setLocalName(String localName) {          public void setWeight(double weight);
                 this.name = new NameImpl(localName);  
         }  
108    
109          /**          /**
110           * Orders the Attributes according to their weight. Heavier => further down.           * @return <code>false</code> if this attribute should not be selectable or
111             *         shown to the end-user.
112           */           */
113          @Override          public boolean isVisible();
         public int compareTo(AttributeMetadata atm2) {  
                 // Double double1 = new Double(1./weight);  
                 // double double2 = 1./atm2.getWeight();  
                 return new Integer(weight).compareTo(atm2.getWeight());  
         }  
114    
115          /**          /**
116           * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes           * Set <code>false</code> if this attribute should not be shown to the
117             * end-user.
118           */           */
119          public double getQuality(List<String> languages) {          public void setVisible(boolean visible);
120                  return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil  
121                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;          String getNoDataValuesFormatted();
122          }  
123  }  }

Legend:
Removed from v.533  
changed lines
  Added in v.797

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26