Search in sources :

Example 1 with GraphPiece

use of org.apache.airavata.workflow.model.graph.GraphPiece in project airavata by apache.

the class GraphCanvas method mouseReleased.

private void mouseReleased(MouseEvent event) {
    Point point = event.getPoint();
    if (this.draggedNode != null) {
        NodeController.getGUI(this.draggedNode).setDraggedFlag(false);
        this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
        // Check if it s stream grouping
        if (draggedNode instanceof InputNode) {
            StreamSourceNode streamNode = NodeController.getGUI(this.graph).getStreamSourceAt(point);
            if (streamNode != null) {
                streamNode.addInputNode((InputNode) draggedNode);
            }
        }
        this.draggedNode = null;
    }
    if (this.draggedPort != null) {
        GraphPiece graphPiece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
        if (graphPiece instanceof DynamicNode) {
            if (this.draggedPort.getKind() == Kind.DATA_OUT && draggedPort instanceof DataPort) {
                this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                DynamicNode dynamicNode = (DynamicNode) graphPiece;
                dynamicNode.getComponent();
                DataPort freePort = dynamicNode.getFreeInPort();
                try {
                    freePort.copyType((DataPort) draggedPort);
                } catch (GraphException e) {
                    engine.getGUI().getErrorWindow().error(e);
                    return;
                }
                // selectInputPort(freePort);
                connect(this.draggedPort, freePort);
                this.dynamicNodeWithFreePort = null;
            }
        } else if (graphPiece instanceof Port) {
            Port port = (Port) graphPiece;
            if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
                connect(this.draggedPort, port);
            } else if (port.getKind() == Kind.DATA_OUT && this.draggedPort.getKind() == Kind.DATA_IN) {
                connect(port, this.draggedPort);
            } else if (this.draggedPort.getKind() == Kind.CONTROL_OUT && port.getKind() == Kind.CONTROL_IN) {
                connect(this.draggedPort, port);
            } else if (this.draggedPort.getKind() == Kind.CONTROL_IN && port.getKind() == Kind.CONTROL_OUT) {
                connect(port, this.draggedPort);
            } else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
                connect(this.draggedPort, port);
            } else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
                connect(port, this.draggedPort);
            }
        }
        this.draggedPort = null;
    }
    if (this.dynamicNodeWithFreePort != null) {
        try {
            this.dynamicNodeWithFreePort.removeLastDynamicallyAddedInPort();
        } catch (GraphException e) {
            this.engine.getGUI().getErrorWindow().error(e);
        }
    }
    /*
         * Multiple selected
         */
    if (this.mousePointForSelection != null) {
        double width = Math.abs(this.mousePoint.getX() - this.mousePointForSelection.getX());
        double height = Math.abs(this.mousePoint.getY() - this.mousePointForSelection.getY());
        int x = (int) (this.mousePoint.getX() > this.mousePointForSelection.getX() ? this.mousePointForSelection.getX() : this.mousePoint.getX());
        int y = (int) (this.mousePoint.getY() > this.mousePointForSelection.getY() ? this.mousePointForSelection.getY() : this.mousePoint.getY());
        this.multipleSelectedNodes = NodeController.getGUI(this.graph).getNodesIn(new Rectangle(x, y, (int) width, (int) height));
        selectNodes(this.multipleSelectedNodes);
        // clear mousepoint
        this.mousePointForSelection = null;
    }
    if (this.multipleSelectedNodes != null) {
        this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
    }
    maybeShowPopup(event);
    updateSize();
    this.panel.repaint();
    event.consume();
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Rectangle(java.awt.Rectangle) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Point(java.awt.Point) Point(java.awt.Point)

Example 2 with GraphPiece

use of org.apache.airavata.workflow.model.graph.GraphPiece in project airavata by apache.

the class GraphCanvas method maybeShowPopup.

private void maybeShowPopup(MouseEvent event) {
    if (event.isPopupTrigger()) {
        GraphPiece piece = NodeController.getGUI(this.graph).getGraphPieceAt(event.getPoint());
        if (piece instanceof Node) {
            prepareNodePopupMenu((Node) piece);
            this.nodePopup.show(event.getComponent(), event.getX(), event.getY());
        } else if (piece instanceof Edge) {
            this.edgePopup.show(event.getComponent(), event.getX(), event.getY());
        }
    }
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) Edge(org.apache.airavata.workflow.model.graph.Edge)

Example 3 with GraphPiece

use of org.apache.airavata.workflow.model.graph.GraphPiece in project airavata by apache.

the class GraphCanvas method mouseClicked.

