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

Legend:
Removed from v.464  
changed lines
  Added in v.769

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26