Last change
on this file since 7489 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
|
Rev | Line | |
---|
[3246] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.preferences;
|
---|
| 3 |
|
---|
| 4 | import org.openstreetmap.josm.Main;
|
---|
| 5 |
|
---|
[5464] | 6 | /**
|
---|
| 7 | * A property containing an {@code Integer} value.
|
---|
| 8 | */
|
---|
[4282] | 9 | public class IntegerProperty extends AbstractProperty<Integer> {
|
---|
[3246] | 10 |
|
---|
[5464] | 11 | /**
|
---|
| 12 | * Constructs a new {@code IntegerProperty}.
|
---|
| 13 | * @param key The property key
|
---|
| 14 | * @param defaultValue The default value
|
---|
| 15 | */
|
---|
[3246] | 16 | public IntegerProperty(String key, int defaultValue) {
|
---|
[5464] | 17 | super(key, defaultValue);
|
---|
[3246] | 18 | }
|
---|
| 19 |
|
---|
[5464] | 20 | @Override
|
---|
| 21 | public Integer get() {
|
---|
[3451] | 22 | return Main.pref.getInteger(getKey(), getDefaultValue());
|
---|
[3246] | 23 | }
|
---|
| 24 |
|
---|
[5464] | 25 | @Override
|
---|
| 26 | public boolean put(Integer value) {
|
---|
[3451] | 27 | return Main.pref.putInteger(getKey(), value);
|
---|
[3246] | 28 | }
|
---|
| 29 |
|
---|
[3461] | 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 | }
|
---|
[3246] | 45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.