From 00e4304a70e3674f6a30aef38f55b732fd896f75 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 2 Jan 2022 16:44:02 -0500 Subject: [PATCH] live data progress: UI flickering --- .../com/rusefi/livedata/LiveDataParserPanel.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 0169686ba4..2d870703e4 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 @@ -73,12 +73,10 @@ public class LiveDataParserPanel { } catch (BadLocationException e) { throw new IllegalStateException(e); } + if (r == null) + return; // when would this happen? g.drawString(value.toString(), r.x, r.y); - - } - - } }; private final VariableValueSource valueSource; @@ -139,7 +137,14 @@ public class LiveDataParserPanel { StyleContext sc = StyleContext.getDefaultStyleContext(); - StyledDocument styledDocument = text.getStyledDocument(); + SimpleAttributeSet attributes = new SimpleAttributeSet(); + DefaultStyledDocument styledDocument = new DefaultStyledDocument(); + try { + styledDocument.insertString(0, sourceCode, attributes); + } catch (BadLocationException e) { + throw new IllegalStateException(e); + } + AttributeSet oldSet = styledDocument.getCharacterElement(0).getAttributes(); styledDocument.setCharacterAttributes(0, sourceCode.length(), sc.getEmptySet(), true); @@ -158,6 +163,7 @@ public class LiveDataParserPanel { styledDocument.setCharacterAttributes(range.getStart(), range.getLength(), s, false); } }, tree); + text.setDocument(styledDocument); } @NotNull