From ee1c00b92ccd0e44a09ee829d4aeb85554248068 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 7 Sep 2017 13:17:51 +0300 Subject: [PATCH] Links now clickable --- .../main/java/com/annimon/hotarufx/Main.java | 2 + .../hotarufx/ui/ClickableHyperLink.java | 38 +++++++++++++++++++ app/src/main/resources/fxml/About.fxml | 8 ++-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/annimon/hotarufx/ui/ClickableHyperLink.java diff --git a/app/src/main/java/com/annimon/hotarufx/Main.java b/app/src/main/java/com/annimon/hotarufx/Main.java index 131ed6b..c4ac6e8 100644 --- a/app/src/main/java/com/annimon/hotarufx/Main.java +++ b/app/src/main/java/com/annimon/hotarufx/Main.java @@ -1,5 +1,6 @@ package com.annimon.hotarufx; +import com.annimon.hotarufx.ui.ClickableHyperLink; import com.annimon.hotarufx.ui.controller.EditorController; import java.io.IOException; import javafx.application.Application; @@ -14,6 +15,7 @@ public class Main extends Application { @Override public void start(Stage primaryStage) { + ClickableHyperLink.setHostServices(getHostServices()); primaryStage.setTitle("HotaruFX"); try { val loader = new FXMLLoader(getClass().getResource("/fxml/Editor.fxml")); diff --git a/app/src/main/java/com/annimon/hotarufx/ui/ClickableHyperLink.java b/app/src/main/java/com/annimon/hotarufx/ui/ClickableHyperLink.java new file mode 100644 index 0000000..ac21258 --- /dev/null +++ b/app/src/main/java/com/annimon/hotarufx/ui/ClickableHyperLink.java @@ -0,0 +1,38 @@ +package com.annimon.hotarufx.ui; + +import java.util.Optional; +import javafx.application.HostServices; +import javafx.scene.Node; +import javafx.scene.control.Hyperlink; + +public class ClickableHyperLink extends Hyperlink { + + private static HostServices hostServices; + + public static void setHostServices(HostServices hostServices) { + // Please, forgive me this approach + // it saved me a lot of time + ClickableHyperLink.hostServices = hostServices; + } + + public ClickableHyperLink() { + init(); + } + + public ClickableHyperLink(String text) { + super(text); + init(); + } + + public ClickableHyperLink(String text, Node graphic) { + super(text, graphic); + init(); + } + + private void init() { + setOnAction(e -> Optional + .ofNullable(hostServices) + .ifPresent(s -> s.showDocument(getText())) + ); + } +} diff --git a/app/src/main/resources/fxml/About.fxml b/app/src/main/resources/fxml/About.fxml index 6f9147a..d8e1926 100644 --- a/app/src/main/resources/fxml/About.fxml +++ b/app/src/main/resources/fxml/About.fxml @@ -4,8 +4,8 @@ - + - https://github.com/aNNiMON/HotaruFX + https://github.com/aNNiMON/HotaruFX - https://annimon.com/ + https://annimon.com/ @@ -44,7 +44,7 @@ - http://fontawesome.io + http://fontawesome.io