Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java @ 601:4c6d2b4df3ae
Changes id_layer of Table layerhasparameter from literal to number.
gnv-artifacts/trunk@659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 05 Feb 2010 10:36:46 +0000 |
parents | f42ed4f10b79 |
children | b1f5f2a8840f |
rev | line source |
---|---|
438
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.raster; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.HashMap; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.lang.ref.SoftReference; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 /** |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 */ |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 public class PaletteManager |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 protected Palette base; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 protected String description; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 protected String name; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 protected HashMap<Integer, SoftReference<Palette>> levels; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 public PaletteManager() { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public PaletteManager( |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 String name, |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 String description, |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 Palette base |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 ) { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 this.name = name; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 this.description = description; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 this.base = base; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 levels = new HashMap<Integer, SoftReference<Palette>>(); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public String getDescription() { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 return description; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
37 public String getName() { |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
38 return name; |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
39 } |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
40 |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
41 public Palette getBase() { |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
42 return base; |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
43 } |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
44 |
438
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public Palette getLevel(int n) { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 if (n < 2) { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 return base; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 Integer N = Integer.valueOf(n); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 Palette palette; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 synchronized (levels) { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 SoftReference<Palette> ref = levels.get(N); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 if (ref != null && (palette = ref.get()) != null) { |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return palette; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 palette = base.subdivide(n); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 ref = new SoftReference(palette); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 levels.put(N, ref); |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 return palette; |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
7399bb8f83ea
Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |