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