Search in sources :

Example 1 with ContainerShape

use of cbit.gui.graph.ContainerShape in project vcell by virtualcell.

the class ConstraintsGraphModel method refreshAll.

public void refreshAll() {
    Set<Shape> unwantedShapes = new HashSet<Shape>();
    unwantedShapes.addAll(getShapes());
    for (Shape shape : getShapes()) {
        if (shape instanceof ConstraintVarNode) {
            ((ConstraintVarNode) shape).setDegree(1);
        }
    }
    ContainerShape containerShape = (ContainerShape) getShapeFromModelObject(getConstraintContainerImpl());
    if (containerShape == null) {
        containerShape = new SimpleContainerShape(getConstraintContainerImpl(), this, "constraint network");
        containerShape.setLabel("constraint network");
        addShape(containerShape);
    }
    containerShape.refreshLabel();
    unwantedShapes.remove(containerShape);
    // 
    // add nodes for GeneralConstraints and edges to its Variables (add Variable when necessary)
    // 
    GeneralConstraint[] generalConstraints = getConstraintContainerImpl().getGeneralConstraints();
    for (int i = 0; i < generalConstraints.length; i++) {
        String[] symbols = generalConstraints[i].getExpression().getSymbols();
        if (symbols == null) {
            continue;
        }
        GeneralConstraintNode generalConstraintNode = (GeneralConstraintNode) getShapeFromModelObject(generalConstraints[i]);
        if (generalConstraintNode == null) {
            generalConstraintNode = new GeneralConstraintNode(generalConstraints[i], this, symbols.length);
            containerShape.addChildShape(generalConstraintNode);
            addShape(generalConstraintNode);
        }
        generalConstraintNode.refreshLabel();
        unwantedShapes.remove(generalConstraintNode);
        for (int j = 0; j < symbols.length; j++) {
            ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(symbols[j]);
            if (constraintVarNode == null) {
                constraintVarNode = new ConstraintVarNode(symbols[j], this, 1);
                containerShape.addChildShape(constraintVarNode);
                addShape(constraintVarNode);
            } else {
                constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
            }
            constraintVarNode.refreshLabel();
            unwantedShapes.remove(constraintVarNode);
            ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
            for (Shape shape : getShapes()) {
                if (shape instanceof ConstraintDependencyEdgeShape) {
                    if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == generalConstraintNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                        constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                    }
                }
            }
            if (constraintDependencyEdgeShape == null) {
                constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(generalConstraintNode, constraintVarNode, this);
                containerShape.addChildShape(constraintDependencyEdgeShape);
                addShape(constraintDependencyEdgeShape);
            }
            unwantedShapes.remove(constraintDependencyEdgeShape);
        }
    }
    // 
    // add nodes for SimpleBounds and edges to its Variables (add Variable when necessary)
    // 
    cbit.vcell.constraints.SimpleBounds[] simpleBounds = getConstraintContainerImpl().getSimpleBounds();
    for (int i = 0; i < simpleBounds.length; i++) {
        BoundsNode boundsNode = (BoundsNode) getShapeFromModelObject(simpleBounds[i]);
        if (boundsNode == null) {
            boundsNode = new BoundsNode(simpleBounds[i], this);
            containerShape.addChildShape(boundsNode);
            addShape(boundsNode);
        }
        boundsNode.refreshLabel();
        unwantedShapes.remove(boundsNode);
        ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(simpleBounds[i].getIdentifier());
        if (constraintVarNode == null) {
            constraintVarNode = new ConstraintVarNode(simpleBounds[i].getIdentifier(), this, 1);
            containerShape.addChildShape(constraintVarNode);
            addShape(constraintVarNode);
        } else {
            constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
        }
        constraintVarNode.refreshLabel();
        unwantedShapes.remove(constraintVarNode);
        ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
        for (Shape shape : getShapes()) {
            if (shape instanceof ConstraintDependencyEdgeShape) {
                if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == boundsNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                    constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                }
            }
        }
        if (constraintDependencyEdgeShape == null) {
            constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(boundsNode, constraintVarNode, this);
            containerShape.addChildShape(constraintDependencyEdgeShape);
            addShape(constraintDependencyEdgeShape);
        }
        constraintDependencyEdgeShape.refreshLabel();
        unwantedShapes.remove(constraintDependencyEdgeShape);
    }
    for (Shape unwantedShape : unwantedShapes) {
        removeShape(unwantedShape);
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) SimpleBounds(cbit.vcell.constraints.SimpleBounds) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) HashSet(java.util.HashSet)

