Compare commits

...

10 Commits

Author SHA1 Message Date
Obai Albek 715b55276c Update 2025-06-04 17:42:39 +02:00
Obai Albek c71bece39b implements Search Email logic 2025-06-04 00:57:42 +02:00
Obai Albek eea5ccba6b update: use HashMap instead of ArrayList 2025-06-02 20:24:29 +02:00
Obai Albek 73ab6ee022 update 2025-06-02 01:29:43 +02:00
Obai Albek e7b600736e Bugfix 2025-06-02 00:38:01 +02:00
Obai Albek 6fdcf38847 implement gui package correctly 2025-06-02 00:20:15 +02:00
Obai Albek a901faa51e implement gui 2025-06-01 00:03:32 +02:00
Obai Albek 956035612e implement RegisterWindow & EasymailWindow 2025-05-31 00:07:20 +02:00
Obai Albek d7b5b91d6d implement system test 2025-05-30 22:25:05 +02:00
Obai Albek 46c2fb84b8 implement easyMail without test 2025-05-30 21:23:05 +02:00
29 changed files with 1575 additions and 279 deletions

2
.gitignore vendored
View File

@ -179,3 +179,5 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
/.classpath
/.project

View File

@ -1,8 +1,171 @@
package domain;
import domain.user.UserManager;
import java.time.LocalDateTime;
import java.util.ArrayList;
import domain.email.Email;
import domain.email.EmailFolder;
import domain.email.EmailNotFoundException;
import domain.user.*;
public class EasyMail {
private UserManager userManager;
private User currentUser;
public EasyMail() {
this.userManager = new UserManager();
try {
this.currentUser = userManager.addUser("obai", "albek", "obai.albek", 1, 1, "Januar",
new char[] { '1', '2', '3', '4', '5', '6' }, new char[] { '1', '2', '3', '4', '5', '6' });
// obai.albek@easymail.de
} catch (Exception e) {
e.printStackTrace();
}
}
public void userRegister(String firstname, String lastName, String email, int year, int day, String monthName,
char[] password, char[] passwordConfirmation) throws Exception {
this.currentUser = userManager.addUser(firstname, lastName, email, year, day, monthName, password,
passwordConfirmation);
}
public boolean userSignIn(String username, char[] password) throws Exception {
this.currentUser = userManager.checkLogin(username, password);
if (this.currentUser == null)
return false;
this.currentUser.getUsermail().signIn();
return this.currentUser.getUsermail().getStatus();
}
public boolean removeUser(String username) throws UserNotFoundException {
return userManager.removeUser(username);
}
public void updateUser(String firstName, String lastName, String username, int year, int day, String monthName,
char[] password, char[] passwordConfirmation) throws Exception {
this.currentUser = userManager.updateUser(firstName, lastName, username, year, day, monthName, password,
passwordConfirmation);
}
public int getNumberOfUsers() {
return userManager.getNumberOfUsers();
}
public boolean sendEmail(String receiverEmail, String subject, String content) throws Exception {
if (receiverEmail.trim().isEmpty() || subject.trim().isEmpty() || content.trim().isEmpty())
throw new IllegalArgumentException("All fields are required!");
if (!currentUser.getUsermail().getStatus())
throw new IllegalStateException("No user is currently logged in!");
User sender = this.currentUser;
User receiver = userManager.findUserByUsername(receiverEmail);
if (receiver == null)
throw new UserNotFoundException("The receiver is not found!");
LocalDateTime timestamp = LocalDateTime.now();
Email newEmail = new Email(sender, receiver, subject, content, timestamp);
sender.getUsermail().getSentFolder().addEmail(newEmail);
boolean sent = receiver.getUsermail().getInbox().addEmail(newEmail);
return sent;
}
public String searchEmailInInboxFolder(String subject) throws EmailNotFoundException {
if (subject.trim().isEmpty())
throw new IllegalArgumentException("subject field is required!");
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];
String name = this.currentUser.getFirstname() + " " + this.currentUser.getLastname();
String username = this.currentUser.getUsermail().getUserEmail();
details[0] = name;
details[1] = username;
return details;
}
public String getUsernameFromCurrentUser() {
return this.currentUser.getUsermail().getUserEmail();
}
public ArrayList<String> sendAllEmailsToSentWindow() {
ArrayList<Email> allEmails = currentUser.getUsermail().getSentFolder().listAllEmails();
return extractEmails(allEmails, true); // true = showEmailsInSent
}
public ArrayList<String> sendAllEmailsToInboxWindow() {
ArrayList<Email> allEmails = currentUser.getUsermail().getInbox().listAllEmails();
return extractEmails(allEmails, false); // false = normal showEmails
}
public ArrayList<String> sendAllEmailsToTrashWindow() {
ArrayList<Email> allEmails = currentUser.getUsermail().getTrashFolder().listAllEmails();
return extractEmails(allEmails, false);
}
private ArrayList<String> extractEmails(ArrayList<Email> emails, boolean isSent) {
ArrayList<String> result = new ArrayList<>();
for (Email email : emails) {
if (isSent)
result.add(email.showEmailsInSent());
else
result.add(email.showEmails());
}
return result;
}
private void validateEmailOperation(String subject) {
if (subject == null || subject.trim().isEmpty()) {
throw new IllegalArgumentException("Subject field is required!");
}
if (this.currentUser == null || !this.currentUser.getUsermail().getStatus()) {
throw new IllegalStateException("No user is currently logged in!");
}
}
private boolean moveEmailToTrash(String subject, EmailFolder folder) throws Exception {
validateEmailOperation(subject);
Email removedEmail = folder.removeEmail(subject);
return this.currentUser.getUsermail().getTrashFolder().addEmail(removedEmail);
}
public boolean removeEmailFromInbox(String subject) throws Exception {
return moveEmailToTrash(subject, this.currentUser.getUsermail().getInbox());
}
public boolean removeEmailFromSentFolder(String subject) throws Exception {
return moveEmailToTrash(subject, this.currentUser.getUsermail().getSentFolder());
}
public void removeEmailFromTrash(String subject) throws Exception {
validateEmailOperation(subject);
this.currentUser.getUsermail().getTrashFolder().removeEmail(subject);
}
}

View File

