Prettier logging, better frame titles, batch graduation

This commit is contained in:
2023-10-02 18:17:37 +03:00
parent 13afebe65b
commit 38bec56d58
25 changed files with 364 additions and 145 deletions

View File

@@ -8,16 +8,25 @@ import java.util.List;
public class Faculty implements Serializable {
private final List<Group> groups = new ArrayList<>();
private String name;
private String abbreviation;
private StudyField field;
public Faculty(String name, String abbreviation, StudyField field) {
this.name = name;
this.abbreviation = abbreviation;
this.field = field;
// this.uuid = UUID.randomUUID().toString();
}
// private String uuid;
private String name;
private String abbreviation;
private final List<Group> groups = new ArrayList<>();
private StudyField field;
// public String getUuid() {
// return uuid;
// }
//
// public void setUuid(String uuid) {
// this.uuid = uuid;
// }
public void addGroup(Group group) {
groups.add(group);

View File

@@ -6,7 +6,6 @@ import java.io.Serializable;
public class Grade implements Serializable {
private final Subjects subject;
private final int grade;
public Grade(Subjects subject, int grade) {

View File

@@ -5,14 +5,15 @@ import java.util.ArrayList;
import java.util.List;
public class Group implements Serializable {
private String name;
private Faculty faculty;
private final List<Student> students = new ArrayList<>();
private String name;
// private String uuid;
private Faculty faculty;
public void setName(String name) {
public Group(String name) {
this.name = name;
// this.uuid = UUID.randomUUID().toString();
}
public Faculty getFaculty() {
@@ -23,14 +24,14 @@ public class Group implements Serializable {
this.faculty = faculty;
}
public Group(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void addStudent(Student st) {
students.add(st);
}
@@ -47,4 +48,12 @@ public class Group implements Serializable {
public String toString() {
return name;
}
// public String getUuid() {
// return uuid;
// }
//
// public void setUuid(String uuid) {
// this.uuid = uuid;
// }
}

View File

@@ -7,17 +7,7 @@ import java.util.List;
public class Student implements Serializable {
public Student(String name, String surname, String email, Group group, Faculty faculty, Date birth, Date enrol) {
this.name = name;
this.surname = surname;
this.fullname = name + " " + surname;
this.email = email;
this.group = group;
this.faculty = faculty;
this.dateOfBirth = birth;
this.enrollmentDate = enrol;
}
private final List<Grade> grades = new ArrayList<>();
private boolean graduated = false;
private String name;
@@ -36,7 +26,19 @@ public class Student implements Serializable {
private Group group;
private final List<Grade> grades = new ArrayList<>();
// private String uuid;
public Student(String name, String surname, String email, Group group, Faculty faculty, Date birth, Date enrol) {
this.name = name;
this.surname = surname;
this.fullname = name + " " + surname;
this.email = email;
this.group = group;
this.faculty = faculty;
this.dateOfBirth = birth;
this.enrollmentDate = enrol;
// this.uuid = UUID.randomUUID().toString();
}
public Faculty getFaculty() {
return faculty;
@@ -46,12 +48,6 @@ public class Student implements Serializable {
this.faculty = faculty;
}
public void setGroup(Group gr) {
this.group.deleteStudent(this);
this.group = gr;
gr.addStudent(this);
}
public List<Grade> getGrades() {
return grades;
}
@@ -64,58 +60,64 @@ public class Student implements Serializable {
return name;
}
public String getSurname() {
return surname;
}
public String getFullname() {
return fullname;
}
public String getEmail() {
return email;
}
public Date getEnrollmentDate() {
return enrollmentDate;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public Group getGroup() {
return group;
}
public boolean isGraduated() {
return this.graduated;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getEnrollmentDate() {
return enrollmentDate;
}
public void setEnrollmentDate(Date enrollmentDate) {
this.enrollmentDate = enrollmentDate;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public Group getGroup() {
return group;
}
public void setGroup(Group gr) {
this.group.deleteStudent(this);
this.group = gr;
gr.addStudent(this);
}
public boolean isGraduated() {
return this.graduated;
}
public void setGraduated(boolean graduated) {
this.graduated = graduated;
}

View File

@@ -7,13 +7,12 @@ import java.io.IOException;
import java.io.ObjectOutputStream;
public class DataSerializer {
public static void serialize(Supervisor manager) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("manager.ser"))) {
oos.writeObject(manager);
System.out.println("Supervisor object serialized successfully.");
} catch (IOException e) {
e.printStackTrace();
System.err.println("Error!");
}
}

View File

@@ -13,7 +13,6 @@ public enum StudyField implements Serializable {
VETERINARY_MEDICINE("Veterinary Medicine", "VE");
private final String name;
private final String abbreviation;
StudyField(String name, String abbreviation) {
@@ -35,6 +34,10 @@ public enum StudyField implements Serializable {
return null;
}
public static List<StudyField> getAllEnums() {
return Arrays.asList(values());
}
public String getName() {
return name;
}
@@ -43,10 +46,6 @@ public enum StudyField implements Serializable {
return abbreviation;
}
public static List<StudyField> getAllEnums() {
return Arrays.asList(values());
}
@Override
public String toString() {
return getName();

View File

@@ -1,33 +1,21 @@
package org.lumijiez.enums;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
public enum Subjects implements Serializable {
ENGLISH("English Language", "Eng"),
LINEAR_ALGEBRA("Linear Algebra", "AL"),
OBJECT_ORIENTED_PROGRAMMING("Object Oriented Programming", "OOP"),
DATABASES("Databases", "DB"),
MATHEMATICAL_ANALYSIS("Mathematical Analysis", "Mat. Anal"),
DISCRETE_MATH("Discrete Math", "MD"),
PROBABILITY_AND_STATISTICS("Probability and Statistics", "PSA"),
PHYSICS("Physics", "PHYS");
ENGLISH("English Language"),
LINEAR_ALGEBRA("Linear Algebra"),
OBJECT_ORIENTED_PROGRAMMING("Object Oriented Programming"),
DATABASES("Databases"),
MATHEMATICAL_ANALYSIS("Mathematical Analysis"),
DISCRETE_MATH("Discrete Math"),
PROBABILITY_AND_STATISTICS("Probability and Statistics"),
PHYSICS("Physics");
private final String name;
private final String abbreviation;
Subjects(String name, String abbreviation) {
Subjects(String name) {
this.name = name;
this.abbreviation = abbreviation;
}
public static String getAbbrevFromString(String str) {
for (Subjects st : values()) {
if (st.name.equals(str)) return st.abbreviation;
}
return str;
}
public static Subjects getEnum(String str) {
@@ -41,14 +29,6 @@ public enum Subjects implements Serializable {
return name;
}
public String getAbbreviation() {
return abbreviation;
}
public static List<Subjects> getAllEnums() {
return Arrays.asList(values());
}
@Override
public String toString() {
return getName();

View File

@@ -11,8 +11,9 @@ import org.lumijiez.gui.forms.group.DeleteGroupForm;
import org.lumijiez.gui.forms.group.EditGroupForm;
import org.lumijiez.gui.forms.group.ShowGroupForm;
import org.lumijiez.gui.forms.student.*;
import org.lumijiez.gui.util.BatchGraduater;
import org.lumijiez.gui.util.BatchLoader;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.gui.util.FilePicker;
import org.lumijiez.managers.Supervisor;
import javax.swing.*;
@@ -22,6 +23,7 @@ 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();
@@ -29,25 +31,35 @@ public class StudentManagementGUI extends JFrame {
private final JMenu groupMenu = new JMenu();
private final JMenu facultyMenu = new JMenu();
private final JScrollPane mainScrollPane = new javax.swing.JScrollPane();
private static final JTextArea mainTextLabel = new javax.swing.JTextArea();
public StudentManagementGUI() {
sv = DataDeserializer.deserialize();
this.setSize(650, 720);
this.setTitle("Student Management System");
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"));
JMenuItem graduateBatchOption = new JMenuItem("Graduate as Batch", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem saveAsOption = new JMenuItem("Save As (WIP)", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem saveAndExitOption = new JMenuItem("Save and Exit", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem settingsOption = new JMenuItem("Settings (WIP)", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showAllStudentsOption = new JMenuItem("Show All Students", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showAllStudentsOption = new JMenuItem("Show all Students", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showParticularStudentOption = new JMenuItem("Show a Student", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showStudentGrade = new JMenuItem("Show Student Grades", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem graduateStudent = new JMenuItem("Graduate Student", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showGraduates = new JMenuItem("Show Graduates", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showEnrolled = new JMenuItem("Show enrolled", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem showEnrolled = new JMenuItem("Show Enrolled", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem gradeStudentOption = new JMenuItem("Grade a Student", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem addStudentOption = new JMenuItem("Add a Student", UIManager.getIcon("FileView.directoryIcon"));
JMenuItem editStudentOption = new JMenuItem("Edit a Student", UIManager.getIcon("FileView.directoryIcon"));
@@ -96,10 +108,12 @@ public class StudentManagementGUI extends JFrame {
loadBatchOption.addActionListener(this::loadBatchOptionActionPerformed);
graduateBatchOption.addActionListener(this::graduateBatchOptionActionPerformed);
saveAsOption.addActionListener(this::saveAsOptionActionPerformed);
saveAndExitOption.addActionListener(this::saveAndExitOptionActionPerformed);
fileMenu.add(loadBatchOption);
fileMenu.add(graduateBatchOption);
fileMenu.add(saveAsOption);
fileMenu.add(saveAndExitOption);
fileMenu.add(settingsOption);
@@ -159,7 +173,6 @@ public class StudentManagementGUI extends JFrame {
facultyMenu.add(editFacultyOption);
facultyMenu.add(removeFacultyOption);
menuBar.add(facultyMenu);
setJMenuBar(menuBar);
@@ -170,15 +183,18 @@ public class StudentManagementGUI extends JFrame {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1280, Short.MAX_VALUE)
);
.addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)
);
.addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE));
pack();
}
private void graduateBatchOptionActionPerformed(ActionEvent actionEvent) {
BatchGraduater picker = new BatchGraduater(sv);
picker.setVisible(true);
}
private void showGraduatesOptionActionPerformed(ActionEvent actionEvent) {
if (checkStudent() && checkGroup() && checkFaculty()) {
DisplayerManager.displayGraduates();
@@ -218,7 +234,7 @@ public class StudentManagementGUI extends JFrame {
}
private void loadBatchOptionActionPerformed(ActionEvent evt) {
FilePicker picker = new FilePicker(sv);
BatchLoader picker = new BatchLoader(sv);
picker.setVisible(true);
}
@@ -244,7 +260,7 @@ public class StudentManagementGUI extends JFrame {
}
private void saveAsOptionActionPerformed(ActionEvent evt) {
}
private void showParticularGroupOptionActionPerformed(ActionEvent evt) {
@@ -359,12 +375,4 @@ public class StudentManagementGUI extends JFrame {
}
return true;
}
public static JTextArea getMainLabel() {
return mainTextLabel;
}
public static Supervisor getSv() {
return sv;
}
}

View File

@@ -6,11 +6,11 @@ import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.Objects;
import javax.swing.*;
public class AddFacultyForm extends JFrame {
private final Supervisor sv;
@@ -26,6 +26,7 @@ public class AddFacultyForm extends JFrame {
public AddFacultyForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Add a Faculty");
initComponents();
}

View File

@@ -2,10 +2,10 @@ package org.lumijiez.gui.forms.faculty;
import org.lumijiez.base.Faculty;
import org.lumijiez.enums.StudyField;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -24,10 +24,13 @@ public class EditFacultyForm extends JFrame {
private final JLabel titleLabel = new JLabel();
private final JComboBox<Faculty> facultyCombo;
private final JComboBox<StudyField> specialtyCombo;
private final Supervisor sv;
public EditFacultyForm(Supervisor sv) {
facultyCombo = new JComboBox<>(sv.getFm().getFaculties().toArray(new Faculty[0]));
specialtyCombo = new JComboBox<>(StudyField.getAllEnums().toArray(new StudyField[0]));
this.sv = sv;
this.setTitle("Edit a Faculty");
initComponents();
}
@@ -141,6 +144,7 @@ public class EditFacultyForm extends JFrame {
((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).setAbbreviation(abbreviationField.getText());
((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).setField(((StudyField) Objects.requireNonNull(specialtyCombo.getSelectedItem())));
DisplayerManager.displayFaculties();
sv.getLogger().logOperation("Faculty edited : " + ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).getName());
this.dispose();
}

View File

@@ -1,10 +1,10 @@
package org.lumijiez.gui.forms.faculty;
import org.lumijiez.base.Faculty;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -21,6 +21,7 @@ public class RemoveFacultyForm extends JFrame {
public RemoveFacultyForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Remove a Faculty");
this.facultyCombo = new JComboBox<>(sv.getFm().getFaculties().toArray(new Faculty[0]));
initComponents();
}
@@ -63,7 +64,6 @@ public class RemoveFacultyForm extends JFrame {
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(titleLabel)
.addGap(48, 48, 48)));
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
@@ -82,7 +82,7 @@ public class RemoveFacultyForm extends JFrame {
}
private void submitButtonActionPerformed(ActionEvent evt) {
sv.deleteFaculty(((Faculty)facultyCombo.getSelectedItem()));
sv.deleteFaculty(((Faculty) facultyCombo.getSelectedItem()));
DisplayerManager.displayFaculties();
this.dispose();
}

View File

@@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.faculty;
import org.lumijiez.base.Faculty;
import org.lumijiez.base.Group;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -21,6 +21,7 @@ public class ShowFacultyForm extends JFrame {
public ShowFacultyForm(Supervisor sv, JTextArea mainTextLabel) {
this.mainTextLabel = mainTextLabel;
this.setTitle("Show a Faculty");
this.facultyCombo = new JComboBox<>(sv.getFm().getFaculties().toArray(new Faculty[0]));
initComponents();
}

View File

@@ -2,10 +2,10 @@ package org.lumijiez.gui.forms.group;
import org.lumijiez.base.Faculty;
import org.lumijiez.base.Group;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -25,9 +25,11 @@ public class AddGroupForm extends JFrame {
public AddGroupForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Add a Group");
this.facultyCombo = new JComboBox<>(sv.getFm().getFaculties().toArray(new Faculty[0]));
initComponents();
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

View File

@@ -1,10 +1,10 @@
package org.lumijiez.gui.forms.group;
import org.lumijiez.base.Group;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -20,6 +20,7 @@ public class DeleteGroupForm extends JFrame {
public DeleteGroupForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Delete a Group");
this.groupCombo = new JComboBox<>(sv.getFm().getGm().getGroups().toArray(new Group[0]));
initComponents();
}
@@ -82,7 +83,7 @@ public class DeleteGroupForm extends JFrame {
}
private void submitButtonActionPerformed(ActionEvent evt) {
sv.deleteGroup(((Group)groupCombo.getSelectedItem()));
sv.deleteGroup(((Group) groupCombo.getSelectedItem()));
DisplayerManager.displayGroups();
this.dispose();
}

View File

@@ -2,10 +2,10 @@ package org.lumijiez.gui.forms.group;
import org.lumijiez.base.Faculty;
import org.lumijiez.base.Group;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -24,8 +24,10 @@ public class EditGroupForm extends JFrame {
private final JLabel nameLabel = new JLabel();
private final JButton submitButton = new JButton();
private final JLabel titleLabel = new JLabel();
public EditGroupForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Edit a Group");
this.facultyCombo = new JComboBox<>(sv.getFm().getFaculties().toArray(new Faculty[0]));
this.groupCombo = new JComboBox<>(sv.getFm().getGm().getGroups().toArray(new Group[0]));
initComponents();

View File

@@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.group;
import org.lumijiez.base.Group;
import org.lumijiez.base.Student;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -20,8 +20,10 @@ public class ShowGroupForm extends JFrame {
private final JLabel groupLabel = new JLabel();
private final JButton submitButton = new JButton();
private final JLabel titleLabel = new JLabel();
public ShowGroupForm(Supervisor sv, JTextArea mainTextLabel) {
this.mainTextLabel = mainTextLabel;
this.setTitle("Show a Group");
this.groupCombo = new JComboBox<>(sv.getFm().getGm().getGroups().toArray(new Group[0]));
initComponents();
}

View File

@@ -2,10 +2,10 @@ package org.lumijiez.gui.forms.student;
import org.lumijiez.base.Faculty;
import org.lumijiez.base.Group;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -44,6 +44,7 @@ public class AddStudentForm extends JFrame {
public AddStudentForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Add a Student");
Integer[] days = new Integer[31];
for (int i = 0; i < 31; i++) {

View File

@@ -1,10 +1,10 @@
package org.lumijiez.gui.forms.student;
import org.lumijiez.base.Student;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -21,6 +21,7 @@ public class DeleteStudentForm extends JFrame {
public DeleteStudentForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Delete a Student");
this.studentCombo = new JComboBox<>(sv.getFm().getGm().getSm().getStudents().toArray(new Student[0]));
initComponents();
}

View File

@@ -46,8 +46,8 @@ public class EditStudentForm extends JFrame {
private final Supervisor sv;
public EditStudentForm(Supervisor sv) {
this.sv = sv;
this.setTitle("Edit a Student");
Integer[] days = new Integer[31];
for (int i = 0; i < 31; i++) {

View File

@@ -3,9 +3,9 @@ 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.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -13,7 +13,6 @@ import java.awt.event.ActionEvent;
import java.util.Objects;
public class GradeStudentForm extends JFrame {
Integer[] grades = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
private final Supervisor sv;
private final JTextArea mainTextLabel;
private final JButton cancelButton = new JButton();
@@ -25,9 +24,11 @@ public class GradeStudentForm extends JFrame {
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};
public GradeStudentForm(Supervisor sv, JTextArea mainTextLabel) {
this.sv = sv;
this.setTitle("Grade A Student");
this.mainTextLabel = mainTextLabel;
this.subjectCombo = new JComboBox<>(Subjects.values());
this.gradeCombo = new JComboBox<>(grades);
@@ -120,17 +121,17 @@ public class GradeStudentForm extends JFrame {
Subjects subject = Subjects.getEnum(Objects.requireNonNull(subjectCombo.getSelectedItem()).toString());
int intGrade = (Integer) Objects.requireNonNull(gradeCombo.getSelectedItem());
Grade grade = new Grade(subject, intGrade);
StringBuilder builder = new StringBuilder();
sv.addGrade(student, grade);
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()) {
for (Grade gr : student.getGrades())
builder.append(gr.getSubject()).append(": ").append(gr.getGrade()).append("\n");
}
builder.append("====================================\n");
mainTextLabel.setText(builder.toString());
mainTextLabel.setText(builder.toString());
this.dispose();
}

View File

@@ -1,10 +1,10 @@
package org.lumijiez.gui.forms.student;
import org.lumijiez.base.Student;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -19,6 +19,7 @@ public class GraduateStudentForm extends JFrame {
private final JLabel titleLabel = new JLabel();
public GraduateStudentForm(Supervisor sv) {
this.setTitle("Graduate a Student");
this.studentCombo = new JComboBox<>(sv.getFm().getGm().getSm().getStudents().toArray(new Student[0]));
initComponents();
}

View File

@@ -1,9 +1,9 @@
package org.lumijiez.gui.forms.student;
import org.lumijiez.base.Student;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -20,6 +20,7 @@ public class ShowStudentForm extends JFrame {
public ShowStudentForm(Supervisor sv, JTextArea mainTextLabel) {
this.mainTextLabel = mainTextLabel;
this.setTitle("Show A Student");
this.studentCombo = new JComboBox<>(sv.getFm().getGm().getSm().getStudents().toArray(new Student[0]));
initComponents();
}

View File

@@ -2,9 +2,9 @@ package org.lumijiez.gui.forms.student;
import org.lumijiez.base.Grade;
import org.lumijiez.base.Student;
import org.lumijiez.gui.util.ComboBoxRenderers;
import org.lumijiez.gui.util.ComponentDecorator;
import org.lumijiez.managers.Supervisor;
import org.lumijiez.gui.util.ComboBoxRenderers;
import javax.swing.*;
import java.awt.*;
@@ -22,6 +22,7 @@ public class ShowStudentGradesForm extends JFrame {
public ShowStudentGradesForm(Supervisor sv, JTextArea mainTextLabel) {
this.mainTextLabel = mainTextLabel;
this.setTitle("Show Student Grades");
this.studentCombo = new JComboBox<>(sv.getFm().getGm().getSm().getStudents().toArray(new Student[0]));
initComponents();
}

View File

@@ -0,0 +1,193 @@
package org.lumijiez.gui.util;
import org.lumijiez.base.Faculty;
import org.lumijiez.base.Group;
import org.lumijiez.base.Student;
import org.lumijiez.enums.StudyField;
import org.lumijiez.managers.Supervisor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BatchGraduater extends JFrame {
private final Supervisor sv;
private JTextPane filePane;
public BatchGraduater(Supervisor sv) {
this.sv = sv;
this.setTitle("Graduate a Batch of Students");
initComponents();
}
private void initComponents() {
JButton submitButton = new JButton();
JLabel titleLabel = new JLabel();
JButton browseButton = new JButton();
JLabel formatLabel = new JLabel();
JScrollPane exampleLabel = new JScrollPane();
JTextArea exampleText = new JTextArea();
JButton cancelButton = new JButton();
filePane = new JTextPane();
titleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 24));
submitButton.addActionListener(this::submitButtonActionPerformed);
cancelButton.addActionListener(this::cancelButtonActionPerformed);
browseButton.addActionListener(this::browseButtonActionPerformed);
ComponentDecorator.submitButton(submitButton);
ComponentDecorator.cancelButton(cancelButton);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
titleLabel.setText("Pick a file to graduate a batch");
submitButton.setText("Submit");
browseButton.setText("Browse");
formatLabel.setText("File format example:");
cancelButton.setText("Cancel");
exampleText.setColumns(15);
exampleText.setRows(5);
exampleText.setEditable(false);
exampleText.setText("name: John\nsurname: Doe\nemail: john.doe@example.com\ngroup: FAF-223\nfaculty: FCIM\nspecialty: Mechanical Engineering");
exampleLabel.setViewportView(exampleText);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(filePane, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(browseButton))
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addComponent(cancelButton)
.addGap(18, 18, 18)
.addComponent(submitButton))
.addComponent(formatLabel)
.addComponent(exampleLabel, GroupLayout.PREFERRED_SIZE, 307, GroupLayout.PREFERRED_SIZE))
.addContainerGap(33, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(titleLabel)
.addGap(0, 0, Short.MAX_VALUE)));
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addComponent(titleLabel)
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(filePane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(browseButton))
.addGap(18, 18, 18)
.addComponent(formatLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(exampleLabel, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(submitButton))
.addGap(23, 23, 23)));
pack();
}
private void cancelButtonActionPerformed(ActionEvent evt) {
this.dispose();
}
private void browseButtonActionPerformed(ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
java.io.File file = fileChooser.getSelectedFile();
filePane.setText(file.getAbsolutePath());
}
}
private void submitButtonActionPerformed(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;
while (true) {
line = reader.readLine();
// Sorry for this
if (line == null) break;
if (line.isEmpty()) line = reader.readLine();
name = line.substring("name: ".length());
line = reader.readLine();
// Sorry for this
if (line == null) break;
surname = line.substring("surname: ".length());
line = reader.readLine();
// Sorry for this
if (line == null) break;
email = line.substring("email: ".length());
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());
}
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
DisplayerManager.displayStudents();
this.dispose();
}
}

View File

@@ -15,12 +15,13 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FilePicker extends JFrame {
private JTextPane filePane;
public class BatchLoader extends JFrame {
private final Supervisor sv;
private JTextPane filePane;
public FilePicker(Supervisor sv) {
public BatchLoader(Supervisor sv) {
this.sv = sv;
this.setTitle("Load a Batch of Students");
initComponents();
}
@@ -31,7 +32,7 @@ public class FilePicker extends JFrame {
JButton browseButton = new JButton();
JLabel formatLabel = new JLabel();
JScrollPane exampleLabel = new JScrollPane();
JTextArea jTextArea2 = new JTextArea();
JTextArea exampleText = new JTextArea();
JButton cancelButton = new JButton();
filePane = new JTextPane();
@@ -53,10 +54,11 @@ public class FilePicker extends JFrame {
cancelButton.setText("Cancel");
jTextArea2.setColumns(15);
jTextArea2.setRows(5);
jTextArea2.setText("name: John\nsurname: Doe\nemail: john.doe@example.com\ngroup: FAF-223\nfaculty: FCIM\nbirthdate: 1998-05-15\nenroldate: 2017-09-01\nspecialty: Mechanical Engineering");
exampleLabel.setViewportView(jTextArea2);
exampleText.setColumns(15);
exampleText.setRows(5);
exampleText.setEditable(false);
exampleText.setText("name: John\nsurname: Doe\nemail: john.doe@example.com\ngroup: FAF-223\nfaculty: FCIM\nbirthdate: 1998-05-15\nenroldate: 2017-09-01\nspecialty: Mechanical Engineering");
exampleLabel.setViewportView(exampleText);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);