live data progress

This commit is contained in:
rusefillc 2022-01-11 00:15:42 -05:00
parent 742bbb372c
commit 93c9382c86
5 changed files with 38 additions and 20 deletions

View File

@ -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);
}
}

View File

@ -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<byte[]> reference = new AtomicReference<>();

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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),