Class UIUtils

java.lang.Object
com.example.cab302project.UIUtils

public class UIUtils extends Object
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 Details

    • DB_FORMATTER

      public static final DateTimeFormatter DB_FORMATTER
      Formatter for database-compatible timestamp strings. Format: yyyy-MM-dd HH:mm:ss
    • DISPLAY_FORMATTER

      public static final DateTimeFormatter DISPLAY_FORMATTER
      Formatter for user-friendly display of timestamps. Format: dd/MM/yyyy HH:mm
  • Constructor Details

    • UIUtils

      public UIUtils()
  • Method Details

    • formatForDb

      public static String formatForDb(LocalDateTime dateTime)
      Formats a LocalDateTime object 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

      public static LocalDateTime parseFromDb(String dateString)
      Parses a timestamp string retrieved from the database into a LocalDateTime object.
      Parameters:
      dateString - The raw timestamp string from the database.
      Returns:
      A LocalDateTime representation of the input string.
    • formatLocalDateTime

      public static String formatLocalDateTime(LocalDateTime dateTime)
      Formats a LocalDateTime for 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

      public static String formatBoolean(boolean value)
      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

      public static boolean isValidEmail(String email)
      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

      public static boolean isValidPhone(String phone)
      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 - The Alert.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 - The Alert.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 - The Stage that owns this dialog, ensuring it renders on top.
    • switchScene

      public static void switchScene(javafx.stage.Stage stage, String fxmlFile)
      Transitions the application to a different scene by loading an FXML file. This method uses the global width and height constants defined in HelloApplication.
      Parameters:
      stage - The current Stage to update.
      fxmlFile - The filename of the FXML resource (e.g., "dashboard-view.fxml").