From 97d75aa78e658f9fe398827fb7cba7aa5bc31a6f Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 29 Apr 2025 23:14:36 +0200 Subject: add track UI sections in new model class UI via subclass GUI (not as strings in class Window) --- .../com/example/portfolio2/Controller.java | 7 +++- .../com/example/portfolio2/GUI.java | 17 ++++++++++ .../com/example/portfolio2/UI.java | 38 ++++++++++++++++++++++ .../com/example/portfolio2/Window.java | 35 +++++++++++--------- 4 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 src/com.example.portfolio2/com/example/portfolio2/GUI.java create mode 100644 src/com.example.portfolio2/com/example/portfolio2/UI.java (limited to 'src') diff --git a/src/com.example.portfolio2/com/example/portfolio2/Controller.java b/src/com.example.portfolio2/com/example/portfolio2/Controller.java index 3181199..154cf42 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Controller.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Controller.java @@ -18,6 +18,9 @@ class Controller { /// Storage model private Database store; + /// UI model + private UI ui; + /// Application view private Window view; @@ -29,9 +32,11 @@ class Controller { /// default constructor /// /// @param store Storage model + /// @param ui UI model /// @param view Application view - Controller(final Database store, final Window view) { + Controller(final Database store, UI ui, final Window view) { this.store = store; + this.ui = ui; this.view = view; } diff --git a/src/com.example.portfolio2/com/example/portfolio2/GUI.java b/src/com.example.portfolio2/com/example/portfolio2/GUI.java new file mode 100644 index 0000000..e1f8fb3 --- /dev/null +++ b/src/com.example.portfolio2/com/example/portfolio2/GUI.java @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2025 Jonas Smedegaard +// SPDX-License-Identifier: GPL-3.0-or-later + +package com.example.portfolio2; + +import java.util.ArrayList; + +/// Bachelorizer - graphical user interface model +public class GUI extends UI { + + /// Default constructor + // (declared explicitly only to silence javadoc) + public GUI() { } + + // TODO: extend with sections specific to graphical interface, + // e.g. widgets like statusbar or menu. +} diff --git a/src/com.example.portfolio2/com/example/portfolio2/UI.java b/src/com.example.portfolio2/com/example/portfolio2/UI.java new file mode 100644 index 0000000..6f2c1ec --- /dev/null +++ b/src/com.example.portfolio2/com/example/portfolio2/UI.java @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2025 Jonas Smedegaard +// SPDX-License-Identifier: GPL-3.0-or-later + +package com.example.portfolio2; + +/// Bachelorizer - reference user interface model +public abstract class UI { + + /// Default constructor + // (declared explicitly only to silence javadoc) + public UI() { } + + /// structural sections of user interface + public enum Section { + + /// main programme + PROGRAM("Program"), + + /// first subject module + SUBJECT1("Subject 1"), + + /// second subject module + SUBJECT2("Subject 2"), + + /// elective courses + ELECTIVE("Elective"); + + /// text label + public final String label; + + /// instantiation + /// + /// @param label text label + private Section(String label) { + this.label = label; + } + } +} diff --git a/src/com.example.portfolio2/com/example/portfolio2/Window.java b/src/com.example.portfolio2/com/example/portfolio2/Window.java index 94c5609..36be369 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Window.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Window.java @@ -48,8 +48,11 @@ public final class Window extends Application { /// Storage model private Database store = new Database(); + /// UI model + private UI ui = new GUI(); + /// Application controller - private Controller con = new Controller(store, this); + private Controller con = new Controller(store, ui, this); @Override public void start(final Stage stage) throws IOException { @@ -58,10 +61,10 @@ public final class Window extends Application { // define list of columns based on their names List columns = List.of( - new ActivityColumn("Program"), - new ActivityColumn("Subject 1"), - new ActivityColumn("Subject 2"), - new ActivityColumn("Elective") + new ActivityColumn(UI.Section.PROGRAM), + new ActivityColumn(UI.Section.SUBJECT1), + new ActivityColumn(UI.Section.SUBJECT2), + new ActivityColumn(UI.Section.ELECTIVE) ); // define button functionality for each activity column @@ -86,8 +89,8 @@ public final class Window extends Application { }); // handle each category box - switch (col.name) { - case "Program" -> { + switch (col.section) { + case UI.Section.PROGRAM -> { col.categoryCombo.getItems().addAll( "HumTek", "NatBach"); col.categoryCombo.setOnAction(event -> { @@ -98,7 +101,7 @@ public final class Window extends Application { }); } // TODO: use the list for filling the box - case "Subject 1" -> { + case UI.Section.SUBJECT1 -> { col.categoryCombo.getItems().addAll( "Computer Science", "Informatik", @@ -114,7 +117,7 @@ public final class Window extends Application { col.area); }); } - case "Subject 2" -> { + case UI.Section.SUBJECT2 -> { col.categoryCombo.getItems().addAll( "Computer Science", "Informatik", @@ -131,7 +134,7 @@ public final class Window extends Application { col.area); }); } - case "Elective" -> { + case UI.Section.ELECTIVE -> { // hide useless box col.categoryCombo.setVisible(false); @@ -164,14 +167,14 @@ public final class Window extends Application { /// column of activities /// - /// @param name identifier stored in the text felt + /// @param section structural section for column /// @param nameLabel display text /// @param categoryCombo dropdown list for categories /// @param activitySelect dropdown list for activities /// @param area description of chosen activities /// @param ectsLabel text to display ECTS points private record ActivityColumn( - String name, + UI.Section section, Label nameLabel, ComboBox categoryCombo, ComboBox activitySelect, @@ -181,11 +184,11 @@ public final class Window extends Application { /// column of activities /// - /// @param name identifier - public ActivityColumn(String name) { + /// @param section structural section for column + public ActivityColumn(UI.Section section) { this( - name, - new Label(name), + section, + new Label(section.label), new ComboBox<>(), new ComboBox<>(), new TextArea(), -- cgit v1.2.3