|
/******************************************************************************* |
|
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
|
|
* |
|
|
* This file is part of the SCHMITZM library - a collection of utility |
|
|
* classes based on Java 1.6, focusing (not only) on Java Swing |
|
|
* and the Geotools library. |
|
|
* |
|
|
* The SCHMITZM project is hosted at: |
|
|
* http://wald.intevation.org/projects/schmitzm/ |
|
|
* |
|
|
* This program is free software; you can redistribute it and/or |
|
|
* modify it under the terms of the GNU Lesser General Public License |
|
|
* as published by the Free Software Foundation; either version 3 |
|
|
* of the License, or (at your option) any later version. |
|
|
* |
|
|
* This program is distributed in the hope that it will be useful, |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
* GNU General Public License for more details. |
|
|
* |
|
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
|
|
* along with this program; if not, write to the Free Software |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
|
|
* |
|
|
* Contributors: |
|
|
* Martin O. J. Schmitz - initial API and implementation |
|
|
* Stefan A. Krüger - additional utility classes |
|
|
******************************************************************************/ |
|
1 |
package skrueger; |
package skrueger; |
2 |
|
|
3 |
import org.apache.log4j.Logger; |
import java.io.Serializable; |
4 |
|
import java.util.HashSet; |
5 |
|
import java.util.Set; |
6 |
|
|
7 |
|
import org.geotools.feature.NameImpl; |
8 |
|
import org.opengis.feature.type.Name; |
9 |
|
|
10 |
import skrueger.geotools.Copyable; |
import skrueger.geotools.Copyable; |
|
import skrueger.geotools.StyledLayerInterface; |
|
11 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
12 |
|
|
13 |
/** |
public interface AttributeMetadataInterface extends Copyable<AttributeMetadataInterface>, |
14 |
* This class holds meta information about an attribute/column. This |
Comparable<AttributeMetadataInterface> { |
15 |
* information is used by {@link StyledLayerInterface}. |
|
|
* |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
|
|
*/ |
|
|
public class AttributeMetadata implements Copyable<AttributeMetadata>{ |
|
|
static private final Logger LOGGER = Logger |
|
|
.getLogger(AttributeMetadata.class); |
|
|
protected Translation title = new Translation(); |
|
|
protected Translation desc = new Translation(); |
|
|
protected boolean visible = false; |
|
|
protected String unit = ""; |
|
|
protected int colIdx; |
|
|
|
|
16 |
/** |
/** |
17 |
* Creates an {@link AttributeMetadata} object with the following information |
* @return a translatable title for this attribute.. |
|
* @param colIdx The column index of this attribute in the underlying table/dbf/etc... |
|
|
* @param visible Shall this attribute be displayed or hidden from the user? |
|
|
* @param title {@link Translation} for Name |
|
|
* @param desc {@link Translation} for an attribute description |
|
|
* @param unit {@link String} of the unit that the information is in |
|
18 |
*/ |
*/ |
19 |
public AttributeMetadata(final int colIdx, final Boolean visible, |
public Translation getTitle(); |
20 |
final Translation title, final Translation desc, final String unit) { |
|
21 |
|
/** |
22 |
|
* Set a translatable title for this attribute.. |
23 |
|
*/ |
24 |
|
public void setTitle(Translation title); |
25 |
|
|
26 |
this.colIdx = colIdx; |
/** |
27 |
this.title = title; |
* Set an untranslated title for this attribute or pass a {@link Translation} encryped as a {@link String} |
28 |
this.desc = desc; |
*/ |
29 |
if (colIdx == 0){ |
public void setTitle(String title); |
30 |
// The first attribute is THE_GEOM and shall never be visible! |
|
31 |
this.visible = false; |
/** |
32 |
}else |
* @return a translatable description for this attribute |
33 |
this.visible = visible; |
*/ |
34 |
this.unit = unit; |
public Translation getDesc(); |
35 |
} |
|
36 |
|
/** |
37 |
/** |
* Set a translatable description for this attribute. |
38 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
*/ |
39 |
*/ |
public void setDesc(Translation desc); |
40 |
public AttributeMetadata(final Integer col, final String defaultName) { |
|
41 |
this(col, true, new Translation(defaultName), new Translation(), ""); |
/** |
42 |
} |
* Set an untranslated description for this attribute or pass a {@link Translation} encryped as a {@link String} |
43 |
|
*/ |
44 |
/** Only used for {@link Copyable<AttributeMetaData>#copy()}**/ |
public void setDesc(String desc); |
45 |
private AttributeMetadata() { |
|
46 |
} |
|
47 |
|
/** |
48 |
public boolean isVisible() { |
* The local name. E.g. the name of the DBF column as a {@link String}. |
49 |
return visible; |
*/ |
50 |
} |
public String getLocalName(); |
51 |
|
|
52 |
public void setVisible(final Boolean visible) { |
/** |
53 |
this.visible = visible; |
* A short form for #setName(new NameImpl(localName)) |
54 |
} |
*/ |
55 |
|
public void setLocalName(String localName); |
56 |
/** @return the index of this attribute in the underlying table/dbf **/ |
|
57 |
public int getColIdx() { |
/** |
58 |
return colIdx; |
* The fully qualified {@link Name} of the attribute, e.g. |
59 |
} |
* <code>org.bla.plo:blub</code>. The second part equals the |
60 |
|
* {@link #getLocalName()} value. The first may be <code>null</code> or |
61 |
public Translation getTitle() { |
* represent the layer name. |
62 |
return title; |
*/ |
63 |
} |
public NameImpl getName(); |
64 |
|
|
65 |
public void setTitle(final Translation title) { |
/** |
66 |
this.title = title; |
* set the fully qualified {@link Name} of this attribute. |
67 |
} |
*/ |
68 |
|
public void setName(NameImpl name); |
69 |
public Translation getDesc() { |
|
70 |
return desc; |
/** |
71 |
} |
* A list og objects that represent NODATA-values for this attribute. The |
72 |
|
* objects are supporsed to be correctly casted already. That means that the |
73 |
public void setDesc(final Translation desc) { |
* NODATA objects listed here have must have the same type as the values of |
74 |
this.desc = desc; |
* this object. |
75 |
} |
*/ |
76 |
|
public HashSet<Object> getNodataValues(); |
77 |
public String getUnit() { |
|
78 |
return unit; |
/** |
79 |
} |
* Takes any value object and checks it against the NODATA values. If the |
80 |
|
* value equals a NODATA value, <code>null</code> is returned. Otherwise the |
81 |
public void setUnit(final String unit) { |
* same object is returned. |
82 |
this.unit = unit; |
* |
83 |
} |
* Note: This method is called often. |
84 |
|
*/ |
85 |
@Override |
public Object fiterNodata(Object value); |
86 |
public AttributeMetadata copyTo(AttributeMetadata amd) { |
|
87 |
getTitle().copyTo(amd.getTitle()); |
/** |
88 |
getDesc().copyTo(amd.getDesc()); |
* @return a non-translatable unit {@link String} for this attribute values. |
89 |
amd.setUnit(getUnit()); |
*/ |
90 |
amd.setVisible(isVisible()); |
public String getUnit(); |
91 |
amd.setColIdx(getColIdx()); |
|
92 |
|
/** |
93 |
return amd; |
* Set a unit {@link String} for this attribute values. |
94 |
} |
*/ |
95 |
|
public void setUnit(String unit); |
96 |
@Override |
|
97 |
public AttributeMetadata copy() { |
/** |
98 |
AttributeMetadata amd = new AttributeMetadata(); |
* @return A value defining the position of this attribute whenever the |
99 |
getTitle().copyTo(amd.getTitle()); |
* attributes are listed to an end-user. The higher the weight, the |
100 |
getDesc().copyTo(amd.getDesc()); |
* lower the position. (heavy goes down, light goes up) |
101 |
amd.setUnit(getUnit()); |
*/ |
102 |
amd.setVisible(isVisible()); |
public double getWeight(); |
103 |
amd.setColIdx(getColIdx()); |
|
104 |
|
/** |
105 |
return amd; |
* set a value defining the position of this attribute whenever the |
106 |
} |
* attributes are listed to an end-user. The higher the weight, the lower |
107 |
|
* the position. (heavy goes down, light goes up) |
108 |
private void setColIdx(int colIdx_) { |
*/ |
109 |
colIdx = colIdx_; |
public void setWeight(double weight); |
110 |
} |
|
111 |
|
/** |
112 |
|
* @return <code>false</code> if this attribute should not be selectable or |
113 |
|
* shown to the end-user. |
114 |
|
*/ |
115 |
|
public boolean isVisible(); |
116 |
|
|
117 |
|
/** |
118 |
|
* Set <code>false</code> if this attribute should not be shown to the |
119 |
|
* end-user. |
120 |
|
*/ |
121 |
|
public void setVisible(boolean visible); |
122 |
|
|
123 |
|
String getNoDataValuesFormatted(); |
124 |
|
|
125 |
} |
} |