// SPDX-FileCopyrightText: // SPDX-FileCopyrightText: // SPDX-FileCopyrightText: // SPDX-License-Identifier: GPL-3.0-or-later package com.example.portfolio2; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import java.util.List; /// Bachelorizer - Controller class Controller{ /// Application model private Model model; /// Application view private HelloApplication view; /// clear the participation database at program launch void initialize() { model.initialize(); } /// default constructor /// /// @param model Application model /// @param view Application view Controller(Model model, HelloApplication view){ this.model=model; this.view=view; } /// callback when category box is selected /// /// @param combo involved activity box /// @param select selected item /// @param area whole text area void onComboSelected(ComboBox combo, ComboBox select, TextArea area) { // clear the activity selection box select.getItems().clear(); // clear text area area.clear(); // fill activity box using model method select.getItems().addAll(model.selectProgram(combo.getValue())); } /// callback when activity box is selected /// /// @param combo involved activity box /// @param select selected item /// @param area whole text area void onActivitySelected(ComboBox combo, ComboBox select, TextArea area) { // pass the value chosen in the box addActivity(select.getValue(), area); // update text area based on category choice // // users can choose from the ComboBox, string (activity) and the area would update. updateArea(combo, area); } /// callback when subject module box is selected /// /// @param subject1 involved 1st column subject module box /// @param subject2 involved 2nd column subject module box /// @param subjectModules list of selected subject modules void onSubjectModuleSelected(ComboBox subject1, ComboBox subject2, List subjectModules) { // Beautiful loop we've created to remove option chosen in one subject module box from the other for (String sub : subjectModules) { if (sub.equals(subject1.getValue())) { subject2.getItems().remove(subject1.getValue()); } else if (!sub.equals(subject1.getValue()) && !subject2.getItems().contains(sub)) { subject2.getItems().add(sub); } } } /// add participation to database /// @param s activity identifier /// @param textArea whole text area void addActivity(String s, TextArea textArea) { model.addParticipation(model.getActivityIndeks(s)); } /// update text area for an activity box /// /// Clears the text area /// and adds all activity names from activities in participation. /// /// @param combo involved activity box /// @param textArea whole text area void updateArea(ComboBox combo, TextArea textArea) { textArea.clear(); for(String s : model.getParticipation(combo.getValue())) { textArea.appendText(s + "\n"); } } /// update label with current ECTS of program type /// @param ectslabel text display area for ECTS points /// @param comboBox involved activity box void updateEcts(Label ectslabel, ComboBox comboBox) { ectslabel.setText("ECTS: "+model.getSumEcts(comboBox.getValue())); } void fillElective(ComboBox electiveBox) { electiveBox.getItems().addAll(model.getAllActivities()); } }