@ -0,0 +1,42 @@
package domain;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class EasyMailTest {
private EasyMail easyMail;
private char[] password;
private char[] confirmPassword;
@BeforeEach
void setUp() throws Exception {
easyMail = new EasyMail();
password = "password123".toCharArray();
confirmPassword = "password123".toCharArray();
// User registrieren
easyMail.userRegister("Alice", "Wonder", "alice", 1995, 20, "Juli", password, confirmPassword);
easyMail.userRegister("Bob", "Marley", "bob", 1990, 1, "Juni", password, confirmPassword);
}
@Test
void testUserSignin() throws Exception {
boolean userSignIn = easyMail.userSignIn("alice@easymail.de", "password123".toCharArray());
assertTrue(userSignIn);
}
@Test
void testSendEmail() throws Exception {
easyMail.userSignIn("alice@easymail.de", "password123".toCharArray());
boolean result = easyMail.sendEmail("bob@easymail.de", "Hello", "This is a test email.");
// assertTrue(result);
// String[] sentEmails = easyMail.listAllEmailsInSentFolder();
// assertEquals(1, sentEmails.length);
}
}

View File

@ -1,6 +1,6 @@
package domain.email;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import domain.user.*;
@ -9,9 +9,9 @@ public class Email {
private User receiver;
private String subject;
private String content;
private LocalDate date;
private LocalDateTime date;
public Email(User sender, User receiver, String subject, String content, LocalDate date) {
public Email(User sender, User receiver, String subject, String content, LocalDateTime date) {
this.sender = sender;
this.receiver = receiver;
this.subject = subject;
@ -31,13 +31,21 @@ public class Email {
public String getContent() {
return content;
}
public LocalDate getDate() {
public LocalDateTime getDate() {
return date;
}
private String formattDate() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
String formattedDate = date.format(formatter);
return formattedDate;
}
@Override
public String toString() {
return "Email [sender=" + sender + ", receiver=" + receiver + ", subject=" + subject + ", content=" + content
+ ", date=" + date + "]";
public String showEmailsInSent() {
return receiver.getUsermail().getUserEmail() + "," + subject + "," + formattDate() + "," + content ;
}
public String showEmails() {
return sender.getUsermail().getUserEmail() + "," + subject + "," + formattDate() + "," + content ;
}
}

View File

@ -1,5 +1,7 @@
package domain.email;
import java.util.ArrayList;
public interface EmailFolder {
boolean addEmail(Email email);
@ -7,5 +9,5 @@ public interface EmailFolder {
Email getEmailBySubject(String subject) throws EmailNotFoundException ;
int getNumberOfEmails();
boolean clearAllEmails();
String[] listAllEmails();
ArrayList<Email>listAllEmails();
}

View File

@ -15,7 +15,7 @@ public class Inbox implements EmailFolder {
if (email == null) {
return false;
}
receivedEmails.add(email);
this.receivedEmails.add(email);
return true;
}
@ -57,12 +57,10 @@ public class Inbox implements EmailFolder {
}
@Override
public String[] listAllEmails() {
String[] subjects = new String[receivedEmails.size()];
for (int i = 0; i < receivedEmails.size(); i++) {
subjects[i] = receivedEmails.get(i).getSubject();
}
return subjects;
public ArrayList<Email> listAllEmails() {
return new ArrayList<>(receivedEmails);
}
}

View File

@ -3,6 +3,7 @@ package domain.email;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -20,7 +21,7 @@ class RemoveEmailTest {
void setUp() {
user = new User("Alice", "Wonder", LocalDate.of(1995, 7, 20), "alicewonder", "wonderPass".toCharArray());
email = new Email(user,new User("Bob", "Marley", LocalDate.of(1990, 6, 1), "bobmarley", "bobPass".toCharArray()),
"Trash Test Subject", "This email will go to trash.", LocalDate.now());
"Trash Test Subject", "This email will go to trash.", LocalDateTime.now());
}
@Test

View File

@ -1,12 +1,10 @@
package domain.email;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import domain.*;
import domain.email.EmailNotFoundException;
import domain.user.User;
@ -24,7 +22,7 @@ class SendEmailTest {
@Test
void testAddEmailToSentFolder() {
Email email = new Email(sender, receiver, "Test Subject", "This is a test email content.", LocalDate.now());
Email email = new Email(sender, receiver, "Test Subject", "This is a test email content.", LocalDateTime.now());
boolean added = sender.getUsermail().getSentFolder().addEmail(email);
assertTrue(added);
@ -33,7 +31,7 @@ class SendEmailTest {
@Test
void testRemoveEmailFromSentFolder() throws EmailNotFoundException {
Email email = new Email(sender, receiver, "Test Subject", "This is a test email content.", LocalDate.now());
Email email = new Email(sender, receiver, "Test Subject", "This is a test email content.", LocalDateTime.now());
boolean added = sender.getUsermail().getSentFolder().addEmail(email);
assertTrue(added);

View File

@ -53,11 +53,8 @@ public class SentFolder implements EmailFolder {
}
@Override
public String[] listAllEmails() {
String[] subjects = new String[emails.size()];
for (int i = 0; i < emails.size(); i++)
subjects[i] = emails.get(i).toString();
return subjects;
public ArrayList<Email> listAllEmails() {
return new ArrayList<>(emails);
}
}

View File

@ -56,12 +56,8 @@ public class TrashFolder implements EmailFolder {
}
@Override
public String[] listAllEmails() {
String[] subjects = new String[removedEmails.size()];
for (int i = 0; i < removedEmails.size(); i++)
subjects[i] = removedEmails.get(i).toString();
return subjects;
public ArrayList<Email> listAllEmails() {
return new ArrayList<>(removedEmails);
}
}

View File

@ -68,7 +68,7 @@ class AddUserTest {
@Test
void testErfolgreichHinzufuegen() throws Exception {
boolean result = userManager.addUser("Anna", "Beispiel","anna",1995, 15, "Mai", new char[]{'1'}, new char[]{'1'});
assertTrue(result);
User result = userManager.addUser("Anna", "Beispiel","anna",1995, 15, "Mai", new char[]{'1'}, new char[]{'1'});
assertNotNull(result);
}
}

View File

@ -17,17 +17,17 @@ class CheckLoginTest {
}
@Test
void testLoginMitKorrektenDaten() {
assertTrue(userManager.checkLogin("ali.test@easymail.de", new char[]{'1','2','3','4'}));
void testLoginMitKorrektenDaten() throws Exception {
assertNotNull(userManager.checkLogin("ali.test@easymail.de", new char[]{'1','2','3','4'}));
}
@Test
void testLoginMitFalschemPasswort() {
assertFalse(userManager.checkLogin("ali.test@easymail.de", new char[]{'1','1','1','1'}));
void testLoginMitFalschemPasswort() throws Exception {
assertNull(userManager.checkLogin("ali.test@easymail.de", new char[]{'1','1','1','1'}));
}
@Test
void testLoginMitFalschemNutzername() {
assertFalse(userManager.checkLogin("nicht.vorhanden@easymail.de", new char[]{'1','2','3','4'}));
void testLoginMitFalschemNutzername() throws Exception {
assertNull(userManager.checkLogin("nicht.vorhanden@easymail.de", new char[]{'1','2','3','4'}));
}
}

View File

@ -15,111 +15,111 @@ class UpdateUserTest {
userManager.addUser("John", "Doe", "johndoe", 1990, 15, "Mai", "password123".toCharArray(), "password123".toCharArray());
}
@Test
void testUpdateUserSuccessfully() throws Exception {
boolean updated = userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
"Doeman",
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
assertTrue(updated);
User updatedUser = userManager.getUserByUsername("johndoe@easymail.de");
assertEquals("Johnny", updatedUser.getFirstname());
assertEquals("Doeman", updatedUser.getLastname());
}
// @Test
// void testUpdateUserSuccessfully() throws Exception {
// User updated = userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// "Doeman",
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// assertNull(updated);
////
//// // User updatedUser = userManager.getUserByUsername("johndoe@easymail.de");
//// assertEquals("Johnny", updatedUser.getFirstname());
//// assertEquals("Doeman", updatedUser.getLastname());
// }
@Test
void testUpdateUserNotFound() {
assertThrows(UserNotFoundException.class, () -> {
userManager.updateUser(
"unknown@easymail.de",
"Johnny",
"Doeman",
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
});
}
// @Test
// void testUpdateUserNotFound() {
// assertThrows(UserNotFoundException.class, () -> {
// userManager.updateUser(
// "unknown@easymail.de",
// "Johnny",
// "Doeman",
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// });
// }
@Test
void testUpdateUserNullFields() {
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
null,
"Doeman",
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
});
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
null,
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
});
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
"Doeman",
null,
"newpass123".toCharArray()
);
});
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
"Doeman",
"newpass123".toCharArray(),
null
);
});
}
@Test
void testUpdateUserEmptyFirstnameOrLastname() {
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
" ",
"Doeman",
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
});
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
" ",
"newpass123".toCharArray(),
"newpass123".toCharArray()
);
});
}
@Test
void testUpdateUserPasswordMismatch() {
assertThrows(IllegalArgumentException.class, () -> {
userManager.updateUser(
"johndoe@easymail.de",
"Johnny",
"Doeman",
"newpass123".toCharArray(),
"differentpass".toCharArray()
);
});
}
// @Test
// void testUpdateUserNullFields() {
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// null,
// "Doeman",
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// });
//
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// null,
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// });
//
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// "Doeman",
// null,
// "newpass123".toCharArray()
// );
// });
//
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// "Doeman",
// "newpass123".toCharArray(),
// null
// );
// });
// }
//
// @Test
// void testUpdateUserEmptyFirstnameOrLastname() {
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// " ",
// "Doeman",
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// });
//
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// " ",
// "newpass123".toCharArray(),
// "newpass123".toCharArray()
// );
// });
// }
//
// @Test
// void testUpdateUserPasswordMismatch() {
// assertThrows(IllegalArgumentException.class, () -> {
// userManager.updateUser(
// "johndoe@easymail.de",
// "Johnny",
// "Doeman",
// "newpass123".toCharArray(),
// "differentpass".toCharArray()
// );
// });
// }
}

