diff --git a/src/main/java/de/skymatic/javafxtest/App.java b/src/main/java/de/skymatic/javafxtest/App.java index d2ed815..95d5639 100644 --- a/src/main/java/de/skymatic/javafxtest/App.java +++ b/src/main/java/de/skymatic/javafxtest/App.java @@ -1,50 +1,49 @@ package de.skymatic.javafxtest; import javafx.application.Application; -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.layout.HBox; -import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; -import javafx.scene.text.Text; +import javafx.stage.FileChooser; import javafx.stage.Stage; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.UUID; + /** - * JavaFX App + * Test App for JavaFX Bug */ public class App extends Application { + private static final String PROBLEMATIC_CHAR = "\uD83C\uDF40"; //FOUR LEAF CLOVER + private static final String tmpDir = System.getProperty("java.io.tmpdir"); + + private static Path workingDir; + private static Path expectedFile; + @Override public void start(Stage stage) { - var javaVersion = SystemInfo.javaVersion(); - var javafxVersion = SystemInfo.javafxVersion(); - - var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."); - var textInputFiled = new TextField(); - textInputFiled.setPromptText("Test text field: Enter anything you want."); - var button = new Button("Test Button"); - var vbox = new VBox(label, textInputFiled, button); - vbox.setPadding(new Insets(20)); - vbox.setAlignment(Pos.CENTER); - vbox.setSpacing(10); - - var text = new Text("子貢問曰:有一言而可以終身行之者乎?子曰:其恕乎!己所不欲、勿施於人。"); //https://en.wikipedia.org/wiki/Confucius - var quoteBox = new HBox(text); - quoteBox.setAlignment(Pos.BOTTOM_RIGHT); - HBox.setMargin(text, new Insets(20)); - - var stackPane = new StackPane(quoteBox, vbox); - var scene = new Scene(stackPane, 640, 480); - stage.setScene(scene); - stage.setTitle("JavaFX Test App"); - stage.show(); + var fileChooser = new FileChooser(); + fileChooser.setInitialDirectory(workingDir.toFile()); + var chosenFile = fileChooser.showOpenDialog(stage); + if (chosenFile != null) { + if (!chosenFile.toPath().equals(expectedFile)) { + throw new IllegalStateException("Chosen path is not correct: " + chosenFile.getPath()); + } + } + stage.close(); + System.exit(0); + } + + private static void prepare() throws IOException { + var dir = Files.createDirectories(Path.of(tmpDir).resolve(UUID.randomUUID()+"/" + PROBLEMATIC_CHAR)); + workingDir = dir.getParent(); + expectedFile = Files.createFile(dir.resolve("foo")); } - public static void main(String[] args) { + public static void main(String[] args) throws IOException { + assert tmpDir != null; + prepare(); + assert workingDir != null; launch(); }