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