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

Annotation of /trunk/src/skrueger/AttributeMetadataImpl.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 772 - (hide annotations)
Sun Mar 21 14:05:26 2010 UTC (14 years, 11 months ago) by alfonx
File size: 8020 byte(s)
The new Interface AttributeMetadata has been renamed to AttributeMetadataInterface. 

1 alfonx 244 /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3     *
4     * This file is part of the SCHMITZM library - a collection of utility
5 alfonx 256 * classes based on Java 1.6, focusing (not only) on Java Swing
6 alfonx 244 * and the Geotools library.
7     *
8     * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10     *
11     * This program is free software; you can redistribute it and/or
12     * modify it under the terms of the GNU Lesser General Public License
13     * as published by the Free Software Foundation; either version 3
14     * of the License, or (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * 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     * or try this link: http://www.gnu.org/licenses/lgpl.html
25     *
26     * Contributors:
27     * Martin O. J. Schmitz - initial API and implementation
28     * Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30     package skrueger;
31    
32 alfonx 658 import java.util.HashSet;
33 alfonx 518 import java.util.List;
34    
35 alfonx 244 import org.apache.log4j.Logger;
36 alfonx 464 import org.geotools.feature.NameImpl;
37     import org.opengis.feature.type.AttributeDescriptor;
38 alfonx 244
39 alfonx 420 import skrueger.geotools.Copyable;
40 mojays 325 import skrueger.geotools.StyledLayerInterface;
41 alfonx 518 import skrueger.i8n.I8NUtil;
42 alfonx 244 import skrueger.i8n.Translation;
43    
44     /**
45 alfonx 464 * This class holds meta information about an attribute/column. This information
46 alfonx 518 * is used by {@link StyledLayerInterface} and many others.<br/>
47 alfonx 464 *
48 alfonx 244 * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
49     */
50 alfonx 769 public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
51     QualityQuantizable {
52 alfonx 681
53 alfonx 244 static private final Logger LOGGER = Logger
54 alfonx 769 .getLogger(AttributeMetadataImpl.class);
55 alfonx 464
56 alfonx 534 /**
57     * For numerical attributes the value can be transformed by VALUE*X+A when
58     * presented on screen. TODO not implemented yet
59     **/
60     protected Double functionA = 0.;
61 alfonx 518
62     /**
63 alfonx 534 * For numerical attributes the value can be transformed by VALUE*X+A when
64     * presented on screen. TODO not implemented yet
65 alfonx 518 **/
66 alfonx 534 protected Double functionX = 1.;
67 alfonx 518
68 alfonx 534 /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
69 alfonx 769 private AttributeMetadataImpl() {
70 alfonx 534 }
71    
72 alfonx 769 public AttributeMetadataImpl(final AttributeDescriptor attDesc,
73 alfonx 681 final int weight, final List<String> langs) {
74 alfonx 770 this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
75 alfonx 534 setWeight(weight);
76     }
77    
78 alfonx 769 public AttributeMetadataImpl(final AttributeDescriptor attDesc,
79 alfonx 681 final List<String> langs) {
80 alfonx 770 this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
81 alfonx 534 }
82    
83 alfonx 518 /**
84 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
85 alfonx 464 * information
86     *
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 alfonx 244 */
99 alfonx 770 public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
100 alfonx 244 final Translation title, final Translation desc, final String unit) {
101 alfonx 464
102     this.setName(name);
103 alfonx 244 this.title = title;
104     this.desc = desc;
105 alfonx 546 this.visible = visible;
106 alfonx 244 this.unit = unit;
107     }
108    
109     /**
110 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
111 alfonx 658 * 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 alfonx 770 public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
122 alfonx 681 final String unit) {
123 alfonx 658 this.setName(name);
124     this.visible = visible;
125     this.unit = unit;
126     }
127    
128     /**
129 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
130 alfonx 534 */
131 alfonx 770 public AttributeMetadataImpl(final NameImpl name, final List<String> langs) {
132 alfonx 534 this(name, true, new Translation(langs, name.getLocalPart()),
133     new Translation(), "");
134     }
135    
136     /**
137 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
138 alfonx 534 */
139 alfonx 770 public AttributeMetadataImpl(final NameImpl name, final String defaultTitle,
140 alfonx 534 final List<String> langs) {
141     this(name, true, new Translation(langs, defaultTitle),
142     new Translation(), "");
143     }
144    
145     /**
146 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
147 alfonx 464 * 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 alfonx 244 */
158 alfonx 769 public AttributeMetadataImpl(final String localName, final Boolean visible,
159 alfonx 464 final Translation title, final Translation desc, final String unit) {
160     this(new NameImpl(localName), true, title, desc, "");
161 alfonx 244 }
162    
163 alfonx 464 /**
164 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl} with default (no)
165     * values.
166 alfonx 464 */
167 alfonx 769 public AttributeMetadataImpl(final String localName,
168     final List<String> langs) {
169 alfonx 534 this(localName, true, new Translation(langs, localName),
170     new Translation(), "");
171 alfonx 464 }
172    
173     /**
174 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
175 alfonx 464 */
176 alfonx 769 public AttributeMetadataImpl(final String localName,
177     final String defaultTitle, final List<String> langs) {
178 alfonx 534 this(localName, true, new Translation(langs, defaultTitle),
179     new Translation(), "");
180 alfonx 464 }
181    
182     /**
183 alfonx 534 * Orders the attributes according to their {@link #weight}. Heavier =>
184     * further down.
185 alfonx 464 */
186 alfonx 534 @Override
187 alfonx 772 public int compareTo(final AttributeMetadataInterface atm2) {
188 alfonx 769 return new Integer(weight).compareTo(new Double(atm2.getWeight())
189     .intValue());
190 alfonx 464 }
191    
192     /**
193 alfonx 534 * @see Copyable inferface
194 alfonx 464 */
195 alfonx 534 @Override
196 alfonx 772 public AttributeMetadataInterface copy() {
197 alfonx 769 return copyTo(new AttributeMetadataImpl());
198 alfonx 464 }
199    
200 alfonx 534 /**
201     * @see Copyable inferface
202     */
203     @Override
204 alfonx 772 public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
205 alfonx 534 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 alfonx 769 if (amd instanceof AttributeMetadataImpl) {
215     AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
216 alfonx 534
217 alfonx 769 amd_.setFunctionX(getFunctionX());
218     amd_.setFunctionA(getFunctionA());
219     amd_.setNodataValues(getNodataValues());
220     }
221    
222 alfonx 534 return amd;
223 alfonx 420 }
224    
225 alfonx 678 // only to be used by copyTo()
226 alfonx 769 private void setNodataValues(HashSet<Object> nodataValues_) {
227     nodataValues = nodataValues_;
228 alfonx 678 }
229    
230 alfonx 534 public Double getFunctionA() {
231     return functionA;
232 alfonx 523 }
233    
234 alfonx 534 public Double getFunctionX() {
235     return functionX;
236 alfonx 244 }
237    
238 alfonx 534 /**
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 alfonx 769 @Override
244 alfonx 534 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 alfonx 244 }
252    
253 alfonx 534 public void setFunctionA(final Double functionA) {
254     this.functionA = functionA;
255 alfonx 420 }
256    
257 alfonx 534 public void setFunctionX(final Double functionX) {
258     this.functionX = functionX;
259 alfonx 420 }
260 alfonx 464
261    
262 alfonx 244 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26