/[schmitzm]/trunk/src/skrueger/RasterLegendData.java
ViewVC logotype

Diff of /trunk/src/skrueger/RasterLegendData.java

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

trunk/src/skrueger/RasterLegendData.java revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java revision 395 by mojays, Mon Sep 14 11:37:53 2009 UTC
# Line 1  Line 1 
1  package skrueger;  /*******************************************************************************
2  import java.util.Arrays;   * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.util.HashMap;   *
4  import java.util.LinkedList;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.util.List;   * classes based on Java 1.6, focusing (not only) on Java Swing
6     * and the Geotools library.
7  import org.apache.log4j.Logger;   *
8     * The SCHMITZM project is hosted at:
9  import skrueger.i8n.Translation;   * http://wald.intevation.org/projects/schmitzm/
10     *
11  /**   * This program is free software; you can redistribute it and/or
12   * Holds all the additional information needed to paint a Legend for a RasterLayer.   * modify it under the terms of the GNU Lesser General Public License
13   * So far, only Legends for one-band raster layers are supported.   * as published by the Free Software Foundation; either version 3
14   *   * of the License, or (at your option) any later version.
15   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   *
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  public class RasterLegendData extends HashMap<Double, Translation> {   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19          static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class);   * GNU General Public License for more details.
20          private Boolean paintGaps = false;   *
21     * You should have received a copy of the GNU Lesser General Public License (license.txt)
22          public Boolean isPaintGaps() {   * along with this program; if not, write to the Free Software
23                  return paintGaps;   * 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          public void setPaintGaps(boolean paintPaps) {   * Contributors:
27                  this.paintGaps = paintPaps;   *     Martin O. J. Schmitz - initial API and implementation
28          }   *     Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30          /**  package skrueger;
31           * {@link #paintGaps} defines, if gaps should be painted between the legends colors,  import java.util.Arrays;
32           * indicating nominal values in the raster (e.g. classifications)  import java.util.HashMap;
33           */  import java.util.LinkedList;
34          public RasterLegendData(boolean paintGaps) {  import java.util.List;
35                  super();  import java.util.Map;
36                  this.paintGaps = paintGaps;  
37          }  import org.apache.log4j.Logger;
38    import org.geotools.coverage.grid.GridCoverage2D;
39          public boolean getPaintGaps() {  import org.geotools.geometry.Envelope2D;
40                  return paintGaps ;  import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
41          }  
42    import schmitzm.geotools.GTUtil;
43          public List<Double> getSortedKeys(){  import schmitzm.geotools.grid.GridUtil;
44                  Object[] array = keySet().toArray();  import skrueger.i8n.Translation;
45    
46                  Arrays.sort(array);  /**
47     * Holds all the additional information needed to paint a Legend for a RasterLayer.
48                  final LinkedList<Double> linkedList = new LinkedList<Double>();   * So far, only Legends for one-band raster layers are supported.
49                  for (Object o : array){   *
50                          linkedList.add( (Double)o);   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
51                  }   *
52     */
53                  return linkedList;  public class RasterLegendData extends HashMap<Double, Translation> {
54            static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class);
55          }          private Boolean paintGaps = false;
56  }  
57            public Boolean isPaintGaps() {
58                    return paintGaps;
59            }
60    
61            public void setPaintGaps(boolean paintPaps) {
62                    this.paintGaps = paintPaps;
63            }
64    
65            /**
66             * {@link #paintGaps} defines, if gaps should be painted between the legends colors,
67             * indicating nominal values in the raster (e.g. classifications)
68             */
69            public RasterLegendData(boolean paintGaps) {
70                    this.paintGaps = paintGaps;
71            }
72    
73            public boolean getPaintGaps() {
74                    return paintGaps ;
75            }
76    
77            public List<Double> getSortedKeys(){
78                    Object[] array = keySet().toArray();
79    
80                    Arrays.sort(array);
81    
82                    final LinkedList<Double> linkedList = new LinkedList<Double>();
83                    for (Object o : array){
84                            linkedList.add( (Double)o);
85                    }
86    
87                    return linkedList;
88    
89            }
90    
91        /**
92         * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each
93         * legend value.  These rasters can be used to do visualize the
94         * legend item in the corresponding color via {@link GridCoverageRenderer}.
95         */
96        public Map<Double, GridCoverage2D> createSampleRasters() {
97          Map<Double, GridCoverage2D> sampleRaster = new HashMap<Double, GridCoverage2D>();
98          
99          for (Double rasterValue : keySet()) {
100            GridCoverage2D grid = GridUtil.GRID_FAC.create(
101                "Legend_"+rasterValue,
102                new float[][] { { rasterValue.floatValue() } },
103                new Envelope2D(GTUtil.WGS84, 0,0,1,1)
104            );
105            sampleRaster.put(rasterValue, grid);
106          }
107          
108          
109          return sampleRaster;
110        }
111    }

Legend:
Removed from v.2  
changed lines
  Added in v.395

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26