Scrollable stable message list in the rusefi_Console fix #3303

hopefully good enough for progress
This commit is contained in:
rusefillc 2021-10-03 18:06:44 -04:00
parent d3033273cb
commit 00579af8a0
11 changed files with 76 additions and 28 deletions

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20210930;
public static final int CONSOLE_VERSION = 20211003;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -4,6 +4,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.ui.MessagesView;
import com.rusefi.ui.UIContext;
import com.rusefi.ui.storage.PersistentConfiguration;
import com.rusefi.ui.util.UiUtils;
import org.jetbrains.annotations.NotNull;
@ -18,7 +19,7 @@ public class BenchTestPane {
private final JPanel content = new JPanel(new GridLayout(2, 5));
private final UIContext uiContext;
public BenchTestPane(UIContext uiContext) {
public BenchTestPane(UIContext uiContext, PersistentConfiguration config) {
this.uiContext = uiContext;
content.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
@ -45,7 +46,7 @@ public class BenchTestPane {
return Fields.CMD_REBOOT_DFU;
}
}.getContent());
content.add(new MessagesView().messagesScroll);
content.add(new MessagesView(config.getRoot()).messagesScroll);
}
private Component grabPerformanceTrace() {

View File

@ -96,14 +96,14 @@ public class ConsoleUI {
uiContext.DetachedRepositoryINSTANCE.init(getConfig().getRoot().getChild("detached"));
uiContext.DetachedRepositoryINSTANCE.load();
if (!linkManager.isLogViewer())
tabbedPane.addTab("Gauges", new GaugesPanel(uiContext, getConfig().getRoot().getChild("gauges"), tabbedPane.paneSettings).getContent());
tabbedPane.addTab("Gauges", new GaugesPanel(uiContext, getConfig().getRoot().getChild("gauges")).getContent());
if (!linkManager.isLogViewer()) {
MessagesPane messagesPane = new MessagesPane(uiContext, getConfig().getRoot().getChild("messages"));
tabbedPaneAdd("Messages", messagesPane.getContent(), messagesPane.getTabSelectedListener());
}
if (!linkManager.isLogViewer()) {
tabbedPane.addTab("Bench Test", new BenchTestPane(uiContext).getContent());
tabbedPane.addTab("Bench Test", new BenchTestPane(uiContext, getConfig()).getContent());
if (tabbedPane.paneSettings.showEtbPane)
tabbedPane.addTab("ETB", new ETBPane(uiContext).getContent());
tabbedPane.addTab("Presets", new PresetsPane(uiContext).getContent());

View File

@ -79,7 +79,7 @@ public class GaugesPanel {
private final JPanel messagesPanel = new JPanel(new BorderLayout());
private final JSplitPane middleSplitPanel;
public GaugesPanel(UIContext uiContext, final Node config, PaneSettings paneSettings) {
public GaugesPanel(UIContext uiContext, final Node config) {
this.uiContext = uiContext;
gauges = new GaugesGrid(DEFAULT_ROWS, DEFAULT_COLUMNS);
this.config = config;
@ -101,7 +101,7 @@ public class GaugesPanel {
content.add(middleSplitPanel, BorderLayout.CENTER);
content.add(new WarningPanel().getPanel(), BorderLayout.SOUTH);
content.add(new WarningPanel(config).getPanel(config), BorderLayout.SOUTH);
applyShowFlags();
final int splitLocation = config.getIntProperty(SPLIT_LOCATION, -1);
@ -203,7 +203,7 @@ public class GaugesPanel {
}
private void prepareMessagesPanel() {
MessagesPanel mp = new MessagesPanel(null);
MessagesPanel mp = new MessagesPanel(null, config);
messagesPanel.add(BorderLayout.NORTH, mp.getButtonPanel());
messagesPanel.add(BorderLayout.CENTER, mp.getMessagesScroll());
}

View File

@ -0,0 +1,40 @@
package com.rusefi.ui;
import com.rusefi.ui.storage.Node;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class LogSizeControl {
private static final String LINES = "SCREEN_LOG_LINES";
private final JPanel content = new JPanel(new FlowLayout());
public LogSizeControl(Node config) {
content.add(new JLabel("On screen lines: "));
JTextField lines = new JTextField(8);
content.add(lines);
lines.setText(Integer.toString(getValue(config)));
lines.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ev) {
int value;
try {
value = Integer.parseInt(lines.getText());
} catch (NumberFormatException ex) {
return;
}
config.setProperty(LINES, Integer.toString(value));
}
});
}
public static int getValue(Node config) {
return config.getIntProperty(LINES, 1000);
}
public Component getContent() {
return content;
}
}

View File

@ -13,6 +13,10 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* One of console top level tabs
* @see MessagesPanel
*/
public class MessagesPane {
private static final String HELP_URL = "http://rusefi.com/wiki/index.php?title=Manual:Software:dev_console_commands";
@ -30,7 +34,7 @@ public class MessagesPane {
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
command = AnyCommand.createArea(uiContext, config, config.getProperty(AnyCommand.KEY), true, false);
final MessagesPanel upperPanel = new MessagesPanel(command.getContent());
final MessagesPanel upperPanel = new MessagesPanel(command.getContent(), config);
upperPanel.loadFont(config);
JPanel middlePanel = new JPanel(new BorderLayout());
@ -49,7 +53,7 @@ public class MessagesPane {
statsPanel.add(new RpmLabel(uiContext).getContent());
statsPanel.add(new IdleLabel());
statsPanel.add(new WarningPanel().getPanel());
statsPanel.add(new WarningPanel(config).getPanel(config));
content.add(statsPanel, BorderLayout.SOUTH);
@ -70,11 +74,6 @@ public class MessagesPane {
}
public ActionListener getTabSelectedListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
command.requestFocus();
}
};
return e -> command.requestFocus();
}
}

View File

@ -15,17 +15,19 @@ import java.awt.*;
* Andrey Belomutskiy, (c) 2013-2020
*
* @see AnyCommand
* @see MessagesView
*/
public class MessagesPanel {
private static final String FONT_SIZE = "font_size";
private static final String FONT_NAME = "font_name";
private final MessagesView messagesView = new MessagesView();
private final MessagesView messagesView;
private final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
public MessagesPanel(JComponent extraButton) {
public MessagesPanel(JComponent extraButton, Node config) {
JPanel middlePanel = new JPanel(new BorderLayout());
messagesView = new MessagesView(config);
middlePanel.add(messagesView.messagesScroll, BorderLayout.CENTER);
// buttonPanel.setBorder(BorderFactory.createLineBorder(Color.cyan));

View File

@ -4,6 +4,7 @@ import com.opensr5.Logger;
import com.rusefi.core.EngineState;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.CommandQueue;
import com.rusefi.ui.storage.Node;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@ -21,13 +22,15 @@ public class MessagesView {
private final Style bold;
private final Style italic;
private final Node config;
private boolean isPaused;
protected final JTextPane messages = new JTextPane();
public final JScrollPane messagesScroll = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public MessagesView() {
public MessagesView(Node config) {
this.config = config;
messages.setEditable(false);
JPopupMenu menu = createPopupMenu();
@ -105,8 +108,9 @@ does not work? maybe wrong UI colors since control is not editable?
private void append(String line, Class clazz) {
Document d = messages.getDocument();
if (d.getLength() > MAX_SIZE)
clearMessages(d);
int logSizeControl = LogSizeControl.getValue(config);
if (d.getLength() > logSizeControl)
clearMessages(d, logSizeControl);
try {
d.insertString(d.getLength(), line + "\r\n", getStyle(clazz));
messages.select(d.getLength(), d.getLength());
@ -129,9 +133,9 @@ does not work? maybe wrong UI colors since control is not editable?
}
private void clearMessages(Document d) {
private void clearMessages(Document d, int logSizeControl) {
try {
d.remove(0, d.getLength());
d.remove(0, d.getLength() - logSizeControl / 2);
} catch (BadLocationException e) {
throw new IllegalStateException(e);
}
@ -139,7 +143,7 @@ does not work? maybe wrong UI colors since control is not editable?
public void clear() {
Document d = messages.getDocument();
clearMessages(d);
clearMessages(d, 0);
}
public void setPaused(boolean isPaused) {

View File

@ -3,6 +3,7 @@ package com.rusefi.ui;
import com.rusefi.FileLog;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.util.UiUtils;
import javax.swing.*;
@ -26,7 +27,7 @@ public class WarningPanel {
}
});
public WarningPanel() {
public WarningPanel(Node config) {
label.setForeground(Color.red);
panel.add(label);
@ -65,6 +66,7 @@ public class WarningPanel {
panel.add(reset);
// todo: only display label if logs are being recorded
panel.add(new JLabel(FileLog.LOG_INFO_TEXT));
panel.add(new LogSizeControl(config).getContent());
}
private void clear() {
@ -72,7 +74,7 @@ public class WarningPanel {
reset.setEnabled(false);
}
public JPanel getPanel() {
public JPanel getPanel(Node config) {
return panel;
}
}

View File

@ -167,7 +167,7 @@ public class EngineSnifferPanel {
});
mainPanel.add(chartPanel, BorderLayout.CENTER);
mainPanel.add(new WarningPanel().getPanel(), BorderLayout.SOUTH);
mainPanel.add(new WarningPanel(config).getPanel(config), BorderLayout.SOUTH);
}
private void setPaused(JButton pauseButton, boolean isPaused) {

View File

@ -50,7 +50,7 @@ public class LuaScriptPanel {
//centerPanel.add(, BorderLayout.WEST);
JPanel messagesPanel = new JPanel(new BorderLayout());
MessagesPanel mp = new MessagesPanel(null);
MessagesPanel mp = new MessagesPanel(null, config);
messagesPanel.add(BorderLayout.NORTH, mp.getButtonPanel());
messagesPanel.add(BorderLayout.CENTER, mp.getMessagesScroll());