### Eclipse Workspace Patch 1.0
#P JOSM
|
|
|
|
| 2 | 2 | package org.openstreetmap.josm.data.preferences; |
| 3 | 3 | |
| 4 | 4 | import java.awt.Color; |
| | 5 | import java.util.HashMap; |
| 5 | 6 | import java.util.Locale; |
| | 7 | import java.util.Map; |
| | 8 | import java.util.regex.Pattern; |
| 6 | 9 | |
| 7 | 10 | import org.openstreetmap.josm.Main; |
| 8 | 11 | import org.openstreetmap.josm.data.Preferences.ColorKey; |
| … |
… |
|
| 35 | 38 | return Main.pref.putColor(getColorKey(name), value); |
| 36 | 39 | } |
| 37 | 40 | |
| | 41 | private static final Map<String, String> XLATED_COLOR_KEYS = new HashMap<String, String>(); |
| | 42 | private static final Pattern XLATED_COLOR_PATTERN = Pattern.compile("[^a-z0-9]+"); |
| | 43 | |
| 38 | 44 | /** |
| 39 | 45 | * Replies the color key used in JOSM preferences for this property. |
| 40 | 46 | * @param colName The color name |
| … |
… |
|
| 41 | 47 | * @return The color key for this property |
| 42 | 48 | */ |
| 43 | 49 | public static String getColorKey(String colName) { |
| 44 | | return colName == null ? null : colName.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]+", "."); |
| | 50 | |
| | 51 | if (colName == null) { |
| | 52 | return null; |
| | 53 | } |
| | 54 | |
| | 55 | synchronized (XLATED_COLOR_KEYS) { |
| | 56 | String xlated = XLATED_COLOR_KEYS.get(colName); |
| | 57 | if (xlated == null) { |
| | 58 | xlated = XLATED_COLOR_PATTERN.matcher(colName.toLowerCase(Locale.ENGLISH)).replaceAll("."); |
| | 59 | XLATED_COLOR_KEYS.put(colName, xlated); |
| | 60 | } |
| | 61 | return xlated; |
| | 62 | } |
| 45 | 63 | } |
| 46 | 64 | |
| 47 | 65 | @Override |