diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-30 22:21:28 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-30 22:23:08 +0200 |
commit | b591061ec982ea087488afe39ce55fff6fa4bfa4 (patch) | |
tree | aa6c1351e5648a6438f440829551dcb8f513bf99 /src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java | |
parent | 714b07ea2012a880e0bee2ec6e090324500fa06a (diff) |
merge project portfolio2 into bachelorizer, except class myDB
Diffstat (limited to 'src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java')
-rw-r--r-- | src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java | 252 |
1 files changed, 187 insertions, 65 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java index c129aad..6c21db5 100644 --- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java +++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java @@ -1,18 +1,23 @@ +// SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk> +// SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk> // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> +// SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk> // SPDX-License-Identifier: GPL-3.0-or-later package dk.biks.bachelorizer; import javafx.application.Application; -import javafx.scene.control.Button; +import javafx.scene.Scene; +import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.scene.Scene; import javafx.stage.Stage; +import java.io.IOException; +import java.util.List; + /// Bachelorizer - JavaFX Window view // Class is final to forbid subclassing, // because object is passed to controller during instantiation @@ -20,42 +25,39 @@ public final class Window extends Application { /// Default constructor // (declared explicitly only to silence javadoc) - public Window() { - } + public Window() { } /// window width - private static final int WINDOW_WIDTH = 500; + private static final int WINDOW_WIDTH = 1000; /// window height private static final int WINDOW_HEIGHT = 500; + /// box width + private static final int LIST_WIDTH = 250; + /// box height - private static final int BOX_HEIGHT = 10; + private static final int LIST_HEIGHT = 35; /// Label styling private static final String LABEL_STYLE = - "-fx-font-weight: bold; -fx-font-size: 20;"; - - /// Application model - private GUI model = new GUI(); - - /// Application controller - private Controller control = new Controller(model, this); - - /// Name of student - private TextField nameEntry = new TextField(); + "-fx-font-weight: bold;" + + "-fx-font-size: 18;" + + "-fx-padding: 10"; - /// Text entry for adding an activity - private TextField activityEntry = new TextField(); + /// Storage model + private Database store = new Database(); - /// Text area for activity entries - private TextArea area = new TextArea(); + /// UI model + /// + /// Must be subclass GUI to cover columns. + private GUI ui = new GUI(); - /// Button to delete one activity - private Button delOne = new Button("Delete one"); + /// Application controller + private Controller control = new Controller(store, ui, this); - /// Button to delete all activities - private Button delAll = new Button("Delete all"); + /// column state data as List of ActivityColumn objects + private List<ActivityColumn> columns; /// Application instantiation /// @@ -65,62 +67,182 @@ public final class Window extends Application { } @Override - public void start(final Stage stage) { + public void start(final Stage stage) throws IOException { // pass application parameters to controller control.setParameters(getParameters().getRaw()); - // add listeners -// NameEntry.setOnAction(e -> control.enterName( -// activityEntry.getText())); - activityEntry.setOnAction(e -> control.enterActivity( - activityEntry.getText())); - delOne.setOnAction(e -> control.delOne()); - delAll.setOnAction(e -> control.delAll()); - - // add buttons - VBox root = new VBox(BOX_HEIGHT, - ourHBox("Student", nameEntry), - ourHBox("Add activity", activityEntry), - new HBox(BOX_HEIGHT, delOne, delAll), - area); - - // compose stage + // clear old insertions into participation table + control.initialize(); + + // define list of columns based on their names + columns = List.of( + new ActivityColumn(GUI.Section.PROGRAM), + new ActivityColumn(GUI.Section.SUBJECT1), + new ActivityColumn(GUI.Section.SUBJECT2), + new ActivityColumn(GUI.Section.ELECTIVE) + ); + + // define button functionality for each activity column + for (ActivityColumn col : columns) { + col.nameLabel.setStyle(LABEL_STYLE); + col.ectsLabel.setStyle(LABEL_STYLE); + col.categoryCombo.setPrefSize( + LIST_WIDTH, LIST_HEIGHT); + col.activitySelect.setPrefSize( + LIST_WIDTH, LIST_HEIGHT); + col.area.setPrefWidth(LIST_WIDTH); + + // all boxes share same activity logic + col.activitySelect.setOnAction(event -> { + control.onActivitySelected( + col.categoryCombo, + col.activitySelect, + col.area); + control.updateEcts( + col.ectsLabel, + col.categoryCombo); + }); + + // handle each category box + switch (col.section) { + case GUI.Section.PROGRAM -> { + col.categoryCombo.getItems().addAll( + "HumTek", "NatBach"); + col.categoryCombo.setOnAction(event -> { + control.onCategorySelected( + col.section, + col.categoryCombo.getValue()); + }); + } + // TODO: use the list for filling the box + case GUI.Section.SUBJECT1 -> { + col.categoryCombo.getItems().addAll( + "Computer Science", + "Informatik", + "Astrology"); + col.categoryCombo.setOnAction(event -> { + control.onSubjectModuleSelected( + col.categoryCombo, + columns.get( + GUI.Section.SUBJECT2.column) + .categoryCombo); + control.onCategorySelected( + col.section, + col.categoryCombo.getValue()); + }); + } + case GUI.Section.SUBJECT2 -> { + col.categoryCombo.getItems().addAll( + "Computer Science", + "Informatik", + "Astrology"); + // TODO: figure out a better way... + col.categoryCombo.setOnAction(event -> { + control.onSubjectModuleSelected( + col.categoryCombo, + columns.get( + GUI.Section.SUBJECT1.column) + .categoryCombo); + control.onCategorySelected( + col.section, + col.categoryCombo.getValue()); + }); + } + case GUI.Section.ELECTIVE -> { + + // hide useless box + col.categoryCombo.setVisible(false); + + control.fillElective(col.activitySelect); + } + } + } + + // define HBox and scene for columns + HBox root = new HBox( + columns.get(GUI.Section.PROGRAM.column) + .asVBox(), + columns.get(GUI.Section.SUBJECT1.column) + .asVBox(), + columns.get(GUI.Section.SUBJECT2.column) + .asVBox(), + columns.get(GUI.Section.ELECTIVE.column) + .asVBox()); Scene scene = new Scene( root, WINDOW_WIDTH, WINDOW_HEIGHT); - stage.setTitle("JavaFX Demo"); + stage.setTitle("Bachelorizer - RUC Course Selector"); stage.setScene(scene); stage.show(); } - /// action to apply student name + /// column of activities /// - /// @param s Text to apply - public void setStudentName(final String s) { - nameEntry.setText(s); + /// @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( + GUI.Section section, + Label nameLabel, + ComboBox<String> categoryCombo, + ComboBox<String> activitySelect, + TextArea area, + Label ectsLabel + ) { + + /// column of activities + /// + /// @param section structural section for column + ActivityColumn(final GUI.Section section) { + this( + section, + new Label(section.label), + new ComboBox<>(), + new ComboBox<>(), + new TextArea(), + new Label() + ); + } + + /// activity columne as VBox + /// + /// @return column of activities as VBox + VBox asVBox() { + return new VBox( + nameLabel, + categoryCombo, + activitySelect, + area, + ectsLabel); + } } - /// action to apply text to area + /// populate activities for a category /// - /// @param s Text to apply - public void setArea(final String s) { - area.setText(s); + /// @param section structural section to operate on + /// @param activities activities to apply as string + public void setOptions( + final GUI.Section section, final List<String> activities + ) { + + // clear the activity selection box + columns.get(section.column).activitySelect + .getItems().clear(); + + // fill activity box from data in store + columns.get(section.column).activitySelect + .getItems().addAll(activities); } - /// Button action to clear field - public void clearActivityEntry() { - activityEntry.setText(""); - } - - /// Styled HBox with label and TextField + /// remove selections from a category /// - /// @param s Label string - /// @param f Text field - /// @return HBox containing styled label and text field - public HBox ourHBox(final String s, final TextField f) { - Label label = new Label(s + ":"); - label.setStyle(LABEL_STYLE); - - return new HBox(BOX_HEIGHT, label, f); + /// @param section structural section to operate on + public void clearSelections(final GUI.Section section) { + + // clear text area + columns.get(section.column).area.clear(); } } |