Search in sources :

Example 21 with Shape

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

the class ReactionCartoonTool method positionShapeForObject.

protected void positionShapeForObject(Structure structure, Object object, Point pos) {
    Shape structureShape = getReactionCartoon().getShapeFromModelObject(structure);
    Shape shape = getReactionCartoon().getShapeFromModelObject(object);
    if (shape != null) {
        if (structureShape != null) {
            Rectangle boundary = getReactionCartoon().getContainerLayout().getBoundaryForAutomaticLayout(structureShape);
            shape.getSpaceManager().setAbsLoc(pos);
            int xMax = boundary.x + boundary.width - shape.getWidth();
            if (shape.getAbsX() < boundary.x) {
                shape.setAbsX(boundary.x);
            } else if (shape.getAbsX() > xMax) {
                shape.setAbsX(xMax);
            }
            int yMax = boundary.y + boundary.height - shape.getHeight();
            if (shape.getAbsY() < boundary.y) {
                shape.setAbsY(boundary.y);
            } else if (shape.getAbsY() > yMax) {
                shape.setAbsY(yMax);
            }
        } else {
            shape.getSpaceManager().setAbsLoc(pos);
        }
    }
}
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) Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 22 with Shape

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

the class ReactionCartoonTool method getLineTypeFromAttachment.

private LineType getLineTypeFromAttachment(SpeciesContext speciesContext, Point worldPoint) throws Exception {
    Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
    if (mouseOverShape instanceof ReactionStepShape) {
        // check if the ReactionStep already has a ReactionParticipant for
        // this SpeciesContext
        ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
        ReactionParticipant[] rps = reactionStep.getReactionParticipants();
        if (mouseOverShape instanceof SimpleReactionShape) {
            switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
                case Shape.ATTACH_LEFT:
                    {
                        for (int i = 0; i < rps.length; i++) {
                            if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.REACTANT;
                    }
                case Shape.ATTACH_CENTER:
                    {
                        for (int i = 0; i < rps.length; i++) {
                            if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.CATALYST;
                    }
                case Shape.ATTACH_RIGHT:
                    {
                        for (int i = 0; i < rps.length; i++) {
                            if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.PRODUCT;
                    }
            }
        } else if (mouseOverShape instanceof FluxReactionShape) {
            switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
                case Shape.ATTACH_LEFT:
                    {
                        // return LineType.FLUX;
                        for (int i = 0; i < rps.length; i++) {
                            if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.REACTANT;
                    }
                case Shape.ATTACH_CENTER:
                    {
                        for (int i = 0; i < rps.length; i++) {
                            if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.CATALYST;
                    }
                case Shape.ATTACH_RIGHT:
                    {
                        for (int i = 0; i < rps.length; i++) {
                            // return LineType.FLUX;
                            if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
                                return LineType.NULL;
                            }
                        }
                        return LineType.PRODUCT;
                    }
            }
        }
    }
    return LineType.NULL;
}
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) ReactionStep(cbit.vcell.model.ReactionStep) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) Product(cbit.vcell.model.Product) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant) Catalyst(cbit.vcell.model.Catalyst) Point(java.awt.Point) FluxReactionShape(cbit.vcell.graph.FluxReactionShape)

Example 23 with Shape

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

the class ReactionCartoonTool method detailsDeleteSpecies.

