aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/HelloApplication.java
blob: 9fada8b22817321654ed0e6b6591d02ad70b8f6e (plain)
  1. // SPDX-FileCopyrightText: <Alexander Marthin Klemensen stud-marthin@ruc.dk>
  2. // SPDX-FileCopyrightText: <Ian Valentin Christensen stud-ianc@ruc.dk>
  3. // SPDX-FileCopyrightText: <Zahed Noos zahed@ruc.dk>
  4. package com.example.portfolio2;
  5. import javafx.application.Application;
  6. import javafx.scene.Scene;
  7. import javafx.scene.control.ComboBox;
  8. import javafx.scene.control.Label;
  9. import javafx.scene.control.TextArea;
  10. import javafx.scene.layout.HBox;
  11. import javafx.scene.layout.VBox;
  12. import javafx.stage.Stage;
  13. import java.io.IOException;
  14. import java.util.List;
  15. public class HelloApplication extends Application {
  16. // Initializing model, controller and database objects
  17. private Model model = new Model();
  18. private Controller con = new Controller(model,this);
  19. MyDB myDB = new MyDB();
  20. /* Below is the original implementation of the UI elements with
  21. accompanying, individual calls to setOnAction to specify functionality.
  22. Before changing to a list format,
  23. we made sure methods in controller and model
  24. were generalized to allow for the new structure seamlessly.
  25. private ComboBox<String> programCombo = new ComboBox<>();
  26. private ComboBox<String> subject1Combo = new ComboBox<>();
  27. private ComboBox<String> subject2Combo = new ComboBox<>();
  28. private ComboBox<String> electiveCombo = new ComboBox<>();
  29. private ComboBox<String> programSelect = new ComboBox<>();
  30. private ComboBox<String> subject1Select = new ComboBox<>();
  31. private ComboBox<String> subject2Select = new ComboBox<>();
  32. private ComboBox<String> electiveSelect = new ComboBox<>();
  33. private TextArea programArea = new TextArea();
  34. private TextArea subject1Area = new TextArea();
  35. private TextArea subject2Area = new TextArea();
  36. private TextArea electiveArea = new TextArea();
  37. private Label programEcts = new Label();
  38. private Label subject1Ects = new Label();
  39. private Label subject2Ects = new Label();
  40. private Label electiveEcts = new Label();
  41. private VBox program = new VBox(new Label("Program"), programCombo, programSelect, programArea, programEcts);
  42. private VBox subject1 = new VBox(new Label("Subject 1"), subject1Combo, subject1Select, subject1Area, subject1Ects);
  43. private VBox subject2 = new VBox(new Label("Subject 2"), subject2Combo, subject2Select, subject2Area, subject2Ects);
  44. private VBox elective = new VBox(new Label("Elective"), electiveCombo, electiveSelect, electiveArea, electiveEcts);
  45. */
  46. @Override
  47. public void start(Stage stage) throws IOException {
  48. // Clears old insertions into the participation table
  49. con.initialize();
  50. // Defines a list of columns based on their names.
  51. List<ActivityColumn> columns = List.of(
  52. new ActivityColumn("Program"),
  53. new ActivityColumn("Subject 1"),
  54. new ActivityColumn("Subject 2"),
  55. new ActivityColumn("Elective")
  56. );
  57. // Defines a list of subject modules
  58. List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
  59. // Loop for defining button funtionality for each activity column
  60. for (ActivityColumn col : columns) {
  61. col.nameLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px;"); // Styling
  62. col.ectsLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px");
  63. col.categoryCombo.setPrefSize(250, 35);
  64. col.activitySelect.setPrefSize(250, 35);
  65. col.area.setPrefWidth(250);
  66. // All boxes share the same activity logic
  67. col.activitySelect.setOnAction(event -> {
  68. con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
  69. con.updateEcts(col.ectsLabel, col.categoryCombo);
  70. });
  71. switch (col.name) { // Switch statement handles different category boxes
  72. case "Program" -> {
  73. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  74. col.categoryCombo.setOnAction(event -> {
  75. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  76. });
  77. }
  78. case "Subject 1" -> { // We considered using the list for filling the box but couldn't figure it out
  79. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  80. col.categoryCombo.setOnAction(event -> {
  81. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  82. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  83. });
  84. }
  85. case "Subject 2" -> {
  86. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  87. col.categoryCombo.setOnAction(event -> { // We figured we have to specify
  88. // the second column like this but reckon there's a better way.
  89. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  90. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  91. });
  92. }
  93. case "Elective" -> {
  94. col.categoryCombo.setVisible(false); // Hide useless box
  95. con.fillElective(col.activitySelect);
  96. }
  97. }
  98. }
  99. // Define an HBox based on the columns and define the scene based on it.
  100. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  101. Scene scene = new Scene(root, 1000, 500);
  102. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  103. stage.setScene(scene);
  104. stage.show();
  105. }
  106. public static void main(String[] args) {
  107. launch();
  108. }
  109. // Class for each column of activities
  110. private class ActivityColumn {
  111. // Each column contains these elements
  112. String name;
  113. Label nameLabel;
  114. ComboBox<String> categoryCombo;
  115. ComboBox<String> activitySelect;
  116. TextArea area;
  117. Label ectsLabel;
  118. ActivityColumn(String name) {
  119. this.name = name;
  120. nameLabel = new Label(name);
  121. categoryCombo = new ComboBox<>();
  122. activitySelect = new ComboBox<>();
  123. area = new TextArea();
  124. ectsLabel = new Label();
  125. // new column, "this.name" to define and saved in the text felt,
  126. // new "nameLabel" to show visual text.
  127. // CategoryCombo creat a dropdown list
  128. // activitySelect creat one more dropdown list with Combobox, possible to choose activity.
  129. // area = new TextArea helps create a text felt to describe the chosen activity
  130. // ectsLabel = new Label shows text for ects points
  131. }
  132. VBox asVBox() {
  133. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  134. }
  135. }
  136. }