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