Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java @ 483:c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
gnv-artifacts/trunk@558 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 18 Jan 2010 10:56:41 +0000 |
parents | c7ca2fce041f |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
482:64e65daa65e9 | 483:c8089cd7d777 |
---|---|
26 private Entry left; | 26 private Entry left; |
27 private Entry right; | 27 private Entry right; |
28 | 28 |
29 private int index; | 29 private int index; |
30 | 30 |
31 private int externalIndex; | |
32 | |
31 private double from; | 33 private double from; |
32 private double to; | 34 private double to; |
33 | 35 |
34 private String description; | 36 private String description; |
35 | 37 |
37 | 39 |
38 public Entry() { | 40 public Entry() { |
39 } | 41 } |
40 | 42 |
41 public Entry(Entry other) { | 43 public Entry(Entry other) { |
42 index = other.index; | 44 index = other.index; |
43 from = other.from; | 45 externalIndex = other.externalIndex; |
44 to = other.to; | 46 from = other.from; |
45 description = other.description; | 47 to = other.to; |
46 color = other.color; | 48 description = other.description; |
49 color = other.color; | |
47 } | 50 } |
48 | 51 |
49 public Entry( | 52 public Entry( |
50 int index, | 53 int index, |
54 int externalIndex, | |
51 double from, | 55 double from, |
52 double to, | 56 double to, |
53 Color color, | 57 Color color, |
54 String description | 58 String description |
55 ) { | 59 ) { |
56 this.index = index; | 60 this.index = index; |
57 this.from = from; | 61 this.externalIndex = externalIndex; |
58 this.to = to; | 62 this.from = from; |
59 this.color = color; | 63 this.to = to; |
60 this.description = description; | 64 this.color = color; |
65 this.description = description; | |
61 } | 66 } |
62 | 67 |
63 public int compareTo(Object other) { | 68 public int compareTo(Object other) { |
64 Entry e = (Entry)other; | 69 Entry e = (Entry)other; |
65 if (from < e.from) return -1; | 70 if (from < e.from) return -1; |
75 return to; | 80 return to; |
76 } | 81 } |
77 | 82 |
78 public Color getColor() { | 83 public Color getColor() { |
79 return color; | 84 return color; |
85 } | |
86 | |
87 public int getExternalIndex() { | |
88 return externalIndex; | |
80 } | 89 } |
81 | 90 |
82 public Entry locateEntry(double value) { | 91 public Entry locateEntry(double value) { |
83 Entry current = this; | 92 Entry current = this; |
84 while (current != null) { | 93 while (current != null) { |
148 entries = new Entry[rangeNodes.getLength()]; | 157 entries = new Entry[rangeNodes.getLength()]; |
149 rgbs = new Color[entries.length]; | 158 rgbs = new Color[entries.length]; |
150 | 159 |
151 for (int i = 0; i < entries.length; ++i) { | 160 for (int i = 0; i < entries.length; ++i) { |
152 Element rangeElement = (Element)rangeNodes.item(i); | 161 Element rangeElement = (Element)rangeNodes.item(i); |
153 double from = doubleValue(rangeElement.getAttribute("from")); | 162 double from = doubleValue(rangeElement.getAttribute("from")); |
154 double to = doubleValue(rangeElement.getAttribute("to")); | 163 double to = doubleValue(rangeElement.getAttribute("to")); |
155 Color color = color(rangeElement.getAttribute("rgb")); | 164 int extIndex = intValue(rangeElement.getAttribute("index"), i); |
156 String desc = rangeElement.getAttribute("description"); | 165 Color color = color(rangeElement.getAttribute("rgb")); |
166 String desc = rangeElement.getAttribute("description"); | |
157 if (from > to) { double t = from; from = to; to = t; } | 167 if (from > to) { double t = from; from = to; to = t; } |
158 entries[i] = new Entry(i, from, to, color, desc); | 168 entries[i] = new Entry(i, extIndex, from, to, color, desc); |
159 rgbs[i] = color; | 169 rgbs[i] = color; |
160 } | 170 } |
161 | 171 |
162 buildLookup(); | 172 buildLookup(); |
163 } | 173 } |
205 } // for all original entries | 215 } // for all original entries |
206 | 216 |
207 buildLookup(); | 217 buildLookup(); |
208 } | 218 } |
209 | 219 |
220 private static final int intValue(String s, int def) { | |
221 if (s == null || (s = s.trim()).length() == 0) { | |
222 return def; | |
223 } | |
224 try { | |
225 return Integer.parseInt(s); | |
226 } | |
227 catch (NumberFormatException nfe) { | |
228 log.error(nfe.getLocalizedMessage(), nfe); | |
229 } | |
230 return def; | |
231 } | |
232 | |
210 private static final double doubleValue(String s) { | 233 private static final double doubleValue(String s) { |
211 if (s == null || (s = s.trim()).length() == 0) { | 234 if (s == null || (s = s.trim()).length() == 0) { |
212 return 0d; | 235 return 0d; |
213 } | 236 } |
214 if ((s = s.toLowerCase()).startsWith("-inf")) { | 237 if ((s = s.toLowerCase()).startsWith("-inf")) { |