auto-sync

This commit is contained in:
rusEfi 2017-01-29 09:06:38 -05:00
parent 547f96cac0
commit 8aa0a1adda
5 changed files with 89 additions and 12 deletions

View File

@ -21,8 +21,13 @@ import com.rusefi.ui.util.UiUtils;
import jssc.SerialPortList;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
@ -39,7 +44,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20170120;
public static final int CONSOLE_VERSION = 20170129;
public static final boolean SHOW_STIMULATOR = false;
private static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port";
@ -111,6 +116,7 @@ public class Launcher {
super.onWindowClosed();
}
};
private final Map<JComponent, ActionListener> tabSelectedListeners = new HashMap<JComponent, ActionListener>();
public Launcher(String port) {
this.port = port;
@ -148,11 +154,12 @@ public class Launcher {
if (!LinkManager.isLogViewer())
tabbedPane.addTab("Formulas", new FormulasPane().getContent());
tabbedPane.addTab("Engine Sniffer", engineSnifferPanel.getPanel());
if (!LinkManager.isLogViewer())
tabbedPane.addTab("Sensor Sniffer", new SensorSnifferPane(getConfig().getRoot().getChild("sensor_sniffer")).getPanel());
tabbedPaneAdd("Engine Sniffer", engineSnifferPanel.getPanel(), engineSnifferPanel.getTabSelectedListener());
if (!LinkManager.isLogViewer()) {
SensorSnifferPane sensorSniffer = new SensorSnifferPane(getConfig().getRoot().getChild("sensor_sniffer"));
tabbedPaneAdd("Sensor Sniffer", sensorSniffer.getPanel(), sensorSniffer.getTabSelectedListener());
}
// tabbedPane.addTab("LE controls", new FlexibleControls().getPanel());
@ -163,8 +170,10 @@ public class Launcher {
tabbedPane.add("ECU stimulation", stimulator.getPanel());
}
// tabbedPane.addTab("live map adjustment", new Live3DReport().getControl());
if (!LinkManager.isLogViewer())
tabbedPane.add("Messages", new MessagesPane(getConfig().getRoot().getChild("messages")).getContent());
if (!LinkManager.isLogViewer()) {
MessagesPane messagesPane = new MessagesPane(getConfig().getRoot().getChild("messages"));
tabbedPaneAdd("Messages", messagesPane.getContent(), messagesPane.getTabSelectedListener());
}
if (!LinkManager.isLogViewer())
tabbedPane.addTab("Table Editor", tableEditor);
// tabbedPane.add("Wizards", new Wizard().createPane());
@ -185,10 +194,29 @@ public class Launcher {
tabbedPane.setSelectedIndex(selectedIndex);
}
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() instanceof JTabbedPane) {
JTabbedPane pane = (JTabbedPane) e.getSource();
int selectedIndex = pane.getSelectedIndex();
System.out.println("Selected paneNo: " + selectedIndex);
ActionListener actionListener = tabSelectedListeners.get(pane.getComponentAt(selectedIndex));
if (actionListener != null)
actionListener.actionPerformed(null);
}
}
});
StartupFrame.setAppIcon(mainFrame.getFrame());
mainFrame.showFrame(tabbedPane);
}
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() {

View File

@ -34,6 +34,7 @@ public class SensorSnifferPane {
private double maxY;
private final JPanel content = new JPanel(new BorderLayout());
private final AnyCommand command;
private boolean paused = false;
@ -85,7 +86,8 @@ public class SensorSnifferPane {
upperPanel.add(pauseButton);
upperPanel.add(new RpmLabel(2).getContent());
upperPanel.add(AnyCommand.createField(config, true, false).getContent());
command = AnyCommand.createField(config, true, false);
upperPanel.add(command.getContent());
upperPanel.add(new URLLabel(EngineSnifferPanel.HELP_TEXT, HELP_URL));
pauseButton.addActionListener(new
@ -138,6 +140,15 @@ public class SensorSnifferPane {
return content;
}
public ActionListener getTabSelectedListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
command.requestFocus();
}
};
}
private class SensorSnifferCanvas extends JComponent {
@Override
public void paint(Graphics g) {

View File

@ -24,11 +24,12 @@ public class MessagesPane {
}
};
private final JButton fontButton = new JButton("Font");
private final AnyCommand command;
public MessagesPane(final Node config) {
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
AnyCommand command = AnyCommand.createArea(config, config.getProperty(AnyCommand.KEY), true, false);
command = AnyCommand.createArea(config, config.getProperty(AnyCommand.KEY), true, false);
final MessagesPanel upperPanel = new MessagesPanel(command.getContent());
upperPanel.loadFont(config);
@ -67,4 +68,13 @@ public class MessagesPane {
public JComponent getContent() {
return content;
}
public ActionListener getTabSelectedListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
command.requestFocus();
}
};
}
}

View File

@ -72,6 +72,7 @@ public class EngineSnifferPanel {
private final ChartScrollControl scrollControl;
// todo: move it some sort of a singleton?
public final HashMap<String, String> channelName2PhysicalPin = new HashMap<>();
private AnyCommand command;
private boolean isPaused;
@ -112,8 +113,8 @@ public class EngineSnifferPanel {
upperPanel.add(new RpmLabel(2).getContent());
if (!LinkManager.isLogViewer()) {
JComponent command = AnyCommand.createField(config, "chartsize " + EFI_DEFAULT_CHART_SIZE, true, true).getContent();
upperPanel.add(command);
command = AnyCommand.createField(config, "chartsize " + EFI_DEFAULT_CHART_SIZE, true, true);
upperPanel.add(command.getContent());
}
upperPanel.add(zoomControl);
@ -320,6 +321,16 @@ public class EngineSnifferPanel {
scrollControl.reset();
}
public ActionListener getTabSelectedListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (command != null)
command.requestFocus();
}
};
}
/**
* The job of this comparator is to place Spark charts before Injection charts
*/

View File

@ -29,6 +29,7 @@ public class AnyCommand {
private AnyCommand(final JTextComponent text, final Node config, String defaultCommand, final boolean listenToCommands, boolean withCommandCaption) {
this.text = text;
installCtrlEnterAction();
text.setText(defaultCommand);
content.setBorder(BorderFactory.createLineBorder(Color.PINK));
if (withCommandCaption) {
@ -61,7 +62,6 @@ public class AnyCommand {
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
@ -83,6 +83,19 @@ public class AnyCommand {
// todo: limit the length of text in the text field
}
private void installCtrlEnterAction() {
text.setToolTipText("Ctrl-Enter to send");
text.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
java.awt.event.InputEvent.CTRL_DOWN_MASK),
"sendKey");
text.getActionMap().put("sendKey", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
send();
}
});
}
private void send() {
String cmd = text.getText();
for (String s : cmd.split("\n"))
@ -123,6 +136,10 @@ public class AnyCommand {
this.content = content;
}
public void requestFocus() {
text.requestFocus();
}
interface Listener {
void onSend();
}