Search in sources :

Example 11 with ReactionContainerShape

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

the class ReactionCartoonTool method shapeHasMenuAction.

@Override
public boolean shapeHasMenuAction(Shape shape, String menuAction) {
    if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
        if (shape instanceof ReactionStepShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
        if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants don't make sense without their rule
        shape instanceof RuleParticipantSignatureDiagramShape || shape instanceof ReactionRuleDiagramShape) {
            return true;
        }
    }
    if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
				|| */
    menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape || shape instanceof ReactionStepShape || shape instanceof SpeciesContextShape || shape instanceof ReactantShape || shape instanceof ProductShape || shape instanceof CatalystShape || shape instanceof ReactionRuleDiagramShape || shape instanceof RuleParticipantSignatureDiagramShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            return true;
        }
    }
    if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
        if (shape instanceof ReactionStepShape || shape instanceof SpeciesContextShape || shape instanceof ReactantShape || shape instanceof ProductShape || shape instanceof CatalystShape || shape instanceof ReactionContainerShape) {
            return true;
        }
    }
    GraphViewAction paintingAction = ActionUtil.getAction(paintingActions, menuAction);
    if (paintingAction != null) {
        return paintingAction.canBeAppliedToShape(shape);
    }
    GraphViewAction groupAction = ActionUtil.getAction(groupActions, menuAction);
    if (groupAction != null) {
        return groupAction.canBeAppliedToShape(shape);
    }
    return false;
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ProductShape(cbit.vcell.graph.ProductShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) ReactantShape(cbit.vcell.graph.ReactantShape) GraphViewAction(cbit.gui.graph.actions.GraphViewAction) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape)

Example 12 with ReactionContainerShape

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

the class ReactionCartoonTool method updateRXContainerDropTargetInfoMap.

private HashMap<RXContainerDropTargetInfo, Boolean> updateRXContainerDropTargetInfoMap(Point pointWorld) {
    HashMap<RXContainerDropTargetInfo, Boolean> rxContainerDropTargetInfoMap = null;
    if (rxContainerDropTargetInfoMap == null) {
        // System.out.println("-----redoing map...");
        AllStructureSuite allStructureSuite = (getReactionCartoon().getStructureSuite() instanceof AllStructureSuite ? (AllStructureSuite) getReactionCartoon().getStructureSuite() : null);
        if (allStructureSuite == null) {
            throw new RuntimeException("Expecting " + AllStructureSuite.class.getName());
        }
        rxContainerDropTargetInfoMap = new HashMap<ReactionCartoonTool.RXContainerDropTargetInfo, Boolean>();
        Structure[] originalOrderedStructArr = allStructureSuite.getStructures().toArray(new Structure[0]);
        for (int i = 0; i < originalOrderedStructArr.length; i++) {
            Shape currentRXContainerShape = getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i]);
            if (i == 0) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_BEGINNING), false);
            } else {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, (ReactionContainerShape) getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i - 1]), null), false);
            }
            if (i == (originalOrderedStructArr.length - 1)) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_END), false);
            }
        }
    }
    // System.out.println("-----Starting to update selection..."+pointWorld);
    for (RXContainerDropTargetInfo rxcContainerDropTargetInfo : rxContainerDropTargetInfoMap.keySet()) {
        if (rxcContainerDropTargetInfo.absoluteRectangle.contains(pointWorld)) {
            // System.out.println(rxcContainerDropTargetInfo.dropShape.getLabel()+" "+rxcContainerDropTargetInfo.closestNeighborShape);
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, true);
        } else {
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, false);
        }
    }
    return rxContainerDropTargetInfoMap;
}
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) Structure(cbit.vcell.model.Structure) Point(java.awt.Point)

Example 13 with ReactionContainerShape

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

the class ReactionCartoonTool method mousePressed.

