Class UIUtil
java.lang.Object
com.dlsc.gemsfx.util.UIUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddClassesIfAbsent(javafx.css.Styleable node, String... styleClasses) Adds a list of style classes to a node if they are not already present.static voidaddClassIfAbsent(javafx.css.Styleable node, String styleClass) Adds a style class to a node if it is not already present.static StringcamelCaseToNaturalCase(String camelCaseString) Converts a camelCase string to a natural language expression.static <T extends Enum<T>>
voidclearStylesByEnum(javafx.css.Styleable node, Class<T> enumClass) Removes all styles associated with a given enum class from a Node.static voidcopyToClipboard(String copyContent) Copies the specified content to the clipboard.static doublegetInsetsHeight(javafx.geometry.Insets insets) Returns the height of the top and bottom insets combined.static doublegetInsetsWidth(javafx.geometry.Insets insets) Returns the width of the left and right insets combined.static booleanisClickOnNode(javafx.scene.input.MouseEvent event) Determines if the given mouse event is a primary button click that hasn't moved since it was pressed.static booleanisClickOnNode(javafx.scene.input.MouseEvent event, boolean isSingleClick) Determines if the given mouse clicked event is a primary button click that hasn't moved since it was pressed.static voidtoggleClass(javafx.css.Styleable node, String styleClass) Toggles a style class on a node.static voidtoggleClassBasedOnObservable(javafx.css.Styleable node, String styleClass, javafx.beans.value.ObservableValue<Boolean> booleanObservableValue) Toggles a style class on a node based on an observable value.static voidtoggleClassOnCondition(javafx.css.Styleable node, String styleClass, boolean condition) Toggles a style class on a node based on a condition.static <T extends Enum<T>>
voidupdateStyleFromEnum(javafx.css.Styleable node, T enumValue) Applies a style derived from an enum value to a Node, removing other styles from the same enum class.static voidupdateStyles(javafx.css.Styleable node, String[] stylesToRemove, String styleToAdd) Optimizes style updates for a given node by first adding a specified style to ensure it's present, and then removing other specified styles, except the newly added one.static voidupdateStyles(javafx.css.Styleable node, List<String> stylesToRemove, String styleToAdd) Optimizes style updates for a given node by first adding a specified style to ensure it's present, and then removing other specified styles, except the newly added one.
-
Method Details
-
addClassIfAbsent
Adds a style class to a node if it is not already present.- Parameters:
node- The node to add the style class to.styleClass- The style class to add.
-
addClassesIfAbsent
Adds a list of style classes to a node if they are not already present.- Parameters:
node- The node to add the style classes to.styleClasses- The style classes to add.
-
toggleClass
Toggles a style class on a node. If the style class is present, it is removed. If it is not present, it is added.- Parameters:
node- The node to toggle the style on.styleClass- The style class to add or remove.
-
toggleClassOnCondition
public static void toggleClassOnCondition(javafx.css.Styleable node, String styleClass, boolean condition) Toggles a style class on a node based on a condition. If the condition is true, the style class is added. If the condition is false, the style class is removed.- Parameters:
node- The node to toggle the style on.styleClass- The style class to add or remove.condition- The condition that determines whether to add or remove the style.
-
toggleClassBasedOnObservable
public static void toggleClassBasedOnObservable(javafx.css.Styleable node, String styleClass, javafx.beans.value.ObservableValue<Boolean> booleanObservableValue) Toggles a style class on a node based on an observable value. If the observable value is true, the style class is added. If the observable value is false, the style class is removed.- Parameters:
node- The node to toggle the style on.styleClass- The style class to add or remove.booleanObservableValue- The observable value that determines whether to add or remove the style.
-
updateStyles
public static void updateStyles(javafx.css.Styleable node, List<String> stylesToRemove, String styleToAdd) Optimizes style updates for a given node by first adding a specified style to ensure it's present, and then removing other specified styles, except the newly added one. This approach helps in preventing unnecessary UI flicker by avoiding the removal of a style that needs to be present.- Parameters:
node- The node whose styles are to be updated.stylesToRemove- A list of styles to be removed from the node, except for the styleToAdd.styleToAdd- The style to be added to the node, if it's not already present.
-
updateStyles
public static void updateStyles(javafx.css.Styleable node, String[] stylesToRemove, String styleToAdd) Optimizes style updates for a given node by first adding a specified style to ensure it's present, and then removing other specified styles, except the newly added one. This approach helps in preventing unnecessary UI flicker by avoiding the removal of a style that needs to be present.- Parameters:
node- The node whose styles are to be updated.stylesToRemove- An array of styles to be removed from the node, except for the styleToAdd.styleToAdd- The style to be added to the node, if it's not already present.
-
updateStyleFromEnum
Applies a style derived from an enum value to a Node, removing other styles from the same enum class.- Parameters:
node- The Node to update.enumValue- The enum value determining the style to apply.Example If Dir.UP is passed, add "up" style and removes {"down", "left", "right"} styles.
-
clearStylesByEnum
public static <T extends Enum<T>> void clearStylesByEnum(javafx.css.Styleable node, Class<T> enumClass) Removes all styles associated with a given enum class from a Node.- Parameters:
node- The Node to clear styles from.enumClass- The enum class whose associated styles will be removed.Example If Dir.class is passed, removes all styles {"up","down","left", "right"}.
-
getInsetsHeight
public static double getInsetsHeight(javafx.geometry.Insets insets) Returns the height of the top and bottom insets combined. -
getInsetsWidth
public static double getInsetsWidth(javafx.geometry.Insets insets) Returns the width of the left and right insets combined. -
camelCaseToNaturalCase
Converts a camelCase string to a natural language expression.This method is designed to transform strings formatted in camelCase, commonly used in programming, into a more readable format that is suitable for display in user interfaces. It inserts spaces between words and ensures that acronyms remain capitalized while the first letter of the resulting string is also capitalized.
Example: "ONSCode" becomes "ONS Code" "customerServiceOrder" becomes "Customer Service Order"
- Parameters:
camelCaseString- The camelCase string to be converted.- Returns:
- A string in natural language format, with appropriate spaces and capitalization.
-
copyToClipboard
Copies the specified content to the clipboard.- Parameters:
copyContent- The content to be copied to the clipboard.
-
isClickOnNode
public static boolean isClickOnNode(javafx.scene.input.MouseEvent event) Determines if the given mouse event is a primary button click that hasn't moved since it was pressed.This method checks if the mouse event satisfies the following conditions:
- The mouse button is the primary button (usually the left button).
- The mouse has not moved since it was pressed.
- Parameters:
event- The mouse event to check. Must not be null.- Returns:
trueif the event is a single stable primary button click,falseotherwise.- Throws:
NullPointerException- if the event is null.
-
isClickOnNode
public static boolean isClickOnNode(javafx.scene.input.MouseEvent event, boolean isSingleClick) Determines if the given mouse clicked event is a primary button click that hasn't moved since it was pressed.This method checks if the mouse event satisfies the following conditions:
- The mouse button is the primary button (usually the left button).
- The mouse has not moved since it was pressed.
- If
isSingleClickistrue, the event must be a single click.
- Parameters:
event- The mouse event to check. Must not be null.isSingleClick-trueif the event must be a single click,falseotherwise.- Returns:
trueif the event is a stable primary button click,falseotherwise.- Throws:
IllegalArgumentException- if the event is not a mouse clicked event.
-