Skip to content

Commit

Permalink
feat:add auto copy & string extract, adjust UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Sep 11, 2021
1 parent 894ab1f commit 9318573
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/ToolsApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ToolsApp : App(Home::class, Styles::class) {
init {
// for text i18n
FX.locale = if (Prefs.language == "zh") Locale.CHINESE else Locale.ENGLISH
addStageIcon(Image(resources.stream("/tb.png")))
addStageIcon(Image(resources.stream("/img/tb.png")))
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/ext/FXExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.imageio.ImageIO
fun String.copy() =
Clipboard.getSystemClipboard().setContent(ClipboardContent().apply { putString(this@copy) })

fun clipboardText(): String = Clipboard.getSystemClipboard().string?:""
fun clipboardText(): String = Clipboard.getSystemClipboard().string ?: ""

fun clipboardImage(): Image? = Clipboard.getSystemClipboard().image

Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/me/leon/ext/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object Prefs {
private const val IGNORE_UPDATE = "isIgnoreUpdate"
private const val ALWAYS_ON_TOP = "alwaysOnTop"
private const val LANGUAGE = "language"
private const val AUTO_COPY = "autoCopy"
private val preference = Preferences.userNodeForPackage(Prefs::class.java)
var isIgnoreUpdate
get() = preference.getBoolean(IGNORE_UPDATE, false)
Expand All @@ -22,4 +23,9 @@ object Prefs {
set(value) {
preference.put(LANGUAGE, value)
}
var autoCopy: Boolean
get() = preference.getBoolean(AUTO_COPY, false)
set(value) {
preference.putBoolean(AUTO_COPY, value)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/me/leon/ext/Toast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ class Toast private constructor() {
}
}

fun Stage.showToast(msg: String) {
Toast.makeText(this, msg)
fun Stage.showToast(msg: String, time: Int = 0) {
Toast.makeText(this, msg, time)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/view/AboutView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AboutView : View(messages["about"]) {
alignment = Pos.CENTER
spacing = DEFAULT_SPACING
paddingAll = DEFAULT_SPACING
imageview("/tb.png")
imageview("/img/tb.png")
text("${messages["ver"]}: v$VERSION") { font = Font.font(18.0) }
text("Build: ${times()}")
text("JRE: ${System.getProperty("java.runtime.version")}")
Expand Down
23 changes: 14 additions & 9 deletions src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import me.leon.controller.AsymmetricCryptoController
import me.leon.encode.base.base64
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.DEFAULT_SPACING_10X
import me.leon.ext.Prefs
import me.leon.ext.cast
import me.leon.ext.clipboardText
import me.leon.ext.copy
import me.leon.ext.fileDraggedHandler
import me.leon.ext.openInBrowser
import me.leon.ext.showToast
import tornadofx.FX
import tornadofx.View
import tornadofx.action
Expand Down Expand Up @@ -101,7 +103,7 @@ class AsymmetricCryptoView : View(FX.messages["asymmetric"]) {
spacing = DEFAULT_SPACING
hbox {
label(messages["key"])
button(graphic = imageview("/import.png")) { action { keyText = clipboardText() } }
button(graphic = imageview("/img/import.png")) { action { keyText = clipboardText() } }
}
taKey =
textarea {
Expand All @@ -112,7 +114,9 @@ class AsymmetricCryptoView : View(FX.messages["asymmetric"]) {

hbox {
label(messages["input"]) { tooltip("加密时为明文,解密时为base64编码的密文") }
button(graphic = imageview("/import.png")) { action { inputText = clipboardText() } }
button(graphic = imageview("/img/import.png")) {
action { inputText = clipboardText() }
}
}
taInput =
textarea {
Expand All @@ -138,16 +142,16 @@ class AsymmetricCryptoView : View(FX.messages["asymmetric"]) {
tooltip("默认公钥加密,私钥解密。开启后私钥加密,公钥解密")
}

button(messages["run"], imageview("/run.png")) { action { doCrypto() } }
button(messages["run"], imageview("/img/run.png")) { action { doCrypto() } }
button(messages["genKeypair"]) {
action { "https://miniu.alipay.com/keytool/create".openInBrowser() }
}
}
hbox {
spacing = DEFAULT_SPACING
label(messages["output"])
button(graphic = imageview("/copy.png")) { action { outputText.copy() } }
button(graphic = imageview("/up.png")) {
button(graphic = imageview("/img/copy.png")) { action { outputText.copy() } }
button(graphic = imageview("/img/up.png")) {
action {
inputText = outputText
outputText = ""
Expand Down Expand Up @@ -180,9 +184,10 @@ class AsymmetricCryptoView : View(FX.messages["asymmetric"]) {
controller.pubDecrypt(keyText, alg, inputText, selectedBits.get().toInt())
else controller.priDecrypt(keyText, alg, inputText, selectedBits.get().toInt())
} ui
{
outputText = it
labelInfo.text = info
}
{
outputText = it
labelInfo.text = info
if (Prefs.autoCopy) it.copy().also { primaryStage.showToast(messages["copied"]) }
}
}
}
50 changes: 28 additions & 22 deletions src/main/kotlin/me/leon/view/DigestView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import javafx.scene.control.Label
import javafx.scene.control.TextArea
import me.leon.controller.DigestController
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.Prefs
import me.leon.ext.clipboardText
import me.leon.ext.copy
import me.leon.ext.fileDraggedHandler
import me.leon.ext.showToast
import tornadofx.FX.Companion.messages
import tornadofx.View
import tornadofx.action
Expand Down Expand Up @@ -75,20 +77,20 @@ class DigestView : View(messages["hash"]) {
"Blake2s" to listOf("160", "224", "256"),
"DSTU7564" to listOf("256", "384", "512"),
"Skein" to
listOf(
"256-160",
"256-224",
"256-256",
"512-128",
"512-160",
"512-224",
"512-256",
"512-384",
"512-512",
"1024-384",
"1024-512",
"1024-1024"
),
listOf(
"256-160",
"256-224",
"256-256",
"512-128",
"512-160",
"512-224",
"512-256",
"512-384",
"512-512",
"1024-384",
"1024-512",
"1024-1024"
),
"GOST3411" to listOf("256"),
"GOST3411-2012" to listOf("256", "512"),
"Haraka" to listOf("256", "512"),
Expand All @@ -105,7 +107,9 @@ class DigestView : View(messages["hash"]) {
spacing = DEFAULT_SPACING
hbox {
label(messages["input"])
button(graphic = imageview("/import.png")) { action { inputText = clipboardText() } }
button(graphic = imageview("/img/import.png")) {
action { inputText = clipboardText() }
}
}
taInput =
textarea {
Expand Down Expand Up @@ -154,14 +158,14 @@ class DigestView : View(messages["hash"]) {
spacing = DEFAULT_SPACING
paddingLeft = DEFAULT_SPACING
checkbox(messages["fileMode"], isFileMode)
button(messages["run"], imageview("/run.png")) {
button(messages["run"], imageview("/img/run.png")) {
enableWhen(!isProcessing)
action { doHash() }
}
}
hbox {
label(messages["output"])
button(graphic = imageview("/copy.png")) { action { outputText.copy() } }
button(graphic = imageview("/img/copy.png")) { action { outputText.copy() } }
}
taOutput =
textarea {
Expand All @@ -183,9 +187,11 @@ class DigestView : View(messages["hash"]) {
}
else controller.digest(method, inputText)
} ui
{
isProcessing.value = false
outputText = it
labelInfo.text = info
}
{
isProcessing.value = false
outputText = it
labelInfo.text = info
if (Prefs.autoCopy)
outputText.copy().also { primaryStage.showToast(messages["copied"]) }
}
}
14 changes: 8 additions & 6 deletions src/main/kotlin/me/leon/view/EncodeTransferView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import me.leon.controller.EncodeController
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.DEFAULT_SPACING_80X
import me.leon.ext.EncodeType
import me.leon.ext.Prefs
import me.leon.ext.cast
import me.leon.ext.copy
import me.leon.ext.encodeType
import me.leon.ext.encodeTypeMap
import me.leon.ext.fileDraggedHandler
import me.leon.ext.showToast
import tornadofx.FX.Companion.messages
import tornadofx.View
import tornadofx.action
Expand Down Expand Up @@ -76,7 +78,7 @@ class EncodeTransferView : View(messages["encodeTransfer"]) {
tilepane {
vgap = 8.0
alignment = Pos.TOP_LEFT
prefColumns = 7
prefColumns = 7
togglegroup {
encodeTypeMap.forEach {
radiobutton(it.key) {
Expand Down Expand Up @@ -114,18 +116,18 @@ class EncodeTransferView : View(messages["encodeTransfer"]) {
paddingTop = DEFAULT_SPACING
hgap = DEFAULT_SPACING * 2
alignment = Pos.CENTER
button(messages["transfer"], imageview("/run.png")) {
button(messages["transfer"], imageview("/img/run.png")) {
action { run() }
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE)
}
button(messages["up"], imageview("/up.png")) {
button(messages["up"], imageview("/img/up.png")) {
action {
taInput.text = outputText
taOutput.text = ""
}
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE)
}
button(messages["copy"], imageview("/copy.png")) {
button(messages["copy"], imageview("/img/copy.png")) {
action { outputText.copy() }
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE)
}
Expand All @@ -139,7 +141,7 @@ class EncodeTransferView : View(messages["encodeTransfer"]) {
tilepane {
vgap = 8.0
alignment = Pos.TOP_LEFT
prefColumns = 7
prefColumns = 7
togglegroup {
encodeTypeMap.forEach {
radiobutton(it.key) {
Expand Down Expand Up @@ -173,7 +175,7 @@ class EncodeTransferView : View(messages["encodeTransfer"]) {
taOutput.text =
String(decode, Charsets.UTF_8).takeIf { it.contains("解码错误:") }
?: controller.encode2String(decode, dstEncodeType)

if (Prefs.autoCopy) outputText.copy().also { primaryStage.showToast(messages["copied"]) }
labelInfo.text = info
}
}
42 changes: 27 additions & 15 deletions src/main/kotlin/me/leon/view/EncodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package me.leon.view

import javafx.beans.property.SimpleBooleanProperty
import javafx.geometry.Pos
import javafx.scene.Parent
import javafx.scene.control.Label
import javafx.scene.control.RadioButton
import javafx.scene.control.TabPane
import javafx.scene.control.TextArea
import javafx.scene.control.TextField
import me.leon.controller.EncodeController
import me.leon.encode.base.base64
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.DEFAULT_SPACING_80X
import me.leon.ext.EncodeType
import me.leon.ext.Prefs
import me.leon.ext.cast
import me.leon.ext.clipboardText
import me.leon.ext.copy
Expand All @@ -20,6 +23,8 @@ import me.leon.ext.fileDraggedHandler
import me.leon.ext.readBytesFromNet
import me.leon.ext.readFromNet
import me.leon.ext.readHeadersFromNet
import me.leon.ext.safeAs
import me.leon.ext.showToast
import tornadofx.FX.Companion.messages
import tornadofx.View
import tornadofx.action
Expand Down Expand Up @@ -76,7 +81,9 @@ class EncodeView : View(messages["encodeAndDecode"]) {
spacing = DEFAULT_SPACING
hbox {
label(messages["input"])
button(graphic = imageview("/import.png")) { action { taInput.text = clipboardText() } }
button(graphic = imageview("/img/import.png")) {
action { taInput.text = clipboardText() }
}
}

taInput =
Expand Down Expand Up @@ -112,7 +119,7 @@ class EncodeView : View(messages["encodeAndDecode"]) {
tilepane {
vgap = 8.0
alignment = Pos.TOP_LEFT
prefColumns = 7
prefColumns = 7
togglegroup {
encodeTypeMap.forEach {
radiobutton(it.key) {
Expand All @@ -124,11 +131,7 @@ class EncodeView : View(messages["encodeAndDecode"]) {
encodeType = new.cast<RadioButton>().text.encodeType()
enableDict.value = encodeType.type.contains("base")
tfCustomDict.text = encodeType.defaultDict
if (isEncode) {
taOutput.text =
controller.encode2String(inputText, encodeType, tfCustomDict.text)
lableInfo.text = info
}
if (isEncode) run()
}
}
}
Expand Down Expand Up @@ -158,18 +161,28 @@ class EncodeView : View(messages["encodeAndDecode"]) {
run()
}
}
button(messages["run"], imageview("/run.png")) { action { run() } }
button(messages["run"], imageview("/img/run.png")) { action { run() } }
}
hbox {
spacing = DEFAULT_SPACING
label(messages["output"])
button(graphic = imageview("/copy.png")) { action { outputText.copy() } }
button(graphic = imageview("/up.png")) {
button(graphic = imageview("/img/copy.png")) { action { outputText.copy() } }
button(graphic = imageview("/img/up.png")) {
action {
taInput.text = outputText
taOutput.text = ""
}
}
button(graphic = imageview("/img/jump.png")) {
action {
var tmp: Parent? = parent
while (tmp != null) {
if (tmp is TabPane) break
tmp = tmp.parent
}
tmp.safeAs<TabPane>()?.selectionModel?.select(2)
}
}
}

taOutput =
Expand All @@ -184,11 +197,10 @@ class EncodeView : View(messages["encodeAndDecode"]) {
}

private fun run() {
if (isEncode) {
taOutput.text = controller.encode2String(inputText, encodeType, tfCustomDict.text)
} else {
taOutput.text = controller.decode2String(inputText, encodeType, tfCustomDict.text)
}
taOutput.text =
if (isEncode) controller.encode2String(inputText, encodeType, tfCustomDict.text)
else controller.decode2String(inputText, encodeType, tfCustomDict.text)
if (Prefs.autoCopy) outputText.copy().also { primaryStage.showToast(messages["copied"]) }
lableInfo.text = info
}
}
Loading

0 comments on commit 9318573

Please sign in to comment.