- Timestamp:
- 2012-08-20T23:06:41+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r5462 r5464 49 49 50 50 import org.openstreetmap.josm.Main; 51 import org.openstreetmap.josm.data.preferences.ColorProperty; 51 52 import org.openstreetmap.josm.io.MirroredInputStream; 52 53 import org.openstreetmap.josm.io.XmlWriter; … … 241 242 String getColorName(); 242 243 String getSpecialName(); 243 Color getDefault ();244 Color getDefaultValue(); 244 245 } 245 246 … … 449 450 } 450 451 451 synchronized public boolean getBoolean(final String key) {452 synchronized public Boolean getBoolean(final String key) { 452 453 putDefault(key, null); 453 454 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : false; 454 455 } 455 456 456 synchronized public boolean getBoolean(final String key, final boolean def) {457 synchronized public Boolean getBoolean(final String key, final boolean def) { 457 458 putDefault(key, Boolean.toString(def)); 458 459 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def; 459 460 } 460 461 461 synchronized public boolean getBoolean(final String key, final String specName, final boolean def) {462 synchronized public Boolean getBoolean(final String key, final String specName, final boolean def) { 462 463 putDefault(key, Boolean.toString(def)); 463 464 String skey = key+"."+specName; … … 802 803 803 804 public Color getColor(ColorKey key) { 804 return getColor(key.getColorName(), key.getSpecialName(), key.getDefault ());805 return getColor(key.getColorName(), key.getSpecialName(), key.getDefaultValue()); 805 806 } 806 807 … … 814 815 */ 815 816 synchronized public Color getColor(String colName, String specName, Color def) { 816 String colKey = colName.toLowerCase().replaceAll("[^a-z0-9]+",".");817 String colKey = ColorProperty.getColorKey(colName); 817 818 if(!colKey.equals(colName)) { 818 819 colornames.put(colKey, colName); … … 826 827 } 827 828 828 synchronized public Color getDefaultColor(String col Name) {829 String colStr = defaults.get("color."+col Name);829 synchronized public Color getDefaultColor(String colKey) { 830 String colStr = defaults.get("color."+colKey); 830 831 return colStr == null || "".equals(colStr) ? null : ColorHelper.html2color(colStr); 831 832 } 832 833 833 synchronized public boolean putColor(String col Name, Color val) {834 return put("color."+col Name, val != null ? ColorHelper.color2html(val) : null);834 synchronized public boolean putColor(String colKey, Color val) { 835 return put("color."+colKey, val != null ? ColorHelper.color2html(val) : null); 835 836 } 836 837 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java
r5421 r5464 57 57 } 58 58 59 @Override 59 60 public String getColorName() { 60 61 return name; 61 62 } 62 63 63 public Color getDefault() { 64 @Override 65 public Color getDefaultValue() { 64 66 return defaultColor; 65 67 } 66 68 69 @Override 67 70 public String getSpecialName() { 68 71 return null; -
trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java
r4932 r5464 5 5 6 6 /** 7 * captures the common functionality of preference properties 7 * Captures the common functionality of preference properties 8 * @param <T> The type of object accessed by this property 8 9 */ 9 10 public abstract class AbstractProperty<T> { 10 11 protected final String key; 12 protected final T defaultValue; 11 13 12 public AbstractProperty(String key) { 14 /** 15 * Constructs a new {@code AbstractProperty}. 16 * @param key The property key 17 * @param defaultValue The default value 18 * @since 5464 19 */ 20 public AbstractProperty(String key, T defaultValue) { 13 21 this.key = key; 22 this.defaultValue = defaultValue; 14 23 } 15 24 25 /** 26 * Replies the property key. 27 * @return The property key 28 */ 16 29 public String getKey() { 17 30 return key; 18 31 } 19 32 33 /** 34 * Determines if this property is currently set in JOSM preferences. 35 * @return true if {@code Main.pref} contains this property. 36 */ 20 37 public boolean isSet() { 21 38 return !Main.pref.get(key).isEmpty(); 22 39 } 23 40 24 public abstract T getDefaultValue(); 41 /** 42 * Replies the default value of this property. 43 * @return The default value of this property 44 */ 45 public T getDefaultValue() { 46 return defaultValue; 47 } 25 48 49 /** 50 * Removes this property from JOSM preferences (i.e replace it by its default value). 51 */ 26 52 public void remove() { 27 53 Main.pref.put(getKey(), String.valueOf(getDefaultValue())); 28 54 } 29 55 56 /** 57 * Replies the value of this property. 58 * @return the value of this property 59 * @since 5464 60 */ 61 public abstract T get(); 62 63 /** 64 * Sets this property to the specified value. 65 * @param value The new value of this property 66 * @return true if something has changed (i.e. value is different than before) 67 * @since 5464 68 */ 69 public abstract boolean put(T value); 30 70 } -
trunk/src/org/openstreetmap/josm/data/preferences/BooleanProperty.java
r5170 r5464 4 4 import org.openstreetmap.josm.Main; 5 5 6 /** 7 * A property containing a {@code Boolean} value. 8 */ 6 9 public class BooleanProperty extends AbstractProperty<Boolean> { 7 10 8 protected final boolean defaultValue; 9 11 /** 12 * Constructs a new {@code BooleanProperty}. 13 * @param key The property key 14 * @param defaultValue The default value 15 */ 10 16 public BooleanProperty(String key, boolean defaultValue) { 11 super(key); 12 this.defaultValue = defaultValue; 17 super(key, defaultValue); 13 18 } 14 19 15 public boolean get() { 20 @Override 21 public Boolean get() { 16 22 return Main.pref.getBoolean(getKey(), defaultValue); 17 23 } 18 24 19 public boolean put(boolean value) { 25 @Override 26 public boolean put(Boolean value) { 20 27 return Main.pref.put(getKey(), value); 21 28 } 22 23 @Override24 public Boolean getDefaultValue() {25 return defaultValue;26 }27 29 } -
trunk/src/org/openstreetmap/josm/data/preferences/CachedProperty.java
r4932 r5464 8 8 public abstract class CachedProperty<T> extends AbstractProperty<T> implements PreferenceChangedListener { 9 9 10 pr otected final String defaultValue;10 private final String defaultValueAsString; 11 11 private T value; 12 12 private int updateCount; 13 13 14 protected CachedProperty(String key, String defaultValue) {15 super(key );14 protected CachedProperty(String key, T defaultValue, String defaultValueAsString) { 15 super(key, defaultValue); 16 16 Main.pref.addPreferenceChangeListener(this); 17 this.defaultValue = defaultValue;17 this.defaultValueAsString = defaultValueAsString; 18 18 updateValue(); 19 19 } … … 30 30 protected abstract T fromString(String s); 31 31 32 @Override 32 33 public T get() { 33 34 return value; … … 40 41 } 41 42 43 @Override 44 public final boolean put(T value) { 45 // Not used 46 throw new IllegalAccessError("You cannot use put(T). Use put(String) instead."); 47 } 48 42 49 public int getUpdateCount() { 43 50 return updateCount; 44 51 } 45 52 46 @Override47 public T getDefaultValue() {48 return fromString(getDefaultValueAsString());49 }50 51 53 public String getDefaultValueAsString() { 52 return defaultValue ;54 return defaultValueAsString; 53 55 } 54 56 -
trunk/src/org/openstreetmap/josm/data/preferences/CollectionProperty.java
r5170 r5464 6 6 import org.openstreetmap.josm.Main; 7 7 8 /** 9 * A property containing a {@code Collection} of {@code String} as value. 10 */ 8 11 public class CollectionProperty extends AbstractProperty<Collection<String>> { 9 protected final Collection<String> defaultValue;10 12 13 /** 14 * Constructs a new {@code CollectionProperty}. 15 * @param key The property key 16 * @param defaultValue The default value 17 */ 11 18 public CollectionProperty(String key, Collection<String> defaultValue) { 12 super(key); 13 this.defaultValue = defaultValue; 19 super(key, defaultValue); 14 20 } 15 21 22 @Override 16 23 public Collection<String> get() { 17 24 return Main.pref.getCollection(getKey(), getDefaultValue()); 18 25 } 19 26 27 @Override 20 28 public boolean put(Collection<String> value) { 21 29 return Main.pref.putCollection(getKey(), value); 22 30 } 23 24 @Override25 public Collection<String> getDefaultValue() {26 return defaultValue;27 }28 29 31 } -
trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java
r5170 r5464 4 4 import org.openstreetmap.josm.Main; 5 5 6 /** 7 * A property containing an {@code Integer} value. 8 */ 6 9 public class IntegerProperty extends AbstractProperty<Integer> { 7 10 8 protected final int defaultValue; 9 11 /** 12 * Constructs a new {@code IntegerProperty}. 13 * @param key The property key 14 * @param defaultValue The default value 15 */ 10 16 public IntegerProperty(String key, int defaultValue) { 11 super(key); 12 this.defaultValue = defaultValue; 17 super(key, defaultValue); 13 18 } 14 19 15 public int get() { 20 @Override 21 public Integer get() { 16 22 return Main.pref.getInteger(getKey(), getDefaultValue()); 17 23 } 18 24 19 public boolean put(int value) { 25 @Override 26 public boolean put(Integer value) { 20 27 return Main.pref.putInteger(getKey(), value); 21 28 } … … 36 43 return put(intVal); 37 44 } 38 39 @Override40 public Integer getDefaultValue() {41 return defaultValue;42 }43 44 45 } -
trunk/src/org/openstreetmap/josm/data/preferences/StringProperty.java
r5170 r5464 4 4 import org.openstreetmap.josm.Main; 5 5 6 /** 7 * A property containing an {@code String} value. 8 */ 6 9 public class StringProperty extends AbstractProperty<String> { 7 10 8 protected final String defaultValue; 9 11 /** 12 * Constructs a new {@code StringProperty}. 13 * @param key The property key 14 * @param defaultValue The default value 15 */ 10 16 public StringProperty(String key, String defaultValue) { 11 super(key); 12 this.defaultValue = defaultValue; 17 super(key, defaultValue); 13 18 } 14 19 20 @Override 15 21 public String get() { 16 22 return Main.pref.get(getKey(), getDefaultValue()); 17 23 } 18 24 25 @Override 19 26 public boolean put(String value) { 20 27 return Main.pref.put(getKey(), value); 21 28 } 22 23 @Override24 public String getDefaultValue() {25 return defaultValue;26 }27 28 29 } -
trunk/src/org/openstreetmap/josm/gui/conflict/ConflictColors.java
r4163 r5464 45 45 } 46 46 47 @Override 47 48 public String getColorName() { 48 49 return name; 49 50 } 50 51 51 public Color getDefault() { 52 @Override 53 public Color getDefaultValue() { 52 54 return defaultColor; 53 55 } 54 56 57 @Override 55 58 public String getSpecialName() { 56 59 return null; -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r5462 r5464 35 35 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 36 36 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 37 import org.openstreetmap.josm.data.preferences.ColorProperty; 37 38 import org.openstreetmap.josm.data.preferences.IntegerProperty; 38 39 import org.openstreetmap.josm.gui.MenuScroller; … … 43 44 public abstract class ImageryLayer extends Layer { 44 45 46 public static final ColorProperty PROP_FADE_COLOR = new ColorProperty(marktr("Imagery fade"), Color.white); 45 47 public static final IntegerProperty PROP_FADE_AMOUNT = new IntegerProperty("imagery.fade_amount", 0); 46 48 public static final IntegerProperty PROP_SHARPEN_LEVEL = new IntegerProperty("imagery.sharpen_level", 0); 47 49 48 50 public static Color getFadeColor() { 49 return Main.pref.getColor(marktr("Imagery fade"), Color.white);51 return PROP_FADE_COLOR.get(); 50 52 } 51 53 52 54 public static Color getFadeColorWithAlpha() { 53 Color c = getFadeColor();55 Color c = PROP_FADE_COLOR.get(); 54 56 return new Color(c.getRed(),c.getGreen(),c.getBlue(),PROP_FADE_AMOUNT.get()*255/100); 55 }56 57 public static void setFadeColor(Color color) {58 Main.pref.putColor("imagery.fade", color);59 57 } 60 58 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r4869 r5464 102 102 TemplateEntryProperty result = cache.get(key); 103 103 if (result == null) { 104 String defaultValue = layerName == null?getDefaultLabelPattern():""; 105 TemplateEntryProperty parent = layerName == null?null:forMarker(null); 106 result = new TemplateEntryProperty(key, defaultValue, parent); 107 cache.put(key, result); 104 String defaultValue = layerName == null ? getDefaultLabelPattern():""; 105 TemplateEntryProperty parent = layerName == null ? null : forMarker(null); 106 try { 107 result = new TemplateEntryProperty(key, defaultValue, parent); 108 cache.put(key, result); 109 } catch (ParseError e) { 110 System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s", defaultValue, key)); 111 } 108 112 } 109 113 return result; … … 118 122 if (result == null) { 119 123 String defaultValue = layerName == null?"?{ '{name}' | '{desc}' | '{" + Marker.MARKER_FORMATTED_OFFSET + "}' }":""; 120 TemplateEntryProperty parent = layerName == null?null:forAudioMarker(null); 121 result = new TemplateEntryProperty(key, defaultValue, parent); 122 cache.put(key, result); 124 TemplateEntryProperty parent = layerName == null ? null : forAudioMarker(null); 125 try { 126 result = new TemplateEntryProperty(key, defaultValue, parent); 127 cache.put(key, result); 128 } catch (ParseError e) { 129 System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s", defaultValue, key)); 130 } 123 131 } 124 132 return result; … … 128 136 129 137 130 private TemplateEntryProperty(String key, String defaultValue, TemplateEntryProperty parent) {131 super(key, defaultValue);138 private TemplateEntryProperty(String key, String defaultValue, TemplateEntryProperty parent) throws ParseError { 139 super(key, new TemplateParser(defaultValue).parse(), defaultValue); 132 140 this.parent = parent; 133 141 updateValue(); // Needs to be called because parent wasn't know in super constructor … … 140 148 } catch (ParseError e) { 141 149 System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s. Using default ('%s') instead", 142 s, getKey(), defaultValue));150 s, getKey(), super.getDefaultValueAsString())); 143 151 return getDefaultValue(); 144 152 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r5429 r5464 26 26 import java.util.HashSet; 27 27 import java.util.List; 28 import java.util.Locale;29 28 import java.util.Map; 30 29 import java.util.Set; … … 129 128 final JPanel p = new JPanel(new GridBagLayout()); 130 129 131 this.colFadeColor = ImageryLayer. getFadeColor();130 this.colFadeColor = ImageryLayer.PROP_FADE_COLOR.get(); 132 131 this.btnFadeColor = new JButton(); 133 132 … … 196 195 JLabel labelEast = new JLabel(tr("% of east:")); 197 196 JLabel labelNorth = new JLabel(tr("% of north:")); 198 spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get() , 1, 50, 1));199 spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get() , 1, 50, 1));197 spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get().intValue(), 1, 50, 1)); 198 spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get().intValue(), 1, 50, 1)); 200 199 201 200 JPanel overlapPanel = new JPanel(new FlowLayout()); … … 211 210 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 212 211 JLabel labelSimConn = new JLabel(tr("Simultaneous connections")); 213 spinSimConn = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get() , 1, 30, 1));212 spinSimConn = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get().intValue(), 1, 30, 1)); 214 213 JPanel overlapPanelSimConn = new JPanel(new FlowLayout(FlowLayout.LEFT)); 215 214 overlapPanelSimConn.add(labelSimConn); … … 352 351 353 352 ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue()); 354 ImageryLayer. setFadeColor(this.colFadeColor);353 ImageryLayer.PROP_FADE_COLOR.put(this.colFadeColor); 355 354 ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex()); 356 355
Note:
See TracChangeset
for help on using the changeset viewer.