Skip to content

Commit f94fb91

Browse files
cyaffledzikoysk
authored andcommitted
Added console, maintaining compatibility with Pand, code cleanup and fixes.
1 parent 42bc896 commit f94fb91

File tree

7 files changed

+131
-37
lines changed

7 files changed

+131
-37
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.panda_lang</groupId>
66
<artifactId>lily</artifactId>
7-
<version>1.0.2-SNAPSHOT</version>
7+
<version>1.0.3-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>Lily</name>

src/main/java/org/panda_lang/lily/Lily.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,19 @@ public void start(Stage stage) throws Exception {
3434

3535
// Lily's ui
3636
Parent root = FXMLLoader.load(getClass().getResource("/ui/interface.fxml"));
37-
Scene scene = new Scene(root, bounds.getWidth() - 20, bounds.getHeight() * 0.5);
37+
Scene scene = new Scene(root, bounds.getWidth() - 2, bounds.getHeight() * 0.9);
3838
root.getStylesheets().add("/ui/themes/default_material.css");
3939
stage.getIcons().add(new Image("/ui/icons/icon.png"));
4040

4141
// Lily's position
42-
stage.setWidth(bounds.getWidth() - 20);
43-
stage.setHeight(bounds.getHeight() * 0.8);
42+
stage.setWidth(bounds.getWidth() - 2);
43+
stage.setHeight(bounds.getHeight() * 0.9);
4444
stage.setX((bounds.getWidth() - stage.getWidth()) / 2);
4545
stage.setY((bounds.getHeight() - stage.getHeight()) / 2);
4646

4747
// Others
4848
panda.initializeDefaultElements();
4949
stage.setTitle("Lily the Panda IDE");
50-
stage.setMaximized(true);
5150
stage.setScene(scene);
5251
stage.show();
5352
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.panda_lang.lily.ui;
2+
3+
import javafx.scene.control.TextArea;
4+
import javafx.scene.layout.BorderPane;
5+
import javafx.scene.layout.Region;
6+
7+
import java.io.IOException;
8+
import java.io.OutputStream;
9+
import java.io.PrintStream;
10+
11+
public class ConsolePane extends BorderPane {
12+
13+
private static ConsolePane instance;
14+
private final ConsoleOutputStream consoleOutputStream;
15+
private final TextArea textArea;
16+
17+
protected ConsolePane() {
18+
this.textArea = new TextArea();
19+
this.consoleOutputStream = new ConsoleOutputStream(this);
20+
21+
instance = this;
22+
setCenter(textArea);
23+
System.setOut(new PrintStream(consoleOutputStream));
24+
}
25+
26+
public void bind(Region parent) {
27+
prefWidthProperty().bind(parent.prefWidthProperty());
28+
prefHeightProperty().bind(parent.prefHeightProperty());
29+
}
30+
31+
public void clear() {
32+
textArea.setText("");
33+
}
34+
35+
public void write(char c) {
36+
textArea.setText(textArea.getText() + c);
37+
}
38+
39+
public TextArea getTextArea() {
40+
return textArea;
41+
}
42+
43+
public ConsoleOutputStream getConsoleOutputStream() {
44+
return consoleOutputStream;
45+
}
46+
47+
public static ConsolePane getInstance() {
48+
return instance == null ? new ConsolePane() : instance;
49+
}
50+
51+
private class ConsoleOutputStream extends OutputStream {
52+
53+
private final ConsolePane consolePane;
54+
55+
public ConsoleOutputStream(ConsolePane consolePane) {
56+
this.consolePane = consolePane;
57+
}
58+
59+
@Override
60+
public void write(int b) throws IOException {
61+
consolePane.write((char) b);
62+
}
63+
64+
}
65+
66+
}

src/main/java/org/panda_lang/lily/ui/Interface.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class Interface implements Initializable {
3636
@FXML private MenuItem menuRunRun;
3737
@FXML private MenuItem menuHelpAbout;
3838

39-
@FXML private SplitPane splitPane;
39+
@FXML private SplitPane workspacePane;
40+
@FXML private SplitPane workspaceEditorPane;
41+
@FXML private SplitPane workspaceAssistantsPane;
4042
@FXML private TreeView<String> filesTree;
4143
@FXML private TabPane tabPane;
4244

@@ -48,8 +50,10 @@ public void initialize(URL url, ResourceBundle rb) {
4850
// Initialize Interface
4951
Lily.instance.initAnInterface(this);
5052

51-
// SplitPane
52-
splitPane.setDividerPositions(0.25, 0.75);
53+
// Dividers
54+
workspacePane.setDividerPositions(0.75, 0.25);
55+
workspaceEditorPane.setDividerPositions(0.25, 0.75);
56+
workspaceAssistantsPane.setDividerPositions(1, 0);
5357

5458
// ProjectTree
5559
tree = new ProjectTree(filesTree);
@@ -99,6 +103,12 @@ protected void initializeActions() {
99103

100104
// Action: Run -> Run
101105
menuRunRun.setOnAction(event -> {
106+
ConsolePane consolePane = ConsolePane.getInstance();
107+
consolePane.clear();
108+
workspaceAssistantsPane.getItems().clear();
109+
workspaceAssistantsPane.getItems().add(consolePane);
110+
consolePane.bind(workspaceAssistantsPane);
111+
102112
String source = (String) getCurrentTab().getWebEngine().executeScript("editor.getValue()");
103113
PandaScript pandaScript = Lily.instance.getPanda().getPandaLoader().loadSimpleScript(source);
104114
pandaScript.call(MethodBlock.class, "main");

src/main/resources/ui/interface.fxml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import javafx.scene.control.*?><?import javafx.scene.layout.*?>
3+
<?import javafx.scene.control.*?><?import javafx.scene.layout.*?><?import javafx.scene.web.WebView?>
44
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="1000.0" fx:controller="org.panda_lang.lily.ui.Interface">
55
<top>
66
<BorderPane prefHeight="50.0" prefWidth="1000.0" BorderPane.alignment="CENTER">
@@ -48,12 +48,15 @@
4848
</BorderPane>
4949
</top>
5050
<center>
51-
<SplitPane fx:id="splitPane" dividerPositions="0.1" prefHeight="200.0" prefWidth="1000.0" BorderPane.alignment="CENTER">
52-
<TreeView fx:id="filesTree" editable="true" prefHeight="200.0" prefWidth="400.0"/>
53-
<TabPane fx:id="tabPane" tabClosingPolicy="SELECTED_TAB" prefHeight="200.0" prefWidth="600.0"/>
51+
<SplitPane fx:id="workspacePane" orientation="VERTICAL" prefWidth="1000.0" prefHeight="320.0">
52+
<SplitPane fx:id="workspaceEditorPane" orientation="HORIZONTAL" prefHeight="250.0" prefWidth="1000.0">
53+
<TreeView fx:id="filesTree" editable="true" prefWidth="400.0" prefHeight="250.0"/>
54+
<TabPane fx:id="tabPane" tabClosingPolicy="SELECTED_TAB" prefWidth="600.0" prefHeight="250.0" />
55+
</SplitPane>
56+
<SplitPane fx:id="workspaceAssistantsPane" orientation="HORIZONTAL" prefWidth="1000.0" prefHeight="70.0" />
5457
</SplitPane>
5558
</center>
5659
<bottom>
57-
<ToolBar prefHeight="20.0" prefWidth="1000.0" BorderPane.alignment="CENTER"/>
60+
<ToolBar fx:id="bottomToolBar" prefHeight="20.0" prefWidth="1000.0" BorderPane.alignment="CENTER" />
5861
</bottom>
5962
</BorderPane>

src/main/resources/ui/themes/dark_material.css

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@
2626

2727
.tool-bar {
2828
-fx-background-color: #212121;
29-
-fx-border-width: 1px 0px 0px 0px;
29+
-fx-border-width: 1 0 0 0;
3030
-fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c;
3131
}
3232

3333
/* SplitPane */
3434
.split-pane {
35-
-fx-margin: 0px;
36-
-fx-padding: 0px;
37-
-fx-border-width: 1px 0px 0px 0px;
35+
-fx-margin: 0;
36+
-fx-padding: 0;
37+
-fx-border-width: 1 0 0 0;
3838
-fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c;
3939
-fx-background-color: #212121;
4040
}
4141

42-
.split-pane:horizontal > .split-pane-divider {
43-
-fx-padding: 0 0 0 0;
42+
.split-pane:vertical > .split-pane-divider, .split-pane:horizontal > .split-pane-divider {
43+
-fx-padding: 0 0 0 10;
4444
-fx-border-color: #212121;
4545
-fx-background-color: #212121;
4646
}
4747

4848
/* ScrollBar */
49-
.scroll-bar:horizontal, .scroll-bar:vertical {
49+
.scroll-bar:horizontal, .scroll-bar:vertical {
5050
-fx-background-color: transparent;
5151
}
5252

@@ -94,12 +94,11 @@
9494
/* TabPane */
9595
.tab-pane {
9696
-fx-background-color: #282829;
97-
-fx-border-width: 0px 0px 0px 0px;
97+
-fx-border-width: 0 0 0 0;
9898
}
9999

100100
.tab-pane *.tab-header-background {
101101
-fx-background-color: null;
102-
-fx-effect: innershadow(two-pass-box , transparent , 0, 0.0 , 0 , 0);
103102
}
104103

105104
.tab {

src/main/resources/ui/themes/default_material.css

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* Pane */
2+
.pane {
3+
-fx-background-color: #2a2a2a;
4+
}
15

26
/* Menu */
37
.menu-bar {
@@ -9,7 +13,7 @@
913
}
1014

1115
.menu .label {
12-
-fx-text-fill: #FFFFFF;
16+
-fx-text-fill: #ffffff;
1317
}
1418

1519
.context-menu {
@@ -26,45 +30,46 @@
2630

2731
.tool-bar {
2832
-fx-background-color: #2a2a2a;
29-
-fx-border-width: 1px 0px 0px 0px;
33+
-fx-border-width: 1 0 0 0;
3034
-fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c;
3135
}
3236

3337
/* SplitPane */
3438
.split-pane {
35-
-fx-margin: 0px;
36-
-fx-padding: 0px;
37-
-fx-border-width: 1px 0px 0px 0px;
39+
-fx-margin: 0;
40+
-fx-padding: 0;
41+
-fx-border-width: 1 0 0 0;
3842
-fx-border-color: #2c2c2c #2c2c2c #2c2c2c #2c2c2c;
3943
-fx-background-color: #2a2a2a;
4044
}
4145

42-
.split-pane:horizontal > .split-pane-divider {
46+
.split-pane:horizontal > .split-pane-divider, .split-pane:vertical > .split-pane-divider {
4347
-fx-padding: 0 0 0 0;
44-
-fx-border-color: #2a2a2a;
48+
-fx-border-color: #333333;
4549
-fx-background-color: #2a2a2a;
4650
}
4751

4852
/* ScrollBar */
4953
.scroll-bar:horizontal, .scroll-bar:vertical {
50-
-fx-background-color: transparent;
54+
-fx-background-color: #2a2a2a;
5155
}
5256

5357
.scroll-bar:horizontal .track, .scroll-bar:vertical .track {
54-
-fx-background-color: transparent;
58+
-fx-background-color: #2a2a2a;
5559
}
5660

5761
.scroll-bar:horizontal .increment-button, .scroll-bar:horizontal .decrement-button {
58-
-fx-background-color: transparent;
62+
-fx-background-color: #2a2a2a;
5963
-fx-padding: 0 -2 0 -2;
6064
}
6165

6266
.scroll-bar:vertical .increment-button, .scroll-bar:vertical .decrement-button {
63-
-fx-background-color: transparent;
64-
-fx-padding: -2 0 -2 0;
67+
-fx-background-color: #2a2a2a;
68+
-fx-padding: 0 -2 0 -2;
6569
}
6670

6771
.scroll-bar .increment-arrow, .scroll-bar .decrement-arrow {
72+
-fx-background-color: #2a2a2a;
6873
-fx-shape: " ";
6974
}
7075

@@ -99,7 +104,6 @@
99104

100105
.tab-pane *.tab-header-background {
101106
-fx-background-color: #2a2a2a;
102-
-fx-effect: innershadow(two-pass-box, transparent, 0, 0, 0, 0);
103107
-fx-border-width: 0 0 0 0;
104108
}
105109

@@ -121,12 +125,25 @@
121125
}
122126

123127
.tab-close-button {
124-
-fx-font-size: 8px;
128+
-fx-font-size: 8;
125129
}
126130

127131
/* WebView */
128132
.web-view {
129133
-fx-focus-color: transparent;
130134
-fx-faint-focus-color: transparent;
131-
-fx-border-width: 0px;
135+
-fx-border-width: 0;
136+
}
137+
138+
/* TextArea */
139+
.text-area, .text-area .content {
140+
width: 100%;
141+
-fx-background-color: #2d2d30;
142+
-fx-font-family: monospace;
143+
-fx-font-size: 12;
144+
-fx-border-width: 0 0 0 0;
145+
-fx-text-fill: #ffffff;
146+
-fx-border-radius: 0;
147+
-fx-border-color: #2d2d30;
148+
-fx-background-radius: 0;
132149
}

0 commit comments

Comments
 (0)