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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/AttributeMetaData.java revision 93 by alfonx, Fri May 1 16:24:15 2009 UTC branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java revision 464 by alfonx, Tue Oct 13 13:22:31 2009 UTC
# Line 1  Line 1 
1  package skrueger;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import org.apache.log4j.Logger;   *
4     * This file is part of the SCHMITZM library - a collection of utility
5  import skrueger.geotools.StyledMapInterface;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import skrueger.i8n.Translation;   * and the Geotools library.
7     *
8  /**   * The SCHMITZM project is hosted at:
9   * This class holds meta information about an attribute/column. This   * http://wald.intevation.org/projects/schmitzm/
10   * information is used by {@link StyledMapInterface}.   *
11   *   * This program is free software; you can redistribute it and/or
12   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * modify it under the terms of the GNU Lesser General Public License
13   */   * as published by the Free Software Foundation; either version 3
14  public class AttributeMetaData {   * of the License, or (at your option) any later version.
15          static private final Logger LOGGER = Logger   *
16                          .getLogger(AttributeMetaData.class);   * This program is distributed in the hope that it will be useful,
17          protected Translation title = new Translation();   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18          protected Translation desc = new Translation();   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19          protected boolean visible = false;   * GNU General Public License for more details.
20          protected String unit = "";   *
21          protected int colIdx;   * 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           * Creates an {@link AttributeMetaData} object with the following information   * or try this link: http://www.gnu.org/licenses/lgpl.html
25           * @param colIdx The column index of this attribute in the underlying table/dbf/etc...   *
26           * @param visible Shall this attribute be displayed or hidden from the user?   * Contributors:
27           * @param title {@link Translation} for Name   *     Martin O. J. Schmitz - initial API and implementation
28           * @param desc {@link Translation} for an attribute description   *     Stefan A. Krüger - additional utility classes
29           * @param unit {@link String} of the unit that the information is in   ******************************************************************************/
30           */  package skrueger;
31          public AttributeMetaData(final int colIdx, final Boolean visible,  
32                          final Translation title, final Translation desc, final String unit) {  import org.apache.log4j.Logger;
33            import org.geotools.feature.NameImpl;
34                  this.colIdx = colIdx;  import org.opengis.feature.type.AttributeDescriptor;
35                  this.title = title;  import org.opengis.feature.type.Name;
36                  this.desc = desc;  
37                  if (colIdx == 0){  import skrueger.geotools.Copyable;
38                          // The first attribut is THE_GEOM and shall never be visible!  import skrueger.geotools.StyledLayerInterface;
39                          this.visible = false;  import skrueger.i8n.Translation;
40                  }else  
41                          this.visible = visible;  /**
42                  this.unit = unit;   * This class holds meta information about an attribute/column. This information
43          }   * is used by {@link StyledLayerInterface}.
44     *
45          /**   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
46           * Creates a new visible {@link AttributeMetaData} with default (no) values.     */
47           */  public class AttributeMetadata implements Copyable<AttributeMetadata> {
48          public AttributeMetaData(final Integer col, final String defaultName) {          static private final Logger LOGGER = Logger
49                  this(col, true, new Translation(defaultName), new Translation(), "");                          .getLogger(AttributeMetadata.class);
50          }  
51            protected Translation title = new Translation();
52          public Boolean isVisible() {          protected Translation desc = new Translation();
53                  return visible;          protected boolean visible = true;
54          }          protected String unit = "";
55            protected int colIdx;
56          public void setVisible(final Boolean visible) {          private org.opengis.feature.type.Name name;
57                  this.visible = visible;  
58          }          /**
59             * Creates an {@link AttributeMetadata} object with the following
60          /** @return the index of this attribute in the underlying table/dbf **/           * information
61          public int getColIdx() {           *
62                  return colIdx;           * @param colIdx
63          }           *            The column index of this attribute in the underlying
64             *            table/dbf/etc...
65          public Translation getTitle() {           * @param visible
66                  return title;           *            Shall this attribute be displayed or hidden from the user?
67          }           * @param title
68             *            {@link Translation} for Name
69          public void setTitle(final Translation title) {           * @param desc
70                  this.title = title;           *            {@link Translation} for an attribute description
71          }           * @param unit
72             *            {@link String} of the unit that the information is in
73          public Translation getDesc() {           */
74                  return desc;          public AttributeMetadata(final Name name, final Boolean visible,
75          }                          final Translation title, final Translation desc, final String unit) {
76    
77          public void setDesc(final Translation desc) {                  this.setName(name);
78                  this.desc = desc;                  this.title = title;
79          }                  this.desc = desc;
80                    
81          public String getUnit() {                  // The THE_GEOM and shall never be visible!
82                  return unit;                  if (name.getLocalPart().equalsIgnoreCase("the_geom")) this.visible = false;
83          }                  
84                    this.unit = unit;
85          public void setUnit(final String unit) {          }
86                  this.unit = unit;  
87          }          /**
88  }           * Creates an {@link AttributeMetadata} object with the following
89             * information
90             *
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             */
100            public AttributeMetadata(final String localName, final Boolean visible,
101                            final Translation title, final Translation desc, final String unit) {
102                    this(new NameImpl(localName), true, title, desc, "");
103            }
104    
105            /**
106             * Creates a new visible {@link AttributeMetadata} with default (no) values.
107             */
108            public AttributeMetadata(final String localName, final String defaultTitle) {
109                    this(localName, true, new Translation(defaultTitle), new Translation(),
110                                    "");
111            }
112    
113            /**
114             * Creates a new visible {@link AttributeMetadata} with default (no) values.
115             */
116            public AttributeMetadata(final Name name, final String defaultTitle) {
117                    this(name, true, new Translation(defaultTitle), new Translation(), "");
118            }
119    
120            /**
121             * Creates a new visible {@link AttributeMetadata} with default (no) values.
122             */
123            public AttributeMetadata(final Name name) {
124                    this(name, true, new Translation(name.getLocalPart()),
125                                    new Translation(), "");
126            }
127    
128            /**
129             * Creates a new visible {@link AttributeMetadata} with default (no) values.
130             */
131            public AttributeMetadata(final String localName) {
132                    this(localName, true, new Translation(localName), new Translation(), "");
133            }
134    
135            /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
136            private AttributeMetadata() {
137            }
138    
139            public AttributeMetadata(AttributeDescriptor attDesc) {
140                    this(attDesc.getName());
141            }
142    
143            public boolean isVisible() {
144                    return visible;
145            }
146    
147            public void setVisible(final Boolean visible) {
148                    this.visible = visible;
149            }
150    //
151    //      /** @return the index of this attribute in the underlying table/dbf **/
152    //      public int getColIdx() {
153    //              return colIdx;
154    //      }
155    
156            public Translation getTitle() {
157                    return title;
158            }
159    
160            public void setTitle(final Translation title) {
161                    this.title = title;
162            }
163    
164            public Translation getDesc() {
165                    return desc;
166            }
167    
168            public void setDesc(final Translation desc) {
169                    this.desc = desc;
170            }
171    
172            public String getUnit() {
173                    return unit;
174            }
175    
176            public void setUnit(final String unit) {
177                    this.unit = unit;
178            }
179    
180            @Override
181            public AttributeMetadata copyTo(AttributeMetadata amd) {
182                    getTitle().copyTo(amd.getTitle());
183                    getDesc().copyTo(amd.getDesc());
184                    amd.setUnit(getUnit());
185                    amd.setVisible(isVisible());
186                    amd.setName(new NameImpl(getName().getNamespaceURI(), getName().getLocalPart()));
187    
188                    return amd;
189            }
190    
191            @Override
192            public AttributeMetadata copy() {
193                    return copyTo( new AttributeMetadata());
194            }
195    
196            /**
197             * The local Name. E.g. the name of the DBF column as a String
198             */
199            public String getLocalName() {
200                    return getName().getLocalPart();
201            }
202    
203            /**
204             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
205             */
206            public Name getName() {
207                    return name;
208            }
209    
210            /**
211             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
212             */
213            public void setName(org.opengis.feature.type.Name name) {
214                    this.name = name;
215            }
216    
217            /**
218             * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
219             */
220            public void setLocalName(String localName) {
221                    this.name = new NameImpl(localName);
222            }
223    }

Legend:
Removed from v.93  
changed lines
  Added in v.464

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26