Connection.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package mdd.client.connectable;
  2. import javafx.scene.shape.Line;
  3. import mdd.client.GUIEventHandler;
  4. import mdd.client.IGUIEventClient;
  5. import mdd.client.connectable.Input;
  6. import mdd.client.connectable.Output;
  7. import org.json.simple.JSONObject;
  8. public class Connection extends Line implements IGUIEventClient {
  9. private GUIEventHandler _eventHandler;
  10. public Input in;
  11. public Output out;
  12. public Connection(){
  13. super();
  14. }
  15. public Connection(Input in, Output out){
  16. super(0,0,100,100);
  17. _eventHandler = GUIEventHandler.getEventHandler();
  18. _eventHandler.addEventListener(this);
  19. this.in = in;
  20. this.out = out;
  21. System.out.println("Connection: "+ in.x.toString());
  22. this.startXProperty().bind(in.x);
  23. this.startYProperty().bind(in.y);
  24. this.endXProperty().bind(out.x);
  25. this.endYProperty().bind(out.y);
  26. in.setConnected(true);
  27. out.setConnected(true);
  28. JSONObject json = new JSONObject();
  29. json.put("con", this.toString());
  30. json.put("in", in.toString());
  31. json.put("out", in.toString());
  32. _eventHandler.publishEvent("CONNECTED", json);
  33. }
  34. @Override
  35. public void processGUIEvent(String event, JSONObject args) {
  36. }
  37. @Override
  38. public void close() throws Exception {
  39. _eventHandler.removeEventListener(this);
  40. }
  41. }