aboutsummaryrefslogtreecommitdiff
path: root/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java')
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java156
1 files changed, 119 insertions, 37 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java
index ab62bfa..63eac9d 100644
--- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java
+++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java
@@ -1,16 +1,25 @@
+// SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk>
+// SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk>
// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
+// SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk>
// SPDX-License-Identifier: GPL-3.0-or-later
package dk.biks.bachelorizer;
import java.util.List;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextArea;
+
/// Bachelorizer - Controller
-public class Controller {
+class Controller {
+
+ /// Storage model
+ private Database store;
- /// Application model
- // (declared explicitly only to silence javadoc)
- private GUI model;
+ /// UI model
+ private UI ui;
/// Application view
private Window view;
@@ -18,75 +27,148 @@ public class Controller {
/// Parameters passed on command-line and in JNLP file
private List<String> parameters;
- /// Default constructor
+ /// clear the participation database at program launch
+ void initialize() {
+ store.initialize();
+ }
+
+ /// default constructor
///
- /// @param model Application model
+ /// @param store Storage model
+ /// @param ui UI model
/// @param view Application view
- public Controller(final GUI model, final Window view) {
- this.model = model;
+ Controller(
+ final Database store, final UI ui, final Window view
+ ) {
+ this.store = store;
+ this.ui = ui;
this.view = view;
}
/// parse application parameters
///
- /// parse parameters as GNU-style options and arguments,
+ /// Parse parameters as GNU-style options and arguments,
/// i.e. treat dash-prefixed words as options
/// until an optional first bare "--",
/// taking first non-option argument as name of student
- /// and remaining ones as activity selections
+ /// and remaining ones as activity selections.
///
/// @param parameters Application parameters
public final void setParameters(final List<String> parameters) {
boolean optionsDone = false;
boolean studentAssigned = false;
+/* TODO
for (String item: parameters) {
if (!optionsDone && item.matches("--")) {
optionsDone = true;
} else if (!item.startsWith("-")) {
if (!studentAssigned) {
- model.addStudent(item);
+ store.addStudent(item);
studentAssigned = true;
- showStudent();
+// TODO ui.showStudent(
+// model.getStudentName());
} else {
- model.addActivity(item);
- showActivities();
+ store.addParticipation(
+ store.getActivityIndeks(item));
+// TODO ui.showActivities();
}
}
}
+*/
}
- /// Enter activity
+ /// callback when category has been selected
///
- /// @param s String entered
- public final void enterActivity(final String s) {
- model.addActivity(s);
- view.clearActivityEntry();
- showActivities();
+ /// @param section section the category is tied to
+ /// @param category selected category
+ // TODO: require a UI instead
+ void onCategorySelected(
+ final GUI.Section section,
+ final String category
+ ) {
+ view.clearSelections(section);
+ view.setOptions(section, store.selectProgram(category));
}
- /// Display student
- public final void showStudent() {
- view.setStudentName(model.getStudentName());
+ /// callback when activity has been selected
+ ///
+ /// @param combo involved activity box
+ /// @param select selected item
+ /// @param area whole text area
+ void onActivitySelected(
+ final ComboBox<String> combo,
+ final ComboBox<String> select,
+ final 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,
+ // and string (activity) and the area will then update.
+ updateArea(combo, area);
}
- /// Display list of activity entries
- public final void showActivities() {
- String toarea = "";
- for (String t: model.getActivities()) {
- toarea += t + "\n";
+ /// callback when subject module has been selected
+ ///
+ /// @param subject1 involved 1st column subject module box
+ /// @param subject2 involved 2nd column subject module box
+ void onSubjectModuleSelected(
+ final ComboBox<String> subject1,
+ final ComboBox<String> subject2
+ ) {
+
+ // remove chosen option from opposite subject module box
+ for (String sub: store.getAllSubjects()) {
+ 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(final String s, final TextArea textArea) {
+ store.addParticipation(store.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(
+ final ComboBox<String> combo, final TextArea textArea
+ ) {
+ textArea.clear();
+ for (String s: store.getParticipation(combo.getValue())
+ ) {
+ textArea.appendText(s + "\n");
}
- view.setArea(toarea);
}
- /// drop last activity entry
- public final void delOne() {
- model.delOneActivity();
- showActivities();
+ /// update label with current ECTS of program type
+ /// @param ectslabel text display area for ECTS points
+ /// @param comboBox involved activity box
+ void updateEcts(
+ final Label ectslabel, final ComboBox<String> comboBox
+ ) {
+ ectslabel.setText("ECTS: "
+ + store.getSumEcts(comboBox.getValue()));
}
- /// drop all activity entries
- public final void delAll() {
- model.delAllActivities();
- showActivities();
+ void fillElective(final ComboBox<String> electiveBox) {
+ electiveBox.getItems().addAll(store.getAllActivities());
}
}