Willi Zschiebsch 4 лет назад
Родитель
Сommit
4a7644f645

+ 0 - 3
src/main/java/mdd/client/Client.java

@@ -150,7 +150,6 @@ public class Client implements IGUIEventClient
 
     @Override
     public void processGUIEvent(String event, JSONObject args) {
-        long start = System.currentTimeMillis();
         if (event.equals("try")){
             JSONObject jans = request("try",args);
         }
@@ -158,8 +157,6 @@ public class Client implements IGUIEventClient
             JSONObject jans = request("get",  args);
             _eventHandler.publishEvent("receive", (JSONObject)jans.get("receive"));
         }
-        long end = System.currentTimeMillis();
-        System.out.println("[Client]: "+event+": " +(end-start));
     }
 
     @Override

+ 40 - 32
src/main/java/mdd/client/Configuration.java

@@ -3,10 +3,14 @@ package mdd.client;
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.event.Event;
+import javafx.event.EventHandler;
 import javafx.scene.Group;
+import javafx.scene.control.ColorPicker;
 import javafx.scene.control.ComboBox;
 import javafx.scene.control.TextField;
 import javafx.scene.input.KeyCode;
+import javafx.scene.paint.Color;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 
@@ -14,8 +18,6 @@ public class Configuration extends Group {
     private String _name = "";
     private String _topic = "";
     private JSONObject jparent_id;
-
-    private String _type = "";
     protected GUIEventHandler _eventHandler;
 
     Configuration(String topic, Module parent, String key, JSONObject json){
@@ -37,7 +39,6 @@ public class Configuration extends Group {
         _eventHandler = GUIEventHandler.getEventHandler();
 
         if (json.containsKey("options")){
-            _type = "selection";
             ObservableList<String> options = FXCollections.observableArrayList();
             System.out.println(json.toString());
             for (Object opt : (JSONArray) json.get("options")){
@@ -48,47 +49,54 @@ public class Configuration extends Group {
             ComboBox cbox = new ComboBox(options);
             cbox.getSelectionModel().select(json.get("value").toString());
             cbox.setOnAction(e->{
-                JSONObject jconfi = new JSONObject();
-                jconfi.put("value", cbox.getValue().toString());
-                JSONObject jconfigs = new JSONObject();
-                jconfigs.put(_name, jconfi);
-                JSONObject jconfigure = new JSONObject();
-                jconfigure.put(_topic, jconfigs);
-                JSONObject jmsg = new JSONObject();
-                jmsg.put("operation", "change");
-                JSONObject jargs = new JSONObject();
-                jargs.put("subject",  jparent_id);
-                jargs.put("object",   jconfigure);
-                jmsg.put("args", jargs);
-                _eventHandler.publishEvent("try", jmsg);
+                sendJSONRequest(cbox.getValue().toString());
             });
             getChildren().addAll(cbox);
         }
+        else if(_name.equals("color")){
+            ColorPicker colorPicker = new ColorPicker();
+            colorPicker.setValue(Color.web(json.get("value").toString()));
+            colorPicker.setOnAction(new EventHandler() {
+                public void handle(Event t) {
+                    sendJSONRequest(toHexString(colorPicker.getValue()));
+                }
+            });
+            getChildren().addAll(colorPicker);
+        }
         else {
-            _type = "input";
             TextField cfield = new TextField(json.get("value").toString());
             cfield.setOnKeyPressed(event -> {
                 if (event.getCode().equals(KeyCode.ENTER)) {
-                    JSONObject jconfi = new JSONObject();
-                    jconfi.put("value", cfield.getText().toString());
-                    JSONObject jconfigs = new JSONObject();
-                    jconfigs.put(_name, jconfi);
-                    JSONObject jconfigure = new JSONObject();
-                    jconfigure.put(_topic, jconfigs);
-                    JSONObject jmsg = new JSONObject();
-                    jmsg.put("operation", "change");
-                    JSONObject jargs = new JSONObject();
-                    jargs.put("subject", jparent_id);
-                    jargs.put("object", jconfigure);
-                    jmsg.put("args", jargs);
-                    _eventHandler.publishEvent("try", jmsg);
+                    sendJSONRequest(cfield.getText().toString());
                 }
             });
             getChildren().addAll(cfield);
         }
     }
 
-    public String getName(){
-        return _name;
+    private void sendJSONRequest(String value){
+        JSONObject jconfi = new JSONObject();
+        jconfi.put("value", value);
+        JSONObject jconfigs = new JSONObject();
+        jconfigs.put(_name, jconfi);
+        JSONObject jconfigure = new JSONObject();
+        jconfigure.put(_topic, jconfigs);
+        JSONObject jmsg = new JSONObject();
+        jmsg.put("operation", "change");
+        JSONObject jargs = new JSONObject();
+        jargs.put("subject", jparent_id);
+        jargs.put("object", jconfigure);
+        jmsg.put("args", jargs);
+        _eventHandler.publishEvent("try", jmsg);
+    }
+
+    private String format(double val) {
+        String in = Integer.toHexString((int) Math.round(val * 255));
+        return in.length() == 1 ? "0" + in : in;
+    }
+
+    private String toHexString(Color value) {
+        return "#" + (format(value.getRed()) + format(value.getGreen()) + format(value.getBlue()) + format(value.getOpacity()))
+                .toUpperCase();
     }
 }

+ 27 - 39
src/main/java/mdd/client/Module.java

@@ -60,7 +60,6 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
     public boolean isSelected = false;
 
     public Module(JSONObject json){
-        
         setFocusTraversable(true);
         _eventHandler = GUIEventHandler.getEventHandler();
         _eventHandler.addEventListener(this, 5);
@@ -85,7 +84,7 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
         titlebar.setArcWidth(10.0f);
         titlebar.setArcHeight(10.0f);
 
-        //ackground = new Rectangle(0.0f, 0.0f, 150-20, 150 + 40);
+        //background = 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);
@@ -96,8 +95,13 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
         caption.setX(10);
         caption.setY(15);
 
+        Color color = Color.DARKCYAN;
+        titlebar.setFill(color);
         configure(json);
 
+        getChildren().clear();
+        getChildren().addAll( background, titlebar, caption, vlayout);
+
         addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
             if(e.getButton() == MouseButton.PRIMARY) {
                 isSelected = true;
@@ -152,7 +156,11 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
     }
 
     public void configure(JSONObject json){
-        Type = json.get("type").toString();
+        int test = 0;
+        if (json.containsKey("type")){
+            Type = json.get("type").toString();
+        }
+
         if (json.containsKey("ID")){
             jID = (JSONObject)json.get("ID");
 
@@ -166,9 +174,12 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
             }
         }
 
-        updateConnectable(ConnectableType.INPUT,json);
-        updateConnectable(ConnectableType.OUTPUT,json);
-
+        if (json.containsKey("inputs")){
+            updateConnectable(ConnectableType.INPUT,json);
+        }
+        if (json.containsKey("outputs")){
+            updateConnectable(ConnectableType.OUTPUT,json);
+        }
 
         if (json.containsKey("configure")) {
             configs.getChildren().clear();
@@ -181,16 +192,15 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
             int counter = 0;
             while (itr.hasNext()){
                 String key = itr.next();
-                if(!key.equals("name")){
-                    JSONObject jconfig = (JSONObject) jconfigs.get(key);
-                    Label clabel = new Label(key);
-                    configs.add(clabel,0,counter);
-                    configs.add(new Configuration("configure", this, key, jconfig),1,counter);
-                    ++counter;
-                }
+                JSONObject jconfig = (JSONObject) jconfigs.get(key);
+                Label clabel = new Label(key);
+                configs.add(clabel,0,counter);
+                configs.add(new Configuration("configure", this, key, jconfig),1,counter);
+                ++counter;
             }
         }
 
+
         if (json.containsKey("GUI")) {
             JSONObject jgui = (JSONObject) json.get("GUI");
             if (jgui.containsKey("name")) {
@@ -202,6 +212,9 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
                 caption.setText(Name);
             }
             caption.setText(Name);
+            if (jgui.containsKey("color")) {
+                titlebar.setFill(Color.web(((JSONObject)jgui.get("color")).get("value").toString()));
+            }
             if (jgui.containsKey("posX")){
                 setTranslateX((double)jgui.get("posX"));
             }
@@ -209,12 +222,6 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
                 setTranslateY((double) jgui.get("posY"));
             }
         }
-
-        Color color = Color.DARKCYAN;
-        titlebar.setFill(color);
-
-        getChildren().clear();
-        getChildren().addAll( background, titlebar, caption, vlayout);
     }
 
     protected void updateConnectable(ConnectableType ctype,JSONObject json){
@@ -336,26 +343,7 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
             JSONObject jobj = (JSONObject) jargs.get("object");
             switch((String) args.get("operation")){
                 case "change":
-                    if (jobj.containsKey("GUI")){
-                        JSONObject jgui = (JSONObject) jobj.get("GUI");
-                        if (jgui.containsKey("name")) {
-                            try {
-                                Name = ((JSONObject)jgui.get("name")).get("value").toString();
-                            }catch(ClassCastException e){
-                                Name= jgui.get("name").toString();
-                            }
-                            caption.setText(Name);
-                        }
-                        if (jgui.containsKey("posX")){
-                            setTranslateX((double)jgui.get("posX"));
-                        }
-                        if (jgui.containsKey("posY")) {
-                            setTranslateY((double) jgui.get("posY"));
-                        }
-                    }
-                    if (jobj.containsKey("configure")){
-                        configure((JSONObject) jobj.get("configure"));
-                    }
+                    configure(jobj);
             }
             return;
         }

+ 5 - 3
src/main/java/mdd/client/Processor.java

@@ -206,10 +206,12 @@ public class Processor extends Module{
                     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());
+                        JSONArray jprefix = (JSONArray)json.get("prefix");
+                        connectable = getModule(jprefix.get(jprefix.size()-1).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());
+                        JSONArray jprefix = (JSONArray)json.get("prefix");
+                        connectable = getModule(jprefix.get(jprefix.size()-1).toString()).getOutput(json.get("ID").toString());
                     }
                     if (connectable == null){
                         System.out.println("[Processor]: Couldn't find Connectable!");
@@ -236,7 +238,7 @@ public class Processor extends Module{
                 return;
             }
 
-            if (!jargs.containsKey("object")){return;}
+           if (!jargs.containsKey("object")){return;}
             JSONObject jobj = (JSONObject)jargs.get("object");
             switch (args.get("operation").toString()){
                 case "add":