Last change
on this file since 9689 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:
877 bytes
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.preferences;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 |
|
---|
6 | public abstract class ParametrizedEnumProperty<T extends Enum<T>> {
|
---|
7 |
|
---|
8 | private final T defaultValue;
|
---|
9 | private final Class<T> enumClass;
|
---|
10 |
|
---|
11 | public ParametrizedEnumProperty(Class<T> enumClass, T defaultValue) {
|
---|
12 | this.defaultValue = defaultValue;
|
---|
13 | this.enumClass = enumClass;
|
---|
14 | if (Main.pref != null) {
|
---|
15 | get();
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected abstract String getKey(String... params);
|
---|
20 |
|
---|
21 | public T get(String... params) {
|
---|
22 | return parse(Main.pref.get(getKey(params), defaultValue.name()));
|
---|
23 | }
|
---|
24 |
|
---|
25 | public boolean put(T value, String... params) {
|
---|
26 | return Main.pref.put(getKey(params), value.name());
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected T parse(String s) {
|
---|
30 | return Enum.valueOf(enumClass, s);
|
---|
31 | }
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.