[3246] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.preferences;
|
---|
| 3 |
|
---|
[5464] | 4 | /**
|
---|
| 5 | * A property containing an {@code Integer} value.
|
---|
[8390] | 6 | * @since 3246
|
---|
[5464] | 7 | */
|
---|
[10824] | 8 | public class IntegerProperty extends AbstractToStringProperty<Integer> {
|
---|
[3246] | 9 |
|
---|
[5464] | 10 | /**
|
---|
| 11 | * Constructs a new {@code IntegerProperty}.
|
---|
| 12 | * @param key The property key
|
---|
| 13 | * @param defaultValue The default value
|
---|
| 14 | */
|
---|
[3246] | 15 | public IntegerProperty(String key, int defaultValue) {
|
---|
[5464] | 16 | super(key, defaultValue);
|
---|
[13002] | 17 | if (getPreferences() != null) {
|
---|
[9689] | 18 | get();
|
---|
| 19 | }
|
---|
[3246] | 20 | }
|
---|
| 21 |
|
---|
[5464] | 22 | @Override
|
---|
| 23 | public Integer get() {
|
---|
[10824] | 24 | // Removing this implementation breaks binary compatibility
|
---|
| 25 | return super.get();
|
---|
[3246] | 26 | }
|
---|
| 27 |
|
---|
[5464] | 28 | @Override
|
---|
| 29 | public boolean put(Integer value) {
|
---|
[10824] | 30 | // Removing this implementation breaks binary compatibility
|
---|
| 31 | return super.put(value);
|
---|
[3246] | 32 | }
|
---|
| 33 |
|
---|
[10824] | 34 | @Override
|
---|
| 35 | protected Integer fromString(String string) {
|
---|
| 36 | try {
|
---|
| 37 | return Integer.valueOf(string);
|
---|
| 38 | } catch (NumberFormatException e) {
|
---|
| 39 | throw new InvalidPreferenceValueException(e);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | @Override
|
---|
| 44 | protected String toString(Integer t) {
|
---|
| 45 | return t.toString();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[3461] | 48 | /**
|
---|
| 49 | * parses and saves an integer value
|
---|
| 50 | * @param value the value to be parsed
|
---|
| 51 | * @return true - preference value has changed
|
---|
| 52 | * false - parsing failed or preference value has not changed
|
---|
| 53 | */
|
---|
| 54 | public boolean parseAndPut(String value) {
|
---|
| 55 | try {
|
---|
[8390] | 56 | return put(Integer.valueOf(value));
|
---|
[3461] | 57 | } catch (NumberFormatException ex) {
|
---|
| 58 | return false;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
[3246] | 61 | }
|
---|