29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger; |
package skrueger; |
31 |
|
|
32 |
|
import java.util.ArrayList; |
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; |
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üger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
50 |
*/ |
*/ |
51 |
public class AttributeMetadata implements Copyable<AttributeMetadata> { |
public class AttributeMetadata implements Copyable<AttributeMetadata>, |
52 |
|
Comparable<AttributeMetadata> { |
53 |
static private final Logger LOGGER = Logger |
static private final Logger LOGGER = Logger |
54 |
.getLogger(AttributeMetadata.class); |
.getLogger(AttributeMetadata.class); |
55 |
|
|
56 |
|
// public class WeightComparator implements Comparator<AttributeDescriptor> |
57 |
|
// { |
58 |
|
// |
59 |
|
// @Override |
60 |
|
// public int compare(AttributeDescriptor o1, AttributeDescriptor o2) { |
61 |
|
// // TODO Auto-generated method stub |
62 |
|
// return 0; |
63 |
|
// } |
64 |
|
// |
65 |
|
// }; |
66 |
|
|
67 |
|
/** Translation of the attribute's title **/ |
68 |
protected Translation title = new Translation(); |
protected Translation title = new Translation(); |
69 |
|
|
70 |
|
/** Translation of the attribute's description **/ |
71 |
protected Translation desc = new Translation(); |
protected Translation desc = new Translation(); |
72 |
|
|
73 |
|
/** Is the attribute visible to the user or ignored where possible **/ |
74 |
protected boolean visible = true; |
protected boolean visible = true; |
75 |
|
|
76 |
|
/** |
77 |
|
* The unit append to all visualizations of values of this attribute (is not |
78 |
|
* null) |
79 |
|
**/ |
80 |
protected String unit = ""; |
protected String unit = ""; |
81 |
protected int colIdx; |
|
82 |
|
/** The Name of the attribute **/ |
83 |
private Name name; |
private Name name; |
84 |
|
|
85 |
|
public int getWeight() { |
86 |
|
return weight; |
87 |
|
} |
88 |
|
|
89 |
|
public void setWeight(int weight) { |
90 |
|
this.weight = weight; |
91 |
|
} |
92 |
|
|
93 |
|
public List<Object> getNodataValues() { |
94 |
|
return nodataValues; |
95 |
|
} |
96 |
|
|
97 |
|
public void setNodataValues(List<Object> nodataValues) { |
98 |
|
this.nodataValues = nodataValues; |
99 |
|
} |
100 |
|
|
101 |
|
public Double getFunctionX() { |
102 |
|
return functionX; |
103 |
|
} |
104 |
|
|
105 |
|
public void setFunctionX(Double functionX) { |
106 |
|
this.functionX = functionX; |
107 |
|
} |
108 |
|
|
109 |
|
public Double getFunctionA() { |
110 |
|
return functionA; |
111 |
|
} |
112 |
|
|
113 |
|
public void setFunctionA(Double functionA) { |
114 |
|
this.functionA = functionA; |
115 |
|
} |
116 |
|
|
117 |
|
public void setVisible(boolean visible) { |
118 |
|
this.visible = visible; |
119 |
|
} |
120 |
|
|
121 |
|
/** |
122 |
|
* When listed, the attributes are listed according to their weight (heavier |
123 |
|
* => further down) |
124 |
|
**/ |
125 |
|
protected int weight = 0; |
126 |
|
|
127 |
|
/** |
128 |
|
* Allows to define general NODATA values for an attribute. e.g. -9999 can |
129 |
|
* be set and will always be interpreted as NULL internally and will usually |
130 |
|
* be ignored. |
131 |
|
**/ |
132 |
|
protected List<Object> nodataValues = new ArrayList<Object>(); |
133 |
|
|
134 |
|
/** |
135 |
|
* For numerical attributes the value can be transformed by VALUE*X+A when |
136 |
|
* presented on screen |
137 |
|
**/ |
138 |
|
protected Double functionX = 1.; |
139 |
|
|
140 |
|
/** |
141 |
|
* For numerical attributes the value can be transformed by VALUE*X+A when |
142 |
|
* presented on screen |
143 |
|
**/ |
144 |
|
protected Double functionA = 0.; |
145 |
|
|
146 |
/** |
/** |
147 |
* Creates an {@link AttributeMetadata} object with the following |
* Creates an {@link AttributeMetadata} object with the following |
148 |
* information |
* information |
236 |
} |
} |
237 |
|
|
238 |
public void setVisible(final Boolean visible) { |
public void setVisible(final Boolean visible) { |
239 |
|
|
240 |
|
// The THE_GEOM and shall never be visible! // TODO MAKE BETTER |
241 |
|
if (name.getLocalPart().equalsIgnoreCase("the_geom")) |
242 |
|
this.visible = false; |
243 |
|
else |
244 |
|
this.visible = visible; |
245 |
|
|
246 |
this.visible = visible; |
this.visible = visible; |
247 |
} |
} |
248 |
|
|
|
// |
|
|
// /** @return the index of this attribute in the underlying table/dbf **/ |
|
|
// public int getColIdx() { |
|
|
// return colIdx; |
|
|
// } |
|
|
|
|
249 |
public Translation getTitle() { |
public Translation getTitle() { |
250 |
return title; |
return title; |
251 |
} |
} |
279 |
amd.setName(new NameImpl(getName().getNamespaceURI(), getName() |
amd.setName(new NameImpl(getName().getNamespaceURI(), getName() |
280 |
.getLocalPart())); |
.getLocalPart())); |
281 |
|
|
282 |
|
amd.setWeight(getWeight()); |
283 |
|
amd.setFunctionX(getFunctionX()); |
284 |
|
amd.setFunctionA(getFunctionA()); |
285 |
|
|
286 |
|
for (Object nodataValue : getNodataValues()) { |
287 |
|
amd.getNodataValues().add(nodataValue); |
288 |
|
} |
289 |
|
|
290 |
return amd; |
return amd; |
291 |
} |
} |
292 |
|
|
322 |
public void setLocalName(String localName) { |
public void setLocalName(String localName) { |
323 |
this.name = new NameImpl(localName); |
this.name = new NameImpl(localName); |
324 |
} |
} |
325 |
|
|
326 |
|
/** |
327 |
|
* Orders the Attributes according to their weight. Heavier => further down. |
328 |
|
*/ |
329 |
|
@Override |
330 |
|
public int compareTo(AttributeMetadata atm2) { |
331 |
|
// Double double1 = new Double(1./weight); |
332 |
|
// double double2 = 1./atm2.getWeight(); |
333 |
|
return new Integer(weight).compareTo(atm2.getWeight()); |
334 |
|
} |
335 |
|
|
336 |
|
/** |
337 |
|
* @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes |
338 |
|
*/ |
339 |
|
public double getQuality(List<String> languages) { |
340 |
|
return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil |
341 |
|
.qmTranslation(languages, getDesc()) * 1.) / 3.; |
342 |
|
} |
343 |
} |
} |