Added profile pic change mechanism on client and common side

This commit is contained in:
delvh 2020-08-01 10:00:29 +02:00
parent 498f3ef43d
commit 719aa4cd4f
3 changed files with 96 additions and 1 deletions

View File

@ -1,13 +1,23 @@
package envoy.client.ui.settings; package envoy.client.ui.settings;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.InputEvent; import javafx.scene.input.InputEvent;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.client.ui.IconUtil;
import envoy.client.ui.SceneContext; import envoy.client.ui.SceneContext;
import envoy.data.User; import envoy.data.User;
import envoy.event.*; import envoy.event.*;
@ -35,8 +45,40 @@ public class UserSettingsPane extends SettingsPane {
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public UserSettingsPane(SceneContext sceneContext, User user) { public UserSettingsPane(SceneContext sceneContext, User user) {
super("User"); // Display of profile picture change mechanism super("User");
// Display of profile pic change mechanism
final var hbox = new HBox(); final var hbox = new HBox();
// TODO: display current profile pic
final var profilePic = new ImageView(IconUtil.loadIcon("envoy_logo", 50));
profilePic.setCursor(Cursor.HAND);
profilePic.setOnMouseClicked(e -> {
final var pictureChooser = new FileChooser();
pictureChooser.setTitle("Select a new picture");
pictureChooser.setInitialDirectory(new File(System.getProperty("user.home")));
pictureChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Pictures", "*.png", "*.jpg", "*.bmp", "*.gif"));
final var file = pictureChooser.showOpenDialog(sceneContext.getStage());
if (file != null) {
// Check max file size
if (file.length() > 5E6) {
new Alert(AlertType.WARNING, "The selected file exceeds the size limit of 5MB!").showAndWait();
return;
}
try {
currentImageBytes = Files.readAllBytes(file.toPath());
profilePic.setImage(new Image(new ByteArrayInputStream(currentImageBytes)));
profilePicChanged = true;
} catch (final IOException e1) {
e1.printStackTrace();
}
}
});
hbox.getChildren().add(profilePic);
// Displaying the username change mechanism // Displaying the username change mechanism
final var username = user.getName(); final var username = user.getName();

View File

@ -0,0 +1,33 @@
package envoy.event;
/**
* Project: <strong>envoy-common</strong><br>
* File: <strong>ProfilePicChange.java</strong><br>
* Created: <strong>31.07.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Common v0.2-beta
*/
public class ProfilePicChange extends Event<byte[]> {
private final long id;
private static final long serialVersionUID = 0L;
/**
* @param value the byte[] of the new image
* @param userID the ID of the user who changed his profile pic
* @since Envoy Common v0.2-beta
*/
public ProfilePicChange(byte[] value, long userID) {
super(value);
id = userID;
}
/**
* @return the id
* @since Envoy Common v0.2-beta
*/
public long getId() { return id; }
}

View File

@ -0,0 +1,20 @@
package envoy.server.processors;
import java.io.IOException;
import envoy.event.ProfilePicChange;
import envoy.server.net.ObjectWriteProxy;
/**
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>ProfilePicChangeProcessor.java</strong><br>
* Created: <strong>01.08.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Server v0.2-beta
*/
public class ProfilePicChangeProcessor implements ObjectProcessor<ProfilePicChange> {
@Override
public void process(ProfilePicChange event, long socketID, ObjectWriteProxy writeProxy) throws IOException {}
}