1 |
mojays |
2 |
package skrueger.geotools; |
2 |
|
|
|
3 |
|
|
import java.net.URL; |
4 |
|
|
|
5 |
|
|
import javax.swing.ImageIcon; |
6 |
|
|
|
7 |
|
|
import org.geotools.coverage.grid.GridCoverage2D; |
8 |
|
|
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; |
9 |
mojays |
127 |
import org.geotools.styling.Style; |
10 |
mojays |
2 |
|
11 |
|
|
import schmitzm.geotools.JTSUtil; |
12 |
|
|
import schmitzm.geotools.grid.GridUtil; |
13 |
mojays |
127 |
import skrueger.RasterLegendData; |
14 |
mojays |
2 |
import skrueger.i8n.Translation; |
15 |
|
|
|
16 |
|
|
/** |
17 |
alfonx |
224 |
* This class provides a simple implementation of {@link StyledLayerInterface} |
18 |
mojays |
2 |
* for {@link AbstractGridCoverage2DReader}. The uncache functionality is not supported, |
19 |
|
|
* because if the coverage is read once this class bases on an existing {@link GridCoverage2D} |
20 |
|
|
* object in memory. |
21 |
|
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
22 |
|
|
* @version 1.0 |
23 |
|
|
*/ |
24 |
alfonx |
224 |
public class StyledGridCoverageReader extends AbstractStyledLayer<AbstractGridCoverage2DReader> implements StyledGridCoverageReaderInterface { |
25 |
mojays |
2 |
|
26 |
|
|
/** Holds the meta data for displaying a legend. */ |
27 |
|
|
protected RasterLegendData legendData = null; |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* Creates a styled grid with language-specific informations. |
31 |
|
|
* @param gcr the grid reader |
32 |
|
|
* @param id a unique ID for the object |
33 |
|
|
* @param title a (language-specific) short description |
34 |
|
|
* @param desc a (language-specific) long description |
35 |
|
|
* @param keywords (language-specific) keywords for the geo objects |
36 |
|
|
* @param style a display style (if {@code null}, a default style is created) |
37 |
|
|
* @param legendData meta data for displaying a legend |
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 |
40 |
|
|
*/ |
41 |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) { |
42 |
|
|
super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style, icon); |
43 |
|
|
setLegendMetaData(legendData); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* Creates a styled grid with language-specific informations. |
48 |
|
|
* @param gcr the grid reader |
49 |
|
|
* @param id a unique ID for the object |
50 |
|
|
* @param title a (language-specific) short description |
51 |
|
|
* @param desc a (language-specific) long description |
52 |
|
|
* @param keywords (language-specific) keywords for the geo objects |
53 |
|
|
* @param style a display style with legend information |
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 |
56 |
|
|
*/ |
57 |
alfonx |
224 |
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
58 |
mojays |
2 |
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 |
|
|
} |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* Creates a styled grid with a language-specific title, no long description, no |
64 |
|
|
* keywords and no icon. |
65 |
|
|
* @param gcr the grid reader |
66 |
|
|
* @param id a unique ID for the object |
67 |
|
|
* @param title a short description |
68 |
|
|
* @param style a display style (if {@code null}, a default style is created) |
69 |
|
|
* @param legendData meta data for displaying a legend |
70 |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
71 |
|
|
*/ |
72 |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style, RasterLegendData legendData) { |
73 |
|
|
this(gcr, id, title, null, null, style, legendData, null); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
/** |
77 |
|
|
* Creates a styled grid with non-translated informations. |
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 |
82 |
|
|
* @param keywords keywords for the geo objects |
83 |
|
|
* @param style a display style (if {@code null}, a default style is created) |
84 |
|
|
* @param legendData meta data for displaying a legend |
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 |
87 |
|
|
*/ |
88 |
|
|
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) { |
89 |
|
|
this(gcr, id, (Translation)null, null, null, style, legendData, icon); |
90 |
|
|
setTitle(title); |
91 |
|
|
setDesc(desc); |
92 |
|
|
setKeywords(keywords); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
/** |
96 |
|
|
* Creates a styled grid with non-translated informations. |
97 |
|
|
* @param gcr the grid reader |
98 |
|
|
* @param id a unique ID for the object |
99 |
|
|
* @param title a short description |
100 |
|
|
* @param desc a long description |
101 |
|
|
* @param keywords keywords for the geo objects |
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 |
|
|
*/ |
106 |
alfonx |
224 |
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) { |
107 |
mojays |
2 |
this(gcr, |
108 |
|
|
id, |
109 |
|
|
title, |
110 |
|
|
desc, |
111 |
|
|
keywords, |
112 |
|
|
style != null ? style.getGeoObjectStyle() : null, |
113 |
|
|
style != null ? style.getMetaData() : null, |
114 |
|
|
icon |
115 |
|
|
); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/** |
119 |
|
|
* Creates a styled grid with a non-translated title, no long description, no |
120 |
|
|
* keywords and no icon. |
121 |
|
|
* @param gcr the grid reader |
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 |
126 |
|
|
*/ |
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 |
|
|
|
131 |
|
|
/** |
132 |
|
|
* Creates a styled grid with a non-translated title, no long description, no |
133 |
|
|
* keywords and no icon. |
134 |
|
|
* @param gcr the grid reader |
135 |
|
|
* @param id a unique ID for the object |
136 |
|
|
* @param title a short description |
137 |
|
|
* @param style a display style with legend information |
138 |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or geo object |
139 |
|
|
*/ |
140 |
alfonx |
224 |
public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, StyledLayerStyle<RasterLegendData> style) { |
141 |
mojays |
2 |
this(gcr, |
142 |
|
|
id, |
143 |
|
|
title, |
144 |
|
|
null, |
145 |
|
|
null, |
146 |
|
|
style != null ? style.getGeoObjectStyle() : null, |
147 |
|
|
style != null ? style.getMetaData() : null, |
148 |
|
|
null |
149 |
|
|
); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* Creates a default style for a {@link GridCoverage2D}. |
154 |
|
|
* @see GridUtil#createDefaultStyle() |
155 |
|
|
*/ |
156 |
|
|
protected Style createDefaultStyle() { |
157 |
|
|
return GridUtil.createDefaultStyle(); |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
/** |
161 |
|
|
* Returns the meta data needed for displaying a legend. |
162 |
|
|
*/ |
163 |
|
|
public RasterLegendData getLegendMetaData() { |
164 |
|
|
return legendData; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
/** |
168 |
|
|
* Sets the meta data needed for displaying a legend. |
169 |
|
|
* If {@code legendData} is {@code null} an empty {@link RasterLegendData} |
170 |
|
|
* (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}. |
171 |
|
|
* @param legendData legend meta data |
172 |
|
|
*/ |
173 |
|
|
public void setLegendMetaData(RasterLegendData legendData) { |
174 |
|
|
this.legendData = (legendData != null) ? legendData : new RasterLegendData(false); |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
/** |
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; |
183 |
|
|
this.envelope = null; |
184 |
|
|
this.crs = null; |
185 |
|
|
this.legendData = null; |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/** |
189 |
|
|
* Tests whether the geo object is disposed. |
190 |
|
|
* @return boolean |
191 |
|
|
*/ |
192 |
|
|
public boolean isDisposed() { |
193 |
|
|
return geoObject == null; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
/** |
197 |
alfonx |
224 |
* Does nothing, because the {@link AbstractStyledLayer} bases on existing |
198 |
mojays |
2 |
* objects (in memory) which can not be uncached and reloaded. |
199 |
|
|
*/ |
200 |
|
|
public void uncache() { |
201 |
|
|
LOGGER.warn("Uncache functionality is not supported. Object remains in memory."); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
/* |
205 |
|
|
* (non-Javadoc) |
206 |
alfonx |
224 |
* @see skrueger.geotools.StyledLayerInterface#getInfoURL() |
207 |
mojays |
2 |
*/ |
208 |
|
|
public URL getInfoURL() { |
209 |
|
|
return null; |
210 |
|
|
} |
211 |
|
|
|
212 |
alfonx |
40 |
/** |
213 |
|
|
* If true, this layer will not be shown in the legend. Default = false |
214 |
|
|
*/ |
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 |
219 |
|
|
* Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer. |
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 |
|
|
* |
224 |
mojays |
2 |
public boolean isHideInLegend() { |
225 |
|
|
return false; |
226 |
|
|
} |
227 |
alfonx |
40 |
*/ |
228 |
mojays |
2 |
|
229 |
|
|
} |