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.2 KB
|
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 | /**
|
---|
7 | * A property containing an {@code Integer} value.
|
---|
8 | */
|
---|
9 | public class IntegerProperty extends AbstractProperty<Integer> {
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Constructs a new {@code IntegerProperty}.
|
---|
13 | * @param key The property key
|
---|
14 | * @param defaultValue The default value
|
---|
15 | */
|
---|
16 | public IntegerProperty(String key, int defaultValue) {
|
---|
17 | super(key, defaultValue);
|
---|
18 | }
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | public Integer get() {
|
---|
22 | return Main.pref.getInteger(getKey(), getDefaultValue());
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public boolean put(Integer value) {
|
---|
27 | return Main.pref.putInteger(getKey(), value);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * parses and saves an integer value
|
---|
32 | * @param value the value to be parsed
|
---|
33 | * @return true - preference value has changed
|
---|
34 | * false - parsing failed or preference value has not changed
|
---|
35 | */
|
---|
36 | public boolean parseAndPut(String value) {
|
---|
37 | Integer intVal;
|
---|
38 | try {
|
---|
39 | intVal = Integer.parseInt(value);
|
---|
40 | } catch (NumberFormatException ex) {
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | return put(intVal);
|
---|
44 | }
|
---|
45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.