Skip to content
Snippets Groups Projects
Commit 65b831e8 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Merge branch 'master' into 'master'

GuiController aufgeräumt => Regions zur besseren Übersicht

See merge request !66
parents 479a7839 d5b8a62c
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ import java.util.ArrayList; ...@@ -12,6 +12,7 @@ import java.util.ArrayList;
public class GuiController { public class GuiController {
//region Klassenvariablen
private final static String[] walzenNr = {"I", "II", "III", "IV", "V"}; 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 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 String[] 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 final static String[] 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"};
...@@ -20,7 +21,7 @@ public class GuiController { ...@@ -20,7 +21,7 @@ public class GuiController {
private String textCodiert; private String textCodiert;
private boolean resetDisplay; private boolean resetDisplay;
private Codierer codierer; private Codierer codierer;
//endregion
//region GUI-Elemente //region GUI-Elemente
@FXML @FXML
...@@ -46,10 +47,9 @@ public class GuiController { ...@@ -46,10 +47,9 @@ public class GuiController {
@FXML @FXML
private MenuButton mBtnWalzPos1, mBtnWalzPos2, mBtnWalzPos3, mBtnNotchPos1, mBtnNotchPos2, mBtnNotchPos3, private MenuButton mBtnWalzPos1, mBtnWalzPos2, mBtnWalzPos3, mBtnNotchPos1, mBtnNotchPos2, mBtnNotchPos3,
mBtnStartPos1, mBtnStartPos2, mBtnStartPos3; mBtnStartPos1, mBtnStartPos2, mBtnStartPos3;
//endregion //endregion
//region Init
@FXML @FXML
void initialize() { void initialize() {
...@@ -113,6 +113,109 @@ public class GuiController { ...@@ -113,6 +113,109 @@ public class GuiController {
this.setzeSteckverbindungen(); this.setzeSteckverbindungen();
} }
/**
* init Methode zur Erstellung der Einträge und Action Listener für die einzelnen Menüs
*
* @param button : Button für die die Einträge erstellt werden sollen
*/
private void menu(MenuButton button, String[] str) {
mItem = new ArrayList<>();
for (int i = 0; i < str.length; i++) {
//Eintrag aus str der Arraylist mi hinzufügen
mItem.add(new MenuItem(str[i]));
//MenuItem mi dem Button button hinzufügen
button.getItems().add(mItem.get(i));
int finalI = i;
//Listener für die einzelnen Einträge
ArrayList<MenuItem> finalMi = mItem;
mItem.get(i).setOnAction(e -> setMenuBtnText(button, finalMi.get(finalI)));
}
}
//endregion
//region EventHandler/Listener
/**
* //TODO DOKU
*/
private void leuchten(Button taste, Circle leuchte) {
taste.setOnMousePressed(mouseEvent -> leuchte.setStyle("-fx-fill: #FFA500"));
taste.setOnMouseReleased(mouseEvent -> {
leuchte.setStyle("-fx-background-color: " + taste.getBackground());
leuchte.setStyle("-fx-border-color: #000000");
});
}
/**
* Auswertung welcher Button gedrückt wurde
*
* @param e => ActionEvent des auslösenden Button
*/
@FXML
private void gedrueckteTaste(ActionEvent e) {
//TODO Anbindung an Klasse Hardware
if (e.getSource() == btnA) {
setText(btnA);
//leuchten();
}
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);
if (e.getSource() == btnSenden) sendeFunkspruch();
if (e.getSource() == btnEmpfangen) empfangeFunkspruch();
if (e.getSource() == btnDelete) loeschen();
}
//endregion
//region Methoden
/**
* Methode zum setzen des menuButton Textes auf das ausgewählte MenuItem
*
* @param mBtn : MenuButton der Walze
* @param mItm : MenuItem
*/
private void setMenuBtnText(MenuButton mBtn, MenuItem mItm) {
// mb.setText(mi.getText());
if (mBtn.getId().equals(mBtnStartPos1.getId())) setzePosition(1, mItm.getText().charAt(0));
if (mBtn.getId().equals(mBtnStartPos2.getId())) setzePosition(2, mItm.getText().charAt(0));
if (mBtn.getId().equals(mBtnStartPos3.getId())) setzePosition(3, mItm.getText().charAt(0));
if (mBtn.getId().equals(mBtnWalzPos1.getId())) setzeWalze(1, mItm.getText());
if (mBtn.getId().equals(mBtnWalzPos2.getId())) setzeWalze(2, mItm.getText());
if (mBtn.getId().equals(mBtnWalzPos3.getId())) setzeWalze(3, mItm.getText());
if (mBtn.getId().equals(mBtnNotchPos1.getId()))
setzeRing(1, Integer.parseInt(mItm.getText()) - 1);
if (mBtn.getId().equals(mBtnNotchPos2.getId()))
setzeRing(2, Integer.parseInt(mItm.getText()) - 1);
if (mBtn.getId().equals(mBtnNotchPos3.getId()))
setzeRing(3, Integer.parseInt(mItm.getText()) - 1);
}
/** /**
* Hier werden die TextFelder, welche die Steckverbindungen darstellen, * Hier werden die TextFelder, welche die Steckverbindungen darstellen,
* mit dem Werten die die Klasse Codierer zur Verfügung stellt gefüllt. * mit dem Werten die die Klasse Codierer zur Verfügung stellt gefüllt.
...@@ -134,7 +237,6 @@ public class GuiController { ...@@ -134,7 +237,6 @@ public class GuiController {
* Die Löschen Funktion löscht das letzte Zeichen im Klartext sowie im Codiert Feld, * Die Löschen Funktion löscht das letzte Zeichen im Klartext sowie im Codiert Feld,
* der Codierer wird aufgerufen um ebenfalls das letzte Zeichen zu löschen * der Codierer wird aufgerufen um ebenfalls das letzte Zeichen zu löschen
*/ */
@FXML
private void loeschen() { private void loeschen() {
if (textEingabe.length() == 0) { if (textEingabe.length() == 0) {
tfKlartext.setText(""); tfKlartext.setText("");
...@@ -151,7 +253,9 @@ public class GuiController { ...@@ -151,7 +253,9 @@ public class GuiController {
} }
} }
@FXML /**
* //TODO DOKU
*/
void empfangeFunkspruch() { void empfangeFunkspruch() {
String[] empfangeneNachricht = this.codierer.empfangeNachricht(); String[] empfangeneNachricht = this.codierer.empfangeNachricht();
if (empfangeneNachricht[0] != null) { if (empfangeneNachricht[0] != null) {
...@@ -166,7 +270,9 @@ public class GuiController { ...@@ -166,7 +270,9 @@ public class GuiController {
} }
} }
@FXML /**
* //TODO DOKU
*/
private void sendeFunkspruch() { private void sendeFunkspruch() {
this.tfKlartext.setText(""); this.tfKlartext.setText("");
this.tfCodiert.setText(""); this.tfCodiert.setText("");
...@@ -179,97 +285,12 @@ public class GuiController { ...@@ -179,97 +285,12 @@ public class GuiController {
} }
/**
* Methode zum setzen des menuButton Textes auf das ausgewählte MenuItem
*
* @param mb : MenuButton der Walze
* @param mi : MenuItem
*/
private void listener(MenuButton mb, MenuItem mi) {
// mb.setText(mi.getText());
if (mb.getId().equals(mBtnStartPos1.getId())) setzePosition(1, mi.getText().charAt(0));
if (mb.getId().equals(mBtnStartPos2.getId())) setzePosition(2, mi.getText().charAt(0));
if (mb.getId().equals(mBtnStartPos3.getId())) setzePosition(3, mi.getText().charAt(0));
if (mb.getId().equals(mBtnWalzPos1.getId())) setzeWalze(1, mi.getText());
if (mb.getId().equals(mBtnWalzPos2.getId())) setzeWalze(2, mi.getText());
if (mb.getId().equals(mBtnWalzPos3.getId())) setzeWalze(3, mi.getText());
if (mb.getId().equals(mBtnNotchPos1.getId()))
setzeRing(1, Integer.parseInt(mi.getText()) - 1);
if (mb.getId().equals(mBtnNotchPos2.getId()))
setzeRing(2, Integer.parseInt(mi.getText()) - 1);
if (mb.getId().equals(mBtnNotchPos3.getId()))
setzeRing(3, Integer.parseInt(mi.getText()) - 1);
}
/**
* Methode zur Erstellung der Einträge und Action Listener für die einzelnen Menüs
*
* @param button : Button für die die Einträge erstellt werden sollen
*/
private void menu(MenuButton button, String[] str) {
mItem = new ArrayList<>();
for (int i = 0; i < str.length; i++) {
//Eintrag aus str der Arraylist mi hinzufügen
mItem.add(new MenuItem(str[i]));
//MenuItem mi dem Button button hinzufügen
button.getItems().add(mItem.get(i));
int finalI = i;
//Listener für die einzelnen Einträge
ArrayList<MenuItem> finalMi = mItem;
mItem.get(i).setOnAction(e -> listener(button, finalMi.get(finalI)));
}
}
/**
* Auswertung welcher Button gedrückt wurde
*
* @param e => ActionEvent des auslösenden Button
*/
@FXML
private void gedrueckteTaste(ActionEvent e) {
//TODO Anbindung an Klasse Hardware
if (e.getSource() == btnA){
setText(btnA);
//leuchten();
}
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);
if (e.getSource() == btnSenden) sendeFunkspruch();
if (e.getSource() == btnEmpfangen) empfangeFunkspruch();
if (e.getSource() == btnDelete) loeschen();
}
/** /**
* schreibt Buchstaben des gedrückten Knopfes in Textfeld tfrein * schreibt Buchstaben des gedrückten Knopfes in Textfeld tfrein
* *
* @param b : gedrückter Knopf * @param pressedButton : gedrückter Knopf
*/ */
private void setText(Button b) { private void setText(Button pressedButton) {
if (textEingabe.length() < 250) { if (textEingabe.length() < 250) {
if (this.resetDisplay) { if (this.resetDisplay) {
this.tfCodiert.setText(""); this.tfCodiert.setText("");
...@@ -283,8 +304,8 @@ public class GuiController { ...@@ -283,8 +304,8 @@ public class GuiController {
// Spruchschluessel in das Feld lblSpruchschluessel schreiben // Spruchschluessel in das Feld lblSpruchschluessel schreiben
lblSpruchschluessel.setText(this.codierer.getSpruchschluessel()); lblSpruchschluessel.setText(this.codierer.getSpruchschluessel());
} }
textEingabe += b.getText(); textEingabe += pressedButton.getText();
textCodiert += this.codierer.codiere(b.getText().charAt(0), true); textCodiert += this.codierer.codiere(pressedButton.getText().charAt(0), true);
tfKlartext.setText(textEingabe); tfKlartext.setText(textEingabe);
tfCodiert.setText(textCodiert); tfCodiert.setText(textCodiert);
...@@ -296,15 +317,6 @@ public class GuiController { ...@@ -296,15 +317,6 @@ public class GuiController {
} }
} }
private void leuchten(Button taste, Circle leuchte) {
taste.setOnMousePressed(mouseEvent -> leuchte.setStyle("-fx-fill: #FFA500"));
taste.setOnMouseReleased(mouseEvent -> {
leuchte.setStyle("-fx-background-color: " + taste.getBackground());
leuchte.setStyle("-fx-border-color: #000000");
});
}
/** /**
* Setzt die Anzeige des entsprechende Gui-Element auf die entsprechende Walze * Setzt die Anzeige des entsprechende Gui-Element auf die entsprechende Walze
* ->d.h. welche Walze sitzt auf welcher Position * ->d.h. welche Walze sitzt auf welcher Position
...@@ -341,7 +353,6 @@ public class GuiController { ...@@ -341,7 +353,6 @@ public class GuiController {
break; break;
case 2: case 2:
mBtnWalzPos2.setText(walzenNr[walzeNr]); mBtnWalzPos2.setText(walzenNr[walzeNr]);
break; break;
case 3: case 3:
mBtnWalzPos3.setText(walzenNr[walzeNr]); mBtnWalzPos3.setText(walzenNr[walzeNr]);
...@@ -436,4 +447,5 @@ public class GuiController { ...@@ -436,4 +447,5 @@ public class GuiController {
tfStecker10.setText(this.codierer.getSteckverbindungen()[9][0] + "" + tfStecker10.setText(this.codierer.getSteckverbindungen()[9][0] + "" +
this.codierer.getSteckverbindungen()[9][1]); this.codierer.getSteckverbindungen()[9][1]);
} }
//endregion
} }
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
<Font name="System Bold" size="18.0" /> <Font name="System Bold" size="18.0" />
</font> </font>
</Button> </Button>
<Button fx:id="btnDelete" minHeight="44.0" mnemonicParsing="false" onAction="#loeschen" prefHeight="48.0" prefWidth="51.0" style="-fx-background-radius: 100; -fx-background-color: #0d0d0d;" text="&lt;" textFill="#fffdfd" GridPane.columnIndex="10" GridPane.rowIndex="5"> <Button fx:id="btnDelete" minHeight="44.0" mnemonicParsing="false" onAction="#gedrueckteTaste" prefHeight="48.0" prefWidth="51.0" style="-fx-background-radius: 100; -fx-background-color: #0d0d0d;" text="&lt;" textFill="#fffdfd" GridPane.columnIndex="10" GridPane.rowIndex="5">
<font> <font>
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
...@@ -604,9 +604,9 @@ ...@@ -604,9 +604,9 @@
</GridPane> </GridPane>
<FlowPane layoutX="736.0" layoutY="51.0" prefHeight="173.0" prefWidth="195.0" AnchorPane.rightAnchor="36.0" AnchorPane.topAnchor="51.0"> <FlowPane layoutX="736.0" layoutY="51.0" prefHeight="173.0" prefWidth="195.0" AnchorPane.rightAnchor="36.0" AnchorPane.topAnchor="51.0">
<children> <children>
<Button fx:id="btnEmpfangen" mnemonicParsing="false" onAction="#empfangeFunkspruch" prefHeight="80.0" prefWidth="195.0" text="Funkspruch empfangen" /> <Button fx:id="btnEmpfangen" mnemonicParsing="false" onAction="#gedrueckteTaste" prefHeight="80.0" prefWidth="195.0" text="Funkspruch empfangen" />
<Label prefHeight="17.0" prefWidth="195.0" /> <Label prefHeight="17.0" prefWidth="195.0" />
<Button fx:id="btnSenden" mnemonicParsing="false" onAction="#sendeFunkspruch" prefHeight="80.0" prefWidth="195.0" text="An Funker senden" /> <Button fx:id="btnSenden" mnemonicParsing="false" onAction="#gedrueckteTaste" prefHeight="80.0" prefWidth="195.0" text="An Funker senden" />
</children> </children>
</FlowPane> </FlowPane>
<GridPane layoutX="23.0" layoutY="222.0" prefHeight="60.0" prefWidth="270.0" AnchorPane.leftAnchor="23.0" AnchorPane.topAnchor="222.0"> <GridPane layoutX="23.0" layoutY="222.0" prefHeight="60.0" prefWidth="270.0" AnchorPane.leftAnchor="23.0" AnchorPane.topAnchor="222.0">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment