From f5c5d546c5fb49f5d3e9d940e75776bd5c1a551d Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 7 Dec 2018 23:23:48 +0100 Subject: [PATCH] added kiy input --- .../java/com/jFxKasse/application/Main.java | 12 +- .../jFxKasse/controller/KeyController.java | 227 ++++++++++++++++++ .../controller/MainWindowController.java | 123 +++++++--- src/main/resources/fxml/MainWindow.fxml | 14 +- 4 files changed, 330 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/jFxKasse/controller/KeyController.java diff --git a/src/main/java/com/jFxKasse/application/Main.java b/src/main/java/com/jFxKasse/application/Main.java index a0b4070..3044e0a 100644 --- a/src/main/java/com/jFxKasse/application/Main.java +++ b/src/main/java/com/jFxKasse/application/Main.java @@ -1,6 +1,8 @@ package com.jFxKasse.application; import javafx.application.Application; +import javafx.event.EventHandler; + import java.io.File; import javafx.animation.Animation; import javafx.animation.KeyFrame; @@ -12,7 +14,10 @@ import com.jFxKasse.controller.MainWindowController; import com.jFxKasse.controller.PrinterController; import com.jFxKasse.controller.XMLController; import com.jFxKasse.controller.DBController; +import com.jFxKasse.controller.KeyController; + import javafx.scene.Scene; +import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; public class Main extends Application @@ -31,6 +36,8 @@ public class Main extends Application private DBController dbc = new DBController(filepath); private PrinterController pc = new PrinterController(); + + private KeyController kc; private Stage primaryStage; @@ -65,6 +72,9 @@ public class Main extends Application primaryStage.setScene(scene); primaryStage.show(); // shows the stage + //attach the KeyController + kc = new KeyController(scene, mwc); + Timeline timeline = new Timeline( new KeyFrame(Duration.seconds(1), ev -> { mwc.updateTimeLabel(); // update time label on UI @@ -96,7 +106,7 @@ public class Main extends Application // config.xml found, app starting normal System.out.println("XML found!"); mwc.initUI(); // Starting the UI elements - mwc.setDBLabel(); // Set databese labels + mwc.setDBLabel(); // Set database labels dbc.setDbname(xmlc.getDatabaseName()); // handover database name dbc.connectDatabase(); // estabishing DB conection mwc.fillTablePositionen(); // fill TreeTable 'Positionen' diff --git a/src/main/java/com/jFxKasse/controller/KeyController.java b/src/main/java/com/jFxKasse/controller/KeyController.java new file mode 100644 index 0000000..6fc67c6 --- /dev/null +++ b/src/main/java/com/jFxKasse/controller/KeyController.java @@ -0,0 +1,227 @@ +package com.jFxKasse.controller; + +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; + +public class KeyController +{ + private MainWindowController mwc; + + public KeyController(Scene scene, MainWindowController mwc) + { + this.mwc = mwc; + + scene.setOnKeyPressed(new EventHandler() { + @Override + public void handle(KeyEvent keyEvent) + { + switch (mwc.getActiveTab()) { + case 0: + handleTabNewJob(keyEvent); + break; + + case 1: + handleTabJobs(keyEvent); + break; + + case 2: + handleTabPosEdit(keyEvent); + break; + + case 3: + handleTabSettings(keyEvent); + break; + default: + + } + + } + }); + + } + + private void handleTabNewJob(KeyEvent key) + { + if ((key.getCode() == KeyCode.ENTER) + && (!mwc.btnPrintBill.isDisabled())) { + mwc.btnPrintBillAction(null); + } + + if ((key.getCode() == KeyCode.ESCAPE) && (!mwc.btnLock.isDisabled())) { + mwc.btnLockAction(null); + } + + if ((key.getCode() == KeyCode.DELETE) + && (!mwc.btnDeleteSelectedPosition.isDisabled())) { + mwc.btnDeleteSelectedPositionAction(null); + } + + handelGridButtons(key); + + } + + private void handleTabJobs(KeyEvent key) + { + if ((key.getCode() == KeyCode.ENTER) + && (!mwc.btnReprintJob.isDisabled())) { + mwc.btnReprintJobAction(null); + } + + if ((key.getCode() == KeyCode.DELETE) + && (!mwc.btnCancelJob.isDisabled())) { + mwc.btnCancelJobAction(null); + } + + if ((key.getCode() == KeyCode.S) && (!mwc.btnCalcStats.isDisabled())) { + mwc.btnCalcStatsAction(null); + } + } + + private void handleTabPosEdit(KeyEvent key) + { + if ((key.getCode() == KeyCode.ENTER) + && (!mwc.btnSaveEntry.isDisabled())) { + mwc.btnSaveEntryAction(null); + } + + if ((key.getCode() == KeyCode.DELETE) + && (!mwc.btnClearEntry.isDisabled())) { + mwc.btnClearEntryAction(null); + } + } + + private void handleTabSettings(KeyEvent key) + { + if ((key.getCode() == KeyCode.ENTER) + && (!mwc.btnSavePrinter.isDisabled())) { + mwc.btnSavePrinterAction(null); + } + + if ((key.getCode() == KeyCode.ENTER) && (!mwc.btnSaveCat.isDisabled())) { + mwc.btnSaveCatAction(null); + } + + if ((key.getCode() == KeyCode.ENTER) + && (!mwc.btnCreateNewDatabase.isDisabled())) { + try { + mwc.btnCreateNewDatabaseAction(null); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + void handelGridButtons(KeyEvent key) + { + + switch (key.getCode()) { + case Q: + mwc.gridButton01Action(null); + break; + + case W: + mwc.gridButton02Action(null); + break; + + case E: + mwc.gridButton03Action(null); + break; + + case R: + mwc.gridButton04Action(null); + break; + + case T: + mwc.gridButton05Action(null); + break; + + case Z: + mwc.gridButton06Action(null); + break; + + case U: + mwc.gridButton07Action(null); + break; + + case I: + mwc.gridButton08Action(null); + break; + + case O: + mwc.gridButton09Action(null); + break; + + case P: + mwc.gridButton10Action(null); + break; + + case A: + mwc.gridButton11Action(null); + break; + + case S: + mwc.gridButton12Action(null); + break; + + case D: + mwc.gridButton13Action(null); + break; + + case F: + mwc.gridButton14Action(null); + break; + + case G: + mwc.gridButton15Action(null); + break; + + case H: + mwc.gridButton16Action(null); + break; + + case J: + mwc.gridButton17Action(null); + break; + + case K: + mwc.gridButton18Action(null); + break; + + case L: + mwc.gridButton19Action(null); + break; + + case Y: + mwc.gridButton20Action(null); + break; + + case X: + mwc.gridButton21Action(null); + break; + + case C: + mwc.gridButton22Action(null); + break; + + case V: + mwc.gridButton23Action(null); + break; + + case B: + mwc.gridButton24Action(null); + break; + + case N: + mwc.gridButton25Action(null); + break; + + default: + break; + + } + + } + +} diff --git a/src/main/java/com/jFxKasse/controller/MainWindowController.java b/src/main/java/com/jFxKasse/controller/MainWindowController.java index ce2f253..881fcd8 100644 --- a/src/main/java/com/jFxKasse/controller/MainWindowController.java +++ b/src/main/java/com/jFxKasse/controller/MainWindowController.java @@ -46,9 +46,18 @@ public class MainWindowController @FXML private AnchorPane paneDB; + @FXML + private Tab tapNewJob; + + @FXML + private Tab tapJobs; + @FXML private Tab tapPosEdit; + @FXML + private Tab tapSettings; + @FXML private TreeTableView tableCurrentOrder; @@ -199,34 +208,34 @@ public class MainWindowController private Button gridButton25; @FXML - private Button btnSavePrinter; + public Button btnSavePrinter; @FXML - private Button btnDeleteSelectedPosition; + public Button btnDeleteSelectedPosition; @FXML - private Button btnPrintBill; + public Button btnPrintBill; @FXML - private Button btnLock; + public Button btnLock; @FXML - private Button btnReprintJob; + public Button btnReprintJob; @FXML - private Button btnCancelJob; + public Button btnCancelJob; @FXML - private Button btnCalcStats; + public Button btnCalcStats; @FXML - private Button btnSaveEntry; + public Button btnSaveEntry; @FXML - private Button btnClearEntry; + public Button btnClearEntry; @FXML - private Button btnCreateNewDatabase; + public Button btnCreateNewDatabase; @FXML private Button btnOpenFolder; @@ -268,7 +277,7 @@ public class MainWindowController private JFXTextField tftKat05; @FXML - private Button btnSaveCat; + public Button btnSaveCat; @FXML private Label labelAllPrize; @@ -378,7 +387,7 @@ public class MainWindowController // creates a dialog Dialog> dialog = new Dialog<>(); dialog.setTitle("Über jFxKasse"); - dialog.setHeaderText("Informationen und Lizenzen - Version 0.3.1"); + dialog.setHeaderText("Informationen und Lizenzen - Version 0.3.2"); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK); @@ -625,151 +634,151 @@ public class MainWindowController @FXML public void gridButton01Action(ActionEvent event) { - handelGridButtons(1); + handleGridButtons(1); } @FXML public void gridButton02Action(ActionEvent event) { - handelGridButtons(2); + handleGridButtons(2); } @FXML public void gridButton03Action(ActionEvent event) { - handelGridButtons(3); + handleGridButtons(3); } @FXML public void gridButton04Action(ActionEvent event) { - handelGridButtons(4); + handleGridButtons(4); } @FXML public void gridButton05Action(ActionEvent event) { - handelGridButtons(5); + handleGridButtons(5); } @FXML public void gridButton06Action(ActionEvent event) { - handelGridButtons(6); + handleGridButtons(6); } @FXML public void gridButton07Action(ActionEvent event) { - handelGridButtons(7); + handleGridButtons(7); } @FXML public void gridButton08Action(ActionEvent event) { - handelGridButtons(8); + handleGridButtons(8); } @FXML public void gridButton09Action(ActionEvent event) { - handelGridButtons(9); + handleGridButtons(9); } @FXML public void gridButton10Action(ActionEvent event) { - handelGridButtons(10); + handleGridButtons(10); } @FXML public void gridButton11Action(ActionEvent event) { - handelGridButtons(11); + handleGridButtons(11); } @FXML public void gridButton12Action(ActionEvent event) { - handelGridButtons(12); + handleGridButtons(12); } @FXML public void gridButton13Action(ActionEvent event) { - handelGridButtons(13); + handleGridButtons(13); } @FXML public void gridButton14Action(ActionEvent event) { - handelGridButtons(14); + handleGridButtons(14); } @FXML public void gridButton15Action(ActionEvent event) { - handelGridButtons(15); + handleGridButtons(15); } @FXML public void gridButton16Action(ActionEvent event) { - handelGridButtons(16); + handleGridButtons(16); } @FXML public void gridButton17Action(ActionEvent event) { - handelGridButtons(17); + handleGridButtons(17); } @FXML public void gridButton18Action(ActionEvent event) { - handelGridButtons(18); + handleGridButtons(18); } @FXML public void gridButton19Action(ActionEvent event) { - handelGridButtons(19); + handleGridButtons(19); } @FXML public void gridButton20Action(ActionEvent event) { - handelGridButtons(20); + handleGridButtons(20); } @FXML public void gridButton21Action(ActionEvent event) { - handelGridButtons(21); + handleGridButtons(21); } @FXML public void gridButton22Action(ActionEvent event) { - handelGridButtons(22); + handleGridButtons(22); } @FXML public void gridButton23Action(ActionEvent event) { - handelGridButtons(23); + handleGridButtons(23); } @FXML public void gridButton24Action(ActionEvent event) { - handelGridButtons(24); + handleGridButtons(24); } @FXML public void gridButton25Action(ActionEvent event) { - handelGridButtons(25); + handleGridButtons(25); } @FXML @@ -811,7 +820,13 @@ public class MainWindowController btnReprintJob.setDisable(true); btnCancelJob.setDisable(true); btnDeleteSelectedPosition.setDisable(true); + btnOpenFolder.setFocusTraversable(false); + switchSeparate.setFocusTraversable(false); + ueberbtn.setFocusTraversable(false); isPrintBtnDisabled = true; + btnPrintBill + .setStyle("-fx-background-color: #2ac8fc; -fx-text-fill: black;"); + btnLock.setFocusTraversable(false); initPositionen(); initCurrentOrderTreeTableView(); initJobTreeTableView(); @@ -1167,6 +1182,7 @@ public class MainWindowController { for (int i = 0; i < 25; i++) { getButtonByID(i).setText(dbc.getName_Positionen(i + 1)); + getButtonByID(i).setFocusTraversable(false); if ((getColorID(dbc.getColor_Positionen(i + 1)) == 0) || (getColorID(dbc.getColor_Positionen(i + 1)) == 7)) { getButtonByID(i).setStyle("-fx-background-color: " @@ -1243,8 +1259,14 @@ public class MainWindowController } } - private void handelGridButtons(int pID) + private void handleGridButtons(int pID) { + + if (!getButtonByID(pID - 1).isVisible()) { + // Button is not visible, no action + return; + } + currentJob.addPosition(dbc.getName_Positionen(pID), Float.parseFloat(dbc.getValue_Positionen(pID)), dbc.getCategoryNameFromPositionen(pID)); @@ -1262,6 +1284,9 @@ public class MainWindowController } setJobPrizeLabel(currentJob.getJobValue()); + + btnPrintBill.setFocusTraversable(false); + } private void initCurrentOrderTreeTableView() @@ -1447,4 +1472,26 @@ public class MainWindowController btnLock.setDisable(true); } + public int getActiveTab() + { + + if (tapNewJob.isSelected()) { + return 0; + } + + if (tapJobs.isSelected()) { + return 1; + } + + if (tapPosEdit.isSelected()) { + return 2; + } + + if (tapSettings.isSelected()) { + return 3; + } + + return 404; + } + } diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index abb42fc..17f48aa 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -23,7 +23,7 @@ - + @@ -270,7 +270,7 @@ - + @@ -328,17 +328,17 @@ - + - + - + @@ -487,7 +487,7 @@ -