Skip to content

Commit 127f9a9

Browse files
committed
1.0.0-SNAPSHOT
1 parent 0096491 commit 127f9a9

18 files changed

+150
-504
lines changed

pom.xml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@
1313
<description>Editor for Panda Language</description>
1414
<url>http://panda-lang.org/</url>
1515

16+
<licenses>
17+
<license>
18+
<name>Apache License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
1624
<dependencies>
1725
<dependency>
1826
<groupId>org.panda_lang</groupId>
1927
<artifactId>panda</artifactId>
2028
<version>1.0.0-SNAPSHOT</version>
29+
<scope>compile</scope>
2130
</dependency>
2231
</dependencies>
2332

24-
<licenses>
25-
<license>
26-
<name>Apache License, Version 2.0</name>
27-
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
28-
<distribution>repo</distribution>
29-
</license>
30-
</licenses>
33+
<repositories>
34+
<repository>
35+
<id>sonatype.org</id>
36+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
37+
</repository>
38+
</repositories>
3139

3240
<properties>
3341
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/org/panda_lang/editor/Editor.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ public void start(Stage stage) throws Exception {
2020
instance = this;
2121

2222
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
23+
Initializer.init();
2324

2425
Parent root = FXMLLoader.load(getClass().getResource("/fxml/interface.fxml"));
26+
Scene scene = new Scene(root, bounds.getWidth() * 0.6, bounds.getHeight() * 0.5);
2527
//root.getStylesheets().add("/css/dark.css");
26-
Scene scene = new Scene(root, bounds.getWidth(), bounds.getHeight());
2728

28-
stage.setX(bounds.getMinX());
29-
stage.setY(bounds.getMinY());
30-
stage.setWidth(bounds.getWidth());
31-
stage.setHeight(bounds.getHeight());
29+
stage.setWidth(bounds.getWidth() * 0.7);
30+
stage.setHeight(bounds.getHeight() * 0.6);
31+
stage.setX((bounds.getWidth() - stage.getWidth()) / 2);
32+
stage.setY((bounds.getHeight() - stage.getHeight()) / 2);
3233

3334
stage.setTitle("Panda Editor");
3435
stage.setScene(scene);
3536

36-
stage.setMaximized(true);
37-
3837
stage.show();
3938
}
4039

src/main/java/org/panda_lang/editor/FilesTree.java renamed to src/main/java/org/panda_lang/editor/Explorer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import java.util.HashMap;
1111
import java.util.Map;
1212

