Search in sources :

Example 1 with ReactionRulePatternLargeShape

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

the class ReactionRuleParticipantSignaturePropertiesPanel method initialize.

private void initialize() {
    try {
        shapePanel = new ParticipantSignatureShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (Pair<ReactionRulePatternLargeShape, ReactionRulePatternLargeShape> p : ruleShapeList) {
                    ReactionRulePatternLargeShape rp = p.one;
                    rp.paintSelf(g);
                    ReactionRulePatternLargeShape pp = p.two;
                    pp.paintSelf(g);
                }
            }
        };
        shapePanel.setLayout(new GridBagLayout());
        shapePanel.setBackground(Color.white);
        shapePanel.zoomSmaller();
        shapePanel.zoomSmaller();
        shapePanel.zoomSmaller();
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(true);
        scrollPane = new JScrollPane(shapePanel);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        JPanel optionsPanel = new JPanel();
        optionsPanel.setPreferredSize(new Dimension(140, 200));
        optionsPanel.setLayout(new GridBagLayout());
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(true);
        int gridy = 0;
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 0;
        gbc.insets = new Insets(8, 4, 4, 0);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomLargerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 0;
        gbc.insets = new Insets(8, 0, 4, 4);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomSmallerButton(), gbc);
        // apparently we don't need a fake 3rd cell to the right
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(4, 4, 4, 10);
        optionsPanel.add(new JLabel(""), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowMoleculeColorButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowNonTrivialButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowDifferencesButton(), gbc);
        getShowMoleculeColorButton().setSelected(true);
        getShowNonTrivialButton().setSelected(true);
        getShowDifferencesButton().setSelected(false);
        shapePanel.setShowMoleculeColor(getShowMoleculeColorButton().isSelected());
        shapePanel.setShowNonTrivialOnly(getShowNonTrivialButton().isSelected());
        shapePanel.setShowDifferencesOnly(getShowDifferencesButton().isSelected());
        containerOfScrollPanel = new JPanel();
        containerOfScrollPanel.setLayout(new BorderLayout());
        containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
        containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
        setLayout(new BorderLayout());
        add(containerOfScrollPanel, BorderLayout.CENTER);
        setBackground(Color.white);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Graphics(java.awt.Graphics) ParticipantSignatureShapePanel(cbit.vcell.graph.gui.ParticipantSignatureShapePanel) BorderLayout(java.awt.BorderLayout) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) Pair(org.vcell.util.Pair)

Example 2 with ReactionRulePatternLargeShape

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

the class ReactionRuleParticipantSignaturePropertiesPanel method updateShape.

private void updateShape() {
    int maxXOffset = 0;
    ruleShapeList.clear();
    // all the reactants go in one single ReactionRulePatternLargeShape, all the products the other
    int yOffset = yOffsetReactantInitial + GraphConstants.ReactionRuleParticipantDisplay_ReservedSpaceForNameOnYAxis;
    for (Map.Entry<String, ReactionRule> entry : reactionRuleMap.entrySet()) {
        ReactionRule rr = entry.getValue();
        ReactionRulePatternLargeShape reactantShape = new ReactionRulePatternLargeShape(xOffsetInitial, yOffset, -1, shapePanel, rr, true, issueManager);
        reactantShape.setWriteName(true);
        int xOffset = reactantShape.getRightEnd() + 70;
        ReactionRulePatternLargeShape productShape = new ReactionRulePatternLargeShape(xOffset, yOffset, -1, shapePanel, rr, false, issueManager);
        xOffset += productShape.getRightEnd();
        yOffset += SpeciesPatternLargeShape.defaultHeight + GraphConstants.ReactionRuleParticipantDisplay_ReservedSpaceForNameOnYAxis;
        maxXOffset = Math.max(maxXOffset, xOffset);
        Pair<ReactionRulePatternLargeShape, ReactionRulePatternLargeShape> p = new Pair<>(reactantShape, productShape);
        ruleShapeList.add(p);
    }
    int maxYOffset = Math.max(yOffsetReactantInitial + SpeciesPatternLargeShape.defaultHeight + GraphConstants.ReactionRuleParticipantDisplay_ReservedSpaceForNameOnYAxis, yOffsetReactantInitial + (SpeciesPatternLargeShape.defaultHeight + GraphConstants.ReactionRuleParticipantDisplay_ReservedSpaceForNameOnYAxis) * ruleShapeList.size());
    Dimension preferredSize = new Dimension(maxXOffset, maxYOffset);
    shapePanel.setPreferredSize(preferredSize);
    containerOfScrollPanel.repaint();
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) Dimension(java.awt.Dimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) Pair(org.vcell.util.Pair)

