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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26