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

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

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

revision 225 by alfonx, Wed Jul 15 08:05:22 2009 UTC revision 244 by alfonx, Wed Jul 29 09:33:33 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import javax.swing.ImageIcon;   *
4     * This file is part of the SCHMITZM library - a collection of utility
5  import org.apache.log4j.Logger;   * classes based on Java 1.6, focussing (not only) on Java Swing
6  import org.geotools.styling.Style;   * and the Geotools library.
7  import org.opengis.referencing.crs.CoordinateReferenceSystem;   *
8     * The SCHMITZM project is hosted at:
9  import schmitzm.lang.LangUtil;   * http://wald.intevation.org/projects/schmitzm/
10  import skrueger.i8n.Translation;   *
11     * This program is free software; you can redistribute it and/or
12  import com.vividsolutions.jts.geom.Envelope;   * 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   * This class is a default implementation of {@link StyledLayerInterface}.   *
16   * {@link StyledLayerInterface#dispose()} and {@link StyledLayerInterface#uncache()}   * This program is distributed in the hope that it will be useful,
17   * must be implemented by the sub class. This class only implements the "hold"   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * of an geo object of type {@code <E>}.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)   * GNU General Public License for more details.
20   * @version 1.0   *
21   */   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  public abstract class AbstractStyledLayer<E> implements StyledLayerInterface<E> {   * along with this program; if not, write to the Free Software
23    /** Logger for warning- and error messages. */   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24    protected Logger LOGGER = LangUtil.createLogger(this);   * or try this link: http://www.gnu.org/licenses/lgpl.html
25     *
26    /** Holds the unique ID of the geo object. */   * Contributors:
27    protected String id = null;   *     Martin O. J. Schmitz - initial API and implementation
28    /** Holds a short (language-specific) description of the geo object. */   *     Stefan A. Krüger - additional utility classes
29    protected Translation title = null;   ******************************************************************************/
30    /** Holds a long (language-specific) description of the geo object. */  package skrueger.geotools;
31    protected Translation desc = null;  
32    /** Holds the (language-specific) keywords to describe the geo object. */  import javax.swing.ImageIcon;
33    protected Translation keywords = null;  
34    /** Holds an icon to represent the geo object */  import org.apache.log4j.Logger;
35    protected ImageIcon icon = null;  import org.geotools.styling.Style;
36    /** Holds the geo object represeneted by the map */  import org.opengis.referencing.crs.CoordinateReferenceSystem;
37    protected E geoObject = null;  
38    /** Holds the CRS of the geo object */  import schmitzm.lang.LangUtil;
39    protected CoordinateReferenceSystem crs = null;  import skrueger.i8n.Translation;
40    /** Holds the bounds of the geo object */  
41    protected Envelope envelope = null;  import com.vividsolutions.jts.geom.Envelope;
42    /** Holds the display style for the geo object */  
43    protected Style style = null;  /**
44     * This class is a default implementation of {@link StyledLayerInterface}.
45    /**   * {@link StyledLayerInterface#dispose()} and {@link StyledLayerInterface#uncache()}
46     * Creates a language specific styled layer.   * must be implemented by the sub class. This class only implements the "hold"
47     * @param geoObject the geo object   * of an geo object of type {@code <E>}.
48     * @param envelope the bounds of the geo object   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
49     * @param crs the CRS of the geo object   * @version 1.0
50     * @param id a unique ID for the geo object   */
51     * @param title a (language-specific) short description  public abstract class AbstractStyledLayer<E> implements StyledLayerInterface<E> {
52     * @param desc a (language-specific) long description    /** Logger for warning- and error messages. */
53     * @param keywords (language-specific) keywords for the geo objects    protected Logger LOGGER = LangUtil.createLogger(this);
54     * @param style a display style  
55     * @param icon an icon for the object    /** Holds the unique ID of the geo object. */
56     * @exception IllegalArgumentException if {@code null} is given as ID or    protected String id = null;
57     *            geo object    /** Holds a short (language-specific) description of the geo object. */
58     */    protected Translation title = null;
59    public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) {    /** Holds a long (language-specific) description of the geo object. */
60      if ( id == null )    protected Translation desc = null;
61        throw new IllegalArgumentException("ID is not allowed to be null!");    /** Holds the (language-specific) keywords to describe the geo object. */
62      if ( geoObject == null )    protected Translation keywords = null;
63        throw new IllegalArgumentException("The GeoObject is not allowed to be null!");    /** Holds an icon to represent the geo object */
64      this.id        = id;    protected ImageIcon icon = null;
65      this.geoObject = geoObject;    /** Holds the geo object represeneted by the map */
66      this.crs       = crs;    protected E geoObject = null;
67      this.envelope  = envelope;    /** Holds the CRS of the geo object */
68      setTitle( title );    protected CoordinateReferenceSystem crs = null;
69      setDesc( desc );    /** Holds the bounds of the geo object */
70      setKeywords( keywords );    protected Envelope envelope = null;
71      setStyle( style );    /** Holds the display style for the geo object */
72      setImageIcon( icon );    protected Style style = null;
73    }  
74      /**
75    /**     * Creates a language specific styled layer.
76     * Creates a non-translated styled layer.     * @param geoObject the geo object
77     * @param geoObject the geo object     * @param envelope the bounds of the geo object
78     * @param envelope the bounds of the geo object     * @param crs the CRS of the geo object
79     * @param crs the CRS of the geo object     * @param id a unique ID for the geo object
80     * @param id a unique ID for the geo object     * @param title a (language-specific) short description
81     * @param title a short description     * @param desc a (language-specific) long description
82     * @param desc a long description     * @param keywords (language-specific) keywords for the geo objects
83     * @param keywords keywords for the geo objects     * @param style a display style
84     * @param style a display style     * @param icon an icon for the object
85     * @param icon an icon for the object     * @exception IllegalArgumentException if {@code null} is given as ID or
86     * @exception IllegalArgumentException if {@code null} is given as ID     *            geo object
87     */     */
88    public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, String title, String desc, String keywords, Style style, ImageIcon icon ) {    public AbstractStyledLayer(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) {
89      this(geoObject, envelope, crs, id, (Translation)null, null, null, style, icon);      if ( id == null )
90      setTitle( title );        throw new IllegalArgumentException("ID is not allowed to be null!");
91      setDesc( desc );      if ( geoObject == null )
92      setKeywords( keywords );        throw new IllegalArgumentException("The GeoObject is not allowed to be null!");
93    }      this.id        = id;
94        this.geoObject = geoObject;
95    /**      this.crs       = crs;
96     * Returns a ID for the geo object. The ID should be unique in a map ob      this.envelope  = envelope;
97     * {@linkplain StyledLayerInterface styled layer objects}      setTitle( title );
98     */      setDesc( desc );
99    public String getId() {      setKeywords( keywords );
100      return id;      setStyle( style );
101    }      setImageIcon( icon );
102      }
103    /**  
104     * Returns a short (language-specific) description of the geo object.    /**
105     */     * Creates a non-translated styled layer.
106    public Translation getTitle() {     * @param geoObject the geo object
107      return title;     * @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     * Sets a short (language-specific) description of the geo object.     * @param desc a long description
112     * If {@code title} is {@code null} an untranslated default title is set, so     * @param keywords keywords for the geo objects
113     * {@link #getTitle()} never returns {@code null}.     * @param style a display style
114     * @param title new description for the geo object     * @param icon an icon for the object
115     */     * @exception IllegalArgumentException if {@code null} is given as ID
116    public void setTitle(Translation title) {     */
117      this.title = (title != null) ? title : new Translation("untitled");    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     * Sets a short (non-translated) description of the geo object.      setKeywords( keywords );
122     * If {@code title} is {@code null} an untranslated default title is set, so    }
123     * {@link #getTitle()} never returns {@code null}.  
124     * @param title new description for the geo object    /**
125     */     * Returns a ID for the geo object. The ID should be unique in a map ob
126    public void setTitle(String title) {     * {@linkplain StyledLayerInterface styled layer objects}
127      setTitle( title != null ? new Translation(title): (Translation)null );     */
128    }    public String getId() {
129        return id;
130    /**    }
131     * Returns a long (language-specific) description of the object.  
132     */    /**
133    public Translation getDesc() {     * Returns a short (language-specific) description of the geo object.
134      return desc;     */
135    }    public Translation getTitle() {
136        return title;
137    /**    }
138     * Sets a long (language-specific) description of the object.  
139     * If {@code desc} is {@code null} an (untranslated) empty description is set, so    /**
140     * {@link #getDesc()} never returns {@code null}.     * Sets a short (language-specific) description of the geo object.
141     * @param desc new description for the geo object     * If {@code title} is {@code null} an untranslated default title is set, so
142    */     * {@link #getTitle()} never returns {@code null}.
143    public void setDesc(Translation desc) {     * @param title new description for the geo object
144      this.desc = (desc != null) ? desc : new Translation("");     */
145    }    public void setTitle(Translation title) {
146        this.title = (title != null) ? title : new Translation("untitled");
147    /**    }
148     * Sets a long (non-translated) description of the object.  
149     * If {@code desc} is {@code null} an (untranslated) empty description is set, so    /**
150     * {@link #getDesc()} never returns {@code null}.     * Sets a short (non-translated) description of the geo object.
151     * @param desc new description for the geo object     * If {@code title} is {@code null} an untranslated default title is set, so
152    */     * {@link #getTitle()} never returns {@code null}.
153    public void setDesc(String desc) {     * @param title new description for the geo object
154      setDesc( desc != null ? new Translation(desc) : (Translation)null);     */
155    }    public void setTitle(String title) {
156        setTitle( title != null ? new Translation(title): (Translation)null );
157    /**    }
158     * Returns a (language-specific) key word sequence for the geo object.  
159     */    /**
160    public Translation getKeywords() {     * Returns a long (language-specific) description of the object.
161      return keywords;     */
162    }    public Translation getDesc() {
163        return desc;
164    /**    }
165     * Sets a (language-specific) key word sequence for the geo object.  
166     * If {@code keywords} is {@code null} an (untranslated) empty string is set, so    /**
167     * {@link #getKeywords()} never returns {@code null}.     * Sets a long (language-specific) description of the object.
168     * @param keywords Keywords     * If {@code desc} is {@code null} an (untranslated) empty description is set, so
169     */     * {@link #getDesc()} never returns {@code null}.
170    public void setKeywords(Translation keywords) {     * @param desc new description for the geo object
171      this.keywords = (keywords != null) ? keywords : new Translation("");    */
172    }    public void setDesc(Translation desc) {
173        this.desc = (desc != null) ? desc : new Translation("");
174    /**    }
175     * Sets a (non-translated) key word sequence for the geo object.  
176     * If {@code keywords} is {@code null} an (untranslated) empty string is set, so    /**
177     * {@link #getKeywords()} never returns {@code null}.     * Sets a long (non-translated) description of the object.
178     * @param keywords Keywords     * If {@code desc} is {@code null} an (untranslated) empty description is set, so
179     */     * {@link #getDesc()} never returns {@code null}.
180    public void setKeywords(String keywords) {     * @param desc new description for the geo object
181      setKeywords( keywords != null ? new Translation(keywords) : (Translation)null);    */
182    }    public void setDesc(String desc) {
183        setDesc( desc != null ? new Translation(desc) : (Translation)null);
184    /**    }
185     * Returns the geo object representet in the map. Sub classes must override  
186     * this method to implement "late loading" on first call.    /**
187     * @return {@link #geoObject}     * Returns a (language-specific) key word sequence for the geo object.
188     */     */
189    public E getGeoObject() {    public Translation getKeywords() {
190      return geoObject;      return keywords;
191    }    }
192    
193    /**    /**
194     * Returns the bounds of the geo object.     * 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    public Envelope getEnvelope() {     * {@link #getKeywords()} never returns {@code null}.
197      return envelope;     * @param keywords Keywords
198    }     */
199      public void setKeywords(Translation keywords) {
200    /**      this.keywords = (keywords != null) ? keywords : new Translation("");
201     * Returns the {@link CoordinateReferenceSystem} of the geo object.    }
202     */  
203    public CoordinateReferenceSystem getCrs() {    /**
204      return crs;     * 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     * Returns {@link #crs CoordinateReferenceSystem.toString()}. This method     */
209     * can be overriden to create a "nicer" description.    public void setKeywords(String keywords) {
210     */      setKeywords( keywords != null ? new Translation(keywords) : (Translation)null);
211    public String getCRSString() {    }
212      return crs.toString();  
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     * Returns an icon, which represents the geo object.     * @return {@link #geoObject}
217     */     */
218    public ImageIcon getImageIcon() {    public E getGeoObject() {
219      return null;      return geoObject;
220    }    }
221    
222    /**    /**
223     * Sets an icon, which represents the geo object.     * Returns the bounds of the geo object.
224     * @param icon an icon     */
225     */    public Envelope getEnvelope() {
226    public void setImageIcon(ImageIcon icon) {      return envelope;
227      this.icon = icon;    }
228    }  
229      /**
230    /**     * Returns the {@link CoordinateReferenceSystem} of the geo object.
231     * Returns the display style for the geo object.     */
232     */    public CoordinateReferenceSystem getCrs() {
233    public Style getStyle() {      return crs;
234      return style;    }
235    }  
236      /**
237    /**     * Returns {@link #crs CoordinateReferenceSystem.toString()}. This method
238     * Sets the display style for the geo object.     * can be overriden to create a "nicer" description.
239     * If {@code style} is {@code null} an default style is set, so     */
240     * {@link #getStyle()} never returns {@code null}.    public String getCRSString() {
241     * @see #createDefaultStyle()      return crs.toString();
242     */    }
243    public void setStyle(Style style) {  
244      this.style = (style != null) ? style : createDefaultStyle();    /**
245    }     * Returns an icon, which represents the geo object.
246       */
247    /**    public ImageIcon getImageIcon() {
248     * Creates a default style for the geo object. This style is used whenever      return null;
249     * the style is set to {@code null}.    }
250     * @see #setStyle(Style)  
251     */    /**
252    protected abstract Style createDefaultStyle();     * 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    }

Legend:
Removed from v.225  
changed lines
  Added in v.244

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26