|
@@ -6,27 +6,31 @@ import javafx.beans.value.ObservableValue;
|
|
|
import javafx.collections.FXCollections;
|
|
|
import javafx.collections.ObservableList;
|
|
|
import javafx.geometry.Bounds;
|
|
|
+import javafx.geometry.Orientation;
|
|
|
import javafx.geometry.Point2D;
|
|
|
+import javafx.geometry.Pos;
|
|
|
import javafx.scene.Group;
|
|
|
import javafx.scene.Node;
|
|
|
import javafx.scene.control.ComboBox;
|
|
|
import javafx.scene.control.Label;
|
|
|
import javafx.scene.control.TextField;
|
|
|
-import javafx.scene.input.KeyEvent;
|
|
|
+import javafx.scene.input.KeyCode;
|
|
|
import javafx.scene.input.MouseButton;
|
|
|
import javafx.scene.input.MouseEvent;
|
|
|
-import javafx.scene.layout.BorderPane;
|
|
|
-import javafx.scene.layout.GridPane;
|
|
|
-import javafx.scene.layout.HBox;
|
|
|
-import javafx.scene.layout.VBox;
|
|
|
+import javafx.scene.layout.*;
|
|
|
import javafx.scene.paint.Color;
|
|
|
import javafx.scene.shape.Rectangle;
|
|
|
import javafx.scene.text.Font;
|
|
|
import javafx.scene.text.Text;
|
|
|
+import mdd.client.connectable.Connectable;
|
|
|
+import mdd.client.connectable.Input;
|
|
|
+import mdd.client.connectable.Output;
|
|
|
import org.json.simple.JSONArray;
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
|
|
-import javax.swing.*;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Set;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
@@ -43,104 +47,43 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
public String ID = "TEST-1";
|
|
|
public Vector<String> Prefix;
|
|
|
|
|
|
+ protected JSONObject jID = new JSONObject();
|
|
|
+
|
|
|
protected String Type = "module";
|
|
|
protected String Key = "";
|
|
|
|
|
|
public VBox vlayout = new VBox();
|
|
|
GridPane configs = new GridPane();
|
|
|
public BorderPane hlayout = new BorderPane();
|
|
|
- public VBox inputs = new VBox();
|
|
|
+ public VBox inputs = new VBox();
|
|
|
public VBox outputs = new VBox();
|
|
|
public boolean isSelected = false;
|
|
|
|
|
|
public Module(JSONObject json){
|
|
|
- Name = json.get("name").toString();
|
|
|
- Appendix = (long)json.get("id");
|
|
|
- ID = Name +Appendix;
|
|
|
- Type = json.get("type").toString();
|
|
|
- Key = json.get("key").toString();
|
|
|
- Prefix = new Vector<>();
|
|
|
- JSONArray jarr = (JSONArray)json.get("prefix");
|
|
|
- for (Object o : jarr) {
|
|
|
- Prefix.add(o.toString());
|
|
|
- }
|
|
|
-
|
|
|
- if (json.containsKey("inputs")){
|
|
|
- inputs.getChildren().clear();
|
|
|
- for (Object o : (JSONArray)json.get("inputs")){
|
|
|
- addInput(new Input(this,(JSONObject)o));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (json.containsKey("outputs")) {
|
|
|
- outputs.getChildren().clear();
|
|
|
- for (Object o : (JSONArray) json.get("outputs")) {
|
|
|
- addOutput(new Output(this, (JSONObject) o));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (json.containsKey("configure")) {
|
|
|
- configs.getChildren().clear();
|
|
|
- configs.setHgap(20);
|
|
|
- configs.setVgap(20);
|
|
|
- int counter = 0;
|
|
|
- for (Object o : (JSONArray) json.get("configure")) {
|
|
|
- JSONObject jconfig = (JSONObject) o;
|
|
|
- HBox hbox = new HBox();
|
|
|
- configs.add(new Label((String) jconfig.get("name")),0,counter);
|
|
|
- if (jconfig.containsKey("options")){
|
|
|
- ObservableList<String> options = FXCollections.observableArrayList();
|
|
|
- System.out.println(jconfig.toString());
|
|
|
- for (Object opt : (JSONArray) jconfig.get("options")){
|
|
|
- String item = opt.toString();
|
|
|
- options.add(opt.toString());
|
|
|
-
|
|
|
- }
|
|
|
- ComboBox cbox = new ComboBox(options);
|
|
|
- cbox.getSelectionModel().select(jconfig.get("value").toString());
|
|
|
- configs.add(cbox,1,counter);
|
|
|
- }
|
|
|
- else{
|
|
|
- configs.add(new TextField(jconfig.get("value").toString()),1,counter);
|
|
|
- }
|
|
|
- configs.getChildren().add(hbox);
|
|
|
- ++counter;
|
|
|
- }
|
|
|
- }
|
|
|
- if (json.containsKey("GUI")) {
|
|
|
- JSONObject jgui = (JSONObject) json.get("GUI");
|
|
|
- setTranslateX((double)jgui.get("posX"));
|
|
|
- setTranslateY((double)jgui.get("posY"));
|
|
|
- }
|
|
|
-
|
|
|
- Color color = Color.DARKCYAN;
|
|
|
-
|
|
|
setFocusTraversable(true);
|
|
|
_eventHandler = GUIEventHandler.getEventHandler();
|
|
|
_eventHandler.addEventListener(this);
|
|
|
|
|
|
inputs.setSpacing(10);
|
|
|
-
|
|
|
+ inputs.setAlignment(Pos.TOP_LEFT);
|
|
|
outputs.setSpacing(10);
|
|
|
+ //outputs.setVgap(10);
|
|
|
+ //outputs.setOrientation(Orientation.VERTICAL);
|
|
|
+ outputs.setAlignment(Pos.TOP_RIGHT);
|
|
|
|
|
|
hlayout.setLeft(inputs);
|
|
|
hlayout.setRight(outputs);
|
|
|
- //hlayout.getChildren().addAll(inputs, outputs);
|
|
|
- //hlayout.setSpacing(200);
|
|
|
+
|
|
|
inputs.setTranslateX(-13);
|
|
|
outputs.setTranslateX(13);
|
|
|
vlayout.getChildren().addAll(configs, hlayout);
|
|
|
vlayout.setTranslateX(5);
|
|
|
vlayout.setTranslateY(30);
|
|
|
|
|
|
- // System.out.println("[Module]: pressed: "+ hbox.getPrefWidth());
|
|
|
-
|
|
|
-
|
|
|
- //titlebar = new Rectangle(0.0f, 0.0f, 150-20, 20.0f);
|
|
|
titlebar = new Rectangle(0.0f, 0.0f, 1.0, 20f);
|
|
|
titlebar.setArcWidth(10.0f);
|
|
|
titlebar.setArcHeight(10.0f);
|
|
|
- titlebar.setFill(color);
|
|
|
+
|
|
|
//ackground = new Rectangle(0.0f, 0.0f, 150-20, 150 + 40);
|
|
|
background = new Rectangle(0.0f, 0.0f, 1.0, 1.0);
|
|
|
background.setArcWidth(10.0f);
|
|
@@ -152,10 +95,7 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
caption.setX(10);
|
|
|
caption.setY(15);
|
|
|
|
|
|
-
|
|
|
- getChildren().addAll( background, titlebar, caption, vlayout);
|
|
|
-
|
|
|
-
|
|
|
+ configure(json);
|
|
|
|
|
|
addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
|
|
|
if(e.getButton() == MouseButton.PRIMARY) {
|
|
@@ -210,12 +150,92 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
vlayout.layoutBoundsProperty().addListener(this);
|
|
|
}
|
|
|
|
|
|
- public void addInput(Input in){
|
|
|
- inputs.getChildren().add(in);
|
|
|
+ public void configure(JSONObject json){
|
|
|
+ Type = json.get("type").toString();
|
|
|
+ Key = json.get("key").toString();
|
|
|
+ if (json.containsKey("ID")){
|
|
|
+ jID = (JSONObject)json.get("ID");
|
|
|
+
|
|
|
+ Name = jID.get("name").toString();
|
|
|
+ Appendix = (long)jID.get("appendix");
|
|
|
+ ID = Name +Appendix;
|
|
|
+ Prefix = new Vector<>();
|
|
|
+ JSONArray jarr = (JSONArray)jID.get("prefix");
|
|
|
+ for (Object o : jarr) {
|
|
|
+ Prefix.add(o.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateConnectable(ConnectableType.INPUT,json);
|
|
|
+ updateConnectable(ConnectableType.OUTPUT,json);
|
|
|
+
|
|
|
+
|
|
|
+ if (json.containsKey("configure")) {
|
|
|
+ configs.getChildren().clear();
|
|
|
+ configs.setHgap(20);
|
|
|
+ configs.setVgap(20);
|
|
|
+
|
|
|
+ JSONObject jconfigs = (JSONObject)json.get("configure");
|
|
|
+ Iterator<String> itr = jconfigs.keySet().iterator();
|
|
|
+ int counter = 0;
|
|
|
+ while (itr.hasNext()){
|
|
|
+ String key = itr.next();
|
|
|
+ JSONObject jconfig = (JSONObject) jconfigs.get(key);
|
|
|
+ Label clabel = new Label(key);
|
|
|
+ configs.add(clabel,0,counter);
|
|
|
+ configs.add(new Configuration(this, key, jconfig),1,counter);
|
|
|
+ ++counter;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (json.containsKey("GUI")) {
|
|
|
+ JSONObject jgui = (JSONObject) json.get("GUI");
|
|
|
+ setTranslateX((double)jgui.get("posX"));
|
|
|
+ setTranslateY((double)jgui.get("posY"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Color color = Color.DARKCYAN;
|
|
|
+ titlebar.setFill(color);
|
|
|
+
|
|
|
+ getChildren().clear();
|
|
|
+ getChildren().addAll( background, titlebar, caption, vlayout);
|
|
|
}
|
|
|
|
|
|
- public void addOutput(Output out){
|
|
|
- outputs.getChildren().add(out);
|
|
|
+ protected void updateConnectable(ConnectableType ctype,JSONObject json){
|
|
|
+ JSONArray jarray = new JSONArray();
|
|
|
+ ObservableList<Node> connectables;
|
|
|
+ if (ctype == ConnectableType.INPUT){
|
|
|
+ connectables = inputs.getChildren();
|
|
|
+ if (json.containsKey("inputs")){
|
|
|
+ jarray = (JSONArray)json.get("inputs");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ connectables = outputs.getChildren();
|
|
|
+ if (json.containsKey("outputs")){
|
|
|
+ jarray = (JSONArray)json.get("outputs");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //remove
|
|
|
+ int size = connectables.size() - jarray.size();
|
|
|
+ for (int i = 0; i < size; ++i){
|
|
|
+ connectables.remove(connectables.size()-1);
|
|
|
+ }
|
|
|
+ //change
|
|
|
+ size = connectables.size();
|
|
|
+ for (int i = 0; i < size; ++i){
|
|
|
+ ((Connectable)connectables.get(i)).configure((JSONObject)jarray.get(i));
|
|
|
+ }
|
|
|
+ //add
|
|
|
+ size = jarray.size()-connectables.size();
|
|
|
+ for (int i = 0; i < size; ++i){
|
|
|
+ JSONObject jobj = (JSONObject)jarray.get(i);
|
|
|
+ if (ctype == ConnectableType.INPUT){
|
|
|
+ connectables.add(new Input(this,jobj));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ connectables.add(new Output(this,jobj));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Input getInput(String id){
|
|
@@ -246,14 +266,10 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
public JSONObject getJSONIdentifier(){
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("prefix", Prefix);
|
|
|
- json.put("name", Name);
|
|
|
- json.put("id", Appendix);
|
|
|
- json.put("type", Type);
|
|
|
- json.put("key", Key);
|
|
|
- return json;
|
|
|
+ return jID;
|
|
|
}
|
|
|
|
|
|
public Vector<String> getAsPrefix(){
|
|
@@ -294,6 +310,9 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
setTranslateX((double)jgui.get("posX"));
|
|
|
setTranslateY((double)jgui.get("posY"));
|
|
|
}
|
|
|
+ if (jobj.containsKey("configure")){
|
|
|
+ configure((JSONObject) jobj.get("configure"));
|
|
|
+ }
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -310,8 +329,5 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
|
|
|
titlebar.setHeight(20.0f);
|
|
|
background.setWidth(newValue.getWidth()+10);
|
|
|
background.setHeight(newValue.getHeight()+vlayout.getTranslateY()+10);
|
|
|
- Bounds hlayout_bounds = hlayout.getLayoutBounds();
|
|
|
- //double val = newValue.getWidth()-hlayout.getWidth()-hlayout.getSpacing();
|
|
|
- //System.out.println("[Module]: test" + val+ " " + hlayout.getWidth());
|
|
|
}
|
|
|
}
|