diff --git a/src/main/java/enigma/GuiController.java b/src/main/java/enigma/GuiController.java index 377cab1a676058842f497d1ab34eb946f80dac26..452ab65d83b5a64b6f33f9c05aa803afe9fefef3 100644 --- a/src/main/java/enigma/GuiController.java +++ b/src/main/java/enigma/GuiController.java @@ -12,9 +12,9 @@ import java.util.ArrayList; 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 final static String[] walzenNr = {"I", "II", "III", "IV", "V"}; + private final static String[] ringNr = {"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 char[] position = {'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 ArrayList<MenuItem> mItem; private String textEingabe; private String textCodiert; @@ -124,10 +124,10 @@ public class GuiController { private MenuButton mBtnStartPos2; @FXML - private TextField tfrein; + private TextField tfKlartext; @FXML - private TextField tfcodiert; + private TextField tfCodiert; @FXML private MenuButton mBtnNotchPos1; @@ -327,19 +327,19 @@ public class GuiController { resetDisplay = true; //Einträge für Walzen - menu(mBtnWalzPos1, str); - menu(mBtnWalzPos2, str); - menu(mBtnWalzPos3, str); + menu(mBtnWalzPos1, walzenNr); + menu(mBtnWalzPos2, walzenNr); + menu(mBtnWalzPos3, walzenNr); //Einträge für die Ringe - menu(mBtnNotchPos1, num); - menu(mBtnNotchPos2, num); - menu(mBtnNotchPos3, num); + menu(mBtnNotchPos1, ringNr); + menu(mBtnNotchPos2, ringNr); + menu(mBtnNotchPos3, ringNr); //Einträge für die Startpositionen - menu(mBtnStartPos1, bs); - menu(mBtnStartPos3, bs); - menu(mBtnStartPos2, bs); + menu(mBtnStartPos1, position); + menu(mBtnStartPos3, position); + menu(mBtnStartPos2, position); assert tfStecker1 != null : "fx:id=\"tfStecker1\" was not injected: check your FXML file 'gui.fxml'."; assert tfStecker2 != null : "fx:id=\"tfStecker2\" was not injected: check your FXML file 'gui.fxml'."; @@ -385,8 +385,8 @@ public class GuiController { assert mBtnStartPos1 != null : "fx:id=\"mBtnStartPos1\" was not injected: check your FXML file 'gui.fxml'."; assert mBtnStartPos3 != null : "fx:id=\"mBtnStartPos3\" was not injected: check your FXML file 'gui.fxml'."; 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 tfKlartext != 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 mBtnNotchPos1 != null : "fx:id=\"mBtnNotchPos1\" was not injected: check your FXML file 'gui.fxml'."; assert lblQ != null : "fx:id=\"lblQ\" was not injected: check your FXML file 'gui.fxml'."; assert lblE != null : "fx:id=\"lblE\" was not injected: check your FXML file 'gui.fxml'."; @@ -455,7 +455,7 @@ public class GuiController { @FXML void löschen() { textEingabe = textEingabe.substring(0, textEingabe.length() - 1); - tfrein.setText(textEingabe); + tfKlartext.setText(textEingabe); //TODO: anpassen, wenn kein Text da ist } @@ -463,8 +463,8 @@ public class GuiController { void btnempfangen() { String[] empfangeneNachricht = this.codierer.empfangeNachricht(); if (empfangeneNachricht[0] != null) { - this.tfrein.setText(empfangeneNachricht[2]); - this.tfcodiert.setText(empfangeneNachricht[1]); + this.tfKlartext.setText(empfangeneNachricht[2]); + this.tfCodiert.setText(empfangeneNachricht[1]); this.resetDisplay = true; mBtnStartPos1.setText(String.valueOf(this.codierer.getWalzen()[0])); @@ -475,8 +475,8 @@ public class GuiController { @FXML void btnsenden() { - this.tfrein.setText(""); - this.tfcodiert.setText(""); + this.tfKlartext.setText(""); + this.tfCodiert.setText(""); try { this.codierer.sendeNachricht(); @@ -493,7 +493,18 @@ public class GuiController { * @param mi : MenuItem */ private void listener(MenuButton mb, MenuItem mi) { - mb.setText(mi.getText()); + // mb.setText(mi.getText()); + + if(mb.getId()==mBtnStartPos1.getId())setzePosition(1,mi.getText().charAt(0)); + if(mb.getId()==mBtnStartPos2.getId())setzePosition(2,mi.getText().charAt(0)); + if(mb.getId()==mBtnStartPos3.getId())setzePosition(3,mi.getText().charAt(0)); + if(mb.getId()==mBtnWalzPos1.getId())setzeWalze(1,mi.getText().charAt(0)); + if(mb.getId()==mBtnWalzPos2.getId())setzeWalze(2,mi.getText().charAt(0)); + if(mb.getId()==mBtnWalzPos3.getId())setzeWalze(3,mi.getText().charAt(0)); + if(mb.getId()==mBtnNotchPos1.getId())setzeRing(1,mi.getText().charAt(0)); + if(mb.getId()==mBtnNotchPos2.getId())setzeRing(2,mi.getText().charAt(0)); + if(mb.getId()==mBtnNotchPos3.getId())setzeRing(3,mi.getText().charAt(0)); + } /** @@ -562,8 +573,8 @@ public class GuiController { private void setText(Button b) { if (textEingabe.length() < 250) { if(this.resetDisplay) { - this.tfcodiert.setText(""); - this.tfrein.setText(""); + this.tfCodiert.setText(""); + this.tfKlartext.setText(""); this.resetDisplay = false; this.codierer.resetHardware(); textCodiert = ""; @@ -574,8 +585,8 @@ public class GuiController { textEingabe += b.getText(); textCodiert += this.codierer.codiere(b.getText().charAt(0), true); - tfrein.setText(textEingabe); - tfcodiert.setText(textCodiert); + tfKlartext.setText(textEingabe); + tfCodiert.setText(textCodiert); mBtnStartPos1.setText(String.valueOf(this.codierer.getWalzen()[0])); mBtnStartPos2.setText(String.valueOf(this.codierer.getWalzen()[1])); @@ -599,19 +610,21 @@ public class GuiController { * 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 + * @param walzeNr => gibt die Walzennummer an (entspricht + * @param walzenPosition => gibt die Position der Walze (entspricht */ - public void setzeWalze(int walze, int position) { - switch (position) { + public void setzeWalze(int walzenPosition, int walzeNr) { + switch (walzenPosition) { case 1: - mBtnWalzPos1.setText(str[position]); + mBtnWalzPos1.setText(walzenNr[walzeNr]); + //codierer.setWalze(walzeNr, walzenPosition) break; case 2: - mBtnWalzPos2.setText(str[position]); + mBtnWalzPos2.setText(walzenNr[walzeNr]); + break; case 3: - mBtnWalzPos3.setText(str[position]); + mBtnWalzPos3.setText(walzenNr[walzeNr]); break; default: break; @@ -623,19 +636,19 @@ public class GuiController { * 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 + * @param walzeNr => gibt die walze an + * @param walzenPosition => gibt den notch der Walze (walze) an */ - public void setzeRing(int walze, int position) { - switch (walze) { + public void setzeRing(int walzenPosition, int walzeNr) { + switch (walzeNr) { case 1: - mBtnNotchPos1.setText(num[position]); + mBtnNotchPos1.setText(ringNr[walzenPosition]); break; case 2: - mBtnNotchPos2.setText(num[position]); + mBtnNotchPos2.setText(ringNr[walzenPosition]); break; case 3: - mBtnNotchPos3.setText(num[position]); + mBtnNotchPos3.setText(ringNr[walzenPosition]); break; default: break; @@ -645,11 +658,11 @@ public class GuiController { /** * Setzt die Startposition/ aktuelle Position der Walze * - * @param walze => gibt die walze an + * @param walzenPosition => 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) { + public void setzePosition(int walzenPosition, char buchstabe) { + switch (walzenPosition) { case 1: mBtnStartPos1.setText(String.valueOf(buchstabe)); break;