package com.ts3client.ui; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import com.ts3client.config.Settings; import java.awt.Window; /** * Installs FlatLaf in the requested variant and keeps {@link Theme} in step with it. * *
The client's own look-and-feel defaults — rounded controls, and the darker palette * the dark theme is built on — live beside this class as FlatLaf properties files, which * FlatLaf loads on top of the theme's own. */ public final class LookAndFeelManager { /** Where our own FlatLaf properties files sit. */ private static final String DEFAULTS_PACKAGE = "com.ts3client.ui.laf"; static { // Registered once: FlatLaf keeps every registration, and install() runs again on // each theme switch. FlatLaf.registerCustomDefaultsSource(DEFAULTS_PACKAGE); } private LookAndFeelManager() { } /** Installs the look-and-feel for {@code appearance}. Call before building any window. */ public static void install(Settings.Appearance appearance) { FlatLaf laf = appearance == Settings.Appearance.DARK ? new FlatDarkLaf() : new FlatLightLaf(); // Whatever look-and-feel stays installed on failure, Theme falls back to its own palette. FlatLaf.setup(laf); Theme.refresh(); } /** * Switches the look-and-feel of the running client. Components that read {@link Theme} * while painting follow immediately; the ones that copied a colour when they were built * are refreshed by the look-and-feel update. */ public static void switchTo(Settings.Appearance appearance) { install(appearance); IconTheme.get().refresh(); FlatLaf.updateUI(); for (Window w : Window.getWindows()) { w.repaint(); } } }