From 5cc020bca2c2fdf86d8dcc129fafc97e76300869 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Oct 2023 03:08:07 +0300 Subject: [PATCH] Implemented generics to reuse code, clean-ups --- .idea/inspectionProfiles/Project_Default.xml | 10 ++ .../main/java/org/lumijiez/base/Faculty.java | 3 +- .../main/java/org/lumijiez/base/Group.java | 2 +- .../main/java/org/lumijiez/base/Student.java | 12 +- .../lumijiez/gui/StudentManagementGUI.java | 165 +++++++++--------- .../gui/forms/faculty/AddFacultyForm.java | 40 ++--- .../gui/forms/faculty/EditFacultyForm.java | 39 ++--- .../gui/forms/faculty/RemoveFacultyForm.java | 27 ++- .../gui/forms/faculty/ShowFacultyForm.java | 27 ++- .../faculty/ShowSpecialtyFacultyForm.java | 33 ++-- .../gui/forms/group/AddGroupForm.java | 32 ++-- .../gui/forms/group/DeleteGroupForm.java | 27 ++- .../gui/forms/group/EditGroupForm.java | 40 ++--- .../gui/forms/group/ShowGroupForm.java | 35 ++-- .../gui/forms/student/AddStudentForm.java | 50 +++--- .../gui/forms/student/DeleteStudentForm.java | 39 ++--- .../gui/forms/student/EditStudentForm.java | 70 ++++---- .../gui/forms/student/GradeStudentForm.java | 36 ++-- .../forms/student/GraduateStudentForm.java | 33 ++-- .../gui/forms/student/ShowStudentForm.java | 23 ++- .../forms/student/ShowStudentGradesForm.java | 27 ++- .../lumijiez/gui/loader/BatchGraduater.java | 114 +++++------- .../org/lumijiez/gui/loader/BatchLoader.java | 123 +++++-------- ...mboBoxRenderer.java => ComboRenderer.java} | 3 +- ...playerManager.java => DisplayHandler.java} | 12 +- .../org/lumijiez/managers/Supervisor.java | 30 ++-- 26 files changed, 483 insertions(+), 569 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml rename Lab2/src/main/java/org/lumijiez/gui/util/{ComboBoxRenderer.java => ComboRenderer.java} (81%) rename Lab2/src/main/java/org/lumijiez/gui/util/{DisplayerManager.java => DisplayHandler.java} (86%) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..1a7c662 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/Lab2/src/main/java/org/lumijiez/base/Faculty.java b/Lab2/src/main/java/org/lumijiez/base/Faculty.java index 64152f1..7b311b3 100644 --- a/Lab2/src/main/java/org/lumijiez/base/Faculty.java +++ b/Lab2/src/main/java/org/lumijiez/base/Faculty.java @@ -7,11 +7,10 @@ import java.util.ArrayList; import java.util.List; public class Faculty implements Serializable { - - private final List groups = new ArrayList<>(); private String name; private String abbreviation; private StudyField field; + private final List groups = new ArrayList<>(); public Faculty(String name, String abbreviation, StudyField field) { this.name = name; this.abbreviation = abbreviation; diff --git a/Lab2/src/main/java/org/lumijiez/base/Group.java b/Lab2/src/main/java/org/lumijiez/base/Group.java index 8502317..53cb51e 100644 --- a/Lab2/src/main/java/org/lumijiez/base/Group.java +++ b/Lab2/src/main/java/org/lumijiez/base/Group.java @@ -6,9 +6,9 @@ import java.util.List; public class Group implements Serializable { - private final List students = new ArrayList<>(); private String name; private Faculty faculty; + private final List students = new ArrayList<>(); public Group(String name) { this.name = name; diff --git a/Lab2/src/main/java/org/lumijiez/base/Student.java b/Lab2/src/main/java/org/lumijiez/base/Student.java index 63d5275..327ac0b 100644 --- a/Lab2/src/main/java/org/lumijiez/base/Student.java +++ b/Lab2/src/main/java/org/lumijiez/base/Student.java @@ -7,24 +7,16 @@ import java.util.List; public class Student implements Serializable { - private final List grades = new ArrayList<>(); - private boolean graduated = false; - private String name; - private String surname; - private String fullname; - private String email; - private Date enrollmentDate; - private Date dateOfBirth; - private Faculty faculty; - private Group group; + private boolean graduated = false; + private final List grades = new ArrayList<>(); public Student(String name, String surname, String email, Group group, Faculty faculty, Date birth, Date enrol) { this.name = name; diff --git a/Lab2/src/main/java/org/lumijiez/gui/StudentManagementGUI.java b/Lab2/src/main/java/org/lumijiez/gui/StudentManagementGUI.java index 119d38a..44c9286 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/StudentManagementGUI.java +++ b/Lab2/src/main/java/org/lumijiez/gui/StudentManagementGUI.java @@ -10,7 +10,7 @@ import org.lumijiez.gui.forms.group.ShowGroupForm; import org.lumijiez.gui.forms.student.*; import org.lumijiez.gui.loader.BatchGraduater; import org.lumijiez.gui.loader.BatchLoader; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -20,34 +20,22 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class StudentManagementGUI extends JFrame { - private static final JTextArea mainTextLabel = new javax.swing.JTextArea(); - private static Supervisor sv; - private final JMenuBar menuBar = new JMenuBar(); private final JMenu fileMenu = new JMenu(); private final JMenu studentMenu = new JMenu(); private final JMenu groupMenu = new JMenu(); private final JMenu facultyMenu = new JMenu(); - private final JScrollPane mainScrollPane = new javax.swing.JScrollPane(); + private final JMenuBar menuBar = new JMenuBar(); + private static final JTextArea mainTextLabel = new JTextArea(); + private static Supervisor sv; + private final JScrollPane mainScrollPane = new JScrollPane(); public StudentManagementGUI() { - sv = DataDeserializer.deserialize(); + sv = (DataDeserializer.deserialize()); this.setSize(650, 720); this.setTitle("Student Management System"); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int x = (screenSize.width - this.getWidth()) / 2; - int y = (screenSize.height - this.getHeight()) / 2; - this.setLocation(x, y); initComponents(); } - public static JTextArea getMainLabel() { - return mainTextLabel; - } - - public static Supervisor getSv() { - return sv; - } - private void initComponents() { JMenuItem loadBatchOption = new JMenuItem("Load as Batch", UIManager.getIcon("FileView.directoryIcon")); @@ -108,11 +96,10 @@ public class StudentManagementGUI extends JFrame { } }); - - loadBatchOption.addActionListener(this::loadBatchOptionActionPerformed); - graduateBatchOption.addActionListener(this::graduateBatchOptionActionPerformed); - saveAsOption.addActionListener(this::saveAsOptionActionPerformed); - saveAndExitOption.addActionListener(this::saveAndExitOptionActionPerformed); + loadBatchOption.addActionListener(this::loadBatchEvent); + graduateBatchOption.addActionListener(this::graduateBatchEvent); + saveAsOption.addActionListener(this::saveAsEvent); + saveAndExitOption.addActionListener(this::saveExitEvent); fileMenu.add(loadBatchOption); fileMenu.add(graduateBatchOption); @@ -122,15 +109,16 @@ public class StudentManagementGUI extends JFrame { menuBar.add(fileMenu); - showParticularStudentOption.addActionListener(this::showParticularStudentOptionActionPerformed); - showStudentGrade.addActionListener(this::showStudentGradeActionPerformed); - gradeStudentOption.addActionListener(this::gradeStudentOptionActionPerformed); - addStudentOption.addActionListener(this::addStudentOptionActionPerformed); - editStudentOption.addActionListener(this::editStudentOptionActionPerformed); - deleteStudentOption.addActionListener(this::deleteStudentOptionActionPerformed); - graduateStudent.addActionListener(this::graduateStudentOptionActionPerformed); - showEnrolled.addActionListener(this::showEnrolledOptionActionPerformed); - showGraduates.addActionListener(this::showGraduatesOptionActionPerformed); + showAllStudentsOption.addActionListener(this::showAllStudentsEvent); + showParticularStudentOption.addActionListener(this::showStudentEvent); + showStudentGrade.addActionListener(this::showGradeEvent); + gradeStudentOption.addActionListener(this::gradeStudentEvent); + addStudentOption.addActionListener(this::addStudentEvent); + editStudentOption.addActionListener(this::editStudentEvent); + deleteStudentOption.addActionListener(this::deleteStudentEvent); + graduateStudent.addActionListener(this::graduateStudentEvent); + showEnrolled.addActionListener(this::showEnrolledEvent); + showGraduates.addActionListener(this::showGraduatesEvent); studentMenu.add(showAllStudentsOption); studentMenu.add(showParticularStudentOption); @@ -146,9 +134,11 @@ public class StudentManagementGUI extends JFrame { menuBar.add(studentMenu); - showParticularGroupOption.addActionListener(this::showParticularGroupOptionActionPerformed); - addGroupOption.addActionListener(this::addGroupOptionActionPerformed); - editGroupOption.addActionListener(this::editGroupOptionActionPerformed); + showAllGroupsOption.addActionListener(this::showAllGroupsEvent); + showParticularGroupOption.addActionListener(this::showGroupEvent); + addGroupOption.addActionListener(this::addGroupEvent); + editGroupOption.addActionListener(this::editGroupEvent); + deleteGroupOption.addActionListener(this::deleteGroupEvent); groupMenu.add(showAllGroupsOption); groupMenu.add(showParticularGroupOption); @@ -159,15 +149,12 @@ public class StudentManagementGUI extends JFrame { menuBar.add(groupMenu); - showAllGroupsOption.addActionListener(this::showAllGroupsOptionActionPerformed); - showAllStudentsOption.addActionListener(this::showAllStudentsOptionActionPerformed); - showAllFacultiesOption.addActionListener(this::showAllFacultiesOptionActionPerformed); - showParticularFacultyOption.addActionListener(this::showParticularFacultyOptionActionPerformed); - showFacultyBySpecialtyOption.addActionListener(this::showFacultySpecialtyActionPerformed); - addFacultyOption.addActionListener(this::addFacultyOptionActionPerformed); - editFacultyOption.addActionListener(this::editFacultyOptionActionPerformed); - deleteGroupOption.addActionListener(this::deleteGroupOptionActionPerformed); - removeFacultyOption.addActionListener(this::removeFacultyOptionActionPerformed); + showAllFacultiesOption.addActionListener(this::showAllFacultiesEvent); + showParticularFacultyOption.addActionListener(this::showFacultyEvent); + showFacultyBySpecialtyOption.addActionListener(this::showFacultySpecEvent); + addFacultyOption.addActionListener(this::addFacultyEvent); + editFacultyOption.addActionListener(this::editFacultyEvent); + removeFacultyOption.addActionListener(this::deleteFacultyEvent); facultyMenu.add(showAllFacultiesOption); facultyMenu.add(showParticularFacultyOption); @@ -181,73 +168,77 @@ public class StudentManagementGUI extends JFrame { setJMenuBar(menuBar); - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)); + layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mainScrollPane, GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)); layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)); + layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mainScrollPane, GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)); pack(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int x = (screenSize.width - this.getWidth()) / 2; + int y = (screenSize.height - this.getHeight()) / 2; + this.setLocation(x, y); } - private void showFacultySpecialtyActionPerformed(ActionEvent actionEvent) { + private void showFacultySpecEvent(ActionEvent actionEvent) { ShowSpecialtyFacultyForm form = new ShowSpecialtyFacultyForm(sv, mainTextLabel); form.setVisible(true); } - private void graduateBatchOptionActionPerformed(ActionEvent actionEvent) { + private void graduateBatchEvent(ActionEvent actionEvent) { BatchGraduater picker = new BatchGraduater(sv); picker.setVisible(true); } - private void showGraduatesOptionActionPerformed(ActionEvent actionEvent) { + private void showGraduatesEvent(ActionEvent actionEvent) { if (checkStudent() && checkGroup() && checkFaculty()) { - DisplayerManager.displayGraduates(); + DisplayHandler.displayGraduates(); } } - private void showEnrolledOptionActionPerformed(ActionEvent actionEvent) { + private void showEnrolledEvent(ActionEvent actionEvent) { if (checkStudent() && checkGroup() && checkFaculty()) { - DisplayerManager.displayEnrolled(); + DisplayHandler.displayEnrolled(); } } - private void graduateStudentOptionActionPerformed(ActionEvent actionEvent) { + private void graduateStudentEvent(ActionEvent actionEvent) { if (checkStudent() && checkGroup() && checkFaculty()) { GraduateStudentForm form = new GraduateStudentForm(sv); form.setVisible(true); } } - private void showAllStudentsOptionActionPerformed(ActionEvent actionEvent) { + private void showAllStudentsEvent(ActionEvent actionEvent) { if (checkStudent() && checkGroup() && checkFaculty()) { - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); } } - private void showAllGroupsOptionActionPerformed(ActionEvent actionEvent) { + private void showAllGroupsEvent(ActionEvent actionEvent) { if (checkGroup() && checkFaculty()) { - DisplayerManager.displayGroups(); + DisplayHandler.displayGroups(); } } - private void deleteGroupOptionActionPerformed(ActionEvent actionEvent) { + private void deleteGroupEvent(ActionEvent actionEvent) { if (checkGroup() && checkFaculty()) { DeleteGroupForm form = new DeleteGroupForm(sv); form.setVisible(true); } } - private void loadBatchOptionActionPerformed(ActionEvent evt) { + private void loadBatchEvent(ActionEvent evt) { BatchLoader picker = new BatchLoader(sv); picker.setVisible(true); } - private void saveAndExitOptionActionPerformed(ActionEvent evt) { + private void saveExitEvent(ActionEvent evt) { int result = JOptionPane.showConfirmDialog( StudentManagementGUI.this, "Are you sure you want to exit?", @@ -262,99 +253,99 @@ public class StudentManagementGUI extends JFrame { } } - private void showAllFacultiesOptionActionPerformed(ActionEvent evt) { + private void showAllFacultiesEvent(ActionEvent evt) { if (checkFaculty()) { - DisplayerManager.displayFaculties(); + DisplayHandler.displayFaculties(); } } - private void saveAsOptionActionPerformed(ActionEvent evt) { + private void saveAsEvent(ActionEvent evt) { } - private void showParticularGroupOptionActionPerformed(ActionEvent evt) { + private void showGroupEvent(ActionEvent evt) { if (checkGroup() && checkFaculty()) { ShowGroupForm form = new ShowGroupForm(sv, mainTextLabel); form.setVisible(true); } } - private void addFacultyOptionActionPerformed(ActionEvent evt) { + private void addFacultyEvent(ActionEvent evt) { AddFacultyForm form = new AddFacultyForm(sv); form.setVisible(true); } - private void addStudentOptionActionPerformed(ActionEvent evt) { + private void addStudentEvent(ActionEvent evt) { if (checkGroup() && checkFaculty()) { AddStudentForm form = new AddStudentForm(sv); form.setVisible(true); } } - private void gradeStudentOptionActionPerformed(ActionEvent evt) { + private void gradeStudentEvent(ActionEvent evt) { if (checkStudent() && checkGroup() && checkFaculty()) { GradeStudentForm form = new GradeStudentForm(sv, mainTextLabel); form.setVisible(true); } } - private void editStudentOptionActionPerformed(ActionEvent evt) { + private void editStudentEvent(ActionEvent evt) { if (checkStudent() && checkGroup() && checkFaculty()) { EditStudentForm form = new EditStudentForm(sv); form.setVisible(true); } } - private void deleteStudentOptionActionPerformed(ActionEvent evt) { + private void deleteStudentEvent(ActionEvent evt) { if (checkStudent() && checkGroup() && checkFaculty()) { DeleteStudentForm form = new DeleteStudentForm(sv); form.setVisible(true); } } - private void showStudentGradeActionPerformed(ActionEvent evt) { + private void showGradeEvent(ActionEvent evt) { if (checkStudent() && checkGroup() && checkFaculty()) { ShowStudentGradesForm form = new ShowStudentGradesForm(sv, mainTextLabel); form.setVisible(true); } } - private void showParticularStudentOptionActionPerformed(ActionEvent evt) { + private void showStudentEvent(ActionEvent evt) { if (checkStudent() && checkGroup() && checkFaculty()) { ShowStudentForm form = new ShowStudentForm(sv, mainTextLabel); form.setVisible(true); } } - private void addGroupOptionActionPerformed(ActionEvent evt) { + private void addGroupEvent(ActionEvent evt) { if (checkFaculty()) { AddGroupForm form = new AddGroupForm(sv); form.setVisible(true); } } - private void editGroupOptionActionPerformed(ActionEvent evt) { + private void editGroupEvent(ActionEvent evt) { if (checkGroup() && checkFaculty()) { EditGroupForm form = new EditGroupForm(sv); form.setVisible(true); } } - private void showParticularFacultyOptionActionPerformed(ActionEvent evt) { + private void showFacultyEvent(ActionEvent evt) { if (checkFaculty()) { ShowFacultyForm form = new ShowFacultyForm(sv, mainTextLabel); form.setVisible(true); } } - private void editFacultyOptionActionPerformed(ActionEvent evt) { + private void editFacultyEvent(ActionEvent evt) { if (checkFaculty()) { EditFacultyForm form = new EditFacultyForm(sv); form.setVisible(true); } } - private void removeFacultyOptionActionPerformed(ActionEvent evt) { + private void deleteFacultyEvent(ActionEvent evt) { if (checkFaculty()) { RemoveFacultyForm form = new RemoveFacultyForm(sv); form.setVisible(true); @@ -362,7 +353,7 @@ public class StudentManagementGUI extends JFrame { } private boolean checkFaculty() { - if (sv.getFm().getFaculties().isEmpty()) { + if (sv.facultyManager().getFaculties().isEmpty()) { JOptionPane.showMessageDialog(null, "Configure a faculty!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); return false; } @@ -370,7 +361,7 @@ public class StudentManagementGUI extends JFrame { } private boolean checkGroup() { - if (sv.getFm().getGm().getGroups().isEmpty()) { + if (sv.groupManager().getGroups().isEmpty()) { JOptionPane.showMessageDialog(null, "Configure a group!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); return false; } @@ -378,10 +369,18 @@ public class StudentManagementGUI extends JFrame { } private boolean checkStudent() { - if (sv.getFm().getGm().getSm().getStudents().isEmpty()) { + if (sv.studentManager().getStudents().isEmpty()) { JOptionPane.showMessageDialog(null, "No students in database!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); return false; } return true; } + + public static JTextArea getMainLabel() { + return mainTextLabel; + } + + public static Supervisor getSv() { + return sv; + } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/AddFacultyForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/AddFacultyForm.java index ddb8033..8600f43 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/AddFacultyForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/AddFacultyForm.java @@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.faculty; import org.lumijiez.base.Faculty; import org.lumijiez.enums.StudyField; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -13,16 +13,16 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class AddFacultyForm extends JFrame { - private final Supervisor sv; private final JLabel titleLabel = new JLabel(); - private final JComboBox specialtyCombo = new JComboBox<>(); - private final JTextField nameField = new JTextField(); - private final JButton submitButton = new JButton(); - private final JButton cancelButton = new JButton(); private final JLabel nameLabel = new JLabel(); - private final JTextField abbreviationField = new JTextField(); private final JLabel abbreviationLabel = new JLabel(); private final JLabel specialtyLabel = new JLabel(); + private final JButton submitButton = new JButton(); + private final JButton cancelButton = new JButton(); + private final JTextField nameField = new JTextField(); + private final JTextField abbreviationField = new JTextField(); + private final JComboBox specialtyCombo = new JComboBox<>(); + private final Supervisor sv; public AddFacultyForm(Supervisor sv) { this.sv = sv; @@ -33,7 +33,7 @@ public class AddFacultyForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Add a Faculty"); titleLabel.setText("Add a new faculty"); @@ -45,14 +45,14 @@ public class AddFacultyForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - specialtyCombo.addActionListener(this::specialtyComboActionPerformed); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - - ComboBoxRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); + ComboRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); abbreviationField.setText(StudyField.getAbbrevFromString(Objects.requireNonNull(specialtyCombo.getSelectedItem()).toString())); + specialtyCombo.addActionListener(this::specialtyComboEvent); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); + GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -109,25 +109,23 @@ public class AddFacultyForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { String name = nameField.getText(); String abbreviation = abbreviationField.getText(); StudyField specialty = StudyField.getEnum(Objects.requireNonNull(specialtyCombo.getSelectedItem()).toString()); if (!name.isEmpty()) { Faculty newFaculty = new Faculty(name, abbreviation, specialty); sv.addFaculty(newFaculty); - DisplayerManager.displayFaculties(); + DisplayHandler.displayFaculties(); this.dispose(); - } else { - JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); - } + } else JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); } - private void specialtyComboActionPerformed(ActionEvent evt) { + private void specialtyComboEvent(ActionEvent evt) { abbreviationField.setText(StudyField.getAbbrevFromString(Objects.requireNonNull(specialtyCombo.getSelectedItem()).toString())); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/EditFacultyForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/EditFacultyForm.java index 0bf561b..926f7ad 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/EditFacultyForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/EditFacultyForm.java @@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.faculty; import org.lumijiez.base.Faculty; import org.lumijiez.enums.StudyField; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -13,15 +13,15 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class EditFacultyForm extends JFrame { - private final JTextField abbreviationField = new JTextField(); private final JLabel abbreviationLabel = new JLabel(); - private final JButton cancelButton = new JButton(); private final JLabel facultyLabel = new JLabel(); - private final JTextField nameField = new JTextField(); private final JLabel nameLabel = new JLabel(); private final JLabel specialtyLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JTextField abbreviationField = new JTextField(); + private final JTextField nameField = new JTextField(); private final JComboBox facultyCombo = new JComboBox<>(); private final JComboBox specialtyCombo = new JComboBox<>(); private final Supervisor sv; @@ -35,7 +35,7 @@ public class EditFacultyForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Edit a Faculty"); titleLabel.setText("Edit a faculty"); @@ -47,16 +47,16 @@ public class EditFacultyForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - submitButton.addActionListener(this::submitButtonActionPerformed); - specialtyCombo.addActionListener(this::specialtyComboActionPerformed); - facultyCombo.addActionListener(this::facultyComboActionPerformed); + cancelButton.addActionListener(this::cancelEvent); + submitButton.addActionListener(this::submitEvent); + specialtyCombo.addActionListener(this::specialtyComboEvent); + facultyCombo.addActionListener(this::facultyComboEvent); + + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); specialtyCombo.setSelectedItem(((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).getField()); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); - ComboBoxRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); - GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -87,7 +87,6 @@ public class EditFacultyForm extends JFrame { .addComponent(submitButton))) .addComponent(nameLabel)))))) .addContainerGap(24, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -121,24 +120,24 @@ public class EditFacultyForm extends JFrame { this.setLocation(x, y); } - private void facultyComboActionPerformed(ActionEvent actionEvent) { + private void facultyComboEvent(ActionEvent actionEvent) { specialtyCombo.setSelectedItem(((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).getField()); } - private void specialtyComboActionPerformed(ActionEvent actionEvent) { + private void specialtyComboEvent(ActionEvent actionEvent) { abbreviationField.setText(((StudyField) Objects.requireNonNull(specialtyCombo.getSelectedItem())).getAbbreviation()); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).setName(nameField.getText()); ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).setAbbreviation(abbreviationField.getText()); ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).setField(((StudyField) Objects.requireNonNull(specialtyCombo.getSelectedItem()))); - DisplayerManager.displayFaculties(); + DisplayHandler.displayFaculties(); sv.getLogger().logOperation("Faculty edited : " + ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).getName()); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/RemoveFacultyForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/RemoveFacultyForm.java index 4bed819..2a63d19 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/RemoveFacultyForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/RemoveFacultyForm.java @@ -1,9 +1,9 @@ package org.lumijiez.gui.forms.faculty; import org.lumijiez.base.Faculty; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -11,13 +11,12 @@ import java.awt.*; import java.awt.event.ActionEvent; public class RemoveFacultyForm extends JFrame { - - private final Supervisor sv; - private final JButton cancelButton = new JButton(); - private final JComboBox facultyCombo = new JComboBox<>(); private final JLabel facultyLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox facultyCombo = new JComboBox<>(); + private final Supervisor sv; public RemoveFacultyForm(Supervisor sv) { this.sv = sv; @@ -28,7 +27,7 @@ public class RemoveFacultyForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Remove a Faculty"); titleLabel.setText("Remove a faculty"); @@ -38,10 +37,10 @@ public class RemoveFacultyForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -83,13 +82,13 @@ public class RemoveFacultyForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { sv.deleteFaculty(((Faculty) facultyCombo.getSelectedItem())); - DisplayerManager.displayFaculties(); + DisplayHandler.displayFaculties(); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowFacultyForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowFacultyForm.java index 601e0fb..2ac78db 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowFacultyForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowFacultyForm.java @@ -2,7 +2,7 @@ package org.lumijiez.gui.forms.faculty; import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -11,15 +11,13 @@ import java.awt.*; import java.awt.event.ActionEvent; public class ShowFacultyForm extends JFrame { - - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox facultyCombo = new JComboBox<>(); - private final JLabel facultyLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); - + private final JLabel facultyLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox facultyCombo = new JComboBox<>(); private final Supervisor sv; + private final JTextArea mainTextLabel; public ShowFacultyForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -31,7 +29,7 @@ public class ShowFacultyForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Show a Faculty"); titleLabel.setText("Show a faculty"); @@ -41,10 +39,10 @@ public class ShowFacultyForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -66,7 +64,6 @@ public class ShowFacultyForm extends JFrame { .addComponent(submitButton)) .addComponent(facultyCombo, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE))))) .addContainerGap(27, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -88,7 +85,7 @@ public class ShowFacultyForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { StringBuilder builder = new StringBuilder(); Faculty fac = (Faculty) facultyCombo.getSelectedItem(); assert fac != null; @@ -104,7 +101,7 @@ public class ShowFacultyForm extends JFrame { this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowSpecialtyFacultyForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowSpecialtyFacultyForm.java index 2a9ba0d..49a0c4d 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowSpecialtyFacultyForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/faculty/ShowSpecialtyFacultyForm.java @@ -2,7 +2,7 @@ package org.lumijiez.gui.forms.faculty; import org.lumijiez.base.Faculty; import org.lumijiez.enums.StudyField; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -11,15 +11,13 @@ import java.awt.*; import java.awt.event.ActionEvent; public class ShowSpecialtyFacultyForm extends JFrame { - - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox specialtyCombo = new JComboBox<>(); - private final JLabel facultyLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); - + private final JLabel facultyLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox specialtyCombo = new JComboBox<>(); private final Supervisor sv; + private final JTextArea mainTextLabel; public ShowSpecialtyFacultyForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -31,7 +29,7 @@ public class ShowSpecialtyFacultyForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Show a Faculty by Specialty"); titleLabel.setText("Show a faculty"); @@ -41,10 +39,10 @@ public class ShowSpecialtyFacultyForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); + ComboRenderer.setRenderer(specialtyCombo, StudyField.getAllEnums().toArray(new StudyField[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -66,7 +64,6 @@ public class ShowSpecialtyFacultyForm extends JFrame { .addComponent(submitButton)) .addComponent(specialtyCombo, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE))))) .addContainerGap(27, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -88,7 +85,7 @@ public class ShowSpecialtyFacultyForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { StringBuilder builder = new StringBuilder(); StudyField fac = (StudyField) specialtyCombo.getSelectedItem(); assert fac != null; @@ -96,17 +93,15 @@ public class ShowSpecialtyFacultyForm extends JFrame { builder.append("Specialty: ").append(fac.getName()).append("\n"); builder.append("==========\n"); builder.append("Faculties: ").append("\n"); - for (Faculty fc : sv.getFm().getFaculties()) { - if (fc.getField().equals(fac)) { + for (Faculty fc : sv.facultyManager().getFaculties()) + if (fc.getField().equals(fac)) builder.append(fc.getName()).append("\n").append("==========\n"); - } - } builder.append("============================================================"); mainTextLabel.setText(builder.toString()); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/group/AddGroupForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/group/AddGroupForm.java index 655619c..87d0c12 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/group/AddGroupForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/group/AddGroupForm.java @@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.group; import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -13,15 +13,14 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class AddGroupForm extends JFrame { - - private final Supervisor sv; private final JLabel titleLabel = new JLabel(); - private final JTextField nameField = new JTextField(); + private final JLabel nameLabel = new JLabel(); + private final JLabel facultyLabel = new JLabel(); private final JButton submitButton = new JButton(); private final JButton cancelButton = new JButton(); - private final JLabel nameLabel = new JLabel(); + private final JTextField nameField = new JTextField(); private final JComboBox facultyCombo = new JComboBox<>(); - private final JLabel facultyLabel = new JLabel(); + private final Supervisor sv; public AddGroupForm(Supervisor sv) { this.sv = sv; @@ -32,7 +31,7 @@ public class AddGroupForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Add a Group"); titleLabel.setText("Add a new group"); @@ -43,10 +42,10 @@ public class AddGroupForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -71,7 +70,6 @@ public class AddGroupForm extends JFrame { .addGap(38, 38, 38) .addComponent(titleLabel))) .addContainerGap(29, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -97,19 +95,17 @@ public class AddGroupForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { if (!nameField.getText().isEmpty()) { Group gr = new Group(nameField.getText()); Faculty fac = ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())); sv.addGroup(gr, fac); - DisplayerManager.displayGroups(); + DisplayHandler.displayGroups(); this.dispose(); - } else { - JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); - } + } else JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/group/DeleteGroupForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/group/DeleteGroupForm.java index da5edd9..ba644bc 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/group/DeleteGroupForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/group/DeleteGroupForm.java @@ -1,9 +1,9 @@ package org.lumijiez.gui.forms.group; import org.lumijiez.base.Group; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -11,12 +11,12 @@ import java.awt.*; import java.awt.event.ActionEvent; public class DeleteGroupForm extends JFrame { - private final Supervisor sv; - private final JButton cancelButton = new JButton(); - private final JComboBox groupCombo = new JComboBox<>(); private final JLabel groupLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox groupCombo = new JComboBox<>(); + private final Supervisor sv; public DeleteGroupForm(Supervisor sv) { this.sv = sv; @@ -27,7 +27,7 @@ public class DeleteGroupForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Delete a Group"); titleLabel.setText("Delete a group"); @@ -37,10 +37,10 @@ public class DeleteGroupForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(groupCombo, sv.getFm().getGm().getGroups().toArray(new Group[0])); + ComboRenderer.setRenderer(groupCombo, sv.groupManager().getGroups().toArray(new Group[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -62,7 +62,6 @@ public class DeleteGroupForm extends JFrame { .addGap(54, 54, 54) .addComponent(titleLabel))) .addContainerGap(29, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -84,13 +83,13 @@ public class DeleteGroupForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { sv.deleteGroup(((Group) groupCombo.getSelectedItem())); - DisplayerManager.displayGroups(); + DisplayHandler.displayGroups(); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/group/EditGroupForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/group/EditGroupForm.java index b158ecb..4294256 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/group/EditGroupForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/group/EditGroupForm.java @@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.group; import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -13,17 +13,16 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class EditGroupForm extends JFrame { - - private final Supervisor sv; - private final JButton cancelButton = new JButton(); - private final JComboBox facultyCombo = new JComboBox<>(); - private final JLabel facultyLabel = new JLabel(); - private final JComboBox groupCombo = new JComboBox<>(); - private final JLabel groupLabel = new JLabel(); - private final JTextField nameField = new JTextField(); - private final JLabel nameLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JLabel facultyLabel = new JLabel(); + private final JLabel groupLabel = new JLabel(); + private final JLabel nameLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JTextField nameField = new JTextField(); + private final JComboBox facultyCombo = new JComboBox<>(); + private final JComboBox groupCombo = new JComboBox<>(); + private final Supervisor sv; public EditGroupForm(Supervisor sv) { this.sv = sv; @@ -34,7 +33,7 @@ public class EditGroupForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Edit a Group"); titleLabel.setText("Edit a group"); @@ -46,11 +45,11 @@ public class EditGroupForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); - ComboBoxRenderer.setRenderer(groupCombo, sv.getFm().getGm().getGroups().toArray(new Group[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(groupCombo, sv.groupManager().getGroups().toArray(new Group[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -79,7 +78,6 @@ public class EditGroupForm extends JFrame { .addComponent(facultyCombo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(submitButton)))) .addContainerGap(34, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -111,15 +109,15 @@ public class EditGroupForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { Faculty fac = ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())); Group gr = (Group) Objects.requireNonNull(groupCombo.getSelectedItem()); sv.editGroup(gr, nameField.getText(), fac); - DisplayerManager.displayGroups(); + DisplayHandler.displayGroups(); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/group/ShowGroupForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/group/ShowGroupForm.java index 7ae3efb..ff4fa0f 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/group/ShowGroupForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/group/ShowGroupForm.java @@ -2,7 +2,7 @@ package org.lumijiez.gui.forms.group; import org.lumijiez.base.Group; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -13,14 +13,13 @@ import java.util.Objects; public class ShowGroupForm extends JFrame { - - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox groupCombo = new JComboBox<>(); - private final JLabel groupLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JLabel groupLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox groupCombo = new JComboBox<>(); private final Supervisor sv; + private final JTextArea mainTextLabel; public ShowGroupForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -32,7 +31,7 @@ public class ShowGroupForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Show a Group"); titleLabel.setText("Show a group"); @@ -42,10 +41,10 @@ public class ShowGroupForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(groupCombo, sv.getFm().getGm().getGroups().toArray(new Group[0])); + ComboRenderer.setRenderer(groupCombo, sv.groupManager().getGroups().toArray(new Group[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -67,7 +66,6 @@ public class ShowGroupForm extends JFrame { .addGap(47, 47, 47) .addComponent(titleLabel))) .addContainerGap(24, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -89,23 +87,20 @@ public class ShowGroupForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { StringBuilder text = new StringBuilder(); Group gr = (Group) Objects.requireNonNull(groupCombo.getSelectedItem()); - text.append("======================= Group Info =========================\n"); text.append("=================== Group: ").append(gr.getName()).append("=====================\n"); - - for (Student student : gr.getStudents()) { + for (Student student : gr.getStudents()) text.append("Name: ").append(student.getName()).append("\nEmail: ").append(student.getEmail()) - .append("\nEnrol date: ").append(student.getEnrollmentDate()); - text.append("\n===============================================\n"); - } + .append("\nEnrol date: ").append(student.getEnrollmentDate()) + .append("\n===============================================\n"); mainTextLabel.setText(text.toString()); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/AddStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/AddStudentForm.java index 6f4473f..cec5391 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/AddStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/AddStudentForm.java @@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -15,32 +15,32 @@ import java.util.Date; import java.util.Objects; public class AddStudentForm extends JFrame { - private final Supervisor sv; private final JLabel titleLabel = new JLabel(); - private final JComboBox groupCombo = new JComboBox<>(); - private final JTextField nameField = new JTextField(); - private final JButton submitButton = new JButton(); - private final JButton cancelButton = new JButton(); private final JLabel nameLabel = new JLabel(); - private final JTextField surnameField = new JTextField(); - private final JTextField emailField = new JTextField(); private final JLabel surnameLabel = new JLabel(); private final JLabel emailLabel = new JLabel(); - private final JComboBox facultyCombo = new JComboBox<>(); private final JLabel groupLabel = new JLabel(); private final JLabel facultyLabel = new JLabel(); - private final JComboBox birthYearField = new JComboBox<>(); - private final JComboBox birthDayField = new JComboBox<>(); - private final JComboBox birthMonthField = new JComboBox<>(); private final JLabel birthYearLabel = new JLabel(); private final JLabel birthDayLabel = new JLabel(); private final JLabel birthMonthLabel = new JLabel(); private final JLabel enrolDayLabel = new JLabel(); + private final JLabel enrolMonthLabel = new JLabel(); + private final JLabel enrolYearLabel = new JLabel(); + private final JButton submitButton = new JButton(); + private final JButton cancelButton = new JButton(); + private final JTextField nameField = new JTextField(); + private final JTextField surnameField = new JTextField(); + private final JTextField emailField = new JTextField(); + private final JComboBox groupCombo = new JComboBox<>(); + private final JComboBox facultyCombo = new JComboBox<>(); + private final JComboBox birthYearField = new JComboBox<>(); + private final JComboBox birthDayField = new JComboBox<>(); + private final JComboBox birthMonthField = new JComboBox<>(); private final JComboBox enrolDayField = new JComboBox<>(); private final JComboBox enrolMonthField = new JComboBox<>(); private final JComboBox enrolYearField = new JComboBox<>(); - private final JLabel enrolMonthLabel = new JLabel(); - private final JLabel enrolYearLabel = new JLabel(); + private final Supervisor sv; public AddStudentForm(Supervisor sv) { this.sv = sv; @@ -76,7 +76,7 @@ public class AddStudentForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Add a Student"); titleLabel.setText("Add a new student"); @@ -96,11 +96,11 @@ public class AddStudentForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); - ComboBoxRenderer.setRenderer(groupCombo, sv.getFm().getGm().getGroups().toArray(new Group[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(groupCombo, sv.groupManager().getGroups().toArray(new Group[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -240,11 +240,11 @@ public class AddStudentForm extends JFrame { this.setLocation(x, y); } - private void cancelButtonActionPerformed(ActionEvent actionEvent) { + private void cancelEvent(ActionEvent actionEvent) { this.dispose(); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { String name = nameField.getText(); String surname = surnameField.getText(); String email = emailField.getText(); @@ -255,11 +255,9 @@ public class AddStudentForm extends JFrame { if (!name.isEmpty() && !surname.isEmpty() && !email.isEmpty()) { sv.addStudent(name, surname, email, group, faculty, birthDate, enrolDate); - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); - } else { - JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); - } + } else JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null); } private Group getSelectedGroup() { diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/DeleteStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/DeleteStudentForm.java index 954c83f..f304caf 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/DeleteStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/DeleteStudentForm.java @@ -1,9 +1,9 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -12,12 +12,12 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class DeleteStudentForm extends JFrame { - private final Supervisor sv; - private final JButton cancelButton = new JButton(); - private final JComboBox studentCombo = new JComboBox<>(); - private final JLabel studentLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JLabel studentLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox studentCombo = new JComboBox<>(); + private final Supervisor sv; public DeleteStudentForm(Supervisor sv) { this.sv = sv; @@ -28,20 +28,20 @@ public class DeleteStudentForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Delete a Student"); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); - - studentLabel.setText("Student:"); - submitButton.setText("Submit"); - cancelButton.setText("Cancel"); - titleLabel.setText("Delete Student"); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getStudents().toArray(new Student[0])); ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + cancelButton.setText("Cancel"); + titleLabel.setText("Delete Student"); + submitButton.setText("Submit"); + studentLabel.setText("Student:"); + + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -63,7 +63,6 @@ public class DeleteStudentForm extends JFrame { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(titleLabel) .addGap(51, 51, 51))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -85,14 +84,14 @@ public class DeleteStudentForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); sv.deleteStudent(student); - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/EditStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/EditStudentForm.java index d51c190..62cf46e 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/EditStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/EditStudentForm.java @@ -3,9 +3,9 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -17,32 +17,32 @@ import java.util.Objects; public class EditStudentForm extends JFrame { private final JLabel bdayLabel = new JLabel(); + private final JLabel bmonthLabel = new JLabel(); + private final JLabel byearLabel = new JLabel(); + private final JLabel edayLabel = new JLabel(); + private final JLabel emailLabel = new JLabel(); + private final JLabel emonthLabel = new JLabel(); + private final JLabel eyearLabel = new JLabel(); + private final JLabel facultyLabel = new JLabel(); + private final JLabel groupLabel = new JLabel(); + private final JLabel nameLabel = new JLabel(); + private final JLabel studentLabel = new JLabel(); + private final JLabel surnameLabel = new JLabel(); + private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JTextField nameField = new JTextField(); + private final JTextField emailField = new JTextField(); + private final JTextField surnameField = new JTextField(); + private final JComboBox facultyCombo = new JComboBox<>(); + private final JComboBox groupCombo = new JComboBox<>(); + private final JComboBox studentCombo = new JComboBox<>(); private final JComboBox birthdayCombo; private final JComboBox birthmonthCombo; private final JComboBox birthyearCombo; - private final JLabel bmonthLabel = new JLabel(); - private final JLabel byearLabel = new JLabel(); - private final JButton cancelButton = new JButton(); - private final JLabel edayLabel = new JLabel(); - private final JTextField emailField = new JTextField(); - private final JLabel emailLabel = new JLabel(); - private final JLabel emonthLabel = new JLabel(); private final JComboBox enroldayCombo; private final JComboBox enrolmonthCombo; private final JComboBox enrolyearCombo; - private final JLabel eyearLabel = new JLabel(); - private final JComboBox facultyCombo = new JComboBox<>(); - private final JLabel facultyLabel = new JLabel(); - private final JComboBox groupCombo = new JComboBox<>(); - private final JLabel groupLabel = new JLabel(); - private final JTextField nameField = new JTextField(); - private final JLabel nameLabel = new JLabel(); - private final JComboBox studentCombo = new JComboBox<>(); - private final JLabel studentLabel = new JLabel(); - private final JButton submitButton = new JButton(); - private final JTextField surnameField = new JTextField(); - private final JLabel surnameLabel = new JLabel(); - private final JLabel titleLabel = new JLabel(); private final Supervisor sv; public EditStudentForm(Supervisor sv) { @@ -76,7 +76,7 @@ public class EditStudentForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Edit a Student"); titleLabel.setText("Edit a student"); @@ -95,19 +95,18 @@ public class EditStudentForm extends JFrame { edayLabel.setText("New enrol day:"); cancelButton.setText("Cancel"); - studentCombo.addActionListener(this::studentComboActionPerformed); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + studentCombo.addActionListener(this::studentComboEvent); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); ComponentDecorator.submitAndCancel(submitButton, cancelButton); - ComboBoxRenderer.setRenderer(facultyCombo, sv.getFm().getFaculties().toArray(new Faculty[0])); - ComboBoxRenderer.setRenderer(groupCombo, sv.getFm().getGm().getGroups().toArray(new Group[0])); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); + ComboRenderer.setRenderer(facultyCombo, sv.facultyManager().getFaculties().toArray(new Faculty[0])); + ComboRenderer.setRenderer(groupCombo, sv.groupManager().getGroups().toArray(new Group[0])); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getStudents().toArray(new Student[0])); Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); facultyCombo.setSelectedItem(student.getFaculty()); - System.out.println("lol:" + facultyCombo.getSelectedItem()); groupCombo.setSelectedItem(student.getGroup()); emailField.setText(student.getEmail()); nameField.setText(student.getName()); @@ -250,11 +249,11 @@ public class EditStudentForm extends JFrame { this.setLocation(x, y); } - private void cancelButtonActionPerformed(ActionEvent actionEvent) { + private void cancelEvent(ActionEvent actionEvent) { this.dispose(); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { String name = nameField.getText(); String surname = surnameField.getText(); String email = emailField.getText(); @@ -282,15 +281,14 @@ public class EditStudentForm extends JFrame { Date birthDate = birthCalendar.getTime(); Date enrolDate = enrolCalendar.getTime(); - if (!name.isEmpty() && !surname.isEmpty() && !email.isEmpty()) { + if (!name.isEmpty() && !surname.isEmpty() && !email.isEmpty()) sv.editStudent(student, name, surname, email, group, faculty, birthDate, enrolDate); - } - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); } - private void studentComboActionPerformed(ActionEvent evt) { + private void studentComboEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); facultyCombo.setSelectedItem(student.getFaculty()); groupCombo.setSelectedItem(student.getGroup()); diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/GradeStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/GradeStudentForm.java index 427a7e0..0c186e3 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/GradeStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/GradeStudentForm.java @@ -3,7 +3,7 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Grade; import org.lumijiez.base.Student; import org.lumijiez.enums.Subjects; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -13,19 +13,18 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class GradeStudentForm extends JFrame { - private final Supervisor sv; - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox subjectCombo = new JComboBox<>(); + Integer[] grades = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; private final JLabel gradeLabel = new JLabel(); - private final JComboBox studentCombo = new JComboBox<>(); private final JLabel studentLabel = new JLabel(); private final JLabel subjectLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); - Integer[] grades = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox subjectCombo = new JComboBox<>(); + private final JComboBox studentCombo = new JComboBox<>(); private final JComboBox gradeCombo = new JComboBox<>(grades); - + private final Supervisor sv; + private final JTextArea mainTextLabel; public GradeStudentForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -37,7 +36,7 @@ public class GradeStudentForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Grade A Student"); titleLabel.setText("Grade a student"); @@ -49,11 +48,11 @@ public class GradeStudentForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); - ComboBoxRenderer.setRenderer(subjectCombo, Subjects.values()); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); + ComboRenderer.setRenderer(subjectCombo, Subjects.values()); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getStudents().toArray(new Student[0])); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -88,7 +87,6 @@ public class GradeStudentForm extends JFrame { .addGap(129, 129, 129) .addComponent(titleLabel) .addGap(0, 0, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -117,7 +115,7 @@ public class GradeStudentForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); Subjects subject = Subjects.getEnum(Objects.requireNonNull(subjectCombo.getSelectedItem()).toString()); int intGrade = (Integer) Objects.requireNonNull(gradeCombo.getSelectedItem()); @@ -127,15 +125,13 @@ public class GradeStudentForm extends JFrame { StringBuilder builder = new StringBuilder(); builder.append("============================================================\n"); builder.append("Grades for ").append(student.getFullname()).append(" from ").append(student.getGroup().getName()).append(":\n"); - for (Grade gr : student.getGrades()) { - builder.append(gr.getSubject()).append(": ").append(gr.getGrade()).append("\n"); - } + for (Grade gr : student.getGrades()) builder.append(gr.getSubject()).append(": ").append(gr.getGrade()).append("\n"); builder.append("============================================================\n"); mainTextLabel.setText(builder.toString()); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/GraduateStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/GraduateStudentForm.java index 55a867e..d4b6bd8 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/GraduateStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/GraduateStudentForm.java @@ -1,9 +1,9 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -12,12 +12,11 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class GraduateStudentForm extends JFrame { - private final JButton cancelButton = new JButton(); - private final JComboBox studentCombo = new JComboBox<>(); private final JLabel studentLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); - + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox studentCombo = new JComboBox<>(); private final Supervisor sv; public GraduateStudentForm(Supervisor sv) { @@ -32,20 +31,17 @@ public class GraduateStudentForm extends JFrame { titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Graduate a Student"); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getEnrolled().toArray(new Student[0])); + + ComponentDecorator.submitAndCancel(submitButton, cancelButton); - studentLabel.setText("Student:"); submitButton.setText("Submit"); cancelButton.setText("Cancel"); titleLabel.setText("Graduate a Student"); + studentLabel.setText("Student:"); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - submitButton.addActionListener(this::submitButtonActionPerformed); - - submitButton.setBackground(new Color(204, 255, 204)); - cancelButton.setBackground(new Color(255, 204, 204)); - - ComponentDecorator.submitAndCancel(submitButton, cancelButton); + submitButton.addActionListener(this::cancelEvent); + cancelButton.addActionListener(this::submitEvent); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -67,7 +63,6 @@ public class GraduateStudentForm extends JFrame { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(titleLabel) .addGap(51, 51, 51))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -89,14 +84,14 @@ public class GraduateStudentForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); student.setGraduated(true); - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { this.dispose(); } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentForm.java index 6fa849c..b1df47b 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentForm.java @@ -1,7 +1,7 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -11,13 +11,13 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class ShowStudentForm extends JFrame { - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox studentCombo = new JComboBox<>(); private final JLabel studentLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox studentCombo = new JComboBox<>(); private final Supervisor sv; + private final JTextArea mainTextLabel; public ShowStudentForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -29,7 +29,7 @@ public class ShowStudentForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Show A Student"); titleLabel.setText("Show Student"); @@ -39,10 +39,10 @@ public class ShowStudentForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getStudents().toArray(new Student[0])); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); + cancelButton.addActionListener(this::cancelEvent); + submitButton.addActionListener(this::submitEvent); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -66,7 +66,6 @@ public class ShowStudentForm extends JFrame { .addGap(52, 52, 52) .addComponent(titleLabel))) .addContainerGap(23, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -88,7 +87,7 @@ public class ShowStudentForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); StringBuilder text = new StringBuilder(); @@ -106,7 +105,7 @@ public class ShowStudentForm extends JFrame { this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentGradesForm.java b/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentGradesForm.java index e6aa791..f13fc52 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentGradesForm.java +++ b/Lab2/src/main/java/org/lumijiez/gui/forms/student/ShowStudentGradesForm.java @@ -2,7 +2,7 @@ package org.lumijiez.gui.forms.student; import org.lumijiez.base.Grade; import org.lumijiez.base.Student; -import org.lumijiez.gui.util.ComboBoxRenderer; +import org.lumijiez.gui.util.ComboRenderer; import org.lumijiez.gui.util.ComponentDecorator; import org.lumijiez.managers.Supervisor; @@ -12,14 +12,13 @@ import java.awt.event.ActionEvent; import java.util.Objects; public class ShowStudentGradesForm extends JFrame { - - private final JTextArea mainTextLabel; - private final JButton cancelButton = new JButton(); - private final JComboBox studentCombo = new JComboBox<>(); private final JLabel studentLabel = new JLabel(); - private final JButton submitButton = new JButton(); private final JLabel titleLabel = new JLabel(); + private final JButton cancelButton = new JButton(); + private final JButton submitButton = new JButton(); + private final JComboBox studentCombo = new JComboBox<>(); private final Supervisor sv; + private final JTextArea mainTextLabel; public ShowStudentGradesForm(Supervisor sv, JTextArea mainTextLabel) { this.sv = sv; @@ -31,7 +30,7 @@ public class ShowStudentGradesForm extends JFrame { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18)); + titleLabel.setFont(new Font("sansserif", Font.PLAIN, 18)); setTitle("Show Student Grades"); titleLabel.setText("Show Grades"); @@ -41,10 +40,10 @@ public class ShowStudentGradesForm extends JFrame { ComponentDecorator.submitAndCancel(submitButton, cancelButton); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); + ComboRenderer.setRenderer(studentCombo, sv.studentManager().getStudents().toArray(new Student[0])); - ComboBoxRenderer.setRenderer(studentCombo, sv.getFm().getGm().getSm().getStudents().toArray(new Student[0])); + cancelButton.addActionListener(this::cancelEvent); + submitButton.addActionListener(this::submitEvent); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -68,7 +67,6 @@ public class ShowStudentGradesForm extends JFrame { .addGap(50, 50, 50) .addComponent(titleLabel))) .addContainerGap(30, Short.MAX_VALUE))); - layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -90,20 +88,19 @@ public class ShowStudentGradesForm extends JFrame { this.setLocation(x, y); } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { Student student = ((Student) Objects.requireNonNull(studentCombo.getSelectedItem())); StringBuilder builder = new StringBuilder(); builder.append("============================================================\n"); builder.append("Grades for ").append(student.getFullname()).append(" from ").append(student.getGroup().getName()).append(":\n"); - for (Grade grade : student.getGrades()) { + for (Grade grade : student.getGrades()) builder.append(grade.getSubject()).append(": ").append(grade.getGrade()).append("\n"); - } builder.append("============================================================\n"); mainTextLabel.setText(builder.toString()); this.dispose(); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } diff --git a/Lab2/src/main/java/org/lumijiez/gui/loader/BatchGraduater.java b/Lab2/src/main/java/org/lumijiez/gui/loader/BatchGraduater.java index 0c5d31d..1c20943 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/loader/BatchGraduater.java +++ b/Lab2/src/main/java/org/lumijiez/gui/loader/BatchGraduater.java @@ -5,7 +5,7 @@ import org.lumijiez.base.Group; import org.lumijiez.base.Student; import org.lumijiez.enums.StudyField; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -36,9 +36,9 @@ public class BatchGraduater extends JFrame { titleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 24)); setTitle("Graduate a Batch of Students"); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - browseButton.addActionListener(this::browseButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); + browseButton.addActionListener(this::browseEvent); ComponentDecorator.submitAndCancel(submitButton, cancelButton); @@ -105,11 +105,11 @@ public class BatchGraduater extends JFrame { this.setLocation(x, y); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } - private void browseButtonActionPerformed(ActionEvent evt) { + private void browseEvent(ActionEvent evt) { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { @@ -118,79 +118,57 @@ public class BatchGraduater extends JFrame { } } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { try (BufferedReader reader = new BufferedReader(new FileReader(filePane.getText()))) { - String line; - String name; - String surname; - String email; - String groupName; - String facultyName; - StudyField specialty; + String line, name = "", surname = "", email = "", groupName = "", facultyName = ""; - while (true) { - line = reader.readLine(); - // Sorry for this - if (line == null) break; - if (line.isEmpty()) line = reader.readLine(); - name = line.substring("name: ".length()); + while ((line = reader.readLine()) != null) { + if (line.isEmpty()) continue; - line = reader.readLine(); - // Sorry for this - if (line == null) break; - surname = line.substring("surname: ".length()); + String[] parts = line.split(": ", 2); + if (parts.length != 2) continue; - line = reader.readLine(); - // Sorry for this - if (line == null) break; - email = line.substring("email: ".length()); + String field = parts[0], value = parts[1]; - line = reader.readLine(); - // Sorry for this again lol - if (line == null) break; - groupName = line.substring("group: ".length()); - - line = reader.readLine(); - // Sorry for this again :(( - if (line == null) break; - facultyName = line.substring("faculty: ".length()); - - line = reader.readLine(); - // This is the last one please don't hate me - if (line == null) break; - String spec = line.substring("specialty: ".length()); - - if (StudyField.getEnum(spec) == null) { - specialty = StudyField.DEFAULT_UNASSIGNED; - } else specialty = StudyField.getEnum(spec); - - Faculty faculty; - Group group; - - if (sv.getFacultyByName(facultyName) == null) { - assert specialty != null; - faculty = new Faculty(facultyName, specialty.getAbbreviation(), specialty); - sv.addFaculty(faculty); - } else faculty = sv.getFacultyByName(facultyName); - - - if (sv.getGroupByName(groupName, faculty) == null) { - group = new Group(groupName); - sv.addGroup(group, sv.getFacultyByName(facultyName)); - } else group = sv.getGroupByName(groupName, faculty); - - for (Student st : group.getStudents()) { - if (st.getName().equals(name) && st.getSurname().equals(surname) && st.getEmail().equals(email)) { - st.setGraduated(true); - sv.getLogger().logOperation("Graduated student: " + st.getFullname() + " " + st.getGroup().getName()); - } + switch (field) { + case "name" -> name = value; + case "surname" -> surname = value; + case "email" -> email = value; + case "group" -> groupName = value; + case "faculty" -> facultyName = value; + case "specialty" -> handleStudentGraduation(name, surname, email, groupName, facultyName, value); + default -> System.err.println("Error reading file!"); } } } catch (IOException ex) { throw new RuntimeException(ex); } - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); } + + private void handleStudentGraduation(String name, String surname, String email, String groupName, String facultyName, String fieldName) { + StudyField specialty = (StudyField.getEnum(fieldName) == null) ? StudyField.DEFAULT_UNASSIGNED : StudyField.getEnum(fieldName); + + Faculty faculty = sv.getFacultyByName(facultyName); + if (faculty == null) { + assert specialty != null; + faculty = new Faculty(facultyName, specialty.getAbbreviation(), specialty); + sv.addFaculty(faculty); + } + + Group group = sv.getGroupByName(groupName, faculty); + if (group == null) { + group = new Group(groupName); + sv.addGroup(group, faculty); + } + + for (Student st : group.getStudents()) { + if (st.getName().equals(name) && st.getSurname().equals(surname) && st.getEmail().equals(email)) { + st.setGraduated(true); + sv.getLogger().logOperation("Graduated student: " + st.getFullname() + " " + st.getGroup().getName()); + } + } + } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/loader/BatchLoader.java b/Lab2/src/main/java/org/lumijiez/gui/loader/BatchLoader.java index 5d32798..fcf59dd 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/loader/BatchLoader.java +++ b/Lab2/src/main/java/org/lumijiez/gui/loader/BatchLoader.java @@ -4,7 +4,7 @@ import org.lumijiez.base.Faculty; import org.lumijiez.base.Group; import org.lumijiez.enums.StudyField; import org.lumijiez.gui.util.ComponentDecorator; -import org.lumijiez.gui.util.DisplayerManager; +import org.lumijiez.gui.util.DisplayHandler; import org.lumijiez.managers.Supervisor; import javax.swing.*; @@ -38,9 +38,9 @@ public class BatchLoader extends JFrame { titleLabel.setFont(new java.awt.Font("Segoe UI", Font.PLAIN, 24)); setTitle("Load a Batch of Students"); - submitButton.addActionListener(this::submitButtonActionPerformed); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - browseButton.addActionListener(this::browseButtonActionPerformed); + submitButton.addActionListener(this::submitEvent); + cancelButton.addActionListener(this::cancelEvent); + browseButton.addActionListener(this::browseEvent); ComponentDecorator.submitAndCancel(submitButton, cancelButton); @@ -107,11 +107,11 @@ public class BatchLoader extends JFrame { this.setLocation(x, y); } - private void cancelButtonActionPerformed(ActionEvent evt) { + private void cancelEvent(ActionEvent evt) { this.dispose(); } - private void browseButtonActionPerformed(ActionEvent evt) { + private void browseEvent(ActionEvent evt) { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { @@ -120,87 +120,56 @@ public class BatchLoader extends JFrame { } } - private void submitButtonActionPerformed(ActionEvent evt) { + private void submitEvent(ActionEvent evt) { try (BufferedReader reader = new BufferedReader(new FileReader(filePane.getText()))) { - String line; - String name; - String surname; - String email; - Date birth; - Date enrol; - String groupName; - String facultyName; - StudyField specialty; + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String line, name = "", surname = "", email = "", groupName = "", facultyName = ""; + Date birth = new Date(), enrol = new Date(); - while (true) { - line = reader.readLine(); - // Sorry for this - if (line == null) break; - if (line.isEmpty()) line = reader.readLine(); - name = line.substring("name: ".length()); + while ((line = reader.readLine()) != null) { + if (line.isEmpty()) continue; - line = reader.readLine(); - // Sorry for this - if (line == null) break; - surname = line.substring("surname: ".length()); + String[] parts = line.split(": ", 2); + if (parts.length != 2) continue; - line = reader.readLine(); - // Sorry for this - if (line == null) break; - email = line.substring("email: ".length()); + String field = parts[0], value = parts[1]; - line = reader.readLine(); - // Sorry for this again lol - if (line == null) break; - groupName = line.substring("group: ".length()); - - line = reader.readLine(); - // Sorry for this again :(( - if (line == null) break; - facultyName = line.substring("faculty: ".length()); - - line = reader.readLine(); - // Please forgive me - if (line == null) break; - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - birth = dateFormat.parse(line.substring("birthdate: ".length())); - - line = reader.readLine(); - // I'm really sorry - if (line == null) break; - enrol = dateFormat.parse(line.substring("enroldate: ".length())); - - line = reader.readLine(); - // This is the last one please don't hate me - if (line == null) break; - String spec = line.substring("specialty: ".length()); - - if (StudyField.getEnum(spec) == null) { - specialty = StudyField.DEFAULT_UNASSIGNED; - } else specialty = StudyField.getEnum(spec); - - Faculty faculty; - Group group; - - if (sv.getFacultyByName(facultyName) == null) { - assert specialty != null; - faculty = new Faculty(facultyName, specialty.getAbbreviation(), specialty); - sv.addFaculty(faculty); - } else faculty = sv.getFacultyByName(facultyName); - - - if (sv.getGroupByName(groupName, faculty) == null) { - group = new Group(groupName); - sv.addGroup(group, sv.getFacultyByName(facultyName)); - } else group = sv.getGroupByName(groupName, faculty); - - sv.addStudent(name, surname, email, group, faculty, birth, enrol); + switch (field) { + case "name" -> name = value; + case "surname" -> surname = value; + case "email" -> email = value; + case "group" -> groupName = value; + case "faculty" -> facultyName = value; + case "birthdate" -> birth = dateFormat.parse(value); + case "enroldate" -> enrol = dateFormat.parse(value); + case "specialty" -> handleStudentAddition(name, surname, email, groupName, facultyName, birth, enrol, value); + default -> System.err.println("Error reading file!"); + } } } catch (IOException | ParseException ex) { throw new RuntimeException(ex); } - DisplayerManager.displayStudents(); + DisplayHandler.displayStudents(); this.dispose(); } + + private void handleStudentAddition(String name, String surname, String email, String groupName, String facultyName, Date birth, Date enrol, String fieldName) { + StudyField specialty = (StudyField.getEnum(fieldName) == null) ? StudyField.DEFAULT_UNASSIGNED : StudyField.getEnum(fieldName); + + Faculty faculty = sv.getFacultyByName(facultyName); + if (faculty == null) { + assert specialty != null; + faculty = new Faculty(facultyName, specialty.getAbbreviation(), specialty); + sv.addFaculty(faculty); + } + + Group group = sv.getGroupByName(groupName, faculty); + if (group == null) { + group = new Group(groupName); + sv.addGroup(group, faculty); + } + + sv.addStudent(name, surname, email, group, faculty, birth, enrol); + } } diff --git a/Lab2/src/main/java/org/lumijiez/gui/util/ComboBoxRenderer.java b/Lab2/src/main/java/org/lumijiez/gui/util/ComboRenderer.java similarity index 81% rename from Lab2/src/main/java/org/lumijiez/gui/util/ComboBoxRenderer.java rename to Lab2/src/main/java/org/lumijiez/gui/util/ComboRenderer.java index 833131b..4f708d9 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/util/ComboBoxRenderer.java +++ b/Lab2/src/main/java/org/lumijiez/gui/util/ComboRenderer.java @@ -3,7 +3,8 @@ package org.lumijiez.gui.util; import javax.swing.*; import java.awt.*; -public class ComboBoxRenderer { +// Generic function that takes a ComboBox with a object and sets the DefaultListCellRenderer according to the object +public class ComboRenderer { public static void setRenderer(JComboBox comboBox, T[] items) { comboBox.setModel(new DefaultComboBoxModel<>(items)); comboBox.setRenderer(new DefaultListCellRenderer() { diff --git a/Lab2/src/main/java/org/lumijiez/gui/util/DisplayerManager.java b/Lab2/src/main/java/org/lumijiez/gui/util/DisplayHandler.java similarity index 86% rename from Lab2/src/main/java/org/lumijiez/gui/util/DisplayerManager.java rename to Lab2/src/main/java/org/lumijiez/gui/util/DisplayHandler.java index a5fa4dc..fe19510 100644 --- a/Lab2/src/main/java/org/lumijiez/gui/util/DisplayerManager.java +++ b/Lab2/src/main/java/org/lumijiez/gui/util/DisplayHandler.java @@ -5,11 +5,11 @@ import org.lumijiez.base.Group; import org.lumijiez.base.Student; import org.lumijiez.gui.StudentManagementGUI; -public class DisplayerManager { +public class DisplayHandler { public static void displayStudents() { StringBuilder text = new StringBuilder(); text.append("======================== Students ==========================\n"); - for (Student student : StudentManagementGUI.getSv().getFm().getGm().getSm().getStudents()) { + for (Student student : StudentManagementGUI.getSv().studentManager().getStudents()) { text.append("Name: ").append(student.getFullname()).append("\nGroup: ").append(student.getGroup().getName()) .append("\nEmail: ").append(student.getEmail()).append("\nGraduated: ").append((student.isGraduated() ? "Yes" : "No")); text.append("\n===============================================\n"); @@ -20,7 +20,7 @@ public class DisplayerManager { public static void displayGroups() { StringBuilder text = new StringBuilder(); text.append("========================= Groups ===========================\n"); - for (Group group : StudentManagementGUI.getSv().getFm().getGm().getGroups()) { + for (Group group : StudentManagementGUI.getSv().groupManager().getGroups()) { text.append("Name: ").append(group.getName()).append("\nFaculty: ").append(group.getFaculty().getName()) .append("\nNumber of students: ").append(group.getStudents().size()); text.append("\n===============================================\n"); @@ -31,7 +31,7 @@ public class DisplayerManager { public static void displayFaculties() { StringBuilder text = new StringBuilder(); text.append("======================= Faculties =========================\n"); - for (Faculty fac : StudentManagementGUI.getSv().getFm().getFaculties()) { + for (Faculty fac : StudentManagementGUI.getSv().facultyManager().getFaculties()) { text.append("Name: ").append(fac.getName()).append("\nSpecialty: ").append(fac.getField().getName()) .append("\nAbbreviation: ").append(fac.getAbbreviation()) .append("\nNumber of groups: ").append(fac.getGroups().size()); @@ -43,7 +43,7 @@ public class DisplayerManager { public static void displayGraduates() { StringBuilder text = new StringBuilder(); text.append("======================== Students ==========================\n"); - for (Student st : StudentManagementGUI.getSv().getFm().getGm().getSm().getStudents()) { + for (Student st : StudentManagementGUI.getSv().studentManager().getStudents()) { if (st.isGraduated()) { text.append("Name: ").append(st.getFullname()).append("\nGroup: ").append(st.getGroup().getName()) .append("\nGraduated: ").append("Yes"); @@ -56,7 +56,7 @@ public class DisplayerManager { public static void displayEnrolled() { StringBuilder text = new StringBuilder(); text.append("======================== Students ==========================\n"); - for (Student st : StudentManagementGUI.getSv().getFm().getGm().getSm().getStudents()) { + for (Student st : StudentManagementGUI.getSv().studentManager().getStudents()) { if (!st.isGraduated()) { text.append("Name: ").append(st.getFullname()).append("\nGroup: ").append(st.getGroup().getName()) .append("\nGraduated: ").append("No"); diff --git a/Lab2/src/main/java/org/lumijiez/managers/Supervisor.java b/Lab2/src/main/java/org/lumijiez/managers/Supervisor.java index a1888c8..6c8181e 100644 --- a/Lab2/src/main/java/org/lumijiez/managers/Supervisor.java +++ b/Lab2/src/main/java/org/lumijiez/managers/Supervisor.java @@ -22,7 +22,7 @@ public class Supervisor implements Serializable { // Adds a faculty using the FacultyManager public void addFaculty(Faculty faculty) { - getFm().addFaculty(faculty); + facultyManager().addFaculty(faculty); logger.logOperation("Faculty added: " + faculty.getName()); } @@ -30,9 +30,9 @@ public class Supervisor implements Serializable { public void deleteFaculty(Faculty faculty) { fm.deleteFaculty(faculty); for (Group gr : faculty.getGroups()) { - getFm().getGm().deleteGroup(gr); + groupManager().deleteGroup(gr); for (Student st : gr.getStudents()) { - getFm().getGm().getSm().deleteStudent(st); + studentManager().deleteStudent(st); } } logger.logOperation("Faculty deleted : " + faculty.getName()); @@ -59,9 +59,9 @@ public class Supervisor implements Serializable { // Deletes a group, then deletes the students. public void deleteGroup(Group group) { - getFm().getGm().deleteGroup(group); + groupManager().deleteGroup(group); for (Student st : group.getStudents()) { - getFm().getGm().getSm().deleteStudent(st); + studentManager().deleteStudent(st); } logger.logOperation("Group deleted: " + group.getName()); } @@ -69,7 +69,7 @@ public class Supervisor implements Serializable { // Adds a student, using the StudentManager public void addStudent(String name, String surname, String email, Group group, Faculty faculty, Date birth, Date enrol) { Student newStudent = new Student(name, surname, email, group, faculty, birth, enrol); - getFm().getGm().getSm().addStudent(newStudent); + studentManager().addStudent(newStudent); logger.logOperation("Student added: " + newStudent.getFullname()); } @@ -92,21 +92,21 @@ public class Supervisor implements Serializable { public void addGroup(Group group, Faculty faculty) { group.setFaculty(faculty); faculty.addGroup(group); - getFm().getGm().addGroup(group); + groupManager().addGroup(group); logger.logOperation("Group added: " + group.getName()); } // Deletes a student, simple as that public void deleteStudent(Student st) { st.getGroup().deleteStudent(st); - getFm().getGm().getSm().deleteStudent(st); + studentManager().deleteStudent(st); logger.logOperation("Student deleted: " + st.getFullname()); } // Iterates through all faculties to get a faculty that matches the name // In the future would be great to replace it using an UUID instead of a String name. public Faculty getFacultyByName(String facultyName) { - for (Faculty faculty : getFm().getFaculties()) { + for (Faculty faculty : facultyManager().getFaculties()) { if (faculty.getName().equals(facultyName)) return faculty; } @@ -115,17 +115,25 @@ public class Supervisor implements Serializable { // Same thing as getFacultyByName() except for Groups public Group getGroupByName(String groupName, Faculty faculty) { - for (Group group : getFm().getGm().getGroups()) { + for (Group group : groupManager().getGroups()) { if (group.getName().equals(groupName) && group.getFaculty().equals(faculty)) return group; } return null; } - public FacultyManager getFm() { + public FacultyManager facultyManager() { return fm; } + public GroupManager groupManager() { + return fm.getGm(); + } + + public StudentManager studentManager() { + return fm.getGm().getSm(); + } + public LogManager getLogger() { return this.logger; }