aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Window.java
blob: 6977d6be0e45fad60007194df97cf879fa4b6f36 (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;-fx-font-size: 18;-fx-padding: 10";
  34. /// Storage model
  35. private Database store = new Database();
  36. /// Application controller
  37. private Controller con = new Controller(store,this);
  38. @Override
  39. public void start(final Stage stage) throws IOException {
  40. // clear old insertions into participation table
  41. con.initialize();
  42. // define list of columns based on their names
  43. List<ActivityColumn> columns = List.of(
  44. new ActivityColumn("Program"),
  45. new ActivityColumn("Subject 1"),
  46. new ActivityColumn("Subject 2"),
  47. new ActivityColumn("Elective")
  48. );
  49. // define list of subject modules
  50. List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
  51. // define button functionality for each activity column
  52. for (ActivityColumn col : columns) {
  53. col.nameLabel.setStyle(LABEL_STYLE);
  54. col.ectsLabel.setStyle(LABEL_STYLE);
  55. col.categoryCombo.setPrefSize(LIST_WIDTH, LIST_HEIGHT);
  56. col.activitySelect.setPrefSize(LIST_WIDTH, LIST_HEIGHT);
  57. col.area.setPrefWidth(LIST_WIDTH);
  58. // all boxes share same activity logic
  59. col.activitySelect.setOnAction(event -> {
  60. con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
  61. con.updateEcts(col.ectsLabel, col.categoryCombo);
  62. });
  63. // handle each category box
  64. switch (col.name) {
  65. case "Program" -> {
  66. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  67. col.categoryCombo.setOnAction(event -> {
  68. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  69. });
  70. }
  71. // TODO: use the list for filling the box
  72. case "Subject 1" -> {
  73. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  74. col.categoryCombo.setOnAction(event -> {
  75. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  76. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  77. });
  78. }
  79. case "Subject 2" -> {
  80. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  81. // TODO: figure out a better way...
  82. col.categoryCombo.setOnAction(event -> {
  83. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  84. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  85. });
  86. }
  87. case "Elective" -> {
  88. // hide useless box
  89. col.categoryCombo.setVisible(false);
  90. con.fillElective(col.activitySelect);
  91. }
  92. }
  93. }
  94. // define HBox and scene for columns
  95. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  96. Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT);
  97. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  98. stage.setScene(scene);
  99. stage.show();
  100. }
  101. /// JVM entry point
  102. ///
  103. /// @param args command-line arguments
  104. public static void main(final String[] args) {
  105. launch();
  106. }
  107. /// column of activities
  108. private class ActivityColumn {
  109. /// identifier stored in the text felt
  110. String name;
  111. /// display text
  112. Label nameLabel;
  113. /// dropdown list for categories
  114. ComboBox<String> categoryCombo;
  115. /// dropdown list for activities
  116. ComboBox<String> activitySelect;
  117. /// descriptionof chosen activities
  118. TextArea area;
  119. /// text to display ECTS points
  120. Label ectsLabel;
  121. /// column of activities
  122. ///
  123. /// @param name identifier
  124. ActivityColumn(final String name) {
  125. this.name = name;
  126. nameLabel = new Label(name);
  127. categoryCombo = new ComboBox<>();
  128. activitySelect = new ComboBox<>();
  129. area = new TextArea();
  130. ectsLabel = new Label();
  131. }
  132. /// activity columne as VBox
  133. ///
  134. /// @return column of activities as VBox
  135. VBox asVBox() {
  136. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  137. }
  138. }
  139. }