From e5f854dfcd1c1248d97b4a1d83e5c27769d10d8e Mon Sep 17 00:00:00 2001 From: hstyi Date: Wed, 12 Feb 2025 11:45:39 +0800 Subject: [PATCH] feat: HostTree shows more information (#203) --- src/main/kotlin/app/termora/HostTree.kt | 36 ++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/termora/HostTree.kt b/src/main/kotlin/app/termora/HostTree.kt index 8dd37ee..588fdbf 100644 --- a/src/main/kotlin/app/termora/HostTree.kt +++ b/src/main/kotlin/app/termora/HostTree.kt @@ -64,13 +64,37 @@ class HostTree : JTree(), Disposable { hasFocus: Boolean ): Component { val host = value as Host - val c = super.getTreeCellRendererComponent(tree, host, sel, expanded, leaf, row, hasFocus) - if (host.protocol == Protocol.Folder) { - icon = if (expanded) FlatTreeOpenIcon() else FlatTreeClosedIcon() - } else if (host.protocol == Protocol.SSH || host.protocol == Protocol.Local) { - icon = if (sel && this@HostTree.hasFocus()) Icons.terminal.dark else Icons.terminal + var text = host.name + val color = if (sel) { + if (this@HostTree.hasFocus()) { + UIManager.getColor("textHighlightText") + } else { + this.foreground + } + } else { + UIManager.getColor("textInactiveText") + } + + if (host.protocol == Protocol.SSH) { + text = """ + ${host.name} +    + ${host.username}@${host.host} + """.trimIndent() } else if (host.protocol == Protocol.Serial) { - icon = if (sel && this@HostTree.hasFocus()) Icons.plugin.dark else Icons.plugin + text = """ + ${host.name} +    + ${host.options.serialComm.port} + """.trimIndent() + } + + val c = super.getTreeCellRendererComponent(tree, text, sel, expanded, leaf, row, hasFocus) + + icon = when (host.protocol) { + Protocol.Folder -> if (expanded) FlatTreeOpenIcon() else FlatTreeClosedIcon() + Protocol.SSH, Protocol.Local -> if (sel && this@HostTree.hasFocus()) Icons.terminal.dark else Icons.terminal + Protocol.Serial -> if (sel && this@HostTree.hasFocus()) Icons.plugin.dark else Icons.plugin } return c }