console refactoring & better defaults L&F

This commit is contained in:
rusefi 2020-05-01 11:57:41 -04:00
parent 08ffcd9e46
commit aa2e50f782
15 changed files with 259 additions and 204 deletions

View File

@ -6,7 +6,6 @@ import com.opensr5.io.DataListener;
import com.rusefi.ConfigurationImageDiff;
import com.rusefi.FileLog;
import com.rusefi.Timeouts;
import com.rusefi.config.FieldType;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.Pair;
import com.rusefi.core.Sensor;
@ -232,14 +231,14 @@ public class BinaryProtocol implements BinaryProtocolCommands {
continue;
}
ConnectionStatus.INSTANCE.markConnected();
ConnectionStatusLogic.INSTANCE.markConnected();
System.arraycopy(response, 1, image.getContent(), offset, requestSize);
offset += requestSize;
}
setController(image);
logger.info("Got configuration from controller.");
ConnectionStatus.INSTANCE.setValue(ConnectionStatus.Value.CONNECTED);
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.CONNECTED);
}
/**

View File

@ -17,9 +17,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
* todo: eliminate logic duplication with {@link ConnectionWatchdog}
*/
public class ConnectionStatus {
public class ConnectionStatusLogic {
@NotNull
private Value value = Value.NOT_CONNECTED;
private ConnectionStatusValue value = ConnectionStatusValue.NOT_CONNECTED;
public void executeOnceConnected(Runnable r) {
/*
@ -29,19 +29,13 @@ public class ConnectionStatus {
r.run();
} else {
addListener(isConnected -> {
if (getValue() == Value.CONNECTED)
if (getValue() == ConnectionStatusValue.CONNECTED)
r.run();
});
}
}
public enum Value {
NOT_CONNECTED,
LOADING,
CONNECTED
}
public static ConnectionStatus INSTANCE = new ConnectionStatus();
public static ConnectionStatusLogic INSTANCE = new ConnectionStatusLogic();
private List<Listener> listeners = new CopyOnWriteArrayList<>();
private final Timer timer = new Timer(Timeouts.CS_TIMEOUT, new ActionListener() {
@ -51,7 +45,7 @@ public class ConnectionStatus {
}
});
private ConnectionStatus() {
private ConnectionStatusLogic() {
LinkManager.engineState.timeListeners.add(new EngineTimeListener() {
@Override
@ -77,15 +71,15 @@ public class ConnectionStatus {
}
public void markConnected() {
if (value == Value.NOT_CONNECTED)
setValue(Value.LOADING);
if (value == ConnectionStatusValue.NOT_CONNECTED)
setValue(ConnectionStatusValue.LOADING);
/**
* this timer will catch engine inactivity and display a warning
*/
timer.restart();
}
public void setValue(@NotNull Value value) {
public void setValue(@NotNull ConnectionStatusValue value) {
if (value == this.value)
return;
this.value = value;
@ -94,11 +88,11 @@ public class ConnectionStatus {
}
public boolean isConnected() {
return value != Value.NOT_CONNECTED;
return value != ConnectionStatusValue.NOT_CONNECTED;
}
@NotNull
public Value getValue() {
public ConnectionStatusValue getValue() {
return value;
}

View File

@ -0,0 +1,7 @@
package com.rusefi.io;
public enum ConnectionStatusValue {
NOT_CONNECTED,
LOADING,
CONNECTED
}

View File

@ -154,7 +154,7 @@ public class LinkManager {
}
public static void restart() {
ConnectionStatus.INSTANCE.setValue(ConnectionStatus.Value.NOT_CONNECTED);
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.NOT_CONNECTED);
connector.restart();
}

View File

@ -39,7 +39,6 @@ import com.opensr5.ConfigurationImage;
import com.rusefi.UploadChanges;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.CommandQueue;
import com.rusefi.ui.SettingsTab;
public class ECUEditorToolBar extends JToolBar {

View File

@ -3,25 +3,21 @@ package com.rusefi;
import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.core.MessagesCentral;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.*;
import com.rusefi.io.serial.PortHolder;
import com.rusefi.io.tcp.BinaryProtocolServer;
import com.rusefi.maintenance.FirmwareFlasher;
import com.rusefi.maintenance.VersionChecker;
import com.rusefi.ui.*;
import com.rusefi.ui.console.MainFrame;
import com.rusefi.ui.console.TabbedPanel;
import com.rusefi.ui.engine.EngineSnifferPanel;
import com.rusefi.ui.logview.LogViewer;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.util.DefaultExceptionHandler;
import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.JustOneInstance;
import com.rusefi.ui.util.UiUtils;
import jssc.SerialPortList;
import javax.swing.*;
@ -33,7 +29,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
@ -49,11 +44,11 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20200424;
public static final int CONSOLE_VERSION = 20200501;
public static final String INI_FILE_PATH = System.getProperty("ini_file_path", "..");
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");
private static final String TAB_INDEX = "main_tab";
public static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port";
protected static final String SPEED_KEY = "speed";
@ -64,79 +59,28 @@ public class Launcher {
private static final String TOOL_NAME_PERF_ENUMS = "ptrace_enums";
// todo: rename to something more FSIO-specific? would need to update documentation somewhere
private static final String TOOL_NAME_COMPILE = "compile";
private static final int DEFAULT_TAB_INDEX = 0;
private final String port;
// todo: the logic around 'criticalError' could be implemented nicer
private String criticalError;
public static String port;
public static EngineSnifferPanel engineSnifferPanel;
private static SensorCentral.SensorListener wrongVersionListener;
private final JTabbedPane tabbedPane = new JTabbedPane() {
@Override
public void paint(Graphics g) {
super.paint(g);
paintStatusText(g);
}
public TabbedPanel tabbedPane = new TabbedPanel();
private void paintStatusText(Graphics g) {
Font f = g.getFont();
g.setFont(new Font(f.getName(), f.getStyle(), f.getSize() * 4));
Dimension d = getSize();
String text;
switch (ConnectionStatus.INSTANCE.getValue()) {
case NOT_CONNECTED:
text = "Not connected";
break;
case LOADING:
text = "Loading";
break;
default:
text = "";
}
if (criticalError != null) {
text = criticalError;
g.setColor(Color.red);
}
int labelWidth = g.getFontMetrics().stringWidth(text);
g.drawString(text, (d.width - labelWidth) / 2, d.height / 2);
}
};
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
private static Frame staticFrame;
private final TableEditorPane tableEditor = new TableEditorPane();
private final SettingsTab settingsTab = new SettingsTab();
private final LogDownloader logsManager = new LogDownloader();
private final FuelTunePane fuelTunePane;
private final PaneSettings paneSettings;
MainFrame mainFrame = new MainFrame(tabbedPane);
/**
* @see StartupFrame
* We can listen to tab activation event if we so desire
*/
private FrameHelper mainFrame = new FrameHelper() {
@Override
protected void onWindowOpened() {
super.onWindowOpened();
windowOpenedHandler();
}
@Override
protected void onWindowClosed() {
/**
* here we would close the port and log a message about it
*/
windowClosedHandler();
/**
* here we would close the log file
*/
super.onWindowClosed();
}
};
private final Map<JComponent, ActionListener> tabSelectedListeners = new HashMap<JComponent, ActionListener>();
private final Map<JComponent, ActionListener> tabSelectedListeners = new HashMap<>();
public Launcher(String port) {
this.port = port;
staticFrame = mainFrame.getFrame();
Launcher.port = port;
staticFrame = mainFrame.getFrame().getFrame();
FileLog.MAIN.logLine("Console " + CONSOLE_VERSION);
FileLog.MAIN.logLine("Hardware: " + FirmwareFlasher.getHardwareKind());
@ -146,22 +90,12 @@ public class Launcher {
LinkManager.start(port);
MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() {
@Override
public void onMessage(Class clazz, String message) {
if (message.startsWith(Fields.CRITICAL_PREFIX))
criticalError = message;
}
});
paneSettings = new PaneSettings(getConfig().getRoot().getChild("panes"));
engineSnifferPanel = new EngineSnifferPanel(getConfig().getRoot().getChild("digital_sniffer"));
if (!LinkManager.isLogViewerMode(port))
engineSnifferPanel.setOutpinListener(LinkManager.engineState);
if (LinkManager.isLogViewerMode(port))
tabbedPane.add("Log Viewer", new LogViewer(engineSnifferPanel));
tabbedPane.addTab("Log Viewer", new LogViewer(engineSnifferPanel));
ConnectionWatchdog.start();
@ -169,17 +103,17 @@ public class Launcher {
GaugesPanel.DetachedRepository.INSTANCE.init(getConfig().getRoot().getChild("detached"));
GaugesPanel.DetachedRepository.INSTANCE.load();
if (!LinkManager.isLogViewer())
tabbedPane.addTab("Gauges", new GaugesPanel(getConfig().getRoot().getChild("gauges"), paneSettings).getContent());
tabbedPane.addTab("Gauges", new GaugesPanel(getConfig().getRoot().getChild("gauges"), tabbedPane.paneSettings).getContent());
if (!LinkManager.isLogViewer()) {
MessagesPane messagesPane = new MessagesPane(getConfig().getRoot().getChild("messages"));
tabbedPaneAdd("Messages", messagesPane.getContent(), messagesPane.getTabSelectedListener());
}
if (!LinkManager.isLogViewer()) {
tabbedPane.add("Bench Test", new BenchTestPane().getContent());
if (paneSettings.showEtbPane)
tabbedPane.add("ETB", new ETBPane().getContent());
tabbedPane.add("Presets", new PresetsPane().getContent());
tabbedPane.addTab("Bench Test", new BenchTestPane().getContent());
if (tabbedPane.paneSettings.showEtbPane)
tabbedPane.addTab("ETB", new ETBPane().getContent());
tabbedPane.addTab("Presets", new PresetsPane().getContent());
}
tabbedPaneAdd("Engine Sniffer", engineSnifferPanel.getPanel(), engineSnifferPanel.getTabSelectedListener());
@ -192,42 +126,41 @@ public class Launcher {
// tabbedPane.addTab("LE controls", new FlexibleControls().getPanel());
// tabbedPane.addTab("ADC", new AdcPanel(new BooleanInputsModel()).createAdcPanel());
if (paneSettings.showStimulatorPane && !LinkManager.isSimulationMode && !LinkManager.isLogViewerMode(port)) {
if (tabbedPane.paneSettings.showStimulatorPane && !LinkManager.isSimulationMode && !LinkManager.isLogViewerMode(port)) {
// todo: rethink this UI? special command line key to enable it?
EcuStimulator stimulator = EcuStimulator.getInstance();
tabbedPane.add("ECU stimulation", stimulator.getPanel());
tabbedPane.addTab("ECU stimulation", stimulator.getPanel());
}
// tabbedPane.addTab("live map adjustment", new Live3DReport().getControl());
if (!LinkManager.isLogViewer())
tabbedPane.addTab("Table Editor", tableEditor);
tabbedPane.addTab("Table Editor", tabbedPane.tableEditor);
// tabbedPane.add("Wizards", new Wizard().createPane());
if (!LinkManager.isLogViewer())
tabbedPane.add("Settings", settingsTab.createPane());
tabbedPane.addTab("Settings", tabbedPane.settingsTab.createPane());
if (!LinkManager.isLogViewer()) {
tabbedPane.addTab("Formulas/Live Data", new FormulasPane().getContent());
tabbedPane.addTab("Sensors Live Data", new SensorsLiveDataPane().getContent());
}
if (!LinkManager.isLogViewer() && false) // todo: fix it & better name?
tabbedPane.add("Logs Manager", logsManager.getContent());
fuelTunePane = new FuelTunePane(getConfig().getRoot().getChild("fueltune"));
if (paneSettings.showFuelTunePane)
tabbedPane.add("Fuel Tune", fuelTunePane.getContent());
tabbedPane.addTab("Logs Manager", tabbedPane.logsManager.getContent());
if (tabbedPane.paneSettings.showFuelTunePane)
tabbedPane.addTab("Fuel Tune", tabbedPane.fuelTunePane.getContent());
if (!LinkManager.isLogViewer()) {
if (paneSettings.showTriggerShapePane)
tabbedPane.add("Trigger Shape", new AverageAnglePanel().getPanel());
if (tabbedPane.paneSettings.showTriggerShapePane)
tabbedPane.addTab("Trigger Shape", new AverageAnglePanel().getPanel());
}
if (!LinkManager.isLogViewerMode(port)) {
int selectedIndex = getConfig().getRoot().getIntProperty(TAB_INDEX, 2);
if (selectedIndex < tabbedPane.getTabCount())
tabbedPane.setSelectedIndex(selectedIndex);
int selectedIndex = getConfig().getRoot().getIntProperty(TAB_INDEX, DEFAULT_TAB_INDEX);
if (selectedIndex < tabbedPane.tabbedPane.getTabCount())
tabbedPane.tabbedPane.setSelectedIndex(selectedIndex);
}
tabbedPane.addChangeListener(new ChangeListener() {
tabbedPane.tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() instanceof JTabbedPane) {
@ -241,79 +174,16 @@ public class Launcher {
}
});
StartupFrame.setAppIcon(mainFrame.getFrame());
mainFrame.showFrame(tabbedPane);
StartupFrame.setAppIcon(mainFrame.getFrame().getFrame());
mainFrame.getFrame().showFrame(tabbedPane.tabbedPane);
}
/**
* Adds a tab with activation listener
*/
private void tabbedPaneAdd(String title, JComponent component, ActionListener tabSelectedListener) {
tabSelectedListeners.put(component, tabSelectedListener);
tabbedPane.add(title, component);
}
private void windowOpenedHandler() {
setTitle();
ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() {
@Override
public void onConnectionStatus(boolean isConnected) {
setTitle();
UiUtils.trueRepaint(tabbedPane); // this would repaint status label
if (ConnectionStatus.INSTANCE.getValue() == ConnectionStatus.Value.CONNECTED) {
long unixGmtTime = System.currentTimeMillis() / 1000L;
long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
CommandQueue.getInstance().write("set " +
Fields.CMD_DATE +
" " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
InvocationConfirmationListener.VOID, false);
}
}
});
LinkManager.open(new ConnectionStateListener() {
@Override
public void onConnectionFailed() {
}
@Override
public void onConnectionEstablished() {
FileLog.MAIN.logLine("onConnectionEstablished");
tableEditor.showContent();
settingsTab.showContent();
logsManager.showContent();
fuelTunePane.showContent();
BinaryProtocolServer.start();
}
});
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, new EngineState.ValueCallback<String>() {
@Override
public void onUpdate(String firmwareVersion) {
Launcher.firmwareVersion.set(firmwareVersion);
SensorLogger.init();
setTitle();
VersionChecker.getInstance().onFirmwareVersion(firmwareVersion);
}
});
}
private void setTitle() {
String disconnected = ConnectionStatus.INSTANCE.isConnected() ? "" : "DISCONNECTED ";
mainFrame.getFrame().setTitle(disconnected + "Console " + CONSOLE_VERSION + "; firmware=" + Launcher.firmwareVersion.get() + "@" + port);
}
private void windowClosedHandler() {
/**
* looks like reconnectTimer in {@link com.rusefi.ui.RpmPanel} keeps AWT alive. Simplest solution would be to 'exit'
*/
SimulatorHelper.onWindowClosed();
Node root = getConfig().getRoot();
root.setProperty("version", CONSOLE_VERSION);
root.setProperty(TAB_INDEX, tabbedPane.getSelectedIndex());
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
getConfig().save();
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
if (bp != null && !bp.isClosed)
bp.close(); // it could be that serial driver wants to be closed explicitly
System.exit(0);
tabbedPane.addTab(title, component);
}
/**

View File

@ -6,7 +6,8 @@ import com.rusefi.binaryprotocol.BinaryProtocolHolder;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.ConnectionStatus;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.io.ConnectionStatusValue;
import com.rusefi.ui.config.ConfigField;
import java.io.FileWriter;
@ -99,7 +100,7 @@ public class SensorLogger {
SensorCentral.getInstance().addListener(Sensor.TIME_SECONDS, new SensorCentral.SensorListener() {
@Override
public void onSensorUpdate(double value) {
if (ConnectionStatus.INSTANCE.getValue() != ConnectionStatus.Value.CONNECTED)
if (ConnectionStatusLogic.INSTANCE.getValue() != ConnectionStatusValue.CONNECTED)
return;
if (logFile == null) {
/*

View File

@ -9,7 +9,6 @@ import com.rusefi.config.generated.Fields;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.SerialIoStreamJSSC;
import com.rusefi.ui.RecentCommands;
import com.rusefi.ui.SettingsTab;
import com.rusefi.ui.StatusWindow;
import jssc.SerialPort;
import jssc.SerialPortException;

View File

@ -5,8 +5,6 @@ import com.rusefi.ui.StatusWindow;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import static com.rusefi.Launcher.INPUT_FILES_PATH;
@ -34,10 +32,8 @@ public class FirmwareFlasher {
public static final String DONE = "DONE!";
private final JButton button;
private String fileName;
public FirmwareFlasher(String fileName, String buttonTest, String tooltip) {
this.fileName = fileName;
button = new JButton(buttonTest);
button.setToolTipText(tooltip);
button.addActionListener(event -> doUpdateFirmware(fileName, button));

View File

@ -54,6 +54,8 @@ public class GaugesPanel {
private static final String SHOW_RPM = "show_rpm";
private static final String SPLIT_LOCATION = "SPLIT_LOCATION";
public static final String DISABLE_LOGS = "DISABLE_LOGS";
private static final int DEFAULT_ROWS = 3;
private static final int DEFAULT_COLUMNS = 3;
public static boolean IS_PAUSED; // dirty but works for not
static {
@ -76,7 +78,7 @@ public class GaugesPanel {
private final JSplitPane middleSplitPanel;
public GaugesPanel(final Node config, PaneSettings paneSettings) {
gauges = new GaugesGrid(3, 5);
gauges = new GaugesGrid(DEFAULT_ROWS, DEFAULT_COLUMNS);
this.config = config;
showRpmPanel = config.getBoolProperty(SHOW_RPM, true);
showMessagesPanel = config.getBoolProperty(SHOW_MESSAGES, true);
@ -85,8 +87,8 @@ public class GaugesPanel {
lowerRpmPanel.add(new RpmLabel(15).getContent());
int rows = config.getIntProperty(GAUGES_ROWS, SizeSelectorPanel.HEIGHT);
int columns = config.getIntProperty(GAUGES_COLUMNS, SizeSelectorPanel.WIDTH);
int rows = config.getIntProperty(GAUGES_ROWS, DEFAULT_ROWS);
int columns = config.getIntProperty(GAUGES_COLUMNS, DEFAULT_COLUMNS);
setSensorGridDimensions(rows, columns);

View File

@ -2,7 +2,7 @@ package com.rusefi.ui;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.ConnectionStatus;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.io.LinkManager;
import javax.swing.*;
@ -44,7 +44,7 @@ public class RpmLabel {
}
});
ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() {
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
@Override
public void onConnectionStatus(boolean isConnected) {
if (isConnected) {

View File

@ -6,7 +6,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
import com.rusefi.config.Field;
import com.rusefi.io.CommandQueue;
import com.rusefi.io.ConnectionStatus;
import com.rusefi.io.ConnectionStatusLogic;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@ -24,7 +24,7 @@ public abstract class BaseConfigField {
}
protected void requestInitialValue(final Field field) {
ConnectionStatus.INSTANCE.executeOnceConnected(() -> processInitialValue(field));
ConnectionStatusLogic.INSTANCE.executeOnceConnected(() -> processInitialValue(field));
}
private void processInitialValue(Field field) {

View File

@ -0,0 +1,119 @@
package com.rusefi.ui.console;
import com.rusefi.*;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.io.*;
import com.rusefi.io.tcp.BinaryProtocolServer;
import com.rusefi.maintenance.VersionChecker;
import com.rusefi.ui.GaugesPanel;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.UiUtils;
import java.util.TimeZone;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class MainFrame {
private final TabbedPanel tabbedPane;
/**
* @see StartupFrame
*/
private FrameHelper frame = new FrameHelper() {
@Override
protected void onWindowOpened() {
super.onWindowOpened();
windowOpenedHandler();
}
@Override
protected void onWindowClosed() {
/**
* here we would close the port and log a message about it
*/
windowClosedHandler();
/**
* here we would close the log file
*/
super.onWindowClosed();
}
};
public MainFrame(TabbedPanel tabbedPane) {
this.tabbedPane = tabbedPane;
}
private void windowOpenedHandler() {
setTitle();
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
@Override
public void onConnectionStatus(boolean isConnected) {
setTitle();
UiUtils.trueRepaint(tabbedPane.tabbedPane); // this would repaint status label
if (ConnectionStatusLogic.INSTANCE.getValue() == ConnectionStatusValue.CONNECTED) {
long unixGmtTime = System.currentTimeMillis() / 1000L;
long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
CommandQueue.getInstance().write("set " +
Fields.CMD_DATE +
" " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
InvocationConfirmationListener.VOID, false);
}
}
});
LinkManager.open(new ConnectionStateListener() {
@Override
public void onConnectionFailed() {
}
@Override
public void onConnectionEstablished() {
FileLog.MAIN.logLine("onConnectionEstablished");
tabbedPane.tableEditor.showContent();
tabbedPane.settingsTab.showContent();
tabbedPane.logsManager.showContent();
tabbedPane.fuelTunePane.showContent();
BinaryProtocolServer.start();
}
});
LinkManager.engineState.registerStringValueAction(Fields.PROTOCOL_VERSION_TAG, new EngineState.ValueCallback<String>() {
@Override
public void onUpdate(String firmwareVersion) {
Launcher.firmwareVersion.set(firmwareVersion);
SensorLogger.init();
setTitle();
VersionChecker.getInstance().onFirmwareVersion(firmwareVersion);
}
});
}
public FrameHelper getFrame() {
return frame;
}
private void setTitle() {
String disconnected = ConnectionStatusLogic.INSTANCE.isConnected() ? "" : "DISCONNECTED ";
frame.getFrame().setTitle(disconnected + "Console " + Launcher.CONSOLE_VERSION + "; firmware=" + Launcher.firmwareVersion.get() + "@" + Launcher.port);
}
private void windowClosedHandler() {
/**
* looks like reconnectTimer in {@link com.rusefi.ui.RpmPanel} keeps AWT alive. Simplest solution would be to 'exit'
*/
SimulatorHelper.onWindowClosed();
Node root = getConfig().getRoot();
root.setProperty("version", Launcher.CONSOLE_VERSION);
root.setProperty(Launcher.TAB_INDEX, tabbedPane.tabbedPane.getSelectedIndex());
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
getConfig().save();
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
if (bp != null && !bp.isClosed)
bp.close(); // it could be that serial driver wants to be closed explicitly
System.exit(0);
}
}

View File

@ -1,4 +1,4 @@
package com.rusefi.ui;
package com.rusefi.ui.console;
import com.opensr5.ini.DialogModel;
import com.opensr5.ini.IniFileModel;
@ -7,6 +7,7 @@ import com.rusefi.config.Field;
import com.rusefi.config.FieldType;
import com.rusefi.config.FieldsMap;
import com.rusefi.config.generated.Fields;
import com.rusefi.ui.RecentCommands;
import com.rusefi.ui.config.*;
import com.rusefi.ui.util.UiUtils;

View File

@ -0,0 +1,68 @@
package com.rusefi.ui.console;
import com.rusefi.PaneSettings;
import com.rusefi.TableEditorPane;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.ui.FuelTunePane;
import com.rusefi.ui.LogDownloader;
import javax.swing.*;
import java.awt.*;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class TabbedPanel {
// todo: the logic around 'criticalError' could be implemented nicer
private String criticalError;
public final TableEditorPane tableEditor = new TableEditorPane();
public final SettingsTab settingsTab = new SettingsTab();
public final LogDownloader logsManager = new LogDownloader();
public final FuelTunePane fuelTunePane = new FuelTunePane(getConfig().getRoot().getChild("fueltune"));
public final PaneSettings paneSettings = new PaneSettings(getConfig().getRoot().getChild("panes"));
public final JTabbedPane tabbedPane = new JTabbedPane() {
@Override
public void paint(Graphics g) {
super.paint(g);
paintStatusText(g);
}
private void paintStatusText(Graphics g) {
Font f = g.getFont();
g.setFont(new Font(f.getName(), f.getStyle(), f.getSize() * 4));
Dimension d = getSize();
String text;
switch (ConnectionStatusLogic.INSTANCE.getValue()) {
case NOT_CONNECTED:
text = "Not connected";
break;
case LOADING:
text = "Loading";
break;
default:
text = "";
}
if (criticalError != null) {
text = criticalError;
g.setColor(Color.red);
}
int labelWidth = g.getFontMetrics().stringWidth(text);
g.drawString(text, (d.width - labelWidth) / 2, d.height / 2);
}
};
public TabbedPanel() {
MessagesCentral.getInstance().addListener((clazz, message) -> {
if (message.startsWith(Fields.CRITICAL_PREFIX))
criticalError = message;
});
}
public void addTab(String title, Component component) {
tabbedPane.addTab(title, component);
}
}