summaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/HelloApplication.java
blob: e79dbdad8f1d13a708200bada69af451e61a17b6 (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 HelloApplication extends Application {
  20. /// Default constructor
  21. // (declared explicitly only to silence javadoc)
  22. public HelloApplication(){}
  23. /// Label styling
  24. public static final String LABEL_STYLE =
  25. "-fx-font-weight: bold;-fx-font-size: 18;-fx-padding: 10";
  26. /// Application model
  27. private Model model = new Model();
  28. /// Application controller
  29. private Controller con = new Controller(model,this);
  30. /// database singleton
  31. MyDB myDB = new MyDB();
  32. /* Below is the original implementation of the UI elements with
  33. accompanying, individual calls to setOnAction to specify functionality.
  34. Before changing to a list format,
  35. we made sure methods in controller and model
  36. were generalized to allow for the new structure seamlessly.
  37. private ComboBox<String> programCombo = new ComboBox<>();
  38. private ComboBox<String> subject1Combo = new ComboBox<>();
  39. private ComboBox<String> subject2Combo = new ComboBox<>();
  40. private ComboBox<String> electiveCombo = new ComboBox<>();
  41. private ComboBox<String> programSelect = new ComboBox<>();
  42. private ComboBox<String> subject1Select = new ComboBox<>();
  43. private ComboBox<String> subject2Select = new ComboBox<>();
  44. private ComboBox<String> electiveSelect = new ComboBox<>();
  45. private TextArea programArea = new TextArea();
  46. private TextArea subject1Area = new TextArea();
  47. private TextArea subject2Area = new TextArea();
  48. private TextArea electiveArea = new TextArea();
  49. private Label programEcts = new Label();
  50. private Label subject1Ects = new Label();
  51. private Label subject2Ects = new Label();
  52. private Label electiveEcts = new Label();
  53. private VBox program = new VBox(new Label("Program"), programCombo, programSelect, programArea, programEcts);
  54. private VBox subject1 = new VBox(new Label("Subject 1"), subject1Combo, subject1Select, subject1Area, subject1Ects);
  55. private VBox subject2 = new VBox(new Label("Subject 2"), subject2Combo, subject2Select, subject2Area, subject2Ects);
  56. private VBox elective = new VBox(new Label("Elective"), electiveCombo, electiveSelect, electiveArea, electiveEcts);
  57. */
  58. @Override
  59. public void start(Stage stage) throws IOException {
  60. // clear old insertions into participation table
  61. con.initialize();
  62. // define list of columns based on their names
  63. List<ActivityColumn> columns = List.of(
  64. new ActivityColumn("Program"),
  65. new ActivityColumn("Subject 1"),
  66. new ActivityColumn("Subject 2"),
  67. new ActivityColumn("Elective")
  68. );
  69. // define list of subject modules
  70. List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
  71. // define button functionality for each activity column
  72. for (ActivityColumn col : columns) {
  73. col.nameLabel.setStyle(LABEL_STYLE);
  74. col.ectsLabel.setStyle(LABEL_STYLE);
  75. col.categoryCombo.setPrefSize(250, 35);
  76. col.activitySelect.setPrefSize(250, 35);
  77. col.area.setPrefWidth(250);
  78. // all boxes share same activity logic
  79. col.activitySelect.setOnAction(event -> {
  80. con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
  81. con.updateEcts(col.ectsLabel, col.categoryCombo);
  82. });
  83. // handle each category box
  84. switch (col.name) {
  85. case "Program" -> {
  86. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  87. col.categoryCombo.setOnAction(event -> {
  88. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  89. });
  90. }
  91. // TODO: use the list for filling the box
  92. case "Subject 1" -> {
  93. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  94. col.categoryCombo.setOnAction(event -> {
  95. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  96. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  97. });
  98. }
  99. case "Subject 2" -> {
  100. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  101. // TODO: figure out a better way...
  102. col.categoryCombo.setOnAction(event -> {
  103. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  104. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  105. });
  106. }
  107. case "Elective" -> {
  108. // hide useless box
  109. col.categoryCombo.setVisible(false);
  110. con.fillElective(col.activitySelect);
  111. }
  112. }
  113. }
  114. // define HBox and scene for columns
  115. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  116. Scene scene = new Scene(root, 1000, 500);
  117. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  118. stage.setScene(scene);
  119. stage.show();
  120. }
  121. /// JVM entry point
  122. ///
  123. /// @param args command-line arguments
  124. public static void main(String[] args) {
  125. launch();
  126. }
  127. /// column of activities
  128. private class ActivityColumn {
  129. /// identifier stored in the text felt
  130. String name;
  131. /// display text
  132. Label nameLabel;
  133. /// dropdown list for categories
  134. ComboBox<String> categoryCombo;
  135. /// dropdown list for activities
  136. ComboBox<String> activitySelect;
  137. /// descriptionof chosen activities
  138. TextArea area;
  139. /// text to display ECTS points
  140. Label ectsLabel;
  141. /// column of activities
  142. ///
  143. /// @param name identifier
  144. ActivityColumn(String name) {
  145. this.name = name;
  146. nameLabel = new Label(name);
  147. categoryCombo = new ComboBox<>();
  148. activitySelect = new ComboBox<>();
  149. area = new TextArea();
  150. ectsLabel = new Label();
  151. }
  152. /// activity columne as VBox
  153. ///
  154. /// @return column of activities as VBox
  155. VBox asVBox() {
  156. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  157. }
  158. }
  159. }