Example 3 with ReactionRulePatternLargeShape

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

the class ReactionRuleSpecPropertiesPanel method updateShape.

private void updateShape() {
    if (reactionRule == null) {
        return;
    }
    reactantShape = new ReactionRulePatternLargeShape(xOffsetInitial, yOffsetReactantInitial, -1, shapePanel, reactionRule, true, issueManager);
    int xOffset = reactantShape.getRightEnd() + 70;
    productShape = new ReactionRulePatternLargeShape(xOffset, yOffsetReactantInitial, -1, shapePanel, reactionRule, false, issueManager);
    xOffset += productShape.getRightEnd();
    // TODO: instead of offset+100 compute the exact width of the image
    Dimension preferredSize = new Dimension(xOffset + 40, yOffsetReactantInitial + 80);
    shapePanel.setPreferredSize(preferredSize);
    shapePanel.repaint();
}
Also used : Dimension(java.awt.Dimension) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) Point(java.awt.Point)

Example 4 with ReactionRulePatternLargeShape

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

the class ReactionRuleEditorPropertiesPanel method updateShape.

private void updateShape() {
    int maxXOffset;
    if (getViewSingleRowButton().isSelected()) {
        reactantShape = new ReactionRulePatternLargeShape(xOffsetInitial, yOffsetReactantInitial, -1, shapePanel, reactionRule, true, issueManager);
        int xOffset = reactantShape.getRightEnd() + 70;
        productShape = new ReactionRulePatternLargeShape(xOffset, yOffsetReactantInitial, -1, shapePanel, reactionRule, false, issueManager);
        xOffset += productShape.getRightEnd();
        // TODO: instead of offset+100 compute the exact width of the image
        Dimension preferredSize = new Dimension(xOffset + 90, yOffsetReactantInitial + 80 + 20);
        shapePanel.setPreferredSize(preferredSize);
    } else {
        reactantShape = new ReactionRulePatternLargeShape(xOffsetInitial, yOffsetReactantInitial, -1, shapePanel, reactionRule, true, issueManager);
        maxXOffset = Math.max(xOffsetInitial, reactantShape.getXOffset());
        productShape = new ReactionRulePatternLargeShape(xOffsetInitial, yOffsetProductInitial, -1, shapePanel, reactionRule, false, issueManager);
        maxXOffset = Math.max(maxXOffset, productShape.getXOffset());
        Dimension preferredSize = new Dimension(maxXOffset + 90, yOffsetProductInitial + 80 + 20);
        shapePanel.setPreferredSize(preferredSize);
    }
    containerOfScrollPanel.repaint();
}
Also used : Dimension(java.awt.Dimension) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) Point(java.awt.Point)

Example 5 with ReactionRulePatternLargeShape

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

