source: josm/trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java@ 5464

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

Rework Properties a bit to simplify management of Color properties

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.preferences;
3
4import org.openstreetmap.josm.Main;
5
6/**
7 * Captures the common functionality of preference properties
8 * @param <T> The type of object accessed by this property
9 */
10public abstract class AbstractProperty<T> {
11 protected final String key;
12 protected final T defaultValue;
13
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) {
21 this.key = key;
22 this.defaultValue = defaultValue;
23 }
24
25 /**
26 * Replies the property key.
27 * @return The property key
28 */
29 public String getKey() {
30 return key;
31 }
32
33 /**
34 * Determines if this property is currently set in JOSM preferences.
35 * @return true if {@code Main.pref} contains this property.
36 */
37 public boolean isSet() {
38 return !Main.pref.get(key).isEmpty();
39 }
40
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 }
48
49 /**
50 * Removes this property from JOSM preferences (i.e replace it by its default value).
51 */
52 public void remove() {
53 Main.pref.put(getKey(), String.valueOf(getDefaultValue()));
54 }
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);
70}
Note: See TracBrowser for help on using the repository browser.