diff options
Diffstat (limited to 'src/com.example.portfolio2/com/example/portfolio2/Window.java')
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Window.java | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Window.java b/src/com.example.portfolio2/com/example/portfolio2/Window.java new file mode 100644 index 0000000..730741a --- /dev/null +++ b/src/com.example.portfolio2/com/example/portfolio2/Window.java @@ -0,0 +1,192 @@ +// SPDX-FileCopyrightText: <Alexander Marthin Klemensen stud-marthin@ruc.dk> +// SPDX-FileCopyrightText: <Ian Valentin Christensen stud-ianc@ruc.dk> +// SPDX-FileCopyrightText: <Zahed Noos zahed@ruc.dk> +// SPDX-License-Identifier: GPL-3.0-or-later + +package com.example.portfolio2; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +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 +public final class Window extends Application { + + /// Default constructor + // (declared explicitly only to silence javadoc) + public Window() {} + + /// Label styling + public static final String LABEL_STYLE = + "-fx-font-weight: bold;-fx-font-size: 18;-fx-padding: 10"; + + /// Application model + private Model model = new Model(); + + /// Application controller + private Controller con = new Controller(model,this); + + /// database singleton + MyDB myDB = new MyDB(); + + /* Below is the original implementation of the UI elements with + accompanying, individual calls to setOnAction to specify functionality. + Before changing to a list format, + we made sure methods in controller and model + were generalized to allow for the new structure seamlessly. + private ComboBox<String> programCombo = new ComboBox<>(); + private ComboBox<String> subject1Combo = new ComboBox<>(); + private ComboBox<String> subject2Combo = new ComboBox<>(); + private ComboBox<String> electiveCombo = new ComboBox<>(); + + private ComboBox<String> programSelect = new ComboBox<>(); + private ComboBox<String> subject1Select = new ComboBox<>(); + private ComboBox<String> subject2Select = new ComboBox<>(); + private ComboBox<String> electiveSelect = new ComboBox<>(); + + private TextArea programArea = new TextArea(); + private TextArea subject1Area = new TextArea(); + private TextArea subject2Area = new TextArea(); + private TextArea electiveArea = new TextArea(); + + private Label programEcts = new Label(); + private Label subject1Ects = new Label(); + private Label subject2Ects = new Label(); + private Label electiveEcts = new Label(); + + private VBox program = new VBox(new Label("Program"), programCombo, programSelect, programArea, programEcts); + private VBox subject1 = new VBox(new Label("Subject 1"), subject1Combo, subject1Select, subject1Area, subject1Ects); + private VBox subject2 = new VBox(new Label("Subject 2"), subject2Combo, subject2Select, subject2Area, subject2Ects); + private VBox elective = new VBox(new Label("Elective"), electiveCombo, electiveSelect, electiveArea, electiveEcts); + */ + + @Override + public void start(Stage stage) throws IOException { + // clear old insertions into participation table + con.initialize(); + + // define list of columns based on their names + List<ActivityColumn> columns = List.of( + new ActivityColumn("Program"), + new ActivityColumn("Subject 1"), + new ActivityColumn("Subject 2"), + new ActivityColumn("Elective") + ); + + // define list of subject modules + List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology"); + + // define button functionality for each activity column + for (ActivityColumn col : columns) { + col.nameLabel.setStyle(LABEL_STYLE); + col.ectsLabel.setStyle(LABEL_STYLE); + col.categoryCombo.setPrefSize(250, 35); + col.activitySelect.setPrefSize(250, 35); + col.area.setPrefWidth(250); + + // all boxes share same activity logic + col.activitySelect.setOnAction(event -> { + con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area); + con.updateEcts(col.ectsLabel, col.categoryCombo); + }); + + // handle each category box + switch (col.name) { + case "Program" -> { + col.categoryCombo.getItems().addAll("HumTek", "NatBach"); + col.categoryCombo.setOnAction(event -> { + con.onComboSelected(col.categoryCombo, col.activitySelect, col.area); + }); + } + // TODO: use the list for filling the box + case "Subject 1" -> { + col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology"); + col.categoryCombo.setOnAction(event -> { + con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules); + con.onComboSelected(col.categoryCombo, col.activitySelect, col.area); + }); + } + case "Subject 2" -> { + col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology"); + // TODO: figure out a better way... + col.categoryCombo.setOnAction(event -> { + con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules); + con.onComboSelected(col.categoryCombo, col.activitySelect, col.area); + }); + } + case "Elective" -> { + + // hide useless box + col.categoryCombo.setVisible(false); + + con.fillElective(col.activitySelect); + } + } + } + + // define HBox and scene for columns + HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox()); + Scene scene = new Scene(root, 1000, 500); + stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition"); + stage.setScene(scene); + stage.show(); + } + + /// JVM entry point + /// + /// @param args command-line arguments + public static void main(String[] args) { + launch(); + } + + /// column of activities + private class ActivityColumn { + + /// identifier stored in the text felt + String name; + + /// display text + Label nameLabel; + + /// dropdown list for categories + ComboBox<String> categoryCombo; + + /// dropdown list for activities + ComboBox<String> activitySelect; + + /// descriptionof chosen activities + TextArea area; + + /// text to display ECTS points + Label ectsLabel; + + /// column of activities + /// + /// @param name identifier + ActivityColumn(String name) { + this.name = name; + nameLabel = new Label(name); + categoryCombo = new ComboBox<>(); + activitySelect = new ComboBox<>(); + area = new TextArea(); + ectsLabel = new Label(); + } + + /// activity columne as VBox + /// + /// @return column of activities as VBox + VBox asVBox() { + return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel); + } + } +} |