Class SystemPreferences
current() and follows changes with
observeChanges(java.lang.Runnable).
The toolkit reports; the application decides. A dark system does not switch an application's theme, because which palette to use is the application's choice, and its theme may be its brand. Following the system is one line:
SystemPreferences.observeChanges(() -> pickTheme(SystemPreferences.current()).apply());
The one preference the toolkit acts on by itself is reduceMotion(): while it is set,
a Transition finishes at once and popups and dialogs open and close without
fading; see Motion.
What each platform answers: on macOS the application's effective appearance and the
accessibility display options; on Windows the apps' light-theme setting, client-area animation and
high contrast; on Linux the desktop portal's appearance settings, with GNOME's
enable-animations where the portal has no reduced-motion key. A platform that cannot say
reports SystemPreferences.ColorScheme.NO_PREFERENCE and false, as Ubuntu's default appearance does.
The toolkit also follows underlineAccessKeys(): while it is set, the access letters
of menus, buttons and labels stay underlined, where otherwise they show only while Alt is held.
Windows answers it (the keyboard setting to underline access keys); the other systems report
false.
A class and not a record, with no public constructor: only a backend builds one. A
record's constructor and its deconstruction pattern would have made the four preferences of
today a contract, so that a fifth, which a system may offer in a later 1.x release, could not be
added without breaking every caller that builds or deconstructs one. An application reads the
accessors, compares two values with equals(java.lang.Object), and starts from NONE.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA light or dark appearance, or none chosen.static final recordThe palette a user chose when the platform's request for more contrast is a palette of its own: a Windows contrast theme, whose eight system colours every native application draws with. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemPreferencesNo preference, no reduced motion, no increased contrast, access keys underlined only while Alt is held: what a platform that says nothing reports. -
Method Summary
Modifier and TypeMethodDescription@Nullable SystemPreferences.ContrastColorsstatic SystemPreferencescurrent()booleanEqual when every preference is: whatreport(limn.scene.SystemPreferences)compares to tell a change.inthashCode()booleanstatic SubscriptionobserveChanges(Runnable listener) Subscribes to changes.booleanstatic voidreport(SystemPreferences preferences) Reports what the platform says now.toString()Every preference by name, for a log line.boolean
-
Field Details
-
NONE
No preference, no reduced motion, no increased contrast, access keys underlined only while Alt is held: what a platform that says nothing reports.
-
-
Method Details
-
colorScheme
- Returns:
- the appearance the user chose, or
SystemPreferences.ColorScheme.NO_PREFERENCE
-
reduceMotion
public boolean reduceMotion()- Returns:
- whether the user asked for less motion
-
increaseContrast
public boolean increaseContrast()- Returns:
- whether the user asked for more contrast
-
contrastColors
- Returns:
- the palette the user chose for more contrast where the platform has one (a Windows
contrast theme, while
increaseContrast()is true);nullelsewhere, where more contrast keeps the application's palette and strengthens it
-
underlineAccessKeys
public boolean underlineAccessKeys()- Returns:
- whether the user asked for access keys to be underlined at all times;
falseon every system but Windows
-
equals
Equal when every preference is: whatreport(limn.scene.SystemPreferences)compares to tell a change. -
hashCode
public int hashCode() -
toString
Every preference by name, for a log line. -
current
- Returns:
- the preferences the backend last reported, or
NONEbefore any backend did. Any thread.
-
observeChanges
Subscribes to changes. A listener runs on the UI thread once per change of the value, however many signals the platform sent for it.- Parameters:
listener- what to run when the preferences change- Returns:
- a handle that unsubscribes; cancelling it twice is a no-op. UI thread
-
report
Reports what the platform says now. A backend calls it when it starts and whenever the platform signals a change, andNONEwhen it closes; a test calls it to put back what it found incurrent(). Listeners run only when the value differs from the current one. UI thread only.- Parameters:
preferences- what the platform says; nevernull- Throws:
NullPointerException- ifpreferencesisnull
-