# HG changeset patch # User Sascha L. Teichmann # Date 1262001027 0 # Node ID 7399bb8f83ea098cb5736af41cc83c7f84560eca # Parent b624879d29023f74fd62723071f2ad7bc68c1168 Added manager to handle several levels of palette subdivsions. Added parameter ids to identify the palette associated with a parameter gnv-artifacts/trunk@486 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b624879d2902 -r 7399bb8f83ea gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Sun Dec 27 05:25:40 2009 +0000 +++ b/gnv-artifacts/ChangeLog Mon Dec 28 11:50:27 2009 +0000 @@ -1,3 +1,24 @@ +2009-12-28 Sascha L. Teichmann + + * src/main/java/de/intevation/gnv/raster/PaletteManager.java: New. + Used to manage several levels of palette subdivsions derived from + base palette. Contains name and description of palette, too. + + * src/main/java/de/intevation/gnv/raster/Palette.java: Removed + palette description because it is hold by the PaletteManager now. + + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java: + The palettes are not stored under the name of the palette any longer. + Instead the new attribute 'parameter-id' is splitted (comma separated) + into integers which are use as keys now. The values are PaletteManagers. + This should ease the access to an adequate PaletteManager when + generating a chart for a certain parameter. + + * doc/conf/conf.xml: Added the 'parameter-ids' for the four palettes. + The values are extracted from the gdiintern wiki. + + !!! This have to be in sync with the database parameter ids !!! + 2009-12-27 Sascha L. Teichmann * src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java: diff -r b624879d2902 -r 7399bb8f83ea gnv-artifacts/doc/conf/conf.xml --- a/gnv-artifacts/doc/conf/conf.xml Sun Dec 27 05:25:40 2009 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Mon Dec 28 11:50:27 2009 +0000 @@ -393,15 +393,19 @@ diff -r b624879d2902 -r 7399bb8f83ea gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Sun Dec 27 05:25:40 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Mon Dec 28 11:50:27 2009 +0000 @@ -11,6 +11,7 @@ import java.util.Properties; import java.util.HashMap; +import java.util.ArrayList; import org.apache.log4j.Logger; @@ -29,6 +30,7 @@ import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.raster.Palette; +import de.intevation.gnv.raster.PaletteManager; import de.intevation.artifacts.ArtifactContextFactory; @@ -160,7 +162,7 @@ ) { log.info("configure palettes"); - HashMap palettes = new HashMap(); + HashMap palettes = new HashMap(); Node node = Config.getNodeXPath(config, PALETTES_PATH); @@ -171,17 +173,33 @@ NodeList pals = Config.getNodeSetXPath(PALETTE_ITEMS); for (int i = 0, N = pals == null ? 0 : pals.getLength(); i < N; ++i) { Element pal = (Element)pals.item(i); - String name = pal.getAttribute("name"); - String description = pal.getAttribute("description"); - String filename = pal.getAttribute("file"); + String name = pal.getAttribute("name"); + String description = pal.getAttribute("description"); + String filename = pal.getAttribute("file"); + String parameterIds = pal.getAttribute("parameter-ids"); - if (name == null || name.length() == 0) { + if (name == null || (name = name.trim()).length() == 0) { log.error("Palette has no 'name' attribute."); } - else if (filename == null || filename.length() == 0) { - log.error("Palette has no 'file' attribute."); + else if (filename == null + || (filename = filename.trim()).length() == 0) { + log.error("Palette '" + name + "' has no 'file' attribute."); + } + else if (parameterIds == null + || (parameterIds = parameterIds.trim()).length() == 0) { + log.error("no parameter ids given for '" + name + "'"); } else { + ArrayList ids = new ArrayList(); + for (String idString: parameterIds.split("[\t ,]+")) { + try { + ids.add(Integer.valueOf(idString)); + } + catch (NumberFormatException nfe) { + log.error( + "parameter id '" + idString + "' is integer"); + } + } filename = Config.replaceConfigDir(filename); Document document = XMLUtils.parseDocument( new File(filename)); @@ -190,11 +208,16 @@ filename + "'"); } else { - Palette p = new Palette(document, description); - palettes.put(name, p); + PaletteManager manager = new PaletteManager( + name, + description, + new Palette(document)); + for (Integer id: ids) { + palettes.put(id, manager); + } } } - } + } // for all palettes } context.put(PALETTES, palettes); diff -r b624879d2902 -r 7399bb8f83ea gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java Sun Dec 27 05:25:40 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java Mon Dec 28 11:50:27 2009 +0000 @@ -110,7 +110,6 @@ protected Entry [] entries; protected Entry lookup; protected Color [] rgbs; - protected String description; private Entry buildLookup(Entry [] entries, int lo, int hi) { if (lo > hi) { @@ -127,12 +126,6 @@ } public Palette(Document document) { - this(document, null); - } - - public Palette(Document document, String description) { - - this.description = description; NodeList rangeNodes = document.getElementsByTagName("range"); @@ -230,10 +223,6 @@ return new Palette(this, N); } - public String getDescription() { - return description; - } - public int getSize() { return rgbs.length; } diff -r b624879d2902 -r 7399bb8f83ea gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java Mon Dec 28 11:50:27 2009 +0000 @@ -0,0 +1,63 @@ +package de.intevation.gnv.raster; + +import java.util.HashMap; + +import java.lang.ref.SoftReference; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class PaletteManager +{ + protected Palette base; + + protected String description; + protected String name; + + protected HashMap> levels; + + public PaletteManager() { + } + + public PaletteManager( + String name, + String description, + Palette base + ) { + this.name = name; + this.description = description; + this.base = base; + levels = new HashMap>(); + } + + public String getDescription() { + return description; + } + + public Palette getLevel(int n) { + if (n < 2) { + return base; + } + + Integer N = Integer.valueOf(n); + + Palette palette; + + synchronized (levels) { + SoftReference ref = levels.get(N); + + if (ref != null && (palette = ref.get()) != null) { + return palette; + } + + palette = base.subdivide(n); + + ref = new SoftReference(palette); + + levels.put(N, ref); + } + + return palette; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: