| Revision 5170,
1.1 KB
checked in by Don-vip, 6 weeks ago
(diff) |
|
cleanup svn:mime-type properties preventing Java sources from being viewed as such on Trac
|
-
Property svn:eol-style set to
native
|
| 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 class IntegerProperty extends AbstractProperty<Integer> { |
|---|
| 7 | |
|---|
| 8 | protected final int defaultValue; |
|---|
| 9 | |
|---|
| 10 | public IntegerProperty(String key, int defaultValue) { |
|---|
| 11 | super(key); |
|---|
| 12 | this.defaultValue = defaultValue; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | public int get() { |
|---|
| 16 | return Main.pref.getInteger(getKey(), getDefaultValue()); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | public boolean put(int value) { |
|---|
| 20 | return Main.pref.putInteger(getKey(), value); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * parses and saves an integer value |
|---|
| 25 | * @param value the value to be parsed |
|---|
| 26 | * @return true - preference value has changed |
|---|
| 27 | * false - parsing failed or preference value has not changed |
|---|
| 28 | */ |
|---|
| 29 | public boolean parseAndPut(String value) { |
|---|
| 30 | Integer intVal; |
|---|
| 31 | try { |
|---|
| 32 | intVal = Integer.parseInt(value); |
|---|
| 33 | } catch (NumberFormatException ex) { |
|---|
| 34 | return false; |
|---|
| 35 | } |
|---|
| 36 | return put(intVal); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | @Override |
|---|
| 40 | public Integer getDefaultValue() { |
|---|
| 41 | return defaultValue; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.