aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/HelloApplication.java
blob: 3b754d4702f354b77c805195287fada73f7487f0 (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. // SPDX-License-Identifier: GPL-3.0-or-later
  5. package com.example.portfolio2;
  6. import javafx.application.Application;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.ComboBox;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.TextArea;
  11. import javafx.scene.layout.HBox;
  12. import javafx.scene.layout.VBox;
  13. import javafx.stage.Stage;
  14. import java.io.IOException;
  15. import java.util.List;
  16. /// Bachelorizer - bachelor programme registrar
  17. public class HelloApplication extends Application {
  18. /// Default constructor
  19. // (declared explicitly only to silence javadoc)
  20. public HelloApplication(){}
  21. /// Application model
  22. private Model model = new Model();
  23. /// Application controller
  24. private Controller con = new Controller(model,this);
  25. /// database singleton
  26. MyDB myDB = new MyDB();
  27. /* Below is the original implementation of the UI elements with
  28. accompanying, individual calls to setOnAction to specify functionality.
  29. Before changing to a list format,
  30. we made sure methods in controller and model
  31. were generalized to allow for the new structure seamlessly.
  32. private ComboBox<String> programCombo = new ComboBox<>();
  33. private ComboBox<String> subject1Combo = new ComboBox<>();
  34. private ComboBox<String> subject2Combo = new ComboBox<>();
  35. private ComboBox<String> electiveCombo = new ComboBox<>();
  36. private ComboBox<String> programSelect = new ComboBox<>();
  37. private ComboBox<String> subject1Select = new ComboBox<>();
  38. private ComboBox<String> subject2Select = new ComboBox<>();
  39. private ComboBox<String> electiveSelect = new ComboBox<>();
  40. private TextArea programArea = new TextArea();
  41. private TextArea subject1Area = new TextArea();
  42. private TextArea subject2Area = new TextArea();
  43. private TextArea electiveArea = new TextArea();
  44. private Label programEcts = new Label();
  45. private Label subject1Ects = new Label();
  46. private Label subject2Ects = new Label();
  47. private Label electiveEcts = new Label();
  48. private VBox program = new VBox(new Label("Program"), programCombo, programSelect, programArea, programEcts);
  49. private VBox subject1 = new VBox(new Label("Subject 1"), subject1Combo, subject1Select, subject1Area, subject1Ects);
  50. private VBox subject2 = new VBox(new Label("Subject 2"), subject2Combo, subject2Select, subject2Area, subject2Ects);
  51. private VBox elective = new VBox(new Label("Elective"), electiveCombo, electiveSelect, electiveArea, electiveEcts);
  52. */
  53. @Override
  54. public void start(Stage stage) throws IOException {
  55. // clear old insertions into participation table
  56. con.initialize();
  57. // define list of columns based on their names
  58. List<ActivityColumn> columns = List.of(
  59. new ActivityColumn("Program"),
  60. new ActivityColumn("Subject 1"),
  61. new ActivityColumn("Subject 2"),
  62. new ActivityColumn("Elective")
  63. );
  64. // define list of subject modules
  65. List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
  66. // define button functionality for each activity column
  67. for (ActivityColumn col : columns) {
  68. col.nameLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px;"); // Styling
  69. col.ectsLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px");
  70. col.categoryCombo.setPrefSize(250, 35);
  71. col.activitySelect.setPrefSize(250, 35);
  72. col.area.setPrefWidth(250);
  73. // all boxes share same activity logic
  74. col.activitySelect.setOnAction(event -> {
  75. con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
  76. con.updateEcts(col.ectsLabel, col.categoryCombo);
  77. });
  78. // handle each category box
  79. switch (col.name) {
  80. case "Program" -> {
  81. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  82. col.categoryCombo.setOnAction(event -> {
  83. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  84. });
  85. }
  86. // TODO: use the list for filling the box
  87. case "Subject 1" -> {
  88. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  89. col.categoryCombo.setOnAction(event -> {
  90. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  91. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  92. });
  93. }
  94. case "Subject 2" -> {
  95. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  96. // TODO: figure out a better way...
  97. col.categoryCombo.setOnAction(event -> {
  98. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  99. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  100. });
  101. }
  102. case "Elective" -> {
  103. // hide useless box
  104. col.categoryCombo.setVisible(false);
  105. con.fillElective(col.activitySelect);
  106. }
  107. }
  108. }
  109. // define HBox and scene for columns
  110. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  111. Scene scene = new Scene(root, 1000, 500);
  112. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  113. stage.setScene(scene);
  114. stage.show();
  115. }
  116. /// JVM entry point
  117. ///
  118. /// @param args command-line arguments
  119. public static void main(String[] args) {
  120. launch();
  121. }
  122. /// column of activities
  123. private class ActivityColumn {
  124. /// identifier stored in the text felt
  125. String name;
  126. /// display text
  127. Label nameLabel;
  128. /// dropdown list for categories
  129. ComboBox<String> categoryCombo;
  130. /// dropdown list for activities
  131. ComboBox<String> activitySelect;
  132. /// descriptionof chosen activities
  133. TextArea area;
  134. /// text to display ECTS points
  135. Label ectsLabel;
  136. /// column of activities
  137. ///
  138. /// @param name identifier
  139. ActivityColumn(String name) {
  140. this.name = name;
  141. nameLabel = new Label(name);
  142. categoryCombo = new ComboBox<>();
  143. activitySelect = new ComboBox<>();
  144. area = new TextArea();
  145. ectsLabel = new Label();
  146. }
  147. /// activity columne as VBox
  148. ///
  149. /// @return column of activities as VBox
  150. VBox asVBox() {
  151. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  152. }
  153. }
  154. }