From f94fb91b2075a7d4cb5e5ce945e011f1ca51e1ae Mon Sep 17 00:00:00 2001 From: cyanidepanda Date: Sun, 1 May 2016 22:54:03 +0200 Subject: [PATCH] Added console, maintaining compatibility with Pand, code cleanup and fixes. --- pom.xml | 2 +- src/main/java/org/panda_lang/lily/Lily.java | 7 +- .../org/panda_lang/lily/ui/ConsolePane.java | 66 +++++++++++++++++++ .../org/panda_lang/lily/ui/Interface.java | 16 ++++- src/main/resources/ui/interface.fxml | 13 ++-- .../resources/ui/themes/dark_material.css | 17 +++-- .../resources/ui/themes/default_material.css | 47 ++++++++----- 7 files changed, 131 insertions(+), 37 deletions(-) create mode 100644 src/main/java/org/panda_lang/lily/ui/ConsolePane.java diff --git a/pom.xml b/pom.xml index dfe48c9..d6c7fb5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.panda_lang lily - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT jar Lily diff --git a/src/main/java/org/panda_lang/lily/Lily.java b/src/main/java/org/panda_lang/lily/Lily.java index 26ad47b..e455630 100644 --- a/src/main/java/org/panda_lang/lily/Lily.java +++ b/src/main/java/org/panda_lang/lily/Lily.java @@ -34,20 +34,19 @@ public void start(Stage stage) throws Exception { // Lily's ui Parent root = FXMLLoader.load(getClass().getResource("/ui/interface.fxml")); - Scene scene = new Scene(root, bounds.getWidth() - 20, bounds.getHeight() * 0.5); + Scene scene = new Scene(root, bounds.getWidth() - 2, bounds.getHeight() * 0.9); root.getStylesheets().add("/ui/themes/default_material.css"); stage.getIcons().add(new Image("/ui/icons/icon.png")); // Lily's position - stage.setWidth(bounds.getWidth() - 20); - stage.setHeight(bounds.getHeight() * 0.8); + stage.setWidth(bounds.getWidth() - 2); + stage.setHeight(bounds.getHeight() * 0.9); stage.setX((bounds.getWidth() - stage.getWidth()) / 2); stage.setY((bounds.getHeight() - stage.getHeight()) / 2); // Others panda.initializeDefaultElements(); stage.setTitle("Lily the Panda IDE"); - stage.setMaximized(true); stage.setScene(scene); stage.show(); } diff --git a/src/main/java/org/panda_lang/lily/ui/ConsolePane.java b/src/main/java/org/panda_lang/lily/ui/ConsolePane.java new file mode 100644 index 0000000..263898d --- /dev/null +++ b/src/main/java/org/panda_lang/lily/ui/ConsolePane.java @@ -0,0 +1,66 @@ +package org.panda_lang.lily.ui; + +import javafx.scene.control.TextArea; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Region; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +public class ConsolePane extends BorderPane { + + private static ConsolePane instance; + private final ConsoleOutputStream consoleOutputStream; + private final TextArea textArea; + + protected ConsolePane() { + this.textArea = new TextArea(); + this.consoleOutputStream = new ConsoleOutputStream(this); + + instance = this; + setCenter(textArea); + System.setOut(new PrintStream(consoleOutputStream)); + } + + public void bind(Region parent) { + prefWidthProperty().bind(parent.prefWidthProperty()); + prefHeightProperty().bind(parent.prefHeightProperty()); + } + + public void clear() { + textArea.setText(""); + } + + public void write(char c) { + textArea.setText(textArea.getText() + c); + } + + public TextArea getTextArea() { + return textArea; + } + + public ConsoleOutputStream getConsoleOutputStream() { + return consoleOutputStream; + } + + public static ConsolePane getInstance() { + return instance == null ? new ConsolePane() : instance; + } + + private class ConsoleOutputStream extends OutputStream { + + private final ConsolePane consolePane; + + public ConsoleOutputStream(ConsolePane consolePane) { + this.consolePane = consolePane; + } + + @Override + public void write(int b) throws IOException { + consolePane.write((char) b); + } + + } + +} diff --git a/src/main/java/org/panda_lang/lily/ui/Interface.java b/src/main/java/org/panda_lang/lily/ui/Interface.java index c61ecfb..6e02834 100644 --- a/src/main/java/org/panda_lang/lily/ui/Interface.java +++ b/src/main/java/org/panda_lang/lily/ui/Interface.java @@ -36,7 +36,9 @@ public class Interface implements Initializable { @FXML private MenuItem menuRunRun; @FXML private MenuItem menuHelpAbout; - @FXML private SplitPane splitPane; + @FXML private SplitPane workspacePane; + @FXML private SplitPane workspaceEditorPane; + @FXML private SplitPane workspaceAssistantsPane; @FXML private TreeView filesTree; @FXML private TabPane tabPane; @@ -48,8 +50,10 @@ public void initialize(URL url, ResourceBundle rb) { // Initialize Interface Lily.instance.initAnInterface(this); - // SplitPane - splitPane.setDividerPositions(0.25, 0.75); + // Dividers + workspacePane.setDividerPositions(0.75, 0.25); + workspaceEditorPane.setDividerPositions(0.25, 0.75); + workspaceAssistantsPane.setDividerPositions(1, 0); // ProjectTree tree = new ProjectTree(filesTree); @@ -99,6 +103,12 @@ protected void initializeActions() { // Action: Run -> Run menuRunRun.setOnAction(event -> { + ConsolePane consolePane = ConsolePane.getInstance(); + consolePane.clear(); + workspaceAssistantsPane.getItems().clear(); + workspaceAssistantsPane.getItems().add(consolePane); + consolePane.bind(workspaceAssistantsPane); + String source = (String) getCurrentTab().getWebEngine().executeScript("editor.getValue()"); PandaScript pandaScript = Lily.instance.getPanda().getPandaLoader().loadSimpleScript(source); pandaScript.call(MethodBlock.class, "main"); diff --git a/src/main/resources/ui/interface.fxml b/src/main/resources/ui/interface.fxml index 00ac360..60fd44a 100644 --- a/src/main/resources/ui/interface.fxml +++ b/src/main/resources/ui/interface.fxml @@ -1,6 +1,6 @@ - + @@ -48,12 +48,15 @@
- - - + + + + + +
- +
diff --git a/src/main/resources/ui/themes/dark_material.css b/src/main/resources/ui/themes/dark_material.css index 1697c8e..2db925a 100644 --- a/src/main/resources/ui/themes/dark_material.css +++ b/src/main/resources/ui/themes/dark_material.css @@ -26,27 +26,27 @@ .tool-bar { -fx-background-color: #212121; - -fx-border-width: 1px 0px 0px 0px; + -fx-border-width: 1 0 0 0; -fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c; } /* SplitPane */ .split-pane { - -fx-margin: 0px; - -fx-padding: 0px; - -fx-border-width: 1px 0px 0px 0px; + -fx-margin: 0; + -fx-padding: 0; + -fx-border-width: 1 0 0 0; -fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c; -fx-background-color: #212121; } - .split-pane:horizontal > .split-pane-divider { - -fx-padding: 0 0 0 0; + .split-pane:vertical > .split-pane-divider, .split-pane:horizontal > .split-pane-divider { + -fx-padding: 0 0 0 10; -fx-border-color: #212121; -fx-background-color: #212121; } /* ScrollBar */ - .scroll-bar:horizontal, .scroll-bar:vertical { + .scroll-bar:horizontal, .scroll-bar:vertical { -fx-background-color: transparent; } @@ -94,12 +94,11 @@ /* TabPane */ .tab-pane { -fx-background-color: #282829; - -fx-border-width: 0px 0px 0px 0px; + -fx-border-width: 0 0 0 0; } .tab-pane *.tab-header-background { -fx-background-color: null; - -fx-effect: innershadow(two-pass-box , transparent , 0, 0.0 , 0 , 0); } .tab { diff --git a/src/main/resources/ui/themes/default_material.css b/src/main/resources/ui/themes/default_material.css index 7b7e9e5..3ffb52f 100644 --- a/src/main/resources/ui/themes/default_material.css +++ b/src/main/resources/ui/themes/default_material.css @@ -1,3 +1,7 @@ +/* Pane */ + .pane { + -fx-background-color: #2a2a2a; + } /* Menu */ .menu-bar { @@ -9,7 +13,7 @@ } .menu .label { - -fx-text-fill: #FFFFFF; + -fx-text-fill: #ffffff; } .context-menu { @@ -26,45 +30,46 @@ .tool-bar { -fx-background-color: #2a2a2a; - -fx-border-width: 1px 0px 0px 0px; + -fx-border-width: 1 0 0 0; -fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c; } /* SplitPane */ .split-pane { - -fx-margin: 0px; - -fx-padding: 0px; - -fx-border-width: 1px 0px 0px 0px; + -fx-margin: 0; + -fx-padding: 0; + -fx-border-width: 1 0 0 0; -fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c; -fx-background-color: #2a2a2a; } - .split-pane:horizontal > .split-pane-divider { + .split-pane:horizontal > .split-pane-divider, .split-pane:vertical > .split-pane-divider { -fx-padding: 0 0 0 0; - -fx-border-color: #2a2a2a; + -fx-border-color: #333333; -fx-background-color: #2a2a2a; } /* ScrollBar */ .scroll-bar:horizontal, .scroll-bar:vertical { - -fx-background-color: transparent; + -fx-background-color: #2a2a2a; } .scroll-bar:horizontal .track, .scroll-bar:vertical .track { - -fx-background-color: transparent; + -fx-background-color: #2a2a2a; } .scroll-bar:horizontal .increment-button, .scroll-bar:horizontal .decrement-button { - -fx-background-color: transparent; + -fx-background-color: #2a2a2a; -fx-padding: 0 -2 0 -2; } .scroll-bar:vertical .increment-button, .scroll-bar:vertical .decrement-button { - -fx-background-color: transparent; - -fx-padding: -2 0 -2 0; + -fx-background-color: #2a2a2a; + -fx-padding: 0 -2 0 -2; } .scroll-bar .increment-arrow, .scroll-bar .decrement-arrow { + -fx-background-color: #2a2a2a; -fx-shape: " "; } @@ -99,7 +104,6 @@ .tab-pane *.tab-header-background { -fx-background-color: #2a2a2a; - -fx-effect: innershadow(two-pass-box, transparent, 0, 0, 0, 0); -fx-border-width: 0 0 0 0; } @@ -121,12 +125,25 @@ } .tab-close-button { - -fx-font-size: 8px; + -fx-font-size: 8; } /* WebView */ .web-view { -fx-focus-color: transparent; -fx-faint-focus-color: transparent; - -fx-border-width: 0px; + -fx-border-width: 0; + } + +/* TextArea */ + .text-area, .text-area .content { + width: 100%; + -fx-background-color: #2d2d30; + -fx-font-family: monospace; + -fx-font-size: 12; + -fx-border-width: 0 0 0 0; + -fx-text-fill: #ffffff; + -fx-border-radius: 0; + -fx-border-color: #2d2d30; + -fx-background-radius: 0; } \ No newline at end of file