From a59ed72761ca335491ae83f766e23714e9a2453a Mon Sep 17 00:00:00 2001 From: Jan <janschubert93@web.de> Date: Thu, 28 Nov 2019 09:28:49 +0100 Subject: [PATCH] =?UTF-8?q?Bei=20Tastendruck=20wird=20in=20Textfeld=20gesc?= =?UTF-8?q?hrieben.=20Textfelder=20f=C3=BCr=20Steckbrett=20mit=20fx:id=20g?= =?UTF-8?q?eneriert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Enigma/GuiController.java | 213 ++++++++++++++++++++---- src/main/resources/Enigma/gui.fxml | 56 +++---- 2 files changed, 212 insertions(+), 57 deletions(-) diff --git a/src/main/java/Enigma/GuiController.java b/src/main/java/Enigma/GuiController.java index ba4a3e4..71168fa 100644 --- a/src/main/java/Enigma/GuiController.java +++ b/src/main/java/Enigma/GuiController.java @@ -12,6 +12,7 @@ public class GuiController { private final static String[] str= {"I", "II", "III", "IV", "V"}; private final static String[] num ={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26"}; private final static String[] bs ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; + private String textEingabe=""; @FXML @@ -125,15 +126,43 @@ public class GuiController { @FXML private TextField tfcodiert; - @FXML - private TextField tfKenngruppe; @FXML private MenuButton mBtnNotchPos1; @FXML - void gedrueckteTaste() { - } + private TextField tfStecker1; + + @FXML + private TextField tfStecker2; + + @FXML + private TextField tfStecker3; + + @FXML + private TextField tfStecker4; + + @FXML + private TextField tfStecker5; + + @FXML + private TextField tfStecker6; + + @FXML + private TextField tfStecker7; + + @FXML + private TextField tfStecker8; + + @FXML + private TextField tfStecker9; + + @FXML + private TextField tfStecker10; + +// @FXML +// void gedrueckteTaste() { +// } @FXML void btnempfangen() { @@ -173,16 +202,14 @@ public class GuiController { } @FXML - private Button btnQ2; + private Button btnQ1; @FXML void gedrueckteTasteQ() { - btnQ2.setStyle("-fx-background-color: #ff0000"); + btnQ1.setStyle("-fx-background-color: #ff0000"); //btnQ2.setStyle("-fx-background-color: #ffffff"); } - - @FXML void initialize() { //Einträge für Walzen @@ -235,28 +262,158 @@ public class GuiController { assert mBtnStartPos2 != null : "fx:id=\"mBtnStartPos2\" was not injected: check your FXML file 'gui.fxml'."; assert tfrein != null : "fx:id=\"tfrein\" was not injected: check your FXML file 'gui.fxml'."; assert tfcodiert != null : "fx:id=\"tfcodiert\" was not injected: check your FXML file 'gui.fxml'."; - assert tfKenngruppe != null : "fx:id=\"tfKenngruppe\" was not injected: check your FXML file 'gui.fxml'."; assert mBtnNotchPos1 != null : "fx:id=\"mBtnNotchPos1\" was not injected: check your FXML file 'gui.fxml'."; + // ActionListener den Butten hinzufügen + btnA.setOnAction(e -> {gedrueckteTaste(e);}); + btnB.setOnAction(e -> {gedrueckteTaste(e);}); + btnC.setOnAction(e -> {gedrueckteTaste(e);}); + btnD.setOnAction(e -> {gedrueckteTaste(e);}); + btnE.setOnAction(e -> {gedrueckteTaste(e);}); + btnF.setOnAction(e -> {gedrueckteTaste(e);}); + btnG.setOnAction(e -> {gedrueckteTaste(e);}); + btnH.setOnAction(e -> {gedrueckteTaste(e);}); + btnI.setOnAction(e -> {gedrueckteTaste(e);}); + btnJ.setOnAction(e -> {gedrueckteTaste(e);}); + btnK.setOnAction(e -> {gedrueckteTaste(e);}); + btnL.setOnAction(e -> {gedrueckteTaste(e);}); + btnM.setOnAction(e -> {gedrueckteTaste(e);}); + btnN.setOnAction(e -> {gedrueckteTaste(e);}); + btnO.setOnAction(e -> {gedrueckteTaste(e);}); + btnP.setOnAction(e -> {gedrueckteTaste(e);}); + btnQ.setOnAction(e -> {gedrueckteTaste(e);}); + btnR.setOnAction(e -> {gedrueckteTaste(e);}); + btnS.setOnAction(e -> {gedrueckteTaste(e);}); + btnT.setOnAction(e -> {gedrueckteTaste(e);}); + btnU.setOnAction(e -> {gedrueckteTaste(e);}); + btnV.setOnAction(e -> {gedrueckteTaste(e);}); + btnW.setOnAction(e -> {gedrueckteTaste(e);}); + btnX.setOnAction(e -> {gedrueckteTaste(e);}); + btnY.setOnAction(e -> {gedrueckteTaste(e);}); + btnZ.setOnAction(e -> {gedrueckteTaste(e);}); + } + /** + * Auswertung welcher Button gedrückt wurde + * @param e => ActionEvent des auslösenden Button + */ + @FXML + private void gedrueckteTaste(javafx.event.ActionEvent e) { + //TODO Anbindung an Klasse Hardware + if (e.getSource() == btnA) setText(btnA); + if (e.getSource() == btnB) setText(btnB); + if (e.getSource() == btnC) setText(btnC); + if (e.getSource() == btnD) setText(btnD); + if (e.getSource() == btnE) setText(btnE); + if (e.getSource() == btnF) setText(btnF); + if (e.getSource() == btnG) setText(btnG); + if (e.getSource() == btnH) setText(btnH); + if (e.getSource() == btnI) setText(btnI); + if (e.getSource() == btnJ) setText(btnJ); + if (e.getSource() == btnK) setText(btnK); + if (e.getSource() == btnL) setText(btnL); + if (e.getSource() == btnM) setText(btnM); + if (e.getSource() == btnN) setText(btnN); + if (e.getSource() == btnO) setText(btnO); + if (e.getSource() == btnP) setText(btnP); + if (e.getSource() == btnQ) setText(btnQ); + if (e.getSource() == btnR) setText(btnR); + if (e.getSource() == btnS) setText(btnS); + if (e.getSource() == btnT) setText(btnT); + if (e.getSource() == btnU) setText(btnU); + if (e.getSource() == btnV) setText(btnV); + if (e.getSource() == btnW) setText(btnW); + if (e.getSource() == btnX) setText(btnX); + if (e.getSource() == btnY) setText(btnY); + if (e.getSource() == btnZ) setText(btnZ); + } + /** + * schreibt Buchstaben des gedrückten Knopfes in Textfeld tfrein + * @param b : gedrückter Knopf + */ + private void setText(Button b){ + if (textEingabe.length()<250) { + textEingabe += b.getText(); + tfrein.setText(textEingabe); + } } -// /** -// * Setzt die Anzeige des entsprechende Gui-Element auf die entsprechende Walze -// * -// * @param walze => gibt die Walzennummer an (entspricht -// * @param position => gibt die Position der Walze (entspricht -// */ -// public void setzeWalze(int walze, int position){ -// switch (position){ -// case 1: -// // mBtnWalzPos1.setText(); -// break; -// case 2: -// break; -// case 3: -// break; -// } -// -// -// } + /** + * Setzt die Anzeige des entsprechende Gui-Element auf die entsprechende Walze + * ->d.h. welche Walze sitzt auf welcher Position + * + * @param walze => gibt die Walzennummer an (entspricht + * @param position => gibt die Position der Walze (entspricht + */ + public void setzeWalze(int walze, int position){ + switch (position){ + case 1: + mBtnWalzPos1.setText(str[position]); + break; + case 2: + mBtnWalzPos2.setText(str[position]); + break; + case 3: + mBtnWalzPos3.setText(str[position]); + break; + default: + break; + } + } + + /** + * Setzt den Notch (position)=> die Mitnahmeposition der Walze (walze) fest + * Mitnahmeposition meint => die nächste Walze wird bei erreichen dieser Position (notch) + * um eine Stelle versetzt + * + * @param walze => gibt die walze an + * @param position => gibt den notch der Walze (walze) an + */ + public void setzeRing(int walze, int position){ + switch (walze){ + case 1: + mBtnNotchPos1.setText(num[position]); + break; + case 2: + mBtnNotchPos2.setText(num[position]); + break; + case 3: + mBtnNotchPos3.setText(num[position]); + break; + default: + break; + } + } + + /** + * Setzt die Startposition/ aktuelle Position der Walze + * @param walze => gibt die walze an + * @param buchstabe gibt den Startwert bzw die aktuelle Position der Walze (walze) an + */ + public void setzePosition(int walze, char buchstabe){ + switch (walze){ + case 1: + mBtnStartPos1.setText(String.valueOf(buchstabe)); + break; + case 2: + mBtnStartPos2.setText(buchstabe+""); + break; + case 3: + mBtnStartPos3.setText(buchstabe+""); + break; + default: + break; + } + } + + /** + * Setzt den aktuellen TagesSchluessel + * @param tagesSchluessel + */ + public void setzeTagesSchluessel(String tagesSchluessel){ + //TODO Benötige TestString aus der DB Codebuch + } } + + + + diff --git a/src/main/resources/Enigma/gui.fxml b/src/main/resources/Enigma/gui.fxml index b5232e4..71d5c9a 100644 --- a/src/main/resources/Enigma/gui.fxml +++ b/src/main/resources/Enigma/gui.fxml @@ -9,16 +9,16 @@ <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="677.0" prefWidth="967.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Enigma.GuiController"> <children> - <TextField layoutX="104.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="104.0" /> - <TextField layoutX="184.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="184.0" /> - <TextField layoutX="263.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="263.0" /> - <TextField layoutX="343.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="343.0" /> - <TextField layoutX="416.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="416.0" /> - <TextField layoutX="496.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="496.0" /> - <TextField layoutX="576.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="576.0" /> - <TextField layoutX="656.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="656.0" /> - <TextField layoutX="736.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="736.0" /> - <TextField layoutX="816.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="816.0" /> + <TextField fx:id="tfStecker1" layoutX="104.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="104.0" /> + <TextField fx:id="tfStecker2" layoutX="184.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="184.0" /> + <TextField fx:id="tfStecker3" layoutX="263.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="263.0" /> + <TextField fx:id="tfStecker4" layoutX="343.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="343.0" /> + <TextField fx:id="tfStecker5" layoutX="416.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="416.0" /> + <TextField fx:id="tfStecker6" layoutX="496.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="496.0" /> + <TextField fx:id="tfStecker7" layoutX="576.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="576.0" /> + <TextField fx:id="tfStecker8" layoutX="656.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="656.0" /> + <TextField fx:id="tfStecker9" layoutX="736.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="736.0" /> + <TextField fx:id="tfStecker10" layoutX="816.0" layoutY="631.0" prefHeight="25.0" prefWidth="48.0" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="816.0" /> <ButtonBar layoutX="-39.0" layoutY="571.0" prefHeight="36.0" prefWidth="860.0"> <buttons> <Button fx:id="btnP" mnemonicParsing="false" onAction="#gedrueckteTaste" text="P" /> @@ -46,7 +46,7 @@ </ButtonBar> <ButtonBar layoutX="22.0" layoutY="491.0" prefHeight="25.0" prefWidth="583.0"> <buttons> - <Button fx:id="btnQ" minWidth="13.0" mnemonicParsing="false" onAction="#gedrueckteTasteQ" prefHeight="25.0" text="Q" /> + <Button fx:id="btnQ" minWidth="13.0" mnemonicParsing="false" onAction="#gedrueckteTaste" prefHeight="25.0" text="Q" /> <Button fx:id="btnW" mnemonicParsing="false" onAction="#gedrueckteTaste" text="W" /> <Button fx:id="btnE" mnemonicParsing="false" onAction="#gedrueckteTaste" text="E" /> <Button fx:id="btnR" mnemonicParsing="false" onAction="#gedrueckteTaste" text="R" /> @@ -58,11 +58,11 @@ <Button fx:id="btnLöschen" mnemonicParsing="false" text="Löschen" /> </buttons> </ButtonBar> - <MenuButton fx:id="mBtnWalzPos1" layoutX="91.0" layoutY="76.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="40.0" text="I" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="80.0"> + <MenuButton fx:id="mBtnWalzPos1" alignment="CENTER_RIGHT" contentDisplay="CENTER" layoutX="91.0" layoutY="76.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="I" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="80.0"> </MenuButton> - <MenuButton fx:id="mBtnWalzPos3" layoutX="201.0" layoutY="56.0" mnemonicParsing="false" text="I" AnchorPane.leftAnchor="182.0" AnchorPane.topAnchor="80.0"> + <MenuButton fx:id="mBtnWalzPos3" alignment="CENTER_RIGHT" layoutX="208.0" layoutY="80.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="I" textAlignment="CENTER" AnchorPane.leftAnchor="210.0" AnchorPane.topAnchor="80.0"> </MenuButton> - <MenuButton fx:id="mBtnWalzPos2" layoutX="136.0" layoutY="76.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="40.0" text="I" AnchorPane.leftAnchor="136.0" AnchorPane.topAnchor="80.0"> + <MenuButton fx:id="mBtnWalzPos2" alignment="CENTER_RIGHT" layoutX="152.0" layoutY="80.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="I" textAlignment="CENTER" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="80.0"> </MenuButton> <!-- <MenuButton layoutX="93.0" layoutY="114.0" mnemonicParsing="false">--> <!-- <items>--> @@ -94,26 +94,24 @@ <!-- <MenuItem mnemonicParsing="false" onAction="#z26" text="26" />--> <!-- </items>--> <!-- </MenuButton>--> - <MenuButton fx:id="mBtnNotchPos3" layoutX="211.0" layoutY="97.0" mnemonicParsing="false" text="1" AnchorPane.leftAnchor="182.0" AnchorPane.topAnchor="120.0"> + <MenuButton fx:id="mBtnNotchPos3" alignment="CENTER_RIGHT" layoutX="208.0" layoutY="120.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="1" textAlignment="CENTER" AnchorPane.leftAnchor="210.0" AnchorPane.topAnchor="120.0"> </MenuButton> - <MenuButton fx:id="mBtnNotchPos2" layoutX="136.0" layoutY="114.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="39.0" text="1" AnchorPane.leftAnchor="136.0" AnchorPane.topAnchor="120.0"> + <MenuButton fx:id="mBtnNotchPos2" alignment="CENTER_RIGHT" layoutX="152.0" layoutY="120.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="1" textAlignment="CENTER" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="120.0"> </MenuButton> - <MenuButton fx:id="mBtnStartPos1" layoutX="95.0" layoutY="157.0" mnemonicParsing="false" text="A" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="160.0"> + <MenuButton fx:id="mBtnStartPos1" alignment="CENTER_RIGHT" layoutX="95.0" layoutY="157.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="A" textAlignment="CENTER" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="160.0"> </MenuButton> - <MenuButton fx:id="mBtnStartPos3" layoutX="181.0" layoutY="156.0" mnemonicParsing="false" text="A" AnchorPane.leftAnchor="182.0" AnchorPane.topAnchor="160.0"> + <MenuButton fx:id="mBtnStartPos3" alignment="CENTER_RIGHT" layoutX="208.0" layoutY="160.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="A" textAlignment="CENTER" AnchorPane.leftAnchor="210.0" AnchorPane.topAnchor="160.0"> </MenuButton> - <MenuButton fx:id="mBtnStartPos2" layoutX="137.0" layoutY="157.0" mnemonicParsing="false" text="A" AnchorPane.leftAnchor="136.0" AnchorPane.topAnchor="160.0"> + <MenuButton fx:id="mBtnStartPos2" alignment="CENTER_RIGHT" layoutX="152.0" layoutY="160.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="A" textAlignment="CENTER" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="160.0"> </MenuButton> - <TextField fx:id="tfrein" editable="false" layoutX="246.0" layoutY="76.0" prefHeight="77.0" prefWidth="410.0" /> - <TextField fx:id="tfcodiert" editable="false" layoutX="248.0" layoutY="182.0" prefHeight="77.0" prefWidth="410.0" /> - <Button layoutX="717.0" layoutY="221.0" mnemonicParsing="false" onAction="#btnsenden" prefHeight="69.0" prefWidth="164.0" text="An Funker senden" /> - <Button layoutX="717.0" layoutY="135.0" mnemonicParsing="false" onAction="#btnempfangen" prefHeight="69.0" prefWidth="164.0" text="Funkspruch empfangen" /> - <TextField fx:id="tfKenngruppe" layoutX="725.0" layoutY="76.0" /> - <Label layoutX="727.0" layoutY="51.0" prefHeight="17.0" prefWidth="149.0" text="Kenngruppe" /> - <MenuButton fx:id="mBtnNotchPos1" layoutX="93.0" layoutY="114.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="40.0" text="1" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="120.0" /> - <Label layoutX="29.0" layoutY="80.0" text="Walze" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="80.0" /> - <Label layoutX="29.0" layoutY="127.0" text="Ringe" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="120.0" /> - <Label layoutX="11.0" layoutY="161.0" text="Startposition" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="160.0" /> + <TextField fx:id="tfrein" editable="false" layoutX="279.0" layoutY="76.0" prefHeight="77.0" prefWidth="410.0" /> + <TextField fx:id="tfcodiert" editable="false" layoutX="279.0" layoutY="183.0" prefHeight="77.0" prefWidth="410.0" /> + <Button layoutX="726.0" layoutY="187.0" mnemonicParsing="false" onAction="#btnsenden" prefHeight="69.0" prefWidth="164.0" text="An Funker senden" /> + <Button layoutX="726.0" layoutY="80.0" mnemonicParsing="false" onAction="#btnempfangen" prefHeight="69.0" prefWidth="164.0" text="Funkspruch empfangen" /> + <MenuButton fx:id="mBtnNotchPos1" alignment="CENTER_RIGHT" layoutX="93.0" layoutY="114.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="48.0" text="1" textAlignment="CENTER" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="120.0" /> + <Label layoutX="29.0" layoutY="80.0" text="Walze" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="84.0" /> + <Label layoutX="29.0" layoutY="127.0" text="Ringe" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="124.0" /> + <Label layoutX="17.0" layoutY="164.0" text="Startposition" AnchorPane.leftAnchor="17.0" AnchorPane.topAnchor="164.0" /> <Label layoutX="380.0" layoutY="27.0" prefHeight="17.0" prefWidth="172.0" text="Tageseinstellungen" /> <ButtonBar layoutX="-15.0" layoutY="408.0" prefHeight="36.0" prefWidth="860.0"> <buttons> -- GitLab