Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java @ 426:3a0c0ad113d9
Load palettes from configuration.
gnv-artifacts/trunk@474 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 22 Dec 2009 10:34:15 +0000 |
parents | 21fbd254db71 |
children | 67091b17462d |
comparison
equal
deleted
inserted
replaced
425:15b8e95fa8da | 426:3a0c0ad113d9 |
---|---|
95 } // class Entry | 95 } // class Entry |
96 | 96 |
97 protected Entry [] entries; | 97 protected Entry [] entries; |
98 protected Entry lookup; | 98 protected Entry lookup; |
99 protected Color [] rgbs; | 99 protected Color [] rgbs; |
100 protected String description; | |
100 | 101 |
101 private Entry buildLookup(Entry [] entries, int lo, int hi) { | 102 private Entry buildLookup(Entry [] entries, int lo, int hi) { |
102 if (lo > hi) { | 103 if (lo > hi) { |
103 return null; | 104 return null; |
104 } | 105 } |
111 | 112 |
112 public Palette() { | 113 public Palette() { |
113 } | 114 } |
114 | 115 |
115 public Palette(Document document) { | 116 public Palette(Document document) { |
117 this(document, null); | |
118 } | |
119 | |
120 public Palette(Document document, String description) { | |
121 | |
122 this.description = description; | |
116 | 123 |
117 NodeList rangeNodes = document.getElementsByTagName("range"); | 124 NodeList rangeNodes = document.getElementsByTagName("range"); |
118 | 125 |
119 entries = new Entry[rangeNodes.getLength()]; | 126 entries = new Entry[rangeNodes.getLength()]; |
120 rgbs = new Color[entries.length]; | 127 rgbs = new Color[entries.length]; |
122 for (int i = 0; i < entries.length; ++i) { | 129 for (int i = 0; i < entries.length; ++i) { |
123 Element rangeElement = (Element)rangeNodes.item(i); | 130 Element rangeElement = (Element)rangeNodes.item(i); |
124 double from = doubleValue(rangeElement.getAttribute("from")); | 131 double from = doubleValue(rangeElement.getAttribute("from")); |
125 double to = doubleValue(rangeElement.getAttribute("to")); | 132 double to = doubleValue(rangeElement.getAttribute("to")); |
126 Color color = color(rangeElement.getAttribute("rgb")); | 133 Color color = color(rangeElement.getAttribute("rgb")); |
127 String description = rangeElement.getAttribute("description"); | 134 String desc = rangeElement.getAttribute("description"); |
128 if (from > to) { double t = from; from = to; to = t; } | 135 if (from > to) { double t = from; from = to; to = t; } |
129 entries[i] = new Entry(i, from, to, color, description); | 136 entries[i] = new Entry(i, from, to, color, desc); |
130 rgbs[i] = color; | 137 rgbs[i] = color; |
131 } | 138 } |
132 | 139 |
133 buildLookup(); | 140 buildLookup(); |
134 } | 141 } |
159 protected void buildLookup() { | 166 protected void buildLookup() { |
160 Arrays.sort(entries); | 167 Arrays.sort(entries); |
161 lookup = buildLookup(entries, 0, entries.length-1); | 168 lookup = buildLookup(entries, 0, entries.length-1); |
162 } | 169 } |
163 | 170 |
171 public String getDescription() { | |
172 return description; | |
173 } | |
174 | |
164 public int getSize() { | 175 public int getSize() { |
165 return rgbs.length; | 176 return rgbs.length; |
166 } | 177 } |
167 | 178 |
168 public Color getColor(int index) { | 179 public Color getColor(int index) { |