From db57e539760b4f9d3fba2f7027abe9dbd017c45d Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 31 Mar 2025 17:05:42 +0200 Subject: expand to use multi-framework MVC pattern --- .../bachelorizer/Control.java" | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "dk/abcdefghijklmnopqrstuvxyz\303\246\303\270\303\245/bachelorizer/Control.java" (limited to 'dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java') diff --git "a/dk/abcdefghijklmnopqrstuvxyz\303\246\303\270\303\245/bachelorizer/Control.java" "b/dk/abcdefghijklmnopqrstuvxyz\303\246\303\270\303\245/bachelorizer/Control.java" new file mode 100644 index 0000000..09019e4 --- /dev/null +++ "b/dk/abcdefghijklmnopqrstuvxyz\303\246\303\270\303\245/bachelorizer/Control.java" @@ -0,0 +1,94 @@ +// 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(); + } +} -- cgit v1.2.3