eature/gui
Obai Albek 2025-06-04 17:42:39 +02:00
parent c71bece39b
commit 715b55276c
5 changed files with 76 additions and 30 deletions

View File

@ -81,6 +81,21 @@ public class EasyMail {
Email email = this.currentUser.getUsermail().getInbox().getEmailBySubject(subject);
return email.showEmails();
}
public String searchEmailInSentFolder(String subject) throws EmailNotFoundException {
if (subject.trim().isEmpty())
throw new IllegalArgumentException("subject field is required!");
Email email = this.currentUser.getUsermail().getSentFolder().getEmailBySubject(subject);
return email.showEmails();
}
public String searchEmailInTrashFolder(String subject) throws EmailNotFoundException {
if (subject.trim().isEmpty())
throw new IllegalArgumentException("subject field is required!");
Email email = this.currentUser.getUsermail().getTrashFolder().getEmailBySubject(subject);
return email.showEmails();
}
public String[] sendUserDetails() {
String[] details = new String[2];

View File

@ -97,6 +97,7 @@ public class EasyMailWindow extends TemplateWindow {
getAllInboxEmails(email);
} catch (EmailNotFoundException e) {
this.showError(e.getMessage());
getAllInboxEmails("");
}
}
@ -115,7 +116,7 @@ public class EasyMailWindow extends TemplateWindow {
SentWindow sentWindow = new SentWindow();
closeWindow();
sentWindow.showWindow();
sentWindow.getAllSentEmails();
sentWindow.getAllSentEmails("");
showUserDetails();
}
@ -142,22 +143,20 @@ public class EasyMailWindow extends TemplateWindow {
public void getAllInboxEmails(String foundedEmail) {
if (foundedEmail.trim().isEmpty()) {
inboxTableModel.setRowCount(0);
inboxTableModel.setRowCount(0);
ArrayList<String> getEmails = fassade.sendAllEmailsToInboxWindow();
if (getEmails != null && !getEmails.isEmpty())
if (getEmails != null && !getEmails.isEmpty())
for (String tempEmail : getEmails) {
String[] splitEmail = tempEmail.split(",");
Object[] newEmail = { splitEmail[0], splitEmail[1], splitEmail[2] };
inboxTableModel.addRow(newEmail);
}
}else {
} else {
String[] splitEmail = foundedEmail.split(",");
Object[] newEmail = { splitEmail[0], splitEmail[1], splitEmail[2] };
inboxTableModel.addRow(newEmail);
}
}
}

View File

@ -2,6 +2,9 @@ package gui;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import domain.email.EmailNotFoundException;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -41,8 +44,14 @@ public class SentWindow extends TemplateWindow {
}
public void handleSearching() {
String getSubjct = searchField.getText();
try {
String getSubjct = searchField.getText();
String email = fassade.searchEmailInSentFolder(getSubjct);
inboxTableModel.setRowCount(0);
getAllSentEmails(email);
} catch (EmailNotFoundException e) {
this.showError(e.getMessage());
}
}
private void initNavigationPanel() {
@ -90,17 +99,25 @@ public class SentWindow extends TemplateWindow {
tablePanel.add(scrollPane);
}
public void getAllSentEmails() {
ArrayList<String> getEmails = fassade.sendAllEmailsToSentWindow();
String[] splitEmail;
if (getEmails.size() > 0)
for (String tempEmail : getEmails) {
splitEmail = tempEmail.split(",");
String to = splitEmail[0].toString();
String subject = splitEmail[1];
String date = splitEmail[2];
Object[] newEmail = { to, subject, date };
inboxTableModel.addRow(newEmail);
}
public void getAllSentEmails(String email) {
if (email.trim().isEmpty()) {
ArrayList<String> getEmails = fassade.sendAllEmailsToSentWindow();
String[] splitEmail;
if (getEmails.size() > 0)
for (String tempEmail : getEmails) {
splitEmail = tempEmail.split(",");
String to = splitEmail[0].toString();
String subject = splitEmail[1];
String date = splitEmail[2];
Object[] newEmail = { to, subject, date };
inboxTableModel.addRow(newEmail);
}
} else {
String[] splitEmail = email.split(",");
Object[] newEmail = { splitEmail[0], splitEmail[1], splitEmail[2] };
inboxTableModel.addRow(newEmail);
}
}
}

View File

@ -10,7 +10,8 @@ import java.util.ArrayList;
public class TrashWindow extends TemplateWindow {
private DefaultTableModel inboxTableModel;
private JTextField searchField;
public TrashWindow() {
super("Trash - EasyMail");
initUI();
@ -24,11 +25,27 @@ public class TrashWindow extends TemplateWindow {
}
private void initComposePanel() {
JPanel composePanel = createPanel(367, 11, 750, 86, new Color(230, 230, 230), true);
contentPane.add(composePanel);
composePanel.setLayout(null);
JPanel composePanel = createPanel(367, 11, 750, 86, new Color(230, 230, 230), true);
contentPane.add(composePanel);
composePanel.setLayout(null);
searchField = new PlaceholderTextField("Search By subject");
searchField.setBounds(500, 30, 150, 40);
composePanel.add(searchField);
JButton searchButton = new JButton("Search");
searchButton.setBounds(660, 30, 80, 40);
composePanel.add(searchButton);
searchButton.addActionListener(e -> handleSearching());
}
public void handleSearching() {
String getSubjct = searchField.getText();
}
}
private void initNavigationPanel() {
JPanel navigationPanel = createPanel(10, 273, 347, 451, new Color(230, 230, 230), true);
@ -58,7 +75,7 @@ public class TrashWindow extends TemplateWindow {
SentWindow sentWindow = new SentWindow();
closeWindow();
sentWindow.showWindow();
sentWindow.getAllSentEmails();
sentWindow.getAllSentEmails("");
}
});
navigationPanel.add(sentEmails);

View File

@ -5,9 +5,7 @@ import gui.*;
public class Main {
public static void main(String[] args) {
EasyMailWindow easy = new EasyMailWindow();
new EasyMailWindow();
}
}