1 |
alfonx |
244 |
/******************************************************************************* |
2 |
|
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
|
|
* |
4 |
|
|
* This file is part of the SCHMITZM library - a collection of utility |
5 |
alfonx |
256 |
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
alfonx |
244 |
* and the Geotools library. |
7 |
|
|
* |
8 |
|
|
* The SCHMITZM project is hosted at: |
9 |
|
|
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
|
* |
11 |
|
|
* 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 |
|
|
* as published by the Free Software Foundation; either version 3 |
14 |
|
|
* 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 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
|
* GNU General Public License for more details. |
20 |
|
|
* |
21 |
|
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
|
* 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 |
|
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
|
|
* |
26 |
|
|
* Contributors: |
27 |
|
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
alfonx |
862 |
* Stefan A. Tzeggai - additional utility classes |
29 |
alfonx |
244 |
******************************************************************************/ |
30 |
|
|
package skrueger.geotools; |
31 |
|
|
|
32 |
|
|
import java.net.URL; |
33 |
|
|
|
34 |
|
|
import javax.swing.ImageIcon; |
35 |
|
|
|
36 |
|
|
import org.geotools.coverage.grid.GridCoverage2D; |
37 |
alfonx |
1203 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
38 |
alfonx |
244 |
import org.geotools.styling.Style; |
39 |
|
|
|
40 |
|
|
import schmitzm.geotools.JTSUtil; |
41 |
|
|
import schmitzm.geotools.grid.GridUtil; |
42 |
|
|
import skrueger.RasterLegendData; |
43 |
|
|
import skrueger.i8n.Translation; |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* This class provides a simple implementation of {@link StyledLayerInterface} |
47 |
|
|
* for {@link GridCoverage2D}. The uncache functionality is not supported, |
48 |
|
|
* because this class bases on an existing {@link GridCoverage2D} object in |
49 |
|
|
* memory. |
50 |
alfonx |
1203 |
* |
51 |
|
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
52 |
|
|
* (University of Bonn/Germany) |
53 |
alfonx |
244 |
* @version 1.0 |
54 |
|
|
*/ |
55 |
alfonx |
1203 |
public class StyledGridCoverage extends AbstractStyledLayer<GridCoverage2D> |
56 |
|
|
implements StyledGridCoverageInterface { |
57 |
alfonx |
244 |
|
58 |
alfonx |
1203 |
/** Holds the meta data for displaying a legend. */ |
59 |
|
|
protected RasterLegendData legendData = null; |
60 |
alfonx |
244 |
|
61 |
alfonx |
1203 |
/** |
62 |
|
|
* Creates a styled grid with language-specific informations. |
63 |
|
|
* |
64 |
|
|
* @param gc |
65 |
|
|
* the grid |
66 |
|
|
* @param id |
67 |
|
|
* a unique ID for the object |
68 |
|
|
* @param title |
69 |
|
|
* a (language-specific) short description |
70 |
|
|
* @param desc |
71 |
|
|
* a (language-specific) long description |
72 |
|
|
* @param keywords |
73 |
|
|
* (language-specific) keywords for the geo objects |
74 |
|
|
* @param style |
75 |
|
|
* a display style (if {@code null}, a default style is created) |
76 |
|
|
* @param legendData |
77 |
|
|
* meta data for displaying a legend |
78 |
|
|
* @param icon |
79 |
|
|
* an icon for the object (can be {@code null}) |
80 |
|
|
* @exception IllegalArgumentException |
81 |
|
|
* if {@code null} is given as ID or geo object |
82 |
|
|
*/ |
83 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, |
84 |
|
|
Translation desc, Translation keywords, Style style, |
85 |
|
|
RasterLegendData legendData, ImageIcon icon) { |
86 |
|
|
super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc |
87 |
|
|
.getCoordinateReferenceSystem(), id, title, desc, keywords, |
88 |
|
|
style, icon); |
89 |
|
|
setLegendMetaData(legendData); |
90 |
|
|
} |
91 |
alfonx |
244 |
|
92 |
alfonx |
1203 |
/** |
93 |
|
|
* Creates a styled grid with language-specific informations. |
94 |
|
|
* |
95 |
|
|
* @param gc |
96 |
|
|
* the grid |
97 |
|
|
* @param id |
98 |
|
|
* a unique ID for the object |
99 |
|
|
* @param title |
100 |
|
|
* a (language-specific) short description |
101 |
|
|
* @param desc |
102 |
|
|
* a (language-specific) long description |
103 |
|
|
* @param keywords |
104 |
|
|
* (language-specific) keywords for the geo objects |
105 |
|
|
* @param style |
106 |
|
|
* a display style with legend information |
107 |
|
|
* @param icon |
108 |
|
|
* an icon for the object (can be {@code null}) |
109 |
|
|
* @exception IllegalArgumentException |
110 |
|
|
* if {@code null} is given as ID or geo object |
111 |
|
|
*/ |
112 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, |
113 |
|
|
Translation desc, Translation keywords, |
114 |
|
|
StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
115 |
|
|
super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc |
116 |
|
|
.getCoordinateReferenceSystem(), id, title, desc, keywords, |
117 |
|
|
style != null ? style.getGeoObjectStyle() : null, icon); |
118 |
|
|
setLegendMetaData(style != null ? style.getMetaData() : null); |
119 |
|
|
} |
120 |
alfonx |
244 |
|
121 |
alfonx |
1203 |
/** |
122 |
|
|
* Creates a styled grid with a language-specific title, no long |
123 |
|
|
* description, no keywords and no icon. |
124 |
|
|
* |
125 |
|
|
* @param gc |
126 |
|
|
* the grid |
127 |
|
|
* @param id |
128 |
|
|
* a unique ID for the object |
129 |
|
|
* @param title |
130 |
|
|
* a short description |
131 |
|
|
* @param style |
132 |
|
|
* a display style (if {@code null}, a default style is created) |
133 |
|
|
* @param legendData |
134 |
|
|
* meta data for displaying a legend |
135 |
|
|
* @exception IllegalArgumentException |
136 |
|
|
* if {@code null} is given as ID or geo object |
137 |
|
|
*/ |
138 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, |
139 |
|
|
Style style, RasterLegendData legendData) { |
140 |
|
|
this(gc, id, title, null, null, style, legendData, null); |
141 |
|
|
} |
142 |
alfonx |
244 |
|
143 |
alfonx |
1203 |
/** |
144 |
|
|
* Creates a styled grid with non-translated informations. |
145 |
|
|
* |
146 |
|
|
* @param gc |
147 |
|
|
* the grid |
148 |
|
|
* @param id |
149 |
|
|
* a unique ID for the object |
150 |
|
|
* @param title |
151 |
|
|
* a short description |
152 |
|
|
* @param desc |
153 |
|
|
* a long description |
154 |
|
|
* @param keywords |
155 |
|
|
* keywords for the geo objects |
156 |
|
|
* @param style |
157 |
|
|
* a display style (if {@code null}, a default style is created) |
158 |
|
|
* @param legendData |
159 |
|
|
* meta data for displaying a legend |
160 |
|
|
* @param icon |
161 |
|
|
* an icon for the object (can be {@code null}) |
162 |
|
|
* @exception IllegalArgumentException |
163 |
|
|
* if {@code null} is given as ID or geo object |
164 |
|
|
*/ |
165 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, String title, |
166 |
|
|
String desc, String keywords, Style style, |
167 |
|
|
RasterLegendData legendData, ImageIcon icon) { |
168 |
|
|
this(gc, id, (Translation) null, null, null, style, legendData, icon); |
169 |
|
|
setTitle(title); |
170 |
|
|
setDesc(desc); |
171 |
|
|
setKeywords(keywords); |
172 |
|
|
} |
173 |
alfonx |
244 |
|
174 |
alfonx |
1203 |
/** |
175 |
|
|
* Creates a styled grid with non-translated informations. |
176 |
|
|
* |
177 |
|
|
* @param gc |
178 |
|
|
* the grid |
179 |
|
|
* @param id |
180 |
|
|
* a unique ID for the object |
181 |
|
|
* @param title |
182 |
|
|
* a short description |
183 |
|
|
* @param desc |
184 |
|
|
* a long description |
185 |
|
|
* @param keywords |
186 |
|
|
* keywords for the geo objects |
187 |
|
|
* @param style |
188 |
|
|
* a display style with legend information |
189 |
|
|
* @param icon |
190 |
|
|
* an icon for the object (can be {@code null}) |
191 |
|
|
* @exception IllegalArgumentException |
192 |
|
|
* if {@code null} is given as ID or geo object |
193 |
|
|
*/ |
194 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, String title, |
195 |
|
|
String desc, String keywords, |
196 |
|
|
StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
197 |
|
|
this(gc, id, title, desc, keywords, style != null ? style |
198 |
|
|
.getGeoObjectStyle() : null, style != null ? style |
199 |
|
|
.getMetaData() : null, icon); |
200 |
|
|
} |
201 |
alfonx |
244 |
|
202 |
alfonx |
1203 |
/** |
203 |
|
|
* Creates a styled grid with a non-translated title, no long description, |
204 |
|
|
* no keywords and no icon. |
205 |
|
|
* |
206 |
|
|
* @param gc |
207 |
|
|
* the grid |
208 |
|
|
* @param id |
209 |
|
|
* a unique ID for the object |
210 |
|
|
* @param title |
211 |
|
|
* a short description |
212 |
|
|
* @param style |
213 |
|
|
* a display style (if {@code null}, a default style is created) |
214 |
|
|
* @exception IllegalArgumentException |
215 |
|
|
* if {@code null} is given as ID or geo object |
216 |
|
|
*/ |
217 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, String title, |
218 |
|
|
Style style, RasterLegendData legendData) { |
219 |
|
|
this(gc, id, title, null, null, style, legendData, null); |
220 |
|
|
} |
221 |
alfonx |
244 |
|
222 |
alfonx |
1203 |
/** |
223 |
|
|
* Creates a styled grid with a non-translated title, no long description, |
224 |
|
|
* no keywords and no icon. |
225 |
|
|
* |
226 |
|
|
* @param gc |
227 |
|
|
* the grid |
228 |
|
|
* @param id |
229 |
|
|
* a unique ID for the object |
230 |
|
|
* @param title |
231 |
|
|
* a short description |
232 |
|
|
* @param style |
233 |
|
|
* a display style with legend information |
234 |
|
|
* @exception IllegalArgumentException |
235 |
|
|
* if {@code null} is given as ID or geo object |
236 |
|
|
*/ |
237 |
|
|
public StyledGridCoverage(GridCoverage2D gc, String id, String title, |
238 |
|
|
StyledLayerStyle<RasterLegendData> style) { |
239 |
|
|
this(gc, id, title, null, null, style != null ? style |
240 |
|
|
.getGeoObjectStyle() : null, style != null ? style |
241 |
|
|
.getMetaData() : null, null); |
242 |
|
|
} |
243 |
alfonx |
244 |
|
244 |
alfonx |
1203 |
/** |
245 |
|
|
* Creates a default style for a {@link GridCoverage2D}. |
246 |
|
|
* |
247 |
|
|
* @see GridUtil#createDefaultStyle() |
248 |
|
|
*/ |
249 |
|
|
protected Style createDefaultStyle() { |
250 |
|
|
return GridUtil.createDefaultStyle(); |
251 |
|
|
} |
252 |
alfonx |
244 |
|
253 |
alfonx |
1203 |
/** |
254 |
|
|
* Returns the meta data needed for displaying a legend. |
255 |
|
|
*/ |
256 |
|
|
public RasterLegendData getLegendMetaData() { |
257 |
|
|
return legendData; |
258 |
|
|
} |
259 |
alfonx |
244 |
|
260 |
alfonx |
1203 |
/** |
261 |
|
|
* Sets the meta data needed for displaying a legend. If {@code legendData} |
262 |
|
|
* is {@code null} an empty {@link RasterLegendData} (without gaps) is set, |
263 |
|
|
* so {@link #getLegendMetaData()} never returns {@code null}. |
264 |
|
|
* |
265 |
|
|
* @param legendData |
266 |
|
|
* legend meta data |
267 |
|
|
*/ |
268 |
|
|
public void setLegendMetaData(RasterLegendData legendData) { |
269 |
|
|
this.legendData = (legendData != null) ? legendData |
270 |
|
|
: new RasterLegendData(false); |
271 |
|
|
} |
272 |
alfonx |
244 |
|
273 |
alfonx |
1203 |
/** |
274 |
|
|
* Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and |
275 |
|
|
* {@link #legendData} to {@code null}. |
276 |
|
|
*/ |
277 |
|
|
public void dispose() { |
278 |
|
|
this.geoObject = null; |
279 |
|
|
this.envelope = null; |
280 |
|
|
this.crs = null; |
281 |
|
|
this.legendData = null; |
282 |
|
|
} |
283 |
alfonx |
244 |
|
284 |
alfonx |
1203 |
/** |
285 |
|
|
* Tests whether the geo object is disposed. |
286 |
|
|
* |
287 |
|
|
* @return boolean |
288 |
|
|
*/ |
289 |
|
|
public boolean isDisposed() { |
290 |
|
|
return geoObject == null; |
291 |
|
|
} |
292 |
alfonx |
244 |
|
293 |
alfonx |
1203 |
/** |
294 |
|
|
* Does nothing, because the {@link AbstractStyledLayer} bases on existing |
295 |
|
|
* objects (in memory) which can not be uncached and reloaded. |
296 |
|
|
*/ |
297 |
|
|
public void uncache() { |
298 |
|
|
LOGGER.warn("Uncache functionality is not supported. Object remains in memory."); |
299 |
|
|
} |
300 |
alfonx |
244 |
|
301 |
alfonx |
1203 |
/* |
302 |
|
|
* (non-Javadoc) |
303 |
|
|
* |
304 |
|
|
* @see skrueger.geotools.StyledLayerInterface#getInfoURL() |
305 |
|
|
*/ |
306 |
|
|
public URL getInfoURL() { |
307 |
|
|
return null; |
308 |
|
|
} |
309 |
alfonx |
244 |
|
310 |
alfonx |
1203 |
/** |
311 |
alfonx |
244 |
* If true, this layer will not be shown in the legend. Default = false |
312 |
|
|
*/ |
313 |
|
|
/** |
314 |
|
|
* |
315 |
|
|
* Killed by SK: 6. April 09: Ein Layer soll nicht generell auf |
316 |
|
|
* verstecken/nicht verstecken gestellt werden können. Das sind |
317 |
|
|
* Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer. |
318 |
|
|
* Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer |
319 |
|
|
* nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher |
320 |
|
|
* die Funktion genutzt. |
321 |
|
|
* |
322 |
alfonx |
1203 |
* public boolean isHideInLegend() { return false; } |
323 |
alfonx |
244 |
*/ |
324 |
alfonx |
1203 |
@Override |
325 |
|
|
public ReferencedEnvelope getReferencedEnvelope() { |
326 |
|
|
return new ReferencedEnvelope(getEnvelope(), getCrs()); |
327 |
|
|
} |
328 |
|
|
|
329 |
alfonx |
244 |
} |