Added context menu in MessageControl
This commit is contained in:
parent
f9cbc7a62c
commit
272d3f08ef
@ -425,25 +425,7 @@ public final class ChatScene implements Restorable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Context menu actions
|
// 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
|
@FXML
|
||||||
private void deleteContact() { try {} catch (final NullPointerException e) {} }
|
private void deleteContact() { try {} catch (final NullPointerException e) {} }
|
||||||
|
|
||||||
@ -456,7 +438,4 @@ public final class ChatScene implements Restorable {
|
|||||||
updateRemainingCharsLabel();
|
updateRemainingCharsLabel();
|
||||||
postButton.setDisable(messageText.isBlank());
|
postButton.setDisable(messageText.isBlank());
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void loadMessageInfoScene() { try {} catch (final NullPointerException e) {} }
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
package envoy.client.ui.listcell;
|
package envoy.client.ui.listcell;
|
||||||
|
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
@ -14,6 +20,7 @@ import envoy.client.ui.IconUtil;
|
|||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.data.User;
|
import envoy.data.User;
|
||||||
|
import envoy.util.EnvoyLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class formats a single {@link Message} into a UI component.
|
* This class formats a single {@link Message} into a UI component.
|
||||||
@ -25,48 +32,91 @@ import envoy.data.User;
|
|||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public class MessageControl extends VBox {
|
public class MessageControl extends Label {
|
||||||
|
|
||||||
private static User client;
|
private static User client;
|
||||||
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||||
private static final Map<MessageStatus, Image> statusImages = IconUtil.loadByEnum(MessageStatus.class, 16);
|
private static final Map<MessageStatus, Image> statusImages = IconUtil.loadByEnum(MessageStatus.class, 16);
|
||||||
|
|
||||||
|
private static final Logger logger = EnvoyLog.getLogger(MessageControl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param message the message that should be formatted
|
* @param message the message that should be formatted
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public MessageControl(Message message) {
|
public MessageControl(Message message) {
|
||||||
// Creating the underlying VBox, the dateLabel and the textLabel
|
// Creating the underlying VBox and the dateLabel
|
||||||
super(new Label(dateFormat.format(message.getCreationDate())));
|
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
|
// Handling message attachment display
|
||||||
if (message.hasAttachment()) switch (message.getAttachment().getType()) {
|
if (message.hasAttachment()) {
|
||||||
case PICTURE:
|
switch (message.getAttachment().getType()) {
|
||||||
break;
|
case PICTURE:
|
||||||
case VIDEO:
|
break;
|
||||||
break;
|
case VIDEO:
|
||||||
case VOICE:
|
break;
|
||||||
getChildren().add(new AudioControl(message.getAttachment().getData()));
|
case VOICE:
|
||||||
break;
|
vbox.getChildren().add(new AudioControl(message.getAttachment().getData()));
|
||||||
case DOCUMENT:
|
break;
|
||||||
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());
|
final var textLabel = new Label(message.getText());
|
||||||
textLabel.setWrapText(true);
|
textLabel.setWrapText(true);
|
||||||
getChildren().add(textLabel);
|
vbox.getChildren().add(textLabel);
|
||||||
// Setting the message status icon and background color
|
// Setting the message status icon and background color
|
||||||
if (message.getRecipientID() != client.getID()) {
|
if (message.getRecipientID() != client.getID()) {
|
||||||
final var statusIcon = new ImageView(statusImages.get(message.getStatus()));
|
final var statusIcon = new ImageView(statusImages.get(message.getStatus()));
|
||||||
statusIcon.setPreserveRatio(true);
|
statusIcon.setPreserveRatio(true);
|
||||||
getChildren().add(statusIcon);
|
vbox.getChildren().add(statusIcon);
|
||||||
getStyleClass().add("own-message");
|
getStyleClass().add("own-message");
|
||||||
} else getStyleClass().add("received-message");
|
} else getStyleClass().add("received-message");
|
||||||
// Adjusting height and weight of the cell to the corresponding ListView
|
// Adjusting height and weight of the cell to the corresponding ListView
|
||||||
paddingProperty().setValue(new Insets(5, 20, 5, 20));
|
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
|
* @param client the user who has logged in
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
|
@ -92,22 +92,6 @@
|
|||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<contextMenu>
|
|
||||||
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
|
|
||||||
<items>
|
|
||||||
<MenuItem mnemonicParsing="false" onAction="#copyMessage"
|
|
||||||
text="Copy" />
|
|
||||||
<MenuItem mnemonicParsing="false"
|
|
||||||
onAction="#deleteMessage" text="Delete" />
|
|
||||||
<MenuItem mnemonicParsing="false"
|
|
||||||
onAction="#forwardMessage" text="Forward" />
|
|
||||||
<MenuItem mnemonicParsing="false"
|
|
||||||
onAction="#quoteMessage" text="Quote" />
|
|
||||||
<MenuItem mnemonicParsing="false"
|
|
||||||
onAction="#loadMessageInfoScene" text="Info" />
|
|
||||||
</items>
|
|
||||||
</ContextMenu>
|
|
||||||
</contextMenu>
|
|
||||||
</ListView>
|
</ListView>
|
||||||
<ButtonBar prefWidth="436.0" GridPane.columnIndex="1"
|
<ButtonBar prefWidth="436.0" GridPane.columnIndex="1"
|
||||||
GridPane.columnSpan="2147483647" GridPane.halignment="CENTER"
|
GridPane.columnSpan="2147483647" GridPane.halignment="CENTER"
|
||||||
|
Reference in New Issue
Block a user