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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26