Ignore:
Timestamp:
2017-10-29T14:57:41+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #14602 - allow both dot and comma decimal separator everywhere possible for user-entered values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/DefaultPreferenceSetting.java

    r12460 r13050  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.preferences;
     3
     4import javax.swing.JCheckBox;
     5import javax.swing.JTextField;
     6
     7import org.openstreetmap.josm.spi.preferences.Config;
     8import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider;
     9import org.openstreetmap.josm.tools.Logging;
    310
    411/**
    512 * Abstract base class for {@link PreferenceSetting} implementations.
    613 *
    7  * Handles the flag that indicates if a PreferenceSetting is and expert option
    8  * or not.
     14 * Handles the flag that indicates if a PreferenceSetting is and expert option or not.
     15 * @since 4968
    916 */
    1017public abstract class DefaultPreferenceSetting implements PreferenceSetting {
     
    3441        return isExpert;
    3542    }
     43
     44    /**
     45     * Saves state from a {@link JCheckBox} to a boolean preference.
     46     * @param prefName preference name
     47     * @param cb check box
     48     * @since 13050
     49     */
     50    protected static void saveBoolean(String prefName, JCheckBox cb) {
     51        Config.getPref().putBoolean(prefName, cb.isSelected());
     52    }
     53
     54    /**
     55     * Saves text from a {@link JTextField} to a double preference.
     56     * @param prefName preference name
     57     * @param tf text field
     58     * @since 13050
     59     */
     60    protected static void saveDouble(String prefName, JTextField tf) {
     61        String text = tf.getText();
     62        try {
     63            Config.getPref().putDouble(prefName, JosmDecimalFormatSymbolsProvider.parseDouble(text));
     64        } catch (NumberFormatException e) {
     65            Logging.warn("Unable to save '" + text + "' as a double value for preference " + prefName);
     66            Logging.trace(e);
     67        }
     68    }
     69
     70    /**
     71     * Saves text from a {@link JTextField} to an integer preference.
     72     * @param prefName preference name
     73     * @param tf text field
     74     * @since 13050
     75     */
     76    protected static void saveInt(String prefName, JTextField tf) {
     77        String text = tf.getText();
     78        try {
     79            Config.getPref().putInt(prefName, Integer.parseInt(text));
     80        } catch (NumberFormatException e) {
     81            Logging.warn("Unable to save '" + text + "' as an integer value for preference " + prefName);
     82            Logging.trace(e);
     83        }
     84    }
    3685}
Note: See TracChangeset for help on using the changeset viewer.