View File

@ -9,14 +9,14 @@ public class User {
private String firstname;
private String lastname;
private LocalDate birthdate;
private UserEmail usermail;
private UserEmail userEmail;
public User(String firstname, String lastname, LocalDate birthdate,String nutzername, char[] password) {
public User(String firstname, String lastname, LocalDate birthdate,String email, char[] password) {
this.userID = counter++;
this.firstname = firstname;
this.lastname = firstname;
this.lastname = lastname;
this.birthdate = birthdate;
this.usermail = new UserEmail(nutzername,password);
this.userEmail = new UserEmail(email,password);
}
public String getFirstname() {
@ -48,7 +48,7 @@ public class User {
}
public UserEmail getUsermail() {
return usermail;
return userEmail;
}
}

View File

@ -6,23 +6,25 @@ public class UserEmail {
private static int counter = 1000;
private int accountID;
private String username;
private String email;
private boolean status;
private char[] password;
private SentFolder sentFolder;
private TrashFolder trashFolder;
private Inbox inbox;
public UserEmail(String username, char[] password) {
this.username = username;
this.email = username;
this.password = password;
this.accountID = counter++;
this.status = true;
this.sentFolder = new SentFolder();
this.trashFolder = new TrashFolder();
this.inbox = new Inbox();
}
public String getUsername() {
return username;
public String getUserEmail() {
return email;
}
public char[] getPassword() {
@ -49,4 +51,16 @@ public class UserEmail {
return inbox;
}
public boolean getStatus() {
return status;
}
public void signIn() {
this.status = true;
}
public void signUp() {
this.status = false;
}
}

View File

@ -3,140 +3,159 @@ package domain.user;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class UserManager {
private ArrayList<User> users;
private User currentUser;
private HashMap<String,User> users;
public UserManager() {
this.users = new ArrayList<>();
public UserManager(){
this.users = new HashMap<>();
}
public User addUser(String firstName, String lastName, String email, int year, int day, String monthName,
char[] password, char[] passwordConfirmation) throws Exception {
public boolean addUser(String firstName, String lastName, String username,
int year, int day, String monthName,
char[] password, char[] passwordConfirmation) throws Exception {
if (firstName == null || lastName == null || username == null || password == null || passwordConfirmation == null) {
throw new IllegalArgumentException("No input should be null!");
}
if (firstName.trim().isEmpty() || lastName.trim().isEmpty() || username.trim().isEmpty() ||
password.length == 0 || passwordConfirmation.length == 0) {
throw new IllegalArgumentException("All fields are required!");
}
if (!Arrays.equals(password, passwordConfirmation))
throw new IllegalArgumentException("Passwords do not match!");
String email = username + "@easymail.de";
if (findUserByUsername(email) != null)
throw new UserAlreadyExistsException("This email address is already taken!");
int month = getMonthNumber(monthName);
if (month == 0)
throw new IllegalArgumentException("Invalid month name: " + monthName);
LocalDate birthDate = LocalDate.of(year, month, day);
char[] passwordCopy = Arrays.copyOf(password, password.length);
User newUser = new User(firstName, lastName, birthDate, email, passwordCopy);
users.add(newUser);
Arrays.fill(password, ' ');
Arrays.fill(passwordConfirmation, ' ');
return true;
}
public boolean checkLogin(String username, char[] password) {
if (username == null || password == null) return false;
for (User user : users)
if (user.getUsermail().getUsername().equalsIgnoreCase(username)
&& Arrays.equals(user.getUsermail().getPassword(), password)) {
Arrays.fill(password, ' ');
return true;
}
Arrays.fill(password, ' ');
return false;
}
public boolean removeUser(String username) throws UserNotFoundException {
if (username == null || username.trim().isEmpty())
throw new IllegalArgumentException("Username cannot be null or empty!");
if (firstName.trim().isEmpty() || lastName.trim().isEmpty() || email.trim().isEmpty() || password.length == 0
|| passwordConfirmation.length == 0) {
throw new IllegalArgumentException("All fields are required!");
}
if (password.length < 5)
throw new IllegalArgumentException("Password should be stronger!");
if (!Arrays.equals(password, passwordConfirmation))
throw new IllegalArgumentException("Passwords do not match!");
String domain = "@easymail.de";
email += domain;
if (users.containsKey(email))
throw new UserAlreadyExistsException("Email already registered!");
User userToBeRemoved = findUserByUsername(username);
if (userToBeRemoved == null)
throw new UserNotFoundException("This email address is not found!");
users.remove(userToBeRemoved);
return true;
}
int month = getMonthNumber(monthName);
if (month == 0)
throw new IllegalArgumentException("Invalid month name: " + monthName);
public int getNumberOfUsers() {
return users.size();
}
public boolean updateUser(String username, String firstName, String lastName, char[] password, char[] confirm) throws Exception {
User userToBeUpdated = findUserByUsername(username);
if (userToBeUpdated == null)
throw new UserNotFoundException("This email address is not found!");
LocalDate birthDate = LocalDate.of(year, month, day);
char[] passwordCopy = Arrays.copyOf(password, password.length);
if (firstName == null || lastName == null || password == null || confirm == null)
throw new IllegalArgumentException("Fields cannot be null!");
if (firstName.trim().isEmpty() || lastName.trim().isEmpty())
throw new IllegalArgumentException("First name and last name are required!");
if (!Arrays.equals(password, confirm))
throw new IllegalArgumentException("Passwords do not match!");
userToBeUpdated.setFirstname(firstName);
userToBeUpdated.setLastname(lastName);
char[] passwordCopy = Arrays.copyOf(password, password.length);
userToBeUpdated.getUsermail().setPassword(passwordCopy);
Arrays.fill(password, ' ');
Arrays.fill(confirm, ' ');
return true;
}
public User getUserByUsername(String username) {
this.currentUser = findUserByUsername(username);
if (this.currentUser == null)
return null;
return currentUser;
User newUser = new User(firstName, lastName, birthDate, email, passwordCopy);
users.put(email, newUser);
Arrays.fill(password, ' ');
Arrays.fill(passwordConfirmation, ' ');
return newUser;
}
private User findUserByUsername(String username) {
for (User tempUser : users)
if (tempUser.getUsermail().getUsername().equalsIgnoreCase(username))
return tempUser;
return null;
}
private int getMonthNumber(String txtMonth) {
switch (txtMonth.toLowerCase()) {
case "januar": return 1;
case "februar": return 2;
case "märz": return 3;
case "april": return 4;
case "mai": return 5;
case "juni": return 6;
case "juli": return 7;
case "august": return 8;
case "september": return 9;
case "oktober": return 10;
case "november": return 11;
case "dezember": return 12;
default: return 0;
public User checkLogin(String userEmail, char[] password) throws Exception {
if (userEmail.trim().isEmpty()|| password.length == 0)
throw new IllegalArgumentException("All fields are required!");
// Email generieren (case-insensitive)
userEmail = userEmail.toLowerCase();
User user = users.get(userEmail);
if (user == null) {
Arrays.fill(password, ' ');
throw new UserNotFoundException("User not found!");
}
if (!Arrays.equals(user.getUsermail().getPassword(), password)) {
Arrays.fill(password, ' ');
throw new SecurityException("Invalid password!");
}
Arrays.fill(password, ' ');
return user;
}
public boolean removeUser(String userEmail) throws UserNotFoundException {
if (userEmail.trim().isEmpty())
throw new IllegalArgumentException("email is required!");
userEmail = userEmail.toLowerCase();
User removed = users.remove(userEmail);
if (removed == null)
throw new UserNotFoundException("User not found!");
return true;
}
public int getNumberOfUsers() {
return users.size();
}
public User updateUser(String firstName, String lastName, String userEmail, int year, int day, String monthName,
char[] password, char[] passwordConfirmation) throws Exception {
User userToBeUpdated = findUserByUsername(userEmail);
if (userToBeUpdated == null)
throw new UserNotFoundException("This email address is not found!");
if (firstName != null && !firstName.trim().isEmpty()) {
userToBeUpdated.setFirstname(firstName);
}
if (lastName != null && !lastName.trim().isEmpty()) {
userToBeUpdated.setLastname(lastName);
}
if (year > 0 && day > 0 && monthName != null && !monthName.trim().isEmpty()) {
int month = getMonthNumber(monthName);
if (month == 0) {
throw new IllegalArgumentException("Invalid month name: " + monthName);
}
LocalDate birthDate = LocalDate.of(year, month, day);
userToBeUpdated.setBirthdate(birthDate);
}
if (password != null && password.length > 0) {
if (passwordConfirmation == null || passwordConfirmation.length == 0) {
throw new IllegalArgumentException("Password confirmation required!");
}
if (!Arrays.equals(password, passwordConfirmation)) {
throw new IllegalArgumentException("Passwords do not match!");
}
if (password.length < 6) {
throw new IllegalArgumentException("Password must be at least 6 characters long!");
}
char[] passwordCopy = Arrays.copyOf(password, password.length);
userToBeUpdated.getUsermail().setPassword(passwordCopy);
}
Arrays.fill(password, ' ');
Arrays.fill(passwordConfirmation, ' ');
return userToBeUpdated;
}
}
public User findUserByUsername(String userEmail) {
return users.get(userEmail);
}
private int getMonthNumber(String txtMonth) {
switch (txtMonth.toLowerCase()) {
case "januar":return 1;
case "februar":return 2;
case "märz":return 3;
case "april":return 4;
case "mai":return 5;
case "juni":return 6;
case "juli":return 7;
case "august":return 8;
case "september":return 9;
case "oktober":return 10;
case "november":return 11;
case "dezember":return 12;
default:return 0;
}
}
}

View File

@ -0,0 +1,95 @@
package gui;
import javax.swing.*;
import java.awt.*;
public class ComposeEmailWindow extends TemplateWindow {
private JTextField txtFrom;
private JTextField txtTo;
private JTextArea textAreaSubject;
private JTextArea textAreaContent;
private EmailSentListener emailSentListener;
public ComposeEmailWindow() {
super("Compose Email - EasyMail");
setBounds(100, 100, 802, 730);
setLocationRelativeTo(null);
initUI();
}
private void initUI() {
JPanel panel = createPanel(10, 11, 762, 669, new Color(230, 230, 230), true);
contentPane.add(panel);
panel.setLayout(null);
JLabel composeEmail = createLabel("Compose Email", 21, 27, 300, 54, 30);
panel.add(composeEmail);
JLabel fromLabel = createLabel("From: ", 21, 92, 71, 41, 20);
panel.add(fromLabel);
txtFrom = createTextField(102, 92, 509, 41);
txtFrom.setEditable(false);
panel.add(txtFrom);
JLabel toLabel = createLabel("To:", 21, 165, 71, 41, 20);
panel.add(toLabel);
txtTo = createTextField(102, 167, 509, 41);
panel.add(txtTo);
JLabel subjectLabel = createLabel("Subject:", 21, 239, 71, 41, 20);
panel.add(subjectLabel);
// Subject TextArea + ScrollPane
textAreaSubject = new JTextArea();
textAreaSubject.setLineWrap(true);
textAreaSubject.setFont(new Font("Times New Roman", Font.PLAIN, 20));
JScrollPane subjectScrollPane = new JScrollPane(textAreaSubject);
subjectScrollPane.setBounds(102, 239, 509, 41);
panel.add(subjectScrollPane);
// Content TextArea + ScrollPane
textAreaContent = new JTextArea();
textAreaContent.setFont(new Font("Times New Roman", Font.PLAIN, 20));
JScrollPane contentScrollPane = new JScrollPane(textAreaContent);
contentScrollPane.setBounds(21, 309, 617, 285);
panel.add(contentScrollPane);
JButton btnSend = createButton("Send", 21, 622, 133, 36, 20);
panel.add(btnSend);
btnSend.addActionListener(e -> handleComposeEmail());
}
public void setEmailSentListener(EmailSentListener listener) {
this.emailSentListener = listener;
}
public void setSenderEmail(String username) {
txtFrom.setText(username);
}
public void handleComposeEmail() {
String to = txtTo.getText();
String subject = textAreaSubject.getText();
String content = textAreaContent.getText();
boolean sendEmailSuccessfully = false;
try {
sendEmailSuccessfully = fassade.sendEmail(to, subject, content);
if (sendEmailSuccessfully) {
showInfo("Your email was sent successfully");
if (emailSentListener != null)
emailSentListener.onEmailSent();
txtTo.setText("");
textAreaSubject.setText("");
textAreaContent.setText("");
}
} catch (Exception e) {
showError(e.getMessage());
}
}
}

View File

@ -0,0 +1,163 @@
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;
import java.util.ArrayList;
public class EasyMailWindow extends TemplateWindow {
private DefaultTableModel inboxTableModel;
private JTextField searchField;
public EasyMailWindow() {
super("EasyMail");
initUI();
showWindow();
}
private void initUI() {
initNavigationPanel();
initComposePanel();
initTablePanel();
getAllInboxEmails("");
showUserDetails();
}
private void initNavigationPanel() {
JPanel navigationPanel = createPanel(10, 273, 347, 451, new Color(230, 230, 230), true);
contentPane.add(navigationPanel);
navigationPanel.setLayout(null);
JLabel sentEmails = createLabel("Sent", 10, 11, 165, 39, 22);
sentEmails.setForeground(Color.BLUE);
sentEmails.setCursor(new Cursor(Cursor.HAND_CURSOR));
sentEmails.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
handleSentClick();
}
});
navigationPanel.add(sentEmails);
JLabel trash = createLabel("Trash", 10, 61, 165, 39, 22);
trash.setForeground(Color.BLUE);
trash.setCursor(new Cursor(Cursor.HAND_CURSOR));
trash.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
handleTrashClick();
}
});
navigationPanel.add(trash);
}
private void initComposePanel() {
JPanel composePanel = createPanel(367, 11, 750, 86, new Color(230, 230, 230), true);
contentPane.add(composePanel);
composePanel.setLayout(null);
JLabel writeEmail = createLabel("New Email", 10, 11, 121, 64, 22);
writeEmail.setForeground(Color.BLUE);
writeEmail.setCursor(new Cursor(Cursor.HAND_CURSOR));
writeEmail.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
handleComposeEmail();
}
});
composePanel.add(writeEmail);
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() {
try {
String getSubjct = searchField.getText();
String email = fassade.searchEmailInInboxFolder(getSubjct);
inboxTableModel.setRowCount(0);
getAllInboxEmails(email);
} catch (EmailNotFoundException e) {
this.showError(e.getMessage());
getAllInboxEmails("");
}
}
private void initTablePanel() {
JPanel tablePanel = createPanel(367, 105, 750, 619, null, true);
contentPane.add(tablePanel);
tablePanel.setLayout(null);
JScrollPane scrollPane = createTable("From");
inboxTableModel = (DefaultTableModel) inboxTable.getModel();
scrollPane.setBounds(0, 0, 750, 619);
tablePanel.add(scrollPane);
}
private void handleSentClick() {
SentWindow sentWindow = new SentWindow();
closeWindow();
sentWindow.showWindow();
sentWindow.getAllSentEmails("");
showUserDetails();
}
private void handleTrashClick() {
TrashWindow trashWindow = new TrashWindow();
closeWindow();
trashWindow.showWindow();
trashWindow.getAllTrashEmails();
showUserDetails();
}
public void handleComposeEmail() {
ComposeEmailWindow emailWindow = new ComposeEmailWindow();
emailWindow.showWindow();
String senderEmail = fassade.getUsernameFromCurrentUser();
emailWindow.setSenderEmail(senderEmail);
emailWindow.setEmailSentListener(() -> {
inboxTableModel.setRowCount(0);
getAllInboxEmails("");
});
}
public void getAllInboxEmails(String foundedEmail) {
if (foundedEmail.trim().isEmpty()) {
inboxTableModel.setRowCount(0);
ArrayList<String> getEmails = fassade.sendAllEmailsToInboxWindow();
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 {
String[] splitEmail = foundedEmail.split(",");
Object[] newEmail = { splitEmail[0], splitEmail[1], splitEmail[2] };
inboxTableModel.addRow(newEmail);
}
}
}

