Exemplo 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);
  }
Exemplo n.º 2
0
 public void clear() {
   mainLayer.removeChildren();
   constraintsLayer.removeChildren();
   connectionLayer.removeChildren();
   constants.clear();
   functions.clear();
   scene.validate();
 }
Exemplo n.º 3
0
  public static void main(String[] args) {
    final Scene scene = new Scene();

    LayerWidget layer = new LayerWidget(scene);
    scene.addChild(layer);

    Widget nodeWidget = new Widget(scene);
    nodeWidget.setBorder(BorderFactory.createLineBorder(1, Color.RED));
    nodeWidget.setPreferredLocation(new Point(100, 100));
    layer.addChild(nodeWidget);

    final Widget deferredWidget = new Widget(scene);
    deferredWidget.setLayout(LayoutFactory.createCardLayout(deferredWidget));
    deferredWidget.setBorder(BorderFactory.createLineBorder(1, Color.BLUE));
    nodeWidget.addChild(deferredWidget);

    final Widget label = new LabelWidget(scene, "Click me to add ComponentWidget");
    label.setBorder(BorderFactory.createLineBorder(1, Color.GREEN));
    deferredWidget.addChild(label);
    LayoutFactory.setActiveCard(deferredWidget, label);

    label
        .getActions()
        .addAction(
            ActionFactory.createEditAction(
                new EditProvider() {
                  public void edit(Widget widget) {
                    ComponentWidget component =
                        new ComponentWidget(scene, new JButton("This is the new ComponentWidget"));
                    component.setBorder(BorderFactory.createLineBorder(1, Color.GREEN));
                    deferredWidget.addChild(component);
                    LayoutFactory.setActiveCard(deferredWidget, component);
                  }
                }));

    scene
        .getActions()
        .addAction(
            ActionFactory.createEditAction(
                new EditProvider() {
                  public void edit(Widget widget) {
                    LayoutFactory.setActiveCard(deferredWidget, label);
                  }
                }));

    // to force the boundary
    //        nodeWidget.setPreferredBounds (new Rectangle (0, 0, 70, 30));
    //        nodeWidget.setPreferredSize (new Dimension (70, 30));
    nodeWidget.setLayout(LayoutFactory.createOverlayLayout());
    nodeWidget.setCheckClipping(true);
    //

    SceneSupport.show(scene);
  }
Exemplo n.º 4
0
 private Widget createLabel(String text, int x, int y, Color color) {
   LabelWidget label = new LabelWidget(this, text);
   label.setOpaque(true);
   label.setBackground(color);
   label.setBorder(BorderFactory.createLineBorder(5));
   label.setPreferredLocation(new Point(x, y));
   label.getActions().addAction(ActionFactory.createMoveAction());
   mainLayer.addChild(label);
   return label;
 }
  @Override
  protected Widget attachNodeWidget(Object n) {
    Widget widget = (Widget) n;
    widget.setToolTipText("flow node");
    widget.createActions(USE).addAction(0, dragAction);
    widget.createActions(EDIT).addAction(0, createSelectAction());
    widget.createActions(EDIT).addAction(1, multiMove);
    widget.createActions(EDIT).addAction(2, new CustomResizeAction());
    widget.createActions(EDIT).addAction(3, createObjectHoverAction());

    mainLayer.addChild(widget);

    return widget;
  }
Exemplo n.º 6
0
  @Override
  protected Widget attachNodeWidget(Node node) {
    NodeWidget widget = new NodeWidget(this);
    widget.setFont(Util.FIXED_WIDTH_FONT);
    widget.highLight(false);

    nodes.addChild(widget);
    //        widget.getActions().addAction(moveAction);
    widget.getActions().addAction(hoverAction);
    widget.getActions().addAction(nodePopupAction);
    widget.getActions().addAction(connectAction);

    return widget;
  }
