use of org.controlsfx.control.HyperlinkLabel in project sparrow by sparrowwallet.
the class AppServices method showAlertDialog.
public static Optional<ButtonType> showAlertDialog(String title, String content, Alert.AlertType alertType, Node graphic, ButtonType... buttons) {
Alert alert = new Alert(alertType, content, buttons);
setStageIcon(alert.getDialogPane().getScene().getWindow());
alert.getDialogPane().getScene().getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
alert.setTitle(title);
alert.setHeaderText(title);
if (graphic != null) {
alert.setGraphic(graphic);
}
Pattern linkPattern = Pattern.compile("\\[(http.+)]");
Matcher matcher = linkPattern.matcher(content);
if (matcher.find()) {
String link = matcher.group(1);
HyperlinkLabel hyperlinkLabel = new HyperlinkLabel(content);
hyperlinkLabel.setMaxWidth(Double.MAX_VALUE);
hyperlinkLabel.setMaxHeight(Double.MAX_VALUE);
hyperlinkLabel.getStyleClass().add("content");
Label label = new Label();
hyperlinkLabel.setPrefWidth(Math.max(360, TextUtils.computeTextWidth(label.getFont(), link, 0.0D) + 50));
hyperlinkLabel.setOnAction(event -> {
alert.close();
get().getApplication().getHostServices().showDocument(link);
});
alert.getDialogPane().setContent(hyperlinkLabel);
}
String[] lines = content.split("\r\n|\r|\n");
if (lines.length > 3 || org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.WINDOWS) {
double numLines = Arrays.stream(lines).mapToDouble(line -> Math.ceil(TextUtils.computeTextWidth(Font.getDefault(), line, 0) / 300)).sum();
alert.getDialogPane().setPrefHeight(200 + numLines * 20);
}
moveToActiveWindowScreen(alert);
return alert.showAndWait();
}
use of org.controlsfx.control.HyperlinkLabel in project controlsfx by controlsfx.
the class HelloHyperlinkLabel method getPanel.
@Override
public Node getPanel(Stage stage) {
VBox root = new VBox(20);
root.setPadding(new Insets(30, 30, 30, 30));
final TextField textToShowField = new TextField();
textToShowField.setMaxWidth(Double.MAX_VALUE);
textToShowField.setPromptText("Type text in here to display - use [] to indicate a hyperlink - e.g. [hello]");
root.getChildren().add(textToShowField);
final TextField selectedLinkField = new TextField();
selectedLinkField.setMaxWidth(Double.MAX_VALUE);
selectedLinkField.setEditable(false);
selectedLinkField.setPromptText("Click a link - I'll show you which one you clicked :-)");
root.getChildren().add(selectedLinkField);
label = new HyperlinkLabel();
label.textProperty().bind(new StringBinding() {
{
bind(textToShowField.textProperty());
}
@Override
protected String computeValue() {
final String str = textToShowField.getText();
if (str == null || str.isEmpty()) {
return "Hello [world]! I [wonder] what hyperlink [you] [will] [click]";
}
return str;
}
});
label.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Hyperlink link = (Hyperlink) event.getSource();
final String str = link == null ? "" : "You clicked on '" + link.getText() + "'";
selectedLinkField.setText(str);
}
});
root.getChildren().add(label);
return root;
}
Aggregations