annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java @ 801:d766fe2d917a

More javadoc. gnv-artifacts/trunk@883 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 06 Apr 2010 16:53:43 +0000
parents 6cff63d0c434
children f953c9a559d8
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
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
3 import java.lang.ref.SoftReference;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
4
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.HashMap;
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 /**
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
8 * Manages palettes by their name. Provides different levels of
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
9 * subdivisions.
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
10 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
438
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 public class PaletteManager
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
14 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
15 * The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
16 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 protected Palette base;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
19 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
20 * The description of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
21 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 protected String description;
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
23
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
24 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
25 * The name of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
26 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 protected String name;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
29 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
30 * Already created subdivisions of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 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
33
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
34 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
35 * Default constructor.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
36 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public PaletteManager() {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
40 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
41 * Constructor to create a palette manager with a given name,
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
42 * description and base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 * @param name The name.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
44 * @param description The description.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
45 * @param base The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
46 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public PaletteManager(
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 String name,
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 String description,
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 Palette base
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 this.name = name;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 this.description = description;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 this.base = base;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 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
56 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
58 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
59 * Returns the description of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
60 * @return The description.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
61 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 public String getDescription() {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 return description;
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
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
66 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
67 * The name of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
68 * @return The name.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
69 */
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
70 public String getName() {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
71 return name;
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
72 }
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
73
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
74 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
75 * Returns the base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
76 * @return The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
77 */
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
78 public Palette getBase() {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
79 return base;
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
80 }
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
81
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
82 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
83 * Returns the subdivided palette of a given level.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
84 * @param n The level of subdivision.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
85 * @return The subdivided palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
86 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 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
88 if (n < 2) {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 return base;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 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
93
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 Palette palette;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 synchronized (levels) {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 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
98
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 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
100 return palette;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 palette = base.subdivide(n);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 ref = new SoftReference(palette);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 levels.put(N, ref);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 return palette;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 }
798
6cff63d0c434 Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org