java.lang.Object
com.example.cab302project.UIUtils
A collection of static utility methods for UI management, data validation,
and formatting. This class provides centralized logic for common tasks
such as scene switching, alert display, and date-time parsing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterFormatter for database-compatible timestamp strings.static final DateTimeFormatterFormatter for user-friendly display of timestamps. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatBoolean(boolean value) Converts a boolean value into a "Yes" or "No" string for UI display.static StringformatForDb(LocalDateTime dateTime) Formats aLocalDateTimeobject into a string suitable for SQLite storage.static StringformatLocalDateTime(LocalDateTime dateTime) Formats aLocalDateTimefor display within the application UI.static booleanisValidCoordinate(double lat, double lon) Validates if a set of coordinates is within global bounds.static booleanisValidEmail(String email) Validates an email address using a standard regular expression.static booleanisValidPhone(String phone) Validates that a phone number consists of exactly 10 numeric digits.static LocalDateTimeparseFromDb(String dateString) Parses a timestamp string retrieved from the database into aLocalDateTimeobject.static voidDisplays a standardized JavaFX Alert dialog styled to match the RADIUS design system.static voidshowAlert(javafx.scene.control.Alert.AlertType alertType, String title, String message, javafx.stage.Stage owner) Displays a standardized JavaFX Alert dialog with an explicit owner stage.static voidswitchScene(javafx.stage.Stage stage, String fxmlFile) Transitions the application to a different scene by loading an FXML file.
-
Field Details
-
DB_FORMATTER
Formatter for database-compatible timestamp strings. Format:yyyy-MM-dd HH:mm:ss -
DISPLAY_FORMATTER
Formatter for user-friendly display of timestamps. Format:dd/MM/yyyy HH:mm
-
-
Constructor Details
-
UIUtils
public UIUtils()
-
-
Method Details
-
formatForDb
Formats aLocalDateTimeobject into a string suitable for SQLite storage.- Parameters:
dateTime- The date and time to be formatted.- Returns:
- A string representation of the timestamp in DB format.
-
parseFromDb
Parses a timestamp string retrieved from the database into aLocalDateTimeobject.- Parameters:
dateString- The raw timestamp string from the database.- Returns:
- A
LocalDateTimerepresentation of the input string.
-
formatLocalDateTime
Formats aLocalDateTimefor display within the application UI.- Parameters:
dateTime- The date and time to format.- Returns:
- A formatted string (dd/MM/yyyy HH:mm), or an empty string if input is null.
-
formatBoolean
Converts a boolean value into a "Yes" or "No" string for UI display.- Parameters:
value- The boolean state to represent.- Returns:
- "Yes" if true, "No" if false.
-
isValidEmail
Validates an email address using a standard regular expression.- Parameters:
email- The string to validate.- Returns:
- true if the email format is valid; false if null or invalid.
-
isValidPhone
Validates that a phone number consists of exactly 10 numeric digits.- Parameters:
phone- The string to validate.- Returns:
- true if the string contains exactly 10 digits; false otherwise.
-
isValidCoordinate
public static boolean isValidCoordinate(double lat, double lon) Validates if a set of coordinates is within global bounds.- Parameters:
lat- Latitude to check.lon- Longitude to check.- Returns:
- true if coordinates are valid, false otherwise.
-
showAlert
public static void showAlert(javafx.scene.control.Alert.AlertType alertType, String title, String message) Displays a standardized JavaFX Alert dialog styled to match the RADIUS design system. Injects the application stylesheet and applies the alert-dialog-pane CSS class so the dialog uses the correct fonts, colours, and button styles.- Parameters:
alertType- TheAlert.AlertType(e.g., INFORMATION, ERROR, WARNING).title- The text to display in the window title bar.message- The main content text to display in the alert body.
-
showAlert
public static void showAlert(javafx.scene.control.Alert.AlertType alertType, String title, String message, javafx.stage.Stage owner) Displays a standardized JavaFX Alert dialog with an explicit owner stage. Setting the owner ensures the dialog always renders on top of the application window.- Parameters:
alertType- TheAlert.AlertType(e.g., INFORMATION, ERROR, WARNING).title- The text to display in the window title bar.message- The main content text to display in the alert body.owner- TheStagethat owns this dialog, ensuring it renders on top.
-
switchScene
Transitions the application to a different scene by loading an FXML file. This method uses the global width and height constants defined inHelloApplication.- Parameters:
stage- The currentStageto update.fxmlFile- The filename of the FXML resource (e.g., "dashboard-view.fxml").
-