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

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

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

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

Legend:
Removed from v.224  
changed lines
  Added in v.1212

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26