auto-sync

This commit is contained in:
rusEfi 2015-08-22 00:01:32 -04:00
parent 28dc1610e0
commit ce5d013689
6 changed files with 62 additions and 55 deletions

View File

@ -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 = 20150714;
public static final int CONSOLE_VERSION = 20150820;
public static final boolean SHOW_STIMULATOR = false;
private static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port";

View File

@ -0,0 +1,16 @@
package com.rusefi.ui;
import com.rusefi.core.Sensor;
import com.rusefi.ui.widgets.SensorGauge;
import java.awt.*;
/**
* (c) Andrey Belomutskiy
* 8/21/2015.
*/
public class GaugesGridElement {
public static Component createGauge(Sensor sensor, SensorGauge.GaugeChangeListener gaugeChangeListener) {
return SensorGauge.createGauge(sensor, gaugeChangeListener);
}
}

View File

@ -18,6 +18,7 @@ import java.beans.PropertyChangeListener;
/**
* Date: 2/5/13
* (c) Andrey Belomutskiy
* @see SensorGauge
*/
public class GaugesPanel {
private static final Sensor[] DEFAULT_LAYOUT = {
@ -77,7 +78,7 @@ public class GaugesPanel {
int rows = config.getIntProperty(GAUGES_ROWS, SizeSelectorPanel.HEIGHT);
int columns = config.getIntProperty(GAUGES_COLUMNS, SizeSelectorPanel.WIDTH);
applySize(rows, columns);
setSensorGridDimensions(rows, columns);
middleSplitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, createMiddleLeftPanel(), messagesPanel);
@ -127,7 +128,7 @@ public class GaugesPanel {
@Override
public void onSelected(int row, int column) {
System.out.println("new size " + row + "/" + column);
applySize(row, column);
setSensorGridDimensions(row, column);
}
}));
@ -203,20 +204,15 @@ public class GaugesPanel {
return saveImageButton;
}
private void applySize(int rows, int columns) {
private void setSensorGridDimensions(int rows, int columns) {
gauges.setLayout(new GridLayout(rows, columns));
gauges.removeAll();
for (int i = 0; i < rows * columns; i++) {
String gaugeName = config.getProperty(getKey(i), DEFAULT_LAYOUT[i].name());
Sensor sensor;
try {
sensor = Sensor.valueOf(Sensor.class, gaugeName);
} catch (IllegalArgumentException e) {
sensor = DEFAULT_LAYOUT[i];
}
Sensor sensor = lookup(i, gaugeName);
final int currentGaugeIndex = i;
gauges.add(SensorGauge.createGauge(sensor, new SensorGauge.GaugeChangeListener() {
gauges.add(GaugesGridElement.createGauge(sensor, new SensorGauge.GaugeChangeListener() {
@Override
public void onSensorChange(Sensor sensor) {
config.setProperty(getKey(currentGaugeIndex), sensor.name());
@ -227,6 +223,16 @@ public class GaugesPanel {
saveConfig(rows, columns);
}
private Sensor lookup(int i, String gaugeName) {
Sensor sensor;
try {
sensor = Sensor.valueOf(Sensor.class, gaugeName);
} catch (IllegalArgumentException e) {
sensor = DEFAULT_LAYOUT[i];
}
return sensor;
}
@NotNull
private String getKey(int i) {
return "gauge_" + i;

View File

@ -10,8 +10,11 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.Arrays;
import java.util.Collection;
import java.util.Hashtable;
/**
* (c) Andrey Belomutskiy
@ -21,6 +24,17 @@ public class DetachedSensor {
private static final Collection<Sensor> MOCKABLE = Arrays.asList(Sensor.CLT, Sensor.AFR, Sensor.IAT, Sensor.MAF,
Sensor.TPS);
private final static Hashtable<Integer, JComponent> SLIDER_LABELS = new Hashtable<>();
static {
Format f = new DecimalFormat("0.0");
for (int i = 0; i <= 50; i += 5) {
JLabel label = new JLabel(f.format(i * 0.1));
label.setFont(label.getFont().deriveFont(Font.PLAIN));
SLIDER_LABELS.put(i, label);
}
}
/**
* We need to trick the JSlider into displaying float values
*/
@ -72,7 +86,7 @@ public class DetachedSensor {
/**
*/
final JSlider slider = new JSlider(0, _5_VOLTS_WITH_DECIMAL);
slider.setLabelTable(SensorGauge.SLIDER_LABELS);
slider.setLabelTable(SLIDER_LABELS);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(10);

View File

@ -1,15 +0,0 @@
package com.rusefi.ui.widgets;
import com.rusefi.core.Sensor;
/**
* 7/13/13
* (c) Andrey Belomutskiy
*/
public class InjectorControl extends BooleanFlagControlPanel {
public InjectorControl(int id, Sensor sensor) {
super("Injector " + id, "");
installStatusReader(sensor);
installCommand("injector " + id + " ");
}
}

View File

@ -3,29 +3,24 @@ package com.rusefi.ui.widgets;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCategory;
import com.rusefi.core.SensorCentral;
import com.rusefi.ui.GaugesPanel;
import com.rusefi.ui.util.UiUtils;
import eu.hansolo.steelseries.gauges.Radial;
import eu.hansolo.steelseries.tools.ColorDef;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.Hashtable;
import java.awt.event.*;
/**
* Date: 7/9/14
* (c) Andrey Belomutskiy 2012-2014
* @see GaugesPanel
*/
public class SensorGauge {
public static Component createGauge(final Sensor sensor) {
return createGauge(sensor, GaugeChangeListener.VOID);
}
private static final String HINT_LINE_1 = "Double-click to detach";
private static final String HINT_LINE_2 = "Right-click to change";
public static Component createGauge(Sensor sensor, GaugeChangeListener listener) {
JPanelWithListener wrapper = new JPanelWithListener(new BorderLayout());
@ -54,7 +49,8 @@ public class SensorGauge {
private static void createGaugeBody(final Sensor sensor, final JPanelWithListener wrapper, final GaugeChangeListener listener) {
final Radial gauge = createRadial(sensor.getName(), sensor.getUnits(), sensor.getMaxValue(), sensor.getMinValue());
UiUtils.setTwoLineToolTip(gauge, "Double-click to detach", "Right-click to change");
UiUtils.setTwoLineToolTip(gauge, HINT_LINE_1, HINT_LINE_2);
UiUtils.setTwoLineToolTip(wrapper, HINT_LINE_1, HINT_LINE_2);
gauge.setBackgroundColor(sensor.getColor());
@ -66,7 +62,7 @@ public class SensorGauge {
gauge.setValue(sensor.translateValue(SensorCentral.getInstance().getValue(sensor)));
gauge.setLcdDecimals(2);
gauge.addMouseListener(new MouseAdapter() {
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
@ -75,7 +71,10 @@ public class SensorGauge {
handleDoubleClick(e, gauge, sensor);
}
}
});
};
gauge.addMouseListener(mouseListener);
wrapper.removeAllMouseListeners();
wrapper.addMouseListener(mouseListener);
wrapper.removeAll();
wrapper.add(gauge, BorderLayout.CENTER);
UiUtils.trueRepaint(wrapper.getParent());
@ -84,11 +83,11 @@ public class SensorGauge {
private static void showPopupMenu(MouseEvent e, JPanelWithListener wrapper, GaugeChangeListener listener) {
JPopupMenu pm = new JPopupMenu();
fillGaugeItems(pm, wrapper, listener);
fillGaugeMenuItems(pm, wrapper, listener);
pm.show(e.getComponent(), e.getX(), e.getY());
}
private static void fillGaugeItems(JPopupMenu popupMenu, final JPanelWithListener wrapper, final GaugeChangeListener listener) {
private static void fillGaugeMenuItems(JPopupMenu popupMenu, final JPanelWithListener wrapper, final GaugeChangeListener listener) {
for (final SensorCategory sc : SensorCategory.values()) {
JMenuItem cmi = new JMenu(sc.getName());
popupMenu.add(cmi);
@ -120,23 +119,10 @@ public class SensorGauge {
ds.content.add(createGauge(sensor, listener), BorderLayout.CENTER);
ds.content.add(ds.mockControlPanel, BorderLayout.SOUTH);
ds.frame.add(ds.content);
ds.show(e);
}
final static Hashtable<Integer, JComponent> SLIDER_LABELS = new Hashtable<>();
static {
Format f = new DecimalFormat("0.0");
for (int i = 0; i <= 50; i += 5) {
JLabel label = new JLabel(f.format(i * 0.1));
label.setFont(label.getFont().deriveFont(Font.PLAIN));
SLIDER_LABELS.put(i, label);
}
}
public static Radial createRadial(String title, String units, double maxValue, double minValue) {
// final Section[] SECTIONS =
// {