Enum Class DynamicTheme

java.lang.Object
java.lang.Enum<DynamicTheme>
com.flowingcode.vaadin.addons.demo.DynamicTheme
All Implemented Interfaces:
Serializable, Comparable<DynamicTheme>, Constable

public enum DynamicTheme extends Enum<DynamicTheme>
Enumeration representing supported themes for dynamic switching.

This enum facilitates switching between themes (e.g., Lumo, Aura) at runtime.

  • Enum Constant Details

    • LUMO

      public static final DynamicTheme LUMO
      The standard Lumo theme.
    • AURA

      public static final DynamicTheme AURA
      The standard Aura theme.
    • BASE

      public static final DynamicTheme BASE
      A base theme without specific styling.
  • Method Details

    • values

      public static DynamicTheme[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DynamicTheme valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • isFeatureSupported

      public static boolean isFeatureSupported()
      Checks if the dynamic theme feature is supported. The feature is supported in Vaadin 25.
      Returns:
      true if the feature is supported and initialized; false otherwise.
    • isFeatureInitialized

      public static boolean isFeatureInitialized()
      Checks if the dynamic theme feature has been initialized for the current session.
      Returns:
      true if the feature is supported and initialized; false otherwise.
    • getCurrent

      public static DynamicTheme getCurrent()
      Return the current dynamic theme.
      Returns:
      the current dynamic theme, or null if the feature has not been initialized.
      Throws:
      UnsupportedOperationException - if the runtime Vaadin version is older than 25.
    • initialize

      public void initialize(AppShellSettings settings)
      Initializes the theme settings into the provided AppShellSettings.

      This method performs a lazy initialization of the DynamicTheme within the current VaadinSession. If no theme is present, it registers this instance as the session default. Subsequently, it injects the corresponding CSS stylesheet link into the document head.

      Parameters:
      settings - the application shell settings to be modified
      Throws:
      UnsupportedOperationException - if the runtime Vaadin version is older than 25
      IllegalStateException - if the AppShellConfigurator is configured with the legacy Theme annotation
    • initialize

      public void initialize(IndexHtmlResponse response)
      Initializes the theme settings into the provided IndexHtmlResponse.

      This method performs a lazy initialization of the DynamicTheme within the current VaadinSession. If no theme is present, it registers this instance as the session default. Subsequently, it injects the corresponding CSS stylesheet link into the document head.

      Parameters:
      response - the index HTML response to be modified
      Throws:
      UnsupportedOperationException - if the runtime Vaadin version is older than 25
      IllegalStateException - if the AppShellConfigurator is configured with the legacy Theme annotation
    • prepare

      public static void prepare(Component component)
      Prepares the component for dynamic theme switching by preloading stylesheets.

      Adds a client-side listener to the component that detects mouseover events. When triggered, it preloads the theme stylesheets (Lumo and Aura) to ensure they can be applied immediately when needed.

      Parameters:
      component - the component to attach the listener to
      Throws:
      IllegalStateException - if the dynamic theme feature has not been initialized
    • apply

      public void apply(HasElement component)
      Applies this theme to the view.
      Parameters:
      component - a component in the view
      Throws:
      IllegalStateException - if the dynamic theme feature has not been initialized