Skip to content
Snippets Groups Projects
Commit 8e257800 authored by Kaj Koivunen's avatar Kaj Koivunen :coffee:
Browse files

asetusvalikko

parent 00d7f0c5
No related branches found
No related tags found
No related merge requests found
package guru.kake.ronove
import javafx.scene.control.*
import javafx.scene.paint.Color
import tornadofx.*
class SettingsView : View("Settings") {
private lateinit var deeplKey : PasswordField
private lateinit var deeplStatus : Label
private lateinit var deeplRadio : RadioButton
private lateinit var googleKey : PasswordField
private lateinit var googleStatus : Label
private lateinit var googleRadio : RadioButton
private lateinit var applyButton : Button
private val toggleGroup = ToggleGroup()
private var deeplService : TranslationService? = null
private var googleService : TranslationService? = null
override val root = form {
deeplRadio = radiobutton("DeepL", toggleGroup) {
action { updateButton() }
}
fieldset() {
field("API key") {
deeplKey = passwordfield()
}
button("Save & test") {
action {
try {
deeplService = DeepLTranslator(deeplKey.text)
deeplStatus.text = "API initialized succesfully!"
deeplStatus.textFill = Color.GREEN
} catch (e: TranslationServiceException) {
deeplStatus.text = e.message
deeplStatus.textFill = Color.RED
} finally {
updateButton()
}
}
}
deeplStatus = label()
}
googleRadio = radiobutton("Google Translate", toggleGroup) {
action { updateButton() }
}
fieldset() {
field("API key") {
googleKey = passwordfield()
}
button("Save & test") {
}
googleStatus = label()
}
hbox {
applyButton = button("Apply") {
isDefaultButton = true
isDisable = true
action {
when (toggleGroup.selectedToggle) {
googleRadio -> TranslationBackend.service = googleService
deeplRadio -> TranslationBackend.service = deeplService
else -> assert(false)
}
}
}
button("Cancel") {
isCancelButton = true
action {
close()
}
}
}
}
private fun updateButton() {
applyButton.isDisable =
when (toggleGroup.selectedToggle) {
googleRadio -> googleService == null
deeplRadio -> deeplService == null
else -> true
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment