aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/Control.java
blob: 09019e4cff35eac64452ad004ec4b9ceea41ed5e (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer;
  4. import java.util.List;
  5. import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model.GUI;
  6. import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.view.Window;
  7. /// Bachelorizer - Controller
  8. public class Control{
  9. /// Application model
  10. // (declared explicitly only to silence javadoc)
  11. private GUI model;
  12. /// Application view
  13. private Window view;
  14. /// Parameters passed on command-line and in JNLP file
  15. private List<String> parameters;
  16. /// Default constructor
  17. ///
  18. /// @param model Application model
  19. /// @param view Application view
  20. public Control(GUI model, Window view){
  21. this.model = model;
  22. this.view = view;
  23. }
  24. /// parse application parameters
  25. ///
  26. /// parse parameters as GNU-style options and arguments,
  27. /// i.e. treat dash-prefixed words as options
  28. /// until an optional first bare "--",
  29. /// taking first non-option argument as name of student
  30. /// and remaining ones as activity selections
  31. ///
  32. /// @param parameters Application parameters
  33. public void setParameters(List<String> parameters) {
  34. boolean optionsDone = false;
  35. boolean studentAssigned = false;
  36. for (String item : parameters) {
  37. if (!optionsDone && item.matches("--")) {
  38. optionsDone = true;
  39. } else if (!item.startsWith("-")) {
  40. if (!studentAssigned) {
  41. model.addStudent(item);
  42. studentAssigned = true;
  43. showStudent();
  44. } else {
  45. model.addActivity(item);
  46. showActivities();
  47. }
  48. }
  49. }
  50. }
  51. /// Enter activity
  52. ///
  53. /// @param s String entered
  54. public void enterActivity(String s){
  55. model.addActivity(s);
  56. view.clearActivityEntry();
  57. showActivities();
  58. }
  59. /// Display student
  60. public void showStudent() {
  61. view.setStudentName(model.getStudentName());
  62. }
  63. /// Display list of activity entries
  64. public void showActivities() {
  65. String toarea = "";
  66. for (String t : model.getActivities())
  67. toarea += t + "\n";
  68. view.setArea(toarea);
  69. }
  70. /// drop last activity entry
  71. public void delOne(){
  72. model.delOneActivity();
  73. showActivities();
  74. }
  75. /// drop all activity entries
  76. public void delAll(){
  77. model.delAllActivities();
  78. showActivities();
  79. }
  80. }