|
@@ -1,37 +1,109 @@
|
|
|
package mdd.client;
|
|
|
|
|
|
|
|
|
+import javafx.beans.value.ChangeListener;
|
|
|
+import javafx.beans.value.ObservableValue;
|
|
|
+import javafx.collections.FXCollections;
|
|
|
+import javafx.collections.ObservableList;
|
|
|
+import javafx.geometry.Bounds;
|
|
|
import javafx.geometry.Point2D;
|
|
|
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.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.paint.Color;
|
|
|
import javafx.scene.shape.Rectangle;
|
|
|
import javafx.scene.text.Font;
|
|
|
import javafx.scene.text.Text;
|
|
|
+import org.json.simple.JSONArray;
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
|
|
+import javax.swing.*;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
|
-public class Module extends Group implements IGUIEventClient{
|
|
|
+public class Module extends Group implements IGUIEventClient, ChangeListener<Bounds> {
|
|
|
private boolean _dragged = false;
|
|
|
private Point2D _pos = new Point2D(0.0f,0.0f);
|
|
|
+ private Rectangle titlebar;
|
|
|
+ private Rectangle background;
|
|
|
+ private Text caption;
|
|
|
protected GUIEventHandler _eventHandler;
|
|
|
|
|
|
- public String ID = "";
|
|
|
+ public String Name = "TEST";
|
|
|
+ public String ID = "TEST-1";
|
|
|
public Vector<String> Prefix;
|
|
|
+
|
|
|
protected String Type = "module";
|
|
|
- public HBox hlayout = new HBox();
|
|
|
+ protected String Key = "";
|
|
|
+
|
|
|
+ public VBox vlayout = new VBox();
|
|
|
+ GridPane configs = new GridPane();
|
|
|
+ public BorderPane hlayout = new BorderPane();
|
|
|
public VBox inputs = new VBox();
|
|
|
public VBox outputs = new VBox();
|
|
|
public boolean isSelected = false;
|
|
|
|
|
|
- private void init(Color color){
|
|
|
+ public Module(JSONObject json){
|
|
|
+ Name = json.get("name").toString();
|
|
|
+ ID = Name + json.get("id").toString();
|
|
|
+ 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")){
|
|
|
+ options.add(opt.toString());
|
|
|
+ }
|
|
|
+ configs.add(new ComboBox(options),1,counter);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ configs.add(new TextField(jconfig.get("value").toString()),1,counter);
|
|
|
+ }
|
|
|
+ configs.getChildren().add(hbox);
|
|
|
+ ++counter;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Color color = Color.DARKCYAN;
|
|
|
+
|
|
|
setFocusTraversable(true);
|
|
|
_eventHandler = GUIEventHandler.getEventHandler();
|
|
|
_eventHandler.addEventListener(this);
|
|
@@ -40,33 +112,37 @@ public class Module extends Group implements IGUIEventClient{
|
|
|
|
|
|
outputs.setSpacing(10);
|
|
|
|
|
|
-
|
|
|
- hlayout.getChildren().addAll(inputs, outputs);
|
|
|
- hlayout.setSpacing(20);
|
|
|
- hlayout.setTranslateX(-7);
|
|
|
- hlayout.setTranslateY(30);
|
|
|
+ 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());
|
|
|
- Rectangle titlebar;
|
|
|
- Rectangle background;
|
|
|
- Text caption;
|
|
|
|
|
|
- titlebar = new Rectangle(0.0f, 0.0f, 150-20, 20.0f);
|
|
|
+
|
|
|
+ //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);
|
|
|
- background = new Rectangle(0.0f, 0.0f, 150-20, 150 + 40);
|
|
|
+ //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);
|
|
|
background.setArcHeight(10.0f);
|
|
|
background.setFill(Color.GRAY);
|
|
|
- caption = new Text("TEST");
|
|
|
+ caption = new Text(Name);
|
|
|
caption.setFont(new Font("Arial", 15));
|
|
|
caption.getStyleClass().add("text");
|
|
|
caption.setX(10);
|
|
|
caption.setY(15);
|
|
|
|
|
|
|
|
|
- getChildren().addAll( background, titlebar, caption, hlayout);
|
|
|
+ getChildren().addAll( background, titlebar, caption, vlayout);
|
|
|
|
|
|
|
|
|
|
|
@@ -96,30 +172,8 @@ public class Module extends Group implements IGUIEventClient{
|
|
|
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
-
|
|
|
- public static Module DefaultModule(){
|
|
|
- return new Module(new Vector<String>(), "", Color.DARKBLUE);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Module(JSONObject json){
|
|
|
- init(Color.DARKCYAN);
|
|
|
- }
|
|
|
-
|
|
|
- public Module(Vector<String> prefix, String id, Color color){
|
|
|
- Prefix = prefix;
|
|
|
- ID = id;
|
|
|
-
|
|
|
- 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"));
|
|
|
-
|
|
|
- init(color);
|
|
|
+ vlayout.layoutBoundsProperty().addListener(this);
|
|
|
}
|
|
|
|
|
|
public void addInput(Input in){
|
|
@@ -190,4 +244,15 @@ public class Module extends Group implements IGUIEventClient{
|
|
|
public void close() throws Exception {
|
|
|
_eventHandler.removeEventListener(this);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) {
|
|
|
+ titlebar.setWidth(newValue.getWidth()+10);
|
|
|
+ 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());
|
|
|
+ }
|
|
|
}
|