diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 956ce21..4d585e4 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -425,25 +425,7 @@ public final class ChatScene implements Restorable { } // Context menu actions - - @FXML - private void copyMessage() { - try { - Toolkit.getDefaultToolkit() - .getSystemClipboard() - .setContents(new StringSelection(messageList.getSelectionModel().getSelectedItem().getText()), null); - } catch (final NullPointerException e) {} - } - - @FXML - private void deleteMessage() { try {} catch (final NullPointerException e) {} } - - @FXML - private void forwardMessage() { try {} catch (final NullPointerException e) {} } - - @FXML - private void quoteMessage() { try {} catch (final NullPointerException e) {} } - + @FXML private void deleteContact() { try {} catch (final NullPointerException e) {} } @@ -456,7 +438,4 @@ public final class ChatScene implements Restorable { updateRemainingCharsLabel(); postButton.setDisable(messageText.isBlank()); } - - @FXML - private void loadMessageInfoScene() { try {} catch (final NullPointerException e) {} } } diff --git a/src/main/java/envoy/client/ui/listcell/MessageControl.java b/src/main/java/envoy/client/ui/listcell/MessageControl.java index a5a9404..0628c7a 100644 --- a/src/main/java/envoy/client/ui/listcell/MessageControl.java +++ b/src/main/java/envoy/client/ui/listcell/MessageControl.java @@ -1,10 +1,16 @@ package envoy.client.ui.listcell; +import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; import java.time.format.DateTimeFormatter; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import javafx.geometry.Insets; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; @@ -14,6 +20,7 @@ import envoy.client.ui.IconUtil; import envoy.data.Message; import envoy.data.Message.MessageStatus; import envoy.data.User; +import envoy.util.EnvoyLog; /** * This class formats a single {@link Message} into a UI component. @@ -25,48 +32,91 @@ import envoy.data.User; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class MessageControl extends VBox { +public class MessageControl extends Label { private static User client; private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); private static final Map statusImages = IconUtil.loadByEnum(MessageStatus.class, 16); + private static final Logger logger = EnvoyLog.getLogger(MessageControl.class); + /** * * @param message the message that should be formatted * @since Envoy Client v0.1-beta */ public MessageControl(Message message) { - // Creating the underlying VBox, the dateLabel and the textLabel - super(new Label(dateFormat.format(message.getCreationDate()))); + // Creating the underlying VBox and the dateLabel + final var vbox = new VBox(new Label(dateFormat.format(message.getCreationDate()))); + + // Creating the actions for the MenuItems + final ContextMenu contextMenu = new ContextMenu(); + final MenuItem copyMenuItem = new MenuItem("Copy"); + final MenuItem deleteMenuItem = new MenuItem("Delete"); + final MenuItem forwardMenuItem = new MenuItem("Forward"); + final MenuItem quoteMenuItem = new MenuItem("Quote"); + final MenuItem infoMenuItem = new MenuItem("Info"); + copyMenuItem.setOnAction(e -> copyMessage(message)); + deleteMenuItem.setOnAction(e -> deleteMessage(message)); + forwardMenuItem.setOnAction(e -> forwardMessage(message)); + quoteMenuItem.setOnAction(e -> quoteMessage(message)); + infoMenuItem.setOnAction(e -> loadMessageInfoScene(message)); + contextMenu.getItems().addAll(copyMenuItem, deleteMenuItem, forwardMenuItem, quoteMenuItem, infoMenuItem); // Handling message attachment display - if (message.hasAttachment()) switch (message.getAttachment().getType()) { - case PICTURE: - break; - case VIDEO: - break; - case VOICE: - getChildren().add(new AudioControl(message.getAttachment().getData())); - break; - case DOCUMENT: - break; + if (message.hasAttachment()) { + switch (message.getAttachment().getType()) { + case PICTURE: + break; + case VIDEO: + break; + case VOICE: + vbox.getChildren().add(new AudioControl(message.getAttachment().getData())); + break; + case DOCUMENT: + break; + } + final var saveAttachment = new MenuItem("Save attachment"); + saveAttachment.setOnAction(e -> saveAttachment(message)); + contextMenu.getItems().add(saveAttachment); } - + // Creating the textLabel final var textLabel = new Label(message.getText()); textLabel.setWrapText(true); - getChildren().add(textLabel); + vbox.getChildren().add(textLabel); // Setting the message status icon and background color if (message.getRecipientID() != client.getID()) { final var statusIcon = new ImageView(statusImages.get(message.getStatus())); statusIcon.setPreserveRatio(true); - getChildren().add(statusIcon); + vbox.getChildren().add(statusIcon); getStyleClass().add("own-message"); } else getStyleClass().add("received-message"); // Adjusting height and weight of the cell to the corresponding ListView paddingProperty().setValue(new Insets(5, 20, 5, 20)); + setContextMenu(contextMenu); + setGraphic(vbox); } + // Context Menu actions + + private void copyMessage(Message message) { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(message.getText()), null); + } + + private void deleteMessage(Message message) { logger.log(Level.FINEST, "message deletion was requested for " + message); } + + private void forwardMessage(Message message) { logger.log(Level.FINEST, "message forwarding was requested for " + message); } + + private void quoteMessage(Message message) { logger.log(Level.FINEST, "message quotation was requested for " + message); } + + private void loadMessageInfoScene(Message message) { logger.log(Level.FINEST, "message info scene was requested for " + message); } + + /** + * @param message + * @since Envoy Client v0.1-beta + */ + private void saveAttachment(Message message) { logger.log(Level.FINEST, "attachment saving was requested for " + message); } + /** * @param client the user who has logged in * @since Envoy Client v0.1-beta diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index 0ecdeb2..4a6ac3a 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -92,22 +92,6 @@ - - - - - - - - - - -