From ca1256f01f0dcb42ecc0c5ec0339bd3162683d0e Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Tue, 12 Apr 2022 23:46:38 +0200 Subject: [PATCH] Created Classes and Interfaces. Trying to adhere to the MVC pattern --- .../client/gui/ClientController.java | 5 + .../multiplayer/client/gui/ClientModel.java | 5 + .../multiplayer/client/gui/ClientView.java | 5 + .../client/gui/chat/BroadcastButton.java | 7 + .../client/gui/chat/ChatController.java | 7 + .../multiplayer/client/gui/chat/ChatMsg.java | 7 + .../client/gui/chat/ChatObserver.java | 5 + .../multiplayer/client/gui/chat/ChatView.java | 20 ++ .../client/gui/chat/InChatObserver.java | 5 + .../client/gui/chat/InComingChMsg.java | 225 ++++++++++++++++++ .../client/gui/chat/OutChatObserver.java | 5 + .../client/gui/chat/SendButton.java | 7 + .../client/gui/chat/WhisperButton.java | 7 + 13 files changed, 310 insertions(+) create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientController.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientView.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/BroadcastButton.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatMsg.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatObserver.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatView.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InChatObserver.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InComingChMsg.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/OutChatObserver.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/SendButton.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/WhisperButton.java diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientController.java new file mode 100644 index 0000000..b993dba --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientController.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; + +public class ClientController { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java new file mode 100644 index 0000000..da11ecc --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; + +public class ClientModel { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientView.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientView.java new file mode 100644 index 0000000..7440425 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientView.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; + +public class ClientView { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/BroadcastButton.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/BroadcastButton.java new file mode 100644 index 0000000..1ce08d2 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/BroadcastButton.java @@ -0,0 +1,7 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +import javafx.scene.Node; + +public class BroadcastButton extends Node { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java new file mode 100644 index 0000000..97fb8a1 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java @@ -0,0 +1,7 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +public class ChatController { + + public void setChatView(){}; + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatMsg.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatMsg.java new file mode 100644 index 0000000..69954a1 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatMsg.java @@ -0,0 +1,7 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +public interface ChatMsg { + + public String display(String msg); + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatObserver.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatObserver.java new file mode 100644 index 0000000..c89cde3 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatObserver.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +public interface ChatObserver { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatView.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatView.java new file mode 100644 index 0000000..b0086b1 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatView.java @@ -0,0 +1,20 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.SceneAntialiasing; +import javafx.scene.control.Label; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Paint; + +public class ChatView { + + private Label send = new Label("Send"); + + private Pane root; + + private Pane createNodeHierarchy(){ + Pane p = new Pane(); + return p; + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InChatObserver.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InChatObserver.java new file mode 100644 index 0000000..7dcb7da --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InChatObserver.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +public interface InChatObserver { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InComingChMsg.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InComingChMsg.java new file mode 100644 index 0000000..9f37b26 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/InComingChMsg.java @@ -0,0 +1,225 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +import javafx.beans.InvalidationListener; +import javafx.beans.property.Property; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +/** + * This class represents an incoming chat message to be displayed by the clients gui. When creating + * an instance we should make sure we are also passing a String, otherwise {@code incomingChatMsg} + * will have a null value. For now the {@code getValue()} and {@code setValue(Object value)} are the + * main focus. + */ + +public class InComingChMsg implements Property { + + private String incomingChatMsg; + + public InComingChMsg(String incomingChatMsg) { + this.incomingChatMsg = incomingChatMsg; + } + + public InComingChMsg() { + this.incomingChatMsg = null; + } + + /** + * Create a unidirection binding for this {@code Property}. + *

+ * Note that JavaFX has all the bind calls implemented through weak listeners. This means the + * bound property can be garbage collected and stopped from being updated. + * + * @param observable The observable this {@code Property} should be bound to. + * @throws NullPointerException if {@code observable} is {@code null} + */ + @Override + public void bind(ObservableValue observable) { + + } + + /** + * Remove the unidirectional binding for this {@code Property}. + *

+ * If the {@code Property} is not bound, calling this method has no effect. + * + * @see #bind(ObservableValue) + */ + @Override + public void unbind() { + + } + + /** + * Can be used to check, if a {@code Property} is bound. + * + * @return {@code true} if the {@code Property} is bound, {@code false} otherwise + * @see #bind(ObservableValue) + */ + @Override + public boolean isBound() { + return false; + } + + /** + * Create a bidirectional binding between this {@code Property} and another one. Bidirectional + * bindings exists independently of unidirectional bindings. So it is possible to add + * unidirectional binding to a property with bidirectional binding and vice-versa. However, this + * practice is discouraged. + *

+ * It is possible to have multiple bidirectional bindings of one Property. + *

+ * JavaFX bidirectional binding implementation use weak listeners. This means bidirectional + * binding does not prevent properties from being garbage collected. + * + * @param other the other {@code Property} + * @throws NullPointerException if {@code other} is {@code null} + * @throws IllegalArgumentException if {@code other} is {@code this} + */ + @Override + public void bindBidirectional(Property other) { + + } + + /** + * Remove a bidirectional binding between this {@code Property} and another one. + *

+ * If no bidirectional binding between the properties exists, calling this method has no effect. + *

+ * It is possible to unbind by a call on the second property. This code will work: + * + *

+   *     property1.bindBirectional(property2);
+   *     property2.unbindBidirectional(property1);
+   * 
+ * + * @param other the other {@code Property} + * @throws NullPointerException if {@code other} is {@code null} + * @throws IllegalArgumentException if {@code other} is {@code this} + */ + @Override + public void unbindBidirectional(Property other) { + + } + + /** + * Returns the {@code Object} that contains this property. If this property is not contained in an + * {@code Object}, {@code null} is returned. + * + * @return the containing {@code Object} or {@code null} + */ + @Override + public Object getBean() { + return null; + } + + /** + * Returns the name of this property. If the property does not have a name, this method returns an + * empty {@code String}. + * + * @return the name or an empty {@code String} + */ + @Override + public String getName() { + return null; + } + + /** + * Adds a {@link ChangeListener} which will be notified whenever the value of the {@code + * ObservableValue} changes. If the same listener is added more than once, then it will be + * notified more than once. That is, no check is made to ensure uniqueness. + *

+ * Note that the same actual {@code ChangeListener} instance may be safely registered for + * different {@code ObservableValues}. + *

+ * The {@code ObservableValue} stores a strong reference to the listener which will prevent the + * listener from being garbage collected and may result in a memory leak. It is recommended to + * either unregister a listener by calling {@link #removeListener(ChangeListener) removeListener} + * after use or to use an instance of {@link WeakChangeListener} avoid this situation. + * + * @param listener The listener to register + * @throws NullPointerException if the listener is null + * @see #removeListener(ChangeListener) + */ + @Override + public void addListener(ChangeListener listener) { + + } + + /** + * Removes the given listener from the list of listeners that are notified whenever the value of + * the {@code ObservableValue} changes. + *

+ * If the given listener has not been previously registered (i.e. it was never added) then this + * method call is a no-op. If it had been previously added then it will be removed. If it had been + * added more than once, then only the first occurrence will be removed. + * + * @param listener The listener to remove + * @throws NullPointerException if the listener is null + * @see #addListener(ChangeListener) + */ + @Override + public void removeListener(ChangeListener listener) { + + } + + /** + * Returns the current value of this {@code ObservableValue} + * + * @return The current value + */ + @Override + public String getValue() { + return this.incomingChatMsg; + } + + /** + * Set the wrapped value. + * + * @param value The new value + */ + @Override + public void setValue(Object value) { + this.incomingChatMsg = (String) value; + } + + /** + * Adds an {@link InvalidationListener} which will be notified whenever the {@code Observable} + * becomes invalid. If the same listener is added more than once, then it will be notified more + * than once. That is, no check is made to ensure uniqueness. + *

+ * Note that the same actual {@code InvalidationListener} instance may be safely registered for + * different {@code Observables}. + *

+ * The {@code Observable} stores a strong reference to the listener which will prevent the + * listener from being garbage collected and may result in a memory leak. It is recommended to + * either unregister a listener by calling {@link #removeListener(InvalidationListener) + * removeListener} after use or to use an instance of {@link WeakInvalidationListener} avoid this + * situation. + * + * @param listener The listener to register + * @throws NullPointerException if the listener is null + * @see #removeListener(InvalidationListener) + */ + @Override + public void addListener(InvalidationListener listener) { + + } + + /** + * Removes the given listener from the list of listeners, that are notified whenever the value of + * the {@code Observable} becomes invalid. + *

+ * If the given listener has not been previously registered (i.e. it was never added) then this + * method call is a no-op. If it had been previously added then it will be removed. If it had been + * added more than once, then only the first occurrence will be removed. + * + * @param listener The listener to remove + * @throws NullPointerException if the listener is null + * @see #addListener(InvalidationListener) + */ + @Override + public void removeListener(InvalidationListener listener) { + + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/OutChatObserver.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/OutChatObserver.java new file mode 100644 index 0000000..aa93e98 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/OutChatObserver.java @@ -0,0 +1,5 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +public interface OutChatObserver { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/SendButton.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/SendButton.java new file mode 100644 index 0000000..8bba790 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/SendButton.java @@ -0,0 +1,7 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +import javafx.scene.Node; + +public class SendButton extends Node { + +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/WhisperButton.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/WhisperButton.java new file mode 100644 index 0000000..a029bef --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/WhisperButton.java @@ -0,0 +1,7 @@ +package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; + +import javafx.scene.Node; + +public class WhisperButton extends Node { + +}