Search in sources :

Example 26 with MolecularComponentPattern

use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.

the class ReactionRuleEditorPropertiesPanel method reflectBondToProduct.

private void reflectBondToProduct(MolecularComponentPattern mcpReactant) {
    if (mcpReactant.getBondType() == BondType.Specified) {
        // we don't transfer to product explicit bonds
        return;
    }
    MolecularTypePattern mtpReactant = reactionRule.getReactantMoleculeOfComponent(mcpReactant);
    MolecularTypePattern mtpProduct = reactionRule.getMatchingProductMolecule(mtpReactant);
    if (mtpProduct == null) {
        return;
    }
    for (MolecularComponentPattern mcpProduct : mtpProduct.getComponentPatternList()) {
        if (mcpProduct.getMolecularComponent() != mcpReactant.getMolecularComponent()) {
            continue;
        }
        // finally we have the mcpProduct we need to modify
        if (mcpProduct.getBondType() == BondType.Specified) {
        // we don't reset an explicit bond, we assume that the user knew what he was doing
        // mcpProduct.getBond().molecularComponentPattern.setBondType(BondType.Possible);
        // mcpProduct.getBond().molecularComponentPattern.setBond(null);
        // mcpProduct.setBondType(mcpReactant.getBondType());
        // mcpProduct.setBond(null);
        } else {
            mcpProduct.setBondType(mcpReactant.getBondType());
            // bond type can be none, exist or possible
            mcpProduct.setBond(null);
        }
    }
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 27 with MolecularComponentPattern

use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.

the class SpeciesPropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    final Object deepestShape = locationContext.getDeepestShape();
    final RbmElementAbstract 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 {
            if (!fieldSpeciesContext.hasSpeciesPattern()) {
                selectedObject = new SpeciesPattern();
            } else {
                return;
            }
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    System.out.println(selectedObject);
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    if (selectedObject instanceof SpeciesPattern) {
        final SpeciesPattern sp = (SpeciesPattern) selectedObject;
        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.None);
                    }
                    if (!fieldSpeciesContext.hasSpeciesPattern()) {
                        fieldSpeciesContext.setSpeciesPattern(sp);
                    }
                    fieldSpeciesContext.getSpeciesPattern().addMolecularTypePattern(molecularTypePattern);
                }
            });
        }
    // JMenu compartmentMenuItem = new JMenu("Specify structure");
    // popupFromShapeMenu.add(compartmentMenuItem);
    // compartmentMenuItem.removeAll();
    // for (final Structure struct : bioModel.getModel().getStructures()) {
    // JMenuItem menuItem = new JMenuItem(struct.getName());
    // compartmentMenuItem.add(menuItem);
    // menuItem.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // String nameStruct = e.getActionCommand();
    // Structure struct = bioModel.getModel().getStructure(nameStruct);
    // fieldSpeciesContext.setStructure(struct);
    // }
    // });
    // }
    } else if (selectedObject instanceof MolecularTypePattern) {
        MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
        String moveRightMenuText = "Move <b>" + "right" + "</b>";
        moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
        JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
        Icon icon = VCellIcons.moveRightIcon;
        moveRightMenuItem.setIcon(icon);
        moveRightMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.shiftRight(from);
                speciesPropertiesTreeModel.populateTree();
            }
        });
        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.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.shiftLeft(from);
                speciesPropertiesTreeModel.populateTree();
            }
        });
        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);
                if (sp.getMolecularTypePatterns().isEmpty()) {
                    fieldSpeciesContext.setSpeciesPattern(null);
                }
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
    } else if (selectedObject instanceof MolecularComponentPattern) {
        manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
    } else if (selectedObject instanceof ComponentStatePattern) {
        MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
        manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
    } else {
        System.out.println("Where am I ???");
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ActionEvent(java.awt.event.ActionEvent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Point(java.awt.Point) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) JPopupMenu(javax.swing.JPopupMenu) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmElementAbstract(org.vcell.model.rbm.RbmElementAbstract) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) Icon(javax.swing.Icon) JMenuItem(javax.swing.JMenuItem) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) JMenu(javax.swing.JMenu)

Example 28 with MolecularComponentPattern

use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.

the class SpeciesPropertiesPanel method initialize.

/**
 * Initialize the class.
 */
