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

Diff of /trunk/src/skrueger/AttributeMetadataImpl.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/AttributeMetadataImpl.java revision 770 by alfonx, Sun Mar 21 11:36:11 2010 UTC
# Line 29  Line 29 
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger;  package skrueger;
31    
32  import java.util.ArrayList;  import java.util.HashSet;
33  import java.util.List;  import java.util.List;
34    
35  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
36  import org.geotools.feature.NameImpl;  import org.geotools.feature.NameImpl;
37  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
 import org.opengis.feature.type.Name;  
38    
39  import skrueger.geotools.Copyable;  import skrueger.geotools.Copyable;
40  import skrueger.geotools.StyledLayerInterface;  import skrueger.geotools.StyledLayerInterface;
# Line 48  import skrueger.i8n.Translation; Line 47  import skrueger.i8n.Translation;
47   *   *
48   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
49   */   */
50  public class AttributeMetadata implements Copyable<AttributeMetadata>,  public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
51                  Comparable<AttributeMetadata> {                  QualityQuantizable {
         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();  
52    
53          /** Is the attribute visible to the user or ignored where possible **/          static private final Logger LOGGER = Logger
54          protected boolean visible = true;                          .getLogger(AttributeMetadataImpl.class);
55    
56          /**          /**
57           * The unit append to all visualizations of values of this attribute (is not           * For numerical attributes the value can be transformed by VALUE*X+A when
58           * null)           * presented on screen. TODO not implemented yet
59           **/           **/
60          protected String unit = "";          protected Double functionA = 0.;
   
         /** 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;  
         }  
61    
62          public void setFunctionX(Double functionX) {          /**
63                  this.functionX = functionX;           * For numerical attributes the value can be transformed by VALUE*X+A when
64          }           * presented on screen. TODO not implemented yet
65             **/
66            protected Double functionX = 1.;
67    
68          public Double getFunctionA() {          /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
69                  return functionA;          private AttributeMetadataImpl() {
70          }          }
71    
72          public void setFunctionA(Double functionA) {          public AttributeMetadataImpl(final AttributeDescriptor attDesc,
73                  this.functionA = functionA;                          final int weight, final List<String> langs) {
74                    this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
75                    setWeight(weight);
76          }          }
77    
78          public void setVisible(boolean visible) {          public AttributeMetadataImpl(final AttributeDescriptor attDesc,
79                  this.visible = visible;                          final List<String> langs) {
80                    this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
81          }          }
82    
83          /**          /**
84           * When listed, the attributes are listed according to their weight (heavier           * Creates an {@link AttributeMetadataImpl} object with the following
          * => 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.;  
   
         /**  
          * Creates an {@link AttributeMetadata} object with the following  
85           * information           * information
86           *           *
87           * @param colIdx           * @param colIdx
# Line 159  public class AttributeMetadata implement Line 96  public class AttributeMetadata implement
96           * @param unit           * @param unit
97           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
98           */           */
99          public AttributeMetadata(final Name name, final Boolean visible,          public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
100                          final Translation title, final Translation desc, final String unit) {                          final Translation title, final Translation desc, final String unit) {
101    
102                  this.setName(name);                  this.setName(name);
103                  this.title = title;                  this.title = title;
104                  this.desc = desc;                  this.desc = desc;
105                    this.visible = visible;
106                    this.unit = unit;
107            }
108    
109                  // The THE_GEOM and shall never be visible!          /**
110                  if (name.getLocalPart().equalsIgnoreCase("the_geom"))           * Creates an {@link AttributeMetadataImpl} object with the following
111                          this.visible = false;           * information
112                  else           *
113                          this.visible = visible;           * @param colIdx
114             *            The column index of this attribute in the underlying
115             *            table/dbf/etc...
116             * @param visible
117             *            Shall this attribute be displayed or hidden from the user?
118             * @param unit
119             *            {@link String} of the unit that the information is in
120             */
121            public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
122                            final String unit) {
123                    this.setName(name);
124                    this.visible = visible;
125                  this.unit = unit;                  this.unit = unit;
126          }          }
127    
128          /**          /**
129           * Creates an {@link AttributeMetadata} object with the following           * Creates a new visible {@link AttributeMetadataImpl}
130             */
131            public AttributeMetadataImpl(final NameImpl name, final List<String> langs) {
132                    this(name, true, new Translation(langs, name.getLocalPart()),
133                                    new Translation(), "");
134            }
135    
136            /**
137             * Creates a new visible {@link AttributeMetadataImpl}
138             */
139            public AttributeMetadataImpl(final NameImpl name, final String defaultTitle,
140                            final List<String> langs) {
141                    this(name, true, new Translation(langs, defaultTitle),
142                                    new Translation(), "");
143            }
144    
145            /**
146             * Creates an {@link AttributeMetadataImpl} object with the following
147           * information           * information
148           *           *
149           * @param visible           * @param visible
# Line 188  public class AttributeMetadata implement Line 155  public class AttributeMetadata implement
155           * @param unit           * @param unit
156           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
157           */           */
158          public AttributeMetadata(final String localName, final Boolean visible,          public AttributeMetadataImpl(final String localName, final Boolean visible,
159                          final Translation title, final Translation desc, final String unit) {                          final Translation title, final Translation desc, final String unit) {
160                  this(new NameImpl(localName), true, title, desc, "");                  this(new NameImpl(localName), true, title, desc, "");
161          }          }
162    
163          /**          /**
164           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadataImpl} with default (no)
165             * values.
166           */           */
167          public AttributeMetadata(final String localName, final String defaultTitle) {          public AttributeMetadataImpl(final String localName,
168                  this(localName, true, new Translation(defaultTitle), new Translation(),                          final List<String> langs) {
169                                  "");                  this(localName, true, new Translation(langs, localName),
170                                    new Translation(), "");
171          }          }
172    
173          /**          /**
174           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadataImpl}
175           */           */
176          public AttributeMetadata(final Name name, final String defaultTitle) {          public AttributeMetadataImpl(final String localName,
177                  this(name, true, new Translation(defaultTitle), new Translation(), "");                          final String defaultTitle, final List<String> langs) {
178                    this(localName, true, new Translation(langs, defaultTitle),
179                                    new Translation(), "");
180          }          }
181    
182          /**          /**
183           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Orders the attributes according to their {@link #weight}. Heavier =>
184             * further down.
185           */           */
186          public AttributeMetadata(final Name name) {          @Override
187                  this(name, true, new Translation(name.getLocalPart()),          public int compareTo(final AttributeMetadata atm2) {
188                                  new Translation(), "");                  return new Integer(weight).compareTo(new Double(atm2.getWeight())
189                                    .intValue());
190          }          }
191    
192          /**          /**
193           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * @see Copyable inferface
194           */           */
195          public AttributeMetadata(final String localName) {          @Override
196                  this(localName, true, new Translation(localName), new Translation(), "");          public AttributeMetadata copy() {
197          }                  return copyTo(new AttributeMetadataImpl());
   
         /** 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;  
         }  
   
         public String getUnit() {  
                 return unit;  
         }  
   
         public void setUnit(final String unit) {  
                 this.unit = unit;  
198          }          }
199    
200            /**
201             * @see Copyable inferface
202             */
203          @Override          @Override
204          public AttributeMetadata copyTo(AttributeMetadata amd) {          public AttributeMetadata copyTo(final AttributeMetadata amd) {
205                  getTitle().copyTo(amd.getTitle());                  getTitle().copyTo(amd.getTitle());
206                  getDesc().copyTo(amd.getDesc());                  getDesc().copyTo(amd.getDesc());
207                  amd.setUnit(getUnit());                  amd.setUnit(getUnit());
# Line 285  public class AttributeMetadata implement Line 210  public class AttributeMetadata implement
210                                  .getLocalPart()));                                  .getLocalPart()));
211    
212                  amd.setWeight(getWeight());                  amd.setWeight(getWeight());
                 amd.setFunctionX(getFunctionX());  
                 amd.setFunctionA(getFunctionA());  