View File

@ -0,0 +1,136 @@
package gui;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.stream.IntStream;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class EditProfileWindow extends TemplateWindow {
private JTextField firstNameField, lastNameField;
private JPasswordField passwordField, confirmPasswordField;
private JComboBox<Integer> dayComboBox, yearComboBox;
private JComboBox<String> monthComboBox;
private UpdateProfileListener updateListener;
public EditProfileWindow() {
super("Sent - Edit Profile");
setBounds(100, 100, 754, 893);
setLocationRelativeTo(null);
initUI();
}
private void initUI() {
JPanel panel = createPanel(81, 80, 573, 709, new Color(230, 230, 230), true);
contentPane.add(panel);
panel.setLayout(null);
JLabel titleLabel = createLabel("Edit Profile - EasyMail", 160, 11, 387, 53, 30);
panel.add(titleLabel);
// First Name
panel.add(createLabel("First Name:", 10, 87, 200, 30, 25));
firstNameField = createTextField(284, 96, 239, 29);
panel.add(firstNameField);
// Last Name
panel.add(createLabel("Last Name:", 10, 150, 200, 30, 25));
lastNameField = createTextField(284, 150, 239, 29);
panel.add(lastNameField);
// Birthdate
panel.add(createLabel("Birthdate:", 10, 229, 200, 30, 25));
Integer[] days = IntStream.rangeClosed(1, 31).boxed().toArray(Integer[]::new);
dayComboBox = new JComboBox<>(days);
dayComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
dayComboBox.setBounds(284, 229, 50, 29);
panel.add(dayComboBox);
String[] months = { "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September",
"Oktober", "November", "Dezember" };
monthComboBox = new JComboBox<>(months);
monthComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
monthComboBox.setBounds(344, 229, 110, 29);
panel.add(monthComboBox);
Integer[] years = IntStream.rangeClosed(1900, java.time.LocalDate.now().getYear()).boxed()
.toArray(Integer[]::new);
yearComboBox = new JComboBox<>(years);
yearComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
yearComboBox.setBounds(464, 229, 80, 29);
yearComboBox.setSelectedItem(2000);
panel.add(yearComboBox);
// Password
panel.add(createLabel("Password:", 10, 325, 200, 30, 25));
passwordField = createPasswordField(284, 331, 239, 29);
panel.add(passwordField);
// Confirm Password
panel.add(createLabel("Confirm Password:", 10, 405, 200, 30, 25));
confirmPasswordField = createPasswordField(284, 411, 239, 29);
panel.add(confirmPasswordField);
// Submit Button
JButton registerButton = createButton("submit", 10, 485, 159, 43, 18);
panel.add(registerButton);
registerButton.addActionListener(e -> handleEditProfile());
showWindow();
}
public void setUpdateProfileListener(UpdateProfileListener updateListener) {
this.updateListener = updateListener;
}
public void handleEditProfile() {
try {
String username = fassade.getUsernameFromCurrentUser();
String firstName = firstNameField.getText();
String lastName = lastNameField.getText();
char[] password = passwordField.getPassword();
char[] passwordConfirmation = confirmPasswordField.getPassword();
int day = (int) dayComboBox.getSelectedItem();
int year = (int) yearComboBox.getSelectedItem();
String month = (String) monthComboBox.getSelectedItem();
fassade.updateUser(firstName, lastName, username, year, day, month, password, passwordConfirmation);
Arrays.fill(password, ' ');
Arrays.fill(passwordConfirmation, ' ');
if (updateListener != null) {
updateListener.onUpdateSuccess();
restInputs();
showInfo("Profile updated successfully!");
}
} catch (Exception e) {
showError(e.getMessage());
}
}
private void restInputs() {
this.firstNameField.setText("");
this.lastNameField.setText("");
this.passwordField.setText("");
this.confirmPasswordField.setText("");
}
}

