From f9aa6679c59b9a7202fb7991db0b78e462740323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 29 Jan 2019 18:50:15 +0100 Subject: [PATCH] Extract license popup --- .../fxdesigner/MainDesignerController.java | 19 +------- .../fxdesigner/SourceEditorController.java | 3 +- .../fxdesigner/popups/EventLogController.java | 2 +- .../util/fxdesigner/popups/SimplePopups.java | 44 +++++++++++++++++++ 4 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/SimplePopups.java diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java index a0dffe1b8d..d50073af2b 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.util.fxdesigner; +import static net.sourceforge.pmd.util.fxdesigner.popups.SimplePopups.showLicensePopup; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -220,23 +222,6 @@ public class MainDesignerController extends AbstractController titleProperty() { - return parent.getLogger().numNewLogEntriesProperty().map(i -> "Event log (" + (i > 0 ? i : "no") + " new)"); + return getLogger().numNewLogEntriesProperty().map(i -> "Event log (" + (i > 0 ? i : "no") + " new)"); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/SimplePopups.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/SimplePopups.java new file mode 100644 index 0000000000..2b3a73280a --- /dev/null +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/SimplePopups.java @@ -0,0 +1,44 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.util.fxdesigner.popups; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; + +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextArea; + + +/** + * @author Clément Fournier + */ +public final class SimplePopups { + + private SimplePopups() { + + } + + + public static void showLicensePopup() { + Alert licenseAlert = new Alert(AlertType.INFORMATION); + licenseAlert.setWidth(500); + licenseAlert.setHeaderText("License"); + + ScrollPane scroll = new ScrollPane(); + try { + scroll.setContent(new TextArea(IOUtils.toString(SimplePopups.class.getResourceAsStream("LICENSE"), StandardCharsets.UTF_8))); + } catch (IOException e) { + e.printStackTrace(); + } + + licenseAlert.getDialogPane().setContent(scroll); + licenseAlert.showAndWait(); + } + +}