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