aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Window.java
blob: eceb45073ed4a8ddf39b52e5513e9621025d3595 (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk>
  3. // SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk>
  4. // SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk>
  5. // SPDX-License-Identifier: GPL-3.0-or-later
  6. package com.example.portfolio2;
  7. import javafx.application.Application;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.ComboBox;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.control.TextArea;
  12. import javafx.scene.layout.HBox;
  13. import javafx.scene.layout.VBox;
  14. import javafx.stage.Stage;
  15. import java.io.IOException;
  16. import java.util.List;
  17. /// Bachelorizer - JavaFX Window view
  18. // Class is final to forbid subclassing,
  19. // because object is passed to controller during instantiation
  20. public final class Window extends Application {
  21. /// Default constructor
  22. // (declared explicitly only to silence javadoc)
  23. public Window() { }
  24. /// window width
  25. private static final int WINDOW_WIDTH = 1000;
  26. /// window height
  27. private static final int WINDOW_HEIGHT = 500;
  28. /// box width
  29. private static final int LIST_WIDTH = 250;
  30. /// box height
  31. private static final int LIST_HEIGHT = 35;
  32. /// Label styling
  33. private static final String LABEL_STYLE =
  34. "-fx-font-weight: bold;"
  35. + "-fx-font-size: 18;"
  36. + "-fx-padding: 10";
  37. /// Storage model
  38. private Database store = new Database();
  39. /// Application controller
  40. private Controller con = new Controller(store, this);
  41. @Override
  42. public void start(final Stage stage) throws IOException {
  43. // clear old insertions into participation table
  44. con.initialize();
  45. // define list of columns based on their names
  46. List<ActivityColumn> columns = List.of(
  47. new ActivityColumn("Program"),
  48. new ActivityColumn("Subject 1"),
  49. new ActivityColumn("Subject 2"),
  50. new ActivityColumn("Elective")
  51. );
  52. // define list of subject modules
  53. List<String> subjectModules = List.of(
  54. "Computer Science", "Informatik", "Astrology");
  55. // define button functionality for each activity column
  56. for (ActivityColumn col : columns) {
  57. col.nameLabel.setStyle(LABEL_STYLE);
  58. col.ectsLabel.setStyle(LABEL_STYLE);
  59. col.categoryCombo.setPrefSize(
  60. LIST_WIDTH, LIST_HEIGHT);
  61. col.activitySelect.setPrefSize(
  62. LIST_WIDTH, LIST_HEIGHT);
  63. col.area.setPrefWidth(LIST_WIDTH);
  64. // all boxes share same activity logic
  65. col.activitySelect.setOnAction(event -> {
  66. con.onActivitySelected(
  67. col.categoryCombo,
  68. col.activitySelect,
  69. col.area);
  70. con.updateEcts(
  71. col.ectsLabel,
  72. col.categoryCombo);
  73. });
  74. // handle each category box
  75. switch (col.name) {
  76. case "Program" -> {
  77. col.categoryCombo.getItems().addAll(
  78. "HumTek", "NatBach");
  79. col.categoryCombo.setOnAction(event -> {
  80. con.onCategorySelected(
  81. col.categoryCombo,
  82. col.activitySelect,
  83. col.area);
  84. });
  85. }
  86. // TODO: use the list for filling the box
  87. case "Subject 1" -> {
  88. col.categoryCombo.getItems().addAll(
  89. "Computer Science",
  90. "Informatik",
  91. "Astrology");
  92. col.categoryCombo.setOnAction(event -> {
  93. con.onSubjectModuleSelected(
  94. col.categoryCombo,
  95. columns.get(2)
  96. .categoryCombo,
  97. subjectModules);
  98. con.onCategorySelected(
  99. col.categoryCombo,
  100. col.activitySelect,
  101. col.area);
  102. });
  103. }
  104. case "Subject 2" -> {
  105. col.categoryCombo.getItems().addAll(
  106. "Computer Science",
  107. "Informatik",
  108. "Astrology");
  109. // TODO: figure out a better way...
  110. col.categoryCombo.setOnAction(event -> {
  111. con.onSubjectModuleSelected(
  112. col.categoryCombo,
  113. columns.get(1)
  114. .categoryCombo,
  115. subjectModules);
  116. con.onCategorySelected(
  117. col.categoryCombo,
  118. col.activitySelect,
  119. col.area);
  120. });
  121. }
  122. case "Elective" -> {
  123. // hide useless box
  124. col.categoryCombo.setVisible(false);
  125. con.fillElective(col.activitySelect);
  126. }
  127. }
  128. }
  129. // define HBox and scene for columns
  130. HBox root = new HBox(
  131. columns.get(0).asVBox(),
  132. columns.get(1).asVBox(),
  133. columns.get(2).asVBox(),
  134. columns.get(3).asVBox());
  135. Scene scene = new Scene(
  136. root, WINDOW_WIDTH, WINDOW_HEIGHT);
  137. stage.setTitle(
  138. "Course Selector RUC: Ultimate Deluxe Edition");
  139. stage.setScene(scene);
  140. stage.show();
  141. }
  142. /// JVM entry point
  143. ///
  144. /// @param args command-line arguments
  145. public static void main(final String[] args) {
  146. launch();
  147. }
  148. /// column of activities
  149. ///
  150. /// @param name identifier stored in the text felt
  151. /// @param nameLabel display text
  152. /// @param categoryCombo dropdown list for categories
  153. /// @param activitySelect dropdown list for activities
  154. /// @param area description of chosen activities
  155. /// @param ectsLabel text to display ECTS points
  156. private record ActivityColumn(
  157. String name,
  158. Label nameLabel,
  159. ComboBox<String> categoryCombo,
  160. ComboBox<String> activitySelect,
  161. TextArea area,
  162. Label ectsLabel
  163. ) {
  164. public ActivityColumn(String name) {
  165. this(
  166. name,
  167. new Label(name),
  168. new ComboBox<>(),
  169. new ComboBox<>(),
  170. new TextArea(),
  171. new Label()
  172. );
  173. }
  174. /// activity columne as VBox
  175. ///
  176. /// @return column of activities as VBox
  177. VBox asVBox() {
  178. return new VBox(
  179. nameLabel,
  180. categoryCombo,
  181. activitySelect,
  182. area,
  183. ectsLabel);
  184. }
  185. }
  186. }