Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8267546

Add CSS themes as a first-class concept

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:

      Description

      Currently, the two themes shipped with JavaFX (Caspian and Modena) are implemented as a set of stylesheets and some internal logic, mostly in `PlatformImpl`.

      Much of this logic deals with optional features or platform-specific theme modifications. Another piece of logic deals with accessibility themes: on Windows platforms, both Caspian and Modena have high-contrast stylesheets that are added or removed in response to OS theme changes.

      A major downside of this implementation is that it special-cases the built-in themes and doesn't offer enough extension points to make it easy for developers to create new rich themes.

      In order to support first-class themes, a new interface should be added in the `javafx.application` package:

          public interface Theme {
              ObservableList<String> getStylesheets();
              void platformThemeChanged(Map<String, String> properties);
          }

      An implementation of this interface populates the list returned by
      `Theme.getStylesheets()` with its collection of stylesheets.
      Optionally, it can listen to the platform theme properties reported by
      `Theme.platformThemeChanged(...)` and modify its list of stylesheets
      accordingly.

      Platform theme properties are platform-specific key-value pairs, and theme
      implementations are responsible for interpreting the values. For
      example, on the Windows platform, a theme implementation might listen
      to the `Windows.SPI_HighContrastOn` property in order to detect
      whether or not a high-contrast stylesheet should be used. The `Theme`
      class documents all currently supported platform properties.

      A theme is activated by setting it as the user-agent stylesheet of the
      application:

          Application.setUserAgentStylesheet("theme:com.example.CustomTheme");

      "theme:" is a custom URI scheme that is interpreted when the user-agent stylesheet is loaded.

      The existing constants `Application.STYLESHEET_CASPIAN` and
      `Application.STYLESHEET_MODENA` are translated to their respective theme-URI in `PlatformImpl`.

        Attachments

          Activity

            People

            Assignee:
            mstrauss Michael Strauß
            Reporter:
            mstrauss Michael Strauß
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: