diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-28 16:31:25 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-28 16:39:21 +0200 |
commit | 9df1ad472f57adecb59768ffe7c847174c86ccc7 (patch) | |
tree | 6b9c460d7ccdd2dcff1f83461e069b68d8678f39 /src/com.example.portfolio2/com/example/portfolio2/Controller.java | |
parent | 9d419988fa797ca431387db6a77e23832c11c6b3 (diff) |
split classes into separate files
Diffstat (limited to 'src/com.example.portfolio2/com/example/portfolio2/Controller.java')
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Controller.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Controller.java b/src/com.example.portfolio2/com/example/portfolio2/Controller.java new file mode 100644 index 0000000..1e6c002 --- /dev/null +++ b/src/com.example.portfolio2/com/example/portfolio2/Controller.java @@ -0,0 +1,53 @@ +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; + private HelloApplication view; // We do this without using the view directly like this, instead passing options. + void initialize() { // calls on the database + model.initialize(); + } + Controller(Model model, HelloApplication view){ + this.model=model; this.view=view; + } + void onComboSelected(ComboBox<String> combo, ComboBox<String> select, TextArea area) { + select.getItems().clear(); // Clear the activity selection box + area.clear(); // Clear text area + select.getItems().addAll(model.selectProgram((String) combo.getValue())); // Fill activity box using model method + } + void onActivitySelected(ComboBox<String> combo, ComboBox<String> select, TextArea area) { + addActivity((String) select.getValue(), area); // Passes the value chosen in the box + updateArea(combo, area); // Updates the text area based on the category choice + // users can choose from the ComboBox, string (activity) and the area would update. + } + void onSubjectModuleSelected(ComboBox<String> subject1, ComboBox<String> subject2, List<String> 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); + } + } + } + void addActivity(String s, TextArea textArea) { // Calls on model method to add participation in the database + model.addParticipation(model.getActivityIndeks(s)); + } + void updateArea(ComboBox combo, TextArea textArea) { // Clears the text area and adds all activity names from activities in participation + textArea.clear(); + for(String s : model.getParticipation((String) combo.getValue())) { + textArea.appendText(s + "\n"); + } + } + void updateEcts(Label ectslabel, ComboBox<String> comboBox) { // Updates the labels with the current ECTS of the program type + ectslabel.setText("ECTS: "+model.getSumEcts(comboBox.getValue())); + } + void fillElective(ComboBox<String> electiveBox) { + electiveBox.getItems().addAll(model.getAllActivities()); + } +} |