Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

last fixes #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import javafx.application.Platform;
import javafx.event.ActionEvent;
Expand Down Expand Up @@ -109,7 +105,6 @@ public void setMainController(FXMLController mainController) {
}

private void initListeners() {

DataModel.getInstance()
.getCurrentEmailProperty()
.addListener((observable, oldValue, newValue) -> Platform.runLater(() -> {
Expand All @@ -122,10 +117,7 @@ private void initListeners() {
} else {

var recsText =
switch (newValue.getRecipients().size()) {
case 0 -> "";
default -> String.join(";", newValue.getRecipients());
};
newValue.getRecipients().size() == 0 ? "" : String.join(";", newValue.getRecipients());

// Edit mode
subjectField.setText(newValue.getSubject());
Expand All @@ -139,27 +131,31 @@ private void initListeners() {
toLabel.setText(recsText);

// Check if date is today and set the date format accordingly
Calendar today = Calendar.getInstance();

Calendar date = Calendar.getInstance();
date.setTime(newValue.getDate());
DateFormat df;
if (date.get(Calendar.YEAR) == today.get(Calendar.YEAR)
&& date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
df = new SimpleDateFormat("HH:mm");
} else {
df = new SimpleDateFormat("dd MMM yy, HH:mm");
}
dateLabel.setText(df.format(newValue.getDate()));
setDateFormat(newValue, dateLabel);

emailPane.setVisible(true);
logoPane.setVisible(false);
}
}));

DataModel.getInstance().isEditingModeProperty().addListener((observable, oldValue, isEditing) -> {
updateLayout(isEditing);
});
DataModel.getInstance()
.isEditingModeProperty()
.addListener((observable, oldValue, isEditing) -> updateLayout(isEditing));
}

public static void setDateFormat(Email newValue, Label dateLabel) {
Calendar today = Calendar.getInstance();

Calendar date = Calendar.getInstance();
date.setTime(newValue.getDate());
DateFormat df;
if (date.get(Calendar.YEAR) == today.get(Calendar.YEAR)
&& date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
df = new SimpleDateFormat("HH:mm");
} else {
df = new SimpleDateFormat("dd MMM yy, HH:mm");
}
dateLabel.setText(df.format(newValue.getDate()));
}

private void initView() {
Expand All @@ -176,7 +172,7 @@ private void initView() {

// Set the logo
Platform.runLater(() -> {
Image image = new Image(getClass().getResourceAsStream("/logo-transaprent.png"));
Image image = new Image(Objects.requireNonNull(getClass().getResourceAsStream("/logo-transaprent.png")));
var logo = new ImageView(image);
logo.setImage(image);
logo.fitHeightProperty().bind(logoPane.heightProperty().divide(2.5));
Expand All @@ -200,15 +196,15 @@ private void updateLayout(boolean isEditing) {
}

@FXML public void buttonReply(ActionEvent e) {

DataModel.getInstance()
.getCurrentEmail()
.ifPresentOrElse(
email -> {
DataModel.getInstance().setEditingMode(true);

var subject = "RE: " + email.getSubject();
var body = email.getSender() + " wrote: " + email.getBody();
var body = email.getSender() + " wrote: " + email.getBody()
+ "\n----------------------------------------\n";

var newEmail = new Email(
UUID.randomUUID().toString(),
Expand All @@ -226,7 +222,6 @@ private void updateLayout(boolean isEditing) {
}

@FXML public void buttonReplyAll(ActionEvent actionEvent) {

DataModel.getInstance()
.getCurrentEmail()
.ifPresentOrElse(
Expand All @@ -237,7 +232,8 @@ private void updateLayout(boolean isEditing) {
DataModel.getInstance().getCurrentUser().getEmail();

var subject = "RE: " + email.getSubject();
var body = email.getSender() + " wrote: " + email.getBody();
var body = email.getSender() + " wrote: " + email.getBody()
+ "\n----------------------------------------\n";
var recipients = email.getRecipients().stream()
.filter(recipient -> !recipient.equals(userEmail))
.collect(Collectors.toList());
Expand Down Expand Up @@ -304,10 +300,10 @@ private void updateLayout(boolean isEditing) {
.showAndWait()
.ifPresent(response -> {
if (response.equals("yes")) {
mainController.deleteEmail(email.fileID(), currFolder, hardDelete);
mainController.deleteEmail(email.fileID(), currFolder, true);
}
});
} else mainController.deleteEmail(email.fileID(), currFolder, hardDelete);
} else mainController.deleteEmail(email.fileID(), currFolder, false);
}
},
() -> LOGGER.info("TrashButton: no email selected"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ private void initListeners() {
.bind(DataModel.getInstance().getCurrentUserProperty().map(u -> u == null ? "" : u.getEmail()));

// Update currentFolder model based on selected item
listFolder.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
DataModel.getInstance().setCurrentFolder(newValue.toLowerCase());
});
listFolder
.getSelectionModel()
.selectedItemProperty()
.addListener((observable, oldValue, newValue) ->
DataModel.getInstance().setCurrentFolder(newValue.toLowerCase()));

// Update connection status
DataModel.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public void initListeners() {
});

// Quando viene modificato la cartella corrente, viene aggiornato il testo
DataModel.getInstance().getCurrentFolderProperty().addListener((observable, oldValue, newValue) -> {
currentFolder.textProperty().set(newValue.toUpperCase());
});
DataModel.getInstance().getCurrentFolderProperty().addListener((observable, oldValue, newValue) -> currentFolder
.textProperty()
.set(newValue.toUpperCase()));
}

public void initViews() {
Expand Down
8 changes: 0 additions & 8 deletions client/src/main/java/jmail/client/controllers/FXMLLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ public class FXMLLogin {

@FXML private Label connectionLabel;

public FXMLLogin() {
// String css = Main.getResource("style.css").toExternalForm();
// var scene = Main.primaryStage.getScene();
// scene.getStylesheets().clear();
// scene.getStylesheets().add(css);
}

public void initialize() {
var fontIcon = new FontIcon("mdi2w-web-box");
fontIcon.setIconColor(Paint.valueOf(ColorPalette.GREEN.getHexValue()));
Expand All @@ -62,7 +55,6 @@ public void initialize() {

@FXML public void buttonLogin(javafx.event.ActionEvent e) {
login(UsernameField.getText(), PasswordField.getText());
// login("[email protected]", "emme"); // TODO: Remove this
}

public void login(String username, String password) {
Expand Down
33 changes: 15 additions & 18 deletions client/src/main/java/jmail/client/dialogs/CustomDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

public class CustomDialog extends Dialog<String> {

private ButtonType noBtn;
private ButtonType okBtn;

@FXML private Label messageLabel;

@FXML private Label icon;
Expand All @@ -41,38 +38,40 @@ public CustomDialog(Stage owner, String mode, String title, String message) {

FontIcon fontIcon = null;
String color = "";
ButtonType okButton;
ButtonType noButton;
switch (mode) {
case "error" -> {
fontIcon = new FontIcon("mdi2c-close-circle-outline");
fontIcon.setIconColor(Paint.valueOf(ColorPalette.RED.getHexValue()));
color = "#FF5555";
okBtn = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
dialogPane.getButtonTypes().add(okBtn);
okButton = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
dialogPane.getButtonTypes().add(okButton);
}
case "info" -> {
fontIcon = new FontIcon("mdi2a-alert-circle-outline");
fontIcon.setIconColor(Paint.valueOf(ColorPalette.BLUE.getHexValue()));
color = "#1273DE";
okBtn = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
dialogPane.getButtonTypes().add(okBtn);
okButton = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
dialogPane.getButtonTypes().add(okButton);
}
case "confirm" -> {
fontIcon = new FontIcon("mdi2c-check-circle-outline");
fontIcon.setIconColor(Paint.valueOf(ColorPalette.GREEN.getHexValue()));
color = "#39864F";
noBtn = new ButtonType("Cancel");
dialogPane.getButtonTypes().add(noBtn);
okBtn = new ButtonType("Confirm");
dialogPane.getButtonTypes().add(okBtn);
noButton = new ButtonType("Cancel");
dialogPane.getButtonTypes().add(noButton);
okButton = new ButtonType("Confirm");
dialogPane.getButtonTypes().add(okButton);
}
case "warning" -> {
fontIcon = new FontIcon("mdi2a-alert-circle-outline");
fontIcon.setIconColor(Paint.valueOf(ColorPalette.YELLOW.getHexValue()));
color = "#FFB86C";
noBtn = new ButtonType("Cancel");
dialogPane.getButtonTypes().add(noBtn);
okBtn = new ButtonType("Confirm");
dialogPane.getButtonTypes().add(okBtn);
noButton = new ButtonType("Cancel");
dialogPane.getButtonTypes().add(noButton);
okButton = new ButtonType("Confirm");
dialogPane.getButtonTypes().add(okButton);
}
}
icon.setGraphic(fontIcon);
Expand All @@ -91,9 +90,7 @@ public CustomDialog(Stage owner, String mode, String title, String message) {
return "no";
});

setOnShowing(dialogEvent -> Platform.runLater(() -> {
messageLabel.requestFocus();
}));
setOnShowing(dialogEvent -> Platform.runLater(() -> messageLabel.requestFocus()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class EmailCellFactory implements Callback<ListView<Email>, ListCell<Email>> {

private ListView<Email> parent;
private final ListView<Email> parent;

public EmailCellFactory(ListView<Email> listEmails) {
parent = listEmails;
Expand Down

This file was deleted.

17 changes: 2 additions & 15 deletions client/src/main/java/jmail/client/views/EmailCell.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package jmail.client.views;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.layout.Region;
import jmail.client.Main;
import jmail.client.controllers.FXMLEmailController;
import jmail.lib.models.Email;

public class EmailCell extends ListCell<Email> {
Expand Down Expand Up @@ -63,18 +61,7 @@ public void initListeners() {
fromLabel.setText(newValue.getSender());
subjectLabel.setText(newValue.getSubject());

Calendar today = Calendar.getInstance();

Calendar date = Calendar.getInstance();
date.setTime(newValue.getDate());
DateFormat df;
if (date.get(Calendar.YEAR) == today.get(Calendar.YEAR)
&& date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
df = new SimpleDateFormat("HH:mm");
} else {
df = new SimpleDateFormat("dd MMM yy, HH:mm");
}
dateLabel.setText(df.format(newValue.getDate()));
FXMLEmailController.setDateFormat(newValue, dateLabel);

bodyLabel.setText(newValue.getBody());
readMarker.setStyle("-fx-background-color:" + (newValue.getRead() ? "#00000000;" : "#009688FF;"));
Expand Down
1 change: 0 additions & 1 deletion client/src/main/java/jmail/client/views/FolderCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ protected void updateItem(String item, boolean empty) {
}

private void initListeners() {

itemProperty().addListener((obs, oldValue, newValue) -> {

// Empty cell
Expand Down
4 changes: 0 additions & 4 deletions client/src/main/resources/jmail/client/dialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
wrapText="true" styleClass="f16" />
</VBox>
</content>

<!-- <buttonTypes> <ButtonType fx:id="noBtn" text="No" buttonData="CANCEL_CLOSE"
/> <ButtonType fx:id="okBtn" text="Yes" buttonData="OK_DONE" /> </buttonTypes> -->

</DialogPane>
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,14 @@ private void registerEventListener() {

suggestionList.setOnKeyPressed(ke -> {
switch (ke.getCode()) {
case TAB:
case ENTER:
onSuggestionChosen(suggestionList.getSelectionModel().getSelectedItem());
break;
case ESCAPE:
case TAB, ENTER -> onSuggestionChosen(
suggestionList.getSelectionModel().getSelectedItem());
case ESCAPE -> {
if (control.isHideOnEscape()) {
control.hide();
}
break;
default:
break;
}
default -> {}
}
});
}
Expand Down
12 changes: 2 additions & 10 deletions lib/src/main/java/jmail/lib/handlers/LockHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@

public class LockHandler {
private static final LockHandler instance = new LockHandler();
/** La chiave del lock è l'uuid del'utente TODO: Documentare */

/** Key is user's UUID */
private final ConcurrentHashMap<String, CountableLock> lockMap;

private LockHandler() {
lockMap = new ConcurrentHashMap<>();
}

public static LockHandler getInstance() {
// https://errorprone.info/bugpattern/DoubleCheckedLocking
// https://www.infoworld.com/article/2075306/can-double-checked-locking-be-fixed-.html
// if (instance == null) {
// synchronized (LockHandler.class) {
// if (instance == null) {
// instance = new LockHandler();
// }
// }
// }
return instance;
}

Expand Down
7 changes: 0 additions & 7 deletions lib/src/main/java/jmail/lib/helpers/SystemIOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ public static Path getSentEmailPath(String userEmail, String emailID) {
return Path.of(getUserSent(userEmail) + "/" + emailID);
}

// TODO: take a look at this method later
// public static Boolean userExists(String userEmail) {
// Path user = Paths.get(emailpath);
// File f = new File(Paths.get(String.format("%s\\%s.dat", user, userEmail)).toUri());
// return f.exists() && !f.isDirectory();
// }

public static Boolean userExists(String userEmail) {
File f = new File(getUserDirectory(userEmail).toUri());
return f.exists() && f.isDirectory();
Expand Down
Loading