Example #1
0
    public void createConnection(Widget source, Widget target) {

      // Select necessary nodes only

      ConfigNode cnSource = (ConfigNode) findObject(source);
      ConfigNode cnTarget = (ConfigNode) findObject(target);

      String cnSourceIdType = cnSource.getId().substring(0, 2);
      String cnTargetIdType = cnTarget.getId().substring(0, 2);

      String type = "TEMPORAL";

      // filter relavent links only
      if ((cnSourceIdType.equals("L2") && cnTargetIdType.equals("L1"))
          || (cnSourceIdType.equals("L1") && cnTargetIdType.equals("L0"))
          || (cnSourceIdType.equals(cnTargetIdType))) {

        ConnectionWidget conn = new ConnectionWidget(GraphSceneImpl.this);
        conn.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);

        // Double arrow head for cross features
        if (cnSourceIdType.equals(cnTargetIdType)) {
          conn.setSourceAnchorShape(AnchorShape.TRIANGLE_FILLED);
          type = "CROSS";
        }

        //
        // conn.setRouter(RouterFactory.createOrthogonalSearchRouter(GraphSceneImpl.widgetCollector));
        conn.setTargetAnchor(AnchorFactory.createRectangularAnchor(target));
        conn.setSourceAnchor(AnchorFactory.createRectangularAnchor(source));
        connectionLayer.addChild(conn);
        edgeMap.add(new NodeLinks(type, cnSource.getId(), cnTarget.getId()));
      }
    }
Example #2
0
  @Override
  protected Widget attachNodeWidget(ConfigNode arg) {
    IconNodeWidget widget = new IconNodeWidget(this);
    if (arg.getId().startsWith("L2F")) {
      widget.setImage(ImageUtilities.loadImage("com/weaved/server/configurator/images/d.png"));
    } else if (arg.getId().startsWith("L1F")) {
      widget.setImage(ImageUtilities.loadImage("com/weaved/server/configurator/images/f.png"));
    } else {
      widget.setImage(ImageUtilities.loadImage("com/weaved/server/configurator/images/p.png"));
    }

    widget
        .getActions()
        .addAction(
            ActionFactory.createExtendedConnectAction(connectionLayer, new MyConnectProvider()));

    widget
        .getActions()
        .addAction(
            ActionFactory.createAlignWithMoveAction(
                mainLayer, interactionLayer, ActionFactory.createDefaultAlignWithMoveDecorator()));

    widget
        .getActions()
        .addAction(
            ActionFactory.createPopupMenuAction(
                new PopupMenuProvider() {
                  @Override
                  public JPopupMenu getPopupMenu(final Widget widget, Point localLocation) {
                    JPopupMenu popup = new JPopupMenu();

                    // Properties
                    JMenuItem propsMenu = new JMenuItem("Properties");
                    propsMenu.addActionListener(
                        new ActionListener() {
                          @Override
                          public void actionPerformed(ActionEvent e) {

                            Object object =
                                findObject(
                                    widget); // consider a map "string" => ShapeObj at creation
                            // (drop)
                            ConfigNode node = (ConfigNode) object;

                            if (node.getId().startsWith("L0")) {
                              PerceptionConfigPropNode propNode =
                                  new PerceptionConfigPropNode((PerceptionConfigNode) node);
                              propNode.setDisplayName("Node Settings");
                              propNode.setShortDescription(
                                  "Click on properties to get a small discription about the property");
                              NodeOperation.getDefault().showProperties(propNode);
                            } else {
                              ConfigPropNode propNode = new ConfigPropNode(node);
                              propNode.setDisplayName("Node Settings");
                              propNode.setShortDescription(
                                  "Click on properties to get a small discription about the property");
                              NodeOperation.getDefault().showProperties(propNode);
                            }
                          }
                        });

                    // Delete
                    JMenuItem deleteMenu = new JMenuItem("Delete");
                    deleteMenu.addActionListener(
                        new ActionListener() {
                          @Override
                          public void actionPerformed(ActionEvent e) {

                            ConfigNode cn = (ConfigNode) findObject(widget);

                            List<Widget> connections = connectionLayer.getChildren();

                            for (Widget connection : connections) {
                              ConnectionWidget conn = (ConnectionWidget) connection;

                              if (conn.getSourceAnchor().getRelatedWidget().equals(widget)) {

                                connectionLayer.removeChild(conn);
                                //                                edgeMap.remove(conn);

                              }

                              if (conn.getTargetAnchor().getRelatedWidget().equals(widget)) {

                                connectionLayer.removeChild(conn);
                                //                                edgeMap.remove(conn);
                              }
                            }

                            GraphSceneImpl.this.removeNode(cn);
                            nodeMap.remove(cn.getId());
                          }
                        });

                    popup.add(propsMenu);
                    popup.add(deleteMenu);

                    return popup;
                  }
                }));

    widget.setLabel(arg.getId());
    mainLayer.addChild(widget);
    return widget;
  }