Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.4 KiB

  1. package com.ugsbo.matrixcalc;
  2. import javafx.fxml.FXML;
  3. import javafx.scene.control.*;
  4. import javafx.scene.text.Text;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. public class MatrixCalcController {
  8. // Hier werden die fx:id Attribute verknuepft.
  9. @FXML
  10. private Button multiplyButton, addButton, swapInputButton, substractButton, transposeButton;
  11. @FXML
  12. private Text errorText, outputText;
  13. @FXML
  14. private TextArea matrixATextArea, matrixBTextArea;
  15. /**
  16. * Konstructor is called before initialize()
  17. */
  18. public MatrixCalcController() {
  19. // Setup of some Fields could be defined here.
  20. }
  21. /**
  22. * Initializes the controller class. This method is automatically called after
  23. * the fxml file has been loaded.
  24. */
  25. @FXML
  26. public void initialize() {
  27. multiplyButton.setOnMouseClicked((event) -> {
  28. String matrixA = matrixATextArea.getText();
  29. String matrixB = matrixBTextArea.getText();
  30. if (checkInput(matrixA)) {
  31. // TODO matrixATextArea and matrixBTextArea need to be parsed to double[][] do
  32. // this in an extern Methode maybe an extern class.
  33. // MatrixCalcMath math = new MatrixCalcMath();
  34. // math.matrixMultiplication(matrixATextArea, matrixATextArea);
  35. }
  36. // System.out.println(matrixATextArea.getText());
  37. });
  38. }
  39. /**
  40. * Chcks if the Input is Valid, with Regex. Returns true if the Matrix can be
  41. * matched by the regular Expression.
  42. *
  43. * @param matrix It is the InputMatrix
  44. * @return true if the Matrix is valid Input.
  45. */
  46. public boolean checkInput(String matrix) {
  47. boolean isMatched = false;
  48. if (matrix.length() == 0) {
  49. throw new IllegalArgumentException("Please insert a Matrix");
  50. }
  51. // Matches digits witch following spaces 1 to 3 times
  52. String row1 = "(\\d*\\u0020*){1,3}";
  53. // Matches newlineCurrierReturn followed by digits witch following spaces 1 to
  54. // 3times
  55. String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}";
  56. String row3 = "(\\n){0,3}(\\d*\\u0020*){0,3}";
  57. // TODO get the input check more stricktly missing matrix slots are allowed.
  58. Pattern p = Pattern.compile(row1 + row2 + row3);
  59. Matcher m = p.matcher(matrix);
  60. isMatched = m.matches();
  61. // System.out.println(isMatched);
  62. return isMatched;
  63. }
  64. }