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

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

Legend:
Removed from v.523  
changed lines
  Added in v.772

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26