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 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 21:36:37 +00:00
co-authored by Claude Opus 5.5
parent e214f2141e
commit bbe741d5cf
15 changed files with 49 additions and 36 deletions
@@ -1,6 +1,6 @@
package eu.lixko.ts3j.client.android.audio; 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.LibOpus;
import eu.lixko.ts3j.client.audio.opus.OpusCodec; import eu.lixko.ts3j.client.audio.opus.OpusCodec;
import eu.lixko.ts3j.client.audio.opus.OpusDecoder; 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. */ /** 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 final int frameSize;
private long handle; private long handle;
+1 -1
View File
@@ -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 | | 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 | | 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 | | 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 | | 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 | | 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 | | 10 | Android `ServerScreen`: one 456-line composable holding ~25 pieces of state | open |
+1 -1
View File
@@ -312,7 +312,7 @@ swing/ eu.lixko.ts3j.client
├── ConnectDialog connect form ├── ConnectDialog connect form
├── BookmarksDialog manage saved servers ├── BookmarksDialog manage saved servers
├── IdentitiesDialog manage identities (new/import/export/improve) ├── 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 ├── IdentityChooser identity drop-down shared by connect/bookmark forms
├── LevelMeter dBFS meter with threshold marker ├── LevelMeter dBFS meter with threshold marker
├── IconTheme active icon pack: rasterising (JSVG) and caching ├── IconTheme active icon pack: rasterising (JSVG) and caching
@@ -1,7 +1,7 @@
package eu.lixko.ts3j.client.audio.opus; package eu.lixko.ts3j.client.audio.opus;
/** An {@link OpusEncoder} configured through libopus' own controls; a binding supplies {@link #ctl}. */ /** 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)}. */ /** Calls {@code opus_encoder_ctl(encoder, request, value)}. */
protected abstract void ctl(int request, int value); protected abstract void ctl(int request, int value);
@@ -1,6 +1,6 @@
package eu.lixko.ts3j.client.audio.desktop; 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.Arena;
import java.lang.foreign.MemorySegment; 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 * are freed by {@link #close()}; access is serialised by the instance lock, so the
* encoder may be driven from any thread. * 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; private static final int MAX_PACKET_BYTES = 4096;
@@ -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 * 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. * down, and OK/Cancel. Edits a copy and writes it back only on OK.
*/ */
abstract class ListEditorDialog<T> extends JDialog { abstract class AbstractListEditorDialog<T> extends JDialog {
protected final DefaultListModel<T> model = new DefaultListModel<>(); protected final DefaultListModel<T> model = new DefaultListModel<>();
protected final JList<T> list = new JList<>(model); protected final JList<T> list = new JList<>(model);
@@ -42,7 +42,7 @@ abstract class ListEditorDialog<T> extends JDialog {
* @param itemPrompt what Add and a double-click ask for * @param itemPrompt what Add and a double-click ask for
* @param movable whether the order matters, offering Move up and down * @param movable whether the order matters, offering Move up and down
*/ */
ListEditorDialog(Window owner, String title, String intro, String itemPrompt, List<T> items, boolean movable) { AbstractListEditorDialog(Window owner, String title, String intro, String itemPrompt, List<T> items, boolean movable) {
super(owner, title, ModalityType.APPLICATION_MODAL); super(owner, title, ModalityType.APPLICATION_MODAL);
this.itemPrompt = itemPrompt; this.itemPrompt = itemPrompt;
items.forEach(model::addElement); items.forEach(model::addElement);
@@ -39,7 +39,7 @@ import java.util.function.Supplier;
* *
* <p>One per server tab; the tab closes it when the connection goes away. * <p>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"); 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 final JLabel status = new JLabel(" ");
private boolean loading; private boolean loading;
ServerListDialog(Frame owner, ServerSession session, String name) { AbstractServerListDialog(Frame owner, ServerSession session, String name) {
super(owner, name, false); super(owner, name, false);
this.session = session; this.session = session;
this.name = name; 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) { final void showStatus(String text) {
status.setText(text == null || text.isEmpty() ? " " : text); status.setText(text);
status.setForeground(Theme.chatEvent()); status.setForeground(Theme.chatEvent());
} }
/** Blanks the status line, keeping its height. */
final void clearStatus() {
status.setText(" ");
}
final void showError(String text) { final void showError(String text) {
status.setText(text); status.setText(text);
status.setForeground(Theme.isDark() ? new Color(0xFF6B6B) : new Color(0xC00000)); status.setForeground(Theme.isDark() ? new Color(0xFF6B6B) : new Color(0xC00000));
@@ -197,13 +202,19 @@ abstract class ServerListDialog extends JDialog {
return scroll; return scroll;
} }
/** @param icon an {@link Icons} name, or {@code null} */ static JMenuItem item(String text, Runnable action) {
static JMenuItem item(String text, String icon, Runnable action) { JMenuItem item = new JMenuItem(text);
JMenuItem item = new JMenuItem(text, icon == null ? null : Icons.of(icon));
item.addActionListener(e -> action.run()); item.addActionListener(e -> action.run());
return item; 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) { static String date(long epochSeconds) {
if (epochSeconds <= 0) return ""; if (epochSeconds <= 0) return "";
return DATE.format(Instant.ofEpochSecond(epochSeconds).atZone(ZoneId.systemDefault())); return DATE.format(Instant.ofEpochSecond(epochSeconds).atZone(ZoneId.systemDefault()));
@@ -48,7 +48,7 @@ import java.util.stream.Collectors;
* Which columns show is chosen from the header's context menu and remembered. * 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. */ /** The table's columns, in the official order; the split-out target columns start hidden. */
private enum Column { private enum Column {
@@ -45,7 +45,7 @@ import java.util.function.Consumer;
* collapsible row per client complained about, with each complaint's date, author and * collapsible row per client complained about, with each complaint's date, author and
* reason beneath it. * reason beneath it.
*/ */
final class ComplaintsDialog extends ServerListDialog { final class ComplaintsDialog extends AbstractServerListDialog {
private enum Column { private enum Column {
TARGET("Target Nickname", 200), TARGET("Target Nickname", 200),
@@ -50,7 +50,7 @@ import java.util.Set;
* window: the messages above, the selected one's subject and text below. Viewing a message * window: the messages above, the selected one's subject and text below. Viewing a message
* marks it read. * marks it read.
*/ */
final class OfflineMessagesDialog extends ServerListDialog { final class OfflineMessagesDialog extends AbstractServerListDialog {
/** Where Compose and Reply lead: the tab opens the compose window. */ /** Where Compose and Reply lead: the tab opens the compose window. */
interface Composer { interface Composer {
@@ -198,15 +198,15 @@ final class OfflineMessagesDialog extends ServerListDialog {
} }
private JPopupMenu tablePopup() { private JPopupMenu tablePopup() {
JMenuItem reply = item("Reply to message", null, this::replySelected); JMenuItem reply = item("Reply to message", this::replySelected);
JMenuItem delete = item("Delete message", null, this::deleteSelected); JMenuItem delete = item("Delete message", this::deleteSelected);
JMenuItem markRead = item("Mark as Read", null, () -> markSelected(true)); JMenuItem markRead = item("Mark as Read", () -> markSelected(true));
JMenuItem markUnread = item("Mark as Unread", null, () -> markSelected(false)); JMenuItem markUnread = item("Mark as Unread", () -> markSelected(false));
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
menu.add(reply); menu.add(reply);
menu.add(delete); menu.add(delete);
menu.addSeparator(); menu.addSeparator();
menu.add(item("Reload messages", null, this::reload)); menu.add(item("Reload messages", this::reload));
menu.addSeparator(); menu.addSeparator();
menu.add(markRead); menu.add(markRead);
menu.add(markUnread); menu.add(markUnread);
@@ -248,7 +248,8 @@ final class OfflineMessagesDialog extends ServerListDialog {
void reload() { void reload() {
load(session.offlineMessages()::list, messages -> { load(session.offlineMessages()::list, messages -> {
setMessages(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())); }, failure -> showError("Failed to list offline messages: " + failure.getMessage()));
} }
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
* The server's privilege keys, as the official client's Permissions &gt; Privilege Keys * The server's privilege keys, as the official client's Permissions &gt; Privilege Keys
* window: Create and Remove above the list, Reload below it. * window: Create and Remove above the list, Reload below it.
*/ */
final class PrivilegeKeysDialog extends ServerListDialog { final class PrivilegeKeysDialog extends AbstractServerListDialog {
private enum Column { private enum Column {
KEY("Privilege Key", 320), KEY("Privilege Key", 320),
@@ -47,7 +47,7 @@ import java.util.Map;
* by keyword. Find (with "show only matches") stands in for TS3's separate search and * by keyword. Find (with "show only matches") stands in for TS3's separate search and
* include-filter fields. * include-filter fields.
*/ */
final class ServerLogDialog extends ServerListDialog { final class ServerLogDialog extends AbstractServerListDialog {
private static final int LEVEL_WIDTH = "Critical".length(); private static final int LEVEL_WIDTH = "Critical".length();
@@ -220,7 +220,8 @@ final class ServerLogDialog extends ServerListDialog {
// appending at the end never fails // 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) { if (toEnd) {
log.setCaretPosition(doc.getLength()); log.setCaretPosition(doc.getLength());
@@ -4,7 +4,7 @@ import java.awt.Window;
import java.util.List; import java.util.List;
/** The Server Log's exclude filter: terms whose lines are left out. */ /** The Server Log's exclude filter: terms whose lines are left out. */
final class ServerLogExcludeDialog extends ListEditorDialog<String> { final class ServerLogExcludeDialog extends AbstractListEditorDialog<String> {
private ServerLogExcludeDialog(Window owner, List<String> terms) { private ServerLogExcludeDialog(Window owner, List<String> terms) {
super(owner, "Exclude Filter", "Exclude lines containing:", "Term:", terms, false); super(owner, "Exclude Filter", "Exclude lines containing:", "Term:", terms, false);
@@ -23,7 +23,7 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
/** The Server Log's highlighting: keywords and the colours their lines are drawn in, first match first. */ /** The Server Log's highlighting: keywords and the colours their lines are drawn in, first match first. */
final class ServerLogHighlightDialog extends ListEditorDialog<Highlight> { final class ServerLogHighlightDialog extends AbstractListEditorDialog<Highlight> {
private JButton foreground; private JButton foreground;
private JButton background; private JButton background;
@@ -53,7 +53,7 @@ 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 ServerListDialog>, ServerListDialog> listWindows = new HashMap<>(); private final Map<Class<? extends AbstractServerListDialog>, AbstractServerListDialog> listWindows = new HashMap<>();
/** 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;
@@ -212,9 +212,9 @@ final class ServerTab {
} }
/** Opens a list window of this server, or brings the already open one forward. */ /** Opens a list window of this server, or brings the already open one forward. */
private <D extends ServerListDialog> void showListWindow(Class<D> type, Supplier<D> create) { private <D extends AbstractServerListDialog> void showListWindow(Class<D> type, Supplier<D> create) {
if (!session.isConnected()) return; if (!session.isConnected()) return;
ServerListDialog window = listWindow(type); AbstractServerListDialog window = listWindow(type);
if (window == null) { if (window == null) {
window = create.get(); window = create.get();
listWindows.put(type, window); listWindows.put(type, window);
@@ -224,8 +224,8 @@ final class ServerTab {
} }
/** The open list window of a kind, or {@code null}. */ /** The open list window of a kind, or {@code null}. */
private <D extends ServerListDialog> D listWindow(Class<D> type) { private <D extends AbstractServerListDialog> D listWindow(Class<D> type) {
ServerListDialog window = listWindows.get(type); AbstractServerListDialog window = listWindows.get(type);
return window != null && window.isDisplayable() ? type.cast(window) : null; 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. */ /** The server's name changed or the connection went; the list windows follow. */
void serverWindowsChanged(boolean connected) { void serverWindowsChanged(boolean connected) {
for (ServerListDialog window : listWindows.values()) { for (AbstractServerListDialog window : listWindows.values()) {
if (connected) window.serverNameChanged(); if (connected) window.serverNameChanged();
else window.connectionLost(); else window.connectionLost();
} }