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