private void mouseClicked(MouseEvent event) {
    /*
         * If there is multi-selected and a click on a node, switch to that node or deselect node if it is already
         * selected
         */
    Point point = event.getPoint();
    GraphPiece clicked = NodeController.getGUI(this.graph).getGraphPieceAt(point);
    if ((clicked instanceof Node) && this.multipleSelectedNodes != null) {
        Node node = (Node) clicked;
        if (!this.crtlPressed) {
            selectNode(node);
        }
        return;
    } else if ((clicked instanceof Port) && event.getClickCount() == 2) {
        // double click to add Input/Output nodes and connect with them when a DataPort is double clicked
        Port port = (Port) clicked;
        Point pos = port.getNode().getPosition();
        Node node = null;
        int xgap = (int) (1.5 * NodeGUI.MINIMUM_WIDTH);
        int ygap = (int) (NodeGUI.MINIMUM_HEIGHT / 2);
        Point nodePos = null;
        switch(port.getKind()) {
            case DATA_IN:
                if (port.getFromNode() == null) {
                    nodePos = new Point(Math.max(0, pos.x - xgap), Math.max(0, pos.y - ygap));
                    node = addNode(new InputComponent(), nodePos);
                    connect(node.getOutputPorts().get(0), port);
                }
                break;
            case DATA_OUT:
                nodePos = new Point(pos.x + NodeGUI.MINIMUM_WIDTH + xgap, pos.y + ygap);
                node = addNode(new OutputComponent(), nodePos);
                connect(port, node.getInputPorts().get(0));
                break;
            default:
        }
    }
    // delegate the event.
    NodeController.getGUI(this.graph).mouseClicked(event, this.engine);
}
Also used : InputComponent(org.apache.airavata.workflow.model.component.system.InputComponent) GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) OutputComponent(org.apache.airavata.workflow.model.component.system.OutputComponent) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point)

Example 4 with GraphPiece

use of org.apache.airavata.workflow.model.graph.GraphPiece in project airavata by apache.

the class GraphCanvas method mouseMoved.

private void mouseMoved(MouseEvent event) {
    Point point = event.getPoint();
    GraphPiece graphPiece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
    if (graphPiece instanceof Node) {
        Node node = (Node) graphPiece;
        if (NodeController.getGUI(node).isInConfig(point)) {
            this.panel.setCursor(SwingUtil.HAND_CURSOR);
        } else {
            this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
        }
    } else if (graphPiece instanceof Port) {
        this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
    } else {
        this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
    }
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point)

Example 5 with GraphPiece

use of org.apache.airavata.workflow.model.graph.GraphPiece in project airavata by apache.

the class GraphCanvas method mousePressed.

private void mousePressed(MouseEvent event) {
    Point point = event.getPoint();
    // Get focus to handle key board events
    this.panel.requestFocusInWindow();
    // Get select item
    GraphPiece selected = NodeController.getGUI(this.graph).getGraphPieceAt(point);
    /*
         * Doing Nothing if pressed is on the selected node
         */
    if (this.multipleSelectedNodes != null) {
        maybeShowPopup(event);
        if (this.crtlPressed && this.multipleSelectedNodes.contains(selected)) {
            deselectNode((Node) selected);
            return;
        } else if (this.multipleSelectedNodes.contains(selected)) {
            this.mousePoint = point;
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
            return;
        } else if ((selected instanceof Node) && this.crtlPressed) {
            this.mousePoint = point;
            this.multipleSelectedNodes.add((Node) selected);
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
            selectNodes(this.multipleSelectedNodes);
            return;
        }
    }
    // control selection
    if ((selected instanceof Node) && this.crtlPressed) {
        this.multipleSelectedNodes = new ArrayList<Node>();
        if (this.selectedNode != null) {
            this.multipleSelectedNodes.add(this.selectedNode);
        }
        this.multipleSelectedNodes.add((Node) selected);
        this.panel.setCursor(SwingUtil.MOVE_CURSOR);
        selectNodes(this.multipleSelectedNodes);
        return;
    }
    deselectNode();
    deselectEdge();
    if (selected instanceof Node) {
        Node node = (Node) selected;
        selectNode(node);
        if (!NodeController.getGUI(node).isInConfig(point)) {
            this.draggedNode = node;
            NodeController.getGUI(node).setDraggedFlag(true);
            this.panel.setCursor(SwingUtil.MOVE_CURSOR);
        }
    } else if (selected instanceof Port) {
        Port port = (Port) selected;
        NodeController.getGUI(port).setSelectedFlag(true);
        switch(port.getKind()) {
            case DATA_IN:
            case CONTROL_IN:
                selectInputPort(port);
                break;
            case CONTROL_OUT:
            case DATA_OUT:
            case EPR:
                selectOutputPort(port);
                break;
        }
        this.draggedPort = port;
    } else if (selected instanceof Edge) {
        Edge edge = (Edge) selected;
        selectEdge(edge);
    } else {
        /*
             * If nothing is selected
             */
        this.mousePointForSelection = event.getPoint();
    }
    maybeShowPopup(event);
    this.mousePoint = point;
    this.panel.repaint();
    event.consume();
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point) Edge(org.apache.airavata.workflow.model.graph.Edge)

Aggregations

GraphPiece (org.apache.airavata.workflow.model.graph.GraphPiece)7 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)7 Node (org.apache.airavata.workflow.model.graph.Node)6 Port (org.apache.airavata.workflow.model.graph.Port)6 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)6 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)6 Point (java.awt.Point)5 DataPort (org.apache.airavata.workflow.model.graph.DataPort)5 Edge (org.apache.airavata.workflow.model.graph.Edge)3 Rectangle (java.awt.Rectangle)1 InputComponent (org.apache.airavata.workflow.model.component.system.InputComponent)1 OutputComponent (org.apache.airavata.workflow.model.component.system.OutputComponent)1 GraphException (org.apache.airavata.workflow.model.graph.GraphException)1 PortAddable (org.apache.airavata.workflow.model.graph.dynamic.PortAddable)1 MemoNode (org.apache.airavata.workflow.model.graph.system.MemoNode)1