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

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

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

revision 127 by mojays, Sat May 30 14:29:58 2009 UTC revision 1203 by alfonx, Tue Nov 2 22:53:55 2010 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.net.URL;   *
4     * This file is part of the SCHMITZM library - a collection of utility
5  import javax.swing.ImageIcon;   * classes based on Java 1.6, focusing (not only) on Java Swing
6     * and the Geotools library.
7  import org.geotools.coverage.grid.GridCoverage2D;   *
8  import org.geotools.styling.Style;   * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10  import schmitzm.geotools.JTSUtil;   *
11  import schmitzm.geotools.grid.GridUtil;   * This program is free software; you can redistribute it and/or
12  import skrueger.RasterLegendData;   * modify it under the terms of the GNU Lesser General Public License
13  import skrueger.i8n.Translation;   * as published by the Free Software Foundation; either version 3
14     * of the License, or (at your option) any later version.
15  /**   *
16   * This class provides a simple implementation of {@link StyledMapInterface}   * This program is distributed in the hope that it will be useful,
17   * for {@link GridCoverage2D}. The uncache functionality is not supported,   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * because this class bases on an existing {@link GridCoverage2D} object in   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * memory.   * GNU General Public License for more details.
20   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)   *
21   * @version 1.0   * 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  public class StyledGridCoverage extends AbstractStyledMap<GridCoverage2D> implements StyledGridCoverageInterface {   * 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    /** Holds the meta data for displaying a legend. */   *
26    protected RasterLegendData legendData = null;   * Contributors:
27     *     Martin O. J. Schmitz - initial API and implementation
28    /**   *     Stefan A. Tzeggai - additional utility classes
29     * Creates a styled grid with language-specific informations.   ******************************************************************************/
30     * @param gc the grid  package skrueger.geotools;
31     * @param id a unique ID for the object  
32     * @param title a (language-specific) short description  import java.net.URL;
33     * @param desc a (language-specific) long description  
34     * @param keywords (language-specific) keywords for the geo objects  import javax.swing.ImageIcon;
35     * @param style a display style (if {@code null}, a default style is created)  
36     * @param legendData meta data for displaying a legend  import org.geotools.coverage.grid.GridCoverage2D;
37     * @param icon an icon for the object (can be {@code null})  import org.geotools.geometry.jts.ReferencedEnvelope;
38     * @exception IllegalArgumentException if {@code null} is given as ID or geo object  import org.geotools.styling.Style;
39     */  
40    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {  import schmitzm.geotools.JTSUtil;
41      super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc.getCoordinateReferenceSystem(), id, title, desc, keywords, style, icon);  import schmitzm.geotools.grid.GridUtil;
42      setLegendMetaData(legendData);  import skrueger.RasterLegendData;
43    }  import skrueger.i8n.Translation;
44    
45    /**  /**
46     * Creates a styled grid with language-specific informations.   * This class provides a simple implementation of {@link StyledLayerInterface}
47     * @param gc the grid   * for {@link GridCoverage2D}. The uncache functionality is not supported,
48     * @param id a unique ID for the object   * because this class bases on an existing {@link GridCoverage2D} object in
49     * @param title a (language-specific) short description   * memory.
50     * @param desc a (language-specific) long description   *
51     * @param keywords (language-specific) keywords for the geo objects   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
52     * @param style a display style with legend information   *         (University of Bonn/Germany)
53     * @param icon an icon for the object (can be {@code null})   * @version 1.0
54     * @exception IllegalArgumentException if {@code null} is given as ID or geo object   */
55     */  public class StyledGridCoverage extends AbstractStyledLayer<GridCoverage2D>
56    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {                  implements StyledGridCoverageInterface {
57      super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc.getCoordinateReferenceSystem(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);  
58      setLegendMetaData( style != null ? style.getMetaData() : null );          /** Holds the meta data for displaying a legend. */
59    }          protected RasterLegendData legendData = null;
60    
61    /**          /**
62     * Creates a styled grid with a language-specific title, no long description, no           * Creates a styled grid with language-specific informations.
63     * keywords and no icon.           *
64     * @param gc the grid           * @param gc
65     * @param id a unique ID for the object           *            the grid
66     * @param title a short description           * @param id
67     * @param style a display style (if {@code null}, a default style is created)           *            a unique ID for the object
68     * @param legendData meta data for displaying a legend           * @param title
69     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            a (language-specific) short description
70     */           * @param desc
71    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Style style, RasterLegendData legendData) {           *            a (language-specific) long description
72      this(gc, id, title, null, null, style, legendData, null);           * @param keywords
73    }           *            (language-specific) keywords for the geo objects
74             * @param style
75    /**           *            a display style (if {@code null}, a default style is created)
76     * Creates a styled grid with non-translated informations.           * @param legendData
77     * @param gc the grid           *            meta data for displaying a legend
78     * @param id a unique ID for the object           * @param icon
79     * @param title a short description           *            an icon for the object (can be {@code null})
80     * @param desc a long description           * @exception IllegalArgumentException
81     * @param keywords keywords for the geo objects           *                if {@code null} is given as ID or geo object
82     * @param style a display style (if {@code null}, a default style is created)           */
83     * @param legendData meta data for displaying a legend          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
84     * @param icon an icon for the object (can be {@code null})                          Translation desc, Translation keywords, Style style,
85     * @exception IllegalArgumentException if {@code null} is given as ID or geo object                          RasterLegendData legendData, ImageIcon icon) {
86     */                  super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
87    public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
88      this(gc, id, (Translation)null, null, null, style, legendData, icon);                                  style, icon);
89      setTitle(title);                  setLegendMetaData(legendData);
90      setDesc(desc);          }
91      setKeywords(keywords);  
92    }          /**
93             * Creates a styled grid with language-specific informations.
94    /**           *
95     * Creates a styled grid with non-translated informations.           * @param gc
96     * @param gc the grid           *            the grid
97     * @param id a unique ID for the object           * @param id
98     * @param title a short description           *            a unique ID for the object
99     * @param desc a long description           * @param title
100     * @param keywords keywords for the geo objects           *            a (language-specific) short description
101     * @param style a display style with legend information           * @param desc
102     * @param icon an icon for the object (can be {@code null})           *            a (language-specific) long description
103     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           * @param keywords
104     */           *            (language-specific) keywords for the geo objects
105    public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {           * @param style
106      this(gc,           *            a display style with legend information
107           id,           * @param icon
108           title,           *            an icon for the object (can be {@code null})
109           desc,           * @exception IllegalArgumentException
110           keywords,           *                if {@code null} is given as ID or geo object
111           style != null ? style.getGeoObjectStyle() : null,           */
112           style != null ? style.getMetaData() : null,          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
113           icon                          Translation desc, Translation keywords,
114      );                          StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
115    }                  super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
116                                    .getCoordinateReferenceSystem(), id, title, desc, keywords,
117    /**                                  style != null ? style.getGeoObjectStyle() : null, icon);
118     * Creates a styled grid with a non-translated title, no long description, no                  setLegendMetaData(style != null ? style.getMetaData() : null);
119     * keywords and no icon.          }
120     * @param gc the grid  
121     * @param id a unique ID for the object          /**
122     * @param title a short description           * Creates a styled grid with a language-specific title, no long
123     * @param style a display style (if {@code null}, a default style is created)           * description, no keywords and no icon.
124     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *
125     */           * @param gc
126    public StyledGridCoverage(GridCoverage2D gc, String id, String title, Style style, RasterLegendData legendData) {           *            the grid
127      this(gc, id, title, null, null, style, legendData, null);           * @param id
128    }           *            a unique ID for the object
129             * @param title
130    /**           *            a short description
131     * Creates a styled grid with a non-translated title, no long description, no           * @param style
132     * keywords and no icon.           *            a display style (if {@code null}, a default style is created)
133     * @param gc the grid           * @param legendData
134     * @param id a unique ID for the object           *            meta data for displaying a legend
135     * @param title a short description           * @exception IllegalArgumentException
136     * @param style a display style with legend information           *                if {@code null} is given as ID or geo object
137     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           */
138     */          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
139    public StyledGridCoverage(GridCoverage2D gc, String id, String title, StyledMapStyle<RasterLegendData> style) {                          Style style, RasterLegendData legendData) {
140      this(gc,                  this(gc, id, title, null, null, style, legendData, null);
141           id,          }
142           title,  
143           null,          /**
144           null,           * Creates a styled grid with non-translated informations.
145           style != null ? style.getGeoObjectStyle() : null,           *
146           style != null ? style.getMetaData() : null,           * @param gc
147           null           *            the grid
148      );           * @param id
149    }           *            a unique ID for the object
150             * @param title
151    /**           *            a short description
152     * Creates a default style for a {@link GridCoverage2D}.           * @param desc
153     * @see GridUtil#createDefaultStyle()           *            a long description
154     */           * @param keywords
155    protected Style createDefaultStyle() {           *            keywords for the geo objects
156      return GridUtil.createDefaultStyle();           * @param style
157    }           *            a display style (if {@code null}, a default style is created)
158             * @param legendData
159    /**           *            meta data for displaying a legend
160     * Returns the meta data needed for displaying a legend.           * @param icon
161     */           *            an icon for the object (can be {@code null})
162    public RasterLegendData getLegendMetaData() {           * @exception IllegalArgumentException
163      return legendData;           *                if {@code null} is given as ID or geo object
164    }           */
165            public StyledGridCoverage(GridCoverage2D gc, String id, String title,
166    /**                          String desc, String keywords, Style style,
167     * Sets the meta data needed for displaying a legend.                          RasterLegendData legendData, ImageIcon icon) {
168     * If {@code legendData} is {@code null} an empty {@link RasterLegendData}                  this(gc, id, (Translation) null, null, null, style, legendData, icon);
169     * (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.                  setTitle(title);
170     * @param legendData legend meta data                  setDesc(desc);
171     */                  setKeywords(keywords);
172    public void setLegendMetaData(RasterLegendData legendData) {          }
173      this.legendData = (legendData != null) ? legendData : new RasterLegendData(false);  
174    }          /**
175             * Creates a styled grid with non-translated informations.
176    /**           *
177     * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and           * @param gc
178     * {@link #legendData} to {@code null}.           *            the grid
179     */           * @param id
180    public void dispose() {           *            a unique ID for the object
181      this.geoObject  = null;           * @param title
182      this.envelope   = null;           *            a short description
183      this.crs        = null;           * @param desc
184      this.legendData = null;           *            a long description
185    }           * @param keywords
186             *            keywords for the geo objects
187    /**           * @param style
188     * Tests whether the geo object is disposed.           *            a display style with legend information
189     * @return boolean           * @param icon
190     */           *            an icon for the object (can be {@code null})
191    public boolean isDisposed() {           * @exception IllegalArgumentException
192      return geoObject == null;           *                if {@code null} is given as ID or geo object
193    }           */
194            public StyledGridCoverage(GridCoverage2D gc, String id, String title,
195    /**                          String desc, String keywords,
196     * Does nothing, because the {@link AbstractStyledMap} bases on existing                          StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
197     * objects (in memory) which can not be uncached and reloaded.                  this(gc, id, title, desc, keywords, style != null ? style
198     */                                  .getGeoObjectStyle() : null, style != null ? style
199    public void uncache() {                                  .getMetaData() : null, icon);
200      LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");          }
201    }  
202            /**
203    /*           * Creates a styled grid with a non-translated title, no long description,
204     * (non-Javadoc)           * no keywords and no icon.
205     * @see skrueger.geotools.StyledMapInterface#getInfoURL()           *
206     */           * @param gc
207    public URL getInfoURL() {           *            the grid
208          return null;           * @param id
209    }           *            a unique ID for the object
210             * @param title
211    /**           *            a short description
212           * If true, this layer will not be shown in the legend. Default = false           * @param style
213           */           *            a display style (if {@code null}, a default style is created)
214          /**           * @exception IllegalArgumentException
215           *           *                if {@code null} is given as ID or geo object
216           * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf           */
217           * verstecken/nicht verstecken gestellt werden können. Das sind          public StyledGridCoverage(GridCoverage2D gc, String id, String title,
218           * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.                          Style style, RasterLegendData legendData) {
219           * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer                  this(gc, id, title, null, null, style, legendData, null);
220           * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher          }
221           * die Funktion genutzt.  
222           *          /**
223    public boolean isHideInLegend() {           * Creates a styled grid with a non-translated title, no long description,
224          return false;           * no keywords and no icon.
225     }           *
226           */           * @param gc
227               *            the grid
228  }           * @param id
229             *            a unique ID for the object
230             * @param title
231             *            a short description
232             * @param style
233             *            a display style with legend information
234             * @exception IllegalArgumentException
235             *                if {@code null} is given as ID or geo object
236             */
237            public StyledGridCoverage(GridCoverage2D gc, String id, String title,
238                            StyledLayerStyle<RasterLegendData> style) {
239                    this(gc, id, title, null, null, style != null ? style
240                                    .getGeoObjectStyle() : null, style != null ? style
241                                    .getMetaData() : null, null);
242            }
243    
244            /**
245             * Creates a default style for a {@link GridCoverage2D}.
246             *
247             * @see GridUtil#createDefaultStyle()
248             */
249            protected Style createDefaultStyle() {
250                    return GridUtil.createDefaultStyle();
251            }
252    
253            /**
254             * Returns the meta data needed for displaying a legend.
255             */
256            public RasterLegendData getLegendMetaData() {
257                    return legendData;
258            }
259    
260            /**
261             * Sets the meta data needed for displaying a legend. If {@code legendData}
262             * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
263             * so {@link #getLegendMetaData()} never returns {@code null}.
264             *
265             * @param legendData
266             *            legend meta data
267             */
268            public void setLegendMetaData(RasterLegendData legendData) {
269                    this.legendData = (legendData != null) ? legendData
270                                    : new RasterLegendData(false);
271            }
272    
273            /**
274             * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
275             * {@link #legendData} to {@code null}.
276             */
277            public void dispose() {
278                    this.geoObject = null;
279                    this.envelope = null;
280                    this.crs = null;
281                    this.legendData = null;
282            }
283    
284            /**
285             * Tests whether the geo object is disposed.
286             *
287             * @return boolean
288             */
289            public boolean isDisposed() {
290                    return geoObject == null;
291            }
292    
293            /**
294             * Does nothing, because the {@link AbstractStyledLayer} bases on existing
295             * objects (in memory) which can not be uncached and reloaded.
296             */
297            public void uncache() {
298                    LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
299            }
300    
301            /*
302             * (non-Javadoc)
303             *
304             * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
305             */
306            public URL getInfoURL() {
307                    return null;
308            }
309    
310            /**
311             * If true, this layer will not be shown in the legend. Default = false
312             */
313            /**
314             *
315             * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
316             * verstecken/nicht verstecken gestellt werden können. Das sind
317             * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
318             * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
319             * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
320             * die Funktion genutzt.
321             *
322             * public boolean isHideInLegend() { return false; }
323             */
324            @Override
325            public ReferencedEnvelope getReferencedEnvelope() {
326                    return new ReferencedEnvelope(getEnvelope(), getCrs());
327            }
328    
329    }

Legend:
Removed from v.127  
changed lines
  Added in v.1203

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26