re-enable LiveDataPane fix #4842

This commit is contained in:
rusefillc 2022-12-09 23:17:05 -05:00
parent 98a7f5818d
commit 7cbeb3a482
4 changed files with 48 additions and 6 deletions

View File

@ -128,10 +128,7 @@ public class ConsoleUI {
if (!linkManager.isLogViewer())
tabbedPane.addTab("Settings", tabbedPane.settingsTab.createPane());
if (!linkManager.isLogViewer()) {
/**
* re-enable under https://github.com/rusefi/rusefi/issues/4842
tabbedPane.addTab("Live Data", new LiveDataPane(uiContext).getContent());
*/
tabbedPane.addTab("Live Data", LiveDataPane.createLazy(uiContext).getContent());
tabbedPane.addTab("Sensors Live Data", new SensorsLiveDataPane(uiContext).getContent());
}

View File

@ -0,0 +1,33 @@
package com.rusefi.ui;
import com.rusefi.ui.util.UiUtils;
import javax.swing.*;
import java.awt.*;
public abstract class InitOnFirstPaintPanel {
private final JPanel content = new JPanel(new BorderLayout()) {
boolean isFirstPaint = true;
@Override
public void paint(Graphics g) {
if (isFirstPaint) {
content.removeAll();
content.add(createContent(), BorderLayout.CENTER);
UiUtils.trueRepaint(content);
isFirstPaint = false;
}
super.paint(g);
}
};
protected abstract JPanel createContent();
public InitOnFirstPaintPanel() {
content.add(new JLabel("Initializing..."), BorderLayout.CENTER);
}
public JComponent getContent() {
return content;
}
}

View File

@ -42,7 +42,7 @@ public class LiveDataPane {
private final JPanel content = new JPanel(new BorderLayout());
private boolean isPaused;
public LiveDataPane(UIContext uiContext) {
private LiveDataPane(UIContext uiContext) {
long start = System.currentTimeMillis();
JPanel vertical = new JPanel(new MigLayout("wrap 1", "[grow,fill]"));
@ -141,6 +141,16 @@ public class LiveDataPane {
log.info("created in " + (System.currentTimeMillis() - start) + "ms");
}
public static InitOnFirstPaintPanel createLazy(UIContext uiContext) {
InitOnFirstPaintPanel panel = new InitOnFirstPaintPanel() {
@Override
protected JPanel createContent() {
return new LiveDataPane(uiContext).getContent();
}
};
return panel;
}
@NotNull
private JPanel populateLegend() {
JPanel legend = new JPanel(new VerticalFlowLayout());

View File

@ -7,6 +7,8 @@ import javax.swing.*;
public class LiveDataPaneSandbox {
public static void main(String[] args) {
UIContext uiContext = new UIContext();
new FrameHelper(WindowConstants.EXIT_ON_CLOSE).showFrame(new LiveDataPane(uiContext).getContent());
InitOnFirstPaintPanel panel = LiveDataPane.createLazy(uiContext);
new FrameHelper(WindowConstants.EXIT_ON_CLOSE).showFrame(panel.getContent());
}
}