aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: 154cf42de24ef1de244277622697d46354a57311 (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk>
  3. // SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk>
  4. // SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk>
  5. // SPDX-License-Identifier: GPL-3.0-or-later
  6. package com.example.portfolio2;
  7. import javafx.scene.control.ComboBox;
  8. import javafx.scene.control.Label;
  9. import javafx.scene.control.TextArea;
  10. import java.util.List;
  11. /// Bachelorizer - Controller
  12. class Controller {
  13. /// Storage model
  14. private Database store;
  15. /// UI model
  16. private UI ui;
  17. /// Application view
  18. private Window view;
  19. /// clear the participation database at program launch
  20. void initialize() {
  21. store.initialize();
  22. }
  23. /// default constructor
  24. ///
  25. /// @param store Storage model
  26. /// @param ui UI model
  27. /// @param view Application view
  28. Controller(final Database store, UI ui, final Window view) {
  29. this.store = store;
  30. this.ui = ui;
  31. this.view = view;
  32. }
  33. /// callback when category has been selected
  34. ///
  35. /// @param category selected category
  36. /// @param select activity selection object
  37. /// @param area activity listing object
  38. void onCategorySelected(
  39. final String category,
  40. final ComboBox<String> select,
  41. final TextArea area
  42. ) {
  43. // clear the activity selection box
  44. select.getItems().clear();
  45. // clear text area
  46. area.clear();
  47. // fill activity box from data in store
  48. select.getItems().addAll(store.selectProgram(category));
  49. }
  50. /// callback when activity has been selected
  51. ///
  52. /// @param combo involved activity box
  53. /// @param select selected item
  54. /// @param area whole text area
  55. void onActivitySelected(
  56. final ComboBox<String> combo,
  57. final ComboBox<String> select,
  58. final TextArea area
  59. ) {
  60. // pass the value chosen in the box
  61. addActivity(select.getValue(), area);
  62. // update text area based on category choice
  63. //
  64. // Users can choose from the ComboBox,
  65. // and string (activity) and the area will then update.
  66. updateArea(combo, area);
  67. }
  68. /// callback when subject module has been selected
  69. ///
  70. /// @param subject1 involved 1st column subject module box
  71. /// @param subject2 involved 2nd column subject module box
  72. void onSubjectModuleSelected(
  73. final ComboBox<String> subject1,
  74. final ComboBox<String> subject2
  75. ) {
  76. // remove chosen option from opposite subject module box
  77. for (String sub: store.getAllModules()) {
  78. if (sub.equals(subject1.getValue())) {
  79. subject2.getItems().remove(
  80. subject1.getValue());
  81. } else if (
  82. !sub.equals(subject1.getValue())
  83. && !subject2.getItems().contains(sub)
  84. ) {
  85. subject2.getItems().add(sub);
  86. }
  87. }
  88. }
  89. /// add participation to database
  90. /// @param s activity identifier
  91. /// @param textArea whole text area
  92. void addActivity(final String s, final TextArea textArea) {
  93. store.addParticipation(store.getActivityIndeks(s));
  94. }
  95. /// update text area for an activity box
  96. ///
  97. /// Clears the text area
  98. /// and adds all activity names from activities in participation.
  99. ///
  100. /// @param combo involved activity box
  101. /// @param textArea whole text area
  102. void updateArea(
  103. final ComboBox<String> combo, final TextArea textArea
  104. ) {
  105. textArea.clear();
  106. for (String s: store.getParticipation(combo.getValue())
  107. ) {
  108. textArea.appendText(s + "\n");
  109. }
  110. }
  111. /// update label with current ECTS of program type
  112. /// @param ectslabel text display area for ECTS points
  113. /// @param comboBox involved activity box
  114. void updateEcts(
  115. final Label ectslabel, final ComboBox<String> comboBox
  116. ) {
  117. ectslabel.setText("ECTS: "
  118. + store.getSumEcts(comboBox.getValue()));
  119. }
  120. void fillElective(final ComboBox<String> electiveBox) {
  121. electiveBox.getItems().addAll(store.getAllActivities());
  122. }
  123. }