Class ThemeUtilities
java.lang.Object
org.tentackle.fx.ThemeUtilities
- Direct Known Subclasses:
RdcThemeUtilities
Utility methods for theme management.
- Author:
- harald
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordTheme preferences. -
Property Summary
Properties -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates the theme utilities with the default theme name.ThemeUtilities(String defaultThemeName, int fontSize) Creates the theme utilities. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyStylesheets(javafx.scene.Scene scene) Applies the default stylesheets to a scene.
Invoked for all newly created scenes or viareapplyStyleSheets().voidapplyThemePreferences(ThemeUtilities.ThemePreferences preferences) Applies the theme preferences.voidApplies the user agent stylesheet.javafx.beans.property.BooleanPropertyHolds the dark theme boolean.
False is light mode (default).doubleGets the padding for auto-adjusting the width of a table column or tree table column.javafx.scene.text.FontGets the default font.static ThemeUtilitiesThe singleton.getResourceURL(Class<?> clazz, String name) Gets the resource URL.
The method is provided to allow redirects to other resources, usually CSS files.Gets the list of supported themes.Gets the current theme name.booleanReturns whether to enable dark mode.loadPreferences(Class<?> clazz) Loads the theme name and dark mode from the user preferences on the local machine.loadPreferences(Class<?> clazz, Boolean defaultDarkMode, String defaultThemeName) Loads the theme name and dark mode from the user preferences on the local machine.voidResets and applies the stylesheets to all scenes.
Useful when the dark mode configuration changed, for example.voidsavePreferences(Class<?> clazz, ThemeUtilities.ThemePreferences preferences) Saves the theme name and dark mode to the user preferences on the local machine.voidsetDarkMode(boolean darkMode) Enables dark mode.voidSets the theme name and dark mode simultaneously.voidsetThemeName(String themeName) Sets the theme name.javafx.beans.property.StringPropertyHolds the theme name.
"Modena" for the default theme.protected voidUpdates the stylesheets according to the dark mode and theme setting.
-
Property Details
-
darkMode
public javafx.beans.property.BooleanProperty darkModePropertyHolds the dark theme boolean.
False is light mode (default).- See Also:
-
themeName
public javafx.beans.property.StringProperty themeNamePropertyHolds the theme name.
"Modena" for the default theme.- See Also:
-
-
Field Details
-
DARK_MODE
-
THEME_NAME
-
-
Constructor Details
-
ThemeUtilities
Creates the theme utilities.- Parameters:
defaultThemeName- the default theme namefontSize- the default font size
-
ThemeUtilities
public ThemeUtilities()Creates the theme utilities with the default theme name.
-
-
Method Details
-
getInstance
-
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
darkModeproperty - See Also:
-
getSupportedThemes
-
getThemeName
-
setThemeName
Sets the theme name.Throws
FxRuntimeExceptionif 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
themeNameproperty - See Also:
-
setTheme
Sets the theme name and dark mode simultaneously.- Parameters:
darkMode- the dark mode flagthemeName- the theme name
-
savePreferences
Saves the theme name and dark mode to the user preferences on the local machine.- Parameters:
clazz- the application classpreferences- 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 classdefaultDarkMode- the default dark mode value, null for nonedefaultThemeName- the default theme name, null for none- Returns:
- the preferences, never null
-
loadPreferences
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
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 viareapplyStyleSheets().- 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
-
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.
-