aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/HelloApplication.java
blob: 1fa5a623a5cf6662b93af78101d5fbedb83fff80 (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. public class HelloApplication extends Application {
  17. // Initializing model, controller and database objects
  18. private Model model = new Model();
  19. private Controller con = new Controller(model,this);
  20. MyDB myDB = new MyDB();
  21. /* Below is the original implementation of the UI elements with
  22. accompanying, individual calls to setOnAction to specify functionality.
  23. Before changing to a list format,
  24. we made sure methods in controller and model
  25. were generalized to allow for the new structure seamlessly.
  26. private ComboBox<String> programCombo = new ComboBox<>();
  27. private ComboBox<String> subject1Combo = new ComboBox<>();
  28. private ComboBox<String> subject2Combo = new ComboBox<>();
  29. private ComboBox<String> electiveCombo = new ComboBox<>();
  30. private ComboBox<String> programSelect = new ComboBox<>();
  31. private ComboBox<String> subject1Select = new ComboBox<>();
  32. private ComboBox<String> subject2Select = new ComboBox<>();
  33. private ComboBox<String> electiveSelect = new ComboBox<>();
  34. private TextArea programArea = new TextArea();
  35. private TextArea subject1Area = new TextArea();
  36. private TextArea subject2Area = new TextArea();
  37. private TextArea electiveArea = new TextArea();
  38. private Label programEcts = new Label();
  39. private Label subject1Ects = new Label();
  40. private Label subject2Ects = new Label();
  41. private Label electiveEcts = new Label();
  42. private VBox program = new VBox(new Label("Program"), programCombo, programSelect, programArea, programEcts);
  43. private VBox subject1 = new VBox(new Label("Subject 1"), subject1Combo, subject1Select, subject1Area, subject1Ects);
  44. private VBox subject2 = new VBox(new Label("Subject 2"), subject2Combo, subject2Select, subject2Area, subject2Ects);
  45. private VBox elective = new VBox(new Label("Elective"), electiveCombo, electiveSelect, electiveArea, electiveEcts);
  46. */
  47. @Override
  48. public void start(Stage stage) throws IOException {
  49. // Clears old insertions into the participation table
  50. con.initialize();
  51. // Defines a list of columns based on their names.
  52. List<ActivityColumn> columns = List.of(
  53. new ActivityColumn("Program"),
  54. new ActivityColumn("Subject 1"),
  55. new ActivityColumn("Subject 2"),
  56. new ActivityColumn("Elective")
  57. );
  58. // Defines a list of subject modules
  59. List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
  60. // Loop for defining button funtionality for each activity column
  61. for (ActivityColumn col : columns) {
  62. col.nameLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px;"); // Styling
  63. col.ectsLabel.setStyle("-fx-font-size: 18px; -fx-padding: 10px");
  64. col.categoryCombo.setPrefSize(250, 35);
  65. col.activitySelect.setPrefSize(250, 35);
  66. col.area.setPrefWidth(250);
  67. // All boxes share the same activity logic
  68. col.activitySelect.setOnAction(event -> {
  69. con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
  70. con.updateEcts(col.ectsLabel, col.categoryCombo);
  71. });
  72. // Switch statement handles different category boxes
  73. switch (col.name) {
  74. case "Program" -> {
  75. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  76. col.categoryCombo.setOnAction(event -> {
  77. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  78. });
  79. }
  80. // We considered using the list for filling the box but couldn't figure it out
  81. case "Subject 1" -> {
  82. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  83. col.categoryCombo.setOnAction(event -> {
  84. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  85. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  86. });
  87. }
  88. case "Subject 2" -> {
  89. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  90. // We figured we have to specify
  91. // the second column like this but reckon there's a better way.
  92. col.categoryCombo.setOnAction(event -> {
  93. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  94. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  95. });
  96. }
  97. case "Elective" -> {
  98. // Hide useless box
  99. col.categoryCombo.setVisible(false);
  100. con.fillElective(col.activitySelect);
  101. }
  102. }
  103. }
  104. // Define an HBox based on the columns and define the scene based on it.
  105. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  106. Scene scene = new Scene(root, 1000, 500);
  107. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  108. stage.setScene(scene);
  109. stage.show();
  110. }
  111. public static void main(String[] args) {
  112. launch();
  113. }
  114. // Class for each column of activities
  115. private class ActivityColumn {
  116. // Each column contains these elements
  117. String name;
  118. Label nameLabel;
  119. ComboBox<String> categoryCombo;
  120. ComboBox<String> activitySelect;
  121. TextArea area;
  122. Label ectsLabel;
  123. ActivityColumn(String name) {
  124. this.name = name;
  125. nameLabel = new Label(name);
  126. categoryCombo = new ComboBox<>();
  127. activitySelect = new ComboBox<>();
  128. area = new TextArea();
  129. ectsLabel = new Label();
  130. // new column, "this.name" to define and saved in the text felt,
  131. // new "nameLabel" to show visual text.
  132. // CategoryCombo creat a dropdown list
  133. // activitySelect creat one more dropdown list with Combobox, possible to choose activity.
  134. // area = new TextArea helps create a text felt to describe the chosen activity
  135. // ectsLabel = new Label shows text for ects points
  136. }
  137. VBox asVBox() {
  138. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  139. }
  140. }
  141. }