refactoring: better dependency control
This commit is contained in:
parent
af20f4c1f8
commit
62ca66b821
|
@ -11,7 +11,6 @@ import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.serial.BaudRateHolder;
|
import com.rusefi.io.serial.BaudRateHolder;
|
||||||
import com.rusefi.maintenance.FirmwareFlasher;
|
import com.rusefi.maintenance.FirmwareFlasher;
|
||||||
import com.rusefi.maintenance.VersionChecker;
|
import com.rusefi.maintenance.VersionChecker;
|
||||||
import com.rusefi.sensor_logs.SensorLogger;
|
|
||||||
import com.rusefi.ui.*;
|
import com.rusefi.ui.*;
|
||||||
import com.rusefi.ui.console.MainFrame;
|
import com.rusefi.ui.console.MainFrame;
|
||||||
import com.rusefi.ui.console.TabbedPanel;
|
import com.rusefi.ui.console.TabbedPanel;
|
||||||
|
@ -104,7 +103,7 @@ public class ConsoleUI {
|
||||||
tabbedPaneAdd("Engine Sniffer", engineSnifferPanel.getPanel(), engineSnifferPanel.getTabSelectedListener());
|
tabbedPaneAdd("Engine Sniffer", engineSnifferPanel.getPanel(), engineSnifferPanel.getTabSelectedListener());
|
||||||
|
|
||||||
if (!LinkManager.isLogViewer()) {
|
if (!LinkManager.isLogViewer()) {
|
||||||
SensorSnifferPane sensorSniffer = new SensorSnifferPane(getConfig().getRoot().getChild("sensor_sniffer"));
|
SensorSnifferPane sensorSniffer = new SensorSnifferPane(uiContext, getConfig().getRoot().getChild("sensor_sniffer"));
|
||||||
tabbedPaneAdd("Sensor Sniffer", sensorSniffer.getPanel(), sensorSniffer.getTabSelectedListener());
|
tabbedPaneAdd("Sensor Sniffer", sensorSniffer.getPanel(), sensorSniffer.getTabSelectedListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ public class ConsoleUI {
|
||||||
|
|
||||||
tabbedPane.addTab("rusEFI Online", new OnlineTab().getContent());
|
tabbedPane.addTab("rusEFI Online", new OnlineTab().getContent());
|
||||||
|
|
||||||
SensorLogger.init();
|
uiContext.sensorLogger.init();
|
||||||
|
|
||||||
if (!LinkManager.isLogViewerMode(port)) {
|
if (!LinkManager.isLogViewerMode(port)) {
|
||||||
int selectedIndex = getConfig().getRoot().getIntProperty(TAB_INDEX, DEFAULT_TAB_INDEX);
|
int selectedIndex = getConfig().getRoot().getIntProperty(TAB_INDEX, DEFAULT_TAB_INDEX);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.ui.RpmLabel;
|
import com.rusefi.ui.RpmLabel;
|
||||||
import com.rusefi.ui.RpmModel;
|
import com.rusefi.ui.RpmModel;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
import com.rusefi.ui.config.ConfigField;
|
import com.rusefi.ui.config.ConfigField;
|
||||||
import com.rusefi.ui.config.EnumConfigField;
|
import com.rusefi.ui.config.EnumConfigField;
|
||||||
import com.rusefi.ui.engine.EngineSnifferPanel;
|
import com.rusefi.ui.engine.EngineSnifferPanel;
|
||||||
|
@ -38,7 +39,7 @@ public class SensorSnifferPane {
|
||||||
|
|
||||||
private boolean paused = false;
|
private boolean paused = false;
|
||||||
|
|
||||||
public SensorSnifferPane(Node config) {
|
public SensorSnifferPane(UIContext uiContext, Node config) {
|
||||||
SensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
SensorSnifferCentral.addListener(new SensorSnifferCentral.AnalogChartListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnalogChart(final String message) {
|
public void onAnalogChart(final String message) {
|
||||||
|
@ -108,9 +109,9 @@ public class SensorSnifferPane {
|
||||||
lowerPanel.setBorder(BorderFactory.createLineBorder(Color.cyan));
|
lowerPanel.setBorder(BorderFactory.createLineBorder(Color.cyan));
|
||||||
content.add(lowerPanel, BorderLayout.SOUTH);
|
content.add(lowerPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
lowerPanel.add(new EnumConfigField(Fields.SENSORCHARTMODE, "Mode").getContent());
|
lowerPanel.add(new EnumConfigField(uiContext, Fields.SENSORCHARTMODE, "Mode").getContent());
|
||||||
lowerPanel.add(new ConfigField(Fields.SENSORCHARTFREQUENCY, "Every XXX engine cycles").getContent());
|
lowerPanel.add(new ConfigField(uiContext, Fields.SENSORCHARTFREQUENCY, "Every XXX engine cycles").getContent());
|
||||||
lowerPanel.add(new ConfigField(Fields.SENSORSNIFFERRPMTHRESHOLD, "RPM threashold").getContent());
|
lowerPanel.add(new ConfigField(uiContext, Fields.SENSORSNIFFERRPMTHRESHOLD, "RPM threashold").getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPaused(JButton pauseButton, boolean isPaused) {
|
private void setPaused(JButton pauseButton, boolean isPaused) {
|
||||||
|
|
|
@ -86,14 +86,7 @@ public class SensorLogger {
|
||||||
|
|
||||||
private static boolean isInitialized;
|
private static boolean isInitialized;
|
||||||
|
|
||||||
private SensorLogger() {
|
public synchronized void init() {
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized static void init() {
|
|
||||||
if (isInitialized) {
|
if (isInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.rusefi.test;
|
|
||||||
|
|
||||||
import com.rusefi.SensorSnifferPane;
|
|
||||||
import com.rusefi.ui.storage.Node;
|
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2/16/15
|
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class SensorSnifferPaneSandbox {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Node config = null;//getConfig().getRoot().getChild("sensor_sniffer");
|
|
||||||
new FrameHelper().showFrame(new SensorSnifferPane(config).getPanel());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.rusefi.ui;
|
package com.rusefi.ui;
|
||||||
|
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
import com.rusefi.sensor_logs.SensorLogger;
|
||||||
|
|
||||||
public class UIContext {
|
public class UIContext {
|
||||||
private final LinkManager linkManager = new LinkManager();
|
private final LinkManager linkManager = new LinkManager();
|
||||||
|
|
||||||
|
public SensorLogger sensorLogger = new SensorLogger();
|
||||||
|
|
||||||
public LinkManager getLinkManager() {
|
public LinkManager getLinkManager() {
|
||||||
return linkManager;
|
return linkManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.rusefi.config.Field;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
import com.rusefi.io.ConnectionStatusLogic;
|
import com.rusefi.io.ConnectionStatusLogic;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -16,9 +17,11 @@ import java.nio.ByteBuffer;
|
||||||
public abstract class BaseConfigField {
|
public abstract class BaseConfigField {
|
||||||
protected final JLabel status = new JLabel("P");
|
protected final JLabel status = new JLabel("P");
|
||||||
private final JPanel panel = new JPanel(new BorderLayout());
|
private final JPanel panel = new JPanel(new BorderLayout());
|
||||||
|
private final UIContext uiContext;
|
||||||
protected final Field field;
|
protected final Field field;
|
||||||
|
|
||||||
public BaseConfigField(final Field field) {
|
public BaseConfigField(UIContext uiContext, final Field field) {
|
||||||
|
this.uiContext = uiContext;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
status.setToolTipText("Pending...");
|
status.setToolTipText("Pending...");
|
||||||
}
|
}
|
||||||
|
@ -28,7 +31,7 @@ public abstract class BaseConfigField {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processInitialValue(Field field) {
|
private void processInitialValue(Field field) {
|
||||||
BinaryProtocol bp = LinkManager.getCurrentStreamStateStatic();
|
BinaryProtocol bp = uiContext.getLinkManager().getCurrentStreamState();
|
||||||
if (bp == null)
|
if (bp == null)
|
||||||
return;
|
return;
|
||||||
ConfigurationImage ci = bp.getControllerConfiguration();
|
ConfigurationImage ci = bp.getControllerConfiguration();
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class BitConfigField extends BaseConfigField {
|
||||||
private boolean ec;
|
private boolean ec;
|
||||||
|
|
||||||
public BitConfigField(UIContext uiContext, final Field field, String caption) {
|
public BitConfigField(UIContext uiContext, final Field field, String caption) {
|
||||||
super(field);
|
super(uiContext, field);
|
||||||
createUi(caption, view);
|
createUi(caption, view);
|
||||||
requestInitialValue(field); // this is not in base constructor so that view is created by the time we invoke it
|
requestInitialValue(field); // this is not in base constructor so that view is created by the time we invoke it
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.config.Field;
|
||||||
import com.rusefi.config.FieldCommandResponse;
|
import com.rusefi.config.FieldCommandResponse;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.core.Pair;
|
import com.rusefi.core.Pair;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
import com.rusefi.ui.util.JTextFieldWithWidth;
|
import com.rusefi.ui.util.JTextFieldWithWidth;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -17,8 +18,8 @@ public class ConfigField extends BaseConfigField {
|
||||||
private final JTextField view = new JTextFieldWithWidth(200);
|
private final JTextField view = new JTextFieldWithWidth(200);
|
||||||
private final static DecimalFormat df = new DecimalFormat("0.0000");
|
private final static DecimalFormat df = new DecimalFormat("0.0000");
|
||||||
|
|
||||||
public ConfigField(final Field field, String topLabel) {
|
public ConfigField(UIContext uiContext, final Field field, String topLabel) {
|
||||||
super(field);
|
super(uiContext, field);
|
||||||
createUi(topLabel, view);
|
createUi(topLabel, view);
|
||||||
requestInitialValue(field); // this is not in base constructor so that view is created by the time we invoke it
|
requestInitialValue(field); // this is not in base constructor so that view is created by the time we invoke it
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.rusefi.config.FieldCommandResponse;
|
||||||
import com.rusefi.config.FieldType;
|
import com.rusefi.config.FieldType;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.core.Pair;
|
import com.rusefi.core.Pair;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -19,8 +20,8 @@ public class EnumConfigField extends BaseConfigField {
|
||||||
private final Map<String, Integer> ordinals = new HashMap<>();
|
private final Map<String, Integer> ordinals = new HashMap<>();
|
||||||
private final String[] options = field.getOptions();
|
private final String[] options = field.getOptions();
|
||||||
|
|
||||||
public EnumConfigField(final Field field, String caption) {
|
public EnumConfigField(UIContext uiContext, final Field field, String caption) {
|
||||||
super(field);
|
super(uiContext, field);
|
||||||
if (options == null)
|
if (options == null)
|
||||||
throw new NullPointerException("options for " + field);
|
throw new NullPointerException("options for " + field);
|
||||||
createUi(caption, view);
|
createUi(caption, view);
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class MainFrame {
|
||||||
root.setProperty(ConsoleUI.TAB_INDEX, tabbedPane.tabbedPane.getSelectedIndex());
|
root.setProperty(ConsoleUI.TAB_INDEX, tabbedPane.tabbedPane.getSelectedIndex());
|
||||||
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
||||||
getConfig().save();
|
getConfig().save();
|
||||||
BinaryProtocol bp = LinkManager.getCurrentStreamStateStatic();
|
BinaryProtocol bp = consoleUI.uiContext.getLinkManager().getCurrentStreamState();
|
||||||
if (bp != null && !bp.isClosed)
|
if (bp != null && !bp.isClosed)
|
||||||
bp.close(); // it could be that serial driver wants to be closed explicitly
|
bp.close(); // it could be that serial driver wants to be closed explicitly
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
|
|
@ -151,9 +151,9 @@ public class SettingsTab {
|
||||||
if (field.getType() == FieldType.BIT) {
|
if (field.getType() == FieldType.BIT) {
|
||||||
control = new BitConfigField(uiContext, field, f.getUiName()).getContent();
|
control = new BitConfigField(uiContext, field, f.getUiName()).getContent();
|
||||||
} else if (field.getOptions() != null) {
|
} else if (field.getOptions() != null) {
|
||||||
control = new EnumConfigField(field, f.getUiName()).getContent();
|
control = new EnumConfigField(uiContext, field, f.getUiName()).getContent();
|
||||||
} else {
|
} else {
|
||||||
control = new ConfigField(field, f.getUiName()).getContent();
|
control = new ConfigField(uiContext, field, f.getUiName()).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogBody.add(control);
|
dialogBody.add(control);
|
||||||
|
|
|
@ -131,12 +131,12 @@ public class EngineSnifferPanel {
|
||||||
|
|
||||||
if (!LinkManager.isLogViewer()) {
|
if (!LinkManager.isLogViewer()) {
|
||||||
JPanel lowerButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
|
JPanel lowerButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
|
||||||
lowerButtons.add(new ConfigField(Fields.GLOBALTRIGGERANGLEOFFSET, "Trigger Offset").getContent());
|
lowerButtons.add(new ConfigField(uiContext, Fields.GLOBALTRIGGERANGLEOFFSET, "Trigger Offset").getContent());
|
||||||
lowerButtons.add(new BitConfigField(uiContext, Fields.VERBOSETRIGGERSYNCHDETAILS, "Verbose trigger Sync").getContent());
|
lowerButtons.add(new BitConfigField(uiContext, Fields.VERBOSETRIGGERSYNCHDETAILS, "Verbose trigger Sync").getContent());
|
||||||
lowerButtons.add(new BitConfigField(uiContext, Fields.ISENGINECHARTENABLED, "Collect Engine Data").getContent());
|
lowerButtons.add(new BitConfigField(uiContext, Fields.ISENGINECHARTENABLED, "Collect Engine Data").getContent());
|
||||||
lowerButtons.add(new ConfigField(Fields.SENSORCHARTFREQUENCY, "Frequency").getContent());
|
lowerButtons.add(new ConfigField(uiContext, Fields.SENSORCHARTFREQUENCY, "Frequency").getContent());
|
||||||
lowerButtons.add(new ConfigField(Fields.ENGINECHARTSIZE, "Engine Sniffer size").getContent());
|
lowerButtons.add(new ConfigField(uiContext, Fields.ENGINECHARTSIZE, "Engine Sniffer size").getContent());
|
||||||
lowerButtons.add(new ConfigField(Fields.ENGINESNIFFERRPMTHRESHOLD, "RPM threashold").getContent());
|
lowerButtons.add(new ConfigField(uiContext, Fields.ENGINESNIFFERRPMTHRESHOLD, "RPM threashold").getContent());
|
||||||
bottomPanel.add(lowerButtons, BorderLayout.NORTH);
|
bottomPanel.add(lowerButtons, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,10 @@ package com.rusefi.ui.etb;
|
||||||
|
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.ldmp.generated.ElectronicThrottleMeta;
|
|
||||||
import com.rusefi.ui.UIContext;
|
import com.rusefi.ui.UIContext;
|
||||||
import com.rusefi.ui.config.BitConfigField;
|
import com.rusefi.ui.config.BitConfigField;
|
||||||
import com.rusefi.ui.config.ConfigField;
|
import com.rusefi.ui.config.ConfigField;
|
||||||
import com.rusefi.ui.config.EnumConfigField;
|
import com.rusefi.ui.config.EnumConfigField;
|
||||||
import com.rusefi.ui.livedocs.LiveDocPanel;
|
|
||||||
import com.rusefi.ui.storage.Node;
|
import com.rusefi.ui.storage.Node;
|
||||||
import com.rusefi.ui.util.UiUtils;
|
import com.rusefi.ui.util.UiUtils;
|
||||||
import com.rusefi.ui.widgets.AnyCommand;
|
import com.rusefi.ui.widgets.AnyCommand;
|
||||||
|
@ -43,9 +41,9 @@ public class EtbCommandsPanel {
|
||||||
testParameters.add(new JLabel("set etb_p 1.1"));
|
testParameters.add(new JLabel("set etb_p 1.1"));
|
||||||
|
|
||||||
testParameters.add(new BitConfigField(uiContext, Fields.PAUSEETBCONTROL, "Pause").getContent());
|
testParameters.add(new BitConfigField(uiContext, Fields.PAUSEETBCONTROL, "Pause").getContent());
|
||||||
testParameters.add(new ConfigField(Fields.ETB_PFACTOR, "pFactor").getContent());
|
testParameters.add(new ConfigField(uiContext, Fields.ETB_PFACTOR, "pFactor").getContent());
|
||||||
testParameters.add(new ConfigField(Fields.ETB_IFACTOR, "iFactor").getContent());
|
testParameters.add(new ConfigField(uiContext, Fields.ETB_IFACTOR, "iFactor").getContent());
|
||||||
testParameters.add(new ConfigField(Fields.ETB_DFACTOR, "dFactor").getContent());
|
testParameters.add(new ConfigField(uiContext, Fields.ETB_DFACTOR, "dFactor").getContent());
|
||||||
|
|
||||||
content.setBorder(BorderFactory.createTitledBorder("Commands"));
|
content.setBorder(BorderFactory.createTitledBorder("Commands"));
|
||||||
|
|
||||||
|
@ -63,7 +61,7 @@ public class EtbCommandsPanel {
|
||||||
// todo: restore this functionality
|
// todo: restore this functionality
|
||||||
// content.add(LiveDocPanel.createPanel("ETB", ElectronicThrottleMeta.CONTENT));
|
// content.add(LiveDocPanel.createPanel("ETB", ElectronicThrottleMeta.CONTENT));
|
||||||
|
|
||||||
content.add(new EnumConfigField(Fields.DEBUGMODE, "Debug Mode").getContent());
|
content.add(new EnumConfigField(uiContext, Fields.DEBUGMODE, "Debug Mode").getContent());
|
||||||
|
|
||||||
content.add(createMagicSpotsPanel());
|
content.add(createMagicSpotsPanel());
|
||||||
content.add(UiUtils.wrap(new EtbMonteCarloSequence().getButton()));
|
content.add(UiUtils.wrap(new EtbMonteCarloSequence().getButton()));
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.rusefi.io.ConnectionStatusLogic;
|
||||||
import com.rusefi.io.ConnectionWatchdog;
|
import com.rusefi.io.ConnectionWatchdog;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.sensor_logs.SensorLogger;
|
import com.rusefi.sensor_logs.SensorLogger;
|
||||||
|
import com.rusefi.ui.UIContext;
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
import com.rusefi.ui.util.FrameHelper;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
|
@ -62,6 +63,9 @@ public class LightweightGUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
|
|
||||||
|
UIContext uiContext = new UIContext();
|
||||||
|
|
||||||
LightweightGUI gui = new LightweightGUI();
|
LightweightGUI gui = new LightweightGUI();
|
||||||
|
|
||||||
gui.setConnectedUI(false);
|
gui.setConnectedUI(false);
|
||||||
|
@ -72,7 +76,7 @@ public class LightweightGUI {
|
||||||
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
|
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStatus(boolean isConnected) {
|
public void onConnectionStatus(boolean isConnected) {
|
||||||
SensorLogger.init();
|
uiContext.sensorLogger.init();
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Reference in New Issue