| @@ -5,10 +5,18 @@ package de.uniluebeck.mi.projmi6.controller; | |||||
| */ | */ | ||||
| import de.uniluebeck.mi.projmi6.Main; | import de.uniluebeck.mi.projmi6.Main; | ||||
| import javafx.beans.binding.Bindings; | |||||
| import javafx.fxml.FXML; | import javafx.fxml.FXML; | ||||
| import javafx.scene.control.Alert; | import javafx.scene.control.Alert; | ||||
| import javafx.scene.control.Button; | import javafx.scene.control.Button; | ||||
| import javafx.scene.control.TextField; | import javafx.scene.control.TextField; | ||||
| import javafx.scene.control.TextFormatter; | |||||
| import java.net.Inet4Address; | |||||
| import java.net.Inet6Address; | |||||
| import java.net.InetAddress; | |||||
| import java.net.UnknownHostException; | |||||
| import java.util.regex.Pattern; | |||||
| public class SettingsController { | public class SettingsController { | ||||
| @@ -19,12 +27,35 @@ public class SettingsController { | |||||
| } | } | ||||
| @FXML | |||||
| private Button opsServerSave; | |||||
| @FXML | |||||
| private TextField opsServerIp, opsServerPort; | |||||
| @FXML | |||||
| private void initialize(){ | private void initialize(){ | ||||
| opsServerIp.setText(Main.OPS_IP); | opsServerIp.setText(Main.OPS_IP); | ||||
| opsServerPort.setText(Integer.toString(Main.OPS_PORT)); | opsServerPort.setText(Integer.toString(Main.OPS_PORT)); | ||||
| opsServerSave.setOnAction(event -> { | |||||
| if(validateData(opsServerIp.getText(), opsServerPort.getText())){ | |||||
| Main.OPS_IP = opsServerIp.getText(); | |||||
| Main.OPS_PORT = Integer.parseInt(opsServerPort.getText()); | |||||
| } | |||||
| Alert alert = new Alert(Alert.AlertType.CONFIRMATION); | |||||
| alert.setTitle("Speichern erfolgreich"); | |||||
| alert.setHeaderText("Die OPS-Server-Daten wurden erfolgreich ge\u00e4ndert!"); | |||||
| alert.setContentText(null); | |||||
| alert.showAndWait(); | |||||
| } | |||||
| }); | |||||
| } | |||||
| private void showMessage(String title, String message) { | private void showMessage(String title, String message) { | ||||
| Alert alert = new Alert(Alert.AlertType.INFORMATION); | Alert alert = new Alert(Alert.AlertType.INFORMATION); | ||||
| alert.setTitle("Ung\u00fcltige Daten!"); | alert.setTitle("Ung\u00fcltige Daten!"); | ||||
| @@ -33,33 +64,37 @@ public class SettingsController { | |||||
| alert.showAndWait(); | alert.showAndWait(); | ||||
| } | } | ||||
| private boolean validateData(String server, String portStr){ | private boolean validateData(String server, String portStr){ | ||||
| int port = -1; | int port = -1; | ||||
| try{ | try{ | ||||
| port = Integer.parseInt(portStr); | port = Integer.parseInt(portStr); | ||||
| }catch (Exception e){ | }catch (Exception e){ | ||||
| showMessage("Portnummer ist nicht valide", "Die Portnummer muss eine Zahl zwischen 1024 und 65535 sein!"); | |||||
| showMessage("Portnummer ist nicht valide!", "Die Portnummer muss eine Zahl zwischen 1024 und 65535 sein!"); | |||||
| return false; | return false; | ||||
| } | } | ||||
| if(!(port >= 1024 && port <= 65535)){ | if(!(port >= 1024 && port <= 65535)){ | ||||
| showMessage("Portnummer ist nicht valide", "Die Portnummer muss eine Zahl zwischen 1024 und 65535 sein!"); | |||||
| showMessage("Portnummer ist nicht valide!", "Die Portnummer muss eine Zahl zwischen 1024 und 65535 sein!"); | |||||
| return false; | |||||
| } | |||||
| if(!validate(server)){ | |||||
| showMessage("IP-Adresse nicht valide!", "Die IP-Adresse ist nicht g\u00fcltig!"); | |||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | |||||
| return true; | |||||
| } | } | ||||
| @FXML | |||||
| private Button opsServerSave; | |||||
| @FXML | |||||
| private TextField opsServerIp; | |||||
| @FXML | |||||
| private TextField opsServerPort; | |||||
| private static final Pattern PATTERN = Pattern.compile( | |||||
| "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + | |||||
| "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + | |||||
| "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + | |||||
| "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); | |||||
| public static boolean validate(final String ip) { | |||||
| return PATTERN.matcher(ip).matches(); | |||||
| } | |||||
| } | } | ||||