|
@@ -1,35 +1,68 @@
|
|
package mdd.client;
|
|
package mdd.client;
|
|
|
|
|
|
import javafx.event.EventHandler;
|
|
import javafx.event.EventHandler;
|
|
|
|
+import javafx.geometry.Point2D;
|
|
import javafx.scene.Group;
|
|
import javafx.scene.Group;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.input.*;
|
|
import javafx.scene.input.*;
|
|
|
|
+import javafx.scene.paint.Color;
|
|
|
|
+import javafx.scene.shape.Line;
|
|
import org.json.simple.JSONArray;
|
|
import org.json.simple.JSONArray;
|
|
import org.json.simple.JSONObject;
|
|
import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.JSONParser;
|
|
import org.json.simple.parser.JSONParser;
|
|
import org.json.simple.parser.ParseException;
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
|
|
|
|
+import java.util.Vector;
|
|
|
|
+
|
|
public class Processor extends Module{
|
|
public class Processor extends Module{
|
|
private Group modules = new Group();
|
|
private Group modules = new Group();
|
|
private Group connections = new Group();
|
|
private Group connections = new Group();
|
|
public Group all = new Group(connections, modules);
|
|
public Group all = new Group(connections, modules);
|
|
- public Module selected = new Module("-1");
|
|
|
|
- private GUIEventHandler _eventHandler = new GUIEventHandler();
|
|
|
|
-
|
|
|
|
- public Processor(String id) {
|
|
|
|
- super( id);
|
|
|
|
- //setFocusTraversable(true);
|
|
|
|
- setOnKeyPressed(e -> {
|
|
|
|
- System.out.println("[Processor]: pressed:");
|
|
|
|
- System.out.println("[Processor]: pressed: " + e.getText());
|
|
|
|
- if (isSelected) {
|
|
|
|
- JSONObject json = new JSONObject();
|
|
|
|
- json.put("id", ID);
|
|
|
|
- _eventHandler.publishEvent("OPEN_PROCESSOR", json);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private boolean detected_drag = false;
|
|
|
|
+ private boolean draw_temp_connection = false;
|
|
|
|
+ public Connection temp_connection = new Connection();
|
|
|
|
+ private Connectable connectable;
|
|
|
|
+
|
|
|
|
+ public Processor(Vector<String> prefix, String id) {
|
|
|
|
+ super(prefix, id, Color.DARKVIOLET);
|
|
|
|
+
|
|
|
|
+ modules.addEventHandler(MouseEvent.DRAG_DETECTED, e -> {
|
|
|
|
+ // System.out.println("[Module]: dragg event detected!");
|
|
|
|
+ if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
+ detected_drag = true;
|
|
|
|
+ }
|
|
|
|
+ if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
+
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ all.addEventHandler(MouseEvent.MOUSE_DRAGGED, e -> {
|
|
|
|
+ // System.out.println("[Module]: dragg event detected!");
|
|
|
|
+ if(e.getButton() == MouseButton.PRIMARY) {
|
|
|
|
+ if (draw_temp_connection){
|
|
|
|
+ System.out.println("[Processor] draw Line!");
|
|
|
|
+ temp_connection.setEndX(e.getSceneX());
|
|
|
|
+ temp_connection.setEndY(e.getSceneY());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(e.getButton() == MouseButton.SECONDARY) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ all.addEventHandler(DragEvent.DRAG_DROPPED, e -> {
|
|
|
|
+ //connections.getChildren().remove(temp_connection);
|
|
|
|
+ System.out.println("[Processor] all");
|
|
|
|
+ detected_drag = false;
|
|
|
|
+ });
|
|
|
|
+
|
|
modules.addEventHandler(DragEvent.DRAG_DROPPED, e -> {
|
|
modules.addEventHandler(DragEvent.DRAG_DROPPED, e -> {
|
|
|
|
+ //connections.getChildren().remove(temp_connection);
|
|
|
|
+ System.out.println("[Processor]");
|
|
|
|
+ detected_drag = false;
|
|
|
|
+
|
|
Dragboard db = e.getDragboard();
|
|
Dragboard db = e.getDragboard();
|
|
boolean success = false;
|
|
boolean success = false;
|
|
if (db.hasString()) {
|
|
if (db.hasString()) {
|
|
@@ -53,27 +86,32 @@ public class Processor extends Module{
|
|
if (json.containsKey("type")) {
|
|
if (json.containsKey("type")) {
|
|
String type = json.get("type").toString();
|
|
String type = json.get("type").toString();
|
|
if (type.equals("INPUT")) {
|
|
if (type.equals("INPUT")) {
|
|
- System.out.println("[WorkBench] Dropped found type = " + "INPUT");
|
|
|
|
|
|
+ System.out.println("[Processor] Dropped found type = " + "INPUT");
|
|
foundInput = true;
|
|
foundInput = true;
|
|
- JSONArray idList = (JSONArray) json.get("ID");
|
|
|
|
- in = getModule(idList.get(1).toString()).getInput(idList.get(0).toString());
|
|
|
|
|
|
+ in = getModule(json.get("parent").toString()).getInput(json.get("ID").toString());
|
|
} else if (type.equals("OUTPUT")) {
|
|
} else if (type.equals("OUTPUT")) {
|
|
- System.out.println("[WorkBench] Dropped found type = " + "OUTPUT");
|
|
|
|
|
|
+ System.out.println("[Processor] Dropped found type = " + "OUTPUT");
|
|
foundOutput = true;
|
|
foundOutput = true;
|
|
- JSONArray idList = (JSONArray) json.get("ID");
|
|
|
|
- out = getModule(idList.get(1).toString()).getOutput(idList.get(0).toString());
|
|
|
|
|
|
+ out = getModule(json.get("parent").toString()).getOutput(json.get("ID").toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (foundInput && foundOutput){
|
|
if (foundInput && foundOutput){
|
|
- System.out.println("[WorkBench] Dropped: success!");
|
|
|
|
|
|
+ System.out.println("[Processor] Dropped: success!");
|
|
|
|
+ if(in.connected){
|
|
|
|
+ for (int i = 0; i < connections.getChildren().size(); ++i){
|
|
|
|
+ if (((Connection)connections.getChildren().get(i)).in.equals(in)){
|
|
|
|
+ connections.getChildren().remove(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
connections.getChildren().add(new Connection(in, out));
|
|
connections.getChildren().add(new Connection(in, out));
|
|
success = true;
|
|
success = true;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- System.out.println("[WorkBench] Dropped: " + db.getString());
|
|
|
|
|
|
+ System.out.println("[Processor] Dropped: " + db.getString());
|
|
|
|
|
|
}
|
|
}
|
|
e.setDropCompleted(success);
|
|
e.setDropCompleted(success);
|
|
@@ -90,36 +128,77 @@ public class Processor extends Module{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return new Module("");
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public void setGUIEventHandler(GUIEventHandler eventHandler){
|
|
|
|
- _eventHandler = eventHandler;
|
|
|
|
- for (Node node : inputs.getChildren()){
|
|
|
|
- if(node instanceof Input){
|
|
|
|
- Input in = (Input) node;
|
|
|
|
- in.setGUIEventHandler(_eventHandler);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public Module getModule(Vector<String> id_path){
|
|
|
|
+ id_path.remove(0);
|
|
|
|
+ if (id_path.size() == 1){
|
|
|
|
+ return getModule(id_path.firstElement());
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
+ Processor new_processor = (Processor)getModule(id_path.firstElement());
|
|
|
|
+ return new_processor.getModule(id_path);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- for (Node node : outputs.getChildren()){
|
|
|
|
- if(node instanceof Output){
|
|
|
|
- Output out = (Output) node;
|
|
|
|
- out.setGUIEventHandler(_eventHandler);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public Processor getProcessor(Vector<String> id_path){
|
|
|
|
+ id_path.remove(0);
|
|
|
|
+ Processor new_processor = (Processor)getModule(id_path.firstElement());
|
|
|
|
+ if (id_path.size() == 1){
|
|
|
|
+ return new_processor;
|
|
|
|
+ }else {
|
|
|
|
+ return new_processor.getProcessor(id_path);
|
|
}
|
|
}
|
|
- _eventHandler.addEventListener(this);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void addModule(Module module){
|
|
public void addModule(Module module){
|
|
- module.setGUIEventHandler(getGUIEventHandler());
|
|
|
|
modules.getChildren().add(module);
|
|
modules.getChildren().add(module);
|
|
}
|
|
}
|
|
|
|
|
|
public void addConnection(Connection connection){
|
|
public void addConnection(Connection connection){
|
|
- connection.setGUIEventHandler(getGUIEventHandler());
|
|
|
|
connections.getChildren().add(connection);
|
|
connections.getChildren().add(connection);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void processGUIEvent(String event, JSONObject args) {
|
|
|
|
+ super.processGUIEvent(event, args);
|
|
|
|
+ if (isSelected){
|
|
|
|
+ if (event.equals("KeyTyped")){
|
|
|
|
+ String key = args.get("key").toString();
|
|
|
|
+ if (key.equals("ENTER")){
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
+ json.put("path", getAsPrefix());
|
|
|
|
+ _eventHandler.publishEvent("OPEN_PROCESSOR", json);
|
|
|
|
+ System.out.println("[Processor]: published");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (detected_drag){
|
|
|
|
+ if (event.equals("DRAG_LINE")){
|
|
|
|
+ draw_temp_connection = true;
|
|
|
|
+
|
|
|
|
+ JSONObject json = args;
|
|
|
|
+ if (json.containsKey("type")) {
|
|
|
|
+ String type = json.get("type").toString();
|
|
|
|
+ if (type.equals("INPUT")) {
|
|
|
|
+ System.out.println("[Processor] Line from type = " + "INPUT");
|
|
|
|
+ connectable = getModule(json.get("parent").toString()).getInput(json.get("ID").toString());
|
|
|
|
+ } else if (type.equals("OUTPUT")) {
|
|
|
|
+ System.out.println("[Processor] Line from type = " + "OUTPUT");
|
|
|
|
+ connectable = getModule(json.get("parent").toString()).getOutput(json.get("ID").toString());
|
|
|
|
+ }
|
|
|
|
+ if (connectable == null){
|
|
|
|
+ System.out.println("[Processor]: Couldn't find Connectable!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ temp_connection= new Connection();
|
|
|
|
+ temp_connection.startXProperty().bind(connectable.x);
|
|
|
|
+ temp_connection.startYProperty().bind(connectable.y);
|
|
|
|
+ temp_connection.setEndX(connectable.x.getValue()+100);
|
|
|
|
+ temp_connection.setEndY(connectable.y.getValue()+100);
|
|
|
|
+ //connections.getChildren().add(temp_connection);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|