/[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 518 by alfonx, Fri Nov 13 18:16:38 2009 UTC branches/2.0-RC1/src/skrueger/AttributeMetadata.java revision 604 by alfonx, Wed Dec 9 14:15:53 2009 UTC
# Line 50  import skrueger.i8n.Translation; Line 50  import skrueger.i8n.Translation;
50   */   */
51  public class AttributeMetadata implements Copyable<AttributeMetadata>,  public class AttributeMetadata implements Copyable<AttributeMetadata>,
52                  Comparable<AttributeMetadata> {                  Comparable<AttributeMetadata> {
53            
54          static private final Logger LOGGER = Logger          static private final Logger LOGGER = Logger
55                          .getLogger(AttributeMetadata.class);                          .getLogger(AttributeMetadata.class);
56    
         // 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();  
   
57          /** Translation of the attribute's description **/          /** Translation of the attribute's description **/
58          protected Translation desc = new Translation();          protected Translation desc = new Translation();
59    
60          /** Is the attribute visible to the user or ignored where possible **/          /**
61          protected boolean visible = true;           * For numerical attributes the value can be transformed by VALUE*X+A when
62             * presented on screen. TODO not implemented yet
63             **/
64            protected Double functionA = 0.;
65    
66          /**          /**
67           * 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
68           * null)           * presented on screen. TODO not implemented yet
69           **/           **/
70          protected String unit = "";          protected Double functionX = 1.;
71    
72          /** The Name of the attribute **/          /** The Name of the attribute **/
73          private Name name;          private Name name;
74    
         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;  
   
75          /**          /**
76           * Allows to define general NODATA values for an attribute. e.g. -9999 can           * Allows to define general NODATA values for an attribute. e.g. -9999 can
77           * be set and will always be interpreted as NULL internally and will usually           * be set and will always be interpreted as NULL internally and will usually
78           * be ignored.           * be ignored. TODO not implemented yet
79           **/           **/
80          protected List<Object> nodataValues = new ArrayList<Object>();          protected List<Object> nodataValues = new ArrayList<Object>();
81    
82            /** Translation of the attribute's title **/
83            protected Translation title = new Translation();
84    
85          /**          /**
86           * For numerical attributes the value can be transformed by VALUE*X+A when           * The unit append to all visualizations of values of this attribute (is not
87           * presented on screen           * null)
88           **/           **/
89          protected Double functionX = 1.;          protected String unit = "";
90    
91            /** Is the attribute visible to the user or ignored where possible **/
92            protected boolean visible = true;
93    
94          /**          /**
95           * For numerical attributes the value can be transformed by VALUE*X+A when           * When listed, the attributes are listed according to their {@link #weight} (heavier
96           * presented on screen           * => further down)
97             * @see #compareTo(AttributeMetadata)
98           **/           **/
99          protected Double functionA = 0.;          protected int weight = 0;
100    
101            /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
102            private AttributeMetadata() {
103            }
104    
105            public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,
106                            final List<String> langs) {
107                    this(attDesc.getName(), langs);
108                    setWeight(weight);
109            }
110    
111            public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {
112                    this(attDesc.getName(), langs);
113            }
114    
115          /**          /**
116           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadata} object with the following
# Line 165  public class AttributeMetadata implement Line 134  public class AttributeMetadata implement
134                  this.setName(name);                  this.setName(name);
135                  this.title = title;                  this.title = title;
136                  this.desc = desc;                  this.desc = desc;
137                    this.visible = visible;
138                    this.unit = unit;
139            }
140    
141                  // The THE_GEOM and shall never be visible!          /**
142                  if (name.getLocalPart().equalsIgnoreCase("the_geom"))           * Creates a new visible {@link AttributeMetadata}
143                          this.visible = false;           */
144                  else          public AttributeMetadata(final Name name, final List<String> langs) {
145                          this.visible = visible;                  this(name, true, new Translation(langs, name.getLocalPart()),
146                                    new Translation(), "");
147            }
148    
149                  this.unit = unit;          /**
150             * Creates a new visible {@link AttributeMetadata}
151             */
152            public AttributeMetadata(final Name name, final String defaultTitle,
153                            final List<String> langs) {
154                    this(name, true, new Translation(langs, defaultTitle),
155                                    new Translation(), "");
156          }          }
157    
158          /**          /**
# Line 196  public class AttributeMetadata implement Line 176  public class AttributeMetadata implement
176          /**          /**
177           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadata} with default (no) values.
178           */           */
179          public AttributeMetadata(final String localName, final String defaultTitle) {          public AttributeMetadata(final String localName, final List<String> langs) {
180                  this(localName, true, new Translation(defaultTitle), new Translation(),                  this(localName, true, new Translation(langs, localName),
181                                  "");                                  new Translation(), "");
182          }          }
183    
184          /**          /**
185           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadata}
186           */           */
187          public AttributeMetadata(final Name name, final String defaultTitle) {          public AttributeMetadata(final String localName, final String defaultTitle,
188                  this(name, true, new Translation(defaultTitle), new Translation(), "");                          final List<String> langs) {
189                    this(localName, true, new Translation(langs, defaultTitle),
190                                    new Translation(), "");
191          }          }
192    
193          /**          /**
194           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Orders the attributes according to their {@link #weight}. Heavier =>
195             * further down.
196           */           */
197          public AttributeMetadata(final Name name) {          @Override
198                  this(name, true, new Translation(name.getLocalPart()),          public int compareTo(final AttributeMetadata atm2) {
199                                  new Translation(), "");                  return new Integer(weight).compareTo(atm2.getWeight());
200          }          }
201    
202          /**          /**
203           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * @see Copyable inferface
204           */           */
205          public AttributeMetadata(final String localName) {          @Override
206                  this(localName, true, new Translation(localName), new Translation(), "");          public AttributeMetadata copy() {
207          }                  return copyTo(new AttributeMetadata());
   
         /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/  
         private AttributeMetadata() {  
         }  
   
         public AttributeMetadata(AttributeDescriptor attDesc) {  
                 this(attDesc.getName());  
         }  
   
         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;  
208          }          }
209    
210            /**
211             * @see Copyable inferface
212             */
213          @Override          @Override
214          public AttributeMetadata copyTo(AttributeMetadata amd) {          public AttributeMetadata copyTo(final AttributeMetadata amd) {
215                  getTitle().copyTo(amd.getTitle());                  getTitle().copyTo(amd.getTitle());
216                  getDesc().copyTo(amd.getDesc());                  getDesc().copyTo(amd.getDesc());
217                  amd.setUnit(getUnit());                  amd.setUnit(getUnit());
# Line 283  public class AttributeMetadata implement Line 223  public class AttributeMetadata implement
223                  amd.setFunctionX(getFunctionX());                  amd.setFunctionX(getFunctionX());
224                  amd.setFunctionA(getFunctionA());                  amd.setFunctionA(getFunctionA());
225    
226                  for (Object nodataValue : getNodataValues()) {                  for (final Object nodataValue : getNodataValues()) {
227                          amd.getNodataValues().add(nodataValue);                          amd.getNodataValues().add(nodataValue);
228                  }                  }
229    
230                  return amd;                  return amd;
231          }          }
232    
233          @Override          public Translation getDesc() {
234          public AttributeMetadata copy() {                  return desc;
235                  return copyTo(new AttributeMetadata());          }
236    
237            public Double getFunctionA() {
238                    return functionA;
239            }
240    
241            public Double getFunctionX() {
242                    return functionX;
243          }          }
244    
245          /**          /**
246           * The local Name. E.g. the name of the DBF column as a String           * The local name. E.g. the name of the DBF column as a {@link String}
247           */           */
248          public String getLocalName() {          public String getLocalName() {
249                  return getName().getLocalPart();                  return getName().getLocalPart();
250          }          }
251    
252          /**          /**
253           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
254           */           */
255          public Name getName() {          public Name getName() {
256                  return name;                  return name;
257          }          }
258    
259            public List<Object> getNodataValues() {
260                    return nodataValues;
261            }
262    
263          /**          /**
264           * 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
265             *         amount of translation available. If this attribute is not
266             *         {@link #visible}, it will return 1.
267           */           */
268          public void setName(org.opengis.feature.type.Name name) {          public double getQuality(final List<String> languages) {
269                  this.name = name;  
270                    if (!isVisible())
271                            return 1.;
272    
273                    return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
274                                    .qmTranslation(languages, getDesc()) * 1.) / 3.;
275            }
276    
277            public Translation getTitle() {
278                    return title;
279            }
280    
281            public String getUnit() {
282                    return unit;
283            }
284    
285            public int getWeight() {
286                    return weight;
287            }
288    
289            /**
290             * Will the end-user see this attribute?
291             */
292            public boolean isVisible() {
293                    return visible;
294            }
295    
296            public void setDesc(final Translation desc) {
297                    this.desc = desc;
298            }
299    
300            public void setFunctionA(final Double functionA) {
301                    this.functionA = functionA;
302            }
303    
304            public void setFunctionX(final Double functionX) {
305                    this.functionX = functionX;
306          }          }
307    
308          /**          /**
309           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
310           */           */
311          public void setLocalName(String localName) {          public void setLocalName(final String localName) {
312                  this.name = new NameImpl(localName);                  this.name = new NameImpl(localName);
313          }          }
314    
315          /**          /**
316           * Orders the Attributes according to their weight. Heavier => further down.           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
317           */           */
318          @Override          public void setName(final Name name) {
319          public int compareTo(AttributeMetadata atm2) {                  this.name = name;
320                  // Double double1 = new Double(1./weight);          }
321                  // double double2 = 1./atm2.getWeight();  
322                  return new Integer(weight).compareTo(atm2.getWeight());          public void setNodataValues(final List<Object> nodataValues) {
323                    this.nodataValues = nodataValues;
324            }
325    
326            public void setTitle(final Translation title) {
327                    this.title = title;
328            }
329    
330            public void setUnit(final String unit) {
331                    this.unit = unit;
332            }
333    
334            public void setVisible(final boolean visible) {
335                    this.visible = visible;
336          }          }
337    
338          /**          /**
339           * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes           * Shall the end-user see this attribute?
340             * @param visible
341           */           */
342          public double getQuality(List<String> languages) {          public void setVisible(final Boolean visible) {
343                  return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil  //              // The THE_GEOM and shall never be visible!
344                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;  //              if (name.getLocalPart().equalsIgnoreCase("the_geom"))
345    //                      this.visible = false;
346    //              else
347    //                      this.visible = visible;
348    
349                    this.visible = visible;
350            }
351    
352            public void setWeight(final int weight) {
353                    this.weight = weight;
354            }
355            
356            /**
357             * For nicer debugging
358             */
359            @Override
360            public String toString() {
361                    StringBuffer sb = new StringBuffer();
362                    if (name != null) sb.append(name.toString()+" ");
363                    sb.append("weight="+weight+" ");
364                    sb.append("title="+getTitle().toString());
365                    return sb.toString();
366          }          }
367  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26