Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | f42ed4f10b79 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
1 package de.intevation.gnv.raster; | |
2 | |
3 import java.util.HashMap; | |
4 | |
5 import java.lang.ref.SoftReference; | |
6 | |
7 /** | |
8 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | |
9 */ | |
10 public class PaletteManager | |
11 { | |
12 protected Palette base; | |
13 | |
14 protected String description; | |
15 protected String name; | |
16 | |
17 protected HashMap<Integer, SoftReference<Palette>> levels; | |
18 | |
19 public PaletteManager() { | |
20 } | |
21 | |
22 public PaletteManager( | |
23 String name, | |
24 String description, | |
25 Palette base | |
26 ) { | |
27 this.name = name; | |
28 this.description = description; | |
29 this.base = base; | |
30 levels = new HashMap<Integer, SoftReference<Palette>>(); | |
31 } | |
32 | |
33 public String getDescription() { | |
34 return description; | |
35 } | |
36 | |
37 public String getName() { | |
38 return name; | |
39 } | |
40 | |
41 public Palette getBase() { | |
42 return base; | |
43 } | |
44 | |
45 public Palette getLevel(int n) { | |
46 if (n < 2) { | |
47 return base; | |
48 } | |
49 | |
50 Integer N = Integer.valueOf(n); | |
51 | |
52 Palette palette; | |
53 | |
54 synchronized (levels) { | |
55 SoftReference<Palette> ref = levels.get(N); | |
56 | |
57 if (ref != null && (palette = ref.get()) != null) { | |
58 return palette; | |
59 } | |
60 | |
61 palette = base.subdivide(n); | |
62 | |
63 ref = new SoftReference(palette); | |
64 | |
65 levels.put(N, ref); | |
66 } | |
67 | |
68 return palette; | |
69 } | |
70 } | |
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |