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