Added maximum size for displaying sent images
additionally: - made selecting of bmp or gif images possible - defined a DEFAULT_ICON_SIZE in which most icons are loaded - displayed attachment button with attachment icon
This commit is contained in:
parent
6db489c868
commit
5bd80a2ebc
@ -93,12 +93,13 @@ public final class ChatScene implements Restorable {
|
|||||||
private AudioRecorder recorder;
|
private AudioRecorder recorder;
|
||||||
private boolean recording;
|
private boolean recording;
|
||||||
private Attachment pendingAttachment;
|
private Attachment pendingAttachment;
|
||||||
private boolean postingPermanentlyDisabled = false;
|
private boolean postingPermanentlyDisabled;
|
||||||
|
|
||||||
private static final Settings settings = Settings.getInstance();
|
private static final Settings settings = Settings.getInstance();
|
||||||
private static final EventBus eventBus = EventBus.getInstance();
|
private static final EventBus eventBus = EventBus.getInstance();
|
||||||
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
||||||
private static final int MAX_MESSAGE_LENGTH = 255;
|
private static final int MAX_MESSAGE_LENGTH = 255;
|
||||||
|
private static final int DEFAULT_ICON_SIZE = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the appearance of certain visual components.
|
* Initializes the appearance of certain visual components.
|
||||||
@ -112,8 +113,10 @@ public final class ChatScene implements Restorable {
|
|||||||
messageList.setCellFactory(MessageListCellFactory::new);
|
messageList.setCellFactory(MessageListCellFactory::new);
|
||||||
userList.setCellFactory(ContactListCellFactory::new);
|
userList.setCellFactory(ContactListCellFactory::new);
|
||||||
|
|
||||||
settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", 16)));
|
settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE)));
|
||||||
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
|
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
||||||
|
attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE)));
|
||||||
|
attachmentView.setImage(IconUtil.loadIconThemeSensitive("attachment_present", 20));
|
||||||
|
|
||||||
// Listen to received messages
|
// Listen to received messages
|
||||||
eventBus.register(MessageCreationEvent.class, e -> {
|
eventBus.register(MessageCreationEvent.class, e -> {
|
||||||
@ -273,17 +276,16 @@ public final class ChatScene implements Restorable {
|
|||||||
recording = true;
|
recording = true;
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
voiceButton.setText("Recording");
|
voiceButton.setText("Recording");
|
||||||
voiceButton.setGraphic(new ImageView(IconUtil.loadIcon("microphone_recording", 24)));
|
voiceButton.setGraphic(new ImageView(IconUtil.loadIcon("microphone_recording", DEFAULT_ICON_SIZE)));
|
||||||
});
|
});
|
||||||
recorder.start();
|
recorder.start();
|
||||||
} else {
|
} else {
|
||||||
pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE);
|
pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE);
|
||||||
recording = false;
|
recording = false;
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
|
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
||||||
voiceButton.setText(null);
|
voiceButton.setText(null);
|
||||||
checkPostConditions(false);
|
checkPostConditions(false);
|
||||||
attachmentView.setImage(IconUtil.loadIconThemeSensitive("attachment_present", 20));
|
|
||||||
attachmentView.setVisible(true);
|
attachmentView.setVisible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -302,12 +304,12 @@ public final class ChatScene implements Restorable {
|
|||||||
fileChooser.setTitle("Add Attachment");
|
fileChooser.setTitle("Add Attachment");
|
||||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||||
fileChooser.getExtensionFilters()
|
fileChooser.getExtensionFilters()
|
||||||
.addAll(new FileChooser.ExtensionFilter("Pictures", "*.png", "*.jpg"),
|
.addAll(new FileChooser.ExtensionFilter("Pictures", "*.png", "*.jpg", "*.bmp", "*.gif"),
|
||||||
new FileChooser.ExtensionFilter("Videos", "*.mp4"),
|
new FileChooser.ExtensionFilter("Videos", "*.mp4"),
|
||||||
new FileChooser.ExtensionFilter("All Files", "*.*"));
|
new FileChooser.ExtensionFilter("All Files", "*.*"));
|
||||||
final var file = fileChooser.showOpenDialog(sceneContext.getStage());
|
final var file = fileChooser.showOpenDialog(sceneContext.getStage());
|
||||||
|
|
||||||
if(file != null) {
|
if (file != null) {
|
||||||
|
|
||||||
// Check max file size
|
// Check max file size
|
||||||
if (file.length() > 16E6) {
|
if (file.length() > 16E6) {
|
||||||
@ -330,7 +332,7 @@ public final class ChatScene implements Restorable {
|
|||||||
try {
|
try {
|
||||||
pendingAttachment = new Attachment(Files.readAllBytes(file.toPath()), type);
|
pendingAttachment = new Attachment(Files.readAllBytes(file.toPath()), type);
|
||||||
attachmentView.setVisible(true);
|
attachmentView.setVisible(true);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
new Alert(AlertType.ERROR, "The selected file could not be loaded!").showAndWait();
|
new Alert(AlertType.ERROR, "The selected file could not be loaded!").showAndWait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,8 +424,7 @@ public final class ChatScene implements Restorable {
|
|||||||
final var text = messageTextArea.getText().strip();
|
final var text = messageTextArea.getText().strip();
|
||||||
try {
|
try {
|
||||||
// Creating the message and its metadata
|
// Creating the message and its metadata
|
||||||
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB
|
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
|
||||||
.getIDGenerator())
|
|
||||||
.setText(text);
|
.setText(text);
|
||||||
// Setting an attachment, if present
|
// Setting an attachment, if present
|
||||||
if (pendingAttachment != null) {
|
if (pendingAttachment != null) {
|
||||||
@ -432,8 +433,7 @@ public final class ChatScene implements Restorable {
|
|||||||
attachmentView.setVisible(false);
|
attachmentView.setVisible(false);
|
||||||
}
|
}
|
||||||
// Building the final message
|
// Building the final message
|
||||||
final var message = currentChat.getRecipient() instanceof Group ? builder.buildGroupMessage((Group) currentChat
|
final var message = currentChat.getRecipient() instanceof Group ? builder.buildGroupMessage((Group) currentChat.getRecipient())
|
||||||
.getRecipient())
|
|
||||||
: builder.build();
|
: builder.build();
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
|
@ -68,7 +68,7 @@ public class MessageControl extends Label {
|
|||||||
if (message.hasAttachment()) {
|
if (message.hasAttachment()) {
|
||||||
switch (message.getAttachment().getType()) {
|
switch (message.getAttachment().getType()) {
|
||||||
case PICTURE:
|
case PICTURE:
|
||||||
vbox.getChildren().add(new ImageView(new Image(new ByteArrayInputStream(message.getAttachment().getData()))));
|
vbox.getChildren().add(new ImageView(new Image(new ByteArrayInputStream(message.getAttachment().getData()), 256, 256, true, true)));
|
||||||
break;
|
break;
|
||||||
case VIDEO:
|
case VIDEO:
|
||||||
break;
|
break;
|
||||||
@ -92,9 +92,7 @@ public class MessageControl extends Label {
|
|||||||
statusIcon.setPreserveRatio(true);
|
statusIcon.setPreserveRatio(true);
|
||||||
vbox.getChildren().add(statusIcon);
|
vbox.getChildren().add(statusIcon);
|
||||||
getStyleClass().add("own-message");
|
getStyleClass().add("own-message");
|
||||||
} else {
|
} else getStyleClass().add("received-message");
|
||||||
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);
|
setContextMenu(contextMenu);
|
||||||
|
@ -101,8 +101,7 @@
|
|||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
<buttons>
|
<buttons>
|
||||||
<Button fx:id="attachmentButton" disable="true"
|
<Button fx:id="attachmentButton" disable="true"
|
||||||
mnemonicParsing="false" onAction="#attachmentButtonClicked"
|
mnemonicParsing="false" onAction="#attachmentButtonClicked" />
|
||||||
text="Add Attachment" />
|
|
||||||
<Button fx:id="voiceButton" disable="true"
|
<Button fx:id="voiceButton" disable="true"
|
||||||
onAction="#voiceButtonClicked">
|
onAction="#voiceButtonClicked">
|
||||||
<padding>
|
<padding>
|
||||||
|
Reference in New Issue
Block a user