Changeset 13050 in josm
- Timestamp:
- 2017-10-29T14:57:41+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r13047 r13050 39 39 import org.openstreetmap.josm.tools.GBC; 40 40 import org.openstreetmap.josm.tools.ImageProvider; 41 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 41 42 import org.openstreetmap.josm.tools.Logging; 42 43 … … 263 264 if (layer != null && semicolon >= 0 && semicolon + 1 < ostr.length()) { 264 265 try { 265 // here we assume that Double.parseDouble() needs '.' as a decimal separator 266 String easting = ostr.substring(0, semicolon).trim().replace(',', '.'); 267 String northing = ostr.substring(semicolon + 1).trim().replace(',', '.'); 268 double dx = Double.parseDouble(easting); 269 double dy = Double.parseDouble(northing); 266 String easting = ostr.substring(0, semicolon).trim(); 267 String northing = ostr.substring(semicolon + 1).trim(); 268 double dx = JosmDecimalFormatSymbolsProvider.parseDouble(easting); 269 double dy = JosmDecimalFormatSymbolsProvider.parseDouble(northing); 270 270 tempOffset.setDisplacement(new EastNorth(dx, dy)); 271 271 layer.getDisplaySettings().setOffsetBookmark(tempOffset); -
trunk/src/org/openstreetmap/josm/gui/DownloadParamType.java
r12633 r13050 78 78 * Download area specified on the command line as bounds string. 79 79 * @param rawGps Flag to download raw GPS tracks 80 * @param s The bounds parameter 80 * @param s The bounds parameter. Coordinates must use dot decimal separator as comma is used to delimit values 81 81 * @return the complete download task (including post-download handler), or {@code null} 82 82 */ -
trunk/src/org/openstreetmap/josm/gui/dialogs/LatLonDialog.java
r12938 r13050 358 358 /** 359 359 * Parses a east/north coordinate string 360 * @param s The coordinates 360 * @param s The coordinates. Dot has to be used as decimal separator, as comma can be used to delimit values 361 361 * @return The east/north coordinates or <code>null</code> on error. 362 362 */ -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r12735 r13050 30 30 import org.openstreetmap.josm.gui.widgets.JosmTextField; 31 31 import org.openstreetmap.josm.tools.GBC; 32 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 33 import org.openstreetmap.josm.tools.Logging; 32 34 import org.openstreetmap.josm.tools.OsmUrlToBounds; 33 35 … … 140 142 for (int i = 0; i < 4; i++) { 141 143 try { 142 values[i] = Double.parseDouble(latlon[i].getText());144 values[i] = JosmDecimalFormatSymbolsProvider.parseDouble(latlon[i].getText()); 143 145 } catch (NumberFormatException ex) { 144 146 return null; … … 199 201 double value = 0; 200 202 try { 201 value = Double.parseDouble(tfLatValue.getText());203 value = JosmDecimalFormatSymbolsProvider.parseDouble(tfLatValue.getText()); 202 204 } catch (NumberFormatException ex) { 203 205 setErrorMessage(tfLatValue, tr("The string ''{0}'' is not a valid double value.", tfLatValue.getText())); … … 232 234 double value = 0; 233 235 try { 234 value = Double.parseDouble(tfLonValue.getText());236 value = JosmDecimalFormatSymbolsProvider.parseDouble(tfLonValue.getText()); 235 237 } catch (NumberFormatException ex) { 236 238 setErrorMessage(tfLonValue, tr("The string ''{0}'' is not a valid double value.", tfLonValue.getText())); … … 289 291 double minlon, minlat, maxlon, maxlat; 290 292 try { 291 minlat = Double.parseDouble(latlon[0].getText().trim());292 minlon = Double.parseDouble(latlon[1].getText().trim());293 maxlat = Double.parseDouble(latlon[2].getText().trim());294 maxlon = Double.parseDouble(latlon[3].getText().trim());293 minlat = JosmDecimalFormatSymbolsProvider.parseDouble(latlon[0].getText().trim()); 294 minlon = JosmDecimalFormatSymbolsProvider.parseDouble(latlon[1].getText().trim()); 295 maxlat = JosmDecimalFormatSymbolsProvider.parseDouble(latlon[2].getText().trim()); 296 maxlon = JosmDecimalFormatSymbolsProvider.parseDouble(latlon[3].getText().trim()); 295 297 } catch (NumberFormatException e) { 298 Logging.trace(e); 296 299 return null; 297 300 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/Offset.java
r11971 r13050 9 9 import java.util.concurrent.TimeUnit; 10 10 11 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 11 12 import org.openstreetmap.josm.tools.Pair; 12 13 … … 58 59 offset = offset.substring(1); 59 60 } 60 return Offset.milliseconds(Math.round( Double.parseDouble(offset) * 1000));61 return Offset.milliseconds(Math.round(JosmDecimalFormatSymbolsProvider.parseDouble(offset) * 1000)); 61 62 } catch (NumberFormatException nfe) { 62 63 throw (ParseException) new ParseException(error, 0).initCause(nfe); -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java
r13021 r13050 21 21 import org.openstreetmap.gui.jmapviewer.OsmMercator; 22 22 import org.openstreetmap.josm.CLIModule; 23 import org.openstreetmap.josm.tools.I18n;24 23 import org.openstreetmap.josm.Main; 25 24 import org.openstreetmap.josm.data.Bounds; … … 37 36 import org.openstreetmap.josm.spi.preferences.Config; 38 37 import org.openstreetmap.josm.spi.preferences.MemoryPreferences; 38 import org.openstreetmap.josm.tools.I18n; 39 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 39 40 import org.openstreetmap.josm.tools.Logging; 40 41 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; … … 263 264 case SCALE: 264 265 try { 265 argScale = Double.parseDouble(getopt.getOptarg());266 argScale = JosmDecimalFormatSymbolsProvider.parseDouble(getopt.getOptarg()); 266 267 } catch (NumberFormatException nfe) { 267 268 throw new IllegalArgumentException( … … 285 286 case WIDTH_M: 286 287 try { 287 argWidthM = Double.parseDouble(getopt.getOptarg());288 argWidthM = JosmDecimalFormatSymbolsProvider.parseDouble(getopt.getOptarg()); 288 289 } catch (NumberFormatException nfe) { 289 290 throw new IllegalArgumentException( … … 295 296 case HEIGHT_M: 296 297 try { 297 argHeightM = Double.parseDouble(getopt.getOptarg());298 argHeightM = JosmDecimalFormatSymbolsProvider.parseDouble(getopt.getOptarg()); 298 299 } catch (NumberFormatException nfe) { 299 300 throw new IllegalArgumentException( -
trunk/src/org/openstreetmap/josm/gui/preferences/DefaultPreferenceSetting.java
r12460 r13050 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.preferences; 3 4 import javax.swing.JCheckBox; 5 import javax.swing.JTextField; 6 7 import org.openstreetmap.josm.spi.preferences.Config; 8 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 9 import org.openstreetmap.josm.tools.Logging; 3 10 4 11 /** 5 12 * Abstract base class for {@link PreferenceSetting} implementations. 6 13 * 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 9 16 */ 10 17 public abstract class DefaultPreferenceSetting implements PreferenceSetting { … … 34 41 return isExpert; 35 42 } 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 } 36 85 } -
trunk/src/org/openstreetmap/josm/gui/preferences/audio/AudioPreference.java
r12846 r13050 134 134 public boolean ok() { 135 135 Config.getPref().putBoolean("audio.menuinvisible", !audioMenuVisible.isSelected()); 136 Config.getPref().putBoolean("marker.traceaudio", markerAudioTraceVisible.isSelected());137 Config.getPref().putBoolean("marker.buttonlabels", markerButtonLabels.isSelected());138 Config.getPref().putBoolean("marker.audiofromexplicitwaypoints", audioMarkersFromExplicitWaypoints.isSelected());139 Config.getPref().putBoolean("marker.audiofromuntimedwaypoints", audioMarkersFromUntimedWaypoints.isSelected());140 Config.getPref().putBoolean("marker.audiofromnamedtrackpoints", audioMarkersFromNamedTrackpoints.isSelected());141 Config.getPref().putBoolean("marker.audiofromwavtimestamps", audioMarkersFromWavTimestamps.isSelected());142 Config.getPref().putBoolean("marker.audiofromstart", audioMarkersFromStart.isSelected());143 Config.getPref().put("audio.forwardbackamount", audioForwardBackAmount.getText());144 Config.getPref().put("audio.fastfwdmultiplier", audioFastForwardMultiplier.getText());145 Config.getPref().put("audio.leadin", audioLeadIn.getText());146 Config.getPref().put("audio.calibration", audioCalibration.getText());136 saveBoolean("marker.traceaudio", markerAudioTraceVisible); 137 saveBoolean("marker.buttonlabels", markerButtonLabels); 138 saveBoolean("marker.audiofromexplicitwaypoints", audioMarkersFromExplicitWaypoints); 139 saveBoolean("marker.audiofromuntimedwaypoints", audioMarkersFromUntimedWaypoints); 140 saveBoolean("marker.audiofromnamedtrackpoints", audioMarkersFromNamedTrackpoints); 141 saveBoolean("marker.audiofromwavtimestamps", audioMarkersFromWavTimestamps); 142 saveBoolean("marker.audiofromstart", audioMarkersFromStart); 143 saveDouble("audio.forwardbackamount", audioForwardBackAmount); 144 saveDouble("audio.fastfwdmultiplier", audioFastForwardMultiplier); 145 saveDouble("audio.leadin", audioLeadIn); 146 saveDouble("audio.calibration", audioCalibration); 147 147 return false; 148 148 } -
trunk/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java
r12735 r13050 20 20 import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat; 21 21 import org.openstreetmap.josm.tools.GBC; 22 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 23 import org.openstreetmap.josm.tools.Logging; 22 24 import org.openstreetmap.josm.tools.OsmUrlToBounds; 23 25 … … 99 101 double minlon, minlat, maxlon, maxlat; 100 102 try { 101 minlat = Double.parseDouble(tfLatLon[0].getText().trim());102 minlon = Double.parseDouble(tfLatLon[1].getText().trim());103 maxlat = Double.parseDouble(tfLatLon[2].getText().trim());104 maxlon = Double.parseDouble(tfLatLon[3].getText().trim());103 minlat = JosmDecimalFormatSymbolsProvider.parseDouble(tfLatLon[0].getText().trim()); 104 minlon = JosmDecimalFormatSymbolsProvider.parseDouble(tfLatLon[1].getText().trim()); 105 maxlat = JosmDecimalFormatSymbolsProvider.parseDouble(tfLatLon[2].getText().trim()); 106 maxlon = JosmDecimalFormatSymbolsProvider.parseDouble(tfLatLon[3].getText().trim()); 105 107 } catch (NumberFormatException e) { 108 Logging.trace(e); 106 109 return null; 107 110 } 108 111 if (!LatLon.isValidLon(minlon) || !LatLon.isValidLon(maxlon) 109 112 || !LatLon.isValidLat(minlat) || !LatLon.isValidLat(maxlat)) 110 113 return null; 111 114 if (minlon > maxlon) … … 145 148 double value = 0; 146 149 try { 147 value = Double.parseDouble(getComponent().getText());150 value = JosmDecimalFormatSymbolsProvider.parseDouble(getComponent().getText()); 148 151 } catch (NumberFormatException ex) { 149 152 feedbackInvalid(tr("The string ''{0}'' is not a valid double value.", getComponent().getText())); 153 Logging.trace(ex); 150 154 return; 151 155 } … … 160 164 public boolean isValid() { 161 165 try { 162 return LatLon.isValidLat(Double.parseDouble(getComponent().getText())); 163 } catch (NumberFormatException ex) { 166 return LatLon.isValidLat(JosmDecimalFormatSymbolsProvider.parseDouble(getComponent().getText())); 167 } catch (NumberFormatException ex) { 168 Logging.trace(ex); 164 169 return false; 165 170 } … … 181 186 double value = 0; 182 187 try { 183 value = Double.parseDouble(getComponent().getText());188 value = JosmDecimalFormatSymbolsProvider.parseDouble(getComponent().getText()); 184 189 } catch (NumberFormatException ex) { 185 190 feedbackInvalid(tr("The string ''{0}'' is not a valid double value.", getComponent().getText())); 191 Logging.trace(ex); 186 192 return; 187 193 } … … 196 202 public boolean isValid() { 197 203 try { 198 return LatLon.isValidLon(Double.parseDouble(getComponent().getText())); 199 } catch (NumberFormatException ex) { 204 return LatLon.isValidLon(JosmDecimalFormatSymbolsProvider.parseDouble(getComponent().getText())); 205 } catch (NumberFormatException ex) { 206 Logging.trace(ex); 200 207 return false; 201 208 } -
trunk/src/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProvider.java
r12931 r13050 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.text.DecimalFormat; 4 5 import java.text.DecimalFormatSymbols; 6 import java.text.NumberFormat; 5 7 import java.text.spi.DecimalFormatSymbolsProvider; 6 8 import java.util.Locale; … … 28 30 return I18n.getAvailableTranslations(); 29 31 } 32 33 /** 34 * Returns a new {@code double} initialized to the value represented by the specified {@code String}, 35 * allowing both dot and comma decimal separators. 36 * 37 * @param s the string to be parsed. 38 * @return the {@code double} value represented by the string argument. 39 * @throws NullPointerException if the string is null 40 * @throws NumberFormatException if the string does not contain a parsable {@code double}. 41 * @see Double#parseDouble(String) 42 * @since 13050 43 */ 44 public static double parseDouble(String s) throws NumberFormatException { 45 String text = s; 46 NumberFormat format = DecimalFormat.getInstance(); 47 if (format instanceof DecimalFormat) { 48 char decimalSeparator = ((DecimalFormat) format).getDecimalFormatSymbols().getDecimalSeparator(); 49 text = text.replace('.', decimalSeparator).replace(',', decimalSeparator); 50 } 51 return Double.parseDouble(text); 52 } 30 53 }
Note:
See TracChangeset
for help on using the changeset viewer.