Paint the client with FlatLaf, in a light and a dark theme
The look-and-feel is FlatLaf now, chosen light or dark on the new Design tab and remembered in the settings. Theme keeps only the colours TeamSpeak gives meaning to (talking, away, muted, channel and server names) and takes its surfaces and fonts from the look-and-feel, so a switch recolours the whole window, chat logs included: the HTML panes share one themed stylesheet and re-parse their content when the theme changes. Also fixes the channel tree not scrolling: the tree listened for the mouse wheel to re-check its hover row, and AWT only forwards a wheel event to the enclosing scroll pane when the component under the pointer has no wheel listener of its own. The hover row now follows the viewport instead, which also covers scrollbar drags and keyboard scrolling. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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 javax.swing.UIManager;
|
||||
import java.awt.Window;
|
||||
|
||||
/**
|
||||
* Installs FlatLaf in the requested variant and keeps {@link Theme} in step with it.
|
||||
*
|
||||
* <p>Also carries the few look-and-feel defaults the client wants everywhere: rounded
|
||||
* controls, a slimmer tree row and scroll bars that only show their thumb.
|
||||
*/
|
||||
public final class LookAndFeelManager {
|
||||
|
||||
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();
|
||||
if (!FlatLaf.setup(laf)) {
|
||||
// Leave whatever look-and-feel is installed; Theme falls back to its own palette.
|
||||
Theme.refresh();
|
||||
return;
|
||||
}
|
||||
applyDefaults();
|
||||
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);
|
||||
FlatLaf.updateUI();
|
||||
for (Window w : Window.getWindows()) {
|
||||
w.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyDefaults() {
|
||||
UIManager.put("Component.focusWidth", 1);
|
||||
UIManager.put("Component.arc", 6);
|
||||
UIManager.put("Button.arc", 6);
|
||||
UIManager.put("ScrollBar.showButtons", false);
|
||||
UIManager.put("ScrollBar.thumbArc", 8);
|
||||
UIManager.put("ScrollBar.trackArc", 8);
|
||||
UIManager.put("TabbedPane.tabHeight", 26);
|
||||
UIManager.put("Tree.rowHeight", 0);
|
||||
UIManager.put("Tree.paintLines", false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user