private static DeleteSpeciesInfo detailsDeleteSpecies(Component requester, SpeciesContext[] speciesContextArr, ReactionStep[] toBeDeletedReactStepArr, ReactionCartoon rxCartoon) throws Exception, UserCancelException {
    if (speciesContextArr == null || speciesContextArr.length == 0) {
        return null;
    }
    // Warn user that there may be some BioModel components that reference speciesContext to be removed
    // Get ReactionParticipant list
    Collection<Shape> rxPartColl = rxCartoon.getShapes();
    HashMap<SpeciesContext, HashSet<ReactionParticipant>> rxPartHashMap = new HashMap<SpeciesContext, HashSet<ReactionParticipant>>();
    for (Shape objShape : rxPartColl) {
        if (objShape instanceof ReactionParticipantShape) {
            ReactionParticipant objReactionParticipant = ((ReactionParticipantShape) objShape).getReactionParticipant();
            if (Arrays.asList(speciesContextArr).contains(objReactionParticipant.getSpeciesContext())) {
                if (!rxPartHashMap.containsKey(objReactionParticipant.getSpeciesContext())) {
                    rxPartHashMap.put(objReactionParticipant.getSpeciesContext(), new HashSet<ReactionParticipant>());
                }
                if (!rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).contains(objReactionParticipant)) {
                    rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).add(objReactionParticipant);
                }
            }
        }
    }
    int reactionParticipantCount = 0;
    for (HashSet<ReactionParticipant> objReactPart : rxPartHashMap.values()) {
        reactionParticipantCount += objReactPart.size();
    }
    // find bioModel and get SymbolTable references to SpeciesContext
    BioModelEditor bioModelEditor = (BioModelEditor) BeanUtils.findTypeParentOfComponent(requester, BioModelEditor.class);
    if (bioModelEditor == null) {
        throw new Exception("Error deleting Speciescontext, Can't find BiomodelEditor");
    }
    BioModel bioModel = bioModelEditor.getBioModelWindowManager().getVCDocument();
    HashMap<SpeciesContext, HashSet<SymbolTableEntry>> referencingSymbolsHashMap = new HashMap<SpeciesContext, HashSet<SymbolTableEntry>>();
    for (int i = 0; i < speciesContextArr.length; i++) {
        List<SymbolTableEntry> referencingSymbolsList = bioModel.findReferences(speciesContextArr[i]);
        if (referencingSymbolsList != null && referencingSymbolsList.size() > 0) {
            if (!referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
                referencingSymbolsHashMap.put(speciesContextArr[i], new HashSet<SymbolTableEntry>());
            }
            referencingSymbolsHashMap.get(speciesContextArr[i]).addAll(referencingSymbolsList);
        }
    }
    int referencingSymbolsCount = 0;
    for (HashSet<SymbolTableEntry> objSimTableEntry : referencingSymbolsHashMap.values()) {
        referencingSymbolsCount += objSimTableEntry.size();
    }
    // Warn user about delete
    HashMap<SpeciesContext, Boolean> bUnresolvableHashMap = new HashMap<SpeciesContext, Boolean>();
    for (int i = 0; i < speciesContextArr.length; i++) {
        bUnresolvableHashMap.put(speciesContextArr[i], Boolean.FALSE);
    }
    String[][] rowData = null;
    if (rxPartHashMap.size() == 0 && referencingSymbolsHashMap.size() == 0) {
        rowData = new String[speciesContextArr.length][4];
        for (int i = 0; i < speciesContextArr.length; i++) {
            rowData[i][0] = speciesContextArr[i].getName();
            rowData[i][1] = "";
            rowData[i][2] = "";
            rowData[i][3] = "";
        }
        Arrays.sort(rowData, new Comparator<String[]>() {

            @Override
            public int compare(String[] o1, String[] o2) {
                return o1[0].compareToIgnoreCase(o2[0]);
            }
        });
    } else {
        // find SpeciesContext that had no reference warnings
        Vector<SpeciesContext> speciesContextNoReferences = new Vector<SpeciesContext>();
        for (int i = 0; i < speciesContextArr.length; i++) {
            if (!rxPartHashMap.containsKey(speciesContextArr[i]) && !referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
                speciesContextNoReferences.add(speciesContextArr[i]);
            }
        }
        rowData = new String[reactionParticipantCount + referencingSymbolsCount + speciesContextNoReferences.size()][4];
        int count = 0;
        for (SpeciesContext objSpeciesContext : speciesContextNoReferences) {
            rowData[count][0] = objSpeciesContext.getName();
            rowData[count][1] = "";
            rowData[count][2] = "";
            rowData[count][3] = "";
            count++;
        }
        for (SpeciesContext objSpeciesContext : rxPartHashMap.keySet()) {
            Iterator<ReactionParticipant> iterRxPart = rxPartHashMap.get(objSpeciesContext).iterator();
            while (iterRxPart.hasNext()) {
                rowData[count][0] = objSpeciesContext.getName();
                rowData[count][1] = "";
                rowData[count][2] = "Reaction Diagram stoichiometry '" + iterRxPart.next().getReactionStep().getName() + "'";
                rowData[count][3] = "";
                count++;
            }
        }
        for (SpeciesContext objSpeciesContext : referencingSymbolsHashMap.keySet()) {
            Iterator<SymbolTableEntry> iterSymbolTableEntry = referencingSymbolsHashMap.get(objSpeciesContext).iterator();
            while (iterSymbolTableEntry.hasNext()) {
                rowData[count][0] = objSpeciesContext.getName();
                rowData[count][1] = "";
                SymbolTableEntry objSymbolTableEntry = iterSymbolTableEntry.next();
                boolean bKineticsParameter = objSymbolTableEntry instanceof KineticsParameter;
                if (bKineticsParameter) {
                    KineticsParameter kp = (KineticsParameter) objSymbolTableEntry;
                    boolean isOK = kp.isRegenerated();
                    for (int i = 0; toBeDeletedReactStepArr != null && i < toBeDeletedReactStepArr.length; i++) {
                        if (toBeDeletedReactStepArr[i] == kp.getKinetics().getReactionStep()) {
                            // OK to delete this Speciescontext if were deleting the reaction that contained the reference
                            isOK = true;
                        }
                    }
                    rowData[count][1] = (isOK ? "" : RXSPECIES_ERROR);
                    bUnresolvableHashMap.put(objSpeciesContext, bUnresolvableHashMap.get(objSpeciesContext) || !isOK);
                }
                boolean bReaction = objSymbolTableEntry.getNameScope() instanceof ReactionNameScope;
                rowData[count][2] = (bReaction ? "Reaction" : objSymbolTableEntry.getNameScope().getClass().getName()) + "( " + objSymbolTableEntry.getNameScope().getName() + " )";
                rowData[count][3] = (bKineticsParameter ? "Parameter" : objSymbolTableEntry.getClass().getName()) + "( " + objSymbolTableEntry.getName() + " )";
                count++;
            }
        }
        // for (SymbolTableEntry referencingSTE : referencingSymbols) {
        // System.out.println("REFERENCE   "+referencingSTE.getClass().getName()+"("+referencingSTE.getName()+") nameScope "+referencingSTE.getNameScope().getClass().getName()+"("+referencingSTE.getNameScope().getName()+")");
        // }
        Arrays.sort(rowData, new Comparator<String[]>() {

            @Override
            public int compare(String[] o1, String[] o2) {
                return o1[0].compareToIgnoreCase(o2[0]);
            }
        });
    }
    if (rowData == null || rowData.length == 0) {
        return null;
    }
    return new DeleteSpeciesInfo(rxPartHashMap, bUnresolvableHashMap, rowData);
}
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) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) BioModelEditor(cbit.vcell.client.desktop.biomodel.BioModelEditor) Vector(java.util.Vector) ReactionNameScope(cbit.vcell.model.ReactionStep.ReactionNameScope) HashSet(java.util.HashSet) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) BioModel(cbit.vcell.biomodel.BioModel) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 24 with Shape

use of cbit.gui.graph.Shape 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 25 with Shape

use of cbit.gui.graph.Shape 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

Shape (cbit.gui.graph.Shape)57 Point (java.awt.Point)30 ContainerShape (cbit.gui.graph.ContainerShape)21 EdgeShape (cbit.gui.graph.EdgeShape)20 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)20 ArrayList (java.util.ArrayList)15 ElipseShape (cbit.gui.graph.ElipseShape)14 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)14 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)14 CatalystShape (cbit.vcell.graph.CatalystShape)13 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)13 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)13 ProductShape (cbit.vcell.graph.ProductShape)13 ReactantShape (cbit.vcell.graph.ReactantShape)13 ReactionParticipantShape (cbit.vcell.graph.ReactionParticipantShape)13 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)13 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)13 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)13 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)13 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)13