Split ServerTab into focused collaborator classes
Extract mic/speaker/away/commander state handling into ServerTabSelfState, ServerTreePanel.Actions delegation (context menus, drag-drop, link clicks) into ServerTabTreeActions, and ConnectionListener event marshaling onto the EDT into ServerTabConnectionEvents. ServerTab keeps its full public API (636 -> 377 lines); no behavior change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package com.ts3client.ui;
|
||||
|
||||
import com.ts3client.net.ClientEntry;
|
||||
import com.ts3client.net.TeamspeakConnection;
|
||||
|
||||
/**
|
||||
* Mic/speaker/away/commander flags for one connection, plus forwarding them into
|
||||
* {@link TeamspeakConnection}. Split out of {@link ServerTab} because the flags
|
||||
* are reset together in one place (on (re)connect) and read from several
|
||||
* (tray icon, toolbar, menu checkmarks).
|
||||
*/
|
||||
final class ServerTabSelfState {
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
|
||||
private boolean micMuted;
|
||||
private boolean micLocalMuted;
|
||||
private boolean deafened;
|
||||
private boolean away;
|
||||
/** Away message currently published, empty when away carries no message. */
|
||||
private String awayMessage = "";
|
||||
private boolean commander;
|
||||
|
||||
ServerTabSelfState(TeamspeakConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
boolean isMicMuted() {
|
||||
return micMuted;
|
||||
}
|
||||
|
||||
boolean isMicLocalMuted() {
|
||||
return micLocalMuted;
|
||||
}
|
||||
|
||||
boolean isDeafened() {
|
||||
return deafened;
|
||||
}
|
||||
|
||||
boolean isAway() {
|
||||
return away;
|
||||
}
|
||||
|
||||
String awayMessage() {
|
||||
return awayMessage;
|
||||
}
|
||||
|
||||
boolean isCommander() {
|
||||
return commander;
|
||||
}
|
||||
|
||||
void setMicMuted(boolean muted) {
|
||||
micMuted = muted;
|
||||
conn.setMicMuted(muted);
|
||||
}
|
||||
|
||||
/** TS3's "Local Mic Mute": silences capture without publishing a status change. */
|
||||
void setMicLocalMuted(boolean muted) {
|
||||
micLocalMuted = muted;
|
||||
conn.setMicLocalMuted(muted);
|
||||
}
|
||||
|
||||
void setDeafened(boolean deaf) {
|
||||
deafened = deaf;
|
||||
conn.setDeafened(deaf);
|
||||
if (deaf) micMuted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the away message, or null to keep the one already set — the
|
||||
* message outlives coming back, so toggling away again restores it
|
||||
*/
|
||||
void setAway(boolean away, String message) {
|
||||
this.away = away;
|
||||
if (message != null) this.awayMessage = message;
|
||||
conn.setAway(away, awayMessage);
|
||||
}
|
||||
|
||||
void setCommander(boolean commander) {
|
||||
this.commander = commander;
|
||||
conn.setChannelCommander(commander);
|
||||
}
|
||||
|
||||
/** Clears all flags on a fresh connection; the server starts us out clean, so nothing to publish. */
|
||||
void resetOnConnect() {
|
||||
micMuted = false;
|
||||
micLocalMuted = false;
|
||||
deafened = false;
|
||||
away = false;
|
||||
awayMessage = "";
|
||||
commander = false;
|
||||
}
|
||||
|
||||
/** What the local client looks like on this server, for the tray icon. */
|
||||
SelfState compute() {
|
||||
if (!conn.isConnected()) return SelfState.DISCONNECTED;
|
||||
if (deafened) return SelfState.DEAFENED;
|
||||
if (micMuted) return SelfState.MIC_MUTED;
|
||||
if (micLocalMuted) return SelfState.MIC_LOCAL_MUTED;
|
||||
if (away) return SelfState.AWAY;
|
||||
ClientEntry self = conn.getModel().getClient(conn.getSelfClientId());
|
||||
boolean talking = self != null && self.talking;
|
||||
if (commander) return talking ? SelfState.COMMANDER_TALKING : SelfState.COMMANDER;
|
||||
return talking ? SelfState.TALKING : SelfState.IDLE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user