// SPDX-FileCopyrightText: 2025 Jonas Smedegaard // SPDX-License-Identifier: GPL-3.0-or-later package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer; import java.util.List; import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model.GUI; import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.view.Window; /// Bachelorizer - Controller public class Control{ /// Application model // (declared explicitly only to silence javadoc) private GUI model; /// Application view private Window view; /// Parameters passed on command-line and in JNLP file private List parameters; /// Default constructor /// /// @param model Application model /// @param view Application view public Control(GUI model, Window view){ this.model = model; this.view = view; } /// parse application parameters /// /// 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 /// /// @param parameters Application parameters public void setParameters(List parameters) { boolean optionsDone = false; boolean studentAssigned = false; for (String item : parameters) { if (!optionsDone && item.matches("--")) { optionsDone = true; } else if (!item.startsWith("-")) { if (!studentAssigned) { model.addStudent(item); studentAssigned = true; showStudent(); } else { model.addActivity(item); showActivities(); } } } } /// Enter activity /// /// @param s String entered public void enterActivity(String s){ model.addActivity(s); view.clearActivityEntry(); showActivities(); } /// Display student public void showStudent() { view.setStudentName(model.getStudentName()); } /// Display list of activity entries public void showActivities() { String toarea = ""; for (String t : model.getActivities()) toarea += t + "\n"; view.setArea(toarea); } /// drop last activity entry public void delOne(){ model.delOneActivity(); showActivities(); } /// drop all activity entries public void delAll(){ model.delAllActivities(); showActivities(); } }