/[schmitzm]/trunk/src/skrueger/geotools/AbstractStyledLayer.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/AbstractStyledLayer.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 244 - (hide annotations)
Wed Jul 29 09:33:33 2009 UTC (15 years, 7 months ago) by alfonx
File size: 9762 byte(s)
* Updated all .java and .properties headers with a recent LGPL 3.0 and a link to the project webpage.
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     * classes based on Java 1.6, focussing (not only) on Java Swing
6     * 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     * Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30     package skrueger.geotools;
31    
32     import javax.swing.ImageIcon;
33    
34     import org.apache.log4j.Logger;
35     import org.geotools.styling.Style;
36     import org.opengis.referencing.crs.CoordinateReferenceSystem;
37    
38     import schmitzm.lang.LangUtil;
39     import skrueger.i8n.Translation;
40    
41     import com.vividsolutions.jts.geom.Envelope;
42    
43     /**
44     * This class is a default implementation of {@link StyledLayerInterface}.
45     * {@link StyledLayerInterface#dispose()} and {@link StyledLayerInterface#uncache()}
46     * must be implemented by the sub class. This class only implements the "hold"
47     * of an geo object of type {@code <E>}.
48     * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
49     * @version 1.0
50     */
51     public abstract class AbstractStyledLayer<E> implements StyledLayerInterface<E> {
52     /** Logger for warning- and error messages. */
53     protected Logger LOGGER = LangUtil.createLogger(this);
54    
55     /** Holds the unique ID of the geo object. */
56     protected String id = null;
57     /** Holds a short (language-specific) description of the geo object. */
58     protected Translation title = null;
59     /** Holds a long (language-specific) description of the geo object. */
60     protected Translation desc = null;
61     /** Holds the (language-specific) keywords to describe the geo object. */
62     protected Translation keywords = null;
63     /** Holds an icon to represent the geo object */
64     protected ImageIcon icon = null;
65     /** Holds the geo object represeneted by the map */
66     protected E geoObject = null;
67     /** Holds the CRS of the geo object */
68     protected CoordinateReferenceSystem crs = null;
69     /** Holds the bounds of the geo object */
70     protected Envelope envelope = null;
71     /** Holds the display style for the geo object */
72     protected Style style = null;
73    
74     /**
75     * Creates a language specific styled layer.
76     * @param geoObject the geo object
77     * @param envelope the bounds of the geo object
78     * @param crs the CRS of the geo object
79     * @param id a unique ID for the geo object
80     * @param title a (language-specific) short description
81     * @param desc a (language-specific) long description
82     * @param keywords (language-specific) keywords for the geo objects
83     * @param style a display style
84     * @param icon an icon for the object
85     * @exception IllegalArgumentException if {@code null} is given as ID or
86     * geo object
87     */
88     public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) {
89     if ( id == null )
90     throw new IllegalArgumentException("ID is not allowed to be null!");
91     if ( geoObject == null )
92     throw new IllegalArgumentException("The GeoObject is not allowed to be null!");
93     this.id = id;
94     this.geoObject = geoObject;
95     this.crs = crs;
96     this.envelope = envelope;
97     setTitle( title );
98     setDesc( desc );
99     setKeywords( keywords );
100     setStyle( style );
101     setImageIcon( icon );
102     }
103    
104     /**
105     * Creates a non-translated styled layer.
106     * @param geoObject the geo object
107     * @param envelope the bounds of the geo object
108     * @param crs the CRS of the geo object
109     * @param id a unique ID for the geo object
110     * @param title a short description
111     * @param desc a long description
112     * @param keywords keywords for the geo objects
113     * @param style a display style
114     * @param icon an icon for the object
115     * @exception IllegalArgumentException if {@code null} is given as ID
116     */
117     public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, String title, String desc, String keywords, Style style, ImageIcon icon ) {
118     this(geoObject, envelope, crs, id, (Translation)null, null, null, style, icon);
119     setTitle( title );
120     setDesc( desc );
121     setKeywords( keywords );
122     }
123    
124     /**
125     * Returns a ID for the geo object. The ID should be unique in a map ob
126     * {@linkplain StyledLayerInterface styled layer objects}
127     */
128     public String getId() {
129     return id;
130     }
131    
132     /**
133     * Returns a short (language-specific) description of the geo object.
134     */
135     public Translation getTitle() {
136     return title;
137     }
138    
139     /**
140     * Sets a short (language-specific) description of the geo object.
141     * If {@code title} is {@code null} an untranslated default title is set, so
142     * {@link #getTitle()} never returns {@code null}.
143     * @param title new description for the geo object
144     */
145     public void setTitle(Translation title) {
146     this.title = (title != null) ? title : new Translation("untitled");
147     }
148    
149     /**
150     * Sets a short (non-translated) description of the geo object.
151     * If {@code title} is {@code null} an untranslated default title is set, so
152     * {@link #getTitle()} never returns {@code null}.
153     * @param title new description for the geo object
154     */
155     public void setTitle(String title) {
156     setTitle( title != null ? new Translation(title): (Translation)null );
157     }
158    
159     /**
160     * Returns a long (language-specific) description of the object.
161     */
162     public Translation getDesc() {
163     return desc;
164     }
165    
166     /**
167     * Sets a long (language-specific) description of the object.
168     * If {@code desc} is {@code null} an (untranslated) empty description is set, so
169     * {@link #getDesc()} never returns {@code null}.
170     * @param desc new description for the geo object
171     */
172     public void setDesc(Translation desc) {
173     this.desc = (desc != null) ? desc : new Translation("");
174     }
175    
176     /**
177     * Sets a long (non-translated) description of the object.
178     * If {@code desc} is {@code null} an (untranslated) empty description is set, so
179     * {@link #getDesc()} never returns {@code null}.
180     * @param desc new description for the geo object
181     */
182     public void setDesc(String desc) {
183     setDesc( desc != null ? new Translation(desc) : (Translation)null);
184     }
185    
186     /**
187     * Returns a (language-specific) key word sequence for the geo object.
188     */
189     public Translation getKeywords() {
190     return keywords;
191     }
192    
193     /**
194     * Sets a (language-specific) key word sequence for the geo object.
195     * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
196     * {@link #getKeywords()} never returns {@code null}.
197     * @param keywords Keywords
198     */
199     public void setKeywords(Translation keywords) {
200     this.keywords = (keywords != null) ? keywords : new Translation("");
201     }
202    
203     /**
204     * Sets a (non-translated) key word sequence for the geo object.
205     * If {@code keywords} is {@code null} an (untranslated) empty string is set, so
206     * {@link #getKeywords()} never returns {@code null}.
207     * @param keywords Keywords
208     */
209     public void setKeywords(String keywords) {
210     setKeywords( keywords != null ? new Translation(keywords) : (Translation)null);
211     }
212    
213     /**
214     * Returns the geo object representet in the map. Sub classes must override
215     * this method to implement "late loading" on first call.
216     * @return {@link #geoObject}
217     */
218     public E getGeoObject() {
219     return geoObject;
220     }
221    
222     /**
223     * Returns the bounds of the geo object.
224     */
225     public Envelope getEnvelope() {
226     return envelope;
227     }
228    
229     /**
230     * Returns the {@link CoordinateReferenceSystem} of the geo object.
231     */
232     public CoordinateReferenceSystem getCrs() {
233     return crs;
234     }
235    
236     /**
237     * Returns {@link #crs CoordinateReferenceSystem.toString()}. This method
238     * can be overriden to create a "nicer" description.
239     */
240     public String getCRSString() {
241     return crs.toString();
242     }
243    
244     /**
245     * Returns an icon, which represents the geo object.
246     */
247     public ImageIcon getImageIcon() {
248     return null;
249     }
250    
251     /**
252     * Sets an icon, which represents the geo object.
253     * @param icon an icon
254     */
255     public void setImageIcon(ImageIcon icon) {
256     this.icon = icon;
257     }
258    
259     /**
260     * Returns the display style for the geo object.
261     */
262     public Style getStyle() {
263     return style;
264     }
265    
266     /**
267     * Sets the display style for the geo object.
268     * If {@code style} is {@code null} an default style is set, so
269     * {@link #getStyle()} never returns {@code null}.
270     * @see #createDefaultStyle()
271     */
272     public void setStyle(Style style) {
273     this.style = (style != null) ? style : createDefaultStyle();
274     }
275    
276     /**
277     * Creates a default style for the geo object. This style is used whenever
278     * the style is set to {@code null}.
279     * @see #setStyle(Style)
280     */
281     protected abstract Style createDefaultStyle();
282     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26