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/com.example.portfolio2 | |
parent | 714b07ea2012a880e0bee2ec6e090324500fa06a (diff) |
merge project portfolio2 into bachelorizer, except class myDB
Diffstat (limited to 'src/com.example.portfolio2')
7 files changed, 1 insertions, 409 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Controller.java b/src/com.example.portfolio2/com/example/portfolio2/Controller.java deleted file mode 100644 index 3d19efb..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/Controller.java +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk> -// SPDX-License-Identifier: GPL-3.0-or-later - -package com.example.portfolio2; - -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.control.TextArea; - -/// Bachelorizer - Controller -class Controller { - - /// Storage model - private Database store; - - /// UI model - private UI ui; - - /// Application view - private Window view; - - /// clear the participation database at program launch - void initialize() { - store.initialize(); - } - - /// default constructor - /// - /// @param store Storage model - /// @param ui UI model - /// @param view Application view - Controller( - final Database store, final UI ui, final Window view - ) { - this.store = store; - this.ui = ui; - this.view = view; - } - - /// callback when category has been selected - /// - /// @param section section the category is tied to - /// @param category selected category - // TODO: require a UI instead - void onCategorySelected( - final GUI.Section section, - final String category - ) { - view.clearSelections(section); - view.setOptions(section, store.selectProgram(category)); - } - - /// callback when activity has been selected - /// - /// @param combo involved activity box - /// @param select selected item - /// @param area whole text area - void onActivitySelected( - final ComboBox<String> combo, - final ComboBox<String> select, - final TextArea area - ) { - - // pass the value chosen in the box - addActivity(select.getValue(), area); - - // update text area based on category choice - // - // Users can choose from the ComboBox, - // and string (activity) and the area will then update. - updateArea(combo, area); - } - - /// callback when subject module has been selected - /// - /// @param subject1 involved 1st column subject module box - /// @param subject2 involved 2nd column subject module box - void onSubjectModuleSelected( - final ComboBox<String> subject1, - final ComboBox<String> subject2 - ) { - - // remove chosen option from opposite subject module box - for (String sub: store.getAllSubjects()) { - if (sub.equals(subject1.getValue())) { - subject2.getItems().remove( - subject1.getValue()); - } else if ( - !sub.equals(subject1.getValue()) - && !subject2.getItems().contains(sub) - ) { - subject2.getItems().add(sub); - } - } - } - - /// add participation to database - /// @param s activity identifier - /// @param textArea whole text area - void addActivity(final String s, final TextArea textArea) { - store.addParticipation(store.getActivityIndeks(s)); - } - - /// update text area for an activity box - /// - /// Clears the text area - /// and adds all activity names from activities in participation. - /// - /// @param combo involved activity box - /// @param textArea whole text area - void updateArea( - final ComboBox<String> combo, final TextArea textArea - ) { - textArea.clear(); - for (String s: store.getParticipation(combo.getValue()) - ) { - textArea.appendText(s + "\n"); - } - } - - /// update label with current ECTS of program type - /// @param ectslabel text display area for ECTS points - /// @param comboBox involved activity box - void updateEcts( - final Label ectslabel, final ComboBox<String> comboBox - ) { - ectslabel.setText("ECTS: " - + store.getSumEcts(comboBox.getValue())); - } - - void fillElective(final ComboBox<String> electiveBox) { - electiveBox.getItems().addAll(store.getAllActivities()); - } -} diff --git a/src/com.example.portfolio2/com/example/portfolio2/Database.java b/src/com.example.portfolio2/com/example/portfolio2/Database.java deleted file mode 100644 index 8b8f93a..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/Database.java +++ /dev/null @@ -1,144 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk> -// SPDX-License-Identifier: GPL-3.0-or-later - -package com.example.portfolio2; - -import java.util.ArrayList; -import java.util.List; - -/// Bachelorizer - database model -/// -/// This model handles all interaction with the database. -class Database { - - /// database singleton - private MyDB db = new MyDB(); - - /// default constructor - // (declared explicitly only to silence javadoc) - Database() { } - - /// student object - // TODO: replace this dummy placeholder with database query - private Person student; - - /// clear the participation database at program launch - void initialize() { - clearParticipation(); - } - - /// Add student - /// - /// @param name Name of student - // TODO: replace this dummy placeholder with database query - public final void addStudent(final String name) { - student = new Person(name); - } - - /// Get student name - /// - /// @return name of student - // TODO: replace this dummy placeholder with database query - public final String getStudentName() { - return student.name; - } - - /// resolve activity index from name - /// - /// @param name activity name - /// @return index of activity as integer - int getActivityIndeks(final String name) { - if (name == null) { - return -1; - } - ArrayList<String> result = db.query( - "SELECT indeks FROM activity" - + " WHERE name IS '" + name + "';", - "indeks"); - - return Integer.parseInt(result.getFirst()); - } - - /// insert activity into participation - /// - /// @param activityIndex index of activity - void addParticipation(final int activityIndex) { - db.cmd("INSERT INTO participation VALUES(123, " - + activityIndex + ");"); - } - - /// list currently participating activities - /// - /// @param program programme name - /// @return names of participating activities - ArrayList<String> getParticipation(final String program) { - return db.query( - "SELECT name FROM participation p" - + " INNER JOIN activity a ON p.indeks = a.indeks" - + " WHERE program IS '" + program + "';", - "name"); - } - - /// purge participation database - void clearParticipation() { - db.cmd("DELETE FROM participation"); - } - - /// list activities within a program - /// - /// @param program programme name - /// @return names of contained activities - ArrayList<String> selectProgram(final String program) { - return db.query( - "SELECT name FROM activity" - + " WHERE program IS '" + program + "';", - "name"); - } - - /// sum of ECTS points under the given category - /// - /// @param program programme name - /// @return ECTS points as String - String getSumEcts(final String program) { - if (program == null) { - return "0"; - } - ArrayList<String> result = db.query( - "SELECT SUM(activity.ects)" - + " AS total_ects,student.name" - + " FROM student LEFT OUTER JOIN participation" - + " ON student.studid = participation.studid" - + " INNER JOIN activity" - + " ON participation.indeks = activity.indeks" - + " WHERE program IS '" + program + "'" - + " GROUP BY student.studid ;", - "total_ects"); - if (result.isEmpty()) { - return "0"; - } - - return result.getFirst(); - } - - /// list of available subject modules - /// - /// @return names of all subject modules as list of strings - List<String> getAllSubjects() { - return db.query( - "SELECT DISTINCT program FROM activity" - + " WHERE program NOT IN (" - + " SELECT program from activity" - + " WHERE name LIKE 'BP1 %')", - "program"); - } - - /// list of available activities - /// - /// @return names of all activities as list of strings - ArrayList<String> getAllActivities() { - return db.query("SELECT name FROM activity;", "name"); - } -} diff --git a/src/com.example.portfolio2/com/example/portfolio2/GUI.java b/src/com.example.portfolio2/com/example/portfolio2/GUI.java deleted file mode 100644 index de05873..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/GUI.java +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// SPDX-License-Identifier: GPL-3.0-or-later - -package com.example.portfolio2; - -/// Bachelorizer - graphical user interface model -public class GUI extends UI { - - /// Default constructor - // (declared explicitly only to silence javadoc) - public GUI() { } - - /// structural sections of user interface - public enum Section { - - /// main programme - PROGRAM("Program", 0), - - /// first subject module - SUBJECT1("Subject 1", 1), - - /// second subject module - SUBJECT2("Subject 2", 2), - - /// elective courses - ELECTIVE("Elective", 3); - - /// text label - final String label; - - /// column position - final int column; - - /// instantiation - /// - /// @param label text label - /// @param column column position - Section(final String label, final int column) { - this.label = label; - this.column = column; - } - } - -/* public static UI.Section asUISection () { - return UI.Section.valueOf(this); - } -*/ -} diff --git a/src/com.example.portfolio2/com/example/portfolio2/Main.java b/src/com.example.portfolio2/com/example/portfolio2/Main.java deleted file mode 100644 index 5f79c22..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/Main.java +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk> -// SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk> -// SPDX-License-Identifier: GPL-3.0-or-later - -package com.example.portfolio2; - -/// Bachelorizer - bachelor programme registrar -public final class Main { - - /// Default constructor - // (declared explicitly only to silence javadoc) - public Main() { } - - /// JVM entry point - /// - /// @param args command-line arguments - public static void main(final String[] args) { - Window.main(args); - } -} diff --git a/src/com.example.portfolio2/com/example/portfolio2/Person.java b/src/com.example.portfolio2/com/example/portfolio2/Person.java deleted file mode 100644 index aaf4c59..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/Person.java +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// SPDX-License-Identifier: GPL-3.0-or-later - -package com.example.portfolio2; - -/// Bachelorizer - Person model -public class Person { - - /// Person name - public String name; - - /// Constructor - /// - /// @param name Name of person - public Person(final String name) { - this.name = name; - } -} diff --git a/src/com.example.portfolio2/com/example/portfolio2/UI.java b/src/com.example.portfolio2/com/example/portfolio2/UI.java deleted file mode 100644 index a70bf8e..0000000 --- a/src/com.example.portfolio2/com/example/portfolio2/UI.java +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> -// 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 - final String label; - - /// instantiation - /// - /// @param label text label - Section(final String label) { - this.label = label; - } - } -} diff --git a/src/com.example.portfolio2/module-info.java b/src/com.example.portfolio2/module-info.java index 1f6940d..1456b90 100644 --- a/src/com.example.portfolio2/module-info.java +++ b/src/com.example.portfolio2/module-info.java @@ -1,6 +1,5 @@ -/// Bachelorizer - bachelor programme registrar +/// foo module com.example.portfolio2 { - requires transitive javafx.controls; requires java.sql; exports com.example.portfolio2; |