Implemented generating QR code automatically if Enter or Tab is pressed and required data is entered

This commit is contained in:
dankito 2020-11-16 02:06:04 +01:00
parent bec5ca8f14
commit c2f7dbc3ac
1 changed files with 28 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import javafx.geometry.Pos
import javafx.scene.control.Alert
import javafx.scene.control.TextFormatter
import javafx.scene.image.Image
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import javafx.scene.layout.Priority
import javafx.stage.FileChooser
import org.slf4j.LoggerFactory
@ -75,18 +77,24 @@ class MainWindow : View(FX.messages["application.title"]) {
field(messages["Receiver"]) {
textfield(receiver) {
prefHeight = FieldHeight
setOnKeyPressed { handleTextFieldKeyPressed(it) }
}
}
field(messages["IBAN"]) {
textfield(iban) {
prefHeight = FieldHeight
setOnKeyPressed { handleTextFieldKeyPressed(it) }
}
}
field(messages["BIC"]) {
textfield(bic) {
prefHeight = FieldHeight
setOnKeyPressed { handleTextFieldKeyPressed(it) }
}
}
@ -97,12 +105,16 @@ class MainWindow : View(FX.messages["application.title"]) {
setTextFormatter(TextFormatter<String> { change ->
isDecimalNumberEntered(change)
})
setOnKeyPressed { handleTextFieldKeyPressed(it) }
}
}
field(messages["Reference"]) {
textfield(reference) {
prefHeight = FieldHeight
setOnKeyPressed { handleTextFieldKeyPressed(it) }
}
}
}
@ -196,6 +208,22 @@ class MainWindow : View(FX.messages["application.title"]) {
}
}
private fun handleTextFieldKeyPressed(event: KeyEvent) {
if (event.code == KeyCode.ENTER || event.code == KeyCode.TAB) {
if (haveRequiredDataBeenEntered()) {
generateQrCode()
}
}
}
private fun haveRequiredDataBeenEntered(): Boolean {
return receiver.value.isNotBlank()
&& iban.value.isNotBlank() // TODO: also check if it's a valid IBAN
// TODO: check if either no BIC or a valid BIC is entered
&& amount.value.isNotBlank()
&& reference.value.isNotBlank()
}
private fun selectDestinationFileAndSaveTo() {
val fileChooser = FileChooser()