/[schmitzm]/branches/2.2.x/src/skrueger/geotools/StyledGridCoverageReader.java
ViewVC logotype

Diff of /branches/2.2.x/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 256 by alfonx, Fri Jul 31 14:43:47 2009 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. Krüger - 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.styling.Style;
39     * @param icon an icon for the object (can be {@code null})  
40     * @exception IllegalArgumentException if {@code null} is given as ID or geo object  import schmitzm.geotools.JTSUtil;
41     */  import schmitzm.geotools.grid.GridUtil;
42    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {  import skrueger.RasterLegendData;
43      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style, icon);  import skrueger.i8n.Translation;
44      setLegendMetaData(legendData);  
45    }  /**
46     * This class provides a simple implementation of {@link StyledLayerInterface}
47    /**   * for {@link AbstractGridCoverage2DReader}. The uncache functionality is not supported,
48     * Creates a styled grid with language-specific informations.   * because if the coverage is read once this class bases on an existing {@link GridCoverage2D}
49     * @param gcr the grid reader   * object in memory.
50     * @param id a unique ID for the object   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
51     * @param title a (language-specific) short description   * @version 1.0
52     * @param desc a (language-specific) long description   */
53     * @param keywords (language-specific) keywords for the geo objects  public class StyledGridCoverageReader extends AbstractStyledLayer<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface {
54     * @param style a display style with legend information  
55     * @param icon an icon for the object (can be {@code null})    /** Holds the meta data for displaying a legend. */
56     * @exception IllegalArgumentException if {@code null} is given as ID or geo object    protected RasterLegendData legendData = null;
57     */  
58    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {    /**
59      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);     * Creates a styled grid with language-specific informations.
60      setLegendMetaData( style != null ? style.getMetaData() : null );     * @param gcr the grid reader
61    }     * @param id a unique ID for the object
62       * @param title a (language-specific) short description
63    /**     * @param desc a (language-specific) long description
64     * Creates a styled grid with a language-specific title, no long description, no     * @param keywords (language-specific) keywords for the geo objects
65     * keywords and no icon.     * @param style a display style (if {@code null}, a default style is created)
66     * @param gcr the grid reader     * @param legendData meta data for displaying a legend
67     * @param id a unique ID for the object     * @param icon an icon for the object (can be {@code null})
68     * @param title a short description     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
69     * @param style a display style (if {@code null}, a default style is created)     */
70     * @param legendData meta data for displaying a legend    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {
71     * @exception IllegalArgumentException if {@code null} is given as ID or geo object      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style, icon);
72     */      setLegendMetaData(legendData);
73    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style, RasterLegendData legendData) {    }
74      this(gcr, id, title, null, null, style, legendData, null);  
75    }    /**
76       * Creates a styled grid with language-specific informations.
77    /**     * @param gcr the grid reader
78     * Creates a styled grid with non-translated informations.     * @param id a unique ID for the object
79     * @param gcr the grid reader     * @param title a (language-specific) short description
80     * @param id a unique ID for the object     * @param desc a (language-specific) long description
81     * @param title a short description     * @param keywords (language-specific) keywords for the geo objects
82     * @param desc a long description     * @param style a display style with legend information
83     * @param keywords keywords for the geo objects     * @param icon an icon for the object (can be {@code null})
84     * @param style a display style (if {@code null}, a default style is created)     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
85     * @param legendData meta data for displaying a legend     */
86     * @param icon an icon for the object (can be {@code null})    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
87     * @exception IllegalArgumentException if {@code null} is given as ID or geo object      super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);
88     */      setLegendMetaData( style != null ? style.getMetaData() : null );
89    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {    }
90      this(gcr, id, (Translation)null, null, null, style, legendData, icon);  
91      setTitle(title);    /**
92      setDesc(desc);     * Creates a styled grid with a language-specific title, no long description, no
93      setKeywords(keywords);     * keywords and no icon.
94    }     * @param gcr the grid reader
95       * @param id a unique ID for the object
96    /**     * @param title a short description
97     * Creates a styled grid with non-translated informations.     * @param style a display style (if {@code null}, a default style is created)
98     * @param gcr the grid reader     * @param legendData meta data for displaying a legend
99     * @param id a unique ID for the object     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
100     * @param title a short description     */
101     * @param desc a long description    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style, RasterLegendData legendData) {
102     * @param keywords keywords for the geo objects      this(gcr, id, title, null, null, style, legendData, null);
103     * @param style a display style with legend information    }
104     * @param icon an icon for the object (can be {@code null})  
105     * @exception IllegalArgumentException if {@code null} is given as ID or geo object    /**
106     */     * Creates a styled grid with non-translated informations.
107    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledMapStyle<RasterLegendData> style, ImageIcon icon) {     * @param gcr the grid reader
108      this(gcr,     * @param id a unique ID for the object
109           id,     * @param title a short description
110           title,     * @param desc a long description
111           desc,     * @param keywords keywords for the geo objects
112           keywords,     * @param style a display style (if {@code null}, a default style is created)
113           style != null ? style.getGeoObjectStyle() : null,     * @param legendData meta data for displaying a legend
114           style != null ? style.getMetaData() : null,     * @param icon an icon for the object (can be {@code null})
115           icon     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
116      );     */
117    }    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {
118        this(gcr, id, (Translation)null, null, null, style, legendData, icon);
119    /**      setTitle(title);
120     * Creates a styled grid with a non-translated title, no long description, no      setDesc(desc);
121     * keywords and no icon.      setKeywords(keywords);
122     * @param gcr the grid reader    }
123     * @param id a unique ID for the object  
124     * @param title a short description    /**
125     * @param style a display style (if {@code null}, a default style is created)     * Creates a styled grid with non-translated informations.
126     * @exception IllegalArgumentException if {@code null} is given as ID or geo object     * @param gcr the grid reader
127     */     * @param id a unique ID for the object
128    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, Style style, RasterLegendData legendData) {     * @param title a short description
129      this(gcr, id, title, null, null, style, legendData, null);     * @param desc a long description
130    }     * @param keywords keywords for the geo objects
131       * @param style a display style with legend information
132    /**     * @param icon an icon for the object (can be {@code null})
133     * Creates a styled grid with a non-translated title, no long description, no     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
134     * keywords and no icon.     */
135     * @param gcr the grid reader    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
136     * @param id a unique ID for the object      this(gcr,
137     * @param title a short description           id,
138     * @param style a display style with legend information           title,
139     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           desc,
140     */           keywords,
141    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledMapStyle<RasterLegendData> style) {           style != null ? style.getGeoObjectStyle() : null,
142      this(gcr,           style != null ? style.getMetaData() : null,
143           id,           icon
144           title,      );
145           null,    }
146           null,  
147           style != null ? style.getGeoObjectStyle() : null,    /**
148           style != null ? style.getMetaData() : null,     * Creates a styled grid with a non-translated title, no long description, no
149           null     * keywords and no icon.
150      );     * @param gcr the grid reader
151    }     * @param id a unique ID for the object
152       * @param title a short description
153    /**     * @param style a display style (if {@code null}, a default style is created)
154     * Creates a default style for a {@link GridCoverage2D}.     * @exception IllegalArgumentException if {@code null} is given as ID or geo object
155     * @see GridUtil#createDefaultStyle()     */
156     */    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, Style style, RasterLegendData legendData) {
157    protected Style createDefaultStyle() {      this(gcr, id, title, null, null, style, legendData, null);
158      return GridUtil.createDefaultStyle();    }
159    }  
160      /**
161    /**     * Creates a styled grid with a non-translated title, no long description, no
162     * Returns the meta data needed for displaying a legend.     * keywords and no icon.
163     */     * @param gcr the grid reader
164    public RasterLegendData getLegendMetaData() {     * @param id a unique ID for the object
165      return legendData;     * @param title a short description
166    }     * @param style a display style with legend information
167       * @exception IllegalArgumentException if {@code null} is given as ID or geo object
168    /**     */
169     * Sets the meta data needed for displaying a legend.    public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledLayerStyle<RasterLegendData> style) {
170     * If {@code legendData} is {@code null} an empty {@link RasterLegendData}      this(gcr,
171     * (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.           id,
172     * @param legendData legend meta data           title,
173     */           null,
174    public void setLegendMetaData(RasterLegendData legendData) {           null,
175      this.legendData = (legendData != null) ? legendData : new RasterLegendData(false);           style != null ? style.getGeoObjectStyle() : null,
176    }           style != null ? style.getMetaData() : null,
177             null
178    /**      );
179     * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and    }
180     * {@link #legendData} to {@code null}.  
181     */    /**
182    public void dispose() {     * Creates a default style for a {@link GridCoverage2D}.
183      this.geoObject  = null;     * @see GridUtil#createDefaultStyle()
184      this.envelope   = null;     */
185      this.crs        = null;    protected Style createDefaultStyle() {
186      this.legendData = null;      return GridUtil.createDefaultStyle();
187    }    }
188    
189    /**    /**
190     * Tests whether the geo object is disposed.     * Returns the meta data needed for displaying a legend.
191     * @return boolean     */
192     */    public RasterLegendData getLegendMetaData() {
193    public boolean isDisposed() {      return legendData;
194      return geoObject == null;    }
195    }  
196      /**
197    /**     * Sets the meta data needed for displaying a legend.
198     * Does nothing, because the {@link AbstractStyledMap} bases on existing     * If {@code legendData} is {@code null} an empty {@link RasterLegendData}
199     * objects (in memory) which can not be uncached and reloaded.     * (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.
200     */     * @param legendData legend meta data
201    public void uncache() {     */
202      LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");    public void setLegendMetaData(RasterLegendData legendData) {
203    }      this.legendData = (legendData != null) ? legendData : new RasterLegendData(false);
204      }
205    /*  
206     * (non-Javadoc)    /**
207     * @see skrueger.geotools.StyledMapInterface#getInfoURL()     * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
208     */     * {@link #legendData} to {@code null}.
209    public URL getInfoURL() {     */
210      return null;    public void dispose() {
211    }      this.geoObject  = null;
212        this.envelope   = null;
213    public boolean isHideInLegend() {      this.crs        = null;
214      return false;      this.legendData = null;
215    }    }
216      
217  }    /**
218       * Tests whether the geo object is disposed.
219       * @return boolean
220       */
221      public boolean isDisposed() {
222        return geoObject == null;
223      }
224    
225      /**
226       * Does nothing, because the {@link AbstractStyledLayer} bases on existing
227       * objects (in memory) which can not be uncached and reloaded.
228       */
229      public void uncache() {
230        LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
231      }
232    
233      /*
234       * (non-Javadoc)
235       * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
236       */
237      public URL getInfoURL() {
238        return null;
239      }
240    
241      /**
242             * If true, this layer will not be shown in the legend. Default = false
243             */
244            /**
245             *
246             * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
247             * verstecken/nicht verstecken gestellt werden können. Das sind
248             * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
249             * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
250             * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
251             * die Funktion genutzt.
252             *
253      public boolean isHideInLegend() {
254        return false;
255      }
256             */
257      
258    }

Legend:
Removed from v.2  
changed lines
  Added in v.256

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26