aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-03-31 17:05:42 +0200
committerJonas Smedegaard <dr@jones.dk>2025-03-31 17:07:33 +0200
commitdb57e539760b4f9d3fba2f7027abe9dbd017c45d (patch)
treef4165a9b65e7a9da28cdfbac9616609528e5f2a5 /dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java
parent4649104978b834156a649d7f1e4613c940e6b626 (diff)
expand to use multi-framework MVC pattern
Diffstat (limited to 'dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java')
-rw-r--r--dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java
new file mode 100644
index 0000000..09019e4
--- /dev/null
+++ b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java
@@ -0,0 +1,94 @@
+// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
+// 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<String> 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<String> 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();
+ }
+}