private void initialize() {
    try {
        Border border = BorderFactory.createLineBorder(Color.gray);
        shapePanel = new // glyph (shape) panel
        LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spls != null) {
                    spls.paintSelf(g);
                }
            }

            @Override
            public DisplayMode getDisplayMode() {
                return DisplayMode.other;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleParticipantSignature getSignature() {
                return null;
            }

            @Override
            public GroupingCriteria getCriteria() {
                return null;
            }

            @Override
            public boolean isViewSingleRow() {
                return true;
            }
        };
        shapePanel.setBorder(border);
        shapePanel.setBackground(Color.white);
        shapePanel.setZoomFactor(-1);
        shapePanel.setEditable(true);
        shapePanel.setShowMoleculeColor(true);
        shapePanel.setShowNonTrivialOnly(true);
        // Dimension ms = new Dimension(350, 80);
        // shapePanel.setMinimumSize(ms);
        shapePanel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if (e.getButton() == 1) {
                    // left click selects the object (we highlight it)
                    Point whereClicked = e.getPoint();
                    PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                    manageMouseActivity(locationContext);
                } else if (e.getButton() == 3) {
                    // right click invokes popup menu (only if the object is highlighted)
                    Point whereClicked = e.getPoint();
                    PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                    manageMouseActivity(locationContext);
                    if (locationContext.getDeepestShape() != null && !locationContext.getDeepestShape().isHighlighted()) {
                    // TODO: (maybe) add code here to highlight the shape if it's not highlighted already but don't show the menu
                    // return;
                    }
                    showPopupMenu(e, locationContext);
                }
            }

            private void manageMouseActivity(PointLocationInShapeContext locationContext) {
                Graphics g = shapePanel.getGraphics();
                spls.turnHighlightOffRecursive(g);
                if (spls.contains(locationContext)) {
                    // check if mouse is inside shape
                    System.out.println("left click inside shape " + locationContext.getDeepestShape().toString());
                }
                locationContext.highlightDeepestShape();
                locationContext.paintDeepestShape(g);
            }
        });
        shapePanel.addMouseMotionListener(new MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                Point overWhat = e.getPoint();
                PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
                spls.contains(locationContext);
                HighlightableShapeInterface hsi = locationContext.getDeepestShape();
                if (hsi == null) {
                    shapePanel.setToolTipText(null);
                } else {
                    shapePanel.setToolTipText("Right click for " + hsi.getDisplayType() + " menus");
                }
                for (MolecularTypeLargeShape mtls : spls.getMolecularTypeLargeShapes()) {
                    Rectangle r = mtls.getAnchorHotspot();
                    if (r != null && r.contains(overWhat)) {
                        mtls.getMolecularType();
                        shapePanel.setToolTipText(mtls.getAnchorsHTML());
                        break;
                    }
                }
            }
        });
        // ----------------------------------------------------------------------------------
        leftPanel = new JPanel();
        GridBagLayout mgr = new GridBagLayout();
        mgr.rowHeights = new int[] { 100, 100 };
        leftPanel.setLayout(mgr);
        leftPanel.setBackground(Color.white);
        speciesPropertiesTree = new BioModelNodeEditableTree();
        speciesPropertiesTreeModel = new SpeciesPropertiesTreeModel(speciesPropertiesTree);
        speciesPropertiesTree.setModel(speciesPropertiesTreeModel);
        JPanel generalPanel = new JPanel();
        generalPanel.setLayout(new GridBagLayout());
        Dimension size = new Dimension(100, 150);
        generalPanel.setMinimumSize(size);
        nameTextField = new JTextField();
        nameTextField.setEditable(false);
        nameTextField.addActionListener(eventHandler);
        int gridy = 0;
        GridBagConstraints gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        JLabel label = new JLabel("Species Name");
        generalPanel.add(label, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        generalPanel.add(nameTextField, gbc);
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(4, 4, 4, 4);
        gbc.anchor = GridBagConstraints.FIRST_LINE_END;
        generalPanel.add(new JLabel("Linked Pathway Object(s)"), gbc);
        linkedPOScrollPane = new JScrollPane();
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 0.1;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        generalPanel.add(linkedPOScrollPane, gbc);
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(9, 8, 4, 6);
        gbc.anchor = GridBagConstraints.FIRST_LINE_END;
        generalPanel.add(new JLabel("Annotation "), gbc);
        annotationTextArea = new javax.swing.JTextArea("", 1, 30);
        annotationTextArea.setLineWrap(true);
        annotationTextArea.setWrapStyleWord(true);
        annotationTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
        annotationTextArea.setEditable(false);
        javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(annotationTextArea);
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 0.1;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        generalPanel.add(jsp, gbc);
        GridBagConstraints gbc1 = new GridBagConstraints();
        gbc1.gridx = 0;
        gbc1.gridy = 0;
        gbc1.gridwidth = 1;
        gbc1.weightx = 1;
        gbc1.weighty = 1;
        gbc1.fill = GridBagConstraints.BOTH;
        leftPanel.add(generalPanel, gbc1);
        scrollPane = new JScrollPane(shapePanel);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        // -----------------------------------------------------------
        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new GridBagLayout());
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(true);
        GridBagConstraints gbc2 = new GridBagConstraints();
        gbc2.gridx = 0;
        gbc2.gridy = 0;
        gbc2.insets = new Insets(4, 4, 0, 10);
        gbc2.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomLargerButton(), gbc2);
        gbc2 = new GridBagConstraints();
        gbc2.gridx = 0;
        gbc2.gridy = 1;
        gbc2.insets = new Insets(4, 4, 4, 10);
        gbc2.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomSmallerButton(), gbc2);
        gbc2 = new GridBagConstraints();
        gbc2.gridx = 0;
        gbc2.gridy = 2;
        gbc2.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc2.weighty = 1;
        gbc2.anchor = GridBagConstraints.WEST;
        gbc2.insets = new Insets(4, 4, 4, 10);
        optionsPanel.add(new JLabel(""), gbc2);
        JPanel containerOfScrollPanel = new JPanel();
        containerOfScrollPanel.setLayout(new BorderLayout());
        containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
        containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
        // gbc1 = new GridBagConstraints();
        gbc1.gridx = 0;
        gbc1.gridy = 1;
        gbc1.weightx = 1;
        gbc1.weighty = 0.1;
        gbc1.fill = GridBagConstraints.BOTH;
        leftPanel.add(containerOfScrollPanel, gbc1);
        setName("SpeciesEditorPanel");
        setLayout(new BorderLayout());
        setBackground(Color.white);
        add(leftPanel, BorderLayout.CENTER);
        initConnections();
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JPanel(javax.swing.JPanel) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Rectangle(java.awt.Rectangle) JTextField(javax.swing.JTextField) Font(java.awt.Font) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) BorderLayout(java.awt.BorderLayout) RuleAnalysisChanged(cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) GroupingCriteria(cbit.vcell.model.GroupingCriteria) MouseAdapter(java.awt.event.MouseAdapter) HighlightableShapeInterface(cbit.vcell.graph.HighlightableShapeInterface) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) PointLocationInShapeContext(cbit.vcell.graph.PointLocationInShapeContext) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) JScrollPane(javax.swing.JScrollPane) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) JTextArea(javax.swing.JTextArea) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border)