Exemplo n.º 7
0
  @Override
  protected Widget attachEdgeWidget(Edge edge) {
    EdgeWidget connection = new EdgeWidget(this);
    connection.setStroke(Util.STROKE_2);
    connection.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);

    LabelWidget label = createEdgeLabel(edge);
    connection.setConstraint(label, LayoutFactory.ConnectionWidgetLayoutAlignment.TOP_CENTER, 0.5f);

    connection.addChild(label);
    connections.addChild(connection);

    connection.setRouter(router);
    connection.highLight(false);

    connection.getActions().addAction(hoverAction);
    connection.getActions().addAction(editAction);
    connection.getActions().addAction(edgePopupAction);
    return 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;
  }
  public void createConnection(Widget sourceWidget, Widget targetWidget) {
    try {
      ConnectionWidget connection = new ConnectionWidget(sourceWidget.getScene());
      connection.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
      connection.setSourceAnchor(AnchorFactory.createRectangularAnchor(sourceWidget));
      connection.setTargetAnchor(AnchorFactory.createRectangularAnchor(targetWidget));
      Stroke stroke = Costanti.BASIC_STROKE;
      connection.setStroke(stroke);
      connection
          .getActions()
          .addAction(
              ActionFactory.createPopupMenuAction(
                  new MyPopupProviderConnectionFunc(
                      sourceWidget.getScene(), mainLayer, caratteristiche)));
      ConnectionInfo connectionInfo = new ConnectionInfo();
      connectionInfo.setTargetWidget(targetWidget);
      connectionInfo.setConnectionWidget(connection);
      caratteristiche.setTargetWidget((VMDPinWidgetTarget) targetWidget);

      creator.createCorrespondenceWithFunction(
          mainLayer, targetWidget, caratteristiche, connectionInfo);

      caratteristiche.setConnectionInfo(connectionInfo);
      connectionLayer.addChild(connection, connectionInfo);
    } catch (ExpressionSyntaxException e) {
      DialogDisplayer.getDefault()
          .notify(
              new NotifyDescriptor.Message(
                  NbBundle.getMessage(Costanti.class, Costanti.SYNTAX_WARNING)
                      + " : "
                      + e.getMessage(),
                  DialogDescriptor.WARNING_MESSAGE));
      // giannisk delete target connection if exception if caught
      deleteTargetConnection(sourceWidget);
    }
  }
Exemplo n.º 10
0
 public void createNode(VisualNode node) {
   mainLayer.addChild(node);
 }
Exemplo n.º 11
0
  public ProxyAnchorExpandTest() {
    setBackground(Color.LIGHT_GRAY);

    // layer for widgets
    LayerWidget mainLayer = new LayerWidget(this);
    addChild(mainLayer);
    // layer for connections
    LayerWidget connLayer = new LayerWidget(this);
    addChild(connLayer);

    // outer widget
    Widget outerWidget = new Widget(this);
    outerWidget.setOpaque(true);
    outerWidget.setBackground(Color.WHITE);
    outerWidget.setBorder(BorderFactory.createLineBorder(10));
    outerWidget.setPreferredLocation(new Point(100, 100));
    outerWidget.setLayout(
        LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.CENTER, 4));

    outerWidget.addChild(
        new LabelWidget(
            this, "The anchor switches based on a state in StateModel used by ProxyAnchor."));
    outerWidget.addChild(
        new LabelWidget(this, "ConnectionWidget has the same anchors assigned all the time."));

    // inner widget
    LabelWidget innerWidget = new LabelWidget(this, "Internal frame");
    innerWidget.setBorder(BorderFactory.createLineBorder());
    outerWidget.addChild(innerWidget);

    mainLayer.addChild(outerWidget);

    // the target widget
    Widget targetWidget =
        new LabelWidget(this, "Click here to switch the state in StateModel/anchor.");
    targetWidget.setOpaque(true);
    targetWidget.setBackground(Color.WHITE);
    targetWidget.setBorder(BorderFactory.createLineBorder(10));
    targetWidget.setPreferredLocation(new Point(450, 300));
    mainLayer.addChild(targetWidget);

    // an action for switching a state of a StateModel used by the ProxyAnchor to determinate an
    // active anchor
    WidgetAction switchAction = ActionFactory.createSelectAction(new SwitchProvider());
    targetWidget.getActions().addAction(switchAction);

    Anchor outerAnchor = AnchorFactory.createRectangularAnchor(outerWidget);
    Anchor innerAnchor = AnchorFactory.createRectangularAnchor(innerWidget);

    // a proxy anchor which acts like an one of the specified anchors.
    // The active anchor is defined by a state in the StateModel
    Anchor proxyAnchor = AnchorFactory.createProxyAnchor(model, outerAnchor, innerAnchor);

    // the connection widget
    ConnectionWidget conn = new ConnectionWidget(this);
    conn.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
    connLayer.addChild(conn);

    // the proxy anchor is used as a source
    conn.setSourceAnchor(proxyAnchor);
    // the target anchor is assigned to the targetWidget widget
    conn.setTargetAnchor(AnchorFactory.createRectangularAnchor(targetWidget));
  }
Exemplo n.º 12
0
 public void clearFunctionalDependencies() {
   mainLayer.removeChildren(functionalDependencies);
   functionalDependencies.clear();
   scene.validate();
 }
Exemplo n.º 13
0
 public void clearConstants() {
   mainLayer.removeChildren(constants);
   constants.clear();
   scene.validate();
 }
Exemplo n.º 14
0
 public void clearConnections() {
   connectionLayer.removeChildren();
 }
Exemplo n.º 15
0
 public void clearTrees() {
   clearConnectionLayer();
   mainLayer.removeChildren();
   constraintsLayer.removeChildren();
 }
Exemplo n.º 16
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;
  }
Exemplo n.º 17
0
 public void clearFunctions() {
   mainLayer.removeChildren(functions);
   functions.clear();
   scene.validate();
 }