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