feat: HostTree shows more information (#203)

This commit is contained in:
hstyi
2025-02-12 11:45:39 +08:00
committed by GitHub
parent 4e690bafed
commit e5f854dfcd

View File

@@ -64,13 +64,37 @@ class HostTree : JTree(), Disposable {
hasFocus: Boolean hasFocus: Boolean
): Component { ): Component {
val host = value as Host val host = value as Host
val c = super.getTreeCellRendererComponent(tree, host, sel, expanded, leaf, row, hasFocus) var text = host.name
if (host.protocol == Protocol.Folder) { val color = if (sel) {
icon = if (expanded) FlatTreeOpenIcon() else FlatTreeClosedIcon() if (this@HostTree.hasFocus()) {
} else if (host.protocol == Protocol.SSH || host.protocol == Protocol.Local) { UIManager.getColor("textHighlightText")
icon = if (sel && this@HostTree.hasFocus()) Icons.terminal.dark else Icons.terminal } else {
this.foreground
}
} else {
UIManager.getColor("textInactiveText")
}
if (host.protocol == Protocol.SSH) {
text = """
<html>${host.name}
&nbsp;&nbsp;
<font color=rgb(${color.red},${color.green},${color.blue})>${host.username}@${host.host}</font></html>
""".trimIndent()
} else if (host.protocol == Protocol.Serial) { } else if (host.protocol == Protocol.Serial) {
icon = if (sel && this@HostTree.hasFocus()) Icons.plugin.dark else Icons.plugin text = """
<html>${host.name}
&nbsp;&nbsp;
<font color=rgb(${color.red},${color.green},${color.blue})>${host.options.serialComm.port}</font></html>
""".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 return c
} }