sascha@438: package de.intevation.gnv.raster; sascha@438: sascha@779: import java.lang.ref.SoftReference; sascha@779: sascha@438: import java.util.HashMap; sascha@438: sascha@438: /** sascha@780: * @author Sascha L. Teichmann sascha@438: */ sascha@438: public class PaletteManager sascha@438: { sascha@438: protected Palette base; sascha@438: sascha@438: protected String description; sascha@438: protected String name; sascha@438: sascha@438: protected HashMap> levels; sascha@438: sascha@438: public PaletteManager() { sascha@438: } sascha@438: sascha@438: public PaletteManager( sascha@438: String name, sascha@438: String description, sascha@438: Palette base sascha@438: ) { sascha@438: this.name = name; sascha@438: this.description = description; sascha@438: this.base = base; sascha@438: levels = new HashMap>(); sascha@438: } sascha@438: sascha@438: public String getDescription() { sascha@438: return description; sascha@438: } sascha@438: sascha@445: public String getName() { sascha@445: return name; sascha@445: } sascha@445: sascha@445: public Palette getBase() { sascha@445: return base; sascha@445: } sascha@445: sascha@438: public Palette getLevel(int n) { sascha@438: if (n < 2) { sascha@438: return base; sascha@438: } sascha@438: sascha@438: Integer N = Integer.valueOf(n); sascha@438: sascha@438: Palette palette; sascha@438: sascha@438: synchronized (levels) { sascha@438: SoftReference ref = levels.get(N); sascha@438: sascha@438: if (ref != null && (palette = ref.get()) != null) { sascha@438: return palette; sascha@438: } sascha@438: sascha@438: palette = base.subdivide(n); sascha@438: sascha@438: ref = new SoftReference(palette); sascha@438: sascha@438: levels.put(N, ref); sascha@438: } sascha@438: sascha@438: return palette; sascha@438: } sascha@438: } sascha@798: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :