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

trunk/src/skrueger/AttributeMetaData.java revision 93 by alfonx, Fri May 1 16:24:15 2009 UTC trunk/src/skrueger/AttributeMetadataImpl.java revision 772 by alfonx, Sun Mar 21 14:05:26 2010 UTC
# Line 1  Line 1 
1  package skrueger;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import org.apache.log4j.Logger;   *
4     * This file is part of the SCHMITZM library - a collection of utility
5  import skrueger.geotools.StyledMapInterface;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import skrueger.i8n.Translation;   * and the Geotools library.
7     *
8  /**   * The SCHMITZM project is hosted at:
9   * This class holds meta information about an attribute/column. This   * http://wald.intevation.org/projects/schmitzm/
10   * information is used by {@link StyledMapInterface}.   *
11   *   * This program is free software; you can redistribute it and/or
12   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * modify it under the terms of the GNU Lesser General Public License
13   */   * as published by the Free Software Foundation; either version 3
14  public class AttributeMetaData {   * of the License, or (at your option) any later version.
15          static private final Logger LOGGER = Logger   *
16                          .getLogger(AttributeMetaData.class);   * This program is distributed in the hope that it will be useful,
17          protected Translation title = new Translation();   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18          protected Translation desc = new Translation();   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19          protected boolean visible = false;   * GNU General Public License for more details.
20          protected String unit = "";   *
21          protected int colIdx;   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22     * along with this program; if not, write to the Free Software
23          /**   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24           * Creates an {@link AttributeMetaData} object with the following information   * or try this link: http://www.gnu.org/licenses/lgpl.html
25           * @param colIdx The column index of this attribute in the underlying table/dbf/etc...   *
26           * @param visible Shall this attribute be displayed or hidden from the user?   * Contributors:
27           * @param title {@link Translation} for Name   *     Martin O. J. Schmitz - initial API and implementation
28           * @param desc {@link Translation} for an attribute description   *     Stefan A. Krüger - additional utility classes
29           * @param unit {@link String} of the unit that the information is in   ******************************************************************************/
30           */  package skrueger;
31          public AttributeMetaData(final int colIdx, final Boolean visible,  
32                          final Translation title, final Translation desc, final String unit) {  import java.util.HashSet;
33            import java.util.List;
34                  this.colIdx = colIdx;  
35                  this.title = title;  import org.apache.log4j.Logger;
36                  this.desc = desc;  import org.geotools.feature.NameImpl;
37                  if (colIdx == 0){  import org.opengis.feature.type.AttributeDescriptor;
38                          // The first attribut is THE_GEOM and shall never be visible!  
39                          this.visible = false;  import skrueger.geotools.Copyable;
40                  }else  import skrueger.geotools.StyledLayerInterface;
41                          this.visible = visible;  import skrueger.i8n.I8NUtil;
42                  this.unit = unit;  import skrueger.i8n.Translation;
43          }  
44    /**
45          /**   * This class holds meta information about an attribute/column. This information
46           * Creates a new visible {@link AttributeMetaData} with default (no) values.     * is used by {@link StyledLayerInterface} and many others.<br/>
47           */   *
48          public AttributeMetaData(final Integer col, final String defaultName) {   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
49                  this(col, true, new Translation(defaultName), new Translation(), "");   */
50          }  public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
51                    QualityQuantizable {
52          public Boolean isVisible() {  
53                  return visible;          static private final Logger LOGGER = Logger
54          }                          .getLogger(AttributeMetadataImpl.class);
55    
56          public void setVisible(final Boolean visible) {          /**
57                  this.visible = visible;           * For numerical attributes the value can be transformed by VALUE*X+A when
58          }           * presented on screen. TODO not implemented yet
59             **/
60          /** @return the index of this attribute in the underlying table/dbf **/          protected Double functionA = 0.;
61          public int getColIdx() {  
62                  return colIdx;          /**
63          }           * For numerical attributes the value can be transformed by VALUE*X+A when
64             * presented on screen. TODO not implemented yet
65          public Translation getTitle() {           **/
66                  return title;          protected Double functionX = 1.;
67          }  
68            /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
69          public void setTitle(final Translation title) {          private AttributeMetadataImpl() {
70                  this.title = title;          }
71          }  
72            public AttributeMetadataImpl(final AttributeDescriptor attDesc,
73          public Translation getDesc() {                          final int weight, final List<String> langs) {
74                  return desc;                  this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
75          }                  setWeight(weight);
76            }
77          public void setDesc(final Translation desc) {  
78                  this.desc = desc;          public AttributeMetadataImpl(final AttributeDescriptor attDesc,
79          }                          final List<String> langs) {
80                    this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
81          public String getUnit() {          }
82                  return unit;  
83          }          /**
84             * Creates an {@link AttributeMetadataImpl} object with the following
85          public void setUnit(final String unit) {           * information
86                  this.unit = unit;           *
87          }           * @param colIdx
88  }           *            The column index of this attribute in the underlying
89             *            table/dbf/etc...
90             * @param visible
91             *            Shall this attribute be displayed or hidden from the user?
92             * @param title
93             *            {@link Translation} for Name
94             * @param desc
95             *            {@link Translation} for an attribute description
96             * @param unit
97             *            {@link String} of the unit that the information is in
98             */
99            public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
100                            final Translation title, final Translation desc, final String unit) {
101    
102                    this.setName(name);
103                    this.title = title;
104                    this.desc = desc;
105                    this.visible = visible;
106                    this.unit = unit;
107            }
108    
109            /**
110             * Creates an {@link AttributeMetadataImpl} object with the following
111             * information
112             *
113             * @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;
126            }
127    
128            /**
129             * 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
148             *
149             * @param visible
150             *            Shall this attribute be displayed or hidden from the user?
151             * @param title
152             *            {@link Translation} for Name
153             * @param desc
154             *            {@link Translation} for an attribute description
155             * @param unit
156             *            {@link String} of the unit that the information is in
157             */
158            public AttributeMetadataImpl(final String localName, final Boolean visible,
159                            final Translation title, final Translation desc, final String unit) {
160                    this(new NameImpl(localName), true, title, desc, "");
161            }
162    
163            /**
164             * Creates a new visible {@link AttributeMetadataImpl} with default (no)
165             * values.
166             */
167            public AttributeMetadataImpl(final String localName,
168                            final List<String> langs) {
169                    this(localName, true, new Translation(langs, localName),
170                                    new Translation(), "");
171            }
172    
173            /**
174             * Creates a new visible {@link AttributeMetadataImpl}
175             */
176            public AttributeMetadataImpl(final String localName,
177                            final String defaultTitle, final List<String> langs) {
178                    this(localName, true, new Translation(langs, defaultTitle),
179                                    new Translation(), "");
180            }
181    
182            /**
183             * Orders the attributes according to their {@link #weight}. Heavier =>
184             * further down.
185             */
186            @Override
187            public int compareTo(final AttributeMetadataInterface atm2) {
188                    return new Integer(weight).compareTo(new Double(atm2.getWeight())
189                                    .intValue());
190            }
191    
192            /**
193             * @see Copyable inferface
194             */
195            @Override
196            public AttributeMetadataInterface copy() {
197                    return copyTo(new AttributeMetadataImpl());
198            }
199    
200            /**
201             * @see Copyable inferface
202             */
203            @Override
204            public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
205                    getTitle().copyTo(amd.getTitle());
206                    getDesc().copyTo(amd.getDesc());
207                    amd.setUnit(getUnit());
208                    amd.setVisible(isVisible());
209                    amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
210                                    .getLocalPart()));
211    
212                    amd.setWeight(getWeight());
213    
214                    if (amd instanceof AttributeMetadataImpl) {
215                            AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
216    
217                            amd_.setFunctionX(getFunctionX());
218                            amd_.setFunctionA(getFunctionA());
219                            amd_.setNodataValues(getNodataValues());
220                    }
221    
222                    return amd;
223            }
224    
225            // only to be used by copyTo()
226            private void setNodataValues(HashSet<Object> nodataValues_) {
227                    nodataValues = nodataValues_;
228            }
229    
230            public Double getFunctionA() {
231                    return functionA;
232            }
233    
234            public Double getFunctionX() {
235                    return functionX;
236            }
237    
238            /**
239             * @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            @Override
244            public double getQuality(final List<String> languages) {
245    
246                    if (!isVisible())
247                            return 1.;
248    
249                    return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
250                                    .qmTranslation(languages, getDesc()) * 1.) / 3.;
251            }
252    
253            public void setFunctionA(final Double functionA) {
254                    this.functionA = functionA;
255            }
256    
257            public void setFunctionX(final Double functionX) {
258                    this.functionX = functionX;
259            }
260    
261    
262    }

Legend:
Removed from v.93  
changed lines
  Added in v.772

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26