Search in sources :

Example 1 with ReactionRuleDiagramShape

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

the class SimpleElipticalLayouter method layout.

// 
// 
// 
// protected static JungNode getOrAddInternalNode(ContainerContext cc, Node node) {
// JungNode glgNode = cc.getIntNodeMap().get(node);
// if(glgNode == null) {
// glgNode = new JungNode(node, false);	// internal
// cc.jungGraph.addVertex(glgNode);
// cc.intNodeMap.put(node, glgNode);
// double posX = node.getCenterX();
// double posY = node.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);	// TODO: here
// }
// return glgNode;
// }
// 
// // inode - internal, already dealt with
// // enode - our external candidate
// protected static JungNode getOrAddExternalNode(ContainerContext cc, Node enode, Node inode) {
// JungNode glgNode = cc.getExtNodeMap().get(enode);
// if(glgNode == null) {
// glgNode = new JungNode(enode, true);	// external
// cc.jungGraph.addVertex(glgNode);
// cc.extNodeMap.put(enode, glgNode);
// double posX = enode.getCenterX() - inode.getCenterX();
// double posY = enode.getCenterY() - inode.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);			// TODO: here
// cc.jungLayout.lock(glgNode, true);
// }
// return glgNode;
// }
// 
// protected static void getOrAddEdge(ContainerContext cc, Edge edge) {
// Node node1 = edge.getNode1();
// Node node2 = edge.getNode2();
// Container container = cc.getContainer();
// if(container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNode2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node1.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNodeExternal2 = getOrAddExternalNode(cc, node2, node1);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNodeExternal2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNodeExternal1 = getOrAddExternalNode(cc, node1, node2);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode2, glgNodeExternal1);
// cc.edgeMap.put(edge, jungEdge);
// }
// }
// }
@Override
public void layout(ContainedGraph graph) {
    for (Container container : graph.getContainers()) {
        // ContainerContext containerContext = new ContainerContext(container);
        // int edgeCount = 0;
        // ContainerContext containerContext = new ContainerContext(container);
        // DirectedSparseMultigraph<String, Number> dag = new DirectedSparseMultigraph<>();
        // Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        // Map<String, Node> speciesNodesMap = new HashMap<>();
        // ReactionContainerShape rcs = (ReactionContainerShape)container.getObject();
        // Structure structure = rcs.getStructure();
        // for(Node node : containerNodes) {
        // if(node.object instanceof SpeciesContextShape) {
        // SpeciesContextShape scs = (SpeciesContextShape)node.object;
        // SpeciesContext sc = (SpeciesContext)(scs.getModelObject());
        // dag.addVertex(sc.getName());
        // speciesNodesMap.put(sc.getName(), node);
        // }
        // }
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp1 : rs.getReactionParticipants()) {
        // for(ReactionParticipant rp2 : rs.getReactionParticipants()) {
        // if(structure == rp1.getStructure() && structure == rp2.getStructure()) {
        // if(rp1 instanceof Reactant && rp2 instanceof Product) {		// edges from reactants to products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Catalyst && rp2 instanceof Reactant) {	// edges from catalysts to reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Reactant && rp2 instanceof Reactant && rp1 != rp2) {	// edges between reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Product && rp2 instanceof Product && rp1 != rp2) {	// edges between products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // }
        // }
        // }
        // }
        // }
        // SpringLayout<String, Number> layout = new SpringLayout<String, Number>(dag);
        // layout.setSize(new Dimension((int)container.width,(int)container.height));
        // 
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // layout.setLocation(v, node.getCenterX(), node.getCenterY());
        // }
        // 
        // int step = 0;
        // while (!springIterate(layout) && step < 1000) {
        // step++;
        // }
        // 
        // // position the nodes on the new locations
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // double x = layout.getX(v);
        // double y = layout.getY(v);
        // node.setCenter(x, y);
        // }
        // 
        // // place all the reaction nodes in the center of mass of its reactants
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // int count = 0;
        // double x = 0;
        // double y = 0;
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp : rs.getReactionParticipants()) {
        // if(structure == rp.getStructure()) {
        // x += layout.getX(rp.getName());
        // y += layout.getY(rp.getName());
        // count++;
        // } else {		// reactant is in another structure
        // x += 5;		// just shift it a little
        // y += 5;
        // // TODO: make big correction as if it's far away to the left or to the right
        // // depending on the order of structures in the diagram
        // count++;
        // }
        // }
        // if(count > 0) {
        // node.setCenter(x/count, y/count);
        // }
        // }
        // }
        double centerX = container.getX() + container.getWidth() / 2;
        double centerY = container.getY() + container.getHeight() / 2;
        double quartaxisX = container.getWidth() / 3;
        double quartaxisY = container.getHeight() / 3;
        double semiaxisX = container.getWidth() / 2;
        double semiaxisY = container.getHeight() / 2;
        Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        int nNodes = containerNodes.size();
        int iNode = 0;
        for (Node node : containerNodes) {
            if (node.object instanceof SpeciesContextShape || node.object instanceof RuleParticipantSignatureDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + quartaxisX * Math.cos(angle), centerY + quartaxisY * Math.sin(angle));
            } else if (node.object instanceof ReactionStepShape || node.object instanceof ReactionRuleDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + semiaxisX * Math.cos(angle), centerY + semiaxisY * Math.sin(angle));
            }
            ++iNode;
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape)

