/[schmitzm]/branches/2.2.x/src/skrueger/AbstractAttributeMetadata.java
ViewVC logotype

Contents of /branches/2.2.x/src/skrueger/AbstractAttributeMetadata.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 772 - (show annotations)
Sun Mar 21 14:05:26 2010 UTC (14 years, 11 months ago) by alfonx
Original Path: trunk/src/skrueger/AbstractAttributeMetadata.java
File MIME type: text/plain
File size: 4192 byte(s)
The new Interface AttributeMetadata has been renamed to AttributeMetadataInterface. 

1 package skrueger;
2
3 import java.util.HashSet;
4
5 import org.geotools.feature.NameImpl;
6 import org.opengis.feature.type.Name;
7
8 import skrueger.geotools.StyledLayerUtil;
9 import skrueger.i8n.Translation;
10
11 public abstract class AbstractAttributeMetadata implements AttributeMetadataInterface {
12
13 /** The Name of the attribute. This is the 'primary key' **/
14 protected NameImpl name;
15
16 /** {@link Translation}s of the attribute's title **/
17 protected Translation title = new Translation();
18
19 /** {@link Translation}s of the attribute's description **/
20 protected Translation desc = new Translation();
21
22 /**
23 * Allows to define general NODATA values for an attribute. e.g. -9999 can
24 * be set and will always be interpreted as NULL internally and will usually
25 * be ignored. This overcomes the problem, that
26 **/
27 protected HashSet<Object> nodataValues = new HashSet<Object>();
28
29 /**
30 * The unit append to all visualizations of values of this attribute (is not
31 * null)
32 **/
33 protected String unit = "";
34
35 /** Is the attribute visible to the user or ignored where possible **/
36 protected boolean visible = true;
37
38 @Override
39 public Translation getTitle() {
40 return title;
41 }
42
43 @Override
44 public String getUnit() {
45 return unit;
46 }
47
48 @Override
49 public void setTitle(final String title) {
50 this.title = new Translation(title);
51 }
52
53 @Override
54 public void setDesc(final String desc) {
55 this.desc = new Translation(desc);
56 }
57
58 /**
59 * When listed, the attributes are listed according to their {@link #weight}
60 * (heavier => further down)
61 *
62 * @see #compareTo(AttributeMetadataImpl)
63 **/
64 protected int weight = 0;
65
66 @Override
67 public double getWeight() {
68 return weight;
69 }
70
71 @Override
72 public void setWeight(double weight) {
73 this.weight = new Double(weight).intValue();
74 }
75
76 /**
77 * Will the end-user see this attribute?
78 */
79 @Override
80 public boolean isVisible() {
81 return visible;
82 }
83
84 @Override
85 public void setDesc(final Translation desc) {
86 this.desc = desc;
87 }
88
89 @Override
90 public Translation getDesc() {
91 return desc;
92 }
93
94 /**
95 * The local name. E.g. the name of the DBF column as a {@link String}
96 */
97 @Override
98 public String getLocalName() {
99 return getName().getLocalPart();
100 }
101
102 /**
103 * The fully qualified {@link Name} of the attribute, e.g.
104 * <code>org.bla.plo:blub</code>
105 */
106 @Override
107 public NameImpl getName() {
108 return name;
109 }
110
111 @Override
112 public HashSet<Object> getNodataValues() {
113 return nodataValues;
114 }
115
116 /**
117 * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
118 */
119 @Override
120 public void setLocalName(final String localName) {
121 setName(new NameImpl(localName));
122 }
123
124 /**
125 * The fully qualified {@link Name} of the attribute, e.g.
126 * <code>org.bla.plo:blub</code>
127 */
128 @Override
129 public void setName(final NameImpl name) {
130 this.name = name;
131 }
132
133 public void addNodataValue(Object nodataValue) {
134 this.nodataValues.add(nodataValue);
135 }
136
137 public void removeNodataValue(Object nodataValue) {
138 this.nodataValues.remove(nodataValue);
139 }
140
141 @Override
142 public void setTitle(final Translation title) {
143 this.title = title;
144 }
145
146 @Override
147 public void setUnit(final String unit) {
148 this.unit = unit;
149 }
150
151 @Override
152 public void setVisible(final boolean visible) {
153 this.visible = visible;
154 }
155
156 /**
157 * For nicer debugging
158 */
159 @Override
160 public String toString() {
161 StringBuffer sb = new StringBuffer();
162 if (name != null)
163 sb.append(name.toString() + " ");
164 sb.append("weight=" + weight + " ");
165 sb.append("title=" + getTitle().toString());
166 return sb.toString();
167 }
168
169
170 /**
171 * Takes any value object and checks it against the NODATA values. If the
172 * value equals a NODATA value, <code>null</code> is returned. Otherwise the
173 * same object is returned.
174 *
175 * Note: This method is called often.
176 */
177 @Override
178 public Object fiterNodata(final Object value) {
179 if (nodataValues.contains(value))
180 return null;
181 return value;
182 }
183
184 /**
185 * @return a nicely formatted String containing all NODATA values. Strings
186 * are quoted so that any empty {@link String} can be seen.
187 */
188 @Override
189 public String getNoDataValuesFormatted() {
190 return StyledLayerUtil.formatNoDataValues(getNodataValues());
191 }
192 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26