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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26