Example 2 with ContainerShape

use of cbit.gui.graph.ContainerShape in project vcell by virtualcell.

the class ReactionCartoonTool method mouseDragged.

@Override
public void mouseDragged(MouseEvent event) {
    if (getGraphPane().getComponentCount() > 0) {
        // we're editing, cancel
        stopEditing();
    }
    if (event.isPopupTrigger()) {
        return;
    }
    boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
    boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
    if (mode == Mode.SELECT && bStartRxContainerLabel) {
        if (dragStructTimer != null) {
            dragStructTimer.stop();
        }
        Point dragPointWorld = getGraphModel().getResizeManager().unzoom(event.getPoint());
        RXContainerDropTargetInfo lastTrueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
        lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(dragPointWorld);
        RXContainerDropTargetInfo currentTrueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
        // System.out.println(lastTrueRXContainerDropTargetInfo+" "+currentTrueRXContainerDropTargetInfo);
        if (dragStructTimer != null || !Compare.isEqualOrNull(lastTrueRXContainerDropTargetInfo, currentTrueRXContainerDropTargetInfo)) {
            activateDropTargetEnable();
            getGraphPane().repaint();
        }
        return;
    }
    try {
        switch(mode) {
            case SELECT:
                {
                    Point worldPoint = screenToWorld(event.getX(), event.getY());
                    if (bMoving) {
                        if (movingShape instanceof ReactionContainerShape) {
                            bMoving = false;
                            return;
                        }
                        List<Shape> selectedShapes = getReactionCartoon().getSelectedShapes();
                        // constrain to stay within the corresponding parent for the
                        // "movingShape" as well as all other selected (hence
                        // moving) shapes.
                        Point movingParentLoc = movingShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension movingParentSize = movingShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(movingOffsetWorld.x + movingParentLoc.x, Math.min(movingOffsetWorld.x + movingParentLoc.x + movingParentSize.width - movingShape.getSpaceManager().getSize().width, worldPoint.x));
                        worldPoint.y = Math.max(movingOffsetWorld.y + movingParentLoc.y, Math.min(movingOffsetWorld.x + movingParentLoc.y + movingParentSize.height - movingShape.getSpaceManager().getSize().height, worldPoint.y));
                        for (Shape shape : selectedShapes) {
                            if (shape != movingShape) {
                                Point selectedParentLoc = shape.getParent().getSpaceManager().getAbsLoc();
                                Dimension selectedParentSize = shape.getParent().getSpaceManager().getSize();
                                int selectedMovingOffsetX = movingOffsetWorld.x + (movingShape.getSpaceManager().getAbsLoc().x - shape.getSpaceManager().getAbsLoc().x);
                                int selectedMovingOffsetY = movingOffsetWorld.y + (movingShape.getSpaceManager().getAbsLoc().y - shape.getSpaceManager().getAbsLoc().y);
                                worldPoint.x = Math.max(selectedMovingOffsetX + selectedParentLoc.x, Math.min(selectedMovingOffsetX + selectedParentLoc.x + selectedParentSize.width - shape.getSpaceManager().getSize().width, worldPoint.x));
                                worldPoint.y = Math.max(selectedMovingOffsetY + selectedParentLoc.y, Math.min(selectedMovingOffsetY + selectedParentLoc.y + selectedParentSize.height - shape.getSpaceManager().getSize().height, worldPoint.y));
                            }
                        }
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        Point newMovingPoint = new Point(worldPoint.x - movingOffsetWorld.x, worldPoint.y - movingOffsetWorld.y);
                        int deltaX = newMovingPoint.x - movingPointWorld.x;
                        int deltaY = newMovingPoint.y - movingPointWorld.y;
                        movingPointWorld = newMovingPoint;
                        movingShape.getSpaceManager().setRelPos(movingPointWorld.x - movingParentLoc.x, movingPointWorld.y - movingParentLoc.y);
                        // them also
                        for (Shape shape : selectedShapes) {
                            if (shape != movingShape) {
                                shape.getSpaceManager().move(deltaX, deltaY);
                            }
                        }
                        getGraphPane().invalidate();
                        ((JViewport) getGraphPane().getParent()).revalidate();
                        getGraphPane().repaint();
                    } else if (bRectStretch) {
                        // constain to stay within parent
                        Point parentLoc = rectShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension parentSize = rectShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(1, Math.min(parentSize.width - 1, worldPoint.x - parentLoc.x)) + parentLoc.x;
                        worldPoint.y = Math.max(1, Math.min(parentSize.height - 1, worldPoint.y - parentLoc.y)) + parentLoc.y;
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        // getGraphPane().repaint();
                        Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                        AffineTransform oldTransform = g.getTransform();
                        g.scale(0.01 * getReactionCartoon().getZoomPercent(), 0.01 * getReactionCartoon().getZoomPercent());
                        g.setXORMode(Color.white);
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        endPointWorld = worldPoint;
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        g.setTransform(oldTransform);
                    } else {
                        Shape shape = (getGraphModel().getSelectedShape() != null ? getGraphModel().getSelectedShape() : getReactionCartoon().pickWorld(worldPoint));
                        if (!bCntrl && !bShift && (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || shape instanceof RuleParticipantSignatureDiagramShape || shape instanceof ReactionRuleDiagramShape)) {
                            bMoving = true;
                            movingShape = shape;
                            movingPointWorld = shape.getSpaceManager().getAbsLoc();
                            movingOffsetWorld = new Point(worldPoint.x - movingPointWorld.x, worldPoint.y - movingPointWorld.y);
                        } else if (shape instanceof ReactionContainerShape || bShift || bCntrl) {
                            if (rectShape == null) {
                                return;
                            }
                            if (startPointWorld != null && worldPoint != null && startPointWorld.equals(worldPoint)) {
                                // Don't start stretching until mouse moves at least 1 from startpoint
                                return;
                            }
                            bRectStretch = true;
                            endPointWorld = new Point((startPointWorld != null ? startPointWorld.x : worldPoint.x), (startPointWorld != null ? startPointWorld.y : worldPoint.y));
                            rectShape.setEnd(endPointWorld);
                            if (!(shape instanceof ReactionContainerShape)) {
                                shape.getParent().addChildShape(rectShape);
                            } else {
                                shape.addChildShape(rectShape);
                            }
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(0.01 * getReactionCartoon().getZoomPercent(), 0.01 * getReactionCartoon().getZoomPercent());
                            g.setXORMode(Color.white);
                            rectShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        }
                    }
                    break;
                }
            case LINE:
            case LINEDIRECTED:
            case LINECATALYST:
                {
                    int x = event.getX();
                    int y = event.getY();
                    Point worldPoint = new Point((int) (x * 100.0 / getReactionCartoon().getZoomPercent()), (int) (y * 100.0 / getReactionCartoon().getZoomPercent()));
                    if (bLineStretch) {
                        // repaint last location with XOR
                        Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                        g.setXORMode(Color.white);
                        edgeShape.setEnd(endPointWorld);
                        AffineTransform oldTransform = g.getTransform();
                        g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
                        edgeShape.paint_NoAntiAlias(g, 0, 0);
                        g.setTransform(oldTransform);
                        // set label and color for line depending on attachment area on ReactionStepShape
                        LineType lineType;
                        if (Mode.LINE.equals(mode)) {
                            SpeciesContext speciesContext = (SpeciesContext) edgeShape.getStartShape().getModelObject();
                            lineType = getLineTypeFromAttachment(speciesContext, worldPoint);
                        } else if (Mode.LINECATALYST.equals(mode)) {
                            lineType = LineType.CATALYST;
                        } else if (edgeShape.getStartShape() instanceof SpeciesContextShape) {
                            lineType = LineType.REACTANT;
                        } else {
                            lineType = LineType.PRODUCT;
                        }
                        edgeShape.setLabel(lineType.getLabel());
                        edgeShape.setForgroundColor(lineType.getColor());
                        getGraphPane().setCursor(lineType.getCursor());
                        // move line and paint with XOR
                        endPointWorld = worldPoint;
                        edgeShape.setEnd(worldPoint);
                        oldTransform = g.getTransform();
                        g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
                        edgeShape.paint_NoAntiAlias(g, 0, 0);
                        g.setTransform(oldTransform);
                    } else {
                        if (edgeShape != null) {
                            return;
                        }
                        if (startShape instanceof SpeciesContextShape || ((Mode.LINEDIRECTED.equals(mode) || Mode.LINECATALYST.equals(mode)) && startShape instanceof ElipseShape)) {
                            ElipseShape startElipseShape = (ElipseShape) startShape;
                            bLineStretch = true;
                            endPointWorld = worldPoint;
                            edgeShape = new RubberBandEdgeShape(startElipseShape, null, getReactionCartoon());
                            edgeShape.setEnd(worldPoint);
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            g.setXORMode(Color.white);
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
                            edgeShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        } else if ((Mode.LINEDIRECTED.equals(mode) || Mode.LINECATALYST.equals(mode)) && startShape instanceof ContainerShape) {
                            bLineStretch = true;
                            endPointWorld = worldPoint;
                            edgeShape = new RubberBandEdgeShape((ElipseShape) null, null, getReactionCartoon());
                            edgeShape.setStart(startPointWorld);
                            edgeShape.setEnd(worldPoint);
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            g.setXORMode(Color.white);
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(getReactionCartoon().getZoomPercent() * 0.01, getReactionCartoon().getZoomPercent() * 0.01);
                            edgeShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        }
                    }
                    break;
                }
            default:
                {
                    break;
                }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseDragged: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) Point(java.awt.Point) Dimension(java.awt.Dimension) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) Graphics2D(java.awt.Graphics2D) ContainerShape(cbit.gui.graph.ContainerShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) List(java.util.List) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ElipseShape(cbit.gui.graph.ElipseShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape)

Example 3 with ContainerShape

use of cbit.gui.graph.ContainerShape in project vcell by virtualcell.

the class WorkflowCartoonTool method selectEventFromWorld.

private void selectEventFromWorld(Rectangle rect, boolean bShift, boolean bCntrl) {
    if (!bShift && !bCntrl) {
        getGraphModel().clearSelection();
        List<Shape> shapes = getGraphModel().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                getGraphModel().selectShape(shape);
            }
        }
    } else if (bShift) {
        if (getGraphModel().getSelectedShape() instanceof ContainerShape) {
            getGraphModel().clearSelection();
        }
        List<Shape> shapes = getGraphModel().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                getGraphModel().selectShape(shape);
            }
        }
    } else if (bCntrl) {
        if (getGraphModel().getSelectedShape() instanceof ContainerShape) {
            getGraphModel().clearSelection();
        }
        List<Shape> shapes = getGraphModel().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                if (shape.isSelected()) {
                    getGraphModel().deselectShape(shape);
                } else {
                    getGraphModel().selectShape(shape);
                }
            }
        }
    }
}
Also used : RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) NodeShape(cbit.gui.graph.NodeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) ContainerShape(cbit.gui.graph.ContainerShape) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ContainerShape

