annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/PaletteManager.java @ 1129:ccfa07b88476

merged geo-backend
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:01 +0200
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 801
diff changeset
8
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 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
10
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
11 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
12
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.HashMap;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 /**
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
16 * Manages palettes by their name. Provides different levels of
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
17 * 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
18 * @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
19 */
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public class PaletteManager
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
22 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
23 * The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
24 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 protected Palette base;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
27 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
28 * The description of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
29 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 protected String description;
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
32 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
33 * The name of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
34 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 protected String name;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
37 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
38 * Already created subdivisions of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
39 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 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
41
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
42 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 * Default constructor.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
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 PaletteManager() {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
48 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
49 * Constructor to create a palette manager with a given name,
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
50 * description and base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
51 * @param name The name.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
52 * @param description The description.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
53 * @param base The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
54 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public PaletteManager(
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 String name,
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 String description,
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 Palette base
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 this.name = name;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 this.description = description;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 this.base = base;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 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
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 * Returns the description of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
68 * @return The description.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
69 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 public String getDescription() {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 return description;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 * The name of the palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
76 * @return The name.
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 String getName() {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
79 return name;
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 base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
84 * @return The base palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
85 */
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
86 public Palette getBase() {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
87 return base;
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
88 }
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 438
diff changeset
89
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
90 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
91 * Returns the subdivided palette of a given level.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
92 * @param n The level of subdivision.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
93 * @return The subdivided palette.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
94 */
438
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 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
96 if (n < 2) {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 return base;
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
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 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
101
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 Palette palette;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 synchronized (levels) {
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 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
106
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 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
108 return palette;
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
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 palette = base.subdivide(n);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 ref = new SoftReference(palette);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 levels.put(N, ref);
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 return palette;
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
7399bb8f83ea Added manager to handle several levels of palette subdivsions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
798
6cff63d0c434 Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
121 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org