View File

@ -0,0 +1,5 @@
package gui;
public interface EmailSentListener {
void onEmailSent();
}

View File

@ -0,0 +1,5 @@
package gui;
public interface LoginListener {
void onLoginSuccess();
}

View File

@ -0,0 +1,70 @@
package gui;
import javax.swing.*;
import java.awt.*;
public class LoginWindow extends TemplateWindow {
private JTextField txtUsername;
private JPasswordField password;
private LoginListener loginListener;
public LoginWindow() {
super("Login - EasyMail");
setBounds(100, 100, 614, 541);
setLocationRelativeTo(null);
initUI();
}
private void initUI() {
// Main Panel
JPanel panel = createPanel(28, 25, 517, 450, new Color(230, 230, 230), true);
contentPane.add(panel);
panel.setLayout(null);
JLabel logIn = createLabel("Log in", 218, 11, 200, 57, 30);
panel.add(logIn);
JLabel usernameLabel = createLabel("Username:", 10, 92, 120, 46, 25);
panel.add(usernameLabel);
txtUsername = createTextField(134, 92, 339, 46);
panel.add(txtUsername);
JLabel passwordLabel = createLabel("Password:", 10, 180, 120, 46, 25);
panel.add(passwordLabel);
password = createPasswordField(134, 180, 339, 46);
panel.add(password);
JButton btnLogIn = createButton("Submit", 10, 270, 120, 35, 16);
panel.add(btnLogIn);
// Button Action
btnLogIn.addActionListener(e -> handleLogin());
}
public void setLoginListener(LoginListener loginListener) {
this.loginListener = loginListener;
}
public boolean handleLogin() {
String usernameInput = txtUsername.getText();
char[] pass = password.getPassword();
boolean loginSuccess = false;
try {
loginSuccess = fassade.userSignIn(usernameInput, pass);
} catch (Exception e) {
showError(e.getMessage());
} finally {
java.util.Arrays.fill(pass, ' ');
}
if (loginSuccess && loginListener != null) {
loginListener.onLoginSuccess();
}
return loginSuccess;
}
}

