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

Last change on this file since 8404 was 8404, checked in by Don-vip, 9 years ago

When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Lithuanian or Turkish. See PMD UseLocaleWithCaseConversions rule and String.toLowerCase() javadoc.

  • 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;
5import java.util.Locale;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.data.Preferences.ColorKey;
9
10/**
11 * A property containing a {@link Color} value.
12 * @since 5464
13 */
14public 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 }
27
28 @Override
29 public Color get() {
30 return Main.pref.getColor(this);
31 }
32
33 @Override
34 public boolean put(Color value) {
35 return Main.pref.putColor(getColorKey(name), value);
36 }
37
38 /**
39 * Replies the color key used in JOSM preferences for this property.
40 * @param colName The color name
41 * @return The color key for this property
42 */
43 public static String getColorKey(String colName) {
44 return colName == null ? null : colName.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]+",".");
45 }
46
47 @Override
48 public String getColorName() {
49 return name;
50 }
51
52 @Override
53 public String getSpecialName() {
54 return null;
55 }
56}
Note: See TracBrowser for help on using the repository browser.