From 98ebb321ce96e1ef011aaca4008e5e3f21b94012 Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 30 Jul 2020 20:46:28 +0200 Subject: [PATCH] Added OOP approach to some boilerplate code currently implemented @DieGurke,as I don't want to interfere with your branch at all, I only added the absolute minimum that should be mergeable without conflict. I leave the rest of the implementation (usage in ChatScene, ChatControl and referencing in FXML) up to you. There's no way in hell I'll risk your wrath... --- .../client/ui/custom/ProfilePicImageView.java | 62 +++++++++++++++++++ .../envoy/client/ui/custom/package-info.java | 14 +++++ client/src/main/java/module-info.java | 1 + 3 files changed, 77 insertions(+) create mode 100644 client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java create mode 100644 client/src/main/java/envoy/client/ui/custom/package-info.java diff --git a/client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java b/client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java new file mode 100644 index 0000000..89147d0 --- /dev/null +++ b/client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java @@ -0,0 +1,62 @@ +package envoy.client.ui.custom; + +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.shape.Rectangle; + +/** + * Displays the profile picture of a user using the superior method of OOP + * instead of boilerplate code. + *

+ * Project: envoy-client
+ * File: ProfilePicImageView.java
+ * Created: 30.07.2020
+ * + * @author Leon Hofmeister + * @since Envoy Client v0.2-beta + */ +public final class ProfilePicImageView extends ImageView { + + /** + * Creates a new {@code ProfilePicImageView} without a default image. + * + * @since Envoy Client v0.2-beta + */ + public ProfilePicImageView() { this(null); } + + /** + * Creates a new {@code ProfilePicImageView}. + * + * @param image the image to display + * @since Envoy Client v0.2-beta + */ + public ProfilePicImageView(Image image) { this(image, 40); } + + /** + * Creates a new {@code ProfilePicImageView}. + * + * @param image the image to display + * @param sizeAndRounding the size and rounding for a circular + * {@code ProfilePicImageView} + * @since Envoy Client v0.2-beta + */ + public ProfilePicImageView(Image image, double sizeAndRounding) { this(image, sizeAndRounding, sizeAndRounding); } + + /** + * Creates a new {@code ProfilePicImageView}. + * + * @param image the image to display + * @param size the size of this {@code ProfilePicImageView} + * @param rounding how rounded this {@code ProfilePicImageView} should be + * @since Envoy Client v0.2-beta + */ + public ProfilePicImageView(Image image, double size, double rounding) { + super(image); + final var clip = new Rectangle(); + clip.setWidth(size); + clip.setHeight(size); + clip.setArcHeight(rounding); + clip.setArcWidth(rounding); + setClip(clip); + } +} diff --git a/client/src/main/java/envoy/client/ui/custom/package-info.java b/client/src/main/java/envoy/client/ui/custom/package-info.java new file mode 100644 index 0000000..97a8f58 --- /dev/null +++ b/client/src/main/java/envoy/client/ui/custom/package-info.java @@ -0,0 +1,14 @@ +/** + * This package stores custom components for use in JavaFX. + * These components are also expected to be used via FXML. + *

+ * Project: envoy-client
+ * File: package-info.java
+ * Created: 30.07.2020
+ * + * @author Leon Hofmeister + * @author Maximilian Käfer + * @author Kai S. K. Engelbart + * @since Envoy Client v0.2-beta + */ +package envoy.client.ui.custom; diff --git a/client/src/main/java/module-info.java b/client/src/main/java/module-info.java index 1f0d0b1..2b39906 100644 --- a/client/src/main/java/module-info.java +++ b/client/src/main/java/module-info.java @@ -20,4 +20,5 @@ module envoy { opens envoy.client.ui to javafx.graphics, javafx.fxml; opens envoy.client.ui.controller to javafx.graphics, javafx.fxml; + opens envoy.client.ui.custom to javafx.graphics, javafx.fxml; }