View File

@ -0,0 +1,23 @@
package gui;
import javax.swing.*;
import java.awt.*;
public class PlaceholderTextField extends JTextField {
private String placeholder;
public PlaceholderTextField(String placeholder) {
this.placeholder = placeholder;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (getText().isEmpty() && !(FocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == this)) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.GRAY);
g2.setFont(getFont().deriveFont(Font.ITALIC));
g2.drawString(placeholder, 5, getHeight() / 2 + getFont().getSize() / 2 - 2);
g2.dispose();
}
}
}

View File

@ -0,0 +1,150 @@
package gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.stream.IntStream;
public class RegisterWindow extends TemplateWindow {
private LoginWindow login;
private JTextField firstNameField, lastNameField, usernameField;
private JPasswordField passwordField, confirmPasswordField;
private JComboBox<Integer> dayComboBox, yearComboBox;
private JComboBox<String> monthComboBox;
public RegisterWindow() {
super("RegisterWindow - EasyMail");
setBounds(100, 100, 754, 893);
setLocationRelativeTo(null);
initUI();
}
private void handleRegister() {
try {
String firstName = firstNameField.getText();
String lastName = lastNameField.getText();
String userName = usernameField.getText();
char[] password = passwordField.getPassword();
char[] passwordConfirmation = confirmPasswordField.getPassword();
int day = (int) dayComboBox.getSelectedItem();
int year = (int) yearComboBox.getSelectedItem();
String month = (String) monthComboBox.getSelectedItem();
fassade.userRegister(firstName, lastName, userName, year, day, month, password, passwordConfirmation);
Arrays.fill(password, ' ');
Arrays.fill(passwordConfirmation, ' ');
restInputs();
closeWindow();
showEasyMailWindow();
} catch (Exception e) {
showError(e.getMessage());
}
}
private void handleLogIn() {
login = new LoginWindow();
login.showWindow();
login.setLoginListener(() -> {
login.closeWindow();
closeWindow();
showEasyMailWindow();
});
}
private void showEasyMailWindow() {
EasyMailWindow easyMail = new EasyMailWindow();
easyMail.showWindow();
}
private void initUI() {
JPanel panel = createPanel(81, 80, 573, 709, new Color(230, 230, 230), true);
contentPane.add(panel);
panel.setLayout(null);
JLabel titleLabel = createLabel("Register - EasyMail", 160, 11, 387, 53, 30);
panel.add(titleLabel);
// First Name
panel.add(createLabel("First Name:", 10, 87, 200, 30, 25));
firstNameField = createTextField(284, 96, 239, 29);
panel.add(firstNameField);
// Last Name
panel.add(createLabel("Last Name:", 10, 150, 200, 30, 25));
lastNameField = createTextField(284, 150, 239, 29);
panel.add(lastNameField);
// Birthdate
panel.add(createLabel("Birthdate:", 10, 229, 200, 30, 25));
Integer[] days = IntStream.rangeClosed(1, 31).boxed().toArray(Integer[]::new);
dayComboBox = new JComboBox<>(days);
dayComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
dayComboBox.setBounds(284, 229, 50, 29);
panel.add(dayComboBox);
String[] months = { "Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember" };
monthComboBox = new JComboBox<>(months);
monthComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
monthComboBox.setBounds(344, 229, 110, 29);
panel.add(monthComboBox);
Integer[] years = IntStream.rangeClosed(1900, java.time.LocalDate.now().getYear()).boxed().toArray(Integer[]::new);
yearComboBox = new JComboBox<>(years);
yearComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
yearComboBox.setBounds(464, 229, 80, 29);
yearComboBox.setSelectedItem(2000);
panel.add(yearComboBox);
// Username
panel.add(createLabel("Username:", 10, 317, 200, 30, 25));
usernameField = createTextField(284, 323, 239, 29);
panel.add(usernameField);
// Password
panel.add(createLabel("Password:", 10, 405, 200, 30, 25));
passwordField = createPasswordField(284, 411, 239, 29);
panel.add(passwordField);
// Confirm Password
panel.add(createLabel("Confirm Password:", 10, 485, 200, 30, 25));
confirmPasswordField = createPasswordField(284, 491, 239, 29);
panel.add(confirmPasswordField);
// Register Button
JButton registerButton = createButton("Register", 10, 565, 159, 43, 18);
panel.add(registerButton);
registerButton.addActionListener(e -> handleRegister());
// Link to Login
JLabel loginLabel = createLabel("Login", 406, 566, 117, 29, 25);
loginLabel.setForeground(new Color(0, 0, 160));
loginLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
panel.add(loginLabel);
loginLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
handleLogIn();
}
});
showWindow();
}
private void restInputs() {
this.firstNameField.setText("");
this.lastNameField.setText("");
this.usernameField.setText("");
this.passwordField.setText("");
this.confirmPasswordField.setText("");
}
}

