/[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/AttributeMetadata.java revision 770 by alfonx, Sun Mar 21 11:36:11 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 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>,  
12                  Comparable<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;  
         }  
13    
14          /**          /**
15           * When listed, the attributes are listed according to their weight (heavier           * @return a translatable title for this attribute..
16           * => further down)           */
17           **/          public Translation getTitle();
         protected int weight = 0;  
18    
19          /**          /**
20           * Allows to define general NODATA values for an attribute. e.g. -9999 can           * Set a translatable title for this attribute..
21           * be set and will always be interpreted as NULL internally and will usually           */
22           * be ignored.          public void setTitle(Translation title);
          **/  
         protected List<Object> nodataValues = new ArrayList<Object>();  
23    
24          /**          /**
25           * For numerical attributes the value can be transformed by VALUE*X+A when           * @return a translatable description for this attribute
26           * presented on screen           */
27           **/          public Translation getDesc();
         protected Double functionX = 1.;  
28    
29          /**          /**
30           * For numerical attributes the value can be transformed by VALUE*X+A when           * Set a translatable description for this attribute.
31           * presented on screen           */
32           **/          public void setDesc(Translation desc);
         protected Double functionA = 0.;  
33    
34          /**          /**
35           * Creates an {@link AttributeMetadata} object with the following           * The local name. E.g. the name of the DBF column as a {@link String}.
36           * information           */
37           *          public String getLocalName();
          * @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;  
         }  
38    
39          /**          /**
40           * Creates an {@link AttributeMetadata} object with the following           * A short form for #setName(new NameImpl(localName))
          * 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  
41           */           */
42          public AttributeMetadata(final String localName, final Boolean visible,          public void setLocalName(String localName);
                         final Translation title, final Translation desc, final String unit) {  
                 this(new NameImpl(localName), true, title, desc, "");  
         }  
43    
44          /**          /**
45           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * The fully qualified {@link Name} of the attribute, e.g.
46             * <code>org.bla.plo:blub</code>. The second part equals the
47             * {@link #getLocalName()} value. The first may be <code>null</code> or
48             * represent the layer name.
49           */           */
50          public AttributeMetadata(final String localName, final String defaultTitle, List<String> langs) {          public NameImpl getName();
                 this(localName, true, new Translation(langs, defaultTitle), new Translation(),  
                                 "");  
         }  
51    
52          /**          /**
53           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * set the fully qualified {@link Name} of this attribute.
54           */           */
55          public AttributeMetadata(final Name name, final String defaultTitle, List<String> langs) {          public void setName(NameImpl name);
                 this(name, true, new Translation(langs, defaultTitle), new Translation(), "");  
         }  
56    
57          /**          /**
58           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * A list og objects that represent NODATA-values for this attribute. The
59             * objects are supporsed to be correctly casted already. That means that the
60             * NODATA objects listed here have must have the same type as the values of
61             * this object.
62           */           */
63          public AttributeMetadata(final Name name, List<String> langs) {          public HashSet<Object> getNodataValues();
                 this(name, true, new Translation(langs, name.getLocalPart()),  
                                 new Translation(), "");  
         }  
64    
65          /**          /**
66           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Takes any value object and checks it against the NODATA values. If the
67             * value equals a NODATA value, <code>null</code> is returned. Otherwise the
68             * same object is returned.
69             *
70             * Note: This method is called often.
71           */           */
72          public AttributeMetadata(final String localName, List<String> langs) {          public Object fiterNodata(Object value);
                 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;  
         }  
   
         public String getUnit() {  
                 return unit;  
         }  
   
         public void setUnit(final String unit) {  
                 this.unit = unit;  
         }  
   
         @Override  
         public AttributeMetadata copyTo(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 (Object nodataValue : getNodataValues()) {  
                         amd.getNodataValues().add(nodataValue);  
                 }  
   
                 return amd;  
         }  
   
         @Override  
         public AttributeMetadata copy() {  
                 return copyTo(new AttributeMetadata());  
         }  
73    
74          /**          /**
75           * 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.
76           */           */
77          public String getLocalName() {          public String getUnit();
                 return getName().getLocalPart();  
         }  
78    
79          /**          /**
80           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * Set a unit {@link String} for this attribute values.
81           */           */
82          public Name getName() {          public void setUnit(String unit);
                 return name;  
         }  
83    
84          /**          /**
85           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * @return A value defining the position of this attribute whenever the
86             *         attributes are listed to an end-user. The higher the weight, the
87             *         lower the position. (heavy goes down, light goes up)
88           */           */
89          public void setName(org.opengis.feature.type.Name name) {          public double getWeight();
                 this.name = name;  
         }  
90    
91          /**          /**
92           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * set a value defining the position of this attribute whenever the
93             * attributes are listed to an end-user. The higher the weight, the lower
94             * the position. (heavy goes down, light goes up)
95           */           */
96          public void setLocalName(String localName) {          public void setWeight(double weight);
                 this.name = new NameImpl(localName);  
         }  
97    
98          /**          /**
99           * Orders the Attributes according to their weight. Heavier => further down.           * @return <code>false</code> if this attribute should not be selectable or
100             *         shown to the end-user.
101           */           */
102          @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());  
         }  
103    
104          /**          /**
105           * @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
106             * end-user.
107           */           */
108          public double getQuality(List<String> languages) {          public void setVisible(boolean visible);
109                  return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil  
110                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;          String getNoDataValuesFormatted();
111          }  
112  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26