Commit bc05d208 authored by Sarah Grebing's avatar Sarah Grebing

Line highlighting for Java source is working now

parent 32c4c671
Pipeline #12296 failed with stage
in 1 minute and 35 seconds
......@@ -158,10 +158,6 @@ public class DebuggerMainWindowController implements Initializable {
scriptController.getDebugPositionHighlighter().highlight(newValue);
});
imodel.highlightedJavaLinesProperty().addListener((observable, oldValue, newValue) -> {
javaArea.enableCurrentLineHighlightingProperty();
});
Utils.addDebugListener(proofTreeController.currentGoalsProperty(), Utils::reprKeyDataList);
Utils.addDebugListener(proofTreeController.currentSelectedGoalProperty(), Utils::reprKeyData);
Utils.addDebugListener(proofTreeController.currentHighlightNodeProperty());
......@@ -190,20 +186,27 @@ public class DebuggerMainWindowController implements Initializable {
showCodeDock(null);
});
//add listener for linehighlighting when changing selection in inspectionview
getInspectionViewsController().getActiveInspectionViewTab().getModel().highlightedJavaLinesProperty().
addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
javaArea.linesToHighlightProperty().set(newValue);
} else {
javaArea.linesToHighlightProperty().set(FXCollections.emptyObservableSet());
}
});
javaCode.addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
try {
javaArea.setText(newValue);
javaArea.enableLineHighlightingProperty();
} catch (Exception e) {
LOGGER.catching(e);
}
}
});
}
......
......@@ -46,14 +46,8 @@ public class InspectionView extends BorderPane {
if (newValue != null && newValue.getData() != null) {
getSequentView().setNode(newValue.getData().getNode());
getSequentView().setGoal(newValue.getData().getGoal());
// TODO weigl: get marked lines of the program, and set it
/*model.get().highlightedJavaLinesProperty().get()
.clear();*/
//set Java lines to highlight in model
model.get().setHighlightedJavaLines(FXCollections.observableSet(newValue.getData().constructLinesSet()));
System.out.println(newValue.getData().constructLinesSet());
}
});
......
......@@ -2,23 +2,18 @@ package edu.kit.formal.gui.controls;
import antlrgrammars.Java8Lexer;
import javafx.beans.property.SimpleSetProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;
import org.antlr.v4.runtime.CharStreams;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import java.util.Collections;
import java.util.Set;
/**
* @author Alexander Weigl
* @version 1 (03.06.17)
*/
public class JavaArea extends BaseCodeArea {
private ANTLR4LexerHighlighter highlighter = new ANTLR4LexerHighlighter((s) -> new Java8Lexer(CharStreams.fromString(s)));
//set with current lines to highlight
private SimpleSetProperty<Integer> linesToHighlight = new SimpleSetProperty<>(this, "JavaLinesToHighlight");
public JavaArea() {
init();
}
......@@ -35,6 +30,36 @@ public class JavaArea extends BaseCodeArea {
getStyleClass().add("java-area");
textProperty().addListener(
(a, b, c) -> updateView());
linesToHighlightProperty().addListener((observable, oldValue, newValue) -> {
setEnableLineHighlighting(true);
unHighlightOldSet(oldValue);
highlightLineSet();
});
}
/**
* Remove old highlights
*
* @param oldValue
*/
private void unHighlightOldSet(ObservableSet<Integer> oldValue) {
if (oldValue != null) {
oldValue.forEach(integer -> {
lineToClass.put(integer - 1, "un-highlight-line");
highlightLines();
});
}
}
/**
* highlight new lines
*/
private void highlightLineSet() {
linesToHighlightProperty().get().forEach(integer -> {
lineToClassProperty().get().put(integer - 1, "line-highlight");
});
highlightLines();
}
private void updateView() {
......@@ -42,4 +67,20 @@ public class JavaArea extends BaseCodeArea {
setStyleSpans(0, highlighter.highlight(textProperty().getValue()));
highlightLines();
}
public ObservableSet<Integer> getLinesToHighlight() {
return linesToHighlight.get();
}
public void setLinesToHighlight(ObservableSet<Integer> linesToHighlight) {
this.linesToHighlight.set(linesToHighlight);
}
public SimpleSetProperty<Integer> linesToHighlightProperty() {
return linesToHighlight;
}
}
......@@ -24,7 +24,7 @@ public class InspectionModel {
private final MapProperty<GoalNode, Color> colorofEachGoalNodeinListView = new SimpleMapProperty<>(FXCollections.observableHashMap());
//private final StringProperty javaString = new SimpleStringProperty();
private final SetProperty<Integer> highlightedJavaLines = new SimpleSetProperty<>(FXCollections.observableSet(), "highlightedJavaLines");
private final BooleanProperty closable = new SimpleBooleanProperty(this, "INspectionViewClosableProperty");
private final BooleanProperty closable = new SimpleBooleanProperty(this, "InspectionViewClosableProperty");
private final BooleanProperty isInterpreterTab = new SimpleBooleanProperty();
private ObjectProperty<Mode> mode = new SimpleObjectProperty<>();
......
......@@ -179,6 +179,13 @@
-fx-fill: firebrick !important;
-fx-underline: true;
}
.line-highlight {
-rtfx-background-color: @blue;
}
.line-un-highlight {
-rtfx-background-color: @base3;
}
}
/**********************************************************************************************************************/
......@@ -226,7 +233,7 @@
.closed-sequent-view {
-fx-font-size: 14pt;
-fx-background-color: @red;
-fx-background-color: @green;
.sequent-highlight {
-rtfx-background-color: @base01;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment