/[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

revision 420 by alfonx, Thu Oct 1 20:22:48 2009 UTC revision 518 by alfonx, Fri Nov 13 18:16:38 2009 UTC
# Line 29  Line 29 
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger;  package skrueger;
31    
32    import java.util.ArrayList;
33    import java.util.List;
34    
35  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
36    import org.geotools.feature.NameImpl;
37    import org.opengis.feature.type.AttributeDescriptor;
38    import org.opengis.feature.type.Name;
39    
40  import skrueger.geotools.Copyable;  import skrueger.geotools.Copyable;
41  import skrueger.geotools.StyledLayerInterface;  import skrueger.geotools.StyledLayerInterface;
42    import skrueger.i8n.I8NUtil;
43  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
44    
45  /**  /**
46   * This class holds meta information about an attribute/column. This   * This class holds meta information about an attribute/column. This information
47   * information is used by {@link StyledLayerInterface}.   * is used by {@link StyledLayerInterface} and many others.<br/>
48   *   *
49   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
50   */   */
51  public class AttributeMetaData implements Copyable<AttributeMetaData>{  public class AttributeMetadata implements Copyable<AttributeMetadata>,
52                    Comparable<AttributeMetadata> {
53          static private final Logger LOGGER = Logger          static private final Logger LOGGER = Logger
54                          .getLogger(AttributeMetaData.class);                          .getLogger(AttributeMetadata.class);
55    
56            // public class WeightComparator implements Comparator<AttributeDescriptor>
57            // {
58            //
59            // @Override
60            // public int compare(AttributeDescriptor o1, AttributeDescriptor o2) {
61            // // TODO Auto-generated method stub
62            // return 0;
63            // }
64            //              
65            // };
66    
67            /** Translation of the attribute's title **/
68          protected Translation title = new Translation();          protected Translation title = new Translation();
69    
70            /** Translation of the attribute's description **/
71          protected Translation desc = new Translation();          protected Translation desc = new Translation();
72          protected boolean visible = false;  
73            /** Is the attribute visible to the user or ignored where possible **/
74            protected boolean visible = true;
75    
76            /**
77             * The unit append to all visualizations of values of this attribute (is not
78             * null)
79             **/
80          protected String unit = "";          protected String unit = "";
81          protected int colIdx;  
82                    /** The Name of the attribute **/
83            private Name name;
84    
85            public int getWeight() {
86                    return weight;
87            }
88    
89            public void setWeight(int weight) {
90                    this.weight = weight;
91            }
92    
93            public List<Object> getNodataValues() {
94                    return nodataValues;
95            }
96    
97            public void setNodataValues(List<Object> nodataValues) {
98                    this.nodataValues = nodataValues;
99            }
100    
101            public Double getFunctionX() {
102                    return functionX;
103            }
104    
105            public void setFunctionX(Double functionX) {
106                    this.functionX = functionX;
107            }
108    
109            public Double getFunctionA() {
110                    return functionA;
111            }
112    
113            public void setFunctionA(Double functionA) {
114                    this.functionA = functionA;
115            }
116    
117            public void setVisible(boolean visible) {
118                    this.visible = visible;
119            }
120    
121            /**
122             * When listed, the attributes are listed according to their weight (heavier
123             * => further down)
124             **/
125            protected int weight = 0;
126    
127            /**
128             * Allows to define general NODATA values for an attribute. e.g. -9999 can
129             * be set and will always be interpreted as NULL internally and will usually
130             * be ignored.
131             **/
132            protected List<Object> nodataValues = new ArrayList<Object>();
133    
134            /**
135             * For numerical attributes the value can be transformed by VALUE*X+A when
136             * presented on screen
137             **/
138            protected Double functionX = 1.;
139    
140            /**
141             * For numerical attributes the value can be transformed by VALUE*X+A when
142             * presented on screen
143             **/
144            protected Double functionA = 0.;
145    
146          /**          /**
147           * Creates an {@link AttributeMetaData} object with the following information           * Creates an {@link AttributeMetadata} object with the following
148           * @param colIdx The column index of this attribute in the underlying table/dbf/etc...           * information
149           * @param visible Shall this attribute be displayed or hidden from the user?           *
150           * @param title {@link Translation} for Name           * @param colIdx
151           * @param desc {@link Translation} for an attribute description           *            The column index of this attribute in the underlying
152           * @param unit {@link String} of the unit that the information is in           *            table/dbf/etc...
153             * @param visible
154             *            Shall this attribute be displayed or hidden from the user?
155             * @param title
156             *            {@link Translation} for Name
157             * @param desc
158             *            {@link Translation} for an attribute description
159             * @param unit
160             *            {@link String} of the unit that the information is in
161           */           */
162          public AttributeMetaData(final int colIdx, final Boolean visible,          public AttributeMetadata(final Name name, final Boolean visible,
163                          final Translation title, final Translation desc, final String unit) {                          final Translation title, final Translation desc, final String unit) {
164            
165                  this.colIdx = colIdx;                  this.setName(name);
166                  this.title = title;                  this.title = title;
167                  this.desc = desc;                  this.desc = desc;
168                  if (colIdx == 0){  
169                          // The first attribute is THE_GEOM and shall never be visible!                  // The THE_GEOM and shall never be visible!
170                    if (name.getLocalPart().equalsIgnoreCase("the_geom"))
171                          this.visible = false;                          this.visible = false;
172                  }else                  else
173                          this.visible = visible;                          this.visible = visible;
174    
175                  this.unit = unit;                  this.unit = unit;
176          }          }
177    
178          /**          /**
179           * Creates a new visible {@link AttributeMetaData} with default (no) values.             * Creates an {@link AttributeMetadata} object with the following
180             * information
181             *
182             * @param visible
183             *            Shall this attribute be displayed or hidden from the user?
184             * @param title
185             *            {@link Translation} for Name
186             * @param desc
187             *            {@link Translation} for an attribute description
188             * @param unit
189             *            {@link String} of the unit that the information is in
190             */
191            public AttributeMetadata(final String localName, final Boolean visible,
192                            final Translation title, final Translation desc, final String unit) {
193                    this(new NameImpl(localName), true, title, desc, "");
194            }
195    
196            /**
197             * Creates a new visible {@link AttributeMetadata} with default (no) values.
198             */
199            public AttributeMetadata(final String localName, final String defaultTitle) {
200                    this(localName, true, new Translation(defaultTitle), new Translation(),
201                                    "");
202            }
203    
204            /**
205             * Creates a new visible {@link AttributeMetadata} with default (no) values.
206           */           */
207          public AttributeMetaData(final Integer col, final String defaultName) {          public AttributeMetadata(final Name name, final String defaultTitle) {
208                  this(col, true, new Translation(defaultName), new Translation(), "");                  this(name, true, new Translation(defaultTitle), new Translation(), "");
209          }          }
210    
211          /** Only used for {@link Copyable<AttributeMetaData>#copy()}**/          /**
212          private AttributeMetaData() {           * Creates a new visible {@link AttributeMetadata} with default (no) values.
213             */
214            public AttributeMetadata(final Name name) {
215                    this(name, true, new Translation(name.getLocalPart()),
216                                    new Translation(), "");
217            }
218    
219            /**
220             * Creates a new visible {@link AttributeMetadata} with default (no) values.
221             */
222            public AttributeMetadata(final String localName) {
223                    this(localName, true, new Translation(localName), new Translation(), "");
224            }
225    
226            /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
227            private AttributeMetadata() {
228            }
229    
230            public AttributeMetadata(AttributeDescriptor attDesc) {
231                    this(attDesc.getName());
232          }          }
233    
234          public boolean isVisible() {          public boolean isVisible() {
# Line 88  public class AttributeMetaData implement Line 236  public class AttributeMetaData implement
236          }          }
237    
238          public void setVisible(final Boolean visible) {          public void setVisible(final Boolean visible) {
                 this.visible = visible;  
         }  
239    
240          /** @return the index of this attribute in the underlying table/dbf **/                  // The THE_GEOM and shall never be visible! // TODO MAKE BETTER
241          public int getColIdx() {                  if (name.getLocalPart().equalsIgnoreCase("the_geom"))
242                  return colIdx;                          this.visible = false;
243                    else
244                            this.visible = visible;
245                    
246                    this.visible = visible;
247          }          }
248    
249          public Translation getTitle() {          public Translation getTitle() {
# Line 121  public class AttributeMetaData implement Line 271  public class AttributeMetaData implement
271          }          }
272    
273          @Override          @Override
274          public AttributeMetaData copyTo(AttributeMetaData amd) {          public AttributeMetadata copyTo(AttributeMetadata amd) {
275                  getTitle().copyTo(amd.getTitle());                  getTitle().copyTo(amd.getTitle());
276                  getDesc().copyTo(amd.getDesc());                  getDesc().copyTo(amd.getDesc());
277                  amd.setUnit(getUnit());                  amd.setUnit(getUnit());
278                  amd.setVisible(isVisible());                  amd.setVisible(isVisible());
279                  amd.setColIdx(getColIdx());                  amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
280                                                    .getLocalPart()));
281    
282                    amd.setWeight(getWeight());
283                    amd.setFunctionX(getFunctionX());
284                    amd.setFunctionA(getFunctionA());
285    
286                    for (Object nodataValue : getNodataValues()) {
287                            amd.getNodataValues().add(nodataValue);
288                    }
289    
290                  return amd;                  return amd;
291          }          }
292    
293          @Override          @Override
294          public AttributeMetaData copy() {          public AttributeMetadata copy() {
295                  AttributeMetaData amd = new AttributeMetaData();                  return copyTo(new AttributeMetadata());
296                  getTitle().copyTo(amd.getTitle());          }
297                  getDesc().copyTo(amd.getDesc());  
298                  amd.setUnit(getUnit());          /**
299                  amd.setVisible(isVisible());           * The local Name. E.g. the name of the DBF column as a String
300                  amd.setColIdx(getColIdx());           */
301                            public String getLocalName() {
302                  return amd;                  return getName().getLocalPart();
303            }
304    
305            /**
306             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
307             */
308            public Name getName() {
309                    return name;
310            }
311    
312            /**
313             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
314             */
315            public void setName(org.opengis.feature.type.Name name) {
316                    this.name = name;
317            }
318    
319            /**
320             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
321             */
322            public void setLocalName(String localName) {
323                    this.name = new NameImpl(localName);
324            }
325    
326            /**
327             * Orders the Attributes according to their weight. Heavier => further down.
328             */
329            @Override
330            public int compareTo(AttributeMetadata atm2) {
331                    // Double double1 = new Double(1./weight);
332                    // double double2 = 1./atm2.getWeight();
333                    return new Integer(weight).compareTo(atm2.getWeight());
334          }          }
335    
336          private void setColIdx(int colIdx_) {          /**
337                  colIdx = colIdx_;           * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
338             */
339            public double getQuality(List<String> languages) {
340                    return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
341                                    .qmTranslation(languages, getDesc()) * 1.) / 3.;
342          }          }
343  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26