From 49f0683a200074ff0ed8d4296106c67cc82e3978 Mon Sep 17 00:00:00 2001 From: Ronaldo Christnawan Date: Thu, 30 Jan 2020 09:45:06 +0700 Subject: [PATCH] Membuat Shortcut, Bug Fix UI, UI Prototype Form Bayar, Logic UI Nomor Kartu * Shortcut F8: Checkout * Bug Fix: Minimum height di FormUtama menyebabkan scroll horizontal tidak muncul * Logic UI nomor kartu: * Hanya bisa menginputkan integegr * Maksimum 4 * Jika input sudah berisi 4 digit, otomatis tab ke nomor berikutnya --- .../posterminal/FormUtamaController.java | 4 +- .../bayar/FormBayarController.java | 65 +++++ .../pos/FormTransaksiController.java | 6 +- .../amigogroup/posterminal/util/Fucout.java | 31 ++- src/main/resources/fxml/FormBayar.fxml | 235 ++++++++++++++++++ src/main/resources/fxml/FormUtama.fxml | 2 +- 6 files changed, 333 insertions(+), 10 deletions(-) create mode 100644 src/main/java/id/amigogroup/posterminal/bayar/FormBayarController.java create mode 100644 src/main/resources/fxml/FormBayar.fxml diff --git a/src/main/java/id/amigogroup/posterminal/FormUtamaController.java b/src/main/java/id/amigogroup/posterminal/FormUtamaController.java index 35f8699..3a13ad0 100644 --- a/src/main/java/id/amigogroup/posterminal/FormUtamaController.java +++ b/src/main/java/id/amigogroup/posterminal/FormUtamaController.java @@ -35,11 +35,11 @@ public class FormUtamaController implements Initializable { initShorcuts(); } - public void initShorcuts() { + private void initShorcuts() { Map listShortcuts = new HashMap<>(); KeyCombination kcCheckout = new KeyCodeCombination(KeyCode.F8); - Runnable rnCheckout = () -> System.out.println("Checkout"); + Runnable rnCheckout = () -> setContent(formFactory.getForm(FormConstanta.BAYAR, this)); listShortcuts.put(kcCheckout, rnCheckout); Platform.runLater(() -> { diff --git a/src/main/java/id/amigogroup/posterminal/bayar/FormBayarController.java b/src/main/java/id/amigogroup/posterminal/bayar/FormBayarController.java new file mode 100644 index 0000000..b031782 --- /dev/null +++ b/src/main/java/id/amigogroup/posterminal/bayar/FormBayarController.java @@ -0,0 +1,65 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package id.amigogroup.posterminal.bayar; + +import id.amigogroup.posterminal.util.Fucout; +import java.net.URL; +import java.util.ResourceBundle; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.robot.Robot; + +/** + * FXML Controller class + * + * @author ronal + */ +public class FormBayarController implements Initializable { + + @FXML + private TextField fldNoKartu1; + @FXML + private TextField fldNoKartu2; + @FXML + private TextField fldNoKartu3; + @FXML + private TextField fldNoKartu4; + + /** + * Initializes the controller class. + */ + @Override + public void initialize(URL url, ResourceBundle rb) { + initComponents(); + } + + private void initComponents() { + Fucout.forceFieldInteger(fldNoKartu1, 4); + Fucout.forceFieldInteger(fldNoKartu2, 4); + Fucout.forceFieldInteger(fldNoKartu3, 4); + Fucout.forceFieldInteger(fldNoKartu4, 4); + } + + @FXML + public void fldNomorKartuOnKeyTyped(KeyEvent event) { + if (event.getSource() != null + && event.getSource() instanceof TextField) { + TextField field = (TextField) event.getSource(); + + if (field.getText().length() >= 4) { + if (event.getCharacter().matches("[0-9]")) { + Robot robot = new Robot(); + robot.keyType(KeyCode.TAB); + } + } + } + } +} diff --git a/src/main/java/id/amigogroup/posterminal/pos/FormTransaksiController.java b/src/main/java/id/amigogroup/posterminal/pos/FormTransaksiController.java index 04a3dc0..3113c1c 100644 --- a/src/main/java/id/amigogroup/posterminal/pos/FormTransaksiController.java +++ b/src/main/java/id/amigogroup/posterminal/pos/FormTransaksiController.java @@ -64,10 +64,10 @@ public class FormTransaksiController implements Initializable { initShortcuts(); } - public void initShortcuts() { + private void initShortcuts() { Map listShortcuts = new HashMap<>(); - KeyCombination kcBtnTunai = new KeyCodeCombination(KeyCode.S); + KeyCombination kcBtnTunai = new KeyCodeCombination(KeyCode.F1); Runnable rnBtnTunai = () -> btnTunai.fire(); listShortcuts.put(kcBtnTunai, rnBtnTunai); @@ -82,7 +82,7 @@ public class FormTransaksiController implements Initializable { KeyCombination kcRetur = new KeyCodeCombination(KeyCode.F4); Runnable rnRetur = () -> btnRetur.fire(); listShortcuts.put(kcRetur, rnRetur); - + Platform.runLater(() -> { fldScan.getScene().getAccelerators().putAll(listShortcuts); }); diff --git a/src/main/java/id/amigogroup/posterminal/util/Fucout.java b/src/main/java/id/amigogroup/posterminal/util/Fucout.java index d2e387e..ff8fb9d 100644 --- a/src/main/java/id/amigogroup/posterminal/util/Fucout.java +++ b/src/main/java/id/amigogroup/posterminal/util/Fucout.java @@ -5,19 +5,42 @@ */ package id.amigogroup.posterminal.util; -import java.util.HashMap; -import java.util.Map; -import javafx.scene.input.KeyCodeCombination; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.scene.control.TextField; /** * * @author ronal */ public class Fucout { + //STRINGS public static final String APP_TITLE = "Pos Terminal"; - + //IMAGES URL public static final String APP_ICON = "/assets/logo-mini-squared.png"; + + //FUNCTIONS + + public static final void forceFieldToInteger(TextField field){ + forceFieldInteger(field,0); + } + public static final void forceFieldInteger(TextField field, int max) { + field.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, String oldValue, + String newValue) { + if (!newValue.matches("\\d*")) { + field.setText(newValue.replaceAll("[^\\d]", "")); + } + if (max > 0) { + if (newValue.length() > max) { + field.setText(oldValue); + } + } + } + }); + } } diff --git a/src/main/resources/fxml/FormBayar.fxml b/src/main/resources/fxml/FormBayar.fxml new file mode 100644 index 0000000..e8b596c --- /dev/null +++ b/src/main/resources/fxml/FormBayar.fxml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/FormUtama.fxml b/src/main/resources/fxml/FormUtama.fxml index ac88958..46f0cf7 100644 --- a/src/main/resources/fxml/FormUtama.fxml +++ b/src/main/resources/fxml/FormUtama.fxml @@ -18,7 +18,7 @@ - +