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
@@ -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<T> extends JDialog {
abstract class AbstractListEditorDialog<T> extends JDialog {
protected final DefaultListModel<T> model = new DefaultListModel<>();
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 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);
this.itemPrompt = itemPrompt;
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.
*/
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()));
@@ -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 {
@@ -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),
@@ -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()));
}
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
* The server's privilege keys, as the official client's Permissions &gt; 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),
@@ -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());
@@ -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<String> {
final class ServerLogExcludeDialog extends AbstractListEditorDialog<String> {
private ServerLogExcludeDialog(Window owner, List<String> terms) {
super(owner, "Exclude Filter", "Exclude lines containing:", "Term:", terms, false);
@@ -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<Highlight> {
final class ServerLogHighlightDialog extends AbstractListEditorDialog<Highlight> {
private JButton foreground;
private JButton background;
@@ -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<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. */
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 <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;
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 extends ServerListDialog> D listWindow(Class<D> type) {
ServerListDialog window = listWindows.get(type);
private <D extends AbstractServerListDialog> D listWindow(Class<D> 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();
}