Search in sources :

Example 6 with ReactionContainerShape

use of cbit.vcell.graph.ReactionContainerShape 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 7 with ReactionContainerShape

use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.

the class ReactionCartoonTool method shapeHasMenuActionEnabled.

@Override
public boolean shapeHasMenuActionEnabled(Shape shape, String menuAction) {
    if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
        if (shape instanceof CatalystShape) {
            return false;
        }
    }
    if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
        if (!(shape instanceof ReactionContainerShape) || !getReactionCartoon().getStructureSuite().getStructures().contains(shape.getModelObject())) {
            return false;
        }
    }
    GraphViewAction paintingAction = ActionUtil.getAction(paintingActions, menuAction);
    if (paintingAction != null) {
        return paintingAction.isEnabledForShape(shape);
    }
    GraphViewAction groupAction = ActionUtil.getAction(groupActions, menuAction);
    if (groupAction != null) {
        return groupAction.isEnabledForShape(shape);
    }
    if (shape instanceof ReactionContainerShape) {
        if (menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
            ReactionSpeciesCopy reactionSpeciesCopy = (ReactionSpeciesCopy) VCellTransferable.getFromClipboard(VCellTransferable.REACTION_SPECIES_ARRAY_FLAVOR);
            if (reactionSpeciesCopy != null) {
                Structure targetStructure = ((ReactionContainerShape) shape).getStructure();
                if (reactionSpeciesCopy.getReactStepArr() != null) {
                    for (int i = 0; i < reactionSpeciesCopy.getReactStepArr().length; i++) {
                        if (!reactionSpeciesCopy.getReactStepArr()[i].getStructure().getClass().equals(targetStructure.getClass())) {
                            return false;
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        } else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
            if (((ReactionContainerShape) shape).getStructureSuite().getStructures().size() == 1) {
                return false;
            }
        }
    }
    return true;
}
Also used : ReactionSpeciesCopy(cbit.vcell.model.ReactionSpeciesCopy) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) GraphViewAction(cbit.gui.graph.actions.GraphViewAction) Structure(cbit.vcell.model.Structure) Point(java.awt.Point)

Example 8 with ReactionContainerShape

use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.

the class ReactionCartoonTool method selectEventFromWorld.

private void selectEventFromWorld(Rectangle rect, boolean bShift, boolean bCntrl) {
    if (!bShift && !bCntrl) {
        getReactionCartoon().clearSelection();
        List<Shape> shapes = getReactionCartoon().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                getReactionCartoon().selectShape(shape);
            }
        }
    } else if (bShift) {
        if (getReactionCartoon().getSelectedShape() instanceof ReactionContainerShape) {
            getReactionCartoon().clearSelection();
        }
        List<Shape> shapes = getReactionCartoon().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                getReactionCartoon().selectShape(shape);
            }
        }
    } else if (bCntrl) {
        if (getReactionCartoon().getSelectedShape() instanceof ReactionContainerShape) {
            getReactionCartoon().clearSelection();
        }
        List<Shape> shapes = getReactionCartoon().pickWorld(rect);
        for (Shape shape : shapes) {
            if (ShapeUtil.isMovable(shape)) {
                if (shape.isSelected()) {
                    getReactionCartoon().deselectShape(shape);
                } else {
                    getReactionCartoon().selectShape(shape);
                }
            }
        }
    }
}
Also used : 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) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with ReactionContainerShape

use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.

the class ReactionCartoonTool method editInPlace.

