/[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 2 by mojays, Tue Feb 24 22:43:52 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.styling.Style;   *
8  import org.geotools.coverage.grid.GridCoverage2D;   * The SCHMITZM project is hosted at:
9  import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;   * 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     * 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  import skrueger.RasterLegendData;   *
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   * This class provides a simple implementation of {@link StyledMapInterface}   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * for {@link AbstractGridCoverage2DReader}. The uncache functionality is not supported,   * GNU General Public License for more details.
20   * because if the coverage is read once this class bases on an existing {@link GridCoverage2D}   *
21   * object in memory.   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)   * along with this program; if not, write to the Free Software
23   * @version 1.0   * 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  public class StyledGridCoverageReader extends AbstractStyledMap<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface {   *
26     * Contributors:
27    /** Holds the meta data for displaying a legend. */   *     Martin O. J. Schmitz - initial API and implementation
28    protected RasterLegendData legendData = null;   *     Stefan A. Tzeggai - additional utility classes
29     ******************************************************************************/
30    /**  package skrueger.geotools;
31     * Creates a styled grid with language-specific informations.  
32     * @param gcr the grid reader  import java.net.URL;
33     * @param id a unique ID for the object  
34     * @param title a (language-specific) short description  import javax.swing.ImageIcon;
35     * @param desc a (language-specific) long description  
36     * @param keywords (language-specific) keywords for the geo objects  import org.geotools.coverage.grid.GridCoverage2D;
37     * @param style a display style (if {@code null}, a default style is created)  import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
38     * @param legendData meta data for displaying a legend  import org.geotools.geometry.jts.ReferencedEnvelope;
39     * @param icon an icon for the object (can be {@code null})  import org.geotools.styling.Style;
40     * @exception IllegalArgumentException if {@code null} is given as ID or geo object  
41     */  import schmitzm.geotools.JTSUtil;
42    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {  import schmitzm.geotools.grid.GridUtil;
43      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style, icon);  import skrueger.RasterLegendData;
44      setLegendMetaData(legendData);  import skrueger.i8n.Translation;
45    }  
46    /**
47    /**   * This class provides a simple implementation of {@link StyledLayerInterface}
48     * Creates a styled grid with language-specific informations.   * for {@link AbstractGridCoverage2DReader}. The uncache functionality is not
49     * @param gcr the grid reader   * supported, because if the coverage is read once this class bases on an
50     * @param id a unique ID for the object   * existing {@link GridCoverage2D} object in memory.
51     * @param title a (language-specific) short description   *
52     * @param desc a (language-specific) long description   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
53     * @param keywords (language-specific) keywords for the geo objects   *         (University of Bonn/Germany)
54     * @param style a display style with legend information   * @version 1.0
55     * @param icon an icon for the object (can be {@code null})   */
56     * @exception IllegalArgumentException if {@code null} is given as ID or geo object  public class StyledGridCoverageReader extends
57     */                  AbstractStyledLayer<AbstractGridCoverage2DReader> implements
58    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {                  StyledGridCoverageReaderInterface {
59      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);          @Override
60      setLegendMetaData( style != null ? style.getMetaData() : null );          public ReferencedEnvelope getReferencedEnvelope() {
61    }                  return new ReferencedEnvelope(getEnvelope(), getCrs());
62            }
63    /**  
64     * Creates a styled grid with a language-specific title, no long description, no          /** Holds the meta data for displaying a legend. */
65     * keywords and no icon.          protected RasterLegendData legendData = null;
66     * @param gcr the grid reader  
67     * @param id a unique ID for the object          /**
68     * @param title a short description           * Creates a styled grid with language-specific informations.
69     * @param style a display style (if {@code null}, a default style is created)           *
70     * @param legendData meta data for displaying a legend           * @param gcr
71     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            the grid reader
72     */           * @param id
73    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style, RasterLegendData legendData) {           *            a unique ID for the object
74      this(gcr, id, title, null, null, style, legendData, null);           * @param title
75    }           *            a (language-specific) short description
76             * @param desc
77    /**           *            a (language-specific) long description
78     * Creates a styled grid with non-translated informations.           * @param keywords
79     * @param gcr the grid reader           *            (language-specific) keywords for the geo objects
80     * @param id a unique ID for the object           * @param style
81     * @param title a short description           *            a display style (if {@code null}, a default style is created)
82     * @param desc a long description           * @param legendData
83     * @param keywords keywords for the geo objects           *            meta data for displaying a legend
84     * @param style a display style (if {@code null}, a default style is created)           * @param icon
85     * @param legendData meta data for displaying a legend           *            an icon for the object (can be {@code null})
86     * @param icon an icon for the object (can be {@code null})           * @exception IllegalArgumentException
87     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
88     */           */
89    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {          public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
90      this(gcr, id, (Translation)null, null, null, style, legendData, icon);                          String id, Translation title, Translation desc,
91      setTitle(title);                          Translation keywords, Style style, RasterLegendData legendData,
92      setDesc(desc);                          ImageIcon icon) {
93      setKeywords(keywords);                  super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
94    }                                  .getCrs(), id, title, desc, keywords, style, icon);
95                    setLegendMetaData(legendData);
96    /**          }
97     * Creates a styled grid with non-translated informations.  
98     * @param gcr the grid reader          /**
99     * @param id a unique ID for the object           * Creates a styled grid with language-specific informations.
100     * @param title a short description           *
101     * @param desc a long description           * @param gcr
102     * @param keywords keywords for the geo objects           *            the grid reader
103     * @param style a display style with legend information           * @param id
104     * @param icon an icon for the object (can be {@code null})           *            a unique ID for the object
105     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           * @param title
106     */           *            a (language-specific) short description
107    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {           * @param desc
108      this(gcr,           *            a (language-specific) long description
109           id,           * @param keywords
110           title,           *            (language-specific) keywords for the geo objects
111           desc,           * @param style
112           keywords,           *            a display style with legend information
113           style != null ? style.getGeoObjectStyle() : null,           * @param icon
114           style != null ? style.getMetaData() : null,           *            an icon for the object (can be {@code null})
115           icon           * @exception IllegalArgumentException
116      );           *                if {@code null} is given as ID or geo object
117    }           */
118            public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
119    /**                          String id, Translation title, Translation desc,
120     * Creates a styled grid with a non-translated title, no long description, no                          Translation keywords, StyledLayerStyle<RasterLegendData> style,
121     * keywords and no icon.                          ImageIcon icon) {
122     * @param gcr the grid reader                  super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
123     * @param id a unique ID for the object                                  .getCrs(), id, title, desc, keywords, style != null ? style
124     * @param title a short description                                  .getGeoObjectStyle() : null, icon);
125     * @param style a display style (if {@code null}, a default style is created)                  setLegendMetaData(style != null ? style.getMetaData() : null);
126     * @exception IllegalArgumentException if {@code null} is given as ID or geo object          }
127     */  
128    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, Style style, RasterLegendData legendData) {          /**
129      this(gcr, id, title, null, null, style, legendData, null);           * Creates a styled grid with a language-specific title, no long
130    }           * description, no keywords and no icon.
131             *
132    /**           * @param gcr
133     * Creates a styled grid with a non-translated title, no long description, no           *            the grid reader
134     * keywords and no icon.           * @param id
135     * @param gcr the grid reader           *            a unique ID for the object
136     * @param id a unique ID for the object           * @param title
137     * @param title a short description           *            a short description
138     * @param style a display style with legend information           * @param style
139     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            a display style (if {@code null}, a default style is created)
140     */           * @param legendData
141    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledMapStyle<RasterLegendData> style) {           *            meta data for displaying a legend
142      this(gcr,           * @exception IllegalArgumentException
143           id,           *                if {@code null} is given as ID or geo object
144           title,           */
145           null,          public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
146           null,                          String id, Translation title, Style style,
147           style != null ? style.getGeoObjectStyle() : null,                          RasterLegendData legendData) {
148           style != null ? style.getMetaData() : null,                  this(gcr, id, title, null, null, style, legendData, null);
149           null          }
150      );  
151    }          /**
152             * Creates a styled grid with non-translated informations.
153    /**           *
154     * Creates a default style for a {@link GridCoverage2D}.           * @param gcr
155     * @see GridUtil#createDefaultStyle()           *            the grid reader
156     */           * @param id
157    protected Style createDefaultStyle() {           *            a unique ID for the object
158      return GridUtil.createDefaultStyle();           * @param title
159    }           *            a short description
160             * @param desc
161    /**           *            a long description
162     * Returns the meta data needed for displaying a legend.           * @param keywords
163     */           *            keywords for the geo objects
164    public RasterLegendData getLegendMetaData() {           * @param style
165      return legendData;           *            a display style (if {@code null}, a default style is created)
166    }           * @param legendData
167             *            meta data for displaying a legend
168    /**           * @param icon
169     * Sets the meta data needed for displaying a legend.           *            an icon for the object (can be {@code null})
170     * If {@code legendData} is {@code null} an empty {@link RasterLegendData}           * @exception IllegalArgumentException
171     * (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.           *                if {@code null} is given as ID or geo object
172     * @param legendData legend meta data           */
173     */          public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
174    public void setLegendMetaData(RasterLegendData legendData) {                          String id, String title, String desc, String keywords, Style style,
175      this.legendData = (legendData != null) ? legendData : new RasterLegendData(false);                          RasterLegendData legendData, ImageIcon icon) {
176    }                  this(gcr, id, (Translation) null, null, null, style, legendData, icon);
177                    setTitle(title);
178    /**                  setDesc(desc);
179     * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and                  setKeywords(keywords);
180     * {@link #legendData} to {@code null}.          }
181     */  
182    public void dispose() {          /**
183      this.geoObject  = null;           * Creates a styled grid with non-translated informations.
184      this.envelope   = null;           *
185      this.crs        = null;           * @param gcr
186      this.legendData = null;           *            the grid reader
187    }           * @param id
188             *            a unique ID for the object
189    /**           * @param title
190     * Tests whether the geo object is disposed.           *            a short description
191     * @return boolean           * @param desc
192     */           *            a long description
193    public boolean isDisposed() {           * @param keywords
194      return geoObject == null;           *            keywords for the geo objects
195    }           * @param style
196             *            a display style with legend information
197    /**           * @param icon
198     * Does nothing, because the {@link AbstractStyledMap} bases on existing           *            an icon for the object (can be {@code null})
199     * objects (in memory) which can not be uncached and reloaded.           * @exception IllegalArgumentException
200     */           *                if {@code null} is given as ID or geo object
201    public void uncache() {           */
202      LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");          public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
203    }                          String id, String title, String desc, String keywords,
204                            StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
205    /*                  this(gcr, id, title, desc, keywords, style != null ? style
206     * (non-Javadoc)                                  .getGeoObjectStyle() : null, style != null ? style
207     * @see skrueger.geotools.StyledMapInterface#getInfoURL()                                  .getMetaData() : null, icon);
208     */          }
209    public URL getInfoURL() {  
210      return null;          /**
211    }           * Creates a styled grid with a non-translated title, no long description,
212             * no keywords and no icon.
213    public boolean isHideInLegend() {           *
214      return false;           * @param gcr
215    }           *            the grid reader
216               * @param id
217  }           *            a unique ID for the object
218             * @param title
219             *            a short description
220             * @param style
221             *            a display style (if {@code null}, a default style is created)
222             * @exception IllegalArgumentException
223             *                if {@code null} is given as ID or geo object
224             */
225            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.2  
changed lines
  Added in v.1212

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26