Ejemplo n.º 1
0
  public ActionsWithRoutingPolicyTest() {
    mainLayer = new LayerWidget(this);
    addChild(mainLayer);
    LayerWidget connLayer = new LayerWidget(this);
    addChild(connLayer);

    Widget source = createLabel("Source", 50, 200, Color.GREEN);
    Widget target = createLabel("Target", 450, 200, Color.GREEN);

    connection = new ConnectionWidget(this);
    connection.setSourceAnchor(
        AnchorFactory.createDirectionalAnchor(
            source, AnchorFactory.DirectionalAnchorKind.HORIZONTAL));
    connection.setTargetAnchor(
        AnchorFactory.createDirectionalAnchor(
            target, AnchorFactory.DirectionalAnchorKind.HORIZONTAL));
    connection.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
    connection.setPaintControlPoints(true);
    connection.setControlPointShape(PointShape.SQUARE_FILLED_BIG);
    connection.setRouter(RouterFactory.createOrthogonalSearchRouter(mainLayer));
    connection
        .getActions()
        .addAction(
            ActionFactory.createAddRemoveControlPointAction(
                1.0, 5.0, ConnectionWidget.RoutingPolicy.UPDATE_END_POINTS_ONLY));
    connection
        .getActions()
        .addAction(
            ActionFactory.createMoveControlPointAction(
                ActionFactory.createFreeMoveControlPointProvider(),
                ConnectionWidget.RoutingPolicy.UPDATE_END_POINTS_ONLY));
    connLayer.addChild(connection);
  }
  @Override
  protected Widget attachEdgeWidget(Object e) {
    // create the visual connection
    CustomConnectionWidget connection = (CustomConnectionWidget) e;
    connection.setPaintControlPoints(true);
    connection.setRouter(CustomRouterFactory.createFreeRouter());
    connection.setControlPointShape(FlowControlPointShape.CIRCLE_FILLED_SMALL);

    // Normal Edit Mode actions
    connection
        .createActions(EDGE_CONTROL_MODE)
        .addAction(0, ActionFactory.createAddRemoveControlPointAction());
    connection
        .createActions(EDGE_CONTROL_MODE)
        .addAction(1, ActionFactory.createFreeMoveControlPointAction());
    connection
        .createActions(EDGE_CONTROL_MODE)
        .addAction(2, ActionFactory.createAddRemoveControlPointAction());
    connection
        .createActions(EDGE_CONTROL_MODE)
        .addAction(3, ActionFactory.createFreeMoveControlPointAction());
    connection.createActions(EDGE_CONTROL_MODE).addAction(4, createObjectHoverAction());

    connectionLayer.addChild(connection);

    // create the data connection
    //        Port srcPort = (Port)
    // connection.getSourceAnchor().getRelatedWidget().getParentWidget();
    //        VisualNode src = srcPort.getParentNode();
    //
    //        Port tgtPort = (Port)
    // connection.getTargetAnchor().getRelatedWidget().getParentWidget();
    //        VisualNode tgt = tgtPort.getParentNode();

    //        dataScene.connect(src.getDataNode(), srcPort.getID(), tgt.getDataNode(),
    // tgtPort.getID());

    return connection;
  }