aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Window.java
blob: fa8d2f9a63fe0315f07f2a97f1b90d78f797ccb5 (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 button functionality for each activity column
  53. for (ActivityColumn col : columns) {
  54. col.nameLabel.setStyle(LABEL_STYLE);
  55. col.ectsLabel.setStyle(LABEL_STYLE);
  56. col.categoryCombo.setPrefSize(
  57. LIST_WIDTH, LIST_HEIGHT);
  58. col.activitySelect.setPrefSize(
  59. LIST_WIDTH, LIST_HEIGHT);
  60. col.area.setPrefWidth(LIST_WIDTH);
  61. // all boxes share same activity logic
  62. col.activitySelect.setOnAction(event -> {
  63. con.onActivitySelected(
  64. col.categoryCombo,
  65. col.activitySelect,
  66. col.area);
  67. con.updateEcts(
  68. col.ectsLabel,
  69. col.categoryCombo);
  70. });
  71. // handle each category box
  72. switch (col.name) {
  73. case "Program" -> {
  74. col.categoryCombo.getItems().addAll(
  75. "HumTek", "NatBach");
  76. col.categoryCombo.setOnAction(event -> {
  77. con.onCategorySelected(
  78. col.categoryCombo,
  79. col.activitySelect,
  80. col.area);
  81. });
  82. }
  83. // TODO: use the list for filling the box
  84. case "Subject 1" -> {
  85. col.categoryCombo.getItems().addAll(
  86. "Computer Science",
  87. "Informatik",
  88. "Astrology");
  89. col.categoryCombo.setOnAction(event -> {
  90. con.onSubjectModuleSelected(
  91. col.categoryCombo,
  92. columns.get(2)
  93. .categoryCombo);
  94. con.onCategorySelected(
  95. col.categoryCombo,
  96. col.activitySelect,
  97. col.area);
  98. });
  99. }
  100. case "Subject 2" -> {
  101. col.categoryCombo.getItems().addAll(
  102. "Computer Science",
  103. "Informatik",
  104. "Astrology");
  105. // TODO: figure out a better way...
  106. col.categoryCombo.setOnAction(event -> {
  107. con.onSubjectModuleSelected(
  108. col.categoryCombo,
  109. columns.get(1)
  110. .categoryCombo);
  111. con.onCategorySelected(
  112. col.categoryCombo,
  113. col.activitySelect,
  114. col.area);
  115. });
  116. }
  117. case "Elective" -> {
  118. // hide useless box
  119. col.categoryCombo.setVisible(false);
  120. con.fillElective(col.activitySelect);
  121. }
  122. }
  123. }
  124. // define HBox and scene for columns
  125. HBox root = new HBox(
  126. columns.get(0).asVBox(),
  127. columns.get(1).asVBox(),
  128. columns.get(2).asVBox(),
  129. columns.get(3).asVBox());
  130. Scene scene = new Scene(
  131. root, WINDOW_WIDTH, WINDOW_HEIGHT);
  132. stage.setTitle(
  133. "Course Selector RUC: Ultimate Deluxe Edition");
  134. stage.setScene(scene);
  135. stage.show();
  136. }
  137. /// JVM entry point
  138. ///
  139. /// @param args command-line arguments
  140. public static void main(final String[] args) {
  141. launch();
  142. }
  143. /// column of activities
  144. ///
  145. /// @param name identifier stored in the text felt
  146. /// @param nameLabel display text
  147. /// @param categoryCombo dropdown list for categories
  148. /// @param activitySelect dropdown list for activities
  149. /// @param area description of chosen activities
  150. /// @param ectsLabel text to display ECTS points
  151. private record ActivityColumn(
  152. String name,
  153. Label nameLabel,
  154. ComboBox<String> categoryCombo,
  155. ComboBox<String> activitySelect,
  156. TextArea area,
  157. Label ectsLabel
  158. ) {
  159. /// column of activities
  160. ///
  161. /// @param name identifier
  162. public ActivityColumn(String name) {
  163. this(
  164. name,
  165. new Label(name),
  166. new ComboBox<>(),
  167. new ComboBox<>(),
  168. new TextArea(),
  169. new Label()
  170. );
  171. }
  172. /// activity columne as VBox
  173. ///
  174. /// @return column of activities as VBox
  175. VBox asVBox() {
  176. return new VBox(
  177. nameLabel,
  178. categoryCombo,
  179. activitySelect,
  180. area,
  181. ectsLabel);
  182. }
  183. }
  184. }