Added a couple of comments

This commit is contained in:
2023-10-02 18:53:58 +03:00
parent d99f604ced
commit d5a7a2c460
5 changed files with 31 additions and 4 deletions

View File

@@ -8,12 +8,14 @@ import java.awt.*;
public class Main {
public static void main(String[] args) {
// Sets a Windows "Look and Feel", or at least tries to
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
System.err.println("Windows LAF not found!");
}
// Application entry point
EventQueue.invokeLater(() -> new StudentManagementGUI().setVisible(true));
}
}

View File

@@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Arrays;
public class DataDeserializer {
public static Supervisor deserialize() {
@@ -16,7 +17,7 @@ public class DataDeserializer {
manager = (Supervisor) ois.readObject();
System.out.println("Supervisor object deserialized successfully.");
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
System.out.println(Arrays.toString(e.getStackTrace()));
}
} else {
System.out.println("Serialized file 'manager.ser' does not exist.");

View File

@@ -5,6 +5,7 @@ import org.lumijiez.managers.Supervisor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Arrays;
public class DataSerializer {
public static void serialize(Supervisor manager) {
@@ -12,7 +13,7 @@ public class DataSerializer {
oos.writeObject(manager);
System.out.println("Supervisor object serialized successfully.");
} catch (IOException e) {
e.printStackTrace();
System.out.println(Arrays.toString(e.getStackTrace()));
}
}

View File

@@ -6,11 +6,15 @@ import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
public class LogManager implements Serializable {
// Has to be transient since it is not serializable
private transient BufferedWriter writer;
// Initializes the writer object with a file that matches the exact date of application launch time.
// Doing it to keep easier track of logging files.
private void init() {
BufferedWriter writerTemp;
LocalDateTime currentDateTime = LocalDateTime.now();
@@ -20,12 +24,14 @@ public class LogManager implements Serializable {
FileWriter fwriter = new FileWriter(fileHandle);
writerTemp = new BufferedWriter(fwriter);
} catch (IOException e) {
e.printStackTrace();
System.out.println(Arrays.toString(e.getStackTrace()));
writerTemp = null;
}
this.writer = writerTemp;
}
// Logs an operation, also adds the current time to it.
// Inits the writer if it's not initialized already.
public void logOperation(String msg) {
if (writer == null) init();
LocalDateTime currentDateTime = LocalDateTime.now();
@@ -35,10 +41,11 @@ public class LogManager implements Serializable {
writer.flush();
writer.newLine();
} catch (IOException e) {
e.printStackTrace();
System.out.println(Arrays.toString(e.getStackTrace()));
}
}
// Closes the file.
public void close() {
try {
this.writer.close();

View File

@@ -8,6 +8,7 @@ import org.lumijiez.base.Student;
import java.io.Serializable;
import java.util.Date;
// Supervisor class handles all managers, and all operations regarding any data
public class Supervisor implements Serializable {
private final FacultyManager fm;
@@ -19,11 +20,13 @@ public class Supervisor implements Serializable {
this.logger = new LogManager();
}
// Adds a faculty using the FacultyManager
public void addFaculty(Faculty faculty) {
getFm().addFaculty(faculty);
logger.logOperation("Faculty added: " + faculty.getName());
}
// Deletes a faculty, then deletes all students and groups from the faculty
public void deleteFaculty(Faculty faculty) {
fm.deleteFaculty(faculty);
for (Group gr : faculty.getGroups()) {
@@ -35,11 +38,16 @@ public class Supervisor implements Serializable {
logger.logOperation("Faculty deleted : " + faculty.getName());
}
// Adds a grade, self-explanatory
public void addGrade(Student student, Grade grade) {
student.addGrade(grade);
logger.logOperation("Student graded: " + student.getName() + " " + grade.getSubject().getName() + " " + grade.getGrade());
}
// Edits a group, also normalizes data to keep track of all bi-directional references
// due to all my base classes containing two-way references to each other.
// For example every Student class holds a reference to the Group and Faculty he is in.
// I did that to keep easier track of objects.
public void editGroup(Group group, String name, Faculty faculty) {
group.setName(name);
Faculty oldFac = group.getFaculty();
@@ -49,6 +57,7 @@ public class Supervisor implements Serializable {
logger.logOperation("Group edited: " + group.getName());
}
// Deletes a group, then deletes the students.
public void deleteGroup(Group group) {
getFm().getGm().deleteGroup(group);
for (Student st : group.getStudents()) {
@@ -57,12 +66,14 @@ public class Supervisor implements Serializable {
logger.logOperation("Group deleted: " + group.getName());
}
// 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);
logger.logOperation("Student added: " + newStudent.getFullname());
}
// Edits the student, deletes the reference from the old group, and adds everything to the new one
public void editStudent(Student student, String name, String surname, String email, Group group, Faculty faculty, Date birth, Date enrol) {
student.getGroup().deleteStudent(student);
student.setName(name);
@@ -77,6 +88,7 @@ public class Supervisor implements Serializable {
logger.logOperation("Student edited: " + student.getFullname());
}
// Adds a group, and adds it to the faculty
public void addGroup(Group group, Faculty faculty) {
group.setFaculty(faculty);
faculty.addGroup(group);
@@ -84,12 +96,15 @@ public class Supervisor implements Serializable {
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);
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()) {
if (faculty.getName().equals(facultyName))
@@ -98,6 +113,7 @@ public class Supervisor implements Serializable {
return null;
}
// Same thing as getFacultyByName() except for Groups
public Group getGroupByName(String groupName, Faculty faculty) {
for (Group group : getFm().getGm().getGroups()) {
if (group.getName().equals(groupName) && group.getFaculty().equals(faculty))