use of cbit.gui.graph.ContainerShape in project vcell by virtualcell.

the class WorkflowCartoonTool method mouseDragged.

@Override
public void mouseDragged(java.awt.event.MouseEvent event) {
    if ((event.getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        return;
    }
    boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
    boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
    // 
    try {
        switch(mode) {
            case SELECT:
                {
                    Point worldPoint = screenToWorld(event.getX(), event.getY());
                    if (bMoving) {
                        List<Shape> selectedShapes = getGraphModel().getSelectedShapes();
                        // constrain to stay within the corresponding parent for the
                        // "movingShape" as well as all other selected (hence
                        // moving) shapes.
                        Point movingParentLoc = movingShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension movingParentSize = movingShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(movingOffsetWorld.x + movingParentLoc.x, Math.min(movingOffsetWorld.x + movingParentLoc.x + movingParentSize.width - movingShape.getSpaceManager().getSize().width, worldPoint.x));
                        worldPoint.y = Math.max(movingOffsetWorld.y + movingParentLoc.y, Math.min(movingOffsetWorld.x + movingParentLoc.y + movingParentSize.height - movingShape.getSpaceManager().getSize().height, worldPoint.y));
                        for (Shape selectedShape : selectedShapes) {
                            if (selectedShape != movingShape) {
                                Point selectedParentLoc = selectedShape.getParent().getSpaceManager().getAbsLoc();
                                Dimension selectedParentSize = selectedShape.getParent().getSpaceManager().getSize();
                                int selectedMovingOffsetX = movingOffsetWorld.x + (movingShape.getSpaceManager().getAbsLoc().x - selectedShape.getSpaceManager().getAbsLoc().x);
                                int selectedMovingOffsetY = movingOffsetWorld.y + (movingShape.getSpaceManager().getAbsLoc().y - selectedShape.getSpaceManager().getAbsLoc().y);
                                worldPoint.x = Math.max(selectedMovingOffsetX + selectedParentLoc.x, Math.min(selectedMovingOffsetX + selectedParentLoc.x + selectedParentSize.width - selectedShape.getSpaceManager().getSize().width, worldPoint.x));
                                worldPoint.y = Math.max(selectedMovingOffsetY + selectedParentLoc.y, Math.min(selectedMovingOffsetY + selectedParentLoc.y + selectedParentSize.height - selectedShape.getSpaceManager().getSize().height, worldPoint.y));
                            }
                        }
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        Point newMovingPoint = new Point(worldPoint.x - movingOffsetWorld.x, worldPoint.y - movingOffsetWorld.y);
                        int deltaX = newMovingPoint.x - movingPointWorld.x;
                        int deltaY = newMovingPoint.y - movingPointWorld.y;
                        movingPointWorld = newMovingPoint;
                        movingShape.getSpaceManager().setRelPos(movingPointWorld.x - movingParentLoc.x, movingPointWorld.y - movingParentLoc.y);
                        // them also
                        if (selectedShapes != null) {
                            for (Shape selectedShape : selectedShapes) {
                                if (selectedShape != movingShape) {
                                    selectedShape.getSpaceManager().move(deltaX, deltaY);
                                }
                            }
                        }
                        getGraphPane().invalidate();
                        ((JViewport) getGraphPane().getParent()).revalidate();
                        getGraphPane().repaint();
                    } else if (bRectStretch) {
                        // constain to stay within parent
                        Point parentLoc = rectShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension parentSize = rectShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(1, Math.min(parentSize.width - 1, worldPoint.x - parentLoc.x)) + parentLoc.x;
                        worldPoint.y = Math.max(1, Math.min(parentSize.height - 1, worldPoint.y - parentLoc.y)) + parentLoc.y;
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        // getGraphPane().repaint();
                        Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                        java.awt.geom.AffineTransform oldTransform = g.getTransform();
                        g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                        g.setXORMode(Color.white);
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        endPointWorld = worldPoint;
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        g.setTransform(oldTransform);
                    } else {
                        Shape shape = (getGraphModel().getSelectedShape() != null ? getGraphModel().getSelectedShape() : getGraphModel().pickWorld(worldPoint));
                        if (!bCntrl && !bShift && (ShapeUtil.isMovable(shape))) {
                            bMoving = true;
                            movingShape = shape;
                            movingPointWorld = shape.getSpaceManager().getAbsLoc();
                            movingOffsetWorld = new Point(worldPoint.x - movingPointWorld.x, worldPoint.y - movingPointWorld.y);
                        } else if (shape instanceof ContainerShape || bShift || bCntrl) {
                            bRectStretch = true;
                            endPointWorld = new Point(worldPoint.x + 1, worldPoint.y + 1);
                            rectShape = new RubberBandRectShape(worldPoint, endPointWorld, getGraphModel());
                            rectShape.setEnd(endPointWorld);
                            if (!(shape instanceof ContainerShape)) {
                                shape.getParent().addChildShape(rectShape);
                            } else {
                                shape.addChildShape(rectShape);
                            }
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                            g.setXORMode(Color.white);
                            rectShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        }
                    }
                    break;
                }
            default:
                {
                    break;
                }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseDragged: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) NodeShape(cbit.gui.graph.NodeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) Point(java.awt.Point) Dimension(java.awt.Dimension) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D) ContainerShape(cbit.gui.graph.ContainerShape) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ContainerShape

use of cbit.gui.graph.ContainerShape in project vcell by virtualcell.

the class WorkflowGraphModel method refreshAll.

/**
 * Insert the method's description here.
 * Creation date: (7/8/2003 9:11:57 AM)
 */
@Override
public void refreshAll() {
    clearAllShapes();
    if (getWorkflow() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    ContainerShape containerShape = new SimpleContainerShape(new Object(), this, "workflow-container");
    addShape(containerShape);
    // 
    for (Task task : getWorkflow().getTasks()) {
        TaskShape taskShape = new TaskShape(task, this);
        containerShape.addChildShape(taskShape);
        addShape(taskShape);
        // 
        for (DataOutput<? extends Object> output : task.getOutputs()) {
            if (!output.getName().equals("displayed")) {
                DataHolderShape dataHolderShape = new DataHolderShape(output, this);
                containerShape.addChildShape(dataHolderShape);
                addShape(dataHolderShape);
                WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape(task.getName() + ":" + output.getName(), taskShape, dataHolderShape, this, true, false);
                containerShape.addChildShape(workflowEdgeShape);
                addShape(workflowEdgeShape);
            }
        }
    // //
    // // add a DataInputShape for each input and connect to TaskShape with an edge
    // //
    // for (DataInput<? extends Object> input : task.getInputs()){
    // DataInputShape dataInputShape = new DataInputShape(input,this);
    // containerShape.addChildShape(dataInputShape);
    // addShape(dataInputShape);
    // 
    // WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape("input:"+task.getName()+":"+input.name,dataInputShape, taskShape, this, true, false);
    // containerShape.addChildShape(workflowEdgeShape);
    // addShape(workflowEdgeShape);
    // }
    }
    // 
    for (Task task : getWorkflow().getTasks()) {
        for (DataInput<? extends Object> input : task.getInputs()) {
            DataObject<? extends Object> source = getWorkflow().getConnectorSource(input);
            if (source instanceof DataOutput) {
                DataHolderShape dataHolderShape = (DataHolderShape) getShapeFromModelObject(source);
                TaskShape taskShape = (TaskShape) getShapeFromModelObject(task);
                WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape("connection:" + input.getName(), dataHolderShape, taskShape, this, true, false);
                containerShape.addChildShape(workflowEdgeShape);
                addShape(workflowEdgeShape);
            }
        }
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : DataOutput(org.vcell.workflow.DataOutput) Task(org.vcell.workflow.Task) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) DataObject(org.vcell.workflow.DataObject) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape)

Aggregations

ContainerShape (cbit.gui.graph.ContainerShape)5 Shape (cbit.gui.graph.Shape)4 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EdgeShape (cbit.gui.graph.EdgeShape)2 GraphEvent (cbit.gui.graph.GraphEvent)2 NodeShape (cbit.gui.graph.NodeShape)2 SimpleContainerShape (cbit.gui.graph.SimpleContainerShape)2 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 Point (java.awt.Point)2 AffineTransform (java.awt.geom.AffineTransform)2 ElipseShape (cbit.gui.graph.ElipseShape)1 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)1 GeneralConstraint (cbit.vcell.constraints.GeneralConstraint)1 SimpleBounds (cbit.vcell.constraints.SimpleBounds)1 CatalystShape (cbit.vcell.graph.CatalystShape)1 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)1 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)1