Commit d8b9ba9b authored by Alexander Weigl's avatar Alexander Weigl

embedd a docking framework

* works, but needed some adaptions or fixes
parent f0a7e8cf
Pipeline #11949 failed with stage
in 1 minute and 25 seconds
[submodule "doc"] [submodule "doc"]
path = doc path = doc
url = git@git.scc.kit.edu:xt9634/ProofScriptParser.wiki.git url = git@git.scc.kit.edu:xt9634/ProofScriptParser.wiki.git
[submodule "lib/AnchorFX"]
path = lib/AnchorFX
url = https://github.com/alexbodogit/AnchorFX.git
[submodule "lib/DockFX"]
path = lib/DockFX
url = https://github.com/RobertBColton/DockFX.git
Subproject commit 0773eb4419e126d2cfa18863306ad1c48050e9b6
Subproject commit bbbc57653d6a0bc7463539de30fec075443c0843
...@@ -72,6 +72,51 @@ ...@@ -72,6 +72,51 @@
</pluginManagement> </pluginManagement>
<plugins> <plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>released-version</id>
<goals>
<goal>released-version</goal>
</goals>
</execution>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>lib/AnchorFX/src/main/java</source>
<source>lib/DockFX/src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>lib/AnchorFX/src/main/resources</directory>
<directory>lib/DockFX/src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId> <artifactId>jaxb2-maven-plugin</artifactId>
......
...@@ -14,6 +14,7 @@ import javafx.scene.Scene; ...@@ -14,6 +14,7 @@ import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dockfx.DockNode;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
...@@ -33,15 +34,14 @@ public class ProofScriptDebugger extends Application { ...@@ -33,15 +34,14 @@ public class ProofScriptDebugger extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
try { try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/DebuggerMain.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/DebuggerMain.fxml"));
Parent root = fxmlLoader.load(); Parent root = fxmlLoader.load();
//DebuggerMainWindowController controller = fxmlLoader.<DebuggerMainWindowController>getController(); //DebuggerMainWindowController controller = fxmlLoader.<DebuggerMainWindowController>getController();
Scene scene = new Scene(root); Scene scene = new Scene(root);
scene.getStylesheets().addAll( scene.getStylesheets().addAll(
getClass().getResource("debugger-ui.css").toExternalForm() getClass().getResource("debugger-ui.css").toExternalForm(),
DockNode.class.getResource("default.css").toExternalForm()
); );
primaryStage.setTitle(NAME + " (" + VERSION + ") with KeY:" + KEY_VERSION); primaryStage.setTitle(NAME + " (" + VERSION + ") with KeY:" + KEY_VERSION);
primaryStage.setScene(scene); primaryStage.setScene(scene);
......
package edu.kit.formal.gui.controller; package edu.kit.formal.gui.controller;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView;
import de.uka.ilkd.key.proof.init.ProofInputException; import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.speclang.Contract; import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.controls.*; import edu.kit.formal.gui.controls.*;
...@@ -10,16 +12,18 @@ import edu.kit.formal.interpreter.KeYProofFacade; ...@@ -10,16 +12,18 @@ import edu.kit.formal.interpreter.KeYProofFacade;
import edu.kit.formal.interpreter.data.KeyData; import edu.kit.formal.interpreter.data.KeyData;
import edu.kit.formal.interpreter.graphs.PTreeNode; import edu.kit.formal.interpreter.graphs.PTreeNode;
import edu.kit.formal.interpreter.graphs.ProofTreeController; import edu.kit.formal.interpreter.graphs.ProofTreeController;
import edu.kit.formal.proofscriptparser.Facade;
import edu.kit.formal.proofscriptparser.ast.ProofScript; import edu.kit.formal.proofscriptparser.ast.ProofScript;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue; import javafx.beans.value.ObservableBooleanValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
...@@ -28,6 +32,10 @@ import org.antlr.v4.runtime.RecognitionException; ...@@ -28,6 +32,10 @@ import org.antlr.v4.runtime.RecognitionException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dockfx.DockNode;
import org.dockfx.DockPane;
import org.dockfx.DockPos;
import org.dockfx.demo.DockFX;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -48,20 +56,23 @@ import java.util.concurrent.Executors; ...@@ -48,20 +56,23 @@ import java.util.concurrent.Executors;
*/ */
public class DebuggerMainWindowController implements Initializable { public class DebuggerMainWindowController implements Initializable {
private static final Logger LOGGER = LogManager.getLogger(DebuggerMainWindowController.class); private static final Logger LOGGER = LogManager.getLogger(DebuggerMainWindowController.class);
private SimpleBooleanProperty debugMode = new SimpleBooleanProperty(false); private SimpleBooleanProperty debugMode = new SimpleBooleanProperty(false);
@FXML @FXML
private Pane rootPane; private Pane rootPane;
@FXML @FXML
private SplitPane splitPane; private DockPane dockStation;
//@FXML
//private SplitPane splitPane;
/*********************************************************************************************************** /***********************************************************************************************************
* Code Area * Code Area
* **********************************************************************************************************/ * **********************************************************************************************************/
@FXML //@FXML
private ScriptTabPane tabPane; private ScriptController scriptController;
/*********************************************************************************************************** /***********************************************************************************************************
* MenuBar * MenuBar
...@@ -142,6 +153,12 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -142,6 +153,12 @@ public class DebuggerMainWindowController implements Initializable {
alert.showAndWait(); alert.showAndWait();
} }
private ObservableList<ScriptArea> openScripts = FXCollections.observableArrayList();
private WelcomePane welcomePane = new WelcomePane();
private DockNode welcomePaneDock = new DockNode(welcomePane,"Welcome", new MaterialDesignIconView(MaterialDesignIcon.ACCOUNT));
/** /**
* @param location * @param location
* @param resources * @param resources
...@@ -149,8 +166,23 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -149,8 +166,23 @@ public class DebuggerMainWindowController implements Initializable {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
setDebugMode(false); setDebugMode(false);
scriptController = new ScriptController(dockStation);
Image dockImage = new Image(DockFX.class.getResource("docknode.png").toExternalForm());
welcomePaneDock.dock(dockStation, DockPos.LEFT);
/*
DockNode scripts = AnchorageSystem.createDock("Scripts", scriptController);
DockNode a = AnchorageSystem.createDock("Abc", new ScriptArea());
DockNode b = AnchorageSystem.createDock("Def", new ScriptArea());
toolbar.getChildrenUnmodifiable().forEach( scripts.dock(dockStation, DockNode.DockPosition.CENTER);
a.dock(dockStation, DockNode.DockPosition.LEFT);
b.dock(dockStation, DockNode.DockPosition.LEFT);
*/
/* toolbar.getChildrenUnmodifiable().forEach(
n -> n.setOnMouseEntered(statusBar.getTooltipHandler())); n -> n.setOnMouseEntered(statusBar.getTooltipHandler()));
buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler()); buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler());
...@@ -162,11 +194,11 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -162,11 +194,11 @@ public class DebuggerMainWindowController implements Initializable {
/** /**
* create a new inspectionviewtab that is the main tab and not closable * create a new inspectionviewtab that is the main tab and not closable
*/ */
inspectionViewTabPane.createNewInspectionViewTab(model, true); // inspectionViewTabPane.createNewInspectionViewTab(model, true);
//TODO this does not work any more //TODO this does not work any more
/*tabPane.getActiveScriptAreaTab().getScriptArea().getMarkedLines().addListener((SetChangeListener<Integer>) change -> { /*scriptController.getActiveScriptAreaTab().getScriptArea().getMarkedRegions().addListener((SetChangeListener<Integer>) change -> {
blocker.getBreakpoints().clear(); blocker.getBreakpoints().clear();
blocker.getBreakpoints().addAll(change.getSet()); blocker.getBreakpoints().addAll(change.getSet());
});*/ });*/
...@@ -178,7 +210,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -178,7 +210,7 @@ public class DebuggerMainWindowController implements Initializable {
//model.currentGoalNodesProperty().bind(pc.currentGoalsProperty()); //model.currentGoalNodesProperty().bind(pc.currentGoalsProperty());
CustomTabPaneSkin skin = new CustomTabPaneSkin(tabPane); //CustomTabPaneSkin skin = new CustomTabPaneSkin(scriptController);
} }
...@@ -197,7 +229,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -197,7 +229,7 @@ public class DebuggerMainWindowController implements Initializable {
// int line = lm.getLine(scriptArea.getCaretPosition()); // int line = lm.getLine(scriptArea.getCaretPosition());
// int inLine = lm.getCharInLine(scriptArea.getCaretPosition()); // int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
//*/ //*/
// ib.ignoreLinesUntil(tabPane.getSelectedScriptArea().getCaretPosition()); // ib.ignoreLinesUntil(scriptController.getSelectedScriptArea().getCaretPosition());
// executeScript(ib, true); // executeScript(ib, true);
} }
...@@ -217,7 +249,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -217,7 +249,7 @@ public class DebuggerMainWindowController implements Initializable {
this.debugMode.set(debugMode); this.debugMode.set(debugMode);
statusBar.publishMessage("Parse ..."); statusBar.publishMessage("Parse ...");
try { try {
List<ProofScript> scripts = Facade.getAST(tabPane.getSelectedScriptArea().getText()); List<ProofScript> scripts = scriptController.getCombinedAST();
statusBar.publishMessage("Creating new Interpreter instance ..."); statusBar.publishMessage("Creating new Interpreter instance ...");
ib.setScripts(scripts); ib.setScripts(scripts);
...@@ -235,18 +267,11 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -235,18 +267,11 @@ public class DebuggerMainWindowController implements Initializable {
model.setCurrentGoalNodes(newValue); model.setCurrentGoalNodes(newValue);
}); });
pc.startHighlightPositionPropertyProperty().addListener((observable, oldValue, newValue) -> { pc.currentHighlightNodeProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.getLineNumber() > -1) { scriptController.getPostMortemHighlighter().highlight(newValue);
tabPane.getSelectedScriptArea().highlightStmt(newValue.getLineNumber(), "line-highlight-postmortem");
}
if (oldValue.getLineNumber() > -1) {
tabPane.getSelectedScriptArea().removeHighlightStmt(oldValue.getLineNumber());
}
}); });
//highlight signature of main script //highlight signature of main script
tabPane.getSelectedScriptArea().setDebugMark(scripts.get(0).getStartPosition().getLineNumber()); //scriptController.setDebugMark(scripts.get(0).getStartPosition().getLineNumber());
} catch (RecognitionException e) { } catch (RecognitionException e) {
showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e); showExceptionDialog("Antlr Exception", "", "Could not parse scripts.", e);
} }
...@@ -278,7 +303,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -278,7 +303,7 @@ public class DebuggerMainWindowController implements Initializable {
private void saveScript(File scriptFile) { private void saveScript(File scriptFile) {
try { try {
FileUtils.write(scriptFile, tabPane.getSelectedScriptArea().getText(), Charset.defaultCharset()); scriptController.saveCurrentScriptAs(scriptFile);
} catch (IOException e) { } catch (IOException e) {
showExceptionDialog("Could not save sourceName", "blubb", "...fsfsfsf fsa", e); showExceptionDialog("Could not save sourceName", "blubb", "...fsfsfsf fsa", e);
} }
...@@ -296,7 +321,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -296,7 +321,7 @@ public class DebuggerMainWindowController implements Initializable {
assert scriptFile != null; assert scriptFile != null;
try { try {
String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset()); String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
ScriptArea area = tabPane.createNewTab(scriptFile); ScriptArea area = scriptController.createNewTab(scriptFile);
openScript(code, area); openScript(code, area);
model.setScriptFile(scriptFile); model.setScriptFile(scriptFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -432,10 +457,14 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -432,10 +457,14 @@ public class DebuggerMainWindowController implements Initializable {
public void stopDebugMode(ActionEvent actionEvent) { public void stopDebugMode(ActionEvent actionEvent) {
//linenumberMainscript from model? //linenumberMainscript from model?
//tabPane.getActiveScriptAreaTab().getScriptArea().removeHighlightStmt(lineNumberMainScript); //scriptController.getActiveScriptAreaTab().getScriptArea().removeHighlightStmt(lineNumberMainScript);
//inspectionViewTabPane.getInspectionViewTab.clear(); //inspectionViewTabPane.getInspectionViewTab.clear();
} }
public void newScript(ActionEvent actionEvent) {
scriptController.newScript();
}
public class ContractLoaderService extends Service<List<Contract>> { public class ContractLoaderService extends Service<List<Contract>> {
@Override @Override
protected Task<List<Contract>> createTask() { protected Task<List<Contract>> createTask() {
......
package edu.kit.formal.gui.controls; package edu.kit.formal.gui.controls;
import com.sun.org.apache.xpath.internal.operations.Mod;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView;
import de.uka.ilkd.key.logic.op.IProgramMethod; import de.uka.ilkd.key.logic.op.IProgramMethod;
...@@ -19,8 +18,8 @@ import javafx.scene.Node; ...@@ -19,8 +18,8 @@ import javafx.scene.Node;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.SplitPane; import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
...@@ -30,7 +29,7 @@ import java.io.StringWriter; ...@@ -30,7 +29,7 @@ import java.io.StringWriter;
* *
* @author S. Grebing * @author S. Grebing
*/ */
public class InspectionViewTab extends Tab { public class InspectionViewTab extends BorderPane {
public GoalOptionsMenu goalOptionsMenu = new GoalOptionsMenu(); public GoalOptionsMenu goalOptionsMenu = new GoalOptionsMenu();
@FXML @FXML
private SectionPane sectionPaneJavaCode; private SectionPane sectionPaneJavaCode;
......
package edu.kit.formal.gui.controls; package edu.kit.formal.gui.controls;
import edu.kit.formal.gui.model.RootModel; import edu.kit.formal.gui.model.RootModel;
import javafx.fxml.FXML; import org.dockfx.DockNode;
import javafx.scene.control.TabPane;
/** /**
* TabPane on the right side of the GUI containing the inspection view as tabs * TabPane on the right side of the GUI containing the inspection view as tabs
*/ */
public class InspectionViewTabPane extends TabPane { public class InspectionViewTabPane {
/** /**
* active tab in which the interpreter resp. Debugger state is shown. * active tab in which the interpreter resp. Debugger state is shown.
* This tab can be changed and later on in this tab it should be possible to select proof commands * This tab can be changed and later on in this tab it should be possible to select proof commands
* All other tabs are only post morten tabs which cannot be shown * All other tabs are only post morten tabs which cannot be shown
*/ */
private InspectionViewTab activeInterpreterTab; private final InspectionViewTab activeInterpreterTab = new InspectionViewTab();
private final DockNode activeInterpreterTabDock = new DockNode(activeInterpreterTab, "Active");
@FXML
private InspectionViewTab inspectionViewTab;
public InspectionViewTabPane() {
super();
Utils.createWithFXML(this);
}
public void setActiveInterpreterTab(InspectionViewTab activeInterpreterTab) {
this.activeInterpreterTab = activeInterpreterTab;
}
public InspectionViewTab getActiveInspectionViewTab() { public InspectionViewTab getActiveInspectionViewTab() {
return this.activeInterpreterTab; return this.activeInterpreterTab;
...@@ -61,8 +47,8 @@ public class InspectionViewTabPane extends TabPane { ...@@ -61,8 +47,8 @@ public class InspectionViewTabPane extends TabPane {
getActiveInspectionViewTab().getGoalView().getSelectionModel().select(fresh); getActiveInspectionViewTab().getGoalView().getSelectionModel().select(fresh);
/* TODO get lines of active statements marked lines /* TODO get lines of active statements marked lines
javaSourceCode.getMarkedLines().clear(); javaSourceCode.getMarkedRegions().clear();
javaSourceCode.getMarkedLines().addAll( javaSourceCode.getMarkedRegions().addAll(
);*/ );*/
}); });
......
...@@ -9,11 +9,13 @@ import edu.kit.formal.proofscriptparser.ScriptLanguageLexer; ...@@ -9,11 +9,13 @@ import edu.kit.formal.proofscriptparser.ScriptLanguageLexer;
import edu.kit.formal.proofscriptparser.ast.ProofScript; import edu.kit.formal.proofscriptparser.ast.ProofScript;
import edu.kit.formal.proofscriptparser.lint.LintProblem; import edu.kit.formal.proofscriptparser.lint.LintProblem;
import edu.kit.formal.proofscriptparser.lint.LinterStrategy; import edu.kit.formal.proofscriptparser.lint.LinterStrategy;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.binding.BooleanBinding; import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.collections.ObservableSet;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Insets; import javafx.geometry.Insets;
...@@ -27,6 +29,8 @@ import javafx.scene.paint.Color; ...@@ -27,6 +29,8 @@ import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.scene.text.FontPosture; import javafx.scene.text.FontPosture;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
...@@ -35,9 +39,7 @@ import org.fxmisc.richtext.CharacterHit; ...@@ -35,9 +39,7 @@ import org.fxmisc.richtext.CharacterHit;
import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.MouseOverTextEvent; import org.fxmisc.richtext.MouseOverTextEvent;
import org.fxmisc.richtext.model.NavigationActions; import org.fxmisc.richtext.model.NavigationActions;
import org.fxmisc.richtext.model.Paragraph;
import org.fxmisc.richtext.model.StyleSpans; import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyledText;
import org.reactfx.collection.LiveList; import org.reactfx.collection.LiveList;
import org.reactfx.value.Val; import org.reactfx.value.Val;
...@@ -52,13 +54,16 @@ import java.util.function.IntFunction; ...@@ -52,13 +54,16 @@ import java.util.function.IntFunction;
*/ */
public class ScriptArea extends CodeArea { public class ScriptArea extends CodeArea {
private final ObjectProperty<File> filePath = new SimpleObjectProperty<>(); private final ObjectProperty<File> filePath = new SimpleObjectProperty<>();
private final BooleanProperty dirty = new SimpleBooleanProperty(this, "dirty", false);
/** /**
* Lines to highlight? * Lines to highlight?
*/ */
private final SetProperty<Integer> markedLines = private final SetProperty<RegionStyle> markedRegions =
new SimpleSetProperty<>(FXCollections.observableSet()); new SimpleSetProperty<>(FXCollections.observableSet());
/** /**
* set by {@link ScriptTabPane} * set by {@link ScriptController}
*/ */
private final ObjectProperty<MainScriptIdentifier> mainScript = new SimpleObjectProperty<>(); private final ObjectProperty<MainScriptIdentifier> mainScript = new SimpleObjectProperty<>();
...@@ -82,15 +87,14 @@ public class ScriptArea extends CodeArea { ...@@ -82,15 +87,14 @@ public class ScriptArea extends CodeArea {
//getStylesheets().add(getClass().getResource("script-keywords.css").toExternalForm()); //getStylesheets().add(getClass().getResource("script-keywords.css").toExternalForm());
getStyleClass().add("script-area"); getStyleClass().add("script-area");
textProperty().addListener((prop, oldValue, newValue) -> { textProperty().addListener((prop, oldValue, newValue) -> {
if (newValue.length() != 0) { dirty.set(true);
clearStyle(0, newValue.length());
StyleSpans<? extends Collection<String>> spans = highlighter.highlight(newValue);
if (spans != null) setStyleSpans(0, spans);
}
highlightProblems();
updateMainScriptMarker(); updateMainScriptMarker();
updateHighlight();
highlightProblems();
}); });
markedRegions.addListener((InvalidationListener) o -> updateHighlight());
/* .successionEnds(Duration.ofMillis(100)) /* .successionEnds(Duration.ofMillis(100))
.hook(collectionRichTextChange -> this.getUndoManager().mark()) .hook(collectionRichTextChange -> this.getUndoManager().mark())
.supplyTask(this::computeHighlightingAsync).awaitLatest(richChanges()) .supplyTask(this::computeHighlightingAsync).awaitLatest(richChanges())
...@@ -121,6 +125,19 @@ public class ScriptArea extends CodeArea { ...@@ -121,6 +125,19 @@ public class ScriptArea extends CodeArea {
contextMenu = new ScriptAreaContextMenu(); contextMenu = new ScriptAreaContextMenu();
} }
private void updateHighlight() {
String newValue = getText();
if (newValue.length() != 0) {
clearStyle(0, newValue.length());
StyleSpans<? extends Collection<String>> spans = highlighter.highlight(newValue);
if (spans != null) setStyleSpans(0, spans);
}
markedRegions.forEach(reg -> {
setStyle(reg.start, reg.stop, Collections.singleton(reg.clazzName));
});
}
private void updateMainScriptMarker() { private void updateMainScriptMarker() {
try { try {
MainScriptIdentifier ms = mainScript.get(); MainScriptIdentifier ms = mainScript.get();
...@@ -211,49 +228,6 @@ public class ScriptArea extends CodeArea { ...@@ -211,49 +228,6 @@ public class ScriptArea extends CodeArea {
a.setBreakpoint(!a.isBreakpoint()); a.setBreakpoint(!a.isBreakpoint());
} }
/**
* Highlight line given by the characterindex
*
* @param lineNumber
*/
public void highlightStmt(int lineNumber, String cssStyleTag) {
//calculate line number from characterindex
//int lineNumber = this.offsetToPosition(chrIdx, Bias.Forward).getMajor();
Paragraph<Collection<String>, StyledText<Collection<String>>, Collection<String>> paragraph = this.getParagraph(lineNumber);
//calculate start and endposition
//int startPos = getAbsolutePosition(this.offsetToPosition(chrIdx, Bias.Forward).getMajor(), 0);
int startPos = getAbsolutePosition(lineNumber, 0);
int length = paragraph.length();
//highlight line
this.setStyle(startPos, startPos + length, Collections.singleton(cssStyleTag));
}
/**
* Remove the highlighting of a statement
*
* @param lineNumber
*/
public void removeHighlightStmt(int lineNumber) {
highlightStmt(lineNumber, "line-unhighlight");
}
/**
* Set a mark in the gutter next to the definition of the main script
*
* @param lineNumberOfSigMainScript
*/
public void setDebugMark(int lineNumberOfSigMainScript) {
highlightStmt(lineNumberOfSigMainScript - 1, "line-highlight-mainScript");
}
public void unsetDebugMark(int lineNumberOfSigMainScript) {
removeHighlightStmt(lineNumberOfSigMainScript - 1);
}
public File getFilePath() { public File getFilePath() {
return filePath.get(); return filePath.get();
} }
...@@ -558,12 +532,45 @@ public class ScriptArea extends CodeArea { ...@@ -558,12 +532,45 @@ public class ScriptArea extends CodeArea {
} }