Parse a color from a Settings file. Values are hexadecimal in either #RRGGBB (for opaque) or 0xAARRGGBB format (to include alpha).
(String attribute)
| 176 | * #RRGGBB (for opaque) or 0xAARRGGBB format (to include alpha). |
| 177 | */ |
| 178 | public Color getColor(String attribute) { |
| 179 | Color outgoing = null; |
| 180 | String s = get(attribute); |
| 181 | if (s != null) { |
| 182 | try { |
| 183 | if (s.startsWith("#")) { |
| 184 | // parse a 6-digit hex color |
| 185 | outgoing = new Color(Integer.parseInt(s.substring(1), 16)); |
| 186 | } else if (s.startsWith("0x")) { |
| 187 | int v = Integer.parseInt(s.substring(2), 16); |
| 188 | outgoing = new Color(v, true); |
| 189 | } |
| 190 | } catch (Exception ignored) { } |
| 191 | } |
| 192 | if (outgoing == null) { |
| 193 | System.err.println("Could not parse color " + s + " for " + attribute); |
| 194 | } |
| 195 | return outgoing; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | public void setColor(String attr, Color what) { |