From bbe741d5cf681fcc0053cfcfe6d9b055db7094d0 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Mon, 12 Oct 2026 21:36:37 +0000 Subject: [PATCH] Name abstract base classes Abstract*; no null as "nothing" in list windows ServerListDialog, ListEditorDialog and CtlOpusEncoder gain the Abstract prefix. The list windows blank their status line with clearStatus() and make icon-less menu items with item(text, action), instead of passing null. Co-Authored-By: Claude Opus 5.5 --- .../ts3j/client/android/audio/NativeOpus.java | 4 +-- ts3-client/AUDIT-STRUCTURE.md | 2 +- ts3-client/README.md | 2 +- ...coder.java => AbstractCtlOpusEncoder.java} | 2 +- .../audio/desktop/NativeOpusEncoder.java | 4 +-- ...log.java => AbstractListEditorDialog.java} | 4 +-- ...log.java => AbstractServerListDialog.java} | 25 +++++++++++++------ .../lixko/ts3j/client/ui/BanListDialog.java | 2 +- .../ts3j/client/ui/ComplaintsDialog.java | 2 +- .../ts3j/client/ui/OfflineMessagesDialog.java | 15 +++++------ .../ts3j/client/ui/PrivilegeKeysDialog.java | 2 +- .../lixko/ts3j/client/ui/ServerLogDialog.java | 5 ++-- .../client/ui/ServerLogExcludeDialog.java | 2 +- .../client/ui/ServerLogHighlightDialog.java | 2 +- .../eu/lixko/ts3j/client/ui/ServerTab.java | 12 ++++----- 15 files changed, 49 insertions(+), 36 deletions(-) rename ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/{CtlOpusEncoder.java => AbstractCtlOpusEncoder.java} (94%) rename ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/{ListEditorDialog.java => AbstractListEditorDialog.java} (97%) rename ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/{ServerListDialog.java => AbstractServerListDialog.java} (92%) diff --git a/android/audio/src/main/java/eu/lixko/ts3j/client/android/audio/NativeOpus.java b/android/audio/src/main/java/eu/lixko/ts3j/client/android/audio/NativeOpus.java index 2f304ff..a668964 100644 --- a/android/audio/src/main/java/eu/lixko/ts3j/client/android/audio/NativeOpus.java +++ b/android/audio/src/main/java/eu/lixko/ts3j/client/android/audio/NativeOpus.java @@ -1,6 +1,6 @@ package eu.lixko.ts3j.client.android.audio; -import eu.lixko.ts3j.client.audio.opus.CtlOpusEncoder; +import eu.lixko.ts3j.client.audio.opus.AbstractCtlOpusEncoder; import eu.lixko.ts3j.client.audio.opus.LibOpus; import eu.lixko.ts3j.client.audio.opus.OpusCodec; import eu.lixko.ts3j.client.audio.opus.OpusDecoder; @@ -29,7 +29,7 @@ public final class NativeOpus implements OpusCodec { } /** Methods may come from different threads, one at a time, so they only share the handle. */ - private static final class Encoder extends CtlOpusEncoder { + private static final class Encoder extends AbstractCtlOpusEncoder { private final int frameSize; private long handle; diff --git a/ts3-client/AUDIT-STRUCTURE.md b/ts3-client/AUDIT-STRUCTURE.md index 55701cc..2ac9e2d 100644 --- a/ts3-client/AUDIT-STRUCTURE.md +++ b/ts3-client/AUDIT-STRUCTURE.md @@ -18,7 +18,7 @@ Items are worked through in the order below. Status: open, done (commit), or clo | 4d | … our own state (mic, speakers, away, talk request, recording) out of the connection | done (`9107bdd`): `OwnClient` owns the devices and our flags, and publishes them; `Recording` the recorder. `ServerSession` no longer keeps its own copy of the flags, and they are cleared when a connect starts rather than once it is done | | 5 | Two front doors: frontends use both `ServerSession` and `session.connection()` with no rule for which | done (`de42429`): `connection()` is gone; frontends reach the model, our ids, devices and the helpers through `ServerSession`. New helpers took the remaining actions off the connection: `ClientAdmin` (move, kick, ban, groups, talk power, poke, details), `ChannelFiles`, `ClientContacts`; `ChannelAdmin` also joins, moves and subscribes. Dialogs take the session, or only the helper they use | | 6 | Menu bar, toolbar and hotkeys each implement the same commands: `MainMenuBar.Listener` (~50 methods, ~210 lines of forwarding in `MainFrame`), `MainToolbar.Listener`, `HotkeyActions` | done (`f7cf040`): `MainCommands` holds each command once, acting on the server on screen or, for hotkeys, on a list of sessions; the menu, toolbar and hotkeys call it directly and both `Listener` interfaces are gone. The menu's mute items no longer click the toolbar's buttons, and the menu's commander toggle now repaints the toolbar and tray | -| 7 | The admin list dialogs (bans, complaints, offline messages, privilege keys, server log) repeat the load/status/table-model scaffolding || done (uncommitted): the five extend `ServerListDialog`, which lays out the toolbar, list, status line and Reload/Close, follows the server's name, binds F5/Ctrl+W/Escape, guards loading, reloads after a change and reports its failure; `ServerTab` keeps them in one map. All five now take F5, show load failures in red, and keep the status line's height; the ban list's own placeholder field is FlatLaf's. The table models stay per dialog: their rows and columns share nothing | +| 7 | The admin list dialogs (bans, complaints, offline messages, privilege keys, server log) repeat the load/status/table-model scaffolding || done (`e214f21`): the five extend `AbstractServerListDialog`, which lays out the toolbar, list, status line and Reload/Close, follows the server's name, binds F5/Ctrl+W/Escape, guards loading, reloads after a change and reports its failure; `ServerTab` keeps them in one map. All five now take F5, show load failures in red, and keep the status line's height; the ban list's own placeholder field is FlatLaf's. The table models stay per dialog: their rows and columns share nothing | | 8 | `Settings`: 58 public fields, each key spelled twice (load and save), no change notification, so callers fan changes out by hand | open | | 9 | Duplicates: three byte-size formatters (`FileBrowserDialog`, `ChatHtml`, `ConnectionStatsFormat`); four "which chat" enums (`ChatScope`, `ChatLogScope`, `ChatPanel.Target`, Android `ChatKey`); the conversation model lives in each frontend | open | | 10 | Android `ServerScreen`: one 456-line composable holding ~25 pieces of state | open | diff --git a/ts3-client/README.md b/ts3-client/README.md index d04109f..60b1b6a 100644 --- a/ts3-client/README.md +++ b/ts3-client/README.md @@ -312,7 +312,7 @@ swing/ eu.lixko.ts3j.client ├── ConnectDialog connect form ├── BookmarksDialog manage saved servers ├── IdentitiesDialog manage identities (new/import/export/improve) - ├── ServerListDialog shared frame of a server's list windows (bans, complaints, privilege keys, offline messages, server log) + ├── AbstractServerListDialog shared frame of a server's list windows (bans, complaints, privilege keys, offline messages, server log) ├── IdentityChooser identity drop-down shared by connect/bookmark forms ├── LevelMeter dBFS meter with threshold marker ├── IconTheme active icon pack: rasterising (JSVG) and caching diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/CtlOpusEncoder.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/AbstractCtlOpusEncoder.java similarity index 94% rename from ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/CtlOpusEncoder.java rename to ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/AbstractCtlOpusEncoder.java index 6a88992..7ee1e4c 100644 --- a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/CtlOpusEncoder.java +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/audio/opus/AbstractCtlOpusEncoder.java @@ -1,7 +1,7 @@ package eu.lixko.ts3j.client.audio.opus; /** An {@link OpusEncoder} configured through libopus' own controls; a binding supplies {@link #ctl}. */ -public abstract class CtlOpusEncoder implements OpusEncoder { +public abstract class AbstractCtlOpusEncoder implements OpusEncoder { /** Calls {@code opus_encoder_ctl(encoder, request, value)}. */ protected abstract void ctl(int request, int value); diff --git a/ts3-client/desktop/src/main/java/eu/lixko/ts3j/client/audio/desktop/NativeOpusEncoder.java b/ts3-client/desktop/src/main/java/eu/lixko/ts3j/client/audio/desktop/NativeOpusEncoder.java index 0f016f8..dbcad46 100644 --- a/ts3-client/desktop/src/main/java/eu/lixko/ts3j/client/audio/desktop/NativeOpusEncoder.java +++ b/ts3-client/desktop/src/main/java/eu/lixko/ts3j/client/audio/desktop/NativeOpusEncoder.java @@ -1,6 +1,6 @@ package eu.lixko.ts3j.client.audio.desktop; -import eu.lixko.ts3j.client.audio.opus.CtlOpusEncoder; +import eu.lixko.ts3j.client.audio.opus.AbstractCtlOpusEncoder; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; @@ -16,7 +16,7 @@ import java.lang.foreign.ValueLayout; * are freed by {@link #close()}; access is serialised by the instance lock, so the * encoder may be driven from any thread. */ -final class NativeOpusEncoder extends CtlOpusEncoder { +final class NativeOpusEncoder extends AbstractCtlOpusEncoder { private static final int MAX_PACKET_BYTES = 4096; diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ListEditorDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractListEditorDialog.java similarity index 97% rename from ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ListEditorDialog.java rename to ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractListEditorDialog.java index 6286675..fb87ac0 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ListEditorDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractListEditorDialog.java @@ -29,7 +29,7 @@ import java.util.List; * A small modal editor for a list of text-keyed items: Add, Remove, optionally Move up and * down, and OK/Cancel. Edits a copy and writes it back only on OK. */ -abstract class ListEditorDialog extends JDialog { +abstract class AbstractListEditorDialog extends JDialog { protected final DefaultListModel model = new DefaultListModel<>(); protected final JList list = new JList<>(model); @@ -42,7 +42,7 @@ abstract class ListEditorDialog extends JDialog { * @param itemPrompt what Add and a double-click ask for * @param movable whether the order matters, offering Move up and down */ - ListEditorDialog(Window owner, String title, String intro, String itemPrompt, List items, boolean movable) { + AbstractListEditorDialog(Window owner, String title, String intro, String itemPrompt, List items, boolean movable) { super(owner, title, ModalityType.APPLICATION_MODAL); this.itemPrompt = itemPrompt; items.forEach(model::addElement); diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerListDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractServerListDialog.java similarity index 92% rename from ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerListDialog.java rename to ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractServerListDialog.java index 3a19258..fc207c1 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerListDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/AbstractServerListDialog.java @@ -39,7 +39,7 @@ import java.util.function.Supplier; * *

One per server tab; the tab closes it when the connection goes away. */ -abstract class ServerListDialog extends JDialog { +abstract class AbstractServerListDialog extends JDialog { static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -48,7 +48,7 @@ abstract class ServerListDialog extends JDialog { private final JLabel status = new JLabel(" "); private boolean loading; - ServerListDialog(Frame owner, ServerSession session, String name) { + AbstractServerListDialog(Frame owner, ServerSession session, String name) { super(owner, name, false); this.session = session; this.name = name; @@ -157,12 +157,17 @@ abstract class ServerListDialog extends JDialog { }); } - /** Shows {@code text} under the list; {@code null} leaves the line blank. */ + /** Shows {@code text} under the list. */ final void showStatus(String text) { - status.setText(text == null || text.isEmpty() ? " " : text); + status.setText(text); status.setForeground(Theme.chatEvent()); } + /** Blanks the status line, keeping its height. */ + final void clearStatus() { + status.setText(" "); + } + final void showError(String text) { status.setText(text); status.setForeground(Theme.isDark() ? new Color(0xFF6B6B) : new Color(0xC00000)); @@ -197,13 +202,19 @@ abstract class ServerListDialog extends JDialog { return scroll; } - /** @param icon an {@link Icons} name, or {@code null} */ - static JMenuItem item(String text, String icon, Runnable action) { - JMenuItem item = new JMenuItem(text, icon == null ? null : Icons.of(icon)); + static JMenuItem item(String text, Runnable action) { + JMenuItem item = new JMenuItem(text); item.addActionListener(e -> action.run()); return item; } + /** @param icon an {@link Icons} name */ + static JMenuItem item(String text, String icon, Runnable action) { + JMenuItem item = item(text, action); + item.setIcon(Icons.of(icon)); + return item; + } + static String date(long epochSeconds) { if (epochSeconds <= 0) return ""; return DATE.format(Instant.ofEpochSecond(epochSeconds).atZone(ZoneId.systemDefault())); diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/BanListDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/BanListDialog.java index 7c735e4..7b295e2 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/BanListDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/BanListDialog.java @@ -48,7 +48,7 @@ import java.util.stream.Collectors; * Which columns show is chosen from the header's context menu and remembered. * */ -final class BanListDialog extends ServerListDialog { +final class BanListDialog extends AbstractServerListDialog { /** The table's columns, in the official order; the split-out target columns start hidden. */ private enum Column { diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ComplaintsDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ComplaintsDialog.java index a6a8f4a..5ba0dff 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ComplaintsDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ComplaintsDialog.java @@ -45,7 +45,7 @@ import java.util.function.Consumer; * collapsible row per client complained about, with each complaint's date, author and * reason beneath it. */ -final class ComplaintsDialog extends ServerListDialog { +final class ComplaintsDialog extends AbstractServerListDialog { private enum Column { TARGET("Target Nickname", 200), diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/OfflineMessagesDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/OfflineMessagesDialog.java index e8ddf21..93ebeee 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/OfflineMessagesDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/OfflineMessagesDialog.java @@ -50,7 +50,7 @@ import java.util.Set; * window: the messages above, the selected one's subject and text below. Viewing a message * marks it read. */ -final class OfflineMessagesDialog extends ServerListDialog { +final class OfflineMessagesDialog extends AbstractServerListDialog { /** Where Compose and Reply lead: the tab opens the compose window. */ interface Composer { @@ -198,15 +198,15 @@ final class OfflineMessagesDialog extends ServerListDialog { } private JPopupMenu tablePopup() { - JMenuItem reply = item("Reply to message", null, this::replySelected); - JMenuItem delete = item("Delete message", null, this::deleteSelected); - JMenuItem markRead = item("Mark as Read", null, () -> markSelected(true)); - JMenuItem markUnread = item("Mark as Unread", null, () -> markSelected(false)); + JMenuItem reply = item("Reply to message", this::replySelected); + JMenuItem delete = item("Delete message", this::deleteSelected); + JMenuItem markRead = item("Mark as Read", () -> markSelected(true)); + JMenuItem markUnread = item("Mark as Unread", () -> markSelected(false)); JPopupMenu menu = new JPopupMenu(); menu.add(reply); menu.add(delete); menu.addSeparator(); - menu.add(item("Reload messages", null, this::reload)); + menu.add(item("Reload messages", this::reload)); menu.addSeparator(); menu.add(markRead); menu.add(markUnread); @@ -248,7 +248,8 @@ final class OfflineMessagesDialog extends ServerListDialog { void reload() { load(session.offlineMessages()::list, messages -> { setMessages(messages); - showStatus(messages.isEmpty() ? "No messages" : null); + if (messages.isEmpty()) showStatus("No messages"); + else clearStatus(); }, failure -> showError("Failed to list offline messages: " + failure.getMessage())); } diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/PrivilegeKeysDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/PrivilegeKeysDialog.java index 3ed1de1..1b39f22 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/PrivilegeKeysDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/PrivilegeKeysDialog.java @@ -31,7 +31,7 @@ import java.util.stream.Collectors; * The server's privilege keys, as the official client's Permissions > Privilege Keys * window: Create and Remove above the list, Reload below it. */ -final class PrivilegeKeysDialog extends ServerListDialog { +final class PrivilegeKeysDialog extends AbstractServerListDialog { private enum Column { KEY("Privilege Key", 320), diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogDialog.java index 4954d80..3b7521c 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogDialog.java @@ -47,7 +47,7 @@ import java.util.Map; * by keyword. Find (with "show only matches") stands in for TS3's separate search and * include-filter fields. */ -final class ServerLogDialog extends ServerListDialog { +final class ServerLogDialog extends AbstractServerListDialog { private static final int LEVEL_WIDTH = "Critical".length(); @@ -220,7 +220,8 @@ final class ServerLogDialog extends ServerListDialog { // appending at the end never fails } - showStatus(entries.isEmpty() ? "No log entries available" : null); + if (entries.isEmpty()) showStatus("No log entries available"); + else clearStatus(); if (toEnd) { log.setCaretPosition(doc.getLength()); diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogExcludeDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogExcludeDialog.java index 96e1d4b..8ecb1d5 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogExcludeDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogExcludeDialog.java @@ -4,7 +4,7 @@ import java.awt.Window; import java.util.List; /** The Server Log's exclude filter: terms whose lines are left out. */ -final class ServerLogExcludeDialog extends ListEditorDialog { +final class ServerLogExcludeDialog extends AbstractListEditorDialog { private ServerLogExcludeDialog(Window owner, List terms) { super(owner, "Exclude Filter", "Exclude lines containing:", "Term:", terms, false); diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogHighlightDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogHighlightDialog.java index 8cf2c34..3f9166f 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogHighlightDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerLogHighlightDialog.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.function.Function; /** The Server Log's highlighting: keywords and the colours their lines are drawn in, first match first. */ -final class ServerLogHighlightDialog extends ListEditorDialog { +final class ServerLogHighlightDialog extends AbstractListEditorDialog { private JButton foreground; private JButton background; diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java index a04fe91..f389a93 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java @@ -53,7 +53,7 @@ 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, ServerListDialog> listWindows = new HashMap<>(); + private final Map, AbstractServerListDialog> listWindows = new HashMap<>(); /** The unread count last reported, to tell new mail from messages being read. */ private int unreadMessages; @@ -212,9 +212,9 @@ final class ServerTab { } /** Opens a list window of this server, or brings the already open one forward. */ - private void showListWindow(Class type, Supplier create) { + private void showListWindow(Class type, Supplier create) { if (!session.isConnected()) return; - ServerListDialog window = listWindow(type); + AbstractServerListDialog window = listWindow(type); if (window == null) { window = create.get(); listWindows.put(type, window); @@ -224,8 +224,8 @@ final class ServerTab { } /** The open list window of a kind, or {@code null}. */ - private D listWindow(Class type) { - ServerListDialog window = listWindows.get(type); + private D listWindow(Class type) { + AbstractServerListDialog window = listWindows.get(type); return window != null && window.isDisplayable() ? type.cast(window) : null; } @@ -256,7 +256,7 @@ final class ServerTab { /** The server's name changed or the connection went; the list windows follow. */ void serverWindowsChanged(boolean connected) { - for (ServerListDialog window : listWindows.values()) { + for (AbstractServerListDialog window : listWindows.values()) { if (connected) window.serverNameChanged(); else window.connectionLost(); }