Top Constructors Methods
com.dlsc.gemsfx.util

public Class UIUtil

extends Object
Class Inheritance
Imports
javafx.beans.value.ObservableValue, javafx.css.Styleable, javafx.geometry.Insets, javafx.scene.input.Clipboard, .ClipboardContent, .MouseButton, .MouseEvent, org.apache.commons.lang3.StringUtils, java.util.Arrays, .List, .Optional

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addClassesIfAbsent(Styleable
The node to add the style classes to.
node
,
String...
The style classes to add.
styleClasses
)

Adds a list of style classes to a node if they are not already present.

public static void
addClassIfAbsent(Styleable
The node to add the style class to.
node
,
String
The style class to add.
styleClass
)

Adds a style class to a node if it is not already present.

public static String

Returns:

A string in natural language format, with appropriate spaces and capitalization.
camelCaseToNaturalCase
(String
The camelCase string to be converted.
camelCaseString
)

Converts a camelCase string to a natural language expression.

public static <T extends Enum<T>> void
clearStylesByEnum(Styleable
The Node to clear styles from.
node
,
Class<T>
The enum class whose associated styles will be removed.

Example If Dir.class is passed, removes all styles {"up","down","left", "right"}.

enumClass
)

Removes all styles associated with a given enum class from a Node.

public static void
copyToClipboard(String
The content to be copied to the clipboard.
copyContent
)

Copies the specified content to the clipboard.

public static double
getInsetsHeight(Insets insets)

Returns the height of the top and bottom insets combined.

public static double
getInsetsWidth(Insets insets)

Returns the width of the left and right insets combined.

public static boolean

Returns:

true if the event is a single stable primary button click, false otherwise.
isClickOnNode
(MouseEvent
The mouse event to check. Must not be null.
event
)

Determines if the given mouse event is a primary button click that hasn't moved since it was pressed.

public static boolean

Returns:

true if the event is a stable primary button click, false otherwise.
isClickOnNode
(MouseEvent
The mouse event to check. Must not be null.
event
,
boolean
true if the event must be a single click, false otherwise.
isSingleClick
)

Determines if the given mouse clicked event is a primary button click that hasn't moved since it was pressed.

public static void
toggleClass(Styleable
The node to toggle the style on.
node
,
String
The style class to add or remove.
styleClass
)

Toggles a style class on a node.

public static void
toggleClassBasedOnObservable(Styleable
The node to toggle the style on.
node
,
String
The style class to add or remove.
styleClass
,
ObservableValue<Boolean>
The observable value that determines whether to add or remove the style.
booleanObservableValue
)

Toggles a style class on a node based on an observable value.

public static void
toggleClassOnCondition(Styleable
The node to toggle the style on.
node
,
String
The style class to add or remove.
styleClass
,
boolean
The condition that determines whether to add or remove the style.
condition
)

Toggles a style class on a node based on a condition.

public static <T extends Enum<T>> void
updateStyleFromEnum(Styleable
The Node to update.
node
,
T
The enum value determining the style to apply.

Example If Dir.UP is passed, add "up" style and removes {"down", "left", "right"} styles.

enumValue
)

Applies a style derived from an enum value to a Node, removing other styles from the same enum class.

public static void
updateStyles(Styleable
The node whose styles are to be updated.
node
,
List<String>
A list of styles to be removed from the node, except for the styleToAdd.
stylesToRemove
,
String
The style to be added to the node, if it's not already present.
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.

public static void
updateStyles(Styleable
The node whose styles are to be updated.
node
,
String[]
An array of styles to be removed from the node, except for the styleToAdd.
stylesToRemove
,
String
The style to be added to the node, if it's not already present.
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

UIUtilback to summary
private UIUtil()

Method Detail

addClassesIfAbsentback to summary
public static void addClassesIfAbsent(Styleable node, String... styleClasses)

Adds a list of style classes to a node if they are not already present.

Parameters
node:Styleable

The node to add the style classes to.

styleClasses:String[]

The style classes to add.

addClassIfAbsentback to summary
public static void addClassIfAbsent(Styleable node, String styleClass)

Adds a style class to a node if it is not already present.

Parameters
node:Styleable

The node to add the style class to.

styleClass:String

The style class to add.

camelCaseToNaturalCaseback to summary
public static String camelCaseToNaturalCase(String camelCaseString)

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:String

The camelCase string to be converted.

Returns:String

A string in natural language format, with appropriate spaces and capitalization.

clearStylesByEnumback to summary
public static <T extends Enum<T>> void clearStylesByEnum(Styleable node, Class<T> enumClass)

Removes all styles associated with a given enum class from a Node.

Parameters
node:Styleable

The Node to clear styles from.

enumClass:Class<T>

The enum class whose associated styles will be removed.

Example If Dir.class is passed, removes all styles {"up","down","left", "right"}.

copyToClipboardback to summary
public static void copyToClipboard(String copyContent)

Copies the specified content to the clipboard.

Parameters
copyContent:String

The content to be copied to the clipboard.

getInsetsHeightback to summary
public static double getInsetsHeight(Insets insets)

Returns the height of the top and bottom insets combined.

getInsetsWidthback to summary
public static double getInsetsWidth(Insets insets)

Returns the width of the left and right insets combined.

isClickOnNodeback to summary
public static boolean isClickOnNode(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:MouseEvent

The mouse event to check. Must not be null.

Returns:boolean

true if the event is a single stable primary button click, false otherwise.

Exceptions
NullPointerException:
if the event is null.
isClickOnNodeback to summary
public static boolean isClickOnNode(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 isSingleClick is true, the event must be a single click.
Parameters
event:MouseEvent

The mouse event to check. Must not be null.

isSingleClick:boolean

true if the event must be a single click, false otherwise.

Returns:boolean

true if the event is a stable primary button click, false otherwise.

Exceptions
IllegalArgumentException:
if the event is not a mouse clicked event.
toggleClassback to summary
public static void toggleClass(Styleable node, String styleClass)

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:Styleable

The node to toggle the style on.

styleClass:String

The style class to add or remove.

toggleClassBasedOnObservableback to summary
public static void toggleClassBasedOnObservable(Styleable node, String styleClass, 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:Styleable

The node to toggle the style on.

styleClass:String

The style class to add or remove.

booleanObservableValue:ObservableValue<Boolean>

The observable value that determines whether to add or remove the style.

toggleClassOnConditionback to summary
public static void toggleClassOnCondition(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:Styleable

The node to toggle the style on.

styleClass:String

The style class to add or remove.

condition:boolean

The condition that determines whether to add or remove the style.

updateStyleFromEnumback to summary
public static <T extends Enum<T>> void updateStyleFromEnum(Styleable node, T enumValue)

Applies a style derived from an enum value to a Node, removing other styles from the same enum class.

Parameters
node:Styleable

The Node to update.

enumValue:T

The enum value determining the style to apply.

Example If Dir.UP is passed, add "up" style and removes {"down", "left", "right"} styles.

updateStylesback to summary
public static void updateStyles(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:Styleable

The node whose styles are to be updated.

stylesToRemove:List<String>

A list of styles to be removed from the node, except for the styleToAdd.

styleToAdd:String

The style to be added to the node, if it's not already present.

updateStylesback to summary
public static void updateStyles(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:Styleable

The node whose styles are to be updated.

stylesToRemove:String[]

An array of styles to be removed from the node, except for the styleToAdd.

styleToAdd:String

The style to be added to the node, if it's not already present.