Hide the default port in bookmark lists

Bookmark.hostPort gives the address alone for port 9987 and address:port
otherwise. The Android connect screen, the myTeamSpeak item lists on
desktop and Android, and the display name of an unnamed bookmark use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 15:29:42 +00:00
co-authored by Claude Opus 5.5
parent 455fc514f5
commit b586a80a14
5 changed files with 42 additions and 6 deletions
@@ -4,11 +4,13 @@ import java.util.UUID;
/** A saved server for quick connect. */
public final class Bookmark {
public static final int DEFAULT_PORT = 9987;
/** Stays the same through edits, for whatever refers to the bookmark from outside, like a launcher shortcut. */
public String id = UUID.randomUUID().toString();
public String label;
public String address;
public int port = 9987;
public int port = DEFAULT_PORT;
public String nickname;
public String password = "";
/** Identity to connect with; empty means "use the default identity". */
@@ -53,10 +55,19 @@ public final class Bookmark {
return this.port == port && this.address != null && this.address.trim().equalsIgnoreCase(address.trim());
}
/** Display name, falling back to "address:port" when no label is set. */
/** Display name, falling back to {@link #hostPort()} when no label is set. */
public String displayName() {
if (label != null && !label.isBlank()) return label;
return address + ":" + port;
return hostPort();
}
public String hostPort() {
return hostPort(address, port);
}
/** {@code address}, followed by {@code :port} unless it is {@link #DEFAULT_PORT}. */
public static String hostPort(String address, int port) {
return port == DEFAULT_PORT ? address : address + ":" + port;
}
@Override
@@ -0,0 +1,23 @@
package eu.lixko.ts3j.client.config;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class BookmarkTest {
@Test
void hostPortOmitsDefaultPort() {
assertEquals("ts.example.com", Bookmark.hostPort("ts.example.com", 9987));
}
@Test
void hostPortKeepsOtherPorts() {
assertEquals("ts.example.com:9988", Bookmark.hostPort("ts.example.com", 9988));
}
@Test
void displayNameWithoutLabelOmitsDefaultPort() {
assertEquals("ts.example.com", new Bookmark("", "ts.example.com", 9987, "nick", "").displayName());
}
}
@@ -2,6 +2,7 @@ package eu.lixko.ts3j.client.ui;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.formdev.flatlaf.util.UIScale;
import eu.lixko.ts3j.client.config.Bookmark;
import eu.lixko.ts3j.client.myts.AccountInfo;
import eu.lixko.ts3j.client.myts.MyTeamSpeak;
import eu.lixko.ts3j.client.myts.MyTeamSpeakLogin;
@@ -416,7 +417,7 @@ final class MyTeamSpeakPanel extends JPanel {
default -> "";
};
case 2 -> switch (r.item()) {
case SyncItem.Bookmark b -> b.address() + ":" + b.port();
case SyncItem.Bookmark b -> Bookmark.hostPort(b.address(), b.port());
case SyncItem.Identity i -> i.nickname();
default -> "";
};