@Override
public void mousePressed(MouseEvent event) {
    if (getReactionCartoon() == null) {
        return;
    }
    try {
        int eventX = event.getX();
        int eventY = event.getY();
        startPointWorld = new java.awt.Point((int) (eventX * 100.0 / getReactionCartoon().getZoomPercent()), (int) (eventY * 100.0 / getReactionCartoon().getZoomPercent()));
        startShape = getReactionCartoon().pickWorld(startPointWorld);
        if (event.isPopupTrigger()) {
            // Mac popup
            popupMenu(getReactionCartoon().getSelectedShape(), eventX, eventY);
        } else if (event.getButton() != MouseEvent.BUTTON1) {
            // this may be a win, linux popup menu gesture on mouseRELEASED, let it pass through
            return;
        } else if (mode == Mode.STRUCTURE) {
            final RXContainerDropTargetInfo selectedContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
            if (selectedContainerDropTargetInfo != null) {
                JPopupMenu jPopupMenu = new JPopupMenu();
                JMenuItem menuItem = new JMenuItem("Add Compartment");
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        addStructure(false, selectedContainerDropTargetInfo);
                    }
                });
                jPopupMenu.add(menuItem);
                menuItem = new JMenuItem("Add Membrane");
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        addStructure(true, selectedContainerDropTargetInfo);
                    }
                });
                jPopupMenu.add(menuItem);
                jPopupMenu.show(event.getComponent(), event.getX(), event.getY());
            }
        } else if (mode == Mode.SELECT) {
            // User force select
            boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
            selectEventFromWorld(startPointWorld, bShift);
            if (startShape instanceof ReactionContainerShape) {
                // setup potential compartment 'drag'
                rectShape = new RubberBandRectShape(startPointWorld, startPointWorld, getReactionCartoon());
                Rectangle labelOutlineRectangle = ((ReactionContainerShape) startShape).getLabelOutline(startShape.getAbsX(), startShape.getAbsY());
                bStartRxContainerLabel = labelOutlineRectangle.contains(startPointWorld.x, startPointWorld.y);
                if (bStartRxContainerLabel) {
                    lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(startPointWorld);
                    // popup menu or name double-click
                    if (dragStructTimer != null) {
                        dragStructTimer.stop();
                    }
                    dragStructTimer = new Timer(500, new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            activateDropTargetEnable();
                            getGraphPane().repaint();
                        }
                    });
                    dragStructTimer.setRepeats(false);
                    dragStructTimer.start();
                }
            }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mousePressed: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) ActionEvent(java.awt.event.ActionEvent) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer) JMenuItem(javax.swing.JMenuItem)

Example 14 with ReactionContainerShape

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

the class ReactionCartoonTool method resetDropTargets.

private void resetDropTargets(Boolean bDropTargetFlag, Boolean bStructureMode) {
    Structure[] structures = getModel().getStructures();
    for (int i = 0; i < structures.length; i++) {
        ((ReactionContainerShape) getGraphModel().getShapeFromModelObject(structures[i])).setDropTargetEnableLow(bDropTargetFlag, bStructureMode);
        ((ReactionContainerShape) getGraphModel().getShapeFromModelObject(structures[i])).setDropTargetEnableHigh(bDropTargetFlag, bStructureMode);
    }
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Structure(cbit.vcell.model.Structure) Point(java.awt.Point)

Example 15 with ReactionContainerShape

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

the class ReactionCartoonTool method mouseClicked.

@Override
public void mouseClicked(MouseEvent event) {
    Point screenPoint = new Point(event.getX(), event.getY());
    Point worldPoint = screenToWorld(screenPoint);
    try {
        if (event.getButton() != MouseEvent.BUTTON1) {
            return;
        }
        switch(mode) {
            case SELECT:
                {
                    if (event.getClickCount() == 2) {
                        final Shape selectedShape = getReactionCartoon().getSelectedShape();
                        if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
                            editInPlace(selectedShape, worldPoint);
                        }
                        if (selectedShape != null) {
                            menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
                        }
                    }
                    break;
                }
            case STEP:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
                            ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
                            positionShapeForObject(structure, reactionStep, worldPoint);
                            saveDiagram();
                        }
                    }
                    break;
                }
            case FLUX:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (structure instanceof Membrane) {
                            Membrane membrane = (Membrane) structure;
                            FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
                            ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
                            Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
                            frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
                            saveDiagram();
                        // setMode(SELECT_MODE);
                        } else {
                        // setMode(SELECT_MODE);
                        // throw new Exception("fluxes only applicable to membranes");
                        }
                    }
                    break;
                }
            case SPECIES:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
                        reactionCartoon.clearSelection();
                        getGraphModel().select(speciesContext);
                        positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
                        // showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
                        saveDiagram();
                    }
                }
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseClicked: uncaught exception");
        e.printStackTrace(System.out);
        Point canvasLoc = getGraphPane().getLocationOnScreen();
        canvasLoc.x += screenPoint.x;
        canvasLoc.y += screenPoint.y;
        DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
    }
}
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) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) 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) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) Structure(cbit.vcell.model.Structure)

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