auto-sync
This commit is contained in:
parent
fc0f93db5b
commit
5e470ba07d
|
@ -38,7 +38,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
|||
* @see EngineSnifferPanel
|
||||
*/
|
||||
public class Launcher {
|
||||
public static final int CONSOLE_VERSION = 20160820;
|
||||
public static final int CONSOLE_VERSION = 20160821;
|
||||
public static final boolean SHOW_STIMULATOR = false;
|
||||
private static final String TAB_INDEX = "main_tab";
|
||||
protected static final String PORT_KEY = "port";
|
||||
|
@ -136,6 +136,9 @@ public class Launcher {
|
|||
|
||||
ConnectionWatchdog.start();
|
||||
|
||||
|
||||
GaugesPanel.DetachedRepository.INSTANCE.init(getConfig().getRoot().getChild("detached"));
|
||||
GaugesPanel.DetachedRepository.INSTANCE.load();
|
||||
if (!LinkManager.isLogViewer())
|
||||
tabbedPane.addTab("Gauges", new GaugesPanel(getConfig().getRoot().getChild("gauges")).getContent());
|
||||
|
||||
|
@ -237,6 +240,7 @@ public class Launcher {
|
|||
Node root = getConfig().getRoot();
|
||||
root.setProperty("version", CONSOLE_VERSION);
|
||||
root.setProperty(TAB_INDEX, tabbedPane.getSelectedIndex());
|
||||
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
||||
getConfig().save();
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
if (bp != null && !bp.isClosed)
|
||||
|
|
|
@ -12,4 +12,9 @@ public class GaugesGrid {
|
|||
public GaugesGrid(int rows, int cols) {
|
||||
panel = new JPanel(new GridLayout(rows, cols));
|
||||
}
|
||||
|
||||
public void setLayout(int rows, int columns) {
|
||||
panel.setLayout(new GridLayout(rows, columns));
|
||||
panel.removeAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.core.Sensor;
|
|||
import com.rusefi.ui.storage.Node;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import com.rusefi.ui.widgets.AnyCommand;
|
||||
import com.rusefi.ui.widgets.DetachedSensor;
|
||||
import com.rusefi.ui.widgets.PopupMenuButton;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -14,10 +15,13 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Date: 2/5/13
|
||||
* (c) Andrey Belomutskiy
|
||||
*
|
||||
* @see GaugesGridElement
|
||||
*/
|
||||
public class GaugesPanel {
|
||||
|
@ -58,7 +62,7 @@ public class GaugesPanel {
|
|||
}
|
||||
|
||||
private final JPanel content = new JPanel(new BorderLayout());
|
||||
private final GaugesGrid gauges = new GaugesGrid(3, 5);
|
||||
private final GaugesGrid gauges;
|
||||
private final Node config;
|
||||
|
||||
private boolean showRpmPanel = true;
|
||||
|
@ -71,6 +75,7 @@ public class GaugesPanel {
|
|||
private final JSplitPane middleSplitPanel;
|
||||
|
||||
public GaugesPanel(final Node config) {
|
||||
gauges = new GaugesGrid(3, 5);
|
||||
this.config = config;
|
||||
showRpmPanel = config.getBoolProperty(SHOW_RPM, true);
|
||||
showMessagesPanel = config.getBoolProperty(SHOW_MESSAGES, true);
|
||||
|
@ -224,8 +229,7 @@ public class GaugesPanel {
|
|||
}
|
||||
|
||||
private void setSensorGridDimensions(int rows, int columns) {
|
||||
gauges.panel.setLayout(new GridLayout(rows, columns));
|
||||
gauges.panel.removeAll();
|
||||
gauges.setLayout(rows, columns);
|
||||
|
||||
for (int i = 0; i < rows * columns; i++) {
|
||||
Component element = GaugesGridElement.read(config.getChild("element_" + i), DEFAULT_LAYOUT[i]);
|
||||
|
@ -249,4 +253,42 @@ public class GaugesPanel {
|
|||
public JComponent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public enum DetachedRepository {
|
||||
INSTANCE;
|
||||
|
||||
public static final String COUNT = "count";
|
||||
public static final String DETACHED = "detached";
|
||||
private List<DetachedSensor> list = new ArrayList<>();
|
||||
private Node config;
|
||||
|
||||
public void add(DetachedSensor detachedSensor) {
|
||||
list.add(detachedSensor);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void remove(DetachedSensor detachedSensor) {
|
||||
list.remove(detachedSensor);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
int count = config.getIntProperty(COUNT, 0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
DetachedSensor.create(config.getChild(DETACHED + i));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
config.setProperty(COUNT, list.size());
|
||||
int index = 0;
|
||||
for (DetachedSensor sensor : list) {
|
||||
sensor.saveConfig(config.getChild(DETACHED + index++));
|
||||
}
|
||||
}
|
||||
|
||||
public void init(Node config) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.rusefi.ui.widgets;
|
|||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.GaugesPanel;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -10,6 +12,8 @@ import javax.swing.event.ChangeEvent;
|
|||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
import java.util.Arrays;
|
||||
|
@ -21,10 +25,14 @@ import java.util.Hashtable;
|
|||
* 11/2/14
|
||||
*/
|
||||
public class DetachedSensor {
|
||||
private static final String NAME = "name";
|
||||
private static final String WIDTH = "width";
|
||||
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<>();
|
||||
public static final String XPOS = "xpos";
|
||||
public static final String YPOS = "ypos";
|
||||
|
||||
static {
|
||||
Format f = new DecimalFormat("0.0");
|
||||
|
@ -47,14 +55,24 @@ public class DetachedSensor {
|
|||
private int width;
|
||||
|
||||
public DetachedSensor(Sensor sensor, int width) {
|
||||
this.sensor = sensor;
|
||||
this.width = width;
|
||||
frame = new JFrame();
|
||||
frame.setAlwaysOnTop(true);
|
||||
onChange(sensor);
|
||||
|
||||
GaugesPanel.DetachedRepository.INSTANCE.add(this);
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
GaugesPanel.DetachedRepository.INSTANCE.remove(DetachedSensor.this);
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
create();
|
||||
}
|
||||
|
||||
void create(Sensor sensor) {
|
||||
void create() {
|
||||
SensorGauge.GaugeChangeListener listener = new SensorGauge.GaugeChangeListener() {
|
||||
@Override
|
||||
public void onSensorChange(Sensor sensor) {
|
||||
|
@ -115,4 +133,21 @@ public class DetachedSensor {
|
|||
|
||||
return slider;
|
||||
}
|
||||
|
||||
public void saveConfig(Node child) {
|
||||
child.setProperty(NAME, sensor.name());
|
||||
child.setProperty(WIDTH, frame.getWidth());
|
||||
child.setProperty(XPOS, frame.getLocation().x);
|
||||
child.setProperty(YPOS, frame.getLocation().y);
|
||||
}
|
||||
|
||||
public static void create(Node child) {
|
||||
Sensor sensor = Sensor.lookup(child.getProperty(NAME, Sensor.RPM.name()), Sensor.RPM);
|
||||
int width = child.getIntProperty(WIDTH, 256);
|
||||
int xpos = child.getIntProperty(XPOS, 0);
|
||||
int ypos = child.getIntProperty(YPOS, 0);
|
||||
DetachedSensor ds = new DetachedSensor(sensor, width);
|
||||
ds.frame.setLocation(xpos, ypos);
|
||||
ds.frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,6 @@ public class SensorGauge {
|
|||
int width = gauge.getSize().width;
|
||||
final DetachedSensor ds = new DetachedSensor(sensor, width);
|
||||
|
||||
ds.create(sensor);
|
||||
ds.show(e);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue