import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
+import java.text.*;
import android.app.Activity;
import android.app.PendingIntent;
void setFrequency(String freq) {
try {
- setFrequency (Double.parseDouble(freq.substring(11, 17)));
- } catch (NumberFormatException e) {
+ setFrequency (AltosParse.parse_double_net(freq.substring(11, 17)));
+ } catch (ParseException e) {
}
}
lon = AltosParse.parse_coord(words[i++]);
alt = AltosParse.parse_int(words[i++]);
if (version > 1 || (i < words.length && !words[i].equals("SAT"))) {
- ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)"));
+ ground_speed = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "m/s(H)"));
course = AltosParse.parse_int(words[i++]);
- climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)"));
- hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)"));
+ climb_rate = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "m/s(V)"));
+ hdop = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "(hdop)"));
h_error = AltosParse.parse_int(words[i++]);
v_error = AltosParse.parse_int(words[i++]);
}
package org.altusmetrum.altoslib_6;
+import java.util.*;
import java.text.*;
public class AltosParse {
}
}
- public static double parse_double(String v) throws ParseException {
+ static NumberFormat nf_locale = NumberFormat.getInstance();
+
+ static NumberFormat nf_net = NumberFormat.getInstance(Locale.ROOT);
+
+ public static double parse_double_locale(String str) throws ParseException {
try {
- return Double.parseDouble(v);
- } catch (NumberFormatException e) {
- throw new ParseException("error parsing double " + v, 0);
+ return nf_locale.parse(str.trim()).doubleValue();
+ } catch (ParseException pe) {
+ throw new ParseException("error parsing double " + str, 0);
+ }
+ }
+
+ public static double parse_double_net(String str) throws ParseException {
+ try {
+ return nf_net.parse(str.trim()).doubleValue();
+ } catch (ParseException pe) {
+ throw new ParseException("error parsing double " + str, 0);
}
}
package org.altusmetrum.altoslib_6;
+import java.text.*;
+
public abstract class AltosUnits {
public abstract double value(double v, boolean imperial_units);
public abstract int show_fraction(int width, boolean imperial_units);
- public double parse(String s, boolean imperial_units) throws NumberFormatException {
- double v = Double.parseDouble(s);
+ public double parse_locale(String s, boolean imperial_units) throws ParseException {
+ double v = AltosParse.parse_double_locale(s);
+ return inverse(v, imperial_units);
+ }
+
+ public double parse_net(String s, boolean imperial_units) throws ParseException {
+ double v = AltosParse.parse_double_net(s);
return inverse(v, imperial_units);
}
- public double parse(String s) throws NumberFormatException {
- return parse(s, AltosConvert.imperial_units);
+ public double parse_locale(String s) throws ParseException {
+ return parse_locale(s, AltosConvert.imperial_units);
+ }
+
+ public double parse_net(String s) throws ParseException {
+ return parse_net(s, AltosConvert.imperial_units);
}
public double value(double v) {
public String say_units(double v) {
return say_units(v, AltosConvert.imperial_units);
}
-}
\ No newline at end of file
+}
package altosui;
+import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
if (units != null) {
try {
- double v = units.parse(value.getText(), !imperial_units);
+ double v = units.parse_locale(value.getText(), !imperial_units);
set(enabled(), v);
- } catch (NumberFormatException ne) {
+ } catch (ParseException pe) {
set(enabled(), 0.0);
}
}
AltosUnits units = AltosPyro.pyro_to_units(flag);
try {
if (units != null)
- return units.parse(value.getText());
- return Double.parseDouble(value.getText());
- } catch (NumberFormatException e) {
+ return units.parse_locale(value.getText());
+ return AltosParse.parse_double_locale(value.getText());
+ } catch (ParseException e) {
throw new AltosConfigDataException("\"%s\": %s\n", value.getText(), e.getMessage());
}
}
String v = pyro_firing_time_value.getSelectedItem().toString();
try {
- return Double.parseDouble(v);
- } catch (NumberFormatException e) {
+ return AltosParse.parse_double_locale(v);
+ } catch (ParseException e) {
throw new AltosConfigDataException("Invalid pyro firing time \"%s\"", v);
}
}
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
+import java.text.*;
import org.altusmetrum.altoslib_6.*;
import org.altusmetrum.altosuilib_6.*;
}
- public int main_deploy() {
- return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
+ public int main_deploy() throws AltosConfigDataException {
+ String str = main_deploy_value.getSelectedItem().toString();
+ try {
+ return (int) (AltosConvert.height.parse_locale(str) + 0.5);
+ } catch (ParseException pe) {
+ throw new AltosConfigDataException("invalid main deploy height %s", str);
+ }
}
String get_main_deploy_label() {
String v = main_deploy_value.getSelectedItem().toString();
main_deploy_label.setText(get_main_deploy_label());
set_main_deploy_values();
- int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
- set_main_deploy(m);
+ try {
+ int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
+ set_main_deploy(m);
+ } catch (ParseException pe) {
+ }
if (tracker_motion_value.isEnabled()) {
String motion = tracker_motion_value.getSelectedItem().toString();
tracker_motion_label.setText(get_tracker_motion_label());
set_tracker_motion_values();
- set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
+ try {
+ int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
+ set_tracker_motion(m);
+ } catch (ParseException pe) {
+ }
}
if (!was_dirty)
}
public int tracker_motion() throws AltosConfigDataException {
- return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
+ String str = tracker_motion_value.getSelectedItem().toString();
+ try {
+ return (int) (AltosConvert.height.parse_locale(str) + 0.5);
+ } catch (ParseException pe) {
+ throw new AltosConfigDataException("invalid tracker motion %s", str);
+ }
}
public void set_tracker_interval(int tracker_interval) {
package org.altusmetrum.altosuilib_6;
import java.awt.*;
+import java.text.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
String d_s = description.getText();
try {
- double f_d = Double.parseDouble(f_s);
+ double f_d = AltosParse.parse_double_locale(f_s);
return new AltosFrequency(f_d, d_s);
- } catch (NumberFormatException ne) {
+ } catch (ParseException ne) {
}
return null;
}
hemi.setSelectedIndex(h);
}
- public double get_value() throws NumberFormatException {
+ public double get_value() throws ParseException {
int h = hemi.getSelectedIndex();
String d_t = deg.getText();
String m_t = min.getText();
double d, m, v;
try {
- d = Double.parseDouble(d_t);
- } catch (NumberFormatException ne) {
+ d = AltosParse.parse_double_locale(d_t);
+ } catch (ParseException pe) {
JOptionPane.showMessageDialog(owner,
String.format("Invalid degrees \"%s\"",
d_t),
"Invalid number",
JOptionPane.ERROR_MESSAGE);
- throw ne;
+ throw pe;
}
try {
if (m_t.equals(""))
m = 0;
else
- m = Double.parseDouble(m_t);
- } catch (NumberFormatException ne) {
+ m = AltosParse.parse_double_locale(m_t);
+ } catch (ParseException pe) {
JOptionPane.showMessageDialog(owner,
String.format("Invalid minutes \"%s\"",
m_t),
"Invalid number",
JOptionPane.ERROR_MESSAGE);
- throw ne;
+ throw pe;
}
v = d + m/60.0;
if (h == 1)
name = elements[0];
try {
- latitude = Double.parseDouble(elements[1]);
- longitude = Double.parseDouble(elements[2]);
- } catch (NumberFormatException ne) {
+ latitude = AltosParse.parse_double_net(elements[1]);
+ longitude = AltosParse.parse_double_net(elements[2]);
+ } catch (ParseException pe) {
throw new ParseException(String.format("Invalid site line %s", line), 0);
}
}
try {
add(new AltosUISite(line));
} catch (ParseException pe) {
+ System.out.printf("parse exception %s\n", pe.toString());
}
}
max_z = min_z;
r = (Integer) radius.getSelectedItem();
loading = true;
- } catch (NumberFormatException ne) {
+ } catch (ParseException pe) {
load_button.setSelected(false);
}
start_load();
import java.io.*;
import java.util.concurrent.*;
import java.util.*;
+import java.text.*;
import org.altusmetrum.altoslib_6.*;
import org.altusmetrum.altosuilib_6.*;
if (args.length < i + 3) {
help(1);
} else {
- double lat = Double.parseDouble(args[i+1]);
- double lon = Double.parseDouble(args[i+2]);
+ try {
+ double lat = AltosParse.parse_double_locale(args[i+1]);
+ double lon = AltosParse.parse_double_locale(args[i+2]);
AltosUIMap.prefetch_maps(lat, lon);
+ } catch (ParseException e) {
+ System.out.printf("Can't parse number %s\n", e.toString());
+ }
i += 2;
}
} else if (args[i].equals("--replay"))
package org.altusmetrum.telegps;
+import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
String motion = tracker_motion_value.getSelectedItem().toString();
tracker_motion_label.setText(get_tracker_motion_label());
set_tracker_motion_values();
- set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
+ try {
+ int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
+ set_tracker_motion(m);
+ } catch (ParseException pe) {
+ }
}
if (!was_dirty)
set_clean();
}
public int tracker_motion() throws AltosConfigDataException {
- return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
+ String str = tracker_motion_value.getSelectedItem().toString();
+ try {
+ return (int) (AltosConvert.height.parse_locale(str) + 0.5);
+ } catch (ParseException pe) {
+ throw new AltosConfigDataException("invalid tracker motion %s", str);
+ }
}
public void set_tracker_interval(int tracker_interval) {