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

Merge branch 'master' into 'master'

Fehler Klasse eingebaut, some fixes

See merge request !94
parents 6c9bb328 ba930d8f
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import projekt.enigma.model.Codierer;
import projekt.enigma.model.Fehler;
import java.io.IOException;
......@@ -20,61 +20,89 @@ import java.io.IOException;
*/
public class App extends Application {
private static String kenngruppe;
private static GuiController gc;
private static int debug;
private static Fehler fehler;
Scene sce1, sce2;
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
Parent result = fxmlLoader.load();
if (fxml.equals("gui")) {
gc = fxmlLoader.getController();
gc.setKenngruppe(kenngruppe);
}
return result;
}
public static void main(String[] args) {
fehler = new Fehler();
launch(args);
}
public static int getDebug() {
return debug;
}
public static void setDebug(int debug) {
App.debug = debug;
}
public static Fehler getFehler() {
return fehler;
}
@Override
public void start(Stage primaryStage) throws IOException {
Codierer cod = new Codierer();
primaryStage.setTitle("Kenngruppenabfrage");
//Scene 1
Label label1= new Label("Bitte Kenngruppe eingeben!");
label1.setTranslateX(55);
Label l1=new Label("");
Label l2 = new Label("");
TextField tfield=new TextField();
Button button1= new Button("Kenngruppe setzen!");
VBox layout1 = new VBox();
// kc.btnGui(primaryStage, sce2);
button1.setOnAction(e -> {
if (tfield.getText().length() < 9) {
for (char c : tfield.getText().toCharArray()) {
if (c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' || c == 'g' || c == 'h' || c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || c == 'o' || c == 'p' || c == 'q' || c == 'r' || c == 's' || c == 't' || c == 'u' || c == 'v' || c == 'w' || c == 'x' || c == 'y' || c == 'z' || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' || c == 'G' || c == 'H' || c == 'I' || c == 'J' || c == 'K' || c == 'L' || c == 'M' || c == 'N' || c == 'O' || c == 'P' || c == 'Q' || c == 'R' || c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || c == 'Y' || c == 'Z') {
cod.setKenngruppe(tfield.getText());
primaryStage.setScene(sce2);
}
public void start(Stage primaryStage) throws IOException {
primaryStage.setTitle("Kenngruppenabfrage");
//Scene 1
Label label1 = new Label("Bitte Kenngruppe eingeben!");
label1.setTranslateX(55);
Label l1 = new Label("");
Label l2 = new Label("");
TextField tfield = new TextField();
Button button1 = new Button("Kenngruppe setzen!");
VBox layout1 = new VBox();
button1.setOnAction(e -> {
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean error = false;
for (char c : tfield.getText().toUpperCase().toCharArray()) {
if (!alphabet.contains(String.valueOf(c))) {
error = true;
break;
}
}else{
}
if (tfield.getText().length() < 9 && !error) {
kenngruppe = tfield.getText();
try {
primaryStage.setScene(new Scene(loadFXML("gui"), 962, 677));
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
tfield.setStyle("-fx-background-color:#FF0000");
tfield.setText("Fehlerhafte Kenngruppe!");
}
});
layout1.getChildren().addAll(label1,l1,tfield,l2,button1);
//sce1= new Scene(loadFXML("kenngruppe"), 300, 250);
sce1=new Scene(layout1,234,137);
});
sce2 = new Scene(loadFXML("gui"), 962, 677);
layout1.getChildren().addAll(label1, l1, tfield, l2, button1);
primaryStage.setScene(sce1);
primaryStage.show();
}
sce1 = new Scene(layout1, 234, 137);
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
primaryStage.setScene(sce1);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
// /**
// * TODO Dokumentieren
// */
......
......@@ -55,7 +55,6 @@ public class GuiController {
//endregion
//region Init
/**
* Initialisiert die Elemente GUI und setzt deren Startwerte
*/
......@@ -81,15 +80,6 @@ public class GuiController {
menu(mBtnStartPos1, position);
menu(mBtnStartPos3, position);
menu(mBtnStartPos2, position);
// Initialisieren des Codierers und setzen der Kenngruppe
codierer = new Codierer();
// Beim nächsten Tastendruck erstmal das Display löschen damit falschen Nachrichten geschickt werden.
resetDisplay = true;
// Einstellungen aus dem Logbuch auslesen und setzen
setzeTagesSchluessel();
setzeSteckverbindungen();
}
/**
......@@ -110,9 +100,7 @@ public class GuiController {
mItem.get(i).setOnAction(e -> setMenuBtnText(button, finalMi.get(finalI)));
}
}
//endregion
//endregion
//region EventHandler/Listener
......@@ -287,11 +275,9 @@ public class GuiController {
this.setzeTagesSchluessel();
}
}
//endregion
//endregion
//region Methoden
/**
* Setzt die Hintergrundfarbe des Kreises (chiffrierter Buchstabe) auf gelb bzw. auf grau.
*
......@@ -445,8 +431,6 @@ public class GuiController {
// Spruchschluessel in das Feld lblSpruchschluessel schreiben
lblSpruchschluessel.setText(codierer.empfangenerSpruchschluessel(empfangeneNachricht[2]));
}
}
......@@ -647,14 +631,17 @@ public class GuiController {
mBtnNotchPos1.setText(String.valueOf(codierer.fetchRingstellung()[0]));
mBtnNotchPos2.setText(String.valueOf(codierer.fetchRingstellung()[1]));
mBtnNotchPos3.setText(String.valueOf(codierer.fetchRingstellung()[2]));
// Walzennummern anzeigen
setzeWalze(1, codierer.fetchWalzenNr()[0]);
setzeWalze(2, codierer.fetchWalzenNr()[1]);
setzeWalze(3, codierer.fetchWalzenNr()[2]);
// Position der Walzen anzeigen
mBtnStartPos1.setText(String.valueOf(codierer.fetchWalzen()[0]));
mBtnStartPos2.setText(String.valueOf(codierer.fetchWalzen()[1]));
mBtnStartPos3.setText(String.valueOf(codierer.fetchWalzen()[2]));
// Steckbrett Felder setzen
tfStecker1.setText(codierer.fetchSteckverbindungen()[0][0] + "" +
codierer.fetchSteckverbindungen()[0][1]);
......@@ -683,5 +670,20 @@ public class GuiController {
}
private enum BUCHSTABE_LEUCHTET {AN, AUS}
public void setKenngruppe(String kenngruppe) {
// Initialisieren des Codierers und setzen der Kenngruppe
codierer = new Codierer(kenngruppe);
this.codierer.resetHardware();
// Beim nächsten Tastendruck erstmal das Display löschen damit falschen Nachrichten geschickt werden.
resetDisplay = true;
// Einstellungen aus dem Logbuch auslesen und setzen
setzeTagesSchluessel();
setzeSteckverbindungen();
}
//endregion
}
package projekt.enigma;
import java.io.IOException;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import projekt.enigma.model.Codierer;
public class KenngruppeController {
private Codierer cod = new Codierer();
@FXML
private TextField tfKenngruppe;
//TODO: Doku
/**
* Beim drücken der Taste wird überprüft ob die eingegebene Kenngruppe weniger als 9 Zeichen hat und ob die
* eingegebenen Zeichen nur Buchstaben sind.
* Bei einer gültigen Eingabe wird die eingegebene Kenngruppe gespeichert und die Enigma-Anwendung gestartet
*
* @throws IOException :
*/
@FXML
private void btnGui() throws IOException {
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean error = false;
for (char c : tfKenngruppe.getText().toUpperCase().toCharArray()) {
if (!alphabet.contains(String.valueOf(c))) {
error = true;
}
}
if (tfKenngruppe.getText().length() < 9 && !error) {
cod.setKenngruppe(tfKenngruppe.getText().toUpperCase());
//setzt
// App.setRoot("gui");
} else {
tfKenngruppe.setStyle("-fx-background-color:#FF0000");
tfKenngruppe.setText("Fehlerhafte Kenngruppe!");
}
}
}
......@@ -9,10 +9,6 @@ import java.sql.SQLException;
public class Main {
public static void main(String[] args) throws SQLException {
Thread app = new Thread(new ThreadApp());
Thread funk = new Thread(new ThreadFunkraum());
app.start();
funk.start();
App.main(args);
}
}
This diff is collapsed.
package projekt.enigma.model;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import projekt.enigma.App;
/**
* In dieser Klasse werden Fehler behandelt und an den User/Admin/Entwickler ausgegeben
*/
public class Fehler {
private String functionPrefix = "- ";
private String messagePrefix = "--> ";
/**
* Zeige Fehler Dialog
*
* @param type : String : Art der Meldung (warning/information/error)
* @param subject : Titel des Dialoges
* @param message : Nachricht der Meldung
*/
public void showErrorDialog(String type, String subject, String message) {
new Fehler().debug(this.getClass().getName() + "." + new Throwable().getStackTrace()[0].getMethodName(), true);
Alert alert;
/* Der Titel darf auch als leerer String übergeben werden, dann wird ein Default gesetzt */
if (subject.equals("")) {
subject = "Es ist ein Fehler aufgetreten";
}
/* Welcher Fehler Typ wurde übergeben? */
switch (type) {
case "warning":
alert = new Alert(AlertType.WARNING);
break;
case "information":
alert = new Alert(AlertType.INFORMATION);
break;
case "error":
alert = new Alert(AlertType.ERROR);
break;
default:
alert = new Alert(AlertType.NONE);
}
/* Setzt den Titel des Dialoges */
alert.setTitle(subject);
/* Setzt den Headertext des Dialoges */
alert.setHeaderText(null);
/* Setzt die Nachricht des Dialoges */
alert.setContentText(message);
/* Zeige den Dialog an */
alert.showAndWait();
}
public void debug(String message, boolean isFunction) {
if (App.getDebug() != 0) {
if (isFunction) {
System.out.println(functionPrefix + message);
} else {
System.out.println(messagePrefix + message);
}
}
}
public void debug(String message, boolean isFunction, int debugLevel) {
if (App.getDebug() != 0 && (App.getDebug() >= debugLevel || App.getDebug() == 3) ) {
if (isFunction) {
System.out.println(functionPrefix + message);
} else {
System.out.println(messagePrefix + message);
}
}
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import projekt.enigma.App;
import java.io.BufferedReader;
import java.io.IOException;
......@@ -63,10 +64,11 @@ public class Funkraum {
}
}
} catch (UnsupportedEncodingException e) {
System.out.println("Encoding wird nicht unterstützt.");
App.getFehler().showErrorDialog("error", "Fehler", "Encoding wird nicht unterstützt.");
} catch (IOException e) {
System.out.println("HTTP Post war nicht erfolgreich.\nBitte wenden Sie sich an ihren Vorgesetzten.");
e.printStackTrace();
App.getFehler().showErrorDialog("error", "HTTP Post war nicht erfolgreich", "Bitte wenden Sie sich an ihren Vorgesetzten.");
} catch (NullPointerException e) {
App.getFehler().showErrorDialog("error", "Fehler", "Keine Nachrichten für diese Kenngruppe");
}
return funkspruch;
......@@ -107,7 +109,7 @@ public class Funkraum {
JSONObject result = new JSONObject(reader.readLine());
if (result.getInt("result") != 200) {
throw new HttpException("Der andere Funker mag deine Nachricht nicht. " +
"Rüge ihn wenn du ihn wieder siehst...");
"Rüge ihn wenn du ihn wieder siehst...");
}
}
}
......
......@@ -7,7 +7,11 @@ import projekt.enigma.model.Funkraum;
* Thread fuer den Funkraum, wird durch das Interface Runnable erweitert
*/
public class ThreadFunkraum implements Runnable {
String kenngruppe = new Codierer().getKenngruppe();
String kenngruppe;
public ThreadFunkraum(String kenngruppe) {
this.kenngruppe = kenngruppe;
}
/**
* Ueberschriebene Funktion - fuehrt die Klasse Funkraum aus und startet
......@@ -16,7 +20,7 @@ public class ThreadFunkraum implements Runnable {
public void run() {
Funkraum funkraum = new Funkraum();
System.out.println("Threadfunkraum" + Thread.currentThread());
funkraum.empfangeFunkspruch(kenngruppe);
funkraum.empfangeFunkspruch(this.kenngruppe);
}
}
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