source: josm/trunk/src/org/openstreetmap/josm/data/preferences/ColorProperty.java@ 8390

Last change on this file since 8390 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.preferences;
3
4import java.awt.Color;
5
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.data.Preferences.ColorKey;
8
9/**
10 * A property containing a {@link Color} value.
11 * @since 5464
12 */
13public class ColorProperty extends AbstractProperty<Color> implements ColorKey {
14
15 private final String name;
16
17 /**
18 * Constructs a new {@code ColorProperty}.
19 * @param colName The color name
20 * @param defaultValue The default value
21 */
22 public ColorProperty(String colName, Color defaultValue) {
23 super(getColorKey(colName), defaultValue);
24 this.name = colName;
25 }
26
27 @Override
28 public Color get() {
29 return Main.pref.getColor(this);
30 }
31
32 @Override
33 public boolean put(Color value) {
34 return Main.pref.putColor(getColorKey(name), value);
35 }
36
37 /**
38 * Replies the color key used in JOSM preferences for this property.
39 * @param colName The color name
40 * @return The color key for this property
41 */
42 public static String getColorKey(String colName) {
43 return colName == null ? null : colName.toLowerCase().replaceAll("[^a-z0-9]+",".");
44 }
45
46 @Override
47 public String getColorName() {
48 return name;
49 }
50
51 @Override
52 public String getSpecialName() {
53 return null;
54 }
55}
Note: See TracBrowser for help on using the repository browser.