|
@@ -1,10 +1,10 @@
|
|
package mdd.client;
|
|
package mdd.client;
|
|
|
|
|
|
-import javafx.geometry.Insets;
|
|
|
|
|
|
+
|
|
import javafx.geometry.Point2D;
|
|
import javafx.geometry.Point2D;
|
|
-import com.sun.javafx.geom.RoundRectangle2D;
|
|
|
|
import javafx.scene.Group;
|
|
import javafx.scene.Group;
|
|
-import javafx.scene.control.Label;
|
|
|
|
|
|
+import javafx.scene.Node;
|
|
|
|
+import javafx.scene.input.KeyEvent;
|
|
import javafx.scene.input.MouseButton;
|
|
import javafx.scene.input.MouseButton;
|
|
import javafx.scene.input.MouseEvent;
|
|
import javafx.scene.input.MouseEvent;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.HBox;
|
|
@@ -13,32 +13,46 @@ import javafx.scene.paint.Color;
|
|
import javafx.scene.shape.Rectangle;
|
|
import javafx.scene.shape.Rectangle;
|
|
import javafx.scene.text.Font;
|
|
import javafx.scene.text.Font;
|
|
import javafx.scene.text.Text;
|
|
import javafx.scene.text.Text;
|
|
-import org.json.JSONObject;
|
|
|
|
|
|
+import org.json.simple.JSONObject;
|
|
|
|
+
|
|
|
|
+import java.util.Vector;
|
|
|
|
|
|
|
|
|
|
-public class Module extends Group {
|
|
|
|
|
|
+public class Module extends Group implements IGUIEventClient{
|
|
private boolean _dragged = false;
|
|
private boolean _dragged = false;
|
|
- private Point2D _old_pos;
|
|
|
|
private Point2D _pos = new Point2D(0.0f,0.0f);
|
|
private Point2D _pos = new Point2D(0.0f,0.0f);
|
|
|
|
+ private GUIEventHandler _eventHandler = new GUIEventHandler();
|
|
|
|
+
|
|
|
|
+ public String ID = "";
|
|
|
|
+ public HBox hlayout = new HBox();
|
|
|
|
+ public VBox inputs = new VBox();
|
|
|
|
+ public VBox outputs = new VBox();
|
|
|
|
+ public boolean isSelected = false;
|
|
|
|
|
|
- public Module(){
|
|
|
|
|
|
+ public Module(String id){
|
|
|
|
+ ID = id;
|
|
Rectangle titlebar;
|
|
Rectangle titlebar;
|
|
Rectangle background;
|
|
Rectangle background;
|
|
Text caption;
|
|
Text caption;
|
|
- VBox inputs = new VBox(new Input(), new Input(), new Input());
|
|
|
|
- VBox outputs = new VBox(new Output(), new Output(), new Output());
|
|
|
|
|
|
+ addInput(new Input(this,"1"));
|
|
|
|
+ addInput(new Input(this,"2"));
|
|
|
|
+ addInput(new Input(this,"3"));
|
|
|
|
+
|
|
|
|
+ addOutput(new Output(this,"1"));
|
|
|
|
+ addOutput(new Output(this,"2"));
|
|
|
|
+ addOutput(new Output(this,"3"));
|
|
|
|
|
|
inputs.setSpacing(10);
|
|
inputs.setSpacing(10);
|
|
|
|
|
|
outputs.setSpacing(10);
|
|
outputs.setSpacing(10);
|
|
|
|
|
|
|
|
|
|
- HBox hbox = new HBox(inputs, outputs);
|
|
|
|
- hbox.setSpacing(20);
|
|
|
|
- hbox.setTranslateX(-7);
|
|
|
|
- hbox.setTranslateY(30);
|
|
|
|
|
|
+ hlayout.getChildren().addAll(inputs, outputs);
|
|
|
|
+ hlayout.setSpacing(20);
|
|
|
|
+ hlayout.setTranslateX(-7);
|
|
|
|
+ hlayout.setTranslateY(30);
|
|
|
|
|
|
- System.out.println(hbox.getPrefWidth());
|
|
|
|
|
|
+ //System.out.println("[Module]: pressed: "+ hbox.getPrefWidth());
|
|
|
|
|
|
//JSONObject parameters
|
|
//JSONObject parameters
|
|
titlebar = new Rectangle(0.0f, 0.0f, 150-20, 20.0f);
|
|
titlebar = new Rectangle(0.0f, 0.0f, 150-20, 20.0f);
|
|
@@ -56,52 +70,113 @@ public class Module extends Group {
|
|
caption.setY(15);
|
|
caption.setY(15);
|
|
|
|
|
|
|
|
|
|
- getChildren().addAll( background, titlebar, caption, hbox);
|
|
|
|
|
|
+ getChildren().addAll( background, titlebar, caption, hlayout);
|
|
|
|
|
|
- addEventFilter(MouseEvent.MOUSE_CLICKED, e -> {
|
|
|
|
- if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
|
|
|
|
+ System.out.println("[Module]: press event filter detected!");
|
|
|
|
+ if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
+ isSelected = true;
|
|
|
|
+ System.out.println("[Module]: select: " + ID);
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
+ json.put("id", id);
|
|
|
|
+ _eventHandler.publishEvent("MOUSE_PRESSED", json);
|
|
|
|
+ _pos = new Point2D(e.getSceneX(), e.getSceneY());
|
|
}
|
|
}
|
|
if(e.getButton() == MouseButton.SECONDARY) {
|
|
if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ e.consume();
|
|
});
|
|
});
|
|
|
|
|
|
- addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
|
|
|
|
- System.out.println("[Module]: press event detected!");
|
|
|
|
|
|
+ addEventHandler(MouseEvent.MOUSE_DRAGGED, e -> {
|
|
|
|
+ //System.out.println("[Module]: dragg event detected!");
|
|
if(e.getButton() == MouseButton.PRIMARY) {
|
|
if(e.getButton() == MouseButton.PRIMARY) {
|
|
- if (!_dragged){
|
|
|
|
- _old_pos = new Point2D(e.getSceneX(), e.getSceneY());
|
|
|
|
- }
|
|
|
|
|
|
+ setTranslateX(getTranslateX()+(e.getSceneX()-_pos.getX()));
|
|
|
|
+ setTranslateY(getTranslateY()+(e.getSceneY()-_pos.getY()));
|
|
|
|
+ _pos = new Point2D( e.getSceneX(), e.getSceneY());
|
|
}
|
|
}
|
|
if(e.getButton() == MouseButton.SECONDARY) {
|
|
if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+ }
|
|
|
|
|
|
- addEventFilter(MouseEvent.MOUSE_DRAGGED, e -> {
|
|
|
|
- //System.out.println("[Module]: dragg event detected!");
|
|
|
|
- if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
- _dragged = true;
|
|
|
|
|
|
+ public void addInput(Input in){
|
|
|
|
+ in.setGUIEventHandler(_eventHandler);
|
|
|
|
+ inputs.getChildren().add(in);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void addOutput(Output out){
|
|
|
|
+ out.setGUIEventHandler(_eventHandler);
|
|
|
|
+ outputs.getChildren().add(out);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Input getInput(String id){
|
|
|
|
+ for (Node node : inputs.getChildren()){
|
|
|
|
+ if(node instanceof Input){
|
|
|
|
+ Input in = (Input) node;
|
|
|
|
+ if (in.ID.equals(id)){
|
|
|
|
+ return in;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ System.out.println("[Module]: getInput: WRONG ID!");
|
|
|
|
+ return new Input(this,"");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Output getOutput(String id){
|
|
|
|
+ for (Node node : outputs.getChildren()){
|
|
|
|
+ if(node instanceof Output){
|
|
|
|
+ Output out = (Output) node;
|
|
|
|
+ if (out.ID.equals(id)){
|
|
|
|
+ return out;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
|
|
- addEventFilter(MouseEvent.MOUSE_RELEASED, e -> {
|
|
|
|
- System.out.println("[Module]: release event detected!");
|
|
|
|
- if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
- _dragged = false;
|
|
|
|
- System.out.print("[Module]: got: "); System.out.print(e.getSceneX()); System.out.print(" | "); System.out.print(e.getSceneY());
|
|
|
|
- System.out.println();
|
|
|
|
- _pos = new Point2D(_pos.getX()+ e.getSceneX() - _old_pos.getX(), _pos.getY() + e.getSceneY() - _old_pos.getY());
|
|
|
|
- setTranslateX(_pos.getX());
|
|
|
|
- setTranslateY(_pos.getY());
|
|
|
|
|
|
+ }
|
|
|
|
+ System.out.println("[Module]: getOutput: WRONG ID!");
|
|
|
|
+ return new Output(this,"");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GUIEventHandler getGUIEventHandler(){
|
|
|
|
+ return _eventHandler;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setGUIEventHandler(GUIEventHandler eventHandler){
|
|
|
|
+ _eventHandler = eventHandler;
|
|
|
|
+ for (Node node : inputs.getChildren()){
|
|
|
|
+ if(node instanceof Input){
|
|
|
|
+ Input in = (Input) node;
|
|
|
|
+ in.setGUIEventHandler(_eventHandler);
|
|
}
|
|
}
|
|
- if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (Node node : outputs.getChildren()){
|
|
|
|
+ if(node instanceof Output){
|
|
|
|
+ Output out = (Output) node;
|
|
|
|
+ out.setGUIEventHandler(_eventHandler);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ _eventHandler.addEventListener(this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void processGUIEvent(String event, JSONObject args) {
|
|
|
|
+ if (event == "MOUSE_PRESSED"){
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
+ json.put("id", ID);
|
|
|
|
+
|
|
|
|
+ if (!args.equals(json)){
|
|
|
|
+ if (isSelected){
|
|
|
|
+ System.out.println("[Module]: deselect: " + ID);
|
|
|
|
+ }
|
|
|
|
+ isSelected = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|