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.

68 lines
2.2 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. public boolean checkInput(String matrix) {
  40. boolean isMatched = false;
  41. if (matrix.length() == 0) {
  42. throw new IllegalArgumentException("Please insert a Matrix");
  43. }
  44. // Matches digits witch following spaces 1 to 3 times
  45. String row1 = "(\\d*\\u0020*){1,3}";
  46. // Matches newlineCurrierReturn followed by digits witch following spaces 1 to
  47. // 3times
  48. String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}";
  49. String row3 = "(\\n){0,3}(\\d*\\u0020*){0,3}";
  50. // TODO get the input check more stricktly missing matrix slots are allowed.
  51. Pattern p = Pattern.compile(row1 + row2 + row3);
  52. Matcher m = p.matcher(matrix);
  53. isMatched = m.matches();
  54. // System.out.println(isMatched);
  55. return isMatched;
  56. }
  57. }