Colour client rows in the channel tree: for everyone, while talking, while muted or away

Design settings on desktop and Android offer a few see-through presets
that suit light and dark themes alike, or a custom colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:47:51 +00:00
co-authored by Claude Opus 5.5
parent 4cdbdea9a2
commit 59176ea017
11 changed files with 408 additions and 15 deletions
@@ -30,7 +30,7 @@ import java.util.Arrays;
/**
* Options page for how the client looks: the light or dark look-and-feel, the interface
* scale, and the icon pack the user interface is drawn with — where to look for more of
* scale, the channel tree's flags and row colours, and the icon pack the user interface is drawn with — where to look for more of
* them, and a viewer showing everything the active pack contains.
*
* <p>Theme and pack apply right away so the change can be seen in the window behind the
@@ -61,6 +61,9 @@ final class DesignPanel extends JPanel {
private final JLabel packInfo = new JLabel();
private final JTextField packDirField;
private final JCheckBox countryFlags = new JCheckBox("Show country flags in the channel tree");
private final RowColorCombo anyColor;
private final RowColorCombo talkingColor;
private final RowColorCombo mutedAwayColor;
private final DefaultListModel<String> previewModel = new DefaultListModel<>();
private final JList<String> preview = new JList<>(previewModel);
@@ -71,6 +74,9 @@ final class DesignPanel extends JPanel {
this.originalPackDir = settings.iconPackDir;
this.originalAppearance = settings.appearance;
this.packDirField = new JTextField(settings.iconPackDir, 18);
this.anyColor = new RowColorCombo(settings.clientRowColors.any);
this.talkingColor = new RowColorCombo(settings.clientRowColors.talking);
this.mutedAwayColor = new RowColorCombo(settings.clientRowColors.mutedAway);
setBorder(new ScaledEmptyBorder(12, 12, 12, 12));
add(buildHeader(), BorderLayout.NORTH);
@@ -87,6 +93,9 @@ final class DesignPanel extends JPanel {
Object selected = packCombo.getSelectedItem();
settings.iconPack = selected instanceof IconPack pack ? pack.id() : "";
settings.countryFlags = countryFlags.isSelected();
settings.clientRowColors.any = anyColor.value();
settings.clientRowColors.talking = talkingColor.value();
settings.clientRowColors.mutedAway = mutedAwayColor.value();
originalPackId = settings.iconPack;
originalPackDir = settings.iconPackDir;
originalAppearance = settings.appearance;
@@ -155,6 +164,9 @@ final class DesignPanel extends JPanel {
}
FormPanel.addSection(p, c, row++, "Channel Tree");
FormPanel.addWide(p, c, row++, countryFlags);
FormPanel.addRow(p, c, row++, new JLabel("Client background:"), anyColor);
FormPanel.addRow(p, c, row++, new JLabel("While talking:"), talkingColor);
FormPanel.addRow(p, c, row++, new JLabel("Muted / away:"), mutedAwayColor);
FormPanel.addSection(p, c, row++, "Icon Pack");
FormPanel.addRow(p, c, row++, new JLabel("Icon pack:"), packCombo);
c.gridx = 1;
@@ -5,6 +5,7 @@ import com.ts3client.config.Settings;
import com.ts3client.net.ChannelNode;
import com.ts3client.net.Spacers;
import com.ts3client.net.ClientEntry;
import com.ts3client.net.ClientStatus;
import com.ts3client.net.ServerModel;
import javax.swing.Icon;
@@ -13,6 +14,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -161,6 +163,7 @@ final class DropIndicatorTree extends JTree {
Rectangle clip = g.getClipBounds();
g.setColor(getBackground());
g.fillRect(clip.x, clip.y, clip.width, clip.height);
paintClientColors(g);
paintSearchHits(g);
paintSelection(g);
paintHover(g);
@@ -206,6 +209,23 @@ final class DropIndicatorTree extends JTree {
}
}
/** Fills client rows across the full width in the colour chosen for what they are doing. */
private void paintClientColors(Graphics g) {
Rectangle visible = getVisibleRect();
int first = Math.max(0, getClosestRowForLocation(visible.x, visible.y));
for (int row = first; row < getRowCount(); row++) {
Rectangle bounds = getRowBounds(row);
if (bounds == null) continue;
if (bounds.y > visible.y + visible.height) break;
Object obj = ((DefaultMutableTreeNode) getPathForRow(row).getLastPathComponent()).getUserObject();
if (!(obj instanceof ClientEntry cl)) continue;
int argb = settings.clientRowColors.of(ClientStatus.of(cl));
if (argb == 0) continue;
g.setColor(new Color(argb, true));
g.fillRect(visible.x, bounds.y, visible.width, bounds.height);
}
}
private void paintSearchHits(Graphics g) {
if (searchHits.isEmpty()) return;
Rectangle visible = getVisibleRect();
@@ -0,0 +1,123 @@
package com.ts3client.ui;
import com.formdev.flatlaf.util.UIScale;
import com.ts3client.config.ClientRowColors;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
/**
* Picks a row background: none, one of {@link ClientRowColors#PRESETS}, or a custom
* colour from a colour chooser. The value is ARGB, 0 for none.
*/
final class RowColorCombo extends JComboBox<RowColorCombo.Option> {
record Option(String name, int argb, boolean custom) {
}
private static final Option NONE = new Option("None", 0, false);
/** The last item, holding whichever custom colour was chosen. */
private Option custom;
private Option previous;
private boolean choosing;
RowColorCombo(int argb) {
addItem(NONE);
for (ClientRowColors.Preset p : ClientRowColors.PRESETS) addItem(new Option(p.name(), p.argb(), false));
boolean isCustom = argb != 0 && ClientRowColors.presetOf(argb) == null;
custom = new Option("Custom…", isCustom ? argb : 0, true);
addItem(custom);
setValue(argb);
previous = (Option) getSelectedItem();
setMaximumRowCount(getItemCount());
setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean selected, boolean focus) {
super.getListCellRendererComponent(list, value, index, selected, focus);
Option o = (Option) value;
setText(o == null ? "" : o.name());
setIcon(o == null ? null : new Swatch(o.argb()));
return this;
}
});
addActionListener(e -> onSelected());
}
int value() {
Option o = (Option) getSelectedItem();
return o == null ? 0 : o.argb();
}
private void setValue(int argb) {
for (int i = 0; i < getItemCount(); i++) {
Option o = getItemAt(i);
if (o.argb() == argb && (argb != 0 || o == NONE)) {
setSelectedIndex(i);
return;
}
}
setSelectedItem(NONE);
}
private void onSelected() {
Option o = (Option) getSelectedItem();
if (o == null || choosing) return;
if (!o.custom()) {
previous = o;
return;
}
choosing = true;
try {
int start = custom.argb() != 0 ? custom.argb() : previous.argb() != 0 ? previous.argb() : 0x59808080;
Color picked = JColorChooser.showDialog(this, "Row Colour", new Color(start, true), true);
if (picked == null || picked.getRGB() == 0) {
setSelectedItem(previous);
return;
}
Option chosen = new Option("Custom…", picked.getRGB(), true);
removeItem(custom);
custom = chosen;
addItem(custom);
setSelectedItem(custom);
previous = custom;
} finally {
choosing = false;
}
}
/** A small square of the colour over the tree's background, as a row shows it. */
private record Swatch(int argb) implements Icon {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
int size = getIconWidth();
g.setColor(UIManager.getColor("Tree.background"));
g.fillRect(x, y, size, size);
if (argb != 0) {
g.setColor(new Color(argb, true));
g.fillRect(x, y, size, size);
}
g.setColor(UIManager.getColor("Component.borderColor"));
g.drawRect(x, y, size - 1, size - 1);
}
@Override
public int getIconWidth() {
return UIScale.scale(14);
}
@Override
public int getIconHeight() {
return getIconWidth();
}
}
}