213    
214                  for (Object nodataValue : getNodataValues()) {                  if (amd instanceof AttributeMetadataImpl) {
215                          amd.getNodataValues().add(nodataValue);                          AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
216    
217                            amd_.setFunctionX(getFunctionX());
218                            amd_.setFunctionA(getFunctionA());
219                            amd_.setNodataValues(getNodataValues());
220                  }                  }
221    
222                  return amd;                  return amd;
223          }          }
224    
225          @Override          // only to be used by copyTo()
226          public AttributeMetadata copy() {          private void setNodataValues(HashSet<Object> nodataValues_) {
227                  return copyTo(new AttributeMetadata());                  nodataValues = nodataValues_;
228          }          }
229    
230          /**          public Double getFunctionA() {
231           * The local Name. E.g. the name of the DBF column as a String                  return functionA;
          */  
         public String getLocalName() {  
                 return getName().getLocalPart();  
232          }          }
233    
234          /**          public Double getFunctionX() {
235           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub                  return functionX;
          */  
         public Name getName() {  
                 return name;  
236          }          }
237    
238          /**          /**
239           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * @return a number between 0 (bad) and 1 (good) that is calculated from the
240             *         amount of translation available. If this attribute is not
241             *         {@link #visible}, it will return 1.
242           */           */
243          public void setName(org.opengis.feature.type.Name name) {          @Override
244                  this.name = name;          public double getQuality(final List<String> languages) {
         }  
245    
246          /**                  if (!isVisible())
247           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub                          return 1.;
248           */  
249          public void setLocalName(String localName) {                  return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
250                  this.name = new NameImpl(localName);                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;
251          }          }
252    
253          /**          public void setFunctionA(final Double functionA) {
254           * Orders the Attributes according to their weight. Heavier => further down.                  this.functionA = functionA;
          */  
         @Override  
         public int compareTo(AttributeMetadata atm2) {  
                 // Double double1 = new Double(1./weight);  
                 // double double2 = 1./atm2.getWeight();  
                 return new Integer(weight).compareTo(atm2.getWeight());  
255          }          }
256    
257          /**          public void setFunctionX(final Double functionX) {
258           * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes                  this.functionX = functionX;
          */  
         public double getQuality(List<String> languages) {  
                 return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil  
                                 .qmTranslation(languages, getDesc()) * 1.) / 3.;  
259          }          }
260    
261    
262  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26