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:
		@@ -93,12 +93,13 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
	private AudioRecorder	recorder;
 | 
			
		||||
	private boolean			recording;
 | 
			
		||||
	private Attachment		pendingAttachment;
 | 
			
		||||
	private boolean			postingPermanentlyDisabled	= false;
 | 
			
		||||
	private boolean			postingPermanentlyDisabled;
 | 
			
		||||
 | 
			
		||||
	private static final Settings	settings			= Settings.getInstance();
 | 
			
		||||
	private static final EventBus	eventBus			= EventBus.getInstance();
 | 
			
		||||
	private static final Logger		logger				= EnvoyLog.getLogger(ChatScene.class);
 | 
			
		||||
	private static final int		MAX_MESSAGE_LENGTH	= 255;
 | 
			
		||||
	private static final int		DEFAULT_ICON_SIZE	= 16;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the appearance of certain visual components.
 | 
			
		||||
@@ -112,8 +113,10 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
		messageList.setCellFactory(MessageListCellFactory::new);
 | 
			
		||||
		userList.setCellFactory(ContactListCellFactory::new);
 | 
			
		||||
 | 
			
		||||
		settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", 16)));
 | 
			
		||||
		voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
 | 
			
		||||
		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(IconUtil.loadIconThemeSensitive("attachment_present", 20));
 | 
			
		||||
 | 
			
		||||
		// Listen to received messages
 | 
			
		||||
		eventBus.register(MessageCreationEvent.class, e -> {
 | 
			
		||||
@@ -273,17 +276,16 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
					recording = true;
 | 
			
		||||
					Platform.runLater(() -> {
 | 
			
		||||
						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();
 | 
			
		||||
				} else {
 | 
			
		||||
					pendingAttachment	= new Attachment(recorder.finish(), AttachmentType.VOICE);
 | 
			
		||||
					recording			= false;
 | 
			
		||||
					Platform.runLater(() -> {
 | 
			
		||||
						voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
 | 
			
		||||
						voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
 | 
			
		||||
						voiceButton.setText(null);
 | 
			
		||||
						checkPostConditions(false);
 | 
			
		||||
						attachmentView.setImage(IconUtil.loadIconThemeSensitive("attachment_present", 20));
 | 
			
		||||
						attachmentView.setVisible(true);
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
@@ -302,12 +304,12 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
		fileChooser.setTitle("Add Attachment");
 | 
			
		||||
		fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
 | 
			
		||||
		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("All Files", "*.*"));
 | 
			
		||||
		final var file = fileChooser.showOpenDialog(sceneContext.getStage());
 | 
			
		||||
 | 
			
		||||
		if(file != null) {
 | 
			
		||||
		if (file != null) {
 | 
			
		||||
 | 
			
		||||
			// Check max file size
 | 
			
		||||
			if (file.length() > 16E6) {
 | 
			
		||||
@@ -330,7 +332,7 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
			try {
 | 
			
		||||
				pendingAttachment = new Attachment(Files.readAllBytes(file.toPath()), type);
 | 
			
		||||
				attachmentView.setVisible(true);
 | 
			
		||||
			} catch (IOException e) {
 | 
			
		||||
			} catch (final IOException e) {
 | 
			
		||||
				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();
 | 
			
		||||
		try {
 | 
			
		||||
			// Creating the message and its metadata
 | 
			
		||||
			final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB
 | 
			
		||||
				.getIDGenerator())
 | 
			
		||||
			final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
 | 
			
		||||
				.setText(text);
 | 
			
		||||
			// Setting an attachment, if present
 | 
			
		||||
			if (pendingAttachment != null) {
 | 
			
		||||
@@ -432,8 +433,7 @@ public final class ChatScene implements Restorable {
 | 
			
		||||
				attachmentView.setVisible(false);
 | 
			
		||||
			}
 | 
			
		||||
			// Building the final message
 | 
			
		||||
			final var message = currentChat.getRecipient() instanceof Group ? builder.buildGroupMessage((Group) currentChat
 | 
			
		||||
				.getRecipient())
 | 
			
		||||
			final var message = currentChat.getRecipient() instanceof Group ? builder.buildGroupMessage((Group) currentChat.getRecipient())
 | 
			
		||||
					: builder.build();
 | 
			
		||||
 | 
			
		||||
			// Send message
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ public class MessageControl extends Label {
 | 
			
		||||
		if (message.hasAttachment()) {
 | 
			
		||||
			switch (message.getAttachment().getType()) {
 | 
			
		||||
				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;
 | 
			
		||||
				case VIDEO:
 | 
			
		||||
					break;
 | 
			
		||||
@@ -92,9 +92,7 @@ public class MessageControl extends Label {
 | 
			
		||||
			statusIcon.setPreserveRatio(true);
 | 
			
		||||
			vbox.getChildren().add(statusIcon);
 | 
			
		||||
			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
 | 
			
		||||
		paddingProperty().setValue(new Insets(5, 20, 5, 20));
 | 
			
		||||
		setContextMenu(contextMenu);
 | 
			
		||||
 
 | 
			
		||||
@@ -101,8 +101,7 @@
 | 
			
		||||
			</GridPane.margin>
 | 
			
		||||
			<buttons>
 | 
			
		||||
				<Button fx:id="attachmentButton" disable="true"
 | 
			
		||||
					mnemonicParsing="false" onAction="#attachmentButtonClicked"
 | 
			
		||||
					text="Add Attachment" />
 | 
			
		||||
					mnemonicParsing="false" onAction="#attachmentButtonClicked" />
 | 
			
		||||
				<Button fx:id="voiceButton" disable="true"
 | 
			
		||||
					onAction="#voiceButtonClicked">
 | 
			
		||||
					<padding>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user