Skip to content

Commit

Permalink
Update about window
Browse files Browse the repository at this point in the history
  • Loading branch information
zapek committed Dec 31, 2024
1 parent 1c52e5a commit fdbdbf7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
78 changes: 71 additions & 7 deletions ui/src/main/java/io/xeres/ui/support/util/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
import static javafx.scene.control.Alert.AlertType.ERROR;
import static javafx.scene.control.Alert.AlertType.WARNING;

/**
* Supplements JavaFX with handy functions for UI operations.
*/
public final class UiUtils
{
private static final Logger log = LoggerFactory.getLogger(UiUtils.class);
Expand All @@ -75,6 +78,7 @@ private UiUtils()

/**
* Shows a generic alert error. Is supposed to be used in {@code doOnError} in the WebClients.
* Will not block.
*
* @param t the throwable
*/
Expand All @@ -85,7 +89,7 @@ public static void showAlertError(Throwable t)

/**
* Shows a generic alert error and allows to run an action afterwards. Is supposed to be used in
* {@code doOnError} in the WebClients.
* {@code doOnError} in the WebClients. Will not block.
*
* @param t the throwable
* @param action the action to perform after the alert has been dismissed
Expand Down Expand Up @@ -129,6 +133,11 @@ public static void showAlertError(Throwable t, Runnable action)
log.error("Error: {}", t.getMessage(), t);
}

/**
* Highlights the specified nodes. Add the 'danger' CSS style to them.
*
* @param nodes the nodes to highlight with errors
*/
public static void showError(Node... nodes)
{
for (var node : nodes)
Expand All @@ -137,6 +146,11 @@ public static void showError(Node... nodes)
}
}

/**
* Clears out the highlighting of the specified nodes. Removes the 'danger' CSS styles to them.
*
* @param nodes the nodes to un-highlight with errors
*/
public static void clearError(Node... nodes)
{
for (var node : nodes)
Expand All @@ -145,18 +159,24 @@ public static void clearError(Node... nodes)
}
}

private static void alert(AlertType alertType, String title, String message, String stackTrace)
{
var alert = buildAlert(alertType, title, message, stackTrace);
alert.showAndWait();
}

/**
* Shows an alert. Is supposed to run in the UI thread and will block.
*
* @param alertType the type of the alert
* @param message the message
*/
public static void alert(AlertType alertType, String message)
{
var alert = buildAlert(alertType, null, message, null);
alert.showAndWait();
}

/**
* Shows an alert with a confirmation. Is supposed to run in the UI thread and will block.
*
* @param message the message to display
* @param runnable the action to run after the confirmation
*/
public static void alertConfirm(String message, Runnable runnable)
{
var alert = buildAlert(AlertType.CONFIRMATION, null, message, null);
Expand All @@ -165,6 +185,12 @@ public static void alertConfirm(String message, Runnable runnable)
.ifPresent(response -> runnable.run());
}

private static void alert(AlertType alertType, String title, String message, String stackTrace)
{
var alert = buildAlert(alertType, title, message, stackTrace);
alert.showAndWait();
}

private static Alert buildAlert(AlertType alertType, String title, String message, String stackTrace)
{
var alert = new Alert(alertType);
Expand Down Expand Up @@ -264,11 +290,21 @@ private static String generateAlertErrorString(AlertType alertType, String title
"\n\n";
}

/**
* Sets the default icon of a stage (once per window).
*
* @param stage the stage to set the default icon to
*/
public static void setDefaultIcon(Stage stage)
{
stage.getIcons().add(new Image(Objects.requireNonNull(stage.getClass().getResourceAsStream("/image/icon.png"))));
}

/**
* Sets the default style of a scene (once per window).
*
* @param scene the scene to set the default icon to
*/
public static void setDefaultStyle(Scene scene)
{
scene.getStylesheets().add("/view/default.css");
Expand Down Expand Up @@ -327,6 +363,12 @@ public static void closeWindow(Node node)
stage.close();
}

/**
* Gets the user data set to a particular node.
*
* @param node the node to get the userdata from
* @return the user data
*/
public static Object getUserData(Node node)
{
return node.getScene().getRoot().getUserData();
Expand Down Expand Up @@ -393,22 +435,44 @@ public static Window getWindow(Event event)
}
}

/**
* Gets the window from a node.
*
* @param node the node to get the window from
* @return the window
*/
public static Window getWindow(Node node)
{
return node.getScene().getWindow();
}

/**
* Sets the presence of a node, that is, if it's visible and takes up space.
*
* @param node the node
* @param present true if visible, false if gone
*/
public static void setPresent(Node node, boolean present)
{
node.setManaged(present);
node.setVisible(present);
}

/**
* Puts a node as present, that is, is visible and takes up space.
*
* @param node the node
*/
public static void setPresent(Node node)
{
setPresent(node, true);
}

/**
* Puts a node as absent, that is, is gone.
*
* @param node the node
*/
public static void setAbsent(Node node)
{
setPresent(node, false);
Expand Down
6 changes: 6 additions & 0 deletions ui/src/main/resources/view/about/about.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@
<DisclosedHyperlink text="Apache 2.0 license." uri="https://www.apache.org/licenses/LICENSE-2.0"/>
<Text text="&#10;&#10;"/>

<DisclosedHyperlink text="Sound Effects" uri="https://pixabay.com/sound-effects"/>
<Text text="&#10;"/>
<Text text=" © Pixabay. Licensed under the "/>
<DisclosedHyperlink text="Creative Commons Zero (CC0) license." uri="https://pixabay.com/service/terms/"/>
<Text text="&#10;&#10;"/>

<DisclosedHyperlink text="Spring Boot" uri="https://spring.io/"/>
<Text text="&#10;"/>
<Text text=" © Broadcom. Licensed under the "/>
Expand Down

0 comments on commit fdbdbf7

Please sign in to comment.