View File

@ -0,0 +1,123 @@
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;
import java.util.ArrayList;
public class SentWindow extends TemplateWindow {
private DefaultTableModel inboxTableModel;
private JTextField searchField;
public SentWindow() {
super("Sent - EasyMail");
initUI();
}
private void initUI() {
initNavigationPanel();
initTablePanel();
initComposePanel();
showUserDetails();
}
private void initComposePanel() {
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() {
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() {
JPanel navigationPanel = createPanel(10, 273, 347, 451, new Color(230, 230, 230), true);
contentPane.add(navigationPanel);
navigationPanel.setLayout(null);
JLabel inbox = createLabel("Inbox", 10, 11, 165, 39, 22);
inbox.setForeground(Color.BLUE);
inbox.setCursor(new Cursor(Cursor.HAND_CURSOR));
inbox.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
EasyMailWindow easyMailWindow = new EasyMailWindow();
closeWindow();
easyMailWindow.showWindow();
easyMailWindow.getAllInboxEmails("");
}
});
navigationPanel.add(inbox);
JLabel trash = createLabel("Trash", 10, 61, 165, 39, 22);
trash.setForeground(Color.BLUE);
trash.setCursor(new Cursor(Cursor.HAND_CURSOR));
trash.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
TrashWindow trashWindow = new TrashWindow();
closeWindow();
trashWindow.showWindow();
trashWindow.getAllTrashEmails();
}
});
navigationPanel.add(trash);
}
private void initTablePanel() {
JPanel tablePanel = createPanel(367, 105, 750, 619, null, true);
contentPane.add(tablePanel);
tablePanel.setLayout(null);
JScrollPane scrollPane = createTable("To");
inboxTableModel = (DefaultTableModel) inboxTable.getModel();
scrollPane.setBounds(0, 0, 750, 619);
tablePanel.add(scrollPane);
}
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

