--- branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java 2009/09/14 11:42:49 398
+++ branches/2.3.KECK/src/skrueger/RasterLegendData.java 2010/10/14 09:45:14 1103
@@ -25,15 +25,15 @@
*
* Contributors:
* Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Krüger - additional utility classes
+ * Stefan A. Tzeggai - additional utility classes
******************************************************************************/
package skrueger;
+
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.log4j.Logger;
@@ -43,19 +43,27 @@
import schmitzm.geotools.GTUtil;
import schmitzm.geotools.grid.GridUtil;
+import skrueger.geotools.Copyable;
import skrueger.i8n.Translation;
/**
- * Holds all the additional information needed to paint a Legend for a RasterLayer.
- * So far, only Legends for one-band raster layers are supported.
- *
- * @author Stefan Alfons Krüger
- *
+ * Holds all the additional information needed to paint a Legend for a
+ * RasterLayer. So far, only Legends for one-band raster layers are supported.
+ *
+ * @author Stefan Alfons Tzeggai
+ *
+ * TODO implements {@link Copyable}
*/
-public class RasterLegendData extends TreeMap {
- static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class);
+public class RasterLegendData extends TreeMap implements
+ Copyable {
+ static private final Logger LOGGER = Logger
+ .getLogger(RasterLegendData.class);
+
private Boolean paintGaps = false;
+ /**
+ * Shall bigger gaps be painted between the raster images
+ */
public Boolean isPaintGaps() {
return paintGaps;
}
@@ -65,49 +73,71 @@
}
/**
- * {@link #paintGaps} defines, if gaps should be painted between the legends colors,
- * indicating nominal values in the raster (e.g. classifications)
+ * {@link #paintGaps} defines, if gaps should be painted between the legends
+ * colors, indicating nominal values in the raster (e.g. classifications)
*/
public RasterLegendData(boolean paintGaps) {
this.paintGaps = paintGaps;
}
- public boolean getPaintGaps() {
- return paintGaps ;
+ /**
+ * Returns a new list containing all {@link Double} values that shall apear
+ * in the legend.
+ */
+ public List getSortedKeys() {
+ Double[] array = keySet().toArray(new Double[] {});
+
+ Arrays.sort(array);
+
+ final LinkedList linkedList = new LinkedList();
+ for (Double o : array) {
+ linkedList.add(o);
+ }
+
+ return linkedList;
+ }
+
+ /**
+ * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each legend
+ * value. These rasters can be used to do visualize the legend item in the
+ * corresponding color via {@link GridCoverageRenderer}.
+ */
+ public Map createSampleRasters() {
+ Map sampleRaster = new HashMap();
+
+ for (Double rasterValue : keySet()) {
+ GridCoverage2D grid = GridUtil.GRID_FAC.create("Legend_"
+ + rasterValue,
+ new float[][] { { rasterValue.floatValue() } },
+ new Envelope2D(GTUtil.WGS84, 0, 0, 1, 1));
+ sampleRaster.put(rasterValue, grid);
+ }
+ return sampleRaster;
+ }
+
+ /**
+ * Creates a new {@link RasterLegendData} object with identical values
+ */
+ @Override
+ public RasterLegendData copy() {
+ RasterLegendData copy = (RasterLegendData) super.clone();
+ return copyTo(copy);
}
-// public List getSortedKeys(){
-// Object[] array = keySet().toArray();
-//
-// Arrays.sort(array);
-//
-// final LinkedList linkedList = new LinkedList();
-// for (Object o : array){
-// linkedList.add( (Double)o);
-// }
-//
-// return linkedList;
-//
-// }
-
- /**
- * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each
- * legend value. These rasters can be used to do visualize the
- * legend item in the corresponding color via {@link GridCoverageRenderer}.
- */
- public SortedMap createSampleRasters() {
- SortedMap sampleRaster = new TreeMap();
-
- for (Double rasterValue : keySet()) {
- GridCoverage2D grid = GridUtil.GRID_FAC.create(
- "Legend_"+rasterValue,
- new float[][] { { rasterValue.floatValue() } },
- new Envelope2D(GTUtil.WGS84, 0,0,1,1)
- );
- sampleRaster.put(rasterValue, grid);
- }
-
-
- return sampleRaster;
- }
+ /**
+ * Deep-copies all values of this {@link RasterLegendData} to another
+ * {@link RasterLegendData}
+ */
+ @Override
+ public RasterLegendData copyTo(RasterLegendData target) {
+ target.clear();
+
+ target.setPaintGaps(isPaintGaps());
+
+ for (Double o : keySet()) {
+ target.put(new Double(o), get(o).copy());
+ }
+
+ return target;
+ }
}