pull/98/head
James Ball 2022-07-06 08:55:33 +01:00 zatwierdzone przez James H Ball
rodzic 8a6ebcdde3
commit 4882db1239
7 zmienionych plików z 113 dodań i 12 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
See the [changelog](https://github.com/jameshball/osci-render/blob/master/CHANGELOG.md) for changes to this version.
See the [changelog](https://github.com/jameshball/osci-render/blob/master/src/main/resources/CHANGELOG.md) for changes to this version.
Please report any bugs or issues on GitHub or by emailing me at [james@ball.sh](mailto:james@ball.sh).

Wyświetl plik

@ -6,6 +6,7 @@ import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
@ -92,11 +93,9 @@ public class Gui extends Application {
editor = new CodeEditor();
editor.initialize();
editorStage = new Stage();
editorScene = new Scene(editor);
editorScene = new Scene(editor, 900, 600, false, SceneAntialiasing.BALANCED);
editorStage.setScene(editorScene);
editorStage.getIcons().add(new Image(Objects.requireNonNull(Gui.class.getResourceAsStream("/icons/icon.png"))));
editorStage.setWidth(900);
editorStage.setHeight(600);
editor.prefHeightProperty().bind(editorStage.heightProperty());
editor.prefWidthProperty().bind(editorStage.widthProperty());
@ -104,6 +103,7 @@ public class Gui extends Application {
Parent projectSelectRoot = projectSelectLoader.load();
projectSelectController = projectSelectLoader.getController();
projectSelectController.setApplicationLauncher(this::launchMainApplication);
projectSelectController.setOpenBrowser(url -> getHostServices().showDocument(url));
stage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/icons/icon.png"))));
stage.setTitle("osci-render");

Wyświetl plik

@ -1,20 +1,37 @@
package sh.ball.gui.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.html.HTMLAnchorElement;
import sh.ball.gui.ExceptionRunnable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.prefs.Preferences;
import static sh.ball.gui.Gui.logger;
public class ProjectSelectController implements Initializable {
private static final int MAX_ITEMS = 20;
@ -23,6 +40,7 @@ public class ProjectSelectController implements Initializable {
private final Preferences userPreferences = Preferences.userNodeForPackage(getClass());
private final ObservableList<String> recentFiles = FXCollections.observableArrayList();
private ExceptionRunnable launchMainApplication;
private Consumer<String> openBrowser;
@FXML
private ListView<String> recentFilesListView;
@ -30,6 +48,8 @@ public class ProjectSelectController implements Initializable {
private Button newProjectButton;
@FXML
private CheckBox startMutedCheckBox;
@FXML
private WebView changelogWebView;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
@ -48,9 +68,40 @@ public class ProjectSelectController implements Initializable {
try {
launchMainApplication.run();
} catch (Exception ex) {
throw new RuntimeException(ex);
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
});
try {
String changelogHtml = new String(getClass().getResourceAsStream("/html/changelog.html").readAllBytes(), StandardCharsets.UTF_8);
changelogWebView.getEngine().loadContent(changelogHtml);
InputStream changelogInputStream = getClass().getResourceAsStream("/CHANGELOG.md");
String changelog = new String(changelogInputStream.readAllBytes(), StandardCharsets.UTF_8);
changelogWebView.getEngine().getLoadWorker().stateProperty().addListener((e, old, state) -> {
if (state == Worker.State.SUCCEEDED) {
JSObject window = (JSObject) changelogWebView.getEngine().executeScript("window");
window.setMember("changelog", changelog);
changelogWebView.getEngine().executeScript(
"document.getElementById('content').innerHTML = marked.parse(changelog);"
);
Document document = changelogWebView.getEngine().getDocument();
NodeList nodeList = document.getElementsByTagName("a");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node= nodeList.item(i);
EventTarget eventTarget = (EventTarget) node;
eventTarget.addEventListener("click", evt -> {
EventTarget target = evt.getCurrentTarget();
HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
String href = anchorElement.getHref();
openBrowser.accept(href);
evt.preventDefault();
}, false);
}
}
});
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
public void addRecentFile(String path) {
@ -81,4 +132,8 @@ public class ProjectSelectController implements Initializable {
public void setApplicationLauncher(ExceptionRunnable launchMainApplication) {
this.launchMainApplication = launchMainApplication;
}
public void setOpenBrowser(Consumer<String> openBrowser) {
this.openBrowser = openBrowser;
}
}

Wyświetl plik

@ -374,4 +374,15 @@
.label.title .text {
-fx-font-size: 1.5em;
}
.text-area .content {
-fx-background-color: very_dark;
}
.text-area {
-fx-background-color: very_dark;
-fx-border-width: 1px;
-fx-border-radius: 0;
-fx-border-color: white;
}

Wyświetl plik

@ -7,19 +7,22 @@
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.web.WebView?>
<AnchorPane prefHeight="752.0" prefWidth="1008.0" stylesheets="@../css/main.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.ProjectSelectController">
<AnchorPane layoutX="11.0" layoutY="12.0" prefHeight="727.0" prefWidth="984.0" styleClass="darkPane">
<children>
<ImageView fitHeight="247.0" fitWidth="252.0" layoutX="372.0" layoutY="15.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="247.0" fitWidth="252.0" layoutX="162.0" layoutY="15.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/osci.png" />
</image>
</ImageView>
<ListView fx:id="recentFilesListView" layoutX="238.0" layoutY="333.0" prefHeight="257.0" prefWidth="527.0" />
<Button fx:id="newProjectButton" layoutX="432.0" layoutY="609.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="131.0" text="Start new project" />
<CheckBox fx:id="startMutedCheckBox" layoutX="450.0" layoutY="670.0" mnemonicParsing="false" text="Start muted" />
<Label layoutX="398.0" layoutY="294.0" styleClass="title" text="Recently opened projects" />
<ListView fx:id="recentFilesListView" layoutX="28.0" layoutY="333.0" prefHeight="257.0" prefWidth="527.0" />
<Button fx:id="newProjectButton" layoutX="222.0" layoutY="609.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="131.0" text="Start new project" />
<CheckBox fx:id="startMutedCheckBox" layoutX="240.0" layoutY="670.0" mnemonicParsing="false" text="Start muted" />
<Label layoutX="188.0" layoutY="294.0" styleClass="title" text="Recently opened projects" />
<Label layoutX="14.0" layoutY="700.0" text="v1.26.4" />
<Label layoutX="727.0" layoutY="40.0" styleClass="title" text="Changelog" />
<WebView fx:id="changelogWebView" layoutX="583.0" layoutY="104.0" prefHeight="590.0" prefWidth="376.0" />
</children></AnchorPane>
</AnchorPane>

File diff suppressed because one or more lines are too long