Desktop: block incoming whispers, Server Connection Info, ServerQuery toggle
- Block Incoming Whispers: toolbar toggle and the three TS3 hotkey actions; mutes all whispers per server, kept across reconnects. - Server Connection Info window (server menu or toolbar), as in TS3: version with build date, uptime, ping, loss and live In/Out traffic. The shared figures panel moves out of ConnectionInfoDialog. - ServerQuery clients are hidden in the tree unless toggled on (toolbar or the bookmark's "Show ServerQuery clients"), remembered per bookmark. - "Show Server Tabs" in the toolbar menu hides the server tab strip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,8 @@ Android app in [`../android`](../android) does.
|
|||||||
has learned carries over between talk bursts.
|
has learned carries over between talk bursts.
|
||||||
- **Playback mixing** — each speaker gets their own Opus decoder and audio line (a stream
|
- **Playback mixing** — each speaker gets their own Opus decoder and audio line (a stream
|
||||||
of their own in the PipeWire mixer), so one slow decode never blocks the others.
|
of their own in the PipeWire mixer), so one slow decode never blocks the others.
|
||||||
- **Whisper receive** — targeted voice is decoded and played like normal voice.
|
- **Whisper receive** — targeted voice is decoded and played like normal voice;
|
||||||
|
**Block Incoming Whispers** (toolbar button or hotkey) mutes all of it per server.
|
||||||
- Per-client **mute**, master **deafen**, adjustable mic gain / playback volume.
|
- Per-client **mute**, master **deafen**, adjustable mic gain / playback volume.
|
||||||
- **On-the-fly Opus tuning** — bitrate, complexity, VBR, FEC and voice/music codec
|
- **On-the-fly Opus tuning** — bitrate, complexity, VBR, FEC and voice/music codec
|
||||||
can all be changed live from the options dialog and take effect on the running
|
can all be changed live from the options dialog and take effect on the running
|
||||||
@@ -126,8 +127,12 @@ Android app in [`../android`](../android) does.
|
|||||||
- Change your nickname, mute/deafen from the toolbar.
|
- Change your nickname, mute/deafen from the toolbar.
|
||||||
- **Customize Toolbar** (right-click the toolbar), as in TeamSpeak 3: pick, order and
|
- **Customize Toolbar** (right-click the toolbar), as in TeamSpeak 3: pick, order and
|
||||||
separate the buttons from ~70 actions (connection, self, dialogs, permissions,
|
separate the buttons from ~70 actions (connection, self, dialogs, permissions,
|
||||||
recording, and channel/client actions on the tree's selection); search, drag and drop,
|
recording, channel/client actions on the tree's selection, server); search, drag and
|
||||||
Reset to Defaults.
|
drop, Reset to Defaults. The same menu hides the server tab strip.
|
||||||
|
- **Server Connection Info** (server's context menu or toolbar), as in TeamSpeak 3: the
|
||||||
|
server's version, uptime, ping, loss and In/Out traffic, live.
|
||||||
|
- **ServerQuery clients** are hidden in the tree unless toggled on (toolbar, or "Show
|
||||||
|
ServerQuery clients" in the bookmark), remembered per bookmarked server.
|
||||||
|
|
||||||
### Hotkeys
|
### Hotkeys
|
||||||
- **Global hotkeys**, as in TeamSpeak 3: single keys or combinations (any key can act
|
- **Global hotkeys**, as in TeamSpeak 3: single keys or combinations (any key can act
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public final class Bookmark {
|
|||||||
public boolean myTeamSpeakFeatures = true;
|
public boolean myTeamSpeakFeatures = true;
|
||||||
/** Offer whispering in this server's menus. */
|
/** Offer whispering in this server's menus. */
|
||||||
public boolean showWhisperControls = false;
|
public boolean showWhisperControls = false;
|
||||||
|
/** List the server's ServerQuery clients in the tree. */
|
||||||
|
public boolean showQueryClients = false;
|
||||||
/** The server's icon as last seen there, 0 for none or not yet known. */
|
/** The server's icon as last seen there, 0 for none or not yet known. */
|
||||||
public long iconId = 0;
|
public long iconId = 0;
|
||||||
|
|
||||||
@@ -52,6 +54,7 @@ public final class Bookmark {
|
|||||||
b.connectOnStartup = connectOnStartup;
|
b.connectOnStartup = connectOnStartup;
|
||||||
b.myTeamSpeakFeatures = myTeamSpeakFeatures;
|
b.myTeamSpeakFeatures = myTeamSpeakFeatures;
|
||||||
b.showWhisperControls = showWhisperControls;
|
b.showWhisperControls = showWhisperControls;
|
||||||
|
b.showQueryClients = showQueryClients;
|
||||||
b.iconId = iconId;
|
b.iconId = iconId;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,31 @@ public final class Bookmarks {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether a bookmark leading to the server lists its ServerQuery clients. */
|
||||||
|
public boolean showsQueryClients(String address, int port) {
|
||||||
|
for (Bookmark b : entries) {
|
||||||
|
if (b.pointsAt(address, port) && b.showQueryClients) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has every bookmark leading to the server list its ServerQuery clients, or not.
|
||||||
|
*
|
||||||
|
* @return whether any bookmark changed, and so needs saving
|
||||||
|
*/
|
||||||
|
public boolean rememberQueryClients(String address, int port, boolean show) {
|
||||||
|
if (address == null || address.isBlank()) return false;
|
||||||
|
boolean changed = false;
|
||||||
|
for (Bookmark b : entries) {
|
||||||
|
if (b.pointsAt(address, port) && b.showQueryClients != show) {
|
||||||
|
b.showQueryClients = show;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
/** The bookmark with this {@link Bookmark#id}, or null. */
|
/** The bookmark with this {@link Bookmark#id}, or null. */
|
||||||
public Bookmark find(String id) {
|
public Bookmark find(String id) {
|
||||||
for (Bookmark b : entries) {
|
for (Bookmark b : entries) {
|
||||||
@@ -90,6 +115,7 @@ public final class Bookmarks {
|
|||||||
bm.connectOnStartup = Boolean.parseBoolean(p.getProperty(prefix + "connectOnStartup", "false"));
|
bm.connectOnStartup = Boolean.parseBoolean(p.getProperty(prefix + "connectOnStartup", "false"));
|
||||||
bm.myTeamSpeakFeatures = Boolean.parseBoolean(p.getProperty(prefix + "myTeamSpeakFeatures", "true"));
|
bm.myTeamSpeakFeatures = Boolean.parseBoolean(p.getProperty(prefix + "myTeamSpeakFeatures", "true"));
|
||||||
bm.showWhisperControls = Boolean.parseBoolean(p.getProperty(prefix + "showWhisperControls", "false"));
|
bm.showWhisperControls = Boolean.parseBoolean(p.getProperty(prefix + "showWhisperControls", "false"));
|
||||||
|
bm.showQueryClients = Boolean.parseBoolean(p.getProperty(prefix + "showQueryClients", "false"));
|
||||||
bm.iconId = parseLong(p.getProperty(prefix + "iconId"));
|
bm.iconId = parseLong(p.getProperty(prefix + "iconId"));
|
||||||
if (bm.address != null && !bm.address.isBlank()) b.entries.add(bm);
|
if (bm.address != null && !bm.address.isBlank()) b.entries.add(bm);
|
||||||
}
|
}
|
||||||
@@ -114,6 +140,7 @@ public final class Bookmarks {
|
|||||||
p.setProperty(prefix + "connectOnStartup", Boolean.toString(bm.connectOnStartup));
|
p.setProperty(prefix + "connectOnStartup", Boolean.toString(bm.connectOnStartup));
|
||||||
p.setProperty(prefix + "myTeamSpeakFeatures", Boolean.toString(bm.myTeamSpeakFeatures));
|
p.setProperty(prefix + "myTeamSpeakFeatures", Boolean.toString(bm.myTeamSpeakFeatures));
|
||||||
p.setProperty(prefix + "showWhisperControls", Boolean.toString(bm.showWhisperControls));
|
p.setProperty(prefix + "showWhisperControls", Boolean.toString(bm.showWhisperControls));
|
||||||
|
p.setProperty(prefix + "showQueryClients", Boolean.toString(bm.showQueryClients));
|
||||||
p.setProperty(prefix + "iconId", Long.toString(bm.iconId));
|
p.setProperty(prefix + "iconId", Long.toString(bm.iconId));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ public final class Settings {
|
|||||||
// ---- window chrome ----
|
// ---- window chrome ----
|
||||||
/** Whether the status bar at the bottom of the window is shown. */
|
/** Whether the status bar at the bottom of the window is shown. */
|
||||||
public final Setting<Boolean> showStatusBar = flag("showStatusBar", true);
|
public final Setting<Boolean> showStatusBar = flag("showStatusBar", true);
|
||||||
|
/** The strip of server tabs while more than one server is open; hidden, only the one on screen shows. */
|
||||||
|
public final Setting<Boolean> showServerTabs = flag("showServerTabs", true);
|
||||||
/** The main toolbar's buttons in order, comma-separated action ids with "-" for a separator; empty for the default set. */
|
/** The main toolbar's buttons in order, comma-separated action ids with "-" for a separator; empty for the default set. */
|
||||||
public final Setting<String> toolbarLayout = text("toolbarLayout", "");
|
public final Setting<String> toolbarLayout = text("toolbarLayout", "");
|
||||||
/** Whether the Master Volume slider is shown on the toolbar. */
|
/** Whether the Master Volume slider is shown on the toolbar. */
|
||||||
|
|||||||
@@ -145,11 +145,11 @@ public enum HotkeyAction {
|
|||||||
WHISPER_REPLY_DEACTIVATE(Category.SELF, 0x0180, "DeactivateReply",
|
WHISPER_REPLY_DEACTIVATE(Category.SELF, 0x0180, "DeactivateReply",
|
||||||
"Deactivate Reply to a Whisper", true, Argument.NONE, false),
|
"Deactivate Reply to a Whisper", true, Argument.NONE, false),
|
||||||
WHISPER_BLOCK_ACTIVATE(Category.SELF, 0x0180, "ActivateBlock",
|
WHISPER_BLOCK_ACTIVATE(Category.SELF, 0x0180, "ActivateBlock",
|
||||||
"Activate Block Incoming Whispers", true, Argument.NONE, false),
|
"Activate Block Incoming Whispers", true, Argument.NONE, true),
|
||||||
WHISPER_BLOCK_DEACTIVATE(Category.SELF, 0x0180, "DeactivateBlock",
|
WHISPER_BLOCK_DEACTIVATE(Category.SELF, 0x0180, "DeactivateBlock",
|
||||||
"Deactivate Block Incoming Whispers", true, Argument.NONE, false),
|
"Deactivate Block Incoming Whispers", true, Argument.NONE, true),
|
||||||
WHISPER_BLOCK_TOGGLE(Category.SELF, 0x0180, "ToggleBlock",
|
WHISPER_BLOCK_TOGGLE(Category.SELF, 0x0180, "ToggleBlock",
|
||||||
"Toggle Block Incoming Whispers", true, Argument.NONE, false),
|
"Toggle Block Incoming Whispers", true, Argument.NONE, true),
|
||||||
|
|
||||||
RECORDING_START(Category.SELF, 0x01c0, "Activate",
|
RECORDING_START(Category.SELF, 0x01c0, "Activate",
|
||||||
"Start Recording", true, Argument.NONE, false),
|
"Start Recording", true, Argument.NONE, false),
|
||||||
|
|||||||
@@ -691,6 +691,7 @@ final class ConnectionEventHandler implements TS3Listener {
|
|||||||
else if ("notifytokenadd".equals(e.getCommand())) conn.privilegeKeys.onAdded(e);
|
else if ("notifytokenadd".equals(e.getCommand())) conn.privilegeKeys.onAdded(e);
|
||||||
else if ("notifycomplainlist".equals(e.getCommand())) conn.complaints.onListEntry(e);
|
else if ("notifycomplainlist".equals(e.getCommand())) conn.complaints.onListEntry(e);
|
||||||
else if ("notifyserverlog".equals(e.getCommand())) conn.serverLog.onLine(e);
|
else if ("notifyserverlog".equals(e.getCommand())) conn.serverLog.onLine(e);
|
||||||
|
else if ("notifyserverconnectioninfo".equals(e.getCommand())) conn.serverStats.onReport(e);
|
||||||
else conn.offlineMessages.onReply(e);
|
else conn.offlineMessages.onReply(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,13 @@ import eu.lixko.ts3j.client.audio.VoiceReceiveStats;
|
|||||||
import eu.lixko.ts3j.client.text.ByteSize;
|
import eu.lixko.ts3j.client.text.ByteSize;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders {@link ConnectionStats} the way the official Connection Info window does: a
|
* Renders {@link ConnectionStats} the way the official Connection Info window does: a
|
||||||
@@ -43,6 +48,12 @@ public final class ConnectionStatsFormat {
|
|||||||
new Tab("Keep Alive", ConnectionStats.Kind.KEEPALIVE),
|
new Tab("Keep Alive", ConnectionStats.Kind.KEEPALIVE),
|
||||||
new Tab("Control", ConnectionStats.Kind.CONTROL));
|
new Tab("Control", ConnectionStats.Kind.CONTROL));
|
||||||
|
|
||||||
|
/** The server window's traffic table headings. */
|
||||||
|
public static final List<String> SERVER_COLUMNS = List.of("In", "Out");
|
||||||
|
|
||||||
|
private static final Pattern BUILD = Pattern.compile("^(.*?)\\s*\\[Build: (\\d+)]\\s*$");
|
||||||
|
private static final DateTimeFormatter BUILD_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public static final String QUOTA_TAB = "Quota";
|
public static final String QUOTA_TAB = "Quota";
|
||||||
public static final String VOICE_TAB = "Voice received";
|
public static final String VOICE_TAB = "Voice received";
|
||||||
|
|
||||||
@@ -112,6 +123,50 @@ public final class ConnectionStatsFormat {
|
|||||||
new Row("Remaining " + direction + " this month:", remaining));
|
new Row("Remaining " + direction + " this month:", remaining));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The server window's facts; {@code s} is {@link ServerStats#UNKNOWN} while loading. */
|
||||||
|
public static List<Row> serverSummaryRows(ServerModel model, String address, ServerStats s) {
|
||||||
|
return List.of(
|
||||||
|
new Row("Name", model.getServerName()),
|
||||||
|
new Row("Version", versionWithBuildDate(model.serverProperty("virtualserver_version"))),
|
||||||
|
new Row("Platform", orUnknown(model.serverProperty("virtualserver_platform"))),
|
||||||
|
new Row("Uptime", uptime(s.uptimeSeconds())),
|
||||||
|
new Row("Address", address),
|
||||||
|
new Row("Average ping", s.pingMs() < 0 ? UNKNOWN : Math.round(s.pingMs()) + " ms"),
|
||||||
|
new Row("Average packetloss", loss(s.packetLoss())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The server window's table, under {@link #SERVER_COLUMNS}; {@code total} is left empty. */
|
||||||
|
public static List<TrafficRow> serverTrafficRows(ServerStats s) {
|
||||||
|
return List.of(
|
||||||
|
new TrafficRow("Packets transferred", "", count(s.packetsIn()), count(s.packetsOut())),
|
||||||
|
new TrafficRow("Bytes transferred", "", ByteSize.format(s.bytesIn()), ByteSize.format(s.bytesOut())),
|
||||||
|
new TrafficRow("Bandwidth last second", "",
|
||||||
|
ByteSize.rate(s.bandwidthInLastSecond()), ByteSize.rate(s.bandwidthOutLastSecond())),
|
||||||
|
new TrafficRow("Bandwidth last minute", "",
|
||||||
|
ByteSize.rate(s.bandwidthInLastMinute()), ByteSize.rate(s.bandwidthOutLastMinute())),
|
||||||
|
new TrafficRow("File transfer bandwidth", "",
|
||||||
|
ByteSize.rate(s.fileTransferBandwidthIn()), ByteSize.rate(s.fileTransferBandwidthOut())),
|
||||||
|
new TrafficRow("File transfer bytes transferred", "",
|
||||||
|
ByteSize.format(s.fileTransferBytesIn()), ByteSize.format(s.fileTransferBytesOut())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@code 3.13.7 [Build: 1655727713]} as {@code 3.13.7 (2022-06-20 12:21:53)}, the build being its time. */
|
||||||
|
public static String versionWithBuildDate(String version) {
|
||||||
|
if (version == null || version.isBlank()) return UNKNOWN;
|
||||||
|
Matcher m = BUILD.matcher(version);
|
||||||
|
if (!m.matches()) return version;
|
||||||
|
try {
|
||||||
|
Instant built = Instant.ofEpochSecond(Long.parseLong(m.group(2)));
|
||||||
|
return m.group(1) + " (" + BUILD_DATE.format(built.atZone(ZoneId.systemDefault())) + ")";
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String orUnknown(String value) {
|
||||||
|
return value == null || value.isBlank() ? UNKNOWN : value;
|
||||||
|
}
|
||||||
|
|
||||||
/** The voice our playback received; every value is a dash when nothing was heard. */
|
/** The voice our playback received; every value is a dash when nothing was heard. */
|
||||||
public static List<Row> voiceRows(VoiceReceiveStats v) {
|
public static List<Row> voiceRows(VoiceReceiveStats v) {
|
||||||
VoiceReceiveStats s = v == null ? VoiceReceiveStats.NONE : v;
|
VoiceReceiveStats s = v == null ? VoiceReceiveStats.NONE : v;
|
||||||
@@ -158,6 +213,15 @@ public final class ConnectionStatsFormat {
|
|||||||
return count(n) + " (" + new DecimalFormat("0.0").format(100.0 * n / of) + " %)";
|
return count(n) + " (" + new DecimalFormat("0.0").format(100.0 * n / of) + " %)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@code 0 hours 3 minutes 55 seconds}, with days in front from a day on. */
|
||||||
|
public static String uptime(long seconds) {
|
||||||
|
if (seconds < 0) return UNKNOWN;
|
||||||
|
long days = seconds / 86400;
|
||||||
|
String rest = (seconds % 86400) / 3600 + " hours " + (seconds % 3600) / 60 + " minutes "
|
||||||
|
+ seconds % 60 + " seconds";
|
||||||
|
return days > 0 ? days + " days " + rest : rest;
|
||||||
|
}
|
||||||
|
|
||||||
/** {@code 04:34}, or {@code 15:35:17} from an hour on. */
|
/** {@code 04:34}, or {@code 15:35:17} from an hour on. */
|
||||||
public static String duration(long ms) {
|
public static String duration(long ms) {
|
||||||
if (ms < 0) return UNKNOWN;
|
if (ms < 0) return UNKNOWN;
|
||||||
|
|||||||
@@ -157,6 +157,10 @@ public final class Permissions {
|
|||||||
return permits("b_virtualserver_log_view");
|
return permits("b_virtualserver_log_view");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canViewServerConnectionInfo() {
|
||||||
|
return permits("b_virtualserver_connectioninfo_view");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canListPrivilegeKeys() {
|
public boolean canListPrivilegeKeys() {
|
||||||
return permits("b_virtualserver_token_list");
|
return permits("b_virtualserver_token_list");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public final class ServerModel {
|
|||||||
private int defaultChannelGroupId;
|
private int defaultChannelGroupId;
|
||||||
/** The channel new clients land in, and kicked ones go back to; 0 until the server names it. */
|
/** The channel new clients land in, and kicked ones go back to; 0 until the server names it. */
|
||||||
private int defaultChannelId;
|
private int defaultChannelId;
|
||||||
|
/** Whether {@link #buildTree} lists ServerQuery clients; a view setting, so kept by {@link #clear}. */
|
||||||
|
private boolean showQueryClients;
|
||||||
|
|
||||||
public synchronized void clear() {
|
public synchronized void clear() {
|
||||||
channels.clear();
|
channels.clear();
|
||||||
@@ -458,7 +460,7 @@ public final class ServerModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ClientEntry cl : clients.values()) {
|
for (ClientEntry cl : clients.values()) {
|
||||||
if (cl.isQuery()) continue; // hide server-query clients from the tree
|
if (cl.isQuery() && !showQueryClients) continue;
|
||||||
if (channels.containsKey(cl.channelId)) {
|
if (channels.containsKey(cl.channelId)) {
|
||||||
inside.computeIfAbsent(cl.channelId, id -> new ArrayList<>()).add(cl);
|
inside.computeIfAbsent(cl.channelId, id -> new ArrayList<>()).add(cl);
|
||||||
}
|
}
|
||||||
@@ -507,6 +509,14 @@ public final class ServerModel {
|
|||||||
siblings.addAll(ordered);
|
siblings.addAll(ordered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean showsQueryClients() {
|
||||||
|
return showQueryClients;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setShowQueryClients(boolean show) {
|
||||||
|
showQueryClients = show;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized int channelCount() {
|
public synchronized int channelCount() {
|
||||||
return channels.size();
|
return channels.size();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package eu.lixko.ts3j.client.net;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual server's connection figures, from {@code notifyserverconnectioninfo}: everything
|
||||||
|
* it exchanged with all its clients. Seen from the server, as the official window shows them:
|
||||||
|
* <em>in</em> is what it received, <em>out</em> what it sent. Unreported values are {@code -1}.
|
||||||
|
*
|
||||||
|
* @param packetLoss a fraction 0..1
|
||||||
|
*/
|
||||||
|
public record ServerStats(long uptimeSeconds, double pingMs, double packetLoss,
|
||||||
|
long packetsIn, long packetsOut, long bytesIn, long bytesOut,
|
||||||
|
long bandwidthInLastSecond, long bandwidthOutLastSecond,
|
||||||
|
long bandwidthInLastMinute, long bandwidthOutLastMinute,
|
||||||
|
long fileTransferBandwidthIn, long fileTransferBandwidthOut,
|
||||||
|
long fileTransferBytesIn, long fileTransferBytesOut) {
|
||||||
|
|
||||||
|
/** Nothing known yet. */
|
||||||
|
public static final ServerStats UNKNOWN = parse(Map.of());
|
||||||
|
|
||||||
|
static ServerStats parse(Map<String, String> m) {
|
||||||
|
return new ServerStats(
|
||||||
|
number(m, "connection_connected_time"),
|
||||||
|
decimal(m, "connection_ping"),
|
||||||
|
decimal(m, "connection_packetloss_total"),
|
||||||
|
number(m, "connection_packets_received_total"),
|
||||||
|
number(m, "connection_packets_sent_total"),
|
||||||
|
number(m, "connection_bytes_received_total"),
|
||||||
|
number(m, "connection_bytes_sent_total"),
|
||||||
|
number(m, "connection_bandwidth_received_last_second_total"),
|
||||||
|
number(m, "connection_bandwidth_sent_last_second_total"),
|
||||||
|
number(m, "connection_bandwidth_received_last_minute_total"),
|
||||||
|
number(m, "connection_bandwidth_sent_last_minute_total"),
|
||||||
|
number(m, "connection_filetransfer_bandwidth_received"),
|
||||||
|
number(m, "connection_filetransfer_bandwidth_sent"),
|
||||||
|
number(m, "connection_filetransfer_bytes_received_total"),
|
||||||
|
number(m, "connection_filetransfer_bytes_sent_total"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long number(Map<String, String> m, String key) {
|
||||||
|
String v = m.get(key);
|
||||||
|
if (v == null) return -1;
|
||||||
|
try {
|
||||||
|
return Long.parseLong(v.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double decimal(Map<String, String> m, String key) {
|
||||||
|
String v = m.get(key);
|
||||||
|
if (v == null) return -1;
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(v.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package eu.lixko.ts3j.client.net;
|
||||||
|
|
||||||
|
import com.github.manevolent.ts3j.command.SingleCommand;
|
||||||
|
import com.github.manevolent.ts3j.event.UnknownTeamspeakEvent;
|
||||||
|
import com.github.manevolent.ts3j.protocol.ProtocolRole;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks for the virtual server's connection figures with {@code serverrequestconnectioninfo},
|
||||||
|
* which the server answers with a {@code notifyserverconnectioninfo} ahead of the command's
|
||||||
|
* result. Needs {@code b_virtualserver_connectioninfo_view}.
|
||||||
|
*
|
||||||
|
* <p>Requests run in the background and fail with a {@link RequestException}.
|
||||||
|
*/
|
||||||
|
public final class ServerStatsAdmin {
|
||||||
|
|
||||||
|
private final Uplink uplink;
|
||||||
|
private volatile ServerStats latest;
|
||||||
|
|
||||||
|
ServerStatsAdmin(Uplink uplink) {
|
||||||
|
this.uplink = uplink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<ServerStats> read() {
|
||||||
|
return uplink.request(() -> {
|
||||||
|
synchronized (this) {
|
||||||
|
latest = null;
|
||||||
|
uplink.socket().executeCommand(new SingleCommand("serverrequestconnectioninfo", ProtocolRole.CLIENT))
|
||||||
|
.complete();
|
||||||
|
uplink.awaitEventsProcessed();
|
||||||
|
ServerStats stats = latest;
|
||||||
|
return stats == null ? ServerStats.UNKNOWN : stats;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void onReport(UnknownTeamspeakEvent e) {
|
||||||
|
latest = ServerStats.parse(e.getMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,7 @@ public final class TeamspeakConnection {
|
|||||||
final PrivilegeKeyAdmin privilegeKeys = new PrivilegeKeyAdmin(uplink);
|
final PrivilegeKeyAdmin privilegeKeys = new PrivilegeKeyAdmin(uplink);
|
||||||
final ComplaintAdmin complaints;
|
final ComplaintAdmin complaints;
|
||||||
final ServerLogAdmin serverLog = new ServerLogAdmin(uplink);
|
final ServerLogAdmin serverLog = new ServerLogAdmin(uplink);
|
||||||
|
final ServerStatsAdmin serverStats = new ServerStatsAdmin(uplink);
|
||||||
final OfflineMessageAdmin offlineMessages;
|
final OfflineMessageAdmin offlineMessages;
|
||||||
private final AvatarAdmin avatarAdmin;
|
private final AvatarAdmin avatarAdmin;
|
||||||
/** Ourselves: devices and status flags; package-private for {@link ConnectionEventHandler}. */
|
/** Ourselves: devices and status flags; package-private for {@link ConnectionEventHandler}. */
|
||||||
@@ -94,6 +95,8 @@ public final class TeamspeakConnection {
|
|||||||
*/
|
*/
|
||||||
/** The client whose whisper we heard last, to reply to; 0 for none yet. */
|
/** The client whose whisper we heard last, to reply to; 0 for none yet. */
|
||||||
private volatile int lastWhisperer;
|
private volatile int lastWhisperer;
|
||||||
|
/** Whether incoming whispers go unheard, whoever sends them; kept across reconnects. */
|
||||||
|
private volatile boolean whispersBlocked;
|
||||||
private volatile LocalIdentity identity;
|
private volatile LocalIdentity identity;
|
||||||
/**
|
/**
|
||||||
* The connect in progress. A disconnect clears it and a newer connect replaces it, which
|
* The connect in progress. A disconnect clears it and a newer connect replaces it, which
|
||||||
@@ -282,7 +285,7 @@ public final class TeamspeakConnection {
|
|||||||
client.addListener(events);
|
client.addListener(events);
|
||||||
client.setVoiceHandler(playback::handleVoice);
|
client.setVoiceHandler(playback::handleVoice);
|
||||||
client.setWhisperHandler(whisper -> {
|
client.setWhisperHandler(whisper -> {
|
||||||
if (!contacts.isWhisperAllowed(whisper.getClientId())) return;
|
if (whispersBlocked || !contacts.isWhisperAllowed(whisper.getClientId())) return;
|
||||||
lastWhisperer = whisper.getClientId();
|
lastWhisperer = whisper.getClientId();
|
||||||
playback.handleWhisper(whisper);
|
playback.handleWhisper(whisper);
|
||||||
});
|
});
|
||||||
@@ -643,6 +646,10 @@ public final class TeamspeakConnection {
|
|||||||
return serverLog;
|
return serverLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerStatsAdmin serverStats() {
|
||||||
|
return serverStats;
|
||||||
|
}
|
||||||
|
|
||||||
/** Our offline message inbox, sending offline messages and finding their recipients. */
|
/** Our offline message inbox, sending offline messages and finding their recipients. */
|
||||||
public OfflineMessageAdmin offlineMessages() {
|
public OfflineMessageAdmin offlineMessages() {
|
||||||
return offlineMessages;
|
return offlineMessages;
|
||||||
@@ -745,6 +752,14 @@ public final class TeamspeakConnection {
|
|||||||
sock.setWhisperTarget(target);
|
sock.setWhisperTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean areWhispersBlocked() {
|
||||||
|
return whispersBlocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWhispersBlocked(boolean blocked) {
|
||||||
|
whispersBlocked = blocked;
|
||||||
|
}
|
||||||
|
|
||||||
/** The client who whispered to us last, if still on the server. */
|
/** The client who whispered to us last, if still on the server. */
|
||||||
public ClientEntry lastWhisperer() {
|
public ClientEntry lastWhisperer() {
|
||||||
int id = lastWhisperer;
|
int id = lastWhisperer;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import eu.lixko.ts3j.client.net.PrivilegeKeyAdmin;
|
|||||||
import eu.lixko.ts3j.client.net.Recording;
|
import eu.lixko.ts3j.client.net.Recording;
|
||||||
import eu.lixko.ts3j.client.net.Replies;
|
import eu.lixko.ts3j.client.net.Replies;
|
||||||
import eu.lixko.ts3j.client.net.ServerLogAdmin;
|
import eu.lixko.ts3j.client.net.ServerLogAdmin;
|
||||||
|
import eu.lixko.ts3j.client.net.ServerStatsAdmin;
|
||||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||||
import eu.lixko.ts3j.client.net.Whisper;
|
import eu.lixko.ts3j.client.net.Whisper;
|
||||||
import eu.lixko.ts3j.client.recording.VoiceRecorder;
|
import eu.lixko.ts3j.client.recording.VoiceRecorder;
|
||||||
@@ -198,6 +199,16 @@ public final class ServerSession {
|
|||||||
return conn.getModel();
|
return conn.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean showsQueryClients() {
|
||||||
|
return conn.getModel().showsQueryClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lists the server's ServerQuery clients in the tree too, or hides them again. */
|
||||||
|
public void setShowQueryClients(boolean show) {
|
||||||
|
conn.getModel().setShowQueryClients(show);
|
||||||
|
listener.onModelChanged();
|
||||||
|
}
|
||||||
|
|
||||||
/** Our client id on the server, or -1 while not connected. */
|
/** Our client id on the server, or -1 while not connected. */
|
||||||
public int selfClientId() {
|
public int selfClientId() {
|
||||||
return conn.getSelfClientId();
|
return conn.getSelfClientId();
|
||||||
@@ -590,6 +601,16 @@ public final class ServerSession {
|
|||||||
return whisper != null && targets != null && targets.isEmpty();
|
return whisper != null && targets != null && targets.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether incoming whispers are blocked here, whatever the contacts allow. */
|
||||||
|
public boolean areWhispersBlocked() {
|
||||||
|
return conn.areWhispersBlocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWhispersBlocked(boolean blocked) {
|
||||||
|
conn.setWhispersBlocked(blocked);
|
||||||
|
listener.onSessionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
/** The client who whispered to us last, to whisper back to; null when none is on. */
|
/** The client who whispered to us last, to whisper back to; null when none is on. */
|
||||||
public ClientEntry lastWhisperer() {
|
public ClientEntry lastWhisperer() {
|
||||||
return conn.isConnected() ? conn.lastWhisperer() : null;
|
return conn.isConnected() ? conn.lastWhisperer() : null;
|
||||||
@@ -850,6 +871,10 @@ public final class ServerSession {
|
|||||||
return conn.serverLog();
|
return conn.serverLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerStatsAdmin serverStats() {
|
||||||
|
return conn.serverStats();
|
||||||
|
}
|
||||||
|
|
||||||
public OfflineMessageAdmin offlineMessages() {
|
public OfflineMessageAdmin offlineMessages() {
|
||||||
return conn.offlineMessages();
|
return conn.offlineMessages();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,6 +271,14 @@ public final class MainCommands {
|
|||||||
forEach(targets, s -> s.setCommander(commander));
|
forEach(targets, s -> s.setCommander(commander));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleWhispersBlocked() {
|
||||||
|
setWhispersBlocked(currentConnected(), !connectedTab().map(t -> t.session().areWhispersBlocked()).orElse(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWhispersBlocked(List<ServerSession> targets, boolean blocked) {
|
||||||
|
forEach(targets, s -> s.setWhispersBlocked(blocked));
|
||||||
|
}
|
||||||
|
|
||||||
/** Asks for a new nickname, used on every server. */
|
/** Asks for a new nickname, used on every server. */
|
||||||
public void changeNickname() {
|
public void changeNickname() {
|
||||||
String nickname = JOptionPane.showInputDialog(frame, "New nickname:", settings.nickname.get());
|
String nickname = JOptionPane.showInputDialog(frame, "New nickname:", settings.nickname.get());
|
||||||
@@ -374,6 +382,14 @@ public final class MainCommands {
|
|||||||
onTab(ServerTab::showServerLog);
|
onTab(ServerTab::showServerLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showServerConnectionInfo() {
|
||||||
|
onTab(ServerTab::showServerConnectionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleQueryClients() {
|
||||||
|
connectedTab().ifPresent(tab -> frame.setShowQueryClients(tab, !tab.session().showsQueryClients()));
|
||||||
|
}
|
||||||
|
|
||||||
void showPrivilegeKeys() {
|
void showPrivilegeKeys() {
|
||||||
onTab(ServerTab::showPrivilegeKeys);
|
onTab(ServerTab::showPrivilegeKeys);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
|||||||
// Switching the icon pack in the options dialog re-decorates the whole window.
|
// Switching the icon pack in the options dialog re-decorates the whole window.
|
||||||
IconTheme.get().addListener(() -> SwingUtilities.invokeLater(this::rebuildIcons));
|
IconTheme.get().addListener(() -> SwingUtilities.invokeLater(this::rebuildIcons));
|
||||||
add(tabPane, BorderLayout.CENTER);
|
add(tabPane, BorderLayout.CENTER);
|
||||||
|
tabPane.setStripShown(settings.showServerTabs.get());
|
||||||
|
settings.showServerTabs.addListener(tabPane::setStripShown);
|
||||||
// The tree and the chat each claim Ctrl+F for themselves while they have the focus;
|
// The tree and the chat each claim Ctrl+F for themselves while they have the focus;
|
||||||
// from anywhere else it searches the chat.
|
// from anywhere else it searches the chat.
|
||||||
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||||
@@ -357,9 +359,16 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
|||||||
public void tabConnected(ServerTab tab) {
|
public void tabConnected(ServerTab tab) {
|
||||||
if (!tabs.contains(tab)) return;
|
if (!tabs.contains(tab)) return;
|
||||||
sessions.connected(tab.session());
|
sessions.connected(tab.session());
|
||||||
|
tab.session().setShowQueryClients(bookmarks.showsQueryClients(tab.session().address(), tab.session().port()));
|
||||||
tabUpdated(tab);
|
tabUpdated(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lists the ServerQuery clients on {@code tab}, or hides them, from now on whenever it is bookmarked. */
|
||||||
|
void setShowQueryClients(ServerTab tab, boolean show) {
|
||||||
|
tab.session().setShowQueryClients(show);
|
||||||
|
if (bookmarks.rememberQueryClients(tab.session().address(), tab.session().port(), show)) bookmarks.save();
|
||||||
|
}
|
||||||
|
|
||||||
public void tabDisconnected(ServerTab tab) {
|
public void tabDisconnected(ServerTab tab) {
|
||||||
if (!tabs.contains(tab)) return;
|
if (!tabs.contains(tab)) return;
|
||||||
sessions.disconnected(tab.session());
|
sessions.disconnected(tab.session());
|
||||||
|
|||||||
@@ -122,6 +122,13 @@ final class MainToolbar extends JToolBar {
|
|||||||
private JPopupMenu buildContextMenu() {
|
private JPopupMenu buildContextMenu() {
|
||||||
JPopupMenu menu = new JPopupMenu();
|
JPopupMenu menu = new JPopupMenu();
|
||||||
|
|
||||||
|
JCheckBoxMenuItem tabsItem = new JCheckBoxMenuItem("Show Server Tabs", settings.showServerTabs.get());
|
||||||
|
tabsItem.addActionListener(e -> {
|
||||||
|
settings.showServerTabs.set(tabsItem.isSelected());
|
||||||
|
settings.save();
|
||||||
|
});
|
||||||
|
settings.showServerTabs.addListener(tabsItem::setSelected);
|
||||||
|
|
||||||
JCheckBoxMenuItem statusBarItem = new JCheckBoxMenuItem("Show Status Bar", settings.showStatusBar.get());
|
JCheckBoxMenuItem statusBarItem = new JCheckBoxMenuItem("Show Status Bar", settings.showStatusBar.get());
|
||||||
statusBarItem.addActionListener(e -> {
|
statusBarItem.addActionListener(e -> {
|
||||||
settings.showStatusBar.set(statusBarItem.isSelected());
|
settings.showStatusBar.set(statusBarItem.isSelected());
|
||||||
@@ -144,6 +151,7 @@ final class MainToolbar extends JToolBar {
|
|||||||
JMenuItem customize = new JMenuItem("Customize Toolbar…");
|
JMenuItem customize = new JMenuItem("Customize Toolbar…");
|
||||||
customize.addActionListener(e -> CustomizeToolbarDialog.show(this, settings, actions));
|
customize.addActionListener(e -> CustomizeToolbarDialog.show(this, settings, actions));
|
||||||
|
|
||||||
|
menu.add(tabsItem);
|
||||||
menu.add(statusBarItem);
|
menu.add(statusBarItem);
|
||||||
menu.add(volumeItem);
|
menu.add(volumeItem);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import java.util.List;
|
|||||||
* Container for the open server connections. With a single connection the
|
* Container for the open server connections. With a single connection the
|
||||||
* server view fills the window as it always did; from the second connection on
|
* server view fills the window as it always did; from the second connection on
|
||||||
* the views move into a {@link JTabbedPane} whose tab strip sits directly under
|
* the views move into a {@link JTabbedPane} whose tab strip sits directly under
|
||||||
* the toolbar.
|
* the toolbar. With the strip turned off, the selected view fills the window alone.
|
||||||
*/
|
*/
|
||||||
final class ServerTabPane extends JPanel {
|
final class ServerTabPane extends JPanel {
|
||||||
|
|
||||||
@@ -42,8 +42,11 @@ final class ServerTabPane extends JPanel {
|
|||||||
private final List<ServerTab> tabs = new ArrayList<>();
|
private final List<ServerTab> tabs = new ArrayList<>();
|
||||||
private final TabDragReorder dragReorder = new TabDragReorder(tabbed, this::moveTab);
|
private final TabDragReorder dragReorder = new TabDragReorder(tabbed, this::moveTab);
|
||||||
|
|
||||||
/** True while the tab strip is in use, i.e. more than one connection is open. */
|
/** True while the tab strip is in use, i.e. more than one connection is open and it is wanted. */
|
||||||
private boolean tabbedMode;
|
private boolean tabbedMode;
|
||||||
|
private boolean stripShown = true;
|
||||||
|
/** The tab on screen; the one shown alone while there is no strip. */
|
||||||
|
private ServerTab selected;
|
||||||
/** Suppresses selection callbacks while we rearrange the pane ourselves. */
|
/** Suppresses selection callbacks while we rearrange the pane ourselves. */
|
||||||
private boolean updating;
|
private boolean updating;
|
||||||
/** Remembered so a drag-reorder can rebuild the tab labels without the caller's help. */
|
/** Remembered so a drag-reorder can rebuild the tab labels without the caller's help. */
|
||||||
@@ -114,12 +117,29 @@ final class ServerTabPane extends JPanel {
|
|||||||
|
|
||||||
void removeTab(ServerTab tab) {
|
void removeTab(ServerTab tab) {
|
||||||
tabs.remove(tab);
|
tabs.remove(tab);
|
||||||
|
if (selected == tab) selected = null;
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Shows or hides the tab strip; without it, tabs are switched by hotkeys or the menus. */
|
||||||
|
void setStripShown(boolean shown) {
|
||||||
|
if (stripShown == shown) return;
|
||||||
|
stripShown = shown;
|
||||||
|
relayout();
|
||||||
|
if (tabbedMode && selected != null) setSelected(selected);
|
||||||
|
refresh(lastMicTab);
|
||||||
|
}
|
||||||
|
|
||||||
void setSelected(ServerTab tab) {
|
void setSelected(ServerTab tab) {
|
||||||
int i = tabs.indexOf(tab);
|
int i = tabs.indexOf(tab);
|
||||||
if (!tabbedMode || i < 0 || tabbed.getSelectedIndex() == i) return;
|
if (i < 0) return;
|
||||||
|
ServerTab previous = selected;
|
||||||
|
selected = tab;
|
||||||
|
if (!tabbedMode) {
|
||||||
|
if (previous != tab) relayout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tabbed.getSelectedIndex() == i) return;
|
||||||
updating = true;
|
updating = true;
|
||||||
try {
|
try {
|
||||||
tabbed.setSelectedIndex(i);
|
tabbed.setSelectedIndex(i);
|
||||||
@@ -145,7 +165,7 @@ final class ServerTabPane extends JPanel {
|
|||||||
* keeping whatever is currently selected on screen.
|
* keeping whatever is currently selected on screen.
|
||||||
*/
|
*/
|
||||||
private void relayout() {
|
private void relayout() {
|
||||||
boolean wantTabs = tabs.size() > 1;
|
boolean wantTabs = stripShown && tabs.size() > 1;
|
||||||
updating = true;
|
updating = true;
|
||||||
try {
|
try {
|
||||||
removeAll();
|
removeAll();
|
||||||
@@ -154,7 +174,7 @@ final class ServerTabPane extends JPanel {
|
|||||||
for (ServerTab tab : tabs) tabbed.addTab(tab.session().title(), tab.component());
|
for (ServerTab tab : tabs) tabbed.addTab(tab.session().title(), tab.component());
|
||||||
add(tabbed, BorderLayout.CENTER);
|
add(tabbed, BorderLayout.CENTER);
|
||||||
} else if (!tabs.isEmpty()) {
|
} else if (!tabs.isEmpty()) {
|
||||||
add(tabs.get(0).component(), BorderLayout.CENTER);
|
add((selected != null ? selected : tabs.get(0)).component(), BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
tabbedMode = wantTabs;
|
tabbedMode = wantTabs;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ final class ToolbarAction {
|
|||||||
RECORDING("Recording"),
|
RECORDING("Recording"),
|
||||||
CHANNEL("Channel"),
|
CHANNEL("Channel"),
|
||||||
CLIENT("Client"),
|
CLIENT("Client"),
|
||||||
|
SERVER("Server"),
|
||||||
MISC("Misc");
|
MISC("Misc");
|
||||||
|
|
||||||
final String label;
|
final String label;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ final class ToolbarActions {
|
|||||||
addRecording();
|
addRecording();
|
||||||
addChannel();
|
addChannel();
|
||||||
addClient();
|
addClient();
|
||||||
|
addServer();
|
||||||
addMisc();
|
addMisc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +113,10 @@ final class ToolbarActions {
|
|||||||
.enabledWhen(() -> is(ServerSession::hasAvatar));
|
.enabledWhen(() -> is(ServerSession::hasAvatar));
|
||||||
add("giantPtt", Category.SELF, "Giant PTT", commands::showGiantPtt, "CAPTURE");
|
add("giantPtt", Category.SELF, "Giant PTT", commands::showGiantPtt, "CAPTURE");
|
||||||
add("soundboard", Category.SELF, "Soundboard", commands::showSoundboard, "SOUNDPACK", "MUSIC");
|
add("soundboard", Category.SELF, "Soundboard", commands::showSoundboard, "SOUNDPACK", "MUSIC");
|
||||||
|
add("blockWhispers", Category.SELF, "Toggle Block Incoming Whispers", commands::toggleWhispersBlocked,
|
||||||
|
"TOGGLE_BLOCK_INCOMING_WHISPERS")
|
||||||
|
.toggle(() -> is(ServerSession::areWhispersBlocked))
|
||||||
|
.enabledWhen(this::connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDialogs() {
|
private void addDialogs() {
|
||||||
@@ -257,6 +262,16 @@ final class ToolbarActions {
|
|||||||
.enabledWhen(() -> anyClient().isPresent());
|
.enabledWhen(() -> anyClient().isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addServer() {
|
||||||
|
add("serverConnectionInfo", Category.SERVER, "Server Connection Info", commands::showServerConnectionInfo,
|
||||||
|
"SERVER_GREEN")
|
||||||
|
.enabledWhen(() -> permitted(Permissions::canViewServerConnectionInfo));
|
||||||
|
add("toggleQueryClients", Category.SERVER, "Toggle ServerQuery Clients", commands::toggleQueryClients,
|
||||||
|
"TOGGLE_SERVER_QUERY_CLIENTS", "SERVER_QUERY")
|
||||||
|
.toggle(() -> is(ServerSession::showsQueryClients))
|
||||||
|
.enabledWhen(this::connected);
|
||||||
|
}
|
||||||
|
|
||||||
private void addMisc() {
|
private void addMisc() {
|
||||||
add("collapseAll", Category.MISC, "Collapse All", () -> collapseAll(true), "CHANNEL_COLLAPSE_ALL")
|
add("collapseAll", Category.MISC, "Collapse All", () -> collapseAll(true), "CHANNEL_COLLAPSE_ALL")
|
||||||
.enabledWhen(this::connected);
|
.enabledWhen(this::connected);
|
||||||
|
|||||||
@@ -100,6 +100,11 @@ public final class HotkeyActions implements HotkeyEngine.Handler {
|
|||||||
else commands.changeNickname(hotkey.argument);
|
else commands.changeNickname(hotkey.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WHISPER_BLOCK_ACTIVATE -> commands.setWhispersBlocked(targets, true);
|
||||||
|
case WHISPER_BLOCK_DEACTIVATE -> commands.setWhispersBlocked(targets, false);
|
||||||
|
case WHISPER_BLOCK_TOGGLE ->
|
||||||
|
commands.setWhispersBlocked(targets, !any(targets, ServerSession::areWhispersBlocked));
|
||||||
|
|
||||||
case RECORDING_START -> commands.startRecording(targets, false);
|
case RECORDING_START -> commands.startRecording(targets, false);
|
||||||
case RECORDING_START_MULTITRACK -> commands.startRecording(targets, true);
|
case RECORDING_START_MULTITRACK -> commands.startRecording(targets, true);
|
||||||
case RECORDING_STOP -> commands.stopRecording(targets);
|
case RECORDING_STOP -> commands.stopRecording(targets);
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public final class BookmarksDialog extends JDialog {
|
|||||||
private final JPasswordField channelPassword = new JPasswordField();
|
private final JPasswordField channelPassword = new JPasswordField();
|
||||||
private final JCheckBox connectOnStartup = new JCheckBox("Connect on startup");
|
private final JCheckBox connectOnStartup = new JCheckBox("Connect on startup");
|
||||||
private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features");
|
private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features");
|
||||||
|
private final JCheckBox showQueryClients = new JCheckBox("Show ServerQuery clients");
|
||||||
private final IdentityChooser identity;
|
private final IdentityChooser identity;
|
||||||
|
|
||||||
private final JPanel details;
|
private final JPanel details;
|
||||||
@@ -145,6 +146,12 @@ public final class BookmarksDialog extends JDialog {
|
|||||||
connectOnStartup.setToolTipText("Connect to this server automatically when the client starts. "
|
connectOnStartup.setToolTipText("Connect to this server automatically when the client starts. "
|
||||||
+ "Several bookmarks may be flagged; each opens its own tab.");
|
+ "Several bookmarks may be flagged; each opens its own tab.");
|
||||||
|
|
||||||
|
// Takes effect at once on the server, when we are on it, as the toolbar's toggle would.
|
||||||
|
showQueryClients.addActionListener(e -> {
|
||||||
|
ServerSession on = sessionHere();
|
||||||
|
if (on != null) on.setShowQueryClients(showQueryClients.isSelected());
|
||||||
|
});
|
||||||
|
|
||||||
thisChannel.setToolTipText("This channel");
|
thisChannel.setToolTipText("This channel");
|
||||||
if (thisChannel.getIcon() == null) thisChannel.setText("This channel");
|
if (thisChannel.getIcon() == null) thisChannel.setText("This channel");
|
||||||
thisChannel.addActionListener(e -> {
|
thisChannel.addActionListener(e -> {
|
||||||
@@ -168,6 +175,7 @@ public final class BookmarksDialog extends JDialog {
|
|||||||
addRow(panel, row++, "Identity:", identity);
|
addRow(panel, row++, "Identity:", identity);
|
||||||
addRow(panel, row++, "", connectOnStartup);
|
addRow(panel, row++, "", connectOnStartup);
|
||||||
addRow(panel, row++, "", myTeamSpeakFeatures);
|
addRow(panel, row++, "", myTeamSpeakFeatures);
|
||||||
|
addRow(panel, row++, "", showQueryClients);
|
||||||
|
|
||||||
GridBagConstraints filler = new GridBagConstraints();
|
GridBagConstraints filler = new GridBagConstraints();
|
||||||
filler.gridx = 0;
|
filler.gridx = 0;
|
||||||
@@ -235,6 +243,7 @@ public final class BookmarksDialog extends JDialog {
|
|||||||
channelPassword.setText(b == null ? "" : nullToEmpty(b.channelPassword));
|
channelPassword.setText(b == null ? "" : nullToEmpty(b.channelPassword));
|
||||||
connectOnStartup.setSelected(b != null && b.connectOnStartup);
|
connectOnStartup.setSelected(b != null && b.connectOnStartup);
|
||||||
myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures);
|
myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures);
|
||||||
|
showQueryClients.setSelected(b != null && b.showQueryClients);
|
||||||
identity.setSelectedIdentityId(b == null ? "" : nullToEmpty(b.identityId));
|
identity.setSelectedIdentityId(b == null ? "" : nullToEmpty(b.identityId));
|
||||||
updateThisChannel();
|
updateThisChannel();
|
||||||
}
|
}
|
||||||
@@ -288,6 +297,7 @@ public final class BookmarksDialog extends JDialog {
|
|||||||
editing.identityId = identity.getSelectedIdentityId();
|
editing.identityId = identity.getSelectedIdentityId();
|
||||||
editing.connectOnStartup = connectOnStartup.isSelected();
|
editing.connectOnStartup = connectOnStartup.isSelected();
|
||||||
editing.myTeamSpeakFeatures = myTeamSpeakFeatures.isSelected();
|
editing.myTeamSpeakFeatures = myTeamSpeakFeatures.isSelected();
|
||||||
|
editing.showQueryClients = showQueryClients.isSelected();
|
||||||
list.repaint();
|
list.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-88
@@ -4,7 +4,6 @@ import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
|||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||||
import eu.lixko.ts3j.client.net.ConnectionStats;
|
import eu.lixko.ts3j.client.net.ConnectionStats;
|
||||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.Row;
|
|
||||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.TrafficRow;
|
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.TrafficRow;
|
||||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat;
|
import eu.lixko.ts3j.client.net.ConnectionStatsFormat;
|
||||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||||
@@ -22,7 +21,6 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSeparator;
|
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
@@ -55,7 +53,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
|||||||
private static final int AVATAR_SIZE = 80;
|
private static final int AVATAR_SIZE = 80;
|
||||||
/** Sample texts sizing the columns, as the official window does, so they don't jitter. */
|
/** Sample texts sizing the columns, as the official window does, so they don't jitter. */
|
||||||
private static final String TOTAL_SAMPLE = "100.00 %";
|
private static final String TOTAL_SAMPLE = "100.00 %";
|
||||||
private static final String VALUE_SAMPLE = "1023.00 KiB/s";
|
private static final String VALUE_SAMPLE = Figures.VALUE_SAMPLE;
|
||||||
|
|
||||||
private final ServerSession session;
|
private final ServerSession session;
|
||||||
private final int clientId;
|
private final int clientId;
|
||||||
@@ -212,85 +210,6 @@ public final class ConnectionInfoDialog extends JDialog {
|
|||||||
return new ImageIcon(icon.getImage().getScaledInstance(size.width, size.height, Image.SCALE_SMOOTH));
|
return new ImageIcon(icon.getImage().getScaledInstance(size.width, size.height, Image.SCALE_SMOOTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- figures ----
|
|
||||||
|
|
||||||
private static JLabel label(String text) {
|
|
||||||
JLabel l = new JLabel(text);
|
|
||||||
l.setFont(Theme.uiFont());
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Pins a label's width to that of {@code sample}, so a growing figure doesn't resize the window. */
|
|
||||||
private static JLabel sized(JLabel l, String sample) {
|
|
||||||
Dimension pref = l.getPreferredSize();
|
|
||||||
int width = l.getFontMetrics(l.getFont()).stringWidth(sample);
|
|
||||||
l.setPreferredSize(new Dimension(Math.max(pref.width, width), pref.height));
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GridBagConstraints cell(int x, int y, int anchor, Insets insets) {
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
|
||||||
c.gridx = x;
|
|
||||||
c.gridy = y;
|
|
||||||
c.anchor = anchor;
|
|
||||||
c.insets = UIScale.scale(insets);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Labelled figures, one per row, in groups set apart by a rule; refreshed in place, and
|
|
||||||
* rows an update leaves out hide.
|
|
||||||
*/
|
|
||||||
private static final class Figures extends JPanel {
|
|
||||||
private final List<List<JLabel[]>> groups = new ArrayList<>();
|
|
||||||
private int lastRow;
|
|
||||||
|
|
||||||
Figures(List<List<Row>> rows, boolean valuesRight) {
|
|
||||||
super(new GridBagLayout());
|
|
||||||
setOpaque(false);
|
|
||||||
int y = 0;
|
|
||||||
for (List<Row> group : rows) {
|
|
||||||
if (y > 0) {
|
|
||||||
GridBagConstraints rule = cell(0, y++, GridBagConstraints.WEST, new Insets(6, 0, 6, 0));
|
|
||||||
rule.gridwidth = 2;
|
|
||||||
rule.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
add(new JSeparator(), rule);
|
|
||||||
}
|
|
||||||
List<JLabel[]> labels = new ArrayList<>();
|
|
||||||
for (Row row : group) {
|
|
||||||
JLabel key = label(row.label());
|
|
||||||
JLabel value = label(row.value());
|
|
||||||
labels.add(new JLabel[]{key, value});
|
|
||||||
add(key, cell(0, y, GridBagConstraints.WEST, new Insets(3, 0, 3, 16)));
|
|
||||||
GridBagConstraints vc = cell(1, y, valuesRight ? GridBagConstraints.EAST : GridBagConstraints.WEST,
|
|
||||||
new Insets(3, 0, 3, 0));
|
|
||||||
vc.weightx = 1;
|
|
||||||
add(value, vc);
|
|
||||||
lastRow = y++;
|
|
||||||
}
|
|
||||||
groups.add(labels);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Puts {@code c} after the last row's value. */
|
|
||||||
void addTrailing(JComponent c) {
|
|
||||||
add(c, cell(2, lastRow, GridBagConstraints.EAST, new Insets(0, 6, 0, 0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(List<List<Row>> rows) {
|
|
||||||
for (int g = 0; g < groups.size(); g++) {
|
|
||||||
List<JLabel[]> labels = groups.get(g);
|
|
||||||
List<Row> group = rows.get(g);
|
|
||||||
for (int i = 0; i < labels.size(); i++) {
|
|
||||||
boolean shown = i < group.size();
|
|
||||||
labels.get(i)[0].setVisible(shown);
|
|
||||||
labels.get(i)[1].setVisible(shown);
|
|
||||||
if (shown) labels.get(i)[1].setText(group.get(i).value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** One traffic category: a row per figure under Total / In / Out headings. */
|
/** One traffic category: a row per figure under Total / In / Out headings. */
|
||||||
private static final class TrafficTable extends JPanel {
|
private static final class TrafficTable extends JPanel {
|
||||||
private final ConnectionStats.Kind kind;
|
private final ConnectionStats.Kind kind;
|
||||||
@@ -304,7 +223,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
|||||||
|
|
||||||
List<String> columns = ConnectionStatsFormat.COLUMNS;
|
List<String> columns = ConnectionStatsFormat.COLUMNS;
|
||||||
for (int c = 0; c < columns.size(); c++) {
|
for (int c = 0; c < columns.size(); c++) {
|
||||||
JLabel heading = label(columns.get(c));
|
JLabel heading = Figures.label(columns.get(c));
|
||||||
heading.setFont(heading.getFont().deriveFont(Font.ITALIC));
|
heading.setFont(heading.getFont().deriveFont(Font.ITALIC));
|
||||||
add(heading, column(c + 1, 0));
|
add(heading, column(c + 1, 0));
|
||||||
}
|
}
|
||||||
@@ -312,19 +231,19 @@ public final class ConnectionInfoDialog extends JDialog {
|
|||||||
cells = new JLabel[rows.size()][];
|
cells = new JLabel[rows.size()][];
|
||||||
for (int r = 0; r < rows.size(); r++) {
|
for (int r = 0; r < rows.size(); r++) {
|
||||||
TrafficRow row = rows.get(r);
|
TrafficRow row = rows.get(r);
|
||||||
add(label(row.label()), cell(0, r + 1, GridBagConstraints.WEST, new Insets(3, 0, 3, 8)));
|
add(Figures.label(row.label()), Figures.cell(0, r + 1, GridBagConstraints.WEST, new Insets(3, 0, 3, 8)));
|
||||||
cells[r] = new JLabel[]{
|
cells[r] = new JLabel[]{
|
||||||
sized(label(row.total()), TOTAL_SAMPLE), sized(label(row.in()), VALUE_SAMPLE),
|
Figures.sized(Figures.label(row.total()), TOTAL_SAMPLE), Figures.sized(Figures.label(row.in()), VALUE_SAMPLE),
|
||||||
sized(label(row.out()), VALUE_SAMPLE)};
|
Figures.sized(Figures.label(row.out()), VALUE_SAMPLE)};
|
||||||
for (int c = 0; c < cells[r].length; c++) add(cells[r][c], column(c + 1, r + 1));
|
for (int c = 0; c < cells[r].length; c++) add(cells[r][c], column(c + 1, r + 1));
|
||||||
}
|
}
|
||||||
GridBagConstraints filler = cell(0, rows.size() + 1, GridBagConstraints.WEST, new Insets(0, 0, 0, 0));
|
GridBagConstraints filler = Figures.cell(0, rows.size() + 1, GridBagConstraints.WEST, new Insets(0, 0, 0, 0));
|
||||||
filler.weighty = 1;
|
filler.weighty = 1;
|
||||||
add(Box.createGlue(), filler);
|
add(Box.createGlue(), filler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GridBagConstraints column(int x, int y) {
|
private static GridBagConstraints column(int x, int y) {
|
||||||
GridBagConstraints c = cell(x, y, GridBagConstraints.WEST, new Insets(3, 8, 3, 8));
|
GridBagConstraints c = Figures.cell(x, y, GridBagConstraints.WEST, new Insets(3, 8, 3, 8));
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package eu.lixko.ts3j.client.ui.server;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.Row;
|
||||||
|
import eu.lixko.ts3j.client.ui.Theme;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Labelled figures, one per row, in groups set apart by a rule; refreshed in place, and
|
||||||
|
* rows an update leaves out hide. The connection info windows' summaries.
|
||||||
|
*/
|
||||||
|
final class Figures extends JPanel {
|
||||||
|
/** A wide traffic figure, to size value columns by so they don't jitter. */
|
||||||
|
static final String VALUE_SAMPLE = "1023.00 KiB/s";
|
||||||
|
|
||||||
|
private final List<List<JLabel[]>> groups = new ArrayList<>();
|
||||||
|
private int lastRow;
|
||||||
|
|
||||||
|
Figures(List<List<Row>> rows, boolean valuesRight) {
|
||||||
|
super(new GridBagLayout());
|
||||||
|
setOpaque(false);
|
||||||
|
int y = 0;
|
||||||
|
for (List<Row> group : rows) {
|
||||||
|
if (y > 0) {
|
||||||
|
GridBagConstraints rule = cell(0, y++, GridBagConstraints.WEST, new Insets(6, 0, 6, 0));
|
||||||
|
rule.gridwidth = 2;
|
||||||
|
rule.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
add(new JSeparator(), rule);
|
||||||
|
}
|
||||||
|
List<JLabel[]> labels = new ArrayList<>();
|
||||||
|
for (Row row : group) {
|
||||||
|
JLabel key = label(row.label());
|
||||||
|
JLabel value = label(row.value());
|
||||||
|
labels.add(new JLabel[]{key, value});
|
||||||
|
add(key, cell(0, y, GridBagConstraints.WEST, new Insets(3, 0, 3, 16)));
|
||||||
|
GridBagConstraints vc = cell(1, y, valuesRight ? GridBagConstraints.EAST : GridBagConstraints.WEST,
|
||||||
|
new Insets(3, 0, 3, 0));
|
||||||
|
vc.weightx = 1;
|
||||||
|
add(value, vc);
|
||||||
|
lastRow = y++;
|
||||||
|
}
|
||||||
|
groups.add(labels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Puts {@code c} after the last row's value. */
|
||||||
|
void addTrailing(JComponent c) {
|
||||||
|
add(c, cell(2, lastRow, GridBagConstraints.EAST, new Insets(0, 6, 0, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Puts {@code c} after the value of row {@code index}, counting rows across groups. */
|
||||||
|
void addTrailing(int index, JComponent c) {
|
||||||
|
int y = 0;
|
||||||
|
for (int g = 0; g < groups.size(); g++) {
|
||||||
|
if (g > 0) y++; // the rule
|
||||||
|
if (index < groups.get(g).size()) {
|
||||||
|
add(c, cell(2, y + index, GridBagConstraints.EAST, new Insets(0, 6, 0, 0)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index -= groups.get(g).size();
|
||||||
|
y += groups.get(g).size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(List<List<Row>> rows) {
|
||||||
|
for (int g = 0; g < groups.size(); g++) {
|
||||||
|
List<JLabel[]> labels = groups.get(g);
|
||||||
|
List<Row> group = rows.get(g);
|
||||||
|
for (int i = 0; i < labels.size(); i++) {
|
||||||
|
boolean shown = i < group.size();
|
||||||
|
labels.get(i)[0].setVisible(shown);
|
||||||
|
labels.get(i)[1].setVisible(shown);
|
||||||
|
if (shown) labels.get(i)[1].setText(group.get(i).value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static JLabel label(String text) {
|
||||||
|
JLabel l = new JLabel(text);
|
||||||
|
l.setFont(Theme.uiFont());
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pins a label's width to that of {@code sample}, so a growing figure doesn't resize the window. */
|
||||||
|
static JLabel sized(JLabel l, String sample) {
|
||||||
|
Dimension pref = l.getPreferredSize();
|
||||||
|
int width = l.getFontMetrics(l.getFont()).stringWidth(sample);
|
||||||
|
l.setPreferredSize(new Dimension(Math.max(pref.width, width), pref.height));
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GridBagConstraints cell(int x, int y, int anchor, Insets insets) {
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
c.gridx = x;
|
||||||
|
c.gridy = y;
|
||||||
|
c.anchor = anchor;
|
||||||
|
c.insets = UIScale.scale(insets);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
package eu.lixko.ts3j.client.ui.server;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
import eu.lixko.ts3j.client.net.ConnectionStatsFormat;
|
||||||
|
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.TrafficRow;
|
||||||
|
import eu.lixko.ts3j.client.net.RequestException;
|
||||||
|
import eu.lixko.ts3j.client.net.ServerStats;
|
||||||
|
import eu.lixko.ts3j.client.session.ServerSession;
|
||||||
|
import eu.lixko.ts3j.client.ui.Theme;
|
||||||
|
import eu.lixko.ts3j.client.ui.icons.Icons;
|
||||||
|
import eu.lixko.ts3j.client.ui.widget.Dialogs;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Live "Server Connection Info" window, laid out as TeamSpeak 3's: the server's name,
|
||||||
|
* version, uptime, address, ping and loss, above an In / Out table of everything the
|
||||||
|
* server exchanged with its clients. Polls once a second while open.
|
||||||
|
*/
|
||||||
|
final class ServerConnectionInfoDialog extends JDialog {
|
||||||
|
|
||||||
|
private static final int REFRESH_MS = 1000;
|
||||||
|
private static final int ADDRESS_ROW = 4;
|
||||||
|
|
||||||
|
private final ServerSession session;
|
||||||
|
private final javax.swing.Timer timer;
|
||||||
|
private final AtomicBoolean inFlight = new AtomicBoolean();
|
||||||
|
private final Figures summary;
|
||||||
|
private final JLabel[][] cells;
|
||||||
|
|
||||||
|
ServerConnectionInfoDialog(Frame owner, ServerSession session) {
|
||||||
|
super(owner, "Server Connection Info", false);
|
||||||
|
this.session = session;
|
||||||
|
summary = new Figures(List.of(summaryRows(ServerStats.UNKNOWN)), false);
|
||||||
|
|
||||||
|
JButton copy = new JButton(Icons.of("COPY"));
|
||||||
|
copy.setToolTipText("Copy server address to clipboard");
|
||||||
|
copy.setMargin(UIScale.scale(new Insets(1, 1, 1, 1)));
|
||||||
|
copy.addActionListener(e -> Toolkit.getDefaultToolkit().getSystemClipboard()
|
||||||
|
.setContents(new StringSelection(address()), null));
|
||||||
|
summary.addTrailing(ADDRESS_ROW, copy);
|
||||||
|
|
||||||
|
List<TrafficRow> rows = ConnectionStatsFormat.serverTrafficRows(ServerStats.UNKNOWN);
|
||||||
|
cells = new JLabel[rows.size()][];
|
||||||
|
|
||||||
|
JPanel content = new JPanel(new BorderLayout(0, UIScale.scale(12)));
|
||||||
|
content.setBackground(Theme.windowBg());
|
||||||
|
content.setBorder(new ScaledEmptyBorder(10, 10, 10, 10));
|
||||||
|
content.add(summary, BorderLayout.NORTH);
|
||||||
|
content.add(buildTable(rows), BorderLayout.CENTER);
|
||||||
|
content.add(buildButtons(), BorderLayout.SOUTH);
|
||||||
|
setContentPane(content);
|
||||||
|
|
||||||
|
Dialogs.closeOnEscape(this);
|
||||||
|
// Disposing is what stops the refresh timer, so the window button must not merely hide.
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(owner);
|
||||||
|
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
timer.stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer = new javax.swing.Timer(REFRESH_MS, e -> refresh());
|
||||||
|
timer.setInitialDelay(0);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel buildTable(List<TrafficRow> rows) {
|
||||||
|
JPanel table = new JPanel(new GridBagLayout());
|
||||||
|
table.setOpaque(false);
|
||||||
|
List<String> columns = ConnectionStatsFormat.SERVER_COLUMNS;
|
||||||
|
for (int c = 0; c < columns.size(); c++) {
|
||||||
|
JLabel heading = Figures.label(columns.get(c));
|
||||||
|
heading.setFont(heading.getFont().deriveFont(Font.ITALIC));
|
||||||
|
table.add(heading, column(c + 1, 0));
|
||||||
|
}
|
||||||
|
GridBagConstraints rule = Figures.cell(0, 1, GridBagConstraints.WEST, new Insets(2, 0, 4, 0));
|
||||||
|
rule.gridwidth = columns.size() + 1;
|
||||||
|
rule.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
table.add(new JSeparator(), rule);
|
||||||
|
for (int r = 0; r < rows.size(); r++) {
|
||||||
|
TrafficRow row = rows.get(r);
|
||||||
|
table.add(Figures.label(row.label()), Figures.cell(0, r + 2, GridBagConstraints.WEST, new Insets(3, 0, 3, 16)));
|
||||||
|
cells[r] = new JLabel[]{Figures.sized(Figures.label(row.in()), Figures.VALUE_SAMPLE),
|
||||||
|
Figures.sized(Figures.label(row.out()), Figures.VALUE_SAMPLE)};
|
||||||
|
for (int c = 0; c < cells[r].length; c++) table.add(cells[r][c], column(c + 1, r + 2));
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GridBagConstraints column(int x, int y) {
|
||||||
|
GridBagConstraints c = Figures.cell(x, y, GridBagConstraints.WEST, new Insets(3, 0, 3, 16));
|
||||||
|
c.weightx = 1;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel buildButtons() {
|
||||||
|
JPanel bar = new JPanel();
|
||||||
|
bar.setLayout(new BoxLayout(bar, BoxLayout.X_AXIS));
|
||||||
|
bar.setOpaque(false);
|
||||||
|
bar.add(Box.createHorizontalGlue());
|
||||||
|
JButton close = new JButton("Close", Icons.of("CLOSE"));
|
||||||
|
close.addActionListener(e -> dispose());
|
||||||
|
bar.add(close);
|
||||||
|
return bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh() {
|
||||||
|
if (!session.isConnected()) {
|
||||||
|
timer.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!inFlight.compareAndSet(false, true)) return; // a previous poll is still running
|
||||||
|
session.serverStats().read().whenComplete((stats, failure) -> SwingUtilities.invokeLater(() -> {
|
||||||
|
inFlight.set(false);
|
||||||
|
if (failure == null) apply(stats);
|
||||||
|
else failed(RequestException.of(failure));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void apply(ServerStats stats) {
|
||||||
|
if (!isDisplayable()) return;
|
||||||
|
summary.update(List.of(summaryRows(stats)));
|
||||||
|
List<TrafficRow> rows = ConnectionStatsFormat.serverTrafficRows(stats);
|
||||||
|
for (int r = 0; r < rows.size(); r++) {
|
||||||
|
cells[r][0].setText(rows.get(r).in());
|
||||||
|
cells[r][1].setText(rows.get(r).out());
|
||||||
|
}
|
||||||
|
// The uptime gains days, the version shows once known; grow rather than cut them off.
|
||||||
|
if (getPreferredSize().width > getWidth()) pack();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A refusal won't change by asking again, so it ends the polling; a lost connection already has. */
|
||||||
|
private void failed(RequestException failure) {
|
||||||
|
if (!isDisplayable() || failure.kind() == RequestException.Kind.NOT_CONNECTED) return;
|
||||||
|
timer.stop();
|
||||||
|
JOptionPane.showMessageDialog(this, failure.getMessage(), "Error requesting server connection info",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ConnectionStatsFormat.Row> summaryRows(ServerStats stats) {
|
||||||
|
return ConnectionStatsFormat.serverSummaryRows(session.model(), address(), stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String address() {
|
||||||
|
return session.address() + ":" + session.port();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,11 @@ final class ServerMenu {
|
|||||||
spacer.setToolTipText("Create a new spacer");
|
spacer.setToolTipText("Create a new spacer");
|
||||||
spacer.addActionListener(a -> actions.createSpacer());
|
spacer.addActionListener(a -> actions.createSpacer());
|
||||||
menu.add(spacer);
|
menu.add(spacer);
|
||||||
|
menu.addSeparator();
|
||||||
|
JMenuItem info = new JMenuItem("Server Connection Info", Icons.of("SERVER_GREEN"));
|
||||||
|
info.setEnabled(actions.canViewServerConnectionInfo());
|
||||||
|
info.addActionListener(a -> actions.showServerConnectionInfo());
|
||||||
|
menu.add(info);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public final class ServerTab {
|
|||||||
/** The one open ban list window for this server, if any. */
|
/** The one open ban list window for this server, if any. */
|
||||||
/** The open ban list, complaints and other list windows, one of each kind. */
|
/** The open ban list, complaints and other list windows, one of each kind. */
|
||||||
private final Map<Class<? extends AbstractServerListDialog>, AbstractServerListDialog> listWindows = new HashMap<>();
|
private final Map<Class<? extends AbstractServerListDialog>, AbstractServerListDialog> listWindows = new HashMap<>();
|
||||||
|
private ServerConnectionInfoDialog serverInfoWindow;
|
||||||
/** The unread count last reported, to tell new mail from messages being read. */
|
/** The unread count last reported, to tell new mail from messages being read. */
|
||||||
private int unreadMessages;
|
private int unreadMessages;
|
||||||
|
|
||||||
@@ -211,6 +212,16 @@ public final class ServerTab {
|
|||||||
showListWindow(ServerLogDialog.class, () -> new ServerLogDialog(host, session, settings));
|
showListWindow(ServerLogDialog.class, () -> new ServerLogDialog(host, session, settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Opens the server's connection figures, or brings the already open window forward. */
|
||||||
|
public void showServerConnectionInfo() {
|
||||||
|
if (!session.isConnected()) return;
|
||||||
|
if (serverInfoWindow == null || !serverInfoWindow.isDisplayable()) {
|
||||||
|
serverInfoWindow = new ServerConnectionInfoDialog(host, session);
|
||||||
|
}
|
||||||
|
serverInfoWindow.setVisible(true);
|
||||||
|
serverInfoWindow.toFront();
|
||||||
|
}
|
||||||
|
|
||||||
public void showPrivilegeKeys() {
|
public void showPrivilegeKeys() {
|
||||||
showListWindow(PrivilegeKeysDialog.class, () -> new PrivilegeKeysDialog(host, session, groupIcons));
|
showListWindow(PrivilegeKeysDialog.class, () -> new PrivilegeKeysDialog(host, session, groupIcons));
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -203,6 +203,16 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
|||||||
treePanel.selectClient(client.id);
|
treePanel.selectClient(client.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canViewServerConnectionInfo() {
|
||||||
|
return session.permissions().canViewServerConnectionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showServerConnectionInfo() {
|
||||||
|
tab.showServerConnectionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showConnectionInfo(ClientEntry client) {
|
public void showConnectionInfo(ClientEntry client) {
|
||||||
if (!session.isConnected()) return;
|
if (!session.isConnected()) return;
|
||||||
|
|||||||
@@ -157,6 +157,11 @@ public final class ServerTreePanel extends JPanel {
|
|||||||
|
|
||||||
/** Opens the per-client volume dialog. */
|
/** Opens the per-client volume dialog. */
|
||||||
void changeClientVolume(ClientEntry client);
|
void changeClientVolume(ClientEntry client);
|
||||||
|
|
||||||
|
/** Whether we may see the server's connection figures. */
|
||||||
|
boolean canViewServerConnectionInfo();
|
||||||
|
|
||||||
|
void showServerConnectionInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DropIndicatorTree tree;
|
private final DropIndicatorTree tree;
|
||||||
|
|||||||
Reference in New Issue
Block a user