Example 29 with MolecularComponentPattern

use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.

the class SpeciesPropertiesPanel method manageComponentPatternFromShape.

public void manageComponentPatternFromShape(final RbmElementAbstract selectedObject, PointLocationInShapeContext locationContext, ShowWhat showWhat) {
    popupFromShapeMenu.removeAll();
    final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
    final MolecularComponent mc = mcp.getMolecularComponent();
    // ------------------------------------------------------------------- State
    if (showWhat == ShowWhat.ShowState && mc.getComponentStateDefinitions().size() != 0) {
        String prefix = "State:  ";
        final Map<String, String> itemMap = new LinkedHashMap<String, String>();
        // itemList.add(ComponentStatePattern.strAny);			// any is not an option for state
        String csdCurrentName;
        for (final ComponentStateDefinition csd : mc.getComponentStateDefinitions()) {
            csdCurrentName = "";
            if (mcp.getComponentStatePattern() != null && !mcp.getComponentStatePattern().isAny()) {
                ComponentStateDefinition csdCurrent = mcp.getComponentStatePattern().getComponentStateDefinition();
                csdCurrentName = csdCurrent.getName();
            }
            String name = csd.getName();
            if (name.equals(csdCurrentName)) {
                // currently selected menu item is shown in bold
                name = "<html>" + prefix + "<b>" + name + "</b></html>";
            } else {
                name = "<html>" + prefix + name + "</html>";
            }
            itemMap.put(name, csd.getName());
        }
        for (String name : itemMap.keySet()) {
            JMenuItem menuItem = new JMenuItem(name);
            popupFromShapeMenu.add(menuItem);
            menuItem.setIcon(VCellIcons.rbmComponentStateIcon);
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    String key = e.getActionCommand();
                    String name = itemMap.get(key);
                    if (name.equals(ComponentStatePattern.strAny)) {
                        ComponentStatePattern csp = new ComponentStatePattern();
                        mcp.setComponentStatePattern(csp);
                    } else {
                        ComponentStateDefinition csd = mcp.getMolecularComponent().getComponentStateDefinition(name);
                        if (csd == null) {
                            throw new RuntimeException("Missing ComponentStateDefinition " + name + " for Component " + mcp.getMolecularComponent().getName());
                        }
                        ComponentStatePattern csp = new ComponentStatePattern(csd);
                        mcp.setComponentStatePattern(csp);
                    }
                }
            });
        }
    }
    if (showWhat == ShowWhat.ShowState) {
        return;
    }
    // ---------------------------------------------------------------------------- Bonds
    final MolecularTypePattern mtp = locationContext.getMolecularTypePattern();
    final SpeciesPattern sp = locationContext.getSpeciesPattern();
    JMenu editBondMenu = new JMenu();
    final String specifiedString = mcp.getBondType() == BondType.Specified ? "<html><b>" + "Site bond specified" + "</b></html>" : "<html>" + "Site bond specified" + "</html>";
    editBondMenu.setText(specifiedString);
    editBondMenu.setToolTipText("Specified");
    editBondMenu.removeAll();
    final Map<String, Bond> itemMap = new LinkedHashMap<String, Bond>();
    String noneString = mcp.getBondType() == BondType.None ? "<html><b>" + "Site is unbound" + "</b></html>" : "<html>" + "Site is unbound" + "</html>";
    itemMap.put(noneString, null);
    // itemMap.put(possibleString, null);	// not a valid option for species
    if (mtp != null && sp != null) {
        List<Bond> bondPartnerChoices = sp.getAllBondPartnerChoices(mtp, mc);
        for (Bond b : bondPartnerChoices) {
            // if(b.equals(mcp.getBond())) {
            // continue;	// if the mcp has a bond already we don't offer it
            // }
            int index = 0;
            if (mcp.getBondType() == BondType.Specified) {
                index = mcp.getBondId();
            } else {
                index = sp.nextBondId();
            }
            itemMap.put(b.toHtmlStringLong(sp, mtp, mc, index), b);
        // itemMap.put(b.toHtmlStringLong(sp, index), b);
        }
    }
    int index = 0;
    Graphics gc = shapePanel.getGraphics();
    for (String name : itemMap.keySet()) {
        JMenuItem menuItem = new JMenuItem(name);
        if (index == 0) {
            menuItem.setIcon(VCellIcons.rbmBondNoneIcon);
            menuItem.setToolTipText("None");
            popupFromShapeMenu.add(menuItem);
        } else {
            Bond b = itemMap.get(name);
            // clone of the sp, with only the bond of interest
            SpeciesPattern spBond = new SpeciesPattern(bioModel.getModel(), sp);
            spBond.resetBonds();
            spBond.resetStates();
            MolecularTypePattern mtpFrom = spBond.getMolecularTypePattern(mtp.getMolecularType().getName(), mtp.getIndex());
            MolecularComponentPattern mcpFrom = mtpFrom.getMolecularComponentPattern(mc);
            MolecularTypePattern mtpTo = spBond.getMolecularTypePattern(b.molecularTypePattern.getMolecularType().getName(), b.molecularTypePattern.getIndex());
            MolecularComponentPattern mcpTo = mtpTo.getMolecularComponentPattern(b.molecularComponentPattern.getMolecularComponent());
            spBond.setBond(mtpTo, mcpTo, mtpFrom, mcpFrom);
            Icon icon = new SpeciesPatternSmallShape(3, 4, spBond, gc, fieldSpeciesContext, false, issueManager);
            ((SpeciesPatternSmallShape) icon).setDisplayRequirements(DisplayRequirements.highlightBonds);
            menuItem.setIcon(icon);
            editBondMenu.add(menuItem);
        }
        menuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                String name = e.getActionCommand();
                BondType btBefore = mcp.getBondType();
                if (name.equals(noneString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> not specified
                        // change the partner to none since this is the only option
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.None);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.None);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            speciesPropertiesTreeModel.populateTree();
                        }
                    });
                } else {
                    if (btBefore != BondType.Specified) {
                        // if we go from a non-specified to a specified we need to find the next available
                        // bond id, so that we can choose the color for displaying the bond
                        // a bad bond id, like -1, will crash badly when trying to choose the color
                        int bondId = sp.nextBondId();
                        mcp.setBondId(bondId);
                    } else {
                        // specified -> specified
                        // change the old partner to none since it's the only available option, continue using the bond id
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.None);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Specified);
                    Bond b = itemMap.get(name);
                    mcp.setBond(b);
                    mcp.getBond().molecularComponentPattern.setBondId(mcp.getBondId());
                    sp.resolveBonds();
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            speciesPropertiesTreeModel.populateTree();
                        }
                    });
                }
            }
        });
        index++;
    }
    popupFromShapeMenu.add(editBondMenu);
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) ActionEvent(java.awt.event.ActionEvent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) Graphics(java.awt.Graphics) ActionListener(java.awt.event.ActionListener) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) Icon(javax.swing.Icon) JMenuItem(javax.swing.JMenuItem) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) JMenu(javax.swing.JMenu)

