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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 888 - (hide annotations)
Thu Jun 3 10:48:43 2010 UTC (14 years, 8 months ago) by alfonx
File size: 8038 byte(s)
* Changes some more kruegers to tzeggai
* Renamed Geopublisher_de.proaperties ResourceBundle to geopublisherTranslation_de.properties etc... 
* Moved openOSFolder(File) method to SwingUtil,allowing to open a folder with a os dependent file explorer
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 alfonx 862 * Stefan A. Tzeggai - additional utility classes
29 alfonx 244 ******************************************************************************/
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 797 import org.opengis.feature.type.Name;
39 alfonx 244
40 alfonx 420 import skrueger.geotools.Copyable;
41 mojays 325 import skrueger.geotools.StyledLayerInterface;
42 alfonx 518 import skrueger.i8n.I8NUtil;
43 alfonx 244 import skrueger.i8n.Translation;
44    
45     /**
46 alfonx 464 * This class holds meta information about an attribute/column. This information
47 alfonx 518 * is used by {@link StyledLayerInterface} and many others.<br/>
48 alfonx 464 *
49 alfonx 888 * @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a>
50 alfonx 244 */
51 alfonx 769 public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
52     QualityQuantizable {
53 alfonx 681
54 alfonx 244 static private final Logger LOGGER = Logger
55 alfonx 769 .getLogger(AttributeMetadataImpl.class);
56 alfonx 464
57 alfonx 534 /**
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 alfonx 518
63     /**
64 alfonx 534 * For numerical attributes the value can be transformed by VALUE*X+A when
65     * presented on screen. TODO not implemented yet
66 alfonx 518 **/
67 alfonx 534 protected Double functionX = 1.;
68 alfonx 518
69 alfonx 534 /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
70 alfonx 769 private AttributeMetadataImpl() {
71 alfonx 534 }
72    
73 alfonx 769 public AttributeMetadataImpl(final AttributeDescriptor attDesc,
74 alfonx 681 final int weight, final List<String> langs) {
75 alfonx 770 this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
76 alfonx 534 setWeight(weight);
77     }
78    
79 alfonx 769 public AttributeMetadataImpl(final AttributeDescriptor attDesc,
80 alfonx 681 final List<String> langs) {
81 alfonx 770 this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
82 alfonx 534 }
83    
84 alfonx 518 /**
85 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
86 alfonx 464 * information
87     *
88     * @param colIdx
89     * The column index of this attribute in the underlying
90     * table/dbf/etc...
91     * @param visible
92     * Shall this attribute be displayed or hidden from the user?
93     * @param title
94     * {@link Translation} for Name
95     * @param desc
96     * {@link Translation} for an attribute description
97     * @param unit
98     * {@link String} of the unit that the information is in
99 alfonx 244 */
100 alfonx 797 public AttributeMetadataImpl(final Name name, final Boolean visible,
101 alfonx 244 final Translation title, final Translation desc, final String unit) {
102 alfonx 464
103     this.setName(name);
104 alfonx 244 this.title = title;
105     this.desc = desc;
106 alfonx 546 this.visible = visible;
107 alfonx 244 this.unit = unit;
108     }
109    
110     /**
111 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
112 alfonx 658 * 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 alfonx 797 public AttributeMetadataImpl(final Name name, final Boolean visible,
123 alfonx 681 final String unit) {
124 alfonx 658 this.setName(name);
125     this.visible = visible;
126     this.unit = unit;
127     }
128    
129     /**
130 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
131 alfonx 534 */
132 alfonx 797 public AttributeMetadataImpl(final Name name, final List<String> langs) {
133 alfonx 534 this(name, true, new Translation(langs, name.getLocalPart()),
134     new Translation(), "");
135     }
136    
137     /**
138 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
139 alfonx 534 */
140 alfonx 797 public AttributeMetadataImpl(final Name name, final String defaultTitle,
141 alfonx 534 final List<String> langs) {
142     this(name, true, new Translation(langs, defaultTitle),
143     new Translation(), "");
144     }
145    
146     /**
147 alfonx 769 * Creates an {@link AttributeMetadataImpl} object with the following
148 alfonx 464 * information
149     *
150     * @param visible
151     * Shall this attribute be displayed or hidden from the user?
152     * @param title
153     * {@link Translation} for Name
154     * @param desc
155     * {@link Translation} for an attribute description
156     * @param unit
157     * {@link String} of the unit that the information is in
158 alfonx 244 */
159 alfonx 769 public AttributeMetadataImpl(final String localName, final Boolean visible,
160 alfonx 464 final Translation title, final Translation desc, final String unit) {
161     this(new NameImpl(localName), true, title, desc, "");
162 alfonx 244 }
163    
164 alfonx 464 /**
165 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl} with default (no)
166     * values.
167 alfonx 464 */
168 alfonx 769 public AttributeMetadataImpl(final String localName,
169     final List<String> langs) {
170 alfonx 534 this(localName, true, new Translation(langs, localName),
171     new Translation(), "");
172 alfonx 464 }
173    
174     /**
175 alfonx 769 * Creates a new visible {@link AttributeMetadataImpl}
176 alfonx 464 */
177 alfonx 769 public AttributeMetadataImpl(final String localName,
178     final String defaultTitle, final List<String> langs) {
179 alfonx 534 this(localName, true, new Translation(langs, defaultTitle),
180     new Translation(), "");
181 alfonx 464 }
182    
183     /**
184 alfonx 534 * Orders the attributes according to their {@link #weight}. Heavier =>
185     * further down.
186 alfonx 464 */
187 alfonx 534 @Override
188 alfonx 772 public int compareTo(final AttributeMetadataInterface atm2) {
189 alfonx 769 return new Integer(weight).compareTo(new Double(atm2.getWeight())
190     .intValue());
191 alfonx 464 }
192    
193     /**
194 alfonx 534 * @see Copyable inferface
195 alfonx 464 */
196 alfonx 534 @Override
197 alfonx 772 public AttributeMetadataInterface copy() {
198 alfonx 769 return copyTo(new AttributeMetadataImpl());
199 alfonx 464 }
200    
201 alfonx 534 /**
202     * @see Copyable inferface
203     */
204     @Override
205 alfonx 772 public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
206 alfonx 534 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     amd.setWeight(getWeight());
214    
215 alfonx 769 if (amd instanceof AttributeMetadataImpl) {
216     AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
217 alfonx 534
218 alfonx 769 amd_.setFunctionX(getFunctionX());
219     amd_.setFunctionA(getFunctionA());
220     amd_.setNodataValues(getNodataValues());
221     }
222    
223 alfonx 534 return amd;
224 alfonx 420 }
225    
226 alfonx 678 // only to be used by copyTo()
227 alfonx 769 private void setNodataValues(HashSet<Object> nodataValues_) {
228     nodataValues = nodataValues_;
229 alfonx 678 }
230    
231 alfonx 534 public Double getFunctionA() {
232     return functionA;
233 alfonx 523 }
234    
235 alfonx 534 public Double getFunctionX() {
236     return functionX;
237 alfonx 244 }
238    
239 alfonx 534 /**
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 alfonx 769 @Override
245 alfonx 534 public double getQuality(final List<String> languages) {
246    
247     if (!isVisible())
248     return 1.;
249    
250     return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
251     .qmTranslation(languages, getDesc()) * 1.) / 3.;
252 alfonx 244 }
253    
254 alfonx 534 public void setFunctionA(final Double functionA) {
255     this.functionA = functionA;
256 alfonx 420 }
257    
258 alfonx 534 public void setFunctionX(final Double functionX) {
259     this.functionX = functionX;
260 alfonx 420 }
261 alfonx 464
262    
263 alfonx 244 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26