Slowly building the SceneGraph from the bottom.

Created a abstract class that imlements the Toggle interface for toggling between who one wants to chat.
This commit is contained in:
Sebastian Lenzlinger 2022-04-13 01:07:49 +02:00
parent 68248c7175
commit e4f9776f7f
9 changed files with 207 additions and 14 deletions

View File

@ -1,7 +1,19 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.collections.ObservableMap;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
public class BroadcastButton extends Node {
/**
* Represents toggling to broadcast to everyone
*/
public class BroadcastButton extends ChatTargetToggle implements Toggle {
Label l = new Label("Broadcast");
}

View File

@ -0,0 +1,81 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.collections.ObservableMap;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
/**
* If this is toggled than the client chat is operating in whisper mode.
*/
public abstract class ChatTargetToggle extends Node implements Toggle{
BooleanProperty isToggled;
ObjectProperty<ToggleGroup> myFriends;
/**
* Returns The {@link ToggleGroup} to which this {@code Toggle} belongs.
*
* @return The {@link ToggleGroup} to which this {@code Toggle} belongs.
*/
@Override
public ToggleGroup getToggleGroup() {
return myFriends.get();
}
/**
* Sets the {@link ToggleGroup} to which this {@code Toggle} belongs.
*
* @param toggleGroup The new {@link ToggleGroup}.
*/
@Override
public void setToggleGroup(ToggleGroup toggleGroup) {
myFriends.bindBidirectional((Property<ToggleGroup>) toggleGroup);
}
/**
* The {@link ToggleGroup} to which this {@code Toggle} belongs.
*
* @return the toggle group property
*/
@Override
public ObjectProperty<ToggleGroup> toggleGroupProperty() {
return myFriends;
}
/**
* Indicates whether this {@code Toggle} is selected.
*
* @return {@code true} if this {@code Toggle} is selected.
*/
@Override
public boolean isSelected() {
return isToggled.get();
}
/**
* Sets this {@code Toggle} as selected or unselected.
*
* @param selected {@code true} to make this {@code Toggle} selected.
*/
@Override
public void setSelected(boolean selected) {
this.isToggled.set(selected);
}
/**
* The selected state for this {@code Toggle}.
*
* @return the selected property
*/
@Override
public BooleanProperty selectedProperty() {
return isToggled;
}
}

View File

@ -1,20 +1,42 @@
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.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Paint;
public class ChatView {
/**
* This is the view of the client chat gui.
*/
public class ChatView extends Node implements NodeWithChildren, ChildNode {
private Label send = new Label("Send");
private Pane root;
private Pane createNodeHierarchy(){
Pane p = new Pane();
return p;
public void createNodeHierarchy(){
Button send = new SendButton();
OutMsgTargetChooserNode chooseTarget = new OutMsgTargetChooserNode();
TextArea clientOutgoingChatMsg = new TextArea();
}
@Override
public Pane getRootPane() {
return root;
}
@Override
public ChildNode getInstance() {
return this;
}
@Override
public void create() {
}
@Override
public void getChildren() {
//TODO implement
NodeWithChildren.super.getChildren();
}
}

View File

@ -0,0 +1,10 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.scene.layout.Pane;
public interface ChildNode {
public Pane getRootPane();
public ChildNode getInstance();
}

View File

@ -0,0 +1,13 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
/**
* Any class that represents a JavaFX node and has children should implement this interface
*/
public interface NodeWithChildren {
void create();
public default void getChildren(){};
void createNodeHierarchy();
}

View File

@ -0,0 +1,32 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
public class OutMsgTargetChooserNode extends ToggleGroup implements NodeWithChildren {
private Pane root;
private ObservableList<Node> targets;
@Override
public void create() {
}
@Override
public void getChildren() {
NodeWithChildren.super.getChildren();
}
@Override
public void createNodeHierarchy() {
this.root = new HBox();
for(Node n : targets)
root.getChildren().add(n);
}
}

View File

@ -1,7 +1,16 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.scene.Node;
import javafx.scene.control.Button;
public class SendButton extends Node {
public class SendButton extends Button implements UINode {
public SendButton() {
super("Send");
}
@Override
public void listen() {
}
}

View File

@ -0,0 +1,9 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
/**
* Any class that represents a JavaFX node that takes user input should implement this interface.
*/
public interface UINode {
void listen();
}

View File

@ -1,7 +1,12 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import javafx.scene.Node;
import javafx.scene.control.Label;
public class WhisperButton extends Node {
/**
* Represents the toggle for a whisper chat.
*/
public class WhisperButton extends ChatTargetToggle {
Label l = new Label("Whisper");
}