1
0
mirror of https://github.com/aNNiMON/HotaruFX.git synced 2024-09-19 14:14:21 +03:00

Links now clickable

This commit is contained in:
Victor 2017-09-07 13:17:51 +03:00
parent 10c0034d64
commit ee1c00b92c
3 changed files with 44 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.annimon.hotarufx; package com.annimon.hotarufx;
import com.annimon.hotarufx.ui.ClickableHyperLink;
import com.annimon.hotarufx.ui.controller.EditorController; import com.annimon.hotarufx.ui.controller.EditorController;
import java.io.IOException; import java.io.IOException;
import javafx.application.Application; import javafx.application.Application;
@ -14,6 +15,7 @@ public class Main extends Application {
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
ClickableHyperLink.setHostServices(getHostServices());
primaryStage.setTitle("HotaruFX"); primaryStage.setTitle("HotaruFX");
try { try {
val loader = new FXMLLoader(getClass().getResource("/fxml/Editor.fxml")); val loader = new FXMLLoader(getClass().getResource("/fxml/Editor.fxml"));

View File

@ -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()))
);
}
}

View File

@ -4,8 +4,8 @@
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<?import com.annimon.hotarufx.ui.LineText?> <?import com.annimon.hotarufx.ui.LineText?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<?import javafx.scene.control.Hyperlink?>
<?import com.annimon.hotarufx.ui.FontAwesomeIcon?> <?import com.annimon.hotarufx.ui.FontAwesomeIcon?>
<?import com.annimon.hotarufx.ui.ClickableHyperLink?>
<ScrollPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" <ScrollPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1"
prefWidth="400.0" prefHeight="300.0" prefWidth="400.0" prefHeight="300.0"
minWidth="NaN" minHeight="NaN" minWidth="NaN" minHeight="NaN"
@ -25,10 +25,10 @@
<LineText /> <LineText />
<FontAwesomeIcon icon="github"/> <FontAwesomeIcon icon="github"/>
<Hyperlink>https://github.com/aNNiMON/HotaruFX</Hyperlink> <ClickableHyperLink>https://github.com/aNNiMON/HotaruFX</ClickableHyperLink>
<LineText /> <LineText />
<FontAwesomeIcon icon="globe"/> <FontAwesomeIcon icon="globe"/>
<Hyperlink>https://annimon.com/</Hyperlink> <ClickableHyperLink>https://annimon.com/</ClickableHyperLink>
<LineText /> <LineText />
<LineText /> <LineText />
@ -44,7 +44,7 @@
<FontAwesomeIcon styleClass="h3" icon="font-awesome" /> <FontAwesomeIcon styleClass="h3" icon="font-awesome" />
<LineText styleClass="h3" content=" Font Awesome" /> <LineText styleClass="h3" content=" Font Awesome" />
<LineText content="by Dave Gandy" /> <LineText content="by Dave Gandy" />
<Hyperlink>http://fontawesome.io</Hyperlink> <ClickableHyperLink>http://fontawesome.io</ClickableHyperLink>
<LineText /> <LineText />
<LineText styleClass="h3" /> <LineText styleClass="h3" />