/[schmitzm]/branches/2.3.x/src/skrueger/geotools/StyledGridCoverage.java
ViewVC logotype

Diff of /branches/2.3.x/src/skrueger/geotools/StyledGridCoverage.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1202 by alfonx, Sat May 22 01:24:46 2010 UTC revision 1203 by alfonx, Tue Nov 2 22:53:55 2010 UTC
# Line 34  import java.net.URL; Line 34  import java.net.URL;
34  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
35    
36  import org.geotools.coverage.grid.GridCoverage2D;  import org.geotools.coverage.grid.GridCoverage2D;
37    import org.geotools.geometry.jts.ReferencedEnvelope;
38  import org.geotools.styling.Style;  import org.geotools.styling.Style;
39    
40  import schmitzm.geotools.JTSUtil;  import schmitzm.geotools.JTSUtil;
# Line 46  import skrueger.i8n.Translation; Line 47  import skrueger.i8n.Translation;
47   * for {@link GridCoverage2D}. The uncache functionality is not supported,   * for {@link GridCoverage2D}. The uncache functionality is not supported,
48   * because this class bases on an existing {@link GridCoverage2D} object in   * because this class bases on an existing {@link GridCoverage2D} object in
49   * memory.   * memory.
50   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)   *
51     * @author <a href="mailto:[email protected]">Martin Schmitz</a>
52     *         (University of Bonn/Germany)
53   * @version 1.0   * @version 1.0
54   */   */
55  public class StyledGridCoverage extends AbstractStyledLayer<GridCoverage2D> implements StyledGridCoverageInterface {  public class StyledGridCoverage extends AbstractStyledLayer<GridCoverage2D>
56                    implements StyledGridCoverageInterface {
57    
58    /** Holds the meta data for displaying a legend. */          /** Holds the meta data for displaying a legend. */
59    protected RasterLegendData legendData = null;          protected RasterLegendData legendData = null;
60    
61    /**          /**
62     * Creates a styled grid with language-specific informations.           * Creates a styled grid with language-specific informations.
63     * @param gc the grid           *
64     * @param id a unique ID for the object           * @param gc
65     * @param title a (language-specific) short description           *            the grid
66     * @param desc a (language-specific) long description           * @param id
67     * @param keywords (language-specific) keywords for the geo objects           *            a unique ID for the object
68     * @param style a display style (if {@code null}, a default style is created)           * @param title
69     * @param legendData meta data for displaying a legend           *            a (language-specific) short description
70     * @param icon an icon for the object (can be {@code null})           * @param desc
71     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            a (language-specific) long description
72     */           * @param keywords
73    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {           *            (language-specific) keywords for the geo objects
74      super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc.getCoordinateReferenceSystem(), id, title, desc, keywords, style, icon);           * @param style
75      setLegendMetaData(legendData);           *            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     * Creates a styled grid with language-specific informations.           *            an icon for the object (can be {@code null})
80     * @param gc the grid           * @exception IllegalArgumentException
81     * @param id a unique ID for the object           *                if {@code null} is given as ID or geo object
82     * @param title a (language-specific) short description           */
83     * @param desc a (language-specific) long description          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
84     * @param keywords (language-specific) keywords for the geo objects                          Translation desc, Translation keywords, Style style,
85     * @param style a display style with legend information                          RasterLegendData legendData, ImageIcon icon) {
86     * @param icon an icon for the object (can be {@code null})                  super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
87     * @exception IllegalArgumentException if {@code null} is given as ID or geo object                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
88     */                                  style, icon);
89    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Translation desc, Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {                  setLegendMetaData(legendData);
90      super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc.getCoordinateReferenceSystem(), id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, icon);          }
91      setLegendMetaData( style != null ? style.getMetaData() : null );  
92    }          /**
93             * Creates a styled grid with language-specific informations.
94    /**           *
95     * Creates a styled grid with a language-specific title, no long description, no           * @param gc
96     * keywords and no icon.           *            the grid
97     * @param gc the grid           * @param id
98     * @param id a unique ID for the object           *            a unique ID for the object
99     * @param title a short description           * @param title
100     * @param style a display style (if {@code null}, a default style is created)           *            a (language-specific) short description
101     * @param legendData meta data for displaying a legend           * @param desc
102     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            a (language-specific) long description
103     */           * @param keywords
104    public StyledGridCoverage(GridCoverage2D gc, String id, Translation title, Style style, RasterLegendData legendData) {           *            (language-specific) keywords for the geo objects
105      this(gc, id, title, null, null, style, legendData, null);           * @param style
106    }           *            a display style with legend information
107             * @param icon
108    /**           *            an icon for the object (can be {@code null})
109     * Creates a styled grid with non-translated informations.           * @exception IllegalArgumentException
110     * @param gc the grid           *                if {@code null} is given as ID or geo object
111     * @param id a unique ID for the object           */
112     * @param title a short description          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
113     * @param desc a long description                          Translation desc, Translation keywords,
114     * @param keywords keywords for the geo objects                          StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
115     * @param style a display style (if {@code null}, a default style is created)                  super(gc, JTSUtil.createEnvelope(gc.getEnvelope()), gc
116     * @param legendData meta data for displaying a legend                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
117     * @param icon an icon for the object (can be {@code null})                                  style != null ? style.getGeoObjectStyle() : null, icon);
118     * @exception IllegalArgumentException if {@code null} is given as ID or geo object                  setLegendMetaData(style != null ? style.getMetaData() : null);
119     */          }
120    public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {  
121      this(gc, id, (Translation)null, null, null, style, legendData, icon);          /**
122      setTitle(title);           * Creates a styled grid with a language-specific title, no long
123      setDesc(desc);           * description, no keywords and no icon.
124      setKeywords(keywords);           *
125    }           * @param gc
126             *            the grid
127    /**           * @param id
128     * Creates a styled grid with non-translated informations.           *            a unique ID for the object
129     * @param gc the grid           * @param title
130     * @param id a unique ID for the object           *            a short description
131     * @param title a short description           * @param style
132     * @param desc a long description           *            a display style (if {@code null}, a default style is created)
133     * @param keywords keywords for the geo objects           * @param legendData
134     * @param style a display style with legend information           *            meta data for displaying a legend
135     * @param icon an icon for the object (can be {@code null})           * @exception IllegalArgumentException
136     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
137     */           */
138    public StyledGridCoverage(GridCoverage2D gc, String id, String title, String desc, String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {          public StyledGridCoverage(GridCoverage2D gc, String id, Translation title,
139      this(gc,                          Style style, RasterLegendData legendData) {
140           id,                  this(gc, id, title, null, null, style, legendData, null);
141           title,          }
142           desc,  
143           keywords,          /**
144           style != null ? style.getGeoObjectStyle() : null,           * Creates a styled grid with non-translated informations.
145           style != null ? style.getMetaData() : null,           *
146           icon           * @param gc
147      );           *            the grid
148    }           * @param id
149             *            a unique ID for the object
150    /**           * @param title
151     * Creates a styled grid with a non-translated title, no long description, no           *            a short description
152     * keywords and no icon.           * @param desc
153     * @param gc the grid           *            a long description
154     * @param id a unique ID for the object           * @param keywords
155     * @param title a short description           *            keywords for the geo objects
156     * @param style a display style (if {@code null}, a default style is created)           * @param style
157     * @exception IllegalArgumentException if {@code null} is given as ID or geo object           *            a display style (if {@code null}, a default style is created)
158     */           * @param legendData
159    public StyledGridCoverage(GridCoverage2D gc, String id, String title, Style style, RasterLegendData legendData) {           *            meta data for displaying a legend
160      this(gc, id, title, null, null, style, legendData, null);           * @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     * Creates a styled grid with a non-translated title, no long description, no           */
165     * keywords and no icon.          public StyledGridCoverage(GridCoverage2D gc, String id, String title,
166     * @param gc the grid                          String desc, String keywords, Style style,
167     * @param id a unique ID for the object                          RasterLegendData legendData, ImageIcon icon) {
168     * @param title a short description                  this(gc, id, (Translation) null, null, null, style, legendData, icon);
169     * @param style a display style with legend information                  setTitle(title);
170     * @exception IllegalArgumentException if {@code null} is given as ID or geo object                  setDesc(desc);
171     */                  setKeywords(keywords);
172    public StyledGridCoverage(GridCoverage2D gc, String id, String title, StyledLayerStyle<RasterLegendData> style) {          }
173      this(gc,  
174           id,          /**
175           title,           * Creates a styled grid with non-translated informations.
176           null,           *
177           null,           * @param gc
178           style != null ? style.getGeoObjectStyle() : null,           *            the grid
179           style != null ? style.getMetaData() : null,           * @param id
180           null           *            a unique ID for the object
181      );           * @param title
182    }           *            a short description
183             * @param desc
184    /**           *            a long description
185     * Creates a default style for a {@link GridCoverage2D}.           * @param keywords
186     * @see GridUtil#createDefaultStyle()           *            keywords for the geo objects
187     */           * @param style
188    protected Style createDefaultStyle() {           *            a display style with legend information
189      return GridUtil.createDefaultStyle();           * @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     * Returns the meta data needed for displaying a legend.           */
194     */          public StyledGridCoverage(GridCoverage2D gc, String id, String title,
195    public RasterLegendData getLegendMetaData() {                          String desc, String keywords,
196      return legendData;                          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     * Sets the meta data needed for displaying a legend.          }
201     * If {@code legendData} is {@code null} an empty {@link RasterLegendData}  
202     * (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.          /**
203     * @param legendData legend meta data           * Creates a styled grid with a non-translated title, no long description,
204     */           * no keywords and no icon.
205    public void setLegendMetaData(RasterLegendData legendData) {           *
206      this.legendData = (legendData != null) ? legendData : new RasterLegendData(false);           * @param gc
207    }           *            the grid
208             * @param id
209    /**           *            a unique ID for the object
210     * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and           * @param title
211     * {@link #legendData} to {@code null}.           *            a short description
212     */           * @param style
213    public void dispose() {           *            a display style (if {@code null}, a default style is created)
214      this.geoObject  = null;           * @exception IllegalArgumentException
215      this.envelope   = null;           *                if {@code null} is given as ID or geo object
216      this.crs        = null;           */
217      this.legendData = null;          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     * Tests whether the geo object is disposed.  
222     * @return boolean          /**
223     */           * Creates a styled grid with a non-translated title, no long description,
224    public boolean isDisposed() {           * no keywords and no icon.
225      return geoObject == null;           *
226    }           * @param gc
227             *            the grid
228    /**           * @param id
229     * Does nothing, because the {@link AbstractStyledLayer} bases on existing           *            a unique ID for the object
230     * objects (in memory) which can not be uncached and reloaded.           * @param title
231     */           *            a short description
232    public void uncache() {           * @param style
233      LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");           *            a display style with legend information
234    }           * @exception IllegalArgumentException
235             *                if {@code null} is given as ID or geo object
236    /*           */
237     * (non-Javadoc)          public StyledGridCoverage(GridCoverage2D gc, String id, String title,
238     * @see skrueger.geotools.StyledLayerInterface#getInfoURL()                          StyledLayerStyle<RasterLegendData> style) {
239     */                  this(gc, id, title, null, null, style != null ? style
240    public URL getInfoURL() {                                  .getGeoObjectStyle() : null, style != null ? style
241          return null;                                  .getMetaData() : null, null);
242    }          }
243    
244    /**          /**
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    
253            /**
254             * Returns the meta data needed for displaying a legend.
255             */
256            public RasterLegendData getLegendMetaData() {
257                    return legendData;
258            }
259    
260            /**
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    
273            /**
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    
284            /**
285             * Tests whether the geo object is disposed.
286             *
287             * @return boolean
288             */
289            public boolean isDisposed() {
290                    return geoObject == null;
291            }
292    
293            /**
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    
301            /*
302             * (non-Javadoc)
303             *
304             * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
305             */
306            public URL getInfoURL() {
307                    return null;
308            }
309    
310            /**
311           * If true, this layer will not be shown in the legend. Default = false           * If true, this layer will not be shown in the legend. Default = false
312           */           */
313          /**          /**
# Line 249  public class StyledGridCoverage extends Line 319  public class StyledGridCoverage extends
319           * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher           * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
320           * die Funktion genutzt.           * die Funktion genutzt.
321           *           *
322    public boolean isHideInLegend() {           * public boolean isHideInLegend() { return false; }
         return false;  
    }  
323           */           */
324              @Override
325            public ReferencedEnvelope getReferencedEnvelope() {
326                    return new ReferencedEnvelope(getEnvelope(), getCrs());
327            }
328    
329  }  }

Legend:
Removed from v.1202  
changed lines
  Added in v.1203

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26