private void editInPlace(final Shape selectedShape, Point worldPoint) {
    if (getGraphPane().getComponentCount() > 0) {
        // remove any existing editor
        getGraphPane().remove(0);
    }
    Rectangle labelOutline = null;
    // What kind of thing is being edited
    if (selectedShape instanceof ReactionContainerShape) {
        labelOutline = ((ReactionContainerShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
        if (!labelOutline.contains(worldPoint)) {
            return;
        }
    } else if (selectedShape instanceof SpeciesContextShape) {
        labelOutline = ((SpeciesContextShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof SimpleReactionShape) {
        labelOutline = ((SimpleReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof FluxReactionShape) {
        labelOutline = ((FluxReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof ReactionRuleDiagramShape) {
        labelOutline = ((ReactionRuleDiagramShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else {
        return;
    }
    // Add press 'Enter' action, 'Escape' action, editor gets focus and mouse 'Exit' parent action
    if (true) {
        final JTextField jTextField = new JTextField(selectedShape.getLabel());
        jTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    // Type specific edit actions
                    if (selectedShape instanceof ReactionContainerShape) {
                        ((ReactionContainerShape) selectedShape).getStructure().setName(jTextField.getText(), true);
                    } else if (selectedShape instanceof SpeciesContextShape) {
                        ((SpeciesContextShape) selectedShape).getSpeciesContext().setName(jTextField.getText());
                    } else if (selectedShape instanceof SimpleReactionShape) {
                        ((SimpleReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
                    } else if (selectedShape instanceof FluxReactionShape) {
                        ((FluxReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
                    } else if (selectedShape instanceof ReactionRuleDiagramShape) {
                        ((ReactionRuleDiagramShape) selectedShape).getReactionRule().setName(jTextField.getText());
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    DialogUtils.showErrorDialog(ReactionCartoonTool.this.getGraphPane(), e2.getMessage());
                }
                stopEditing();
            }
        });
        // just to be sure
        ReactionCartoonTool.this.getGraphPane().removeMouseListener(myStopEditAdapter);
        ReactionCartoonTool.this.getGraphPane().addMouseListener(myStopEditAdapter);
        getGraphModel().removeGraphListener(myGraphListener);
        getGraphModel().addGraphListener(myGraphListener);
        InputMap im = jTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        ActionMap am = jTextField.getActionMap();
        im.put(KeyStroke.getKeyStroke("ESCAPE"), "cancelChange");
        am.put("cancelChange", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                stopEditing();
            }
        });
        GraphResizeManager grm = getGraphModel().getResizeManager();
        jTextField.setBounds((int) grm.zoom(labelOutline.x), (int) grm.zoom(labelOutline.y), Math.max((int) grm.zoom(labelOutline.width + 2), 100), Math.max((int) grm.zoom(labelOutline.height + 2), 20));
        getGraphPane().add(jTextField);
        getGraphPane().validate();
        jTextField.requestFocus();
    }
    return;
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) ActionMap(javax.swing.ActionMap) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) JTextField(javax.swing.JTextField) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ActionListener(java.awt.event.ActionListener) InputMap(javax.swing.InputMap) GraphResizeManager(cbit.gui.graph.GraphResizeManager) AbstractAction(javax.swing.AbstractAction)

Example 10 with ReactionContainerShape

use of cbit.vcell.graph.ReactionContainerShape in project vcell by virtualcell.

the class ReactionCartoonTool method mouseReleased.

@Override
public void mouseReleased(MouseEvent event) {
    if (getReactionCartoon() == null) {
        return;
    }
    try {
        if (dragStructTimer != null) {
            dragStructTimer.stop();
        }
        endPointWorld = getReactionCartoon().getResizeManager().unzoom(event.getPoint());
        Shape endShape = getReactionCartoon().pickWorld(endPointWorld);
        if (event.isPopupTrigger() && mode == Mode.SELECT) {
            // win, linux popup
            popupMenu(getReactionCartoon().getSelectedShape(), event.getX(), event.getY());
            return;
        }
        if (mode == Mode.SELECT && bStartRxContainerLabel) {
            resetDropTargets(null, mode == Mode.STRUCTURE);
            if (endShape != null && endShape instanceof ReactionContainerShape) {
                Rectangle labelOutlineRectangle = ((ReactionContainerShape) endShape).getLabelOutline(endShape.getAbsX(), endShape.getAbsY());
                boolean bLabel = labelOutlineRectangle.contains(startPointWorld.x, startPointWorld.y);
                getGraphPane().setCursor((bLabel ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)));
            }
            bStartRxContainerLabel = false;
            RXContainerDropTargetInfo trueRXContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
            lastRXContainerDropTargetInfoMap = null;
            if (trueRXContainerDropTargetInfo == null) {
                // turn off rxDropTargetRectangles
                getGraphPane().repaint();
                return;
            }
            StructureSuite structureSuite = null;
            structureSuite = getReactionCartoon().getStructureSuite();
            if (structureSuite != null) {
                Structure[] originalOrderedStructArr = structureSuite.getStructures().toArray(new Structure[0]);
                // find where user wants to put the structure
                try {
                    if (trueRXContainerDropTargetInfo != null) {
                        ArrayList<Structure> newStructOrderList = new ArrayList<Structure>(Arrays.asList(originalOrderedStructArr));
                        newStructOrderList.remove(((ReactionContainerShape) startShape).getStructure());
                        int indexEnd = newStructOrderList.indexOf(((ReactionContainerShape) trueRXContainerDropTargetInfo.dropShape).getStructure());
                        int indexClosestNeighbor = (trueRXContainerDropTargetInfo.closestNeighborShape == null ? (trueRXContainerDropTargetInfo.insertFlag == RXContainerDropTargetInfo.INSERT_BEGINNING ? 0 : newStructOrderList.size()) : newStructOrderList.indexOf(((ReactionContainerShape) trueRXContainerDropTargetInfo.closestNeighborShape).getStructure()));
                        if (indexClosestNeighbor < indexEnd) {
                            newStructOrderList.add(indexEnd, ((ReactionContainerShape) startShape).getStructure());
                        } else {
                            newStructOrderList.add(indexClosestNeighbor, ((ReactionContainerShape) startShape).getStructure());
                        }
                        if (structureSuite instanceof AllStructureSuite) {
                            ((AllStructureSuite) structureSuite).setModelStructureOrder(true);
                        }
                        ArrayList<Diagram> newDiagramOrderList = new ArrayList<Diagram>();
                        for (Structure structure : newStructOrderList) {
                            newDiagramOrderList.add(getModel().getDiagram(structure));
                        }
                        getModel().setDiagrams(newDiagramOrderList.toArray(new Diagram[0]));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return;
        }
        // else do select and move
        switch(mode) {
            case SELECT:
                {
                    getGraphPane().setCursor(Cursor.getDefaultCursor());
                    if (bMoving) {
                        getGraphPane().invalidate();
                        ((JViewport) getGraphPane().getParent()).revalidate();
                        getGraphPane().repaint();
                        saveDiagram();
                    } else if (bRectStretch) {
                        Point absLoc = rectShape.getSpaceManager().getRelPos();
                        Dimension size = rectShape.getSpaceManager().getSize();
                        // remove temporary rectangle
                        getReactionCartoon().removeShape(rectShape);
                        rectShape = null;
                        Rectangle rect = new Rectangle(absLoc.x, absLoc.y, size.width, size.height);
                        boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
                        boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
                        selectEventFromWorld(rect, bShift, bCntrl);
                        getGraphPane().repaint();
                    }
                    bMoving = false;
                    movingShape = null;
                    bRectStretch = false;
                    rectShape = null;
                    break;
                }
            case LINEDIRECTED:
                {
                    getGraphPane().setCursor(Cursor.getDefaultCursor());
                    if (bLineStretch && getDragDistanceSquared() >= MIN_DRAG_DISTANCE_TO_CREATE_NEW_ELEMENTS_SQUARED) {
                        bLineStretch = false;
                        // set label and color for line depending on which shape the edge started.
                        // (rather than attachment area on ReactionStepShape)
                        LineType lineType = getLineTypeFromDirection(startShape, endPointWorld);
                        if (endShape instanceof SimpleReactionShape) {
                            SimpleReaction simpleReaction = (SimpleReaction) endShape.getModelObject();
                            Object startShapeObject = null;
                            if (startShape != null) {
                                startShapeObject = startShape.getModelObject();
                            }
                            if (startShapeObject instanceof SpeciesContext) {
                                SpeciesContext speciesContext = (SpeciesContext) startShapeObject;
                                lineAction(speciesContext, simpleReaction);
                            } else if (startShapeObject instanceof Structure) {
                                Structure structure = (Structure) startShapeObject;
                                lineActon(structure, simpleReaction);
                            }
                        } else if (endShape instanceof SpeciesContextShape) {
                            SpeciesContext speciesContextEnd = (SpeciesContext) endShape.getModelObject();
                            Object startShapeObject = null;
                            if (startShape != null) {
                                startShapeObject = startShape.getModelObject();
                            }
                            if (startShapeObject instanceof SimpleReaction) {
                                SimpleReaction simpleReaction = (SimpleReaction) startShapeObject;
                                lineAction(simpleReaction, speciesContextEnd);
                            } else if (startShapeObject instanceof FluxReaction) {
                                FluxReaction fluxReaction = (FluxReaction) startShapeObject;
                                lineAction(fluxReaction, speciesContextEnd);
                            } else if (startShapeObject instanceof SpeciesContext) {
                                SpeciesContext speciesContextStart = (SpeciesContext) startShapeObject;
                                if (!speciesContextStart.equals(speciesContextEnd)) {
                                    lineAction(speciesContextStart, speciesContextEnd);
                                }
                            } else if (startShapeObject instanceof Structure) {
                                Structure startStructure = (Structure) startShapeObject;
                                lineAction(startStructure, speciesContextEnd);
                            }
                        } else if (endShape instanceof FluxReactionShape) {
                            FluxReaction fluxReaction = (FluxReaction) endShape.getModelObject();
                            fluxReaction.setModel(getModel());
                            Object startShapeObject = null;
                            if (startShape != null) {
                                startShapeObject = startShape.getModelObject();
                            }
                            if (startShapeObject instanceof SpeciesContext) {
                                SpeciesContext speciesContext = (SpeciesContext) startShapeObject;
                                lineAction(speciesContext, fluxReaction);
                            } else if (startShapeObject instanceof Structure) {
                                Structure structure = (Structure) startShapeObject;
                                lineActon(structure, fluxReaction);
                            }
                            // remove temporary edge
                            getReactionCartoon().removeShape(edgeShape);
                            edgeShape = null;
                        } else if (endShape instanceof ReactionContainerShape) {
                            Structure endStructure = (Structure) endShape.getModelObject();
                            Object startObject = null;
                            if (startShape != null) {
                                startObject = startShape.getModelObject();
                            }
                            if (startObject instanceof SimpleReaction) {
                                SimpleReaction reaction = (SimpleReaction) startObject;
                                lineAction(reaction, endStructure);
                            } else if (startObject instanceof FluxReaction) {
                                FluxReaction reaction = (FluxReaction) startObject;
                                lineAction(reaction, endStructure);
                            } else if (startObject instanceof SpeciesContext) {
                                SpeciesContext speciesContextStart = (SpeciesContext) startObject;
                                lineAction(speciesContextStart, endStructure);
                            } else if (startObject instanceof Structure) {
                                Structure startStructure = (Structure) startObject;
                                lineAction(startStructure, endStructure, endShape);
                            }
                        }
                    }
                    saveDiagram();
                    break;
                }
            case LINECATALYST:
                {
                    getGraphPane().setCursor(Cursor.getDefaultCursor());
                    if (bLineStretch && getDragDistanceSquared() >= MIN_DRAG_DISTANCE_TO_CREATE_NEW_ELEMENTS_SQUARED) {
                        bLineStretch = false;
                        // set label and color for line depending on which shape the edge started.
                        // (rather than attachment area on ReactionStepShape)
                        Object startObject = startShape.getModelObject();
                        Object endObject = endShape.getModelObject();
                        ReactionStep reactionStep = null;
                        SpeciesContext speciesContext = null;
                        if (startObject instanceof ReactionStep) {
                            reactionStep = (ReactionStep) startObject;
                            if (endObject instanceof SpeciesContext) {
                                if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), ((SpeciesContext) endObject).getStructure())) {
                                    speciesContext = (SpeciesContext) endObject;
                                }
                            } else if (endObject instanceof Structure) {
                                Structure endStructure = (Structure) endObject;
                                if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), endStructure)) {
                                    speciesContext = getReactionCartoon().getModel().createSpeciesContext(endStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    Point endPos = edgeShape.getEnd();
                                    positionShapeForObject(endStructure, speciesContext, endPos);
                                }
                            }
                        } else if (startObject instanceof SpeciesContext) {
                            speciesContext = (SpeciesContext) startObject;
                            if (endObject instanceof ReactionStep) {
                                if (StructureUtil.reactionHereCanHaveParticipantThere(((ReactionStep) endObject).getStructure(), speciesContext.getStructure())) {
                                    reactionStep = (ReactionStep) endObject;
                                }
                            } else if (endObject instanceof Structure) {
                                Structure endStructure = (Structure) endObject;
                                if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, speciesContext.getStructure())) {
                                    reactionStep = getReactionCartoon().getModel().createSimpleReaction(endStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    Point endPos = edgeShape.getEnd();
                                    positionShapeForObject(endStructure, reactionStep, endPos);
                                }
                            }
                        } else if (startObject instanceof Structure) {
                            Structure startStructure = (Structure) startObject;
                            if (endObject instanceof ReactionStep) {
                                reactionStep = (ReactionStep) endObject;
                                if (StructureUtil.reactionHereCanHaveParticipantThere(reactionStep.getStructure(), startStructure)) {
                                    speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    positionShapeForObject(startStructure, speciesContext, startPointWorld);
                                }
                            } else if (endObject instanceof SpeciesContext) {
                                speciesContext = (SpeciesContext) endObject;
                                if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, speciesContext.getStructure())) {
                                    reactionStep = getReactionCartoon().getModel().createSimpleReaction(startStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    positionShapeForObject(startStructure, reactionStep, startPointWorld);
                                }
                            } else if (endObject instanceof Structure) {
                                Structure endStructure = (Structure) endObject;
                                if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, endStructure)) {
                                    speciesContext = getReactionCartoon().getModel().createSpeciesContext(endStructure);
                                    reactionStep = getReactionCartoon().getModel().createSimpleReaction(startStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    Point endPos = edgeShape.getEnd();
                                    positionShapeForObject(endStructure, speciesContext, endPos);
                                    positionShapeForObject(startStructure, reactionStep, startPointWorld);
                                } else if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
                                    speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
                                    reactionStep = getReactionCartoon().getModel().createSimpleReaction(endStructure);
                                    getReactionCartoon().notifyChangeEvent();
                                    positionShapeForObject(startStructure, speciesContext, startPointWorld);
                                    Point endPos = edgeShape.getEnd();
                                    positionShapeForObject(endStructure, reactionStep, endPos);
                                }
                            }
                        }
                        if (reactionStep != null && speciesContext != null) {
                            Catalyst catalyst = null;
                            for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
                                if (participant instanceof Catalyst && participant.getSpeciesContext().equals(speciesContext)) {
                                    catalyst = (Catalyst) participant;
                                }
                            }
                            if (catalyst == null) {
                                reactionStep.addCatalyst(speciesContext);
                                getReactionCartoon().notifyChangeEvent();
                            }
                        // add reactionParticipant to model
                        } else {
                            getGraphPane().repaint();
                        }
                    }
                    saveDiagram();
                    break;
                }
            default:
                {
                    break;
                }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseReleased: uncaught exception");
        e.printStackTrace(System.out);
    }
    resetMouseActionHistory();
    getGraphPane().repaint();
}
Also used : 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) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) StructureSuite(cbit.vcell.graph.structures.StructureSuite) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) Diagram(cbit.vcell.model.Diagram) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst)

Aggregations

ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)21 Point (java.awt.Point)16 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)13 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)12 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)11 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)11 CatalystShape (cbit.vcell.graph.CatalystShape)9 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)8 Shape (cbit.gui.graph.Shape)8 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)8 ProductShape (cbit.vcell.graph.ProductShape)8 ReactantShape (cbit.vcell.graph.ReactantShape)8 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)8 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)8 Structure (cbit.vcell.model.Structure)8 Dimension (java.awt.Dimension)8 ContainerShape (cbit.gui.graph.ContainerShape)7 ElipseShape (cbit.gui.graph.ElipseShape)7 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)7 ReactionParticipantShape (cbit.vcell.graph.ReactionParticipantShape)7