the class ReactionRuleEditorPropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    final Object deepestShape = locationContext.getDeepestShape();
    final RbmObject selectedObject;
    if (deepestShape == null) {
        selectedObject = null;
        // when cursor is outside any species pattern we offer to add a new one
        System.out.println("outside");
    // popupFromShapeMenu.add(getAddSpeciesPatternFromShapeMenuItem());
    } else if (deepestShape instanceof ComponentStateLargeShape) {
        System.out.println("inside state");
        if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStatePattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularComponentLargeShape) {
        System.out.println("inside component");
        if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponentPattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularTypeLargeShape) {
        System.out.println("inside molecule");
        if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularTypePattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof SpeciesPatternLargeShape) {
        System.out.println("inside species pattern");
        if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof ReactionRulePatternLargeShape) {
        System.out.println("inside reactant line or products line");
        if (((ReactionRulePatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ReactionRulePatternLargeShape) deepestShape).getReactionRule();
        } else {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    boolean bReactantsZone = false;
    int xExtent = SpeciesPatternLargeShape.calculateXExtent(shapePanel);
    Rectangle2D reactantRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetReactantInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
    Rectangle2D productRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetProductInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
    if (locationContext.isInside(reactantRectangle)) {
        // clicked inside the reactant rectangle (above yOffsetProductInitial)
        bReactantsZone = true;
    } else if (locationContext.isInside(productRectangle)) {
        // clicked inside the product rectangle (below yOffsetProductInitial)
        bReactantsZone = false;
    } else {
        return;
    }
    // -------------------------------- reactant zone --------------------------------------------------------
    if (bReactantsZone) {
        if (selectedObject == null) {
            return;
        } else if (selectedObject instanceof ReactionRule) {
            // add reactant pattern
            JMenuItem addMenuItem = new JMenuItem("Add Reactant");
            addMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), reactionRule.getStructure()));
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(addMenuItem);
        } else if (selectedObject instanceof SpeciesPattern) {
            // delete (pattern) / specify molecule
            final SpeciesPattern sp = (SpeciesPattern) selectedObject;
            JMenuItem deleteMenuItem = new JMenuItem("Delete");
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
                        if (rp.getSpeciesPattern() == sp) {
                            reactionRule.removeReactant(rp);
                            Structure st = rp.getStructure();
                            if (reactionRule.getReactantPatterns().isEmpty()) {
                                reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), st));
                                shapePanel.repaint();
                            }
                        }
                    }
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            JMenu addMenuItem = new JMenu(VCellErrorMessages.SpecifyMolecularTypes);
            popupFromShapeMenu.add(addMenuItem);
            addMenuItem.removeAll();
            for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
                JMenuItem menuItem = new JMenuItem(mt.getName());
                Graphics gc = shapePanel.getGraphics();
                Icon icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
                menuItem.setIcon(icon);
                addMenuItem.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
                        for (MolecularComponentPattern mcp : molecularTypePattern.getComponentPatternList()) {
                            mcp.setBondType(BondType.Possible);
                        }
                        sp.addMolecularTypePattern(molecularTypePattern);
                        shapePanel.repaint();
                    }
                });
            }
            JMenu compartmentMenuItem = new JMenu("Specify structure");
            popupFromShapeMenu.add(compartmentMenuItem);
            if (sp.getMolecularTypePatterns().isEmpty()) {
                compartmentMenuItem.setEnabled(false);
            }
            compartmentMenuItem.removeAll();
            for (final Structure struct : bioModel.getModel().getStructures()) {
                JMenuItem menuItem = new JMenuItem(struct.getName());
                compartmentMenuItem.add(menuItem);
                for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                    MolecularType mt = mtp.getMolecularType();
                    if (mt.isAnchorAll()) {
                        // no restrictions (no anchor exclusion) for this molecular type
                        continue;
                    }
                    if (!mt.getAnchors().contains(struct)) {
                        // sp can't be in this struct if any of its molecules is excluded (not anchored)
                        menuItem.setEnabled(false);
                        break;
                    }
                }
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        String nameStruct = e.getActionCommand();
                        Structure struct = bioModel.getModel().getStructure(nameStruct);
                        ReactantPattern rp = reactionRule.getReactantPattern(sp);
                        rp.setStructure(struct);
                        productTreeModel.populateTree();
                        shapePanel.repaint();
                    }
                });
            }
        } else if (selectedObject instanceof MolecularTypePattern) {
            // move left / right / delete molecule / reassign match
            MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
            int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
            String moveRightMenuText = "Move <b>" + "right" + "</b>";
            moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
            JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
            Icon icon = VCellIcons.moveRightIcon;
            moveRightMenuItem.setIcon(icon);
            moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveRightMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftRight(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(moveRightMenuItem);
            String moveLeftMenuText = "Move <b>" + "left" + "</b>";
            moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
            JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
            icon = VCellIcons.moveLeftIcon;
            moveLeftMenuItem.setIcon(icon);
            moveLeftMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveLeftMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftLeft(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(moveLeftMenuItem);
            popupFromShapeMenu.add(new JSeparator());
            String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
            deleteMenuText = "<html>" + deleteMenuText + "</html>";
            JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.removeMolecularTypePattern(mtp);
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            if (mtp.hasExplicitParticipantMatch()) {
                String newKey = mtp.getParticipantMatchLabel();
                List<String> keyCandidates = new ArrayList<String>();
                List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
                List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
                for (MolecularTypePattern mtpCandidate : mtpReactantList) {
                    // we can look for indexes in any list, we should find the same
                    if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
                        keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
                    }
                }
                if (!keyCandidates.isEmpty()) {
                    JMenu reassignMatchMenuItem = new JMenu();
                    reassignMatchMenuItem.setText("Reassign match to");
                    for (int i = 0; i < keyCandidates.size(); i++) {
                        JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
                        reassignMatchMenuItem.add(menuItem);
                        menuItem.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                String oldKey = e.getActionCommand();
                                MolecularTypePattern orphanReactant = reactionRule.findMatch(oldKey, mtpReactantList);
                                mtp.setParticipantMatchLabel(oldKey);
                                orphanReactant.setParticipantMatchLabel(newKey);
                                // TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
                                // when the tree will be gone
                                reactantTreeModel.populateTree();
                                productTreeModel.populateTree();
                                shapePanel.repaint();
                                SwingUtilities.invokeLater(new Runnable() {

                                    public void run() {
                                        reactantShape.flash(oldKey);
                                        productShape.flash(oldKey);
                                    }
                                });
                            }
                        });
                    }
                    popupFromShapeMenu.add(reassignMatchMenuItem);
                }
            }
        } else if (selectedObject instanceof MolecularComponentPattern) {
            // edit bond / edit state
            manageComponentPatternFromShape(selectedObject, locationContext, reactantTreeModel, ShowWhat.ShowBond, bReactantsZone);
        } else if (selectedObject instanceof ComponentStatePattern) {
            // edit state
            MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
            manageComponentPatternFromShape(mcp, locationContext, reactantTreeModel, ShowWhat.ShowState, bReactantsZone);
        }
    // ---------------------------------------- product zone ---------------------------------------------
    } else if (!bReactantsZone) {
        if (selectedObject == null) {
            return;
        } else if (selectedObject instanceof ReactionRule) {
            // add product pattern
            JMenuItem addMenuItem = new JMenuItem("Add Product");
            addMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), reactionRule.getStructure()));
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(addMenuItem);
        } else if (selectedObject instanceof SpeciesPattern) {
            // delete (pattern) / specify molecule
            final SpeciesPattern sp = (SpeciesPattern) selectedObject;
            JMenuItem deleteMenuItem = new JMenuItem("Delete");
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    for (ProductPattern pp : reactionRule.getProductPatterns()) {
                        if (pp.getSpeciesPattern() == sp) {
                            reactionRule.removeProduct(pp);
                            Structure st = pp.getStructure();
                            if (reactionRule.getProductPatterns().isEmpty()) {
                                reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), st));
                                shapePanel.repaint();
                            }
                        }
                    }
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            JMenu addMenuItem = new JMenu(VCellErrorMessages.SpecifyMolecularTypes);
            popupFromShapeMenu.add(addMenuItem);
            addMenuItem.removeAll();
            for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
                JMenuItem menuItem = new JMenuItem(mt.getName());
                Graphics gc = shapePanel.getGraphics();
                Icon icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
                menuItem.setIcon(icon);
                addMenuItem.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
                        for (MolecularComponentPattern mcp : molecularTypePattern.getComponentPatternList()) {
                            mcp.setBondType(BondType.Possible);
                        }
                        sp.addMolecularTypePattern(molecularTypePattern);
                        shapePanel.repaint();
                    }
                });
            }
            // specify structure
            JMenu compartmentMenuItem = new JMenu("Specify structure");
            popupFromShapeMenu.add(compartmentMenuItem);
            compartmentMenuItem.removeAll();
            if (sp.getMolecularTypePatterns().isEmpty()) {
                compartmentMenuItem.setEnabled(false);
            }
            for (final Structure struct : bioModel.getModel().getStructures()) {
                JMenuItem menuItem = new JMenuItem(struct.getName());
                compartmentMenuItem.add(menuItem);
                for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                    MolecularType mt = mtp.getMolecularType();
                    if (mt.isAnchorAll()) {
                        // no restrictions for this molecular type
                        continue;
                    }
                    if (!mt.getAnchors().contains(struct)) {
                        // sp can't be in this struct if any of its molecules is excluded (not anchored)
                        menuItem.setEnabled(false);
                        break;
                    }
                }
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        String nameStruct = e.getActionCommand();
                        Structure struct = bioModel.getModel().getStructure(nameStruct);
                        ProductPattern pp = reactionRule.getProductPattern(sp);
                        pp.setStructure(struct);
                        productTreeModel.populateTree();
                        shapePanel.repaint();
                    }
                });
            }
        } else if (selectedObject instanceof MolecularTypePattern) {
            // move left / right / delete molecule / reassign match
            MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
            int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
            String moveRightMenuText = "Move <b>" + "right" + "</b>";
            moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
            JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
            Icon icon = VCellIcons.moveRightIcon;
            moveRightMenuItem.setIcon(icon);
            moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveRightMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftRight(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(moveRightMenuItem);
            String moveLeftMenuText = "Move <b>" + "left" + "</b>";
            moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
            JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
            icon = VCellIcons.moveLeftIcon;
            moveLeftMenuItem.setIcon(icon);
            moveLeftMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveLeftMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftLeft(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(moveLeftMenuItem);
            popupFromShapeMenu.add(new JSeparator());
            String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
            deleteMenuText = "<html>" + deleteMenuText + "</html>";
            JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.removeMolecularTypePattern(mtp);
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            if (mtp.hasExplicitParticipantMatch()) {
                String newKey = mtp.getParticipantMatchLabel();
                List<String> keyCandidates = new ArrayList<String>();
                List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
                List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
                for (MolecularTypePattern mtpCandidate : mtpReactantList) {
                    // we can look for indexes in any list, we should find the same
                    if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
                        keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
                    }
                }
                if (!keyCandidates.isEmpty()) {
                    JMenu reassignMatchMenuItem = new JMenu();
                    reassignMatchMenuItem.setText("Reassign match to");
                    for (int i = 0; i < keyCandidates.size(); i++) {
                        JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
                        reassignMatchMenuItem.add(menuItem);
                        menuItem.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                String oldKey = e.getActionCommand();
                                MolecularTypePattern orphanProduct = reactionRule.findMatch(oldKey, mtpProductList);
                                mtp.setParticipantMatchLabel(oldKey);
                                orphanProduct.setParticipantMatchLabel(newKey);
                                // TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
                                // when the tree will be gone
                                reactantTreeModel.populateTree();
                                productTreeModel.populateTree();
                                shapePanel.repaint();
                                SwingUtilities.invokeLater(new Runnable() {

                                    public void run() {
                                        reactantShape.flash(oldKey);
                                        productShape.flash(oldKey);
                                    }
                                });
                            }
                        });
                    }
                    popupFromShapeMenu.add(reassignMatchMenuItem);
                }
            }
        } else if (selectedObject instanceof MolecularComponentPattern) {
            // edit bond / edit state
            manageComponentPatternFromShape(selectedObject, locationContext, productTreeModel, ShowWhat.ShowBond, bReactantsZone);
        } else if (selectedObject instanceof ComponentStatePattern) {
            // edit state
            MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
            manageComponentPatternFromShape(mcp, locationContext, productTreeModel, ShowWhat.ShowState, bReactantsZone);
        }
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) List(java.util.List) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) Structure(cbit.vcell.model.Structure) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) ReactantPattern(cbit.vcell.model.ReactantPattern) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmObject(org.vcell.model.rbm.RbmObject) RbmObject(org.vcell.model.rbm.RbmObject) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) JMenu(javax.swing.JMenu)

Aggregations

ReactionRulePatternLargeShape (cbit.vcell.graph.ReactionRulePatternLargeShape)5 Dimension (java.awt.Dimension)4 Point (java.awt.Point)3 ReactionRule (cbit.vcell.model.ReactionRule)2 Graphics (java.awt.Graphics)2 Pair (org.vcell.util.Pair)2 MolecularComponentLargeShape (cbit.vcell.graph.MolecularComponentLargeShape)1 ComponentStateLargeShape (cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape)1 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)1 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)1 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)1 ParticipantSignatureShapePanel (cbit.vcell.graph.gui.ParticipantSignatureShapePanel)1 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)1 ProductPattern (cbit.vcell.model.ProductPattern)1 ReactantPattern (cbit.vcell.model.ReactantPattern)1 Structure (cbit.vcell.model.Structure)1 BorderLayout (java.awt.BorderLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1