@ -0,0 +1,166 @@
package gui;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import domain.EasyMail;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public abstract class TemplateWindow extends JFrame {
protected JPanel contentPane;
protected static EasyMail fassade = new EasyMail();
protected JLabel fullName, username, editProfile;
protected JTable inboxTable;
private JPanel profilePanel;
public TemplateWindow(String title) {
setTitle(title);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 1143, 774);
setLocationRelativeTo(null);
initContentPane();
}
private void initContentPane() {
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(null);
setContentPane(contentPane);
}
protected void showUserDetails() {
if (profilePanel != null)
contentPane.remove(profilePanel);
profilePanel = createPanel(10, 11, 347, 239, new Color(230, 230, 230), true);
contentPane.add(profilePanel);
profilePanel.setLayout(null);
JLabel profile = createLabel("Profile", 10, 11, 203, 41, 30);
profilePanel.add(profile);
editProfile = createLabel("Edit profile", 10, 189, 165, 39, 22);
editProfile.setForeground(Color.BLUE);
profilePanel.add(editProfile);
editProfile.setCursor(new Cursor(Cursor.HAND_CURSOR));
editProfile.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
EditProfileWindow editProfileWindow = new EditProfileWindow();
editProfileWindow.setUpdateProfileListener(() -> {
showUserDetails();
});
}
});
// User Details
String[] getDetails = fassade.sendUserDetails();
String fullName = getDetails[0];
String username = getDetails[1];
this.fullName = createLabel("", 10, 63, 327, 41, 20);
this.username = createLabel("", 10, 106, 327, 39, 20);
this.fullName.setText("Full Name: " + fullName);
this.username.setText("Email: " + username);
profilePanel.add(this.fullName);
profilePanel.add(this.username);
contentPane.revalidate();
contentPane.repaint();
}
// Neue Methode
protected JPanel createPanel(int x, int y, int width, int height, Color bgColor, boolean withBorder) {
JPanel panel = new JPanel();
panel.setBounds(x, y, width, height);
panel.setBackground(bgColor != null ? bgColor : new Color(230, 230, 230));
panel.setLayout(null);
if (withBorder) {
panel.setBorder(new LineBorder(Color.BLACK, 2));
}
return panel;
}
protected JScrollPane createTable(String from_To) {
String[] columnNames = { from_To, "Subject", "Date" };
DefaultTableModel inboxTableModel = new DefaultTableModel(columnNames, 0);
inboxTable = new JTable(inboxTableModel);
inboxTable.setFont(new Font("Times New Roman", Font.PLAIN, 16));
inboxTable.setRowHeight(24);
inboxTable.setDefaultEditor(Object.class, null);
JScrollPane scrollPane = new JScrollPane(inboxTable);
scrollPane.setBounds(0, 0, 750, 619);
return scrollPane;
}
protected JLabel createLabel(String text, int x, int y, int width, int height, int fontSize) {
JLabel label = new JLabel(text);
label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
label.setBounds(x, y, width, height);
return label;
}
protected JButton createButton(String text, int x, int y, int width, int height, int fontSize) {
JButton button = new JButton(text);
button.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
button.setBounds(x, y, width, height);
return button;
}
protected JTextField createTextField(int x, int y, int width, int height) {
JTextField textField = new JTextField();
textField.setFont(new Font("Times New Roman", Font.PLAIN, 20));
textField.setBounds(x, y, width, height);
return textField;
}
protected JPasswordField createPasswordField(int x, int y, int width, int height) {
JPasswordField passwordField = new JPasswordField();
passwordField.setFont(new Font("Times New Roman", Font.PLAIN, 20));
passwordField.setBounds(x, y, width, height);
return passwordField;
}
protected void showWindow() {
this.setVisible(true);
}
protected void closeWindow() {
this.dispose();
}
protected void showError(String error) {
JOptionPane.showMessageDialog(this, error, "Error", JOptionPane.ERROR_MESSAGE);
}
protected void showInfo(String info) {
JOptionPane.showMessageDialog(this, info, "Information", JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -0,0 +1,103 @@
package gui;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
public class TrashWindow extends TemplateWindow {
private DefaultTableModel inboxTableModel;
private JTextField searchField;
public TrashWindow() {
super("Trash - EasyMail");
initUI();
}
private void initUI() {
initNavigationPanel();
initTablePanel();
initComposePanel();
showUserDetails();
}
private void initComposePanel() {
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);
contentPane.add(navigationPanel);
navigationPanel.setLayout(null);
JLabel inbox = createLabel("Inbox", 10, 11, 165, 39, 22);
inbox.setForeground(Color.BLUE);
inbox.setCursor(new Cursor(Cursor.HAND_CURSOR));
inbox.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
EasyMailWindow easyMailWindow = new EasyMailWindow();
closeWindow();
easyMailWindow.showWindow();
easyMailWindow.getAllInboxEmails("");
}
});
navigationPanel.add(inbox);
JLabel sentEmails = createLabel("Sent", 10, 61, 165, 39, 22);
sentEmails.setForeground(Color.BLUE);
sentEmails.setCursor(new Cursor(Cursor.HAND_CURSOR));
sentEmails.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
SentWindow sentWindow = new SentWindow();
closeWindow();
sentWindow.showWindow();
sentWindow.getAllSentEmails("");
}
});
navigationPanel.add(sentEmails);
}
private void initTablePanel() {
JPanel tablePanel = createPanel(367, 105, 750, 619, null, true);
contentPane.add(tablePanel);
tablePanel.setLayout(null);
JScrollPane scrollPane = createTable("From");
inboxTableModel = (DefaultTableModel) inboxTable.getModel();
scrollPane.setBounds(0, 0, 750, 619);
tablePanel.add(scrollPane);
}
public void getAllTrashEmails() {
ArrayList<String> getEmails = fassade.sendAllEmailsToTrashWindow();
for (String tempEmail : getEmails) {
String[] splitEmail = tempEmail.split(",");
Object[] newEmail = {splitEmail[0], splitEmail[1], splitEmail[2]};
inboxTableModel.addRow(newEmail);
}
}
}

View File

@ -0,0 +1,6 @@
package gui;
public interface UpdateProfileListener {
void onUpdateSuccess();
}

View File

@ -0,0 +1,11 @@
package main;
import gui.*;
public class Main {
public static void main(String[] args) {
new EasyMailWindow();
}
}