Example 2 with ReactionRuleDiagramShape

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

the class GraphContainerLayoutReactions method getPreferedSizeReactionContainerShape.

public Dimension getPreferedSizeReactionContainerShape(ReactionContainerShape shape, Graphics2D g) {
    // get size when empty
    Font origFont = g.getFont();
    g.setFont(shape.getLabelFont(g));
    try {
        Dimension preferredSize = shape.getPreferedSizeSelf(g);
        // make larger than empty size so that children fit
        for (Shape child : shape.getChildren()) {
            if (child instanceof ReactionStepShape || child instanceof SpeciesContextShape || child instanceof RuleParticipantSignatureFullDiagramShape || child instanceof RuleParticipantSignatureShortDiagramShape || child instanceof ReactionRuleDiagramShape) {
                preferredSize.width = Math.max(preferredSize.width, child.getSpaceManager().getRelPos().x + child.getSpaceManager().getSize().width);
                preferredSize.height = Math.max(preferredSize.height, child.getSpaceManager().getRelPos().y + child.getSpaceManager().getSize().height);
            }
        }
        preferredSize.width = preferredSize.width + WIDTH_PADDING;
        preferredSize.height = preferredSize.height + HEIGHT_PADDING;
        Structure structure = shape.getStructure();
        int minWidthSum = 0;
        for (Structure structure2 : shape.getStructureSuite().getStructures()) {
            if (structure2 instanceof Feature) {
                minWidthSum += FEATURE_MIN_WIDTH;
            } else {
                minWidthSum += MEMBRANE_MIN_WIDTH;
            }
        }
        int compartmentMinWidth = 0;
        if (structure instanceof Feature) {
            compartmentMinWidth = FEATURE_MIN_WIDTH;
        } else {
            compartmentMinWidth = MEMBRANE_MIN_WIDTH;
        }
        int apportionedWidth = compartmentMinWidth * TOTAL_MIN_WIDTH / minWidthSum;
        if (preferredSize.width < compartmentMinWidth) {
            preferredSize.width = compartmentMinWidth;
        }
        if (preferredSize.width < apportionedWidth) {
            preferredSize.width = apportionedWidth;
        }
        if (preferredSize.height < MIN_HEIGHT) {
            preferredSize.height = MIN_HEIGHT;
        }
        return preferredSize;
    } finally {
        g.setFont(origFont);
    }
}
Also used : RuleParticipantSignatureShortDiagramShape(cbit.vcell.graph.RuleParticipantSignatureShortDiagramShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) RuleParticipantSignatureFullDiagramShape(cbit.vcell.graph.RuleParticipantSignatureFullDiagramShape) RuleParticipantSignatureShortDiagramShape(cbit.vcell.graph.RuleParticipantSignatureShortDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) ReactionRuleFullDiagramShape(cbit.vcell.graph.ReactionRuleFullDiagramShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RuleParticipantSignatureFullDiagramShape(cbit.vcell.graph.RuleParticipantSignatureFullDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) Dimension(java.awt.Dimension) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature) Font(java.awt.Font) Point(java.awt.Point)

Example 3 with ReactionRuleDiagramShape

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

the class ReactionCartoonTool method menuAction.

