From aa992e2bcfbf2214ae754b162ca467ac8895b45f Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Wed, 2 Sep 2020 11:10:05 +0200 Subject: [PATCH] Implemented custom preview support on theme change. --- .../envoy/client/ui/controller/ChatScene.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 1ad5d6e..a35a503 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -29,7 +29,9 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; -import javafx.scene.layout.*; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.FileChooser; @@ -145,6 +147,7 @@ public final class ChatScene implements Restorable { private boolean recording; private Attachment pendingAttachment; private boolean postingPermanentlyDisabled; + private boolean isCustomAttachmentImage = false; private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap(); @@ -152,7 +155,7 @@ public final class ChatScene implements Restorable { private static final EventBus eventBus = EventBus.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); - private static final Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); + private static Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); private static final int MAX_MESSAGE_LENGTH = 255; private static final int DEFAULT_ICON_SIZE = 16; @@ -283,6 +286,20 @@ public final class ChatScene implements Restorable { }); eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); + + eventBus.register(ThemeChangeEvent.class, e -> { + settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); + attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); + DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); + attachmentView.setImage(isCustomAttachmentImage ? attachmentView.getImage() : DEFAULT_ATTACHMENT_VIEW_IMAGE); + messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE))); + clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); + messageList.setCellFactory(MessageListCell::new); + if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); + }); } private AnchorPane createOfflineNote() { @@ -348,15 +365,6 @@ public final class ChatScene implements Restorable { @Override public void onRestore() { updateRemainingCharsLabel(); - settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); - voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); - attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); - attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE); - messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE))); - clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); - chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); - if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); - else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); } /** @@ -523,8 +531,10 @@ public final class ChatScene implements Restorable { pendingAttachment = new Attachment(fileBytes, file.getName(), type); checkPostConditions(false); // Setting the preview image as image of the attachmentView - if (type == AttachmentType.PICTURE) + if (type == AttachmentType.PICTURE) { attachmentView.setImage(new Image(new ByteArrayInputStream(fileBytes), DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE, true, true)); + isCustomAttachmentImage = true; + } attachmentView.setVisible(true); } catch (final IOException e) { new Alert(AlertType.ERROR, "The selected file could not be loaded!").showAndWait(); @@ -705,6 +715,7 @@ public final class ChatScene implements Restorable { messageTextArea.setText(""); postButton.setDisable(true); updateRemainingCharsLabel(); + isCustomAttachmentImage = false; } /**