aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/HelloApplication.java
blob: 1a793004cc92710bf26e4e45d85273157a316244 (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 (col.name) { // Switch statement handles different category boxes
  73. case "Program" -> {
  74. col.categoryCombo.getItems().addAll("HumTek", "NatBach");
  75. col.categoryCombo.setOnAction(event -> {
  76. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  77. });
  78. }
  79. case "Subject 1" -> { // We considered using the list for filling the box but couldn't figure it out
  80. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  81. col.categoryCombo.setOnAction(event -> {
  82. con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
  83. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  84. });
  85. }
  86. case "Subject 2" -> {
  87. col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
  88. col.categoryCombo.setOnAction(event -> { // We figured we have to specify
  89. // the second column like this but reckon there's a better way.
  90. con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
  91. con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
  92. });
  93. }
  94. case "Elective" -> {
  95. col.categoryCombo.setVisible(false); // Hide useless box
  96. con.fillElective(col.activitySelect);
  97. }
  98. }
  99. }
  100. // Define an HBox based on the columns and define the scene based on it.
  101. HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
  102. Scene scene = new Scene(root, 1000, 500);
  103. stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
  104. stage.setScene(scene);
  105. stage.show();
  106. }
  107. public static void main(String[] args) {
  108. launch();
  109. }
  110. // Class for each column of activities
  111. private class ActivityColumn {
  112. // Each column contains these elements
  113. String name;
  114. Label nameLabel;
  115. ComboBox<String> categoryCombo;
  116. ComboBox<String> activitySelect;
  117. TextArea area;
  118. Label ectsLabel;
  119. ActivityColumn(String name) {
  120. this.name = name;
  121. nameLabel = new Label(name);
  122. categoryCombo = new ComboBox<>();
  123. activitySelect = new ComboBox<>();
  124. area = new TextArea();
  125. ectsLabel = new Label();
  126. // new column, "this.name" to define and saved in the text felt,
  127. // new "nameLabel" to show visual text.
  128. // CategoryCombo creat a dropdown list
  129. // activitySelect creat one more dropdown list with Combobox, possible to choose activity.
  130. // area = new TextArea helps create a text felt to describe the chosen activity
  131. // ectsLabel = new Label shows text for ects points
  132. }
  133. VBox asVBox() {
  134. return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
  135. }
  136. }
  137. }