From b5d572cbfb0613b7f3acae353716253866e2c846 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 2 Sep 2015 09:01:28 -0400 Subject: [PATCH] auto-sync --- java_console/ui/src/com/rusefi/Launcher.java | 2 +- .../ui/src/com/rusefi/ui/SensorLiveGraph.java | 48 ++++++++++++++++++- .../ui/src/com/rusefi/ui/storage/Node.java | 23 +++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index c8f3455a90..26228d8880 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see com.rusefi.StartupFrame */ public class Launcher { - public static final int CONSOLE_VERSION = 20150901; + public static final int CONSOLE_VERSION = 20150902; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; diff --git a/java_console/ui/src/com/rusefi/ui/SensorLiveGraph.java b/java_console/ui/src/com/rusefi/ui/SensorLiveGraph.java index a5ea81d36b..f4523103d3 100644 --- a/java_console/ui/src/com/rusefi/ui/SensorLiveGraph.java +++ b/java_console/ui/src/com/rusefi/ui/SensorLiveGraph.java @@ -22,6 +22,8 @@ public class SensorLiveGraph extends JPanel { private static final String SENSOR_TYPE = "sensor"; private static final String PERIOD = "period"; private static final String USE_AUTO_SCALE = "auto_scale"; + private static final String UPPER = "upper"; + private static final String LOWER = "lower"; private final LinkedList values = new LinkedList<>(); private final Node config; @@ -30,6 +32,8 @@ public class SensorLiveGraph extends JPanel { private ChangePeriod period = ChangePeriod._100; private Sensor sensor; private boolean autoScale; + private double customUpper; + private double customLower; public SensorLiveGraph(Node config, final Sensor defaultSensor, JMenuItem extraItem) { this.config = config; @@ -42,6 +46,8 @@ public class SensorLiveGraph extends JPanel { thread.start(); period = ChangePeriod.lookup(config.getProperty(PERIOD)); autoScale = config.getBoolProperty(USE_AUTO_SCALE); + customUpper = config.getDoubleProperty(UPPER, Double.NaN); + customLower = config.getDoubleProperty(LOWER, Double.NaN); MouseListener mouseListener = new MouseAdapter() { @Override @@ -89,6 +95,8 @@ public class SensorLiveGraph extends JPanel { addChangeSensorItems(pm); pm.add(new JSeparator()); addChangePeriodItems(pm); + JMenuItem scale = new JMenu("Scale"); + final JCheckBoxMenuItem as = new JCheckBoxMenuItem("Auto scale"); as.setSelected(autoScale); as.addActionListener(new ActionListener() { @@ -98,7 +106,42 @@ public class SensorLiveGraph extends JPanel { config.setBoolProperty(USE_AUTO_SCALE, autoScale); } }); - pm.add(as); + scale.add(as); + + final JCheckBoxMenuItem lowerValue = new JCheckBoxMenuItem("Use custom lower"); + lowerValue.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (lowerValue.isSelected()) { + String initial = Double.isNaN(customLower) ? "" : Double.toString(customLower); + String lower = JOptionPane.showInputDialog("Enter lower value", initial); + if (!Node.isNumeric(lower)) + return; + customLower = Double.parseDouble(lower); + config.setProperty(LOWER, customUpper); + } + } + }); + + final JCheckBoxMenuItem upperValue = new JCheckBoxMenuItem("Use custom upper"); + upperValue.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (upperValue.isSelected()) { + String initial = Double.isNaN(customUpper) ? "" : Double.toString(customUpper); + String upper = JOptionPane.showInputDialog("Enter upper value", initial); + if (!Node.isNumeric(upper)) + return; + customUpper = Double.parseDouble(upper); + config.setProperty(UPPER, customUpper); + } + } + }); + + scale.add(upperValue); + scale.add(lowerValue); + + pm.add(scale); pm.add(extraItem); pm.show(e.getComponent(), e.getX(), e.getY()); @@ -220,7 +263,8 @@ public class SensorLiveGraph extends JPanel { if (autoScale) { range = VisibleRange.findRange(values); } else { - range = new VisibleRange(sensor.getMinValue(), sensor.getMaxValue()); + range = new VisibleRange(Double.isNaN(customLower) ? sensor.getMinValue() : customLower, + Double.isNaN(customUpper) ? sensor.getMaxValue() : customUpper); } return range; } diff --git a/java_console/ui/src/com/rusefi/ui/storage/Node.java b/java_console/ui/src/com/rusefi/ui/storage/Node.java index b1c59054ef..39928e58aa 100644 --- a/java_console/ui/src/com/rusefi/ui/storage/Node.java +++ b/java_console/ui/src/com/rusefi/ui/storage/Node.java @@ -23,6 +23,16 @@ public class Node { } } + @SuppressWarnings("ResultOfMethodCallIgnored") + public static boolean isNumeric(String str) { + try { + Double.parseDouble(str); + } catch (NumberFormatException nfe) { + return false; + } + return true; + } + public Node getChild(String name) { Node child = (Node) config.get(name); if (child == null) { @@ -76,10 +86,14 @@ public class Node { return getProperty(key, ""); } + // this method is used by serializer + @SuppressWarnings("unused") public String getPrefix() { return prefix; } + // this method is used by serializer + @SuppressWarnings("unused") public void setPrefix(String prefix) { this.prefix = prefix; } @@ -102,4 +116,13 @@ public class Node { public void setProperty(String key, double value) { setProperty(key, Double.toString(value)); } + + public double getDoubleProperty(String key, double defaultValue) { + String value = getProperty(key); + if (isNumeric(value)) { + return Double.parseDouble(value); + } else { + return defaultValue; + } + } } \ No newline at end of file