mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-15 18:02:58 +08:00
chore: vnc clipboard charset
This commit is contained in:
@@ -2,11 +2,13 @@ package app.termora.plugins.vnc
|
||||
|
||||
import app.termora.*
|
||||
import app.termora.plugin.internal.BasicProxyOption
|
||||
import app.termora.plugin.internal.BasicTerminalOption
|
||||
import com.formdev.flatlaf.FlatClientProperties
|
||||
import com.formdev.flatlaf.extras.components.FlatComboBox
|
||||
import com.formdev.flatlaf.ui.FlatTextBorder
|
||||
import com.jgoodies.forms.builder.FormBuilder
|
||||
import com.jgoodies.forms.layout.FormLayout
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Component
|
||||
import java.awt.KeyboardFocusManager
|
||||
@@ -19,12 +21,29 @@ import javax.swing.*
|
||||
internal open class VNCHostOptionsPane : OptionsPane() {
|
||||
protected val generalOption = GeneralOption()
|
||||
protected val proxyOption = BasicProxyOption(authenticationTypes = emptyList())
|
||||
private val terminalOption = object : BasicTerminalOption() {
|
||||
override fun getTitle(): String {
|
||||
return "VNC"
|
||||
}
|
||||
|
||||
override fun getIcon(isSelected: Boolean): Icon {
|
||||
return VNCProtocolProvider.instance.getIcon()
|
||||
}
|
||||
}.apply {
|
||||
showAltModifierComboBox = false
|
||||
showCharsetComboBox = true
|
||||
init()
|
||||
|
||||
charsetComboBox.selectedItem = "ISO-8859-1"
|
||||
|
||||
}
|
||||
|
||||
protected val owner: Window get() = SwingUtilities.getWindowAncestor(this)
|
||||
|
||||
init {
|
||||
addOption(generalOption)
|
||||
addOption(proxyOption)
|
||||
|
||||
addOption(terminalOption)
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +84,9 @@ internal open class VNCHostOptionsPane : OptionsPane() {
|
||||
proxy = proxy,
|
||||
sort = System.currentTimeMillis(),
|
||||
remark = generalOption.remarkTextArea.text,
|
||||
options = Options.Default.copy(
|
||||
encoding = terminalOption.charsetComboBox.selectedItem?.toString() ?: "ISO-8859-1"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,6 +100,8 @@ internal open class VNCHostOptionsPane : OptionsPane() {
|
||||
generalOption.passwordTextField.text = host.authentication.password
|
||||
}
|
||||
|
||||
terminalOption.charsetComboBox.selectedItem = StringUtils.defaultIfBlank(host.options.encoding, "ISO-8859-1")
|
||||
|
||||
proxyOption.proxyTypeComboBox.selectedItem = host.proxy.type
|
||||
proxyOption.proxyHostTextField.text = host.proxy.host
|
||||
proxyOption.proxyPasswordTextField.text = host.proxy.password
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package app.termora.plugins.vnc
|
||||
|
||||
import app.termora.*
|
||||
import com.glavsoft.rfb.ClipboardController
|
||||
import com.glavsoft.rfb.client.KeyEventMessage
|
||||
import com.glavsoft.rfb.encoding.EncodingType
|
||||
import com.glavsoft.rfb.protocol.Protocol
|
||||
@@ -14,13 +15,13 @@ import com.glavsoft.viewer.swing.ClipboardControllerImpl
|
||||
import com.glavsoft.viewer.swing.Surface
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.swing.Swing
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils
|
||||
import java.awt.AWTEvent
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Graphics
|
||||
import java.awt.event.AWTEventListener
|
||||
import java.awt.event.ActionEvent
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.Proxy
|
||||
@@ -35,6 +36,7 @@ class VNCViewer(private val host: Host) : JPanel(BorderLayout()), Disposable {
|
||||
private var surface: Surface? = null
|
||||
private var protocol: Protocol? = null
|
||||
private var uiSettings: UiSettings? = null
|
||||
private var clipboardController: ClipboardController? = null
|
||||
|
||||
private val layeredPane = LayeredPane()
|
||||
private val toolbar = MyToolbar()
|
||||
@@ -108,8 +110,13 @@ class VNCViewer(private val host: Host) : JPanel(BorderLayout()), Disposable {
|
||||
uiSettings.addListener(surface)
|
||||
protocolSettings.addListener(surface)
|
||||
|
||||
val encoding = StringUtils.defaultIfBlank(host.options.encoding, "ISO-8859-1")
|
||||
val clipboardController = ClipboardControllerImpl(protocol, encoding).also { this.clipboardController = it }
|
||||
|
||||
protocol.handshake()
|
||||
protocol.startNormalHandling({ disconnect() }, surface, ClipboardControllerImpl(protocol, "GBK"))
|
||||
protocol.startNormalHandling({ disconnect() }, surface, clipboardController)
|
||||
|
||||
executorService.execute(clipboardController)
|
||||
|
||||
withContext(Dispatchers.Swing) {
|
||||
scrollPane.setViewportView(surface)
|
||||
@@ -118,7 +125,9 @@ class VNCViewer(private val host: Host) : JPanel(BorderLayout()), Disposable {
|
||||
|
||||
private fun disconnect() {
|
||||
socket?.close()
|
||||
clipboardController?.setEnabled(false)
|
||||
|
||||
clipboardController = null
|
||||
protocol = null
|
||||
surface = null
|
||||
socket = null
|
||||
@@ -200,16 +209,6 @@ class VNCViewer(private val host: Host) : JPanel(BorderLayout()), Disposable {
|
||||
}
|
||||
})
|
||||
|
||||
addMouseListener(object : MouseAdapter() {
|
||||
override fun mouseEntered(e: MouseEvent) {
|
||||
println("Enter")
|
||||
}
|
||||
|
||||
override fun mouseExited(e: MouseEvent) {
|
||||
println("Exit")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
override fun eventDispatched(event: AWTEvent) {
|
||||
|
||||
Reference in New Issue
Block a user