Search in sources :

Example 6 with GraphPiece

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

the class GraphCanvas method mouseDragged.

private void mouseDragged(MouseEvent event) {
    Point point = event.getPoint();
    if (editable) {
        /*
			 * Move nodes
			 */
        if (this.multipleSelectedNodes != null) {
            if (point.x < 0) {
                point.x = 0;
            }
            if (point.y < 0) {
                point.y = 0;
            }
            int diffX = point.x - this.mousePoint.x;
            int diffY = point.y - this.mousePoint.y;
            for (Node node : this.multipleSelectedNodes) {
                Point newPoint = new Point();
                Point currentPoint = node.getPosition();
                newPoint.x = currentPoint.x + diffX;
                if (newPoint.x < 0) {
                    newPoint.x = 0;
                }
                newPoint.y = currentPoint.y + diffY;
                if (newPoint.y < 0) {
                    newPoint.y = 0;
                }
                node.setPosition(newPoint);
            }
            this.panel.repaint();
            event.consume();
        }
        if (this.draggedNode != null) {
            if (point.x < 0) {
                point.x = 0;
            }
            if (point.y < 0) {
                point.y = 0;
            }
            int diffX = point.x - this.mousePoint.x;
            int diffY = point.y - this.mousePoint.y;
            Point newPoint = new Point();
            Point currentPoint = this.draggedNode.getPosition();
            newPoint.x = currentPoint.x + diffX;
            if (newPoint.x < 0) {
                newPoint.x = 0;
            }
            newPoint.y = currentPoint.y + diffY;
            if (newPoint.y < 0) {
                newPoint.y = 0;
            }
            this.draggedNode.setPosition(newPoint);
            this.panel.repaint();
            event.consume();
        }
        if (this.draggedPort != null) {
            GraphPiece piece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
            if (piece instanceof Port) {
                Port port = (Port) piece;
                // pointer.
                if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.DATA_OUT) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectOutputPort(port);
                } else if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectInputPort(port);
                } else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectOutputPort(port);
                } else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectInputPort(port);
                } else {
                    this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
                }
            } else if (piece instanceof PortAddable) {
                PortAddable dynamicNode = (PortAddable) piece;
                dynamicNode.getFreeInPort();
                this.dynamicNodeWithFreePort = dynamicNode;
            } else {
                this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
            }
            this.panel.repaint();
            event.consume();
        }
        this.mousePoint = point;
        // draw rectangle
        if (this.mousePointForSelection != null) {
            this.panel.repaint();
        }
    }
}
Also used : PortAddable(org.apache.airavata.workflow.model.graph.dynamic.PortAddable) 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) Point(java.awt.Point)

Example 7 with GraphPiece

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

the class GraphGUI method getGraphPieceAt.

/**
 * Returns the visible object at the specified location. The object is either a Node, a Port, or an Edge.
 *
 * @param point
 *            The location
 * @return The visible object a the specified location
 */
protected GraphPiece getGraphPieceAt(Point point) {
    GraphPiece piece = null;
    // Starts from edge because it is drawn first, which means it's at the
    // bottom.
    double minEdgeDist = Double.MAX_VALUE;
    Edge closestEdge = null;
    for (Edge edge : this.graph.getEdges()) {
        double dist = NodeController.getGUI(edge).getMiddlePosition().distance(point);
        if (dist < minEdgeDist) {
            closestEdge = edge;
            minEdgeDist = dist;
        }
    }
    if (minEdgeDist < 20) {
        piece = closestEdge;
    }
    // Then, each node and ports of it.
    for (Node node : this.graph.getNodes()) {
        // Check the node first
        if (NodeController.getGUI(node).isIn(point)) {
            piece = node;
        }
        // Find the closest port of this node.
        double minPortDist = Double.MAX_VALUE;
        Port closestPort = null;
        for (Port port : node.getAllPorts()) {
            double dist = NodeController.getGUI(port).getPosition().distance(point);
            if (dist < minPortDist) {
                closestPort = port;
                minPortDist = dist;
            }
        }
        if (minPortDist <= PortGUI.DATA_PORT_SIZE) {
            piece = closestPort;
        }
    // Don't break from this loop because the later ones are drawn at
    // the top of other nodes.
    }
    return piece;
}
Also used : GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) Node(org.apache.airavata.workflow.model.graph.Node) Port(org.apache.airavata.workflow.model.graph.Port) 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