// 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; class Controller{ private Model model; // We do this without using the view directly like this, instead passing options. private HelloApplication view; // calls on the database void initialize() { model.initialize(); } Controller(Model model, HelloApplication view){ this.model=model; this.view=view; } void onComboSelected(ComboBox combo, ComboBox select, TextArea area) { // Clear the activity selection box select.getItems().clear(); area.clear(); // Clear text area // Fill activity box using model method select.getItems().addAll(model.selectProgram((String) combo.getValue())); } void onActivitySelected(ComboBox combo, ComboBox select, TextArea area) { // Passes the value chosen in the box addActivity((String) select.getValue(), area); // Updates the text area based on the category choice // users can choose from the ComboBox, string (activity) and the area would update. updateArea(combo, area); } 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); } } } // Calls on model method to add participation in the database void addActivity(String s, TextArea textArea) { model.addParticipation(model.getActivityIndeks(s)); } // Clears the text area and adds all activity names from activities in participation void updateArea(ComboBox combo, TextArea textArea) { textArea.clear(); for(String s : model.getParticipation((String) combo.getValue())) { textArea.appendText(s + "\n"); } } // Updates the labels with the current ECTS of the program type void updateEcts(Label ectslabel, ComboBox comboBox) { ectslabel.setText("ECTS: "+model.getSumEcts(comboBox.getValue())); } void fillElective(ComboBox electiveBox) { electiveBox.getItems().addAll(model.getAllActivities()); } }