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:
@@ -0,0 +1,77 @@
|
||||
package com.ts3client.config;
|
||||
|
||||
import com.ts3client.net.ClientStatus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Background colours of client rows in the channel tree: one for every client, overridden
|
||||
* by one while they talk and one while they are muted or away. Colours are ARGB; 0 is none.
|
||||
*/
|
||||
public final class ClientRowColors {
|
||||
|
||||
public record Preset(String name, int argb) {
|
||||
}
|
||||
|
||||
/** See-through, so they tint the light and dark themes alike and the names stay readable. */
|
||||
public static final List<Preset> PRESETS = List.of(
|
||||
new Preset("Green", 0x594CAF50),
|
||||
new Preset("Teal", 0x5926A69A),
|
||||
new Preset("Blue", 0x5942A5F5),
|
||||
new Preset("Purple", 0x59AB47BC),
|
||||
new Preset("Pink", 0x59EC407A),
|
||||
new Preset("Red", 0x59EF5350),
|
||||
new Preset("Orange", 0x59FFA726),
|
||||
new Preset("Yellow", 0x59FFEE58),
|
||||
new Preset("Grey", 0x599E9E9E));
|
||||
|
||||
private static final String PREFIX = "clientRowColor.";
|
||||
|
||||
public int any;
|
||||
public int talking;
|
||||
public int mutedAway;
|
||||
|
||||
/** The colour of a row showing {@code status}; 0 for none. */
|
||||
public int of(ClientStatus status) {
|
||||
int own = switch (status) {
|
||||
case TALKING, COMMANDER_TALKING -> talking;
|
||||
case SPEAKERS_DISABLED, SPEAKERS_MUTED, MIC_DISABLED, MIC_MUTED, AWAY -> mutedAway;
|
||||
default -> 0;
|
||||
};
|
||||
return own != 0 ? own : any;
|
||||
}
|
||||
|
||||
/** The preset named for {@code argb}, or {@code null} for a custom colour or none. */
|
||||
public static Preset presetOf(int argb) {
|
||||
for (Preset p : PRESETS) {
|
||||
if (p.argb() == argb) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void load(Properties p) {
|
||||
any = parse(p.getProperty(PREFIX + "any"));
|
||||
talking = parse(p.getProperty(PREFIX + "talking"));
|
||||
mutedAway = parse(p.getProperty(PREFIX + "mutedAway"));
|
||||
}
|
||||
|
||||
void store(Properties p) {
|
||||
p.setProperty(PREFIX + "any", format(any));
|
||||
p.setProperty(PREFIX + "talking", format(talking));
|
||||
p.setProperty(PREFIX + "mutedAway", format(mutedAway));
|
||||
}
|
||||
|
||||
private static int parse(String v) {
|
||||
if (v == null || v.isBlank()) return 0;
|
||||
try {
|
||||
return (int) Long.parseLong(v.trim().replace("#", ""), 16);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(int argb) {
|
||||
return argb == 0 ? "" : String.format("#%08X", argb);
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,8 @@ public final class Settings {
|
||||
* their details show it beside their name either way.
|
||||
*/
|
||||
public boolean countryFlags = false;
|
||||
/** Background colours of client rows in the channel tree. */
|
||||
public final ClientRowColors clientRowColors = new ClientRowColors();
|
||||
/** Extra folder to look for icon packs in, on top of the well-known locations. */
|
||||
public String iconPackDir = "";
|
||||
|
||||
@@ -314,6 +316,7 @@ public final class Settings {
|
||||
desktopNotifications = parseB(props.getProperty("desktopNotifications"), desktopNotifications);
|
||||
iconPack = props.getProperty("iconPack", iconPack);
|
||||
countryFlags = parseB(props.getProperty("countryFlags"), countryFlags);
|
||||
clientRowColors.load(props);
|
||||
iconPackDir = props.getProperty("iconPackDir", iconPackDir);
|
||||
appearance = parseEnum(Appearance.class, props.getProperty("appearance"), appearance);
|
||||
uiScale = parseD(props.getProperty("uiScale"), uiScale);
|
||||
@@ -375,6 +378,7 @@ public final class Settings {
|
||||
props.setProperty("desktopNotifications", Boolean.toString(desktopNotifications));
|
||||
props.setProperty("iconPack", iconPack);
|
||||
props.setProperty("countryFlags", Boolean.toString(countryFlags));
|
||||
clientRowColors.store(props);
|
||||
props.setProperty("iconPackDir", iconPackDir);
|
||||
props.setProperty("appearance", appearance.name());
|
||||
props.setProperty("uiScale", Double.toString(uiScale));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user