From 93c9382c86037e04930634598a967df020dc58ec Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 11 Jan 2022 00:15:42 -0500 Subject: [PATCH] live data progress --- .../main/java/com/rusefi/CodeWalkthrough.java | 2 +- .../rusefi/livedata/LiveDataParserPanel.java | 37 ++++++++++--------- .../java/com/rusefi/ui/livedata/Range.java | 8 ++++ .../livedata/LiveDataParserPanelSandbox.java | 9 ++++- .../com/rusefi/livedata/LiveDataView.java | 2 + 5 files changed, 38 insertions(+), 20 deletions(-) rename java_console/ui/src/{main => test}/java/com/rusefi/livedata/LiveDataView.java (96%) diff --git a/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java b/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java index f7cce492e0..7939451141 100644 --- a/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java +++ b/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java @@ -165,7 +165,7 @@ public class CodeWalkthrough { allTerminals.get(i + 1).getText().equals("->") ) { Token token = allTerminals.get(i + 2).getSymbol(); - painter.paintForeground(CONFIG, new Range(token, token)); + painter.paintForeground(CONFIG, Range.create(token, token)); configTokens.add(token); } } diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java index 2084494cca..d2f19223e3 100644 --- a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java +++ b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java @@ -80,11 +80,13 @@ public class LiveDataParserPanel { } }; private final VariableValueSource valueSource; + private final String fileName; private String sourceCode; public LiveDataParserPanel(UIContext uiContext, VariableValueSource valueSource, String fileName) { this.uiContext = uiContext; this.valueSource = valueSource; + this.fileName = fileName; JScrollPane rightScrollPane = new JScrollPane(text, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED); @@ -150,28 +152,27 @@ public class LiveDataParserPanel { // todo: technically we do not need to do the complete re-compile on fresh data arrival just repaint! // todo: split compilation and painting/repainting - parseResult = CodeWalkthrough.applyVariables(valueSource, sourceCode, new SourceCodePainter() { - @Override - public void paintBackground(Color color, Range range) { - AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Background, color); - styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, false); - } + try { + parseResult = CodeWalkthrough.applyVariables(valueSource, sourceCode, new SourceCodePainter() { + @Override + public void paintBackground(Color color, Range range) { + AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Background, color); + styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, false); + } + + @Override + public void paintForeground(Color color, Range range) { + AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Foreground, color); + styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, false); + } + }, tree); + } catch (RuntimeException e) { + throw new IllegalStateException("While " + fileName, e); + } - @Override - public void paintForeground(Color color, Range range) { - AttributeSet s = sc.addAttribute(oldSet, StyleConstants.Foreground, color); - styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, false); - } - }, tree); text.setDocument(styledDocument); } - @NotNull - public static JPanel createLiveDataParserContent(UIContext uiContext, LiveDataView view) { - LiveDataParserPanel panel = createLiveDataParserPanel(uiContext, view.getLiveDataE(), view.getValues(), view.getFileName()); - return panel.getContent(); - } - @NotNull public static LiveDataParserPanel createLiveDataParserPanel(UIContext uiContext, final live_data_e live_data_e, final Field[] values, String fileName) { AtomicReference reference = new AtomicReference<>(); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java b/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java index 386d1e34a3..b548016adb 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java @@ -27,6 +27,14 @@ public class Range { this(context.start, context.stop); } + public static Range create(Token startToken, Token stopToken) { + int start = startToken.getStartIndex(); + int stop = stopToken.getStopIndex() + 1; + if (stop < start) + throw new IllegalStateException("Order issue " + startToken + "/" + stopToken); + return new Range(startToken, stopToken); + } + public int getStart() { return start; } diff --git a/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataParserPanelSandbox.java b/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataParserPanelSandbox.java index 4cf3c0f38d..cabdbac19c 100644 --- a/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataParserPanelSandbox.java +++ b/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataParserPanelSandbox.java @@ -6,6 +6,7 @@ import com.rusefi.ldmp.StateDictionary; import com.rusefi.ui.UIContext; import com.rusefi.ui.livedocs.LiveDocsRegistry; import com.rusefi.ui.util.FrameHelper; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -20,7 +21,7 @@ public class LiveDataParserPanelSandbox { UIContext context = new UIContext(); - JPanel panel = LiveDataParserPanel.createLiveDataParserContent(context, + JPanel panel = createLiveDataParserContent(context, liveDataView); Field[] values = StateDictionary.INSTANCE.getFields(liveDataView.getLiveDataE()); @@ -36,4 +37,10 @@ public class LiveDataParserPanelSandbox { new FrameHelper().showFrame(panel); } + + @NotNull + private static JPanel createLiveDataParserContent(UIContext uiContext, LiveDataView view) { + LiveDataParserPanel panel = LiveDataParserPanel.createLiveDataParserPanel(uiContext, view.getLiveDataE(), view.getValues(), view.getFileName()); + return panel.getContent(); + } } diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataView.java b/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataView.java similarity index 96% rename from java_console/ui/src/main/java/com/rusefi/livedata/LiveDataView.java rename to java_console/ui/src/test/java/com/rusefi/livedata/LiveDataView.java index 2adb93ffcf..0aa1c6611a 100644 --- a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataView.java +++ b/java_console/ui/src/test/java/com/rusefi/livedata/LiveDataView.java @@ -6,8 +6,10 @@ import com.rusefi.enums.live_data_e; import com.rusefi.ldmp.StateDictionary; /** + * todo: kill this legacy class? * @see StateDictionary */ +@Deprecated public enum LiveDataView { // todo: code generate this part of the enum with some BEFORE/AFTER tag? AC_CONTROL(live_data_e.LDS_ac_control, AcControl.VALUES),