/[schmitzm]/branches/2.0-RC2/src/skrueger/RasterLegendData.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/RasterLegendData.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 621 - (hide annotations)
Thu Jan 28 10:06:05 2010 UTC (15 years, 1 month ago) by alfonx
File size: 4477 byte(s)
2.0-RC2 ist für die weiterentwicklung und soll bald in den trunk mergen
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     * Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30     package skrueger;
31 alfonx 607
32 alfonx 244 import java.util.Arrays;
33     import java.util.HashMap;
34     import java.util.LinkedList;
35     import java.util.List;
36 mojays 395 import java.util.Map;
37 alfonx 607 import java.util.TreeMap;
38 alfonx 244
39     import org.apache.log4j.Logger;
40 mojays 395 import org.geotools.coverage.grid.GridCoverage2D;
41     import org.geotools.geometry.Envelope2D;
42     import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
43 alfonx 244
44 mojays 395 import schmitzm.geotools.GTUtil;
45     import schmitzm.geotools.grid.GridUtil;
46 alfonx 514 import skrueger.geotools.Copyable;
47 alfonx 244 import skrueger.i8n.Translation;
48    
49     /**
50 alfonx 607 * Holds all the additional information needed to paint a Legend for a
51     * RasterLayer. So far, only Legends for one-band raster layers are supported.
52     *
53 alfonx 244 * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
54 alfonx 607 *
55     * TODO implements {@link Copyable}
56 alfonx 244 */
57 alfonx 607 public class RasterLegendData extends TreeMap<Double, Translation> implements
58     Copyable<RasterLegendData> {
59     static private final Logger LOGGER = Logger
60     .getLogger(RasterLegendData.class);
61    
62 alfonx 244 private Boolean paintGaps = false;
63    
64 alfonx 607 /**
65     * Shall bigger gaps be painted between the raster images
66     */
67 alfonx 244 public Boolean isPaintGaps() {
68     return paintGaps;
69     }
70    
71     public void setPaintGaps(boolean paintPaps) {
72     this.paintGaps = paintPaps;
73     }
74    
75     /**
76 alfonx 607 * {@link #paintGaps} defines, if gaps should be painted between the legends
77     * colors, indicating nominal values in the raster (e.g. classifications)
78 alfonx 244 */
79     public RasterLegendData(boolean paintGaps) {
80     this.paintGaps = paintGaps;
81     }
82    
83 alfonx 607 /**
84     * Returns a new list containing all {@link Double} values that shall apear
85     * in the legend.
86     */
87     public List<Double> getSortedKeys() {
88     Double[] array = keySet().toArray(new Double[] {});
89 alfonx 244
90 mojays 399 Arrays.sort(array);
91    
92     final LinkedList<Double> linkedList = new LinkedList<Double>();
93 alfonx 607 for (Double o : array) {
94     linkedList.add(o);
95 mojays 399 }
96    
97     return linkedList;
98 alfonx 607 }
99 mojays 399
100 alfonx 607 /**
101     * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each legend
102     * value. These rasters can be used to do visualize the legend item in the
103     * corresponding color via {@link GridCoverageRenderer}.
104     */
105     public Map<Double, GridCoverage2D> createSampleRasters() {
106     Map<Double, GridCoverage2D> sampleRaster = new HashMap<Double, GridCoverage2D>();
107    
108     for (Double rasterValue : keySet()) {
109     GridCoverage2D grid = GridUtil.GRID_FAC.create("Legend_"
110     + rasterValue,
111     new float[][] { { rasterValue.floatValue() } },
112     new Envelope2D(GTUtil.WGS84, 0, 0, 1, 1));
113     sampleRaster.put(rasterValue, grid);
114     }
115     return sampleRaster;
116 mojays 399 }
117    
118 alfonx 607 /**
119     * Creates a new {@link RasterLegendData} object with identical values
120     */
121     @Override
122     public RasterLegendData copy() {
123     RasterLegendData copy = (RasterLegendData) super.clone();
124     return copyTo(copy);
125     }
126    
127     /**
128     * Deep-copies all values of this {@link RasterLegendData} to another
129     * {@link RasterLegendData}
130     */
131     @Override
132     public RasterLegendData copyTo(RasterLegendData target) {
133     target.clear();
134    
135     target.setPaintGaps(isPaintGaps());
136    
137     for (Double o : keySet()) {
138     target.put(new Double(o), get(o).copy());
139     }
140    
141     return target;
142     }
143 alfonx 244 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26