Restructured project, windows now appear in the center instead of the top

This commit is contained in:
2023-10-02 18:42:01 +03:00
parent 63da644de3
commit d99f604ced
23 changed files with 94 additions and 29 deletions

View File

@@ -16,7 +16,7 @@ public class DataDeserializer {
manager = (Supervisor) ois.readObject();
System.out.println("Supervisor object deserialized successfully.");
} catch (ClassNotFoundException | IOException e) {
System.err.println("Error!");
e.printStackTrace();
}
} else {
System.out.println("Serialized file 'manager.ser' does not exist.");

View File

@@ -12,7 +12,7 @@ public class DataSerializer {
oos.writeObject(manager);
System.out.println("Supervisor object serialized successfully.");
} catch (IOException e) {
System.err.println("Error!");
e.printStackTrace();
}
}

View File

@@ -11,8 +11,8 @@ 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.loader.BatchGraduater;
import org.lumijiez.gui.loader.BatchLoader;
import org.lumijiez.gui.util.DisplayerManager;
import org.lumijiez.managers.Supervisor;
@@ -36,6 +36,10 @@ public class StudentManagementGUI extends JFrame {
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();
}

View File

@@ -109,6 +109,10 @@ public class AddFacultyForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(24, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -44,10 +44,7 @@ public class EditFacultyForm extends JFrame {
submitButton.setText("Submit");
cancelButton.setText("Cancel");
nameLabel.setText("New name:");
nameField.setText("Name...");
facultyLabel.setText("Faculty:");
abbreviationLabel.setText("New abbreviation:");
abbreviationField.setText("Abbreviation...");
specialtyLabel.setText("New specialty:");
ComponentDecorator.submitButton(submitButton);
@@ -129,6 +126,10 @@ public class EditFacultyForm extends JFrame {
.addComponent(submitButton))
.addGap(14, 14, 14)));
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 facultyComboActionPerformed(ActionEvent actionEvent) {

View File

@@ -79,6 +79,10 @@ public class RemoveFacultyForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(21, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -42,7 +42,6 @@ public class ShowFacultyForm extends JFrame {
submitButton.addActionListener(this::submitButtonActionPerformed);
cancelButton.addActionListener(this::cancelButtonActionPerformed);
facultyCombo.addActionListener(this::facultyComboActionPerformed);
ComboBoxRenderers.setFacultyRenderer(facultyCombo);
@@ -82,9 +81,10 @@ public class ShowFacultyForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(24, Short.MAX_VALUE)));
pack();
}
private void facultyComboActionPerformed(ActionEvent actionEvent) {
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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -37,7 +37,6 @@ public class AddGroupForm extends JFrame {
titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18));
titleLabel.setText("Add a new group");
nameField.setText("Name...");
submitButton.setText("Submit");
cancelButton.setText("Cancel");
nameLabel.setText("Name:");
@@ -94,6 +93,10 @@ public class AddGroupForm extends JFrame {
.addComponent(submitButton))
.addGap(15, 15, 15)));
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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -80,6 +80,10 @@ public class DeleteGroupForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(18, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -40,7 +40,6 @@ public class EditGroupForm extends JFrame {
titleLabel.setFont(new java.awt.Font("sansserif", Font.PLAIN, 18));
titleLabel.setText("Edit a group");
nameField.setText("Name...");
submitButton.setText("Submit");
cancelButton.setText("Cancel");
nameLabel.setText("New name:");
@@ -109,6 +108,10 @@ public class EditGroupForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(36, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -82,6 +82,10 @@ public class ShowGroupForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(25, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -238,6 +238,10 @@ public class AddStudentForm extends JFrame {
.addComponent(submitButton))
.addGap(21, 21, 21)));
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 cancelButtonActionPerformed(ActionEvent actionEvent) {

View File

@@ -81,6 +81,10 @@ public class DeleteStudentForm extends JFrame {
.addComponent(cancelButton))
.addContainerGap(26, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -182,8 +182,7 @@ public class EditStudentForm extends JFrame {
.addComponent(cancelButton)
.addGap(34, 34, 34)
.addComponent(submitButton)))
.addContainerGap(27, Short.MAX_VALUE))
);
.addContainerGap(27, Short.MAX_VALUE)));
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
@@ -246,10 +245,12 @@ public class EditStudentForm extends JFrame {
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(submitButton)
.addComponent(cancelButton))
.addContainerGap(25, Short.MAX_VALUE))
);
.addContainerGap(25, 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 cancelButtonActionPerformed(ActionEvent actionEvent) {

View File

@@ -114,6 +114,10 @@ public class GradeStudentForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(30, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -82,6 +82,10 @@ public class GraduateStudentForm extends JFrame {
.addComponent(cancelButton))
.addContainerGap(26, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -82,6 +82,10 @@ public class ShowStudentForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(22, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -84,6 +84,10 @@ public class ShowStudentGradesForm extends JFrame {
.addComponent(submitButton))
.addContainerGap(22, 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 submitButtonActionPerformed(ActionEvent evt) {

View File

@@ -1,9 +1,11 @@
package org.lumijiez.gui.util;
package org.lumijiez.gui.loader;
import org.lumijiez.base.Faculty;
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.managers.Supervisor;
import javax.swing.*;
@@ -100,6 +102,10 @@ public class BatchGraduater extends JFrame {
.addComponent(submitButton))
.addGap(23, 23, 23)));
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 cancelButtonActionPerformed(ActionEvent evt) {

View File

@@ -1,8 +1,10 @@
package org.lumijiez.gui.util;
package org.lumijiez.gui.loader;
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.managers.Supervisor;
import javax.swing.*;
@@ -22,6 +24,10 @@ public class BatchLoader extends JFrame {
public BatchLoader(Supervisor sv) {
this.sv = sv;
this.setTitle("Load a Batch of Students");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screenSize.width - this.getWidth()) / 2;
int y = (screenSize.height - this.getHeight()) / 2;
this.setLocation(x, y);
initComponents();
}
@@ -102,6 +108,10 @@ public class BatchLoader extends JFrame {
.addComponent(submitButton))
.addGap(23, 23, 23)));
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 cancelButtonActionPerformed(ActionEvent evt) {

View File

@@ -6,7 +6,6 @@ public class ComponentDecorator {
public static void submitButton(JButton button) {
button.setBackground(new java.awt.Color(204, 255, 204));
}
public static void cancelButton(JButton button) {
button.setBackground(new java.awt.Color(255, 204, 204));
}

View File

@@ -11,7 +11,7 @@ public class DisplayerManager {
text.append("==================== Students ======================\n");
for (Student student : StudentManagementGUI.getSv().getFm().getGm().getSm().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"));
.append("\nEmail: ").append(student.getEmail()).append("\nGraduated: ").append((student.isGraduated() ? "Yes" : "No"));
text.append("\n===============================================\n");
}
StudentManagementGUI.getMainLabel().setText(text.toString());

View File

@@ -1,13 +1,13 @@
package org.lumijiez.managers;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LogManager {
public class LogManager implements Serializable {
private transient BufferedWriter writer;
@@ -20,7 +20,7 @@ public class LogManager {
FileWriter fwriter = new FileWriter(fileHandle);
writerTemp = new BufferedWriter(fwriter);
} catch (IOException e) {
System.err.println("Error!");
e.printStackTrace();
writerTemp = null;
}
this.writer = writerTemp;
@@ -29,14 +29,13 @@ public class LogManager {
public void logOperation(String msg) {
if (writer == null) init();
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss |");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss | ");
try {
writer.write(currentDateTime.format(formatter) + msg);
writer.flush();
System.out.println(msg);
writer.newLine();
} catch (IOException e) {
System.err.println("Error!");
e.printStackTrace();
}
}
@@ -46,6 +45,5 @@ public class LogManager {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}