13-
public class FilesTree {
13+
public class Explorer {
1414

1515
private final TreeView<String> tree;
1616
private final Image defaultFileIcon;
1717
private final Image defaultFolderIcon;
1818
private final Map<TreeItem<String>, File> files;
1919

20-
public FilesTree(TreeView<String> tree) {
20+
public Explorer(TreeView<String> tree) {
2121
this.tree = tree;
2222
this.files = new HashMap<>();
2323
this.defaultFileIcon = new Image(getClass().getResourceAsStream("/icons/defaultFileIcon.png"));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.panda_lang.editor;
2+
3+
import javafx.scene.web.WebView;
4+
import org.panda_lang.panda.util.IOUtils;
5+
6+
public class Initializer {
7+
8+
public static void init() {
9+
WebView wv = new WebView();
10+
ResourcesBuilder resourcesBuilder = new ResourcesBuilder(Editor.class);
11+
resourcesBuilder.importCss("/html/cm/codemirror.min.css");
12+
resourcesBuilder.importCss("/html/cm/default.min.css");
13+
resourcesBuilder.importCss("/html/cm/dracula.min.css");
14+
resourcesBuilder.importScript("/html/cm/codemirror.min.js");
15+
resourcesBuilder.importScript("/html/cm/clike.min.js");
16+
String template = IOUtils.convertStreamToString(Editor.class.getResourceAsStream("/html/tab.html"))
17+
.replace("${imports}", resourcesBuilder.toString());
18+
wv.getEngine().loadContent(template);
19+
}
20+
21+
}

src/main/java/org/panda_lang/editor/Interface.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package org.panda_lang.editor;
22

3-
import javafx.event.ActionEvent;
4-
import javafx.event.EventHandler;
53
import javafx.fxml.FXML;
64
import javafx.fxml.FXMLLoader;
75
import javafx.fxml.Initializable;
86
import javafx.scene.control.*;
9-
import javafx.scene.input.KeyEvent;
107
import javafx.stage.DirectoryChooser;
118
import javafx.stage.FileChooser;
12-
import org.panda_lang.panda.util.IOUtils;
139

1410
import java.io.File;
1511
import java.io.IOException;
@@ -24,7 +20,7 @@ public class Interface implements Initializable {
2420
@FXML private TreeView<String> filesTree;
2521
@FXML private TabPane tabPane;
2622

27-
private FilesTree tree;
23+
private Explorer tree;
2824

2925
@Override
3026
public void initialize(URL url, ResourceBundle rb) {
@@ -46,7 +42,7 @@ public void initialize(URL url, ResourceBundle rb) {
4642
});
4743
menuFileExit.setOnAction(event -> System.exit(-1));
4844

49-
this.tree = new FilesTree(filesTree);
45+
this.tree = new Explorer(filesTree);
5046
this.tree.open(new File("./"));
5147
}
5248

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.panda_lang.editor;
2+
3+
public class ResourcesBuilder {
4+
5+
private final Class clazz;
6+
private final StringBuilder stringBuilder;
7+
8+
public ResourcesBuilder(Class clazz) {
9+
this.clazz = clazz;
10+
this.stringBuilder = new StringBuilder();
11+
}
12+
13+
public void importCss(String file) {
14+
stringBuilder.append("<link rel=\"stylesheet\" href=\"");
15+
stringBuilder.append(Editor.class.getResource(file).toExternalForm());
16+
stringBuilder.append("\">");
17+
}
18+
19+
public void importScript(String file) {
20+
stringBuilder.append("<script src=\"");
21+
stringBuilder.append(Editor.class.getResource(file).toExternalForm());
22+
stringBuilder.append("\"></script>");
23+
}
24+
25+
@Override
26+
public String toString() {
27+
return this.stringBuilder.toString();
28+
}
29+
30+
}

src/main/java/org/panda_lang/editor/TabInterface.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package org.panda_lang.editor;
22

3-
import javafx.concurrent.Worker;
4-
import javafx.event.EventHandler;
53
import javafx.fxml.FXML;
64
import javafx.fxml.Initializable;
75
import javafx.scene.control.Tab;
86
import javafx.scene.control.TabPane;
9-
import javafx.scene.control.TextArea;
107
import javafx.scene.input.KeyCode;
118
import javafx.scene.input.KeyCodeCombination;
129
import javafx.scene.input.KeyCombination;
13-
import javafx.scene.input.KeyEvent;
1410
import javafx.scene.web.WebEngine;
1511
import javafx.scene.web.WebView;
1612
import org.panda_lang.panda.util.IOUtils;
@@ -21,13 +17,27 @@
2117

2218
public class TabInterface implements Initializable {
2319

20+
private static final String template;
21+
2422
@FXML private Tab tab;
2523
@FXML private WebView webView;
2624

2725
private String title;
2826
private WebEngine engine;
2927
private boolean changes;
3028

29+
static {
30+
ResourcesBuilder resourcesBuilder = new ResourcesBuilder(Editor.class);
31+
resourcesBuilder.importCss("/html/cm/codemirror.min.css");
32+
resourcesBuilder.importCss("/html/cm/default.min.css");
33+
resourcesBuilder.importCss("/html/cm/dracula.min.css");
34+
resourcesBuilder.importScript("/html/cm/codemirror.min.js");
35+
resourcesBuilder.importScript("/html/cm/clike.min.js");
36+
37+
template = IOUtils.convertStreamToString(Editor.class.getResourceAsStream("/html/tab.html"))
38+
.replace("${imports}", resourcesBuilder.toString());
39+
}
40+
3141
@Override
3242
public void initialize(URL location, ResourceBundle resources) {
3343
engine = webView.getEngine();
@@ -51,10 +61,8 @@ public void run(TabPane pane, File file) {
5161
content = content.replace("\n", "\\n");
5262
content = content.replace("\r", "\\n");
5363

54-
String url = getClass().getResource("/html/area.html").toExternalForm();
55-
5664
// {initData}
57-
engine.load(url);
65+
engine.loadContent(template);
5866
webView.setUserData(file);
5967

6068
// {tab.anem}
@@ -64,11 +72,12 @@ public void run(TabPane pane, File file) {
6472
// {add}
6573
pane.getTabs().add(tab);
6674
pane.getSelectionModel().select(tab);
75+
int selected = pane.getSelectionModel().getSelectedIndex();
6776

6877
// {accelerators}
6978
webView.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_ANY), () -> {
7079
File f = (File) webView.getUserData();
71-
IOUtils.overrideFile(f, (String) engine.executeScript("getSource();"));
80+
IOUtils.overrideFile(f, (String) engine.executeScript("editor.getValue()"));
7281
tab.setText(title);
7382
changes = false;
7483
});
@@ -78,7 +87,9 @@ public void run(TabPane pane, File file) {
7887
engine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
7988
switch (newState) {
8089
case SUCCEEDED:
81-
engine.executeScript("editor.setValue('" + source + "');");
90+
if (!pane.getSelectionModel().isSelected(selected)) return;
91+
webView.setVisible(true);
92+
engine.executeScript("editor.setValue('" + source + "')");
8293
break;
8394
}
8495
});

src/main/resources/html/area.html

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/main/resources/html/cm/clike.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/html/cm/codemirror.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)