@Override
protected void menuAction(Shape shape, String menuAction) {
    if (shape == null) {
        return;
    }
    if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
        if (shape instanceof FluxReactionShape) {
        // showFluxReactionPropertiesDialog((FluxReactionShape) shape);
        } else if (shape instanceof SimpleReactionShape) {
        // showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
        } else if (shape instanceof ReactantShape) {
        // Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
        // Point graphPaneLocation = getGraphPane().getLocationOnScreen();
        // locationOnScreen.translate(graphPaneLocation.x,
        // graphPaneLocation.y);
        // showReactantPropertiesDialog((ReactantShape) shape,
        // locationOnScreen);
        } else if (shape instanceof ProductShape) {
        // Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
        // Point graphPaneLocation = getGraphPane().getLocationOnScreen();
        // locationOnScreen.translate(graphPaneLocation.x,
        // graphPaneLocation.y);
        // showProductPropertiesDialog((ProductShape) shape,
        // locationOnScreen);
        } else if (shape instanceof SpeciesContextShape) {
        // showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
        // .getModel(), ((SpeciesContextShape) shape)
        // .getSpeciesContext());
        } else if (shape instanceof ReactionContainerShape) {
        // ReactionContainerShape rcs = (ReactionContainerShape) shape;
        // if (rcs.getStructure() instanceof Feature) {
        // //
        // // showFeaturePropertyDialog is invoked in two modes:
        // //
        // // 1) parent!=null and child==null
        // // upon ok, it adds a new feature to the supplied parent.
        // //
        // // 2) parent==null and child!=null
        // // upon ok, edits the feature name
        // //
        // showFeaturePropertiesDialog(getGraphPane(),
        // (getReactionCartoon().getModel() == null ? null
        // : getReactionCartoon().getModel()), null,
        // (Feature) rcs.getStructure());
        // } else if (rcs.getStructure() instanceof Membrane) {
        // showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
        // .getStructure());
        // }
        }
    } else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            getGraphModel().deselectShape(shape);
            // showCreateSpeciesContextDialog(getGraphPane(),
            // getReactionCartoon().getModel(),
            // ((ReactionContainerShape) shape).getStructure(), null);
            SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
            getGraphModel().select(speciesContext);
        }
    } else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
        if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
        shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
        shape instanceof ReactionRuleDiagramShape) {
            SpeciesContext[] spArray = getSelectedSpeciesContextArray();
            ReactionStep[] rsArray = getSelectedReactionStepArray();
            ReactionRule[] rrArray = getSelectedReactionRuleArray();
            MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
            Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
            Structure fromStruct = null;
            ReactionContainerShape rcs = null;
            Shape parentShape = shape.getParent();
            if (parentShape instanceof ReactionContainerShape) {
                rcs = (ReactionContainerShape) parentShape;
                fromStruct = rcs.getStructure();
            }
            ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
            VCellTransferable.sendToClipboard(reactionSpeciesCopy);
        }
    } else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
				|| */
    menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            pasteReactionsAndSpecies(((ReactionContainerShape) shape).getStructure());
        }
    } else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
        try {
            if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
                getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
                return;
            }
            if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
                deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
            }
            if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
                ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
                String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
                if (response != null && response.equals(RXSPECIES_DELETE)) {
                    for (int i = 0; i < reactionParticipantArr.length; i++) {
                        ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
                        reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
                    }
                }
            }
        } catch (UserCancelException uce) {
            return;
        } catch (PropertyVetoException e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
        } catch (Exception e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
        try {
            if (shape instanceof ReactionContainerShape) {
                showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
            }
        } catch (Exception e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
        try {
            String resType = null;
            if (shape instanceof ReactionContainerShape) {
                showSaveReactionImageDialog();
            }
        } catch (Exception e) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
        if (shape instanceof ReactionStepShape) {
            // MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
            // System.out.println("Menu action annotate activated...");
            ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
            VCMetaData vcMetaData = rs.getModel().getVcMetaData();
            try {
                String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
                vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
            } catch (UtilCancelException e) {
            // Do Nothing
            } catch (Throwable exc) {
                exc.printStackTrace(System.out);
                DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
            }
        }
    } else {
    // default action is to ignore
    }
}
Also used : ReactionSpeciesCopy(cbit.vcell.model.ReactionSpeciesCopy) 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) ProductShape(cbit.vcell.graph.ProductShape) UserCancelException(org.vcell.util.UserCancelException) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactantShape(cbit.vcell.graph.ReactantShape) SpeciesContext(cbit.vcell.model.SpeciesContext) VCMetaData(cbit.vcell.biomodel.meta.VCMetaData) Structure(cbit.vcell.model.Structure) UtilCancelException(org.vcell.util.UtilCancelException) ReactionRule(cbit.vcell.model.ReactionRule) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) ReactionStep(cbit.vcell.model.ReactionStep) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 4 with ReactionRuleDiagramShape

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

use of cbit.vcell.graph.ReactionRuleDiagramShape 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)

Aggregations

ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)7 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)7 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)6 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)6 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)5 CatalystShape (cbit.vcell.graph.CatalystShape)4 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)4 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)4 ProductShape (cbit.vcell.graph.ProductShape)4 ReactantShape (cbit.vcell.graph.ReactantShape)4 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 Point (java.awt.Point)4 PropertyVetoException (java.beans.PropertyVetoException)4 UserCancelException (org.vcell.util.UserCancelException)4 UtilCancelException (org.vcell.util.UtilCancelException)4 ContainerShape (cbit.gui.graph.ContainerShape)3 ElipseShape (cbit.gui.graph.ElipseShape)3 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)3 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)3