Browse Source

before big infrastructure change

Willi Zschiebsch 4 years ago
parent
commit
b4ba8e5cb0

+ 9 - 5
src/main/java/mdd/client/Configuration.java

@@ -12,19 +12,23 @@ import org.json.simple.JSONObject;
 
 public class Configuration extends Group {
     private String _name = "";
-    private JSONObject jparent_id = new JSONObject();
+    private String _topic = "";
+    private JSONObject jparent_id;
+
     private String _type = "";
     protected GUIEventHandler _eventHandler;
 
-    Configuration(Module parent, String key, JSONObject json){
+    Configuration(String topic, Module parent, String key, JSONObject json){
         jparent_id = parent.getJSONIdentifier();
         _name = key;
+        _topic = topic;
         setUp(json);
     }
 
-    Configuration(JSONObject parent_id, String key, JSONObject json){
+    Configuration(String topic, JSONObject parent_id, String key, JSONObject json){
         jparent_id = parent_id;
         _name = key;
+        _topic = topic;
         setUp(json);
     }
 
@@ -49,7 +53,7 @@ public class Configuration extends Group {
                 JSONObject jconfigs = new JSONObject();
                 jconfigs.put(_name, jconfi);
                 JSONObject jconfigure = new JSONObject();
-                jconfigure.put("configure", jconfigs);
+                jconfigure.put(_topic, jconfigs);
                 JSONObject jmsg = new JSONObject();
                 jmsg.put("operation", "change");
                 JSONObject jargs = new JSONObject();
@@ -70,7 +74,7 @@ public class Configuration extends Group {
                     JSONObject jconfigs = new JSONObject();
                     jconfigs.put(_name, jconfi);
                     JSONObject jconfigure = new JSONObject();
-                    jconfigure.put("configure", jconfigs);
+                    jconfigure.put(_topic, jconfigs);
                     JSONObject jmsg = new JSONObject();
                     jmsg.put("operation", "change");
                     JSONObject jargs = new JSONObject();

+ 41 - 15
src/main/java/mdd/client/Module.java

@@ -108,7 +108,7 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
             if(e.getButton() == MouseButton.SECONDARY) {
 
             }
-            //e.consume();
+            e.consume();
         });
 
         addEventHandler(MouseEvent.MOUSE_DRAGGED, e -> {
@@ -153,14 +153,12 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
 
     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();
-            caption.setText(Name);
+            Key = jID.get("key").toString();
             Appendix = (long)jID.get("appendix");
-            ID = Name +Appendix;
+            ID = Key +Appendix;
             Prefix = new Vector<>();
             JSONArray jarr = (JSONArray)jID.get("prefix");
             for (Object o : jarr) {
@@ -177,23 +175,39 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
             configs.setHgap(20);
             configs.setVgap(20);
 
-            JSONObject jconfigs = (JSONObject)json.get("configure");
+            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(!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;
+                }
             }
         }
 
         if (json.containsKey("GUI")) {
             JSONObject jgui = (JSONObject) json.get("GUI");
-            setTranslateX((double)jgui.get("posX"));
-            setTranslateY((double)jgui.get("posY"));
+            if (jgui.containsKey("name")) {
+                try {
+                    Name = ((JSONObject)jgui.get("name")).get("value").toString();
+                }catch(ClassCastException e){
+                    Name= jgui.get("name").toString();
+                }
+                caption.setText(Name);
+            }
+            caption.setText(Name);
+            if (jgui.containsKey("posX")){
+                setTranslateX((double)jgui.get("posX"));
+            }
+            if (jgui.containsKey("posY")) {
+                setTranslateY((double) jgui.get("posY"));
+            }
         }
 
         Color color = Color.DARKCYAN;
@@ -324,8 +338,20 @@ public class Module extends Group implements IGUIEventClient, ChangeListener<Bou
                 case "change":
                     if (jobj.containsKey("GUI")){
                         JSONObject jgui = (JSONObject) jobj.get("GUI");
-                        setTranslateX((double)jgui.get("posX"));
-                        setTranslateY((double)jgui.get("posY"));
+                        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"));

+ 3 - 6
src/main/java/mdd/client/PropertyManager.java

@@ -33,7 +33,7 @@ public class PropertyManager extends ScrollPane implements IGUIEventClient{
         setFitToWidth(true);
     }
 
-    private GridPane createLayout(JSONObject json){
+    private GridPane createLayout(String topic, JSONObject json){
         GridPane glayout = new GridPane();
         glayout.getChildren().clear();
         glayout.setHgap(5);
@@ -52,7 +52,7 @@ public class PropertyManager extends ScrollPane implements IGUIEventClient{
             }
             Label clabel = new Label(key);
             glayout.add(clabel,0,counter);
-            glayout.add(new Configuration(jsel, key, jconfig),1,counter);
+            glayout.add(new Configuration(topic, jsel, key, jconfig),1,counter);
             ++counter;
         }
 
@@ -65,7 +65,7 @@ public class PropertyManager extends ScrollPane implements IGUIEventClient{
         while (itr.hasNext()){
             String key = itr.next();
             JSONObject jcontent = (JSONObject) json.get(key);
-            Tab tab = new Tab(key  , new ScrollPane(createLayout(jcontent)));
+            Tab tab = new Tab(key  , new ScrollPane(createLayout(key, jcontent)));
             tabPane.getTabs().add(tab);
         }
         tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
@@ -100,9 +100,6 @@ public class PropertyManager extends ScrollPane implements IGUIEventClient{
                 if (jargs.containsKey("info")){
                     JSONObject jinfo = (JSONObject)jargs.get("info");
                     setContent(pane1,jinfo);
-                    if (jinfo.containsKey("GUI")){
-                        setContent(pane2,(JSONObject) jinfo.get("GUI"));
-                    }
                     System.out.println("[PropertyManger]: " + jinfo.toString());
                 }
             }

+ 1 - 1
src/main/java/mdd/client/WorkBench.java

@@ -15,7 +15,7 @@ public class WorkBench extends Tab implements IGUIEventClient{
     private GUIEventHandler _eventHandler;
 
     public WorkBench(Processor processor){
-        super(processor.getAsPrefix().toString());
+        super(processor.Name);
 
         _eventHandler = GUIEventHandler.getEventHandler();
         _eventHandler.addEventListener(this);

+ 7 - 3
src/main/java/mdd/client/connectable/Connectable.java

@@ -42,6 +42,7 @@ public class Connectable extends GridPane implements IGUIEventClient,ChangeListe
     protected StackPane _connection;
     protected Label _label = new Label();
     public String Name = "";
+    public String Key = "";
     public String ID = "";
     public long Appendix = 0;
     public Vector<Double> Value = new Vector<>();
@@ -189,6 +190,9 @@ public class Connectable extends GridPane implements IGUIEventClient,ChangeListe
                     Value.add((Double)o);
                 }
             }
+            if (jconfig.containsKey("name")){
+                Name = (String) jconfig.get("name");
+            }
             if (jconfig.containsKey("optimizable")){
                 JSONObject jopt =  (JSONObject)jconfig.get("optimizable");
                 String state = jopt.get("value").toString();
@@ -205,8 +209,8 @@ public class Connectable extends GridPane implements IGUIEventClient,ChangeListe
 
         if (json.containsKey("ID")){
             jID = (JSONObject)json.get("ID");
-            if (jID.containsKey("name")){
-                Name = (String) jID.get("name");
+            if (json.containsKey("key")){
+                Key = (String) json.get("key");
             }
             if (jID.containsKey("appendix")){
                 Appendix = (long) jID.get("appendix");
@@ -214,7 +218,7 @@ public class Connectable extends GridPane implements IGUIEventClient,ChangeListe
         }
 
 
-        ID = Name + Appendix;
+        ID = Key + Appendix;
         _label.setText(Name);
     }