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:
@@ -271,6 +271,14 @@ public final class MainCommands {
|
||||
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. */
|
||||
public void changeNickname() {
|
||||
String nickname = JOptionPane.showInputDialog(frame, "New nickname:", settings.nickname.get());
|
||||
@@ -374,6 +382,14 @@ public final class MainCommands {
|
||||
onTab(ServerTab::showServerLog);
|
||||
}
|
||||
|
||||
void showServerConnectionInfo() {
|
||||
onTab(ServerTab::showServerConnectionInfo);
|
||||
}
|
||||
|
||||
void toggleQueryClients() {
|
||||
connectedTab().ifPresent(tab -> frame.setShowQueryClients(tab, !tab.session().showsQueryClients()));
|
||||
}
|
||||
|
||||
void 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.
|
||||
IconTheme.get().addListener(() -> SwingUtilities.invokeLater(this::rebuildIcons));
|
||||
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;
|
||||
// from anywhere else it searches the chat.
|
||||
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) {
|
||||
if (!tabs.contains(tab)) return;
|
||||
sessions.connected(tab.session());
|
||||
tab.session().setShowQueryClients(bookmarks.showsQueryClients(tab.session().address(), tab.session().port()));
|
||||
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) {
|
||||
if (!tabs.contains(tab)) return;
|
||||
sessions.disconnected(tab.session());
|
||||
|
||||
@@ -122,6 +122,13 @@ final class MainToolbar extends JToolBar {
|
||||
private JPopupMenu buildContextMenu() {
|
||||
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());
|
||||
statusBarItem.addActionListener(e -> {
|
||||
settings.showStatusBar.set(statusBarItem.isSelected());
|
||||
@@ -144,6 +151,7 @@ final class MainToolbar extends JToolBar {
|
||||
JMenuItem customize = new JMenuItem("Customize Toolbar…");
|
||||
customize.addActionListener(e -> CustomizeToolbarDialog.show(this, settings, actions));
|
||||
|
||||
menu.add(tabsItem);
|
||||
menu.add(statusBarItem);
|
||||
menu.add(volumeItem);
|
||||
menu.addSeparator();
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
* 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
|
||||
* 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 {
|
||||
|
||||
@@ -42,8 +42,11 @@ final class ServerTabPane extends JPanel {
|
||||
private final List<ServerTab> tabs = new ArrayList<>();
|
||||
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 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. */
|
||||
private boolean updating;
|
||||
/** 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) {
|
||||
tabs.remove(tab);
|
||||
if (selected == tab) selected = null;
|
||||
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) {
|
||||
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;
|
||||
try {
|
||||
tabbed.setSelectedIndex(i);
|
||||
@@ -145,7 +165,7 @@ final class ServerTabPane extends JPanel {
|
||||
* keeping whatever is currently selected on screen.
|
||||
*/
|
||||
private void relayout() {
|
||||
boolean wantTabs = tabs.size() > 1;
|
||||
boolean wantTabs = stripShown && tabs.size() > 1;
|
||||
updating = true;
|
||||
try {
|
||||
removeAll();
|
||||
@@ -154,7 +174,7 @@ final class ServerTabPane extends JPanel {
|
||||
for (ServerTab tab : tabs) tabbed.addTab(tab.session().title(), tab.component());
|
||||
add(tabbed, BorderLayout.CENTER);
|
||||
} else if (!tabs.isEmpty()) {
|
||||
add(tabs.get(0).component(), BorderLayout.CENTER);
|
||||
add((selected != null ? selected : tabs.get(0)).component(), BorderLayout.CENTER);
|
||||
}
|
||||
tabbedMode = wantTabs;
|
||||
} finally {
|
||||
|
||||
@@ -30,6 +30,7 @@ final class ToolbarAction {
|
||||
RECORDING("Recording"),
|
||||
CHANNEL("Channel"),
|
||||
CLIENT("Client"),
|
||||
SERVER("Server"),
|
||||
MISC("Misc");
|
||||
|
||||
final String label;
|
||||
|
||||
@@ -44,6 +44,7 @@ final class ToolbarActions {
|
||||
addRecording();
|
||||
addChannel();
|
||||
addClient();
|
||||
addServer();
|
||||
addMisc();
|
||||
}
|
||||
|
||||
@@ -112,6 +113,10 @@ final class ToolbarActions {
|
||||
.enabledWhen(() -> is(ServerSession::hasAvatar));
|
||||
add("giantPtt", Category.SELF, "Giant PTT", commands::showGiantPtt, "CAPTURE");
|
||||
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() {
|
||||
@@ -257,6 +262,16 @@ final class ToolbarActions {
|
||||
.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() {
|
||||
add("collapseAll", Category.MISC, "Collapse All", () -> collapseAll(true), "CHANNEL_COLLAPSE_ALL")
|
||||
.enabledWhen(this::connected);
|
||||
|
||||
@@ -100,6 +100,11 @@ public final class HotkeyActions implements HotkeyEngine.Handler {
|
||||
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_MULTITRACK -> commands.startRecording(targets, true);
|
||||
case RECORDING_STOP -> commands.stopRecording(targets);
|
||||
|
||||
@@ -69,6 +69,7 @@ public final class BookmarksDialog extends JDialog {
|
||||
private final JPasswordField channelPassword = new JPasswordField();
|
||||
private final JCheckBox connectOnStartup = new JCheckBox("Connect on startup");
|
||||
private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features");
|
||||
private final JCheckBox showQueryClients = new JCheckBox("Show ServerQuery clients");
|
||||
private final IdentityChooser identity;
|
||||
|
||||
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. "
|
||||
+ "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");
|
||||
if (thisChannel.getIcon() == null) thisChannel.setText("This channel");
|
||||
thisChannel.addActionListener(e -> {
|
||||
@@ -168,6 +175,7 @@ public final class BookmarksDialog extends JDialog {
|
||||
addRow(panel, row++, "Identity:", identity);
|
||||
addRow(panel, row++, "", connectOnStartup);
|
||||
addRow(panel, row++, "", myTeamSpeakFeatures);
|
||||
addRow(panel, row++, "", showQueryClients);
|
||||
|
||||
GridBagConstraints filler = new GridBagConstraints();
|
||||
filler.gridx = 0;
|
||||
@@ -235,6 +243,7 @@ public final class BookmarksDialog extends JDialog {
|
||||
channelPassword.setText(b == null ? "" : nullToEmpty(b.channelPassword));
|
||||
connectOnStartup.setSelected(b != null && b.connectOnStartup);
|
||||
myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures);
|
||||
showQueryClients.setSelected(b != null && b.showQueryClients);
|
||||
identity.setSelectedIdentityId(b == null ? "" : nullToEmpty(b.identityId));
|
||||
updateThisChannel();
|
||||
}
|
||||
@@ -288,6 +297,7 @@ public final class BookmarksDialog extends JDialog {
|
||||
editing.identityId = identity.getSelectedIdentityId();
|
||||
editing.connectOnStartup = connectOnStartup.isSelected();
|
||||
editing.myTeamSpeakFeatures = myTeamSpeakFeatures.isSelected();
|
||||
editing.showQueryClients = showQueryClients.isSelected();
|
||||
list.repaint();
|
||||
}
|
||||
|
||||
|
||||
+7
-88
@@ -4,7 +4,6 @@ import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
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;
|
||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
@@ -22,7 +21,6 @@ import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
@@ -55,7 +53,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
private static final int AVATAR_SIZE = 80;
|
||||
/** 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 VALUE_SAMPLE = "1023.00 KiB/s";
|
||||
private static final String VALUE_SAMPLE = Figures.VALUE_SAMPLE;
|
||||
|
||||
private final ServerSession session;
|
||||
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));
|
||||
}
|
||||
|
||||
// ---- 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. */
|
||||
private static final class TrafficTable extends JPanel {
|
||||
private final ConnectionStats.Kind kind;
|
||||
@@ -304,7 +223,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
|
||||
List<String> columns = ConnectionStatsFormat.COLUMNS;
|
||||
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));
|
||||
add(heading, column(c + 1, 0));
|
||||
}
|
||||
@@ -312,19 +231,19 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
cells = new JLabel[rows.size()][];
|
||||
for (int r = 0; r < rows.size(); 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[]{
|
||||
sized(label(row.total()), TOTAL_SAMPLE), sized(label(row.in()), VALUE_SAMPLE),
|
||||
sized(label(row.out()), VALUE_SAMPLE)};
|
||||
Figures.sized(Figures.label(row.total()), TOTAL_SAMPLE), Figures.sized(Figures.label(row.in()), 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));
|
||||
}
|
||||
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;
|
||||
add(Box.createGlue(), filler);
|
||||
}
|
||||
|
||||
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;
|
||||
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.addActionListener(a -> actions.createSpacer());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public final class ServerTab {
|
||||
/** The one open ban list window for this server, if any. */
|
||||
/** The open ban list, complaints and other list windows, one of each kind. */
|
||||
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. */
|
||||
private int unreadMessages;
|
||||
|
||||
@@ -211,6 +212,16 @@ public final class ServerTab {
|
||||
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() {
|
||||
showListWindow(PrivilegeKeysDialog.class, () -> new PrivilegeKeysDialog(host, session, groupIcons));
|
||||
}
|
||||
|
||||
+10
@@ -203,6 +203,16 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
treePanel.selectClient(client.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canViewServerConnectionInfo() {
|
||||
return session.permissions().canViewServerConnectionInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showServerConnectionInfo() {
|
||||
tab.showServerConnectionInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showConnectionInfo(ClientEntry client) {
|
||||
if (!session.isConnected()) return;
|
||||
|
||||
@@ -157,6 +157,11 @@ public final class ServerTreePanel extends JPanel {
|
||||
|
||||
/** Opens the per-client volume dialog. */
|
||||
void changeClientVolume(ClientEntry client);
|
||||
|
||||
/** Whether we may see the server's connection figures. */
|
||||
boolean canViewServerConnectionInfo();
|
||||
|
||||
void showServerConnectionInfo();
|
||||
}
|
||||
|
||||
private final DropIndicatorTree tree;
|
||||
|
||||
Reference in New Issue
Block a user