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