Class ThemeUtilities

java.lang.Object
org.tentackle.fx.ThemeUtilities
Direct Known Subclasses:
RdcThemeUtilities

@Service(ThemeUtilities.class) public class ThemeUtilities extends Object
Utility methods for theme management.
Author:
harald
  • Property Details

  • Field Details

  • Constructor Details

    • ThemeUtilities

      public ThemeUtilities(String defaultThemeName, int fontSize)
      Creates the theme utilities.
      Parameters:
      defaultThemeName - the default theme name
      fontSize - the default font size
    • ThemeUtilities

      public ThemeUtilities()
      Creates the theme utilities with the default theme name.
  • Method Details

    • getInstance

      public static ThemeUtilities getInstance()
      The singleton.
      Returns:
      the singleton
    • isDarkMode

      public boolean isDarkMode()
      Returns whether to enable dark mode.
      Returns:
      true to enable dark mode
    • setDarkMode

      public void setDarkMode(boolean darkMode)
      Enables dark mode.
      Parameters:
      darkMode - true to enable dark theme, false for light theme (default)
    • darkModeProperty

      public javafx.beans.property.BooleanProperty darkModeProperty()
      Holds the dark theme boolean.
      False is light mode (default).
      Returns:
      the darkMode property
      See Also:
    • getSupportedThemes

      public List<String> getSupportedThemes()
      Gets the list of supported themes.
      Returns:
      the names of the supported themes, never null
    • getThemeName

      public String getThemeName()
      Gets the current theme name.
      Returns:
      the theme name, never null
    • setThemeName

      public void setThemeName(String themeName)
      Sets the theme name.

      Throws FxRuntimeException if the theme is not supported.

      Parameters:
      themeName - the theme name
    • themeNameProperty

      public javafx.beans.property.StringProperty themeNameProperty()
      Holds the theme name.
      "Modena" for the default theme.
      Returns:
      the themeName property
      See Also:
    • setTheme

      public void setTheme(boolean darkMode, String themeName)
      Sets the theme name and dark mode simultaneously.
      Parameters:
      darkMode - the dark mode flag
      themeName - the theme name
    • savePreferences

      public void savePreferences(Class<?> clazz, ThemeUtilities.ThemePreferences preferences)
      Saves the theme name and dark mode to the user preferences on the local machine.
      Parameters:
      clazz - the application class
      preferences - the preferences to save
    • loadPreferences

      public ThemeUtilities.ThemePreferences loadPreferences(Class<?> clazz, Boolean defaultDarkMode, String defaultThemeName)
      Loads the theme name and dark mode from the user preferences on the local machine.
      Parameters:
      clazz - the application class
      defaultDarkMode - the default dark mode value, null for none
      defaultThemeName - the default theme name, null for none
      Returns:
      the preferences, never null
    • loadPreferences

      public ThemeUtilities.ThemePreferences loadPreferences(Class<?> clazz)
      Loads the theme name and dark mode from the user preferences on the local machine.
      Parameters:
      clazz - the application class
      Returns:
      the preferences, never null
    • applyThemePreferences

      public void applyThemePreferences(ThemeUtilities.ThemePreferences preferences)
      Applies the theme preferences.
      Parameters:
      preferences - the preferences
    • applyUserAgentStylesheet

      public void applyUserAgentStylesheet()
      Applies the user agent stylesheet.
    • applyStylesheets

      public void applyStylesheets(javafx.scene.Scene scene)
      Applies the default stylesheets to a scene.
      Invoked for all newly created scenes or via reapplyStyleSheets().
      Parameters:
      scene - the scene
    • reapplyStyleSheets

      public void reapplyStyleSheets()
      Resets and applies the stylesheets to all scenes.
      Useful when the dark mode configuration changed, for example.
    • getResourceURL

      public URL getResourceURL(Class<?> clazz, String name)
      Gets the resource URL.
      The method is provided to allow redirects to other resources, usually CSS files.
      Parameters:
      clazz - the reference class
      name - the resource name
      Returns:
      the resource URL
    • getDefaultFont

      public javafx.scene.text.Font getDefaultFont()
      Gets the default font.
      Returns:
      the default font
    • getAutoAdjustPadding

      public double getAutoAdjustPadding()
      Gets the padding for auto-adjusting the width of a table column or tree table column.
      Returns:
      the padding in pixels
    • updateStyles

      protected void updateStyles()
      Updates the stylesheets according to the dark mode and theme setting.