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

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

Legend:
Removed from v.518  
changed lines
  Added in v.897

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26