added kiy input

This commit is contained in:
Hendrik Schutter 2018-12-07 23:23:48 +01:00
parent 5c9d54dabf
commit f5c5d546c5
4 changed files with 330 additions and 46 deletions

View File

@ -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'

View File

@ -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<KeyEvent>() {
@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;
}
}
}

View File

@ -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<tableDataCurrentOrder> 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<Pair<String, String>> 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;
}
}

View File

@ -23,7 +23,7 @@
<children>
<TabPane layoutX="4.0" layoutY="5.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="924.0" prefWidth="1536.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Einstellungen">
<Tab fx:id="tapSettings" text="Einstellungen">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
@ -270,7 +270,7 @@
</AnchorPane>
</content>
</Tab>
<Tab text="Aufträge">
<Tab fx:id="tapJobs" text="Aufträge">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="850.0" prefWidth="1536.0">
<children>
@ -328,17 +328,17 @@
</AnchorPane>
</content>
</Tab>
<Tab text="Neuer Auftrag">
<Tab fx:id="tapNewJob" text="Neuer Auftrag">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="850.0" prefWidth="1536.0">
<children>
<TreeTableView fx:id="tableCurrentOrder" layoutX="15.0" layoutY="85.0" prefHeight="358.0" prefWidth="382.0">
<TreeTableView fx:id="tableCurrentOrder" layoutX="15.0" layoutY="85.0" nodeOrientation="LEFT_TO_RIGHT" prefHeight="358.0" prefWidth="382.0">
<placeholder>
<Label text="" />
</placeholder>
<columns>
<TreeTableColumn fx:id="columnPosition" editable="false" prefWidth="320.0" resizable="false" sortable="false" text="Position" />
<TreeTableColumn fx:id="columnQuantity" editable="false" prefWidth="60.0" resizable="false" sortable="false" text="Anzahl" />
<TreeTableColumn fx:id="columnPosition" editable="false" prefWidth="320.0" resizable="false" sortable="false" text="Position" />
</columns>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
@ -487,7 +487,7 @@
</JFXButton>
</children>
</GridPane>
<Button fx:id="btnPrintBill" contentDisplay="CENTER" defaultButton="true" graphicTextGap="1.0" layoutX="75.0" layoutY="588.0" maxHeight="88.0" minHeight="75.0" mnemonicParsing="false" onAction="#btnPrintBillAction" prefHeight="88.0" prefWidth="258.0" text="Drucken" textAlignment="CENTER" wrapText="true">
<Button fx:id="btnPrintBill" contentDisplay="CENTER" focusTraversable="false" graphicTextGap="1.0" layoutX="75.0" layoutY="588.0" maxHeight="88.0" minHeight="75.0" mnemonicParsing="false" onAction="#btnPrintBillAction" prefHeight="88.0" prefWidth="258.0" text="Drucken" textAlignment="CENTER" wrapText="true">
<font>
<Font name="Cantarell Bold" size="48.0" />
</font>
@ -512,7 +512,7 @@
<Font name="Cantarell Regular" size="26.0" />
</font>
</Label>
<JFXButton fx:id="btnLock" buttonType="RAISED" cancelButton="true" layoutX="1.0" layoutY="6.0" lineSpacing="2.0" onAction="#btnLockAction" prefHeight="42.0" prefWidth="180.0" ripplerFill="BLACK" text="Kasse sperren" textAlignment="CENTER" textFill="#c91c1c" textOverrun="LEADING_WORD_ELLIPSIS">
<JFXButton fx:id="btnLock" buttonType="RAISED" layoutX="1.0" layoutY="6.0" lineSpacing="2.0" onAction="#btnLockAction" prefHeight="42.0" prefWidth="180.0" ripplerFill="BLACK" text="Kasse sperren" textAlignment="CENTER" textFill="#c91c1c" textOverrun="LEADING_WORD_ELLIPSIS">
<font>
<Font name="Cantarell Regular" size="19.0" />
</font>