diff --git a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt index 0cfc872..7fbcf84 100644 --- a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt +++ b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt @@ -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 { 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()