Example 30 with MolecularComponentPattern

use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.

the class SpeciesPropertiesTreeModel method valueForPathChanged.

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    Object obj = path.getLastPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    BioModelNode parentNode = (BioModelNode) selectedNode.getParent();
    Object userObject = selectedNode.getUserObject();
    try {
        if (newValue instanceof String) {
            String inputString = (String) newValue;
            if (inputString == null || inputString.length() == 0) {
                return;
            }
        // if (userObject instanceof SeedSpecies) {
        // ((SeedSpecies) userObject).setSpeciesPattern(inputString);
        // }
        } else if (newValue instanceof MolecularComponentPattern) {
            MolecularComponentPattern newMcp = (MolecularComponentPattern) newValue;
            Object parentObject = parentNode == null ? null : parentNode.getUserObject();
            if (parentObject instanceof MolecularTypePattern) {
                MolecularTypePattern mtp = (MolecularTypePattern) parentObject;
                MolecularComponent mc = newMcp.getMolecularComponent();
                MolecularComponentPattern mcp = mtp.getMolecularComponentPattern(mc);
                // TODO: what's correct here ?
                mcp.setComponentStatePattern(newMcp.getComponentStatePattern());
                BondType bp = mcp.getBondType();
                BondType newbp = newMcp.getBondType();
                mcp.setBondType(newbp);
                // specified -> specified
                if (bp == BondType.Specified && newbp == BondType.Specified) {
                // bond didn't change
                } else if (bp == BondType.Specified && newbp != BondType.Specified) {
                    // specified -> non specified
                    // change the partner to possible
                    mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                    mcp.setBond(null);
                } else if (bp != BondType.Specified && newbp == BondType.Specified) {
                    // non specified -> specified
                    int newBondId = newMcp.getBondId();
                    mcp.setBondId(newBondId);
                    mcp.setBond(newMcp.getBond());
                    mcp.getBond().molecularComponentPattern.setBondId(newBondId);
                    speciesContext.getSpeciesPattern().resolveBonds();
                } else {
                }
            }
        }
    } catch (Exception ex) {
        DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
    }
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Aggregations

MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)62 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)30 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)25 Graphics (java.awt.Graphics)16 MolecularComponent (org.vcell.model.rbm.MolecularComponent)14 Point (java.awt.Point)13 MolecularType (org.vcell.model.rbm.MolecularType)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 Icon (javax.swing.Icon)9 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)9 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)8 List (java.util.List)7 BioModelNode (cbit.vcell.desktop.BioModelNode)6 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)6 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)6 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)6