Search in sources :

Example 1 with Bond

use of org.vcell.model.rbm.SpeciesPattern.Bond in project vcell by virtualcell.

the class XmlReader method getRbmMolecularComponentPattern.

private MolecularComponentPattern getRbmMolecularComponentPattern(Element e, MolecularTypePattern mtp, MolecularType mt, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    String s = e.getAttributeValue(XMLTags.RbmMolecularComponentTag);
    if (s == null || s.isEmpty()) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: MolecularComponent name is missing.");
        return null;
    }
    MolecularComponent c = mt.getMolecularComponent(s);
    if (c == null) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponent.");
        return null;
    }
    ComponentStatePattern csp = new ComponentStatePattern();
    MolecularComponentPattern mcp = new MolecularComponentPattern(c);
    s = e.getAttributeValue(XMLTags.RbmMolecularComponentStatePatternTag);
    if (s != null && !s.isEmpty()) {
        // state may be missing, we set it only if is present
        ComponentStateDefinition cs = c.getComponentStateDefinition(s);
        if (cs == null) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponentState.");
            return null;
        }
        csp = new ComponentStatePattern(cs);
        mcp.setComponentStatePattern(csp);
    }
    // s = e.getAttributeValue(XMLTags.RbmMolecularTypeAnyTag);
    // if(s!=null && !s.isEmpty()) {
    // boolean any = Boolean.parseBoolean(s);
    // csp.setAny(any);
    // }
    s = e.getAttributeValue(XMLTags.RbmBondTypeAttrTag);
    BondType bondType = BondType.fromSymbol(s);
    if (bondType == BondType.Specified) {
        int bondId = Integer.parseInt(s);
        mcp.setBondId(bondId);
    }
    mcp.setBondType(bondType);
    // sanity check, we only read the names here and make sure they make sense
    Element bondElement = e.getChild(XMLTags.RbmBondTag, vcNamespace);
    if (bondElement != null) {
        // it's actually the name of the MolecularType inside this pattern
        String molecularTypeName = bondElement.getAttributeValue(XMLTags.RbmMolecularTypePatternTag);
        String molecularComponentName = bondElement.getAttributeValue(XMLTags.RbmMolecularComponentPatternTag);
        if (molecularTypeName == null || molecularTypeName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularTypeName missing.");
            return mcp;
        }
        if (molecularComponentName == null || molecularComponentName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularComponentName missing.");
            return mcp;
        }
        // we'll have a bond here, it will be properly initialized during RbmObservable.resolveBonds() call  !!!
        Bond bond = new Bond();
        mcp.setBond(bond);
    }
    return mcp;
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Element(org.jdom.Element) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 2 with Bond

use of org.vcell.model.rbm.SpeciesPattern.Bond in project vcell by virtualcell.

the class ModelRuleFactory method createRuleEntry.

public ModelRuleEntry createRuleEntry(ReactionRule reactionRule, int reactionRuleIndex, ReactionRuleDirection direction) {
    ModelRuleEntry rule = new ModelRuleEntry(reactionRule, reactionRuleIndex);
    // 
    // for each molecular type in reactant, find all possible matches in products (without regard for consistency).
    // 
    int participantIndex = 0;
    for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
        ModelParticipantEntry reactantEntry = new ModelParticipantEntry(rule, participantIndex, rp);
        rule.reactantEntries.add(reactantEntry);
        int moleculeIndex = 0;
        for (MolecularTypePattern mtp : rp.getSpeciesPattern().getMolecularTypePatterns()) {
            ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(reactantEntry, moleculeIndex, mtp);
            rule.reactantMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                // TODO: divergence point vs. MathRuleFactory
                // we need to look at all components when we compare reactants to products looking for changes
                // if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                // continue;
                // }
                ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.reactantMolecularComponentEntries.add(mce);
                // 
                // if this reactant component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
                // 
                Bond bond = mcp.getBond();
                if (bond != null) {
                    ReactantBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.reactantMolecularComponentEntries) {
                        if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
                            bondEntry = new ReactantBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.reactantBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    participantIndex = 0;
    for (ProductPattern pp : reactionRule.getProductPatterns()) {
        ModelParticipantEntry productEntry = new ModelParticipantEntry(rule, participantIndex, pp);
        rule.productEntries.add(productEntry);
        int moleculeIndex = 0;
        for (MolecularTypePattern mtp : pp.getSpeciesPattern().getMolecularTypePatterns()) {
            ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(productEntry, moleculeIndex, mtp);
            rule.productMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                // TODO: divergence point vs. MathRuleFactory
                // we need to look at all components when we compare reactants to products looking for changes
                // if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                // continue;
                // }
                ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.productMolecularComponentEntries.add(mce);
                // 
                // if this product component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
                // 
                Bond bond = mcp.getBond();
                if (bond != null) {
                    ProductBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.productMolecularComponentEntries) {
                        if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
                            bondEntry = new ProductBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.productBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    return rule;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ProductBondEntry(org.vcell.model.rbm.RuleAnalysis.ProductBondEntry) ReactantBondEntry(org.vcell.model.rbm.RuleAnalysis.ReactantBondEntry) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond)

Example 3 with Bond

use of org.vcell.model.rbm.SpeciesPattern.Bond in project vcell by virtualcell.

the class ObservablePropertiesPanel method manageComponentPatternFromShape.

public void manageComponentPatternFromShape(final RbmElementAbstract selectedObject, PointLocationInShapeContext locationContext, ShowWhat showWhat) {
    final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
    final MolecularComponent mc = mcp.getMolecularComponent();
    popupFromShapeMenu.removeAll();
    // ------------------------------------------------------------------- State
    if (showWhat == ShowWhat.ShowState && mc.getComponentStateDefinitions().size() != 0) {
        String prefix = "State:  ";
        String csdCurrentName = "";
        final Map<String, String> itemMap = new LinkedHashMap<String, String>();
        if (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny()) {
            csdCurrentName = "<html>" + prefix + "<b>" + ComponentStatePattern.strAny + "</b></html>";
        } else {
            csdCurrentName = "<html>" + prefix + ComponentStatePattern.strAny + "</html>";
        }
        itemMap.put(csdCurrentName, ComponentStatePattern.strAny);
        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 = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.None.symbol + "</b> " + BondType.None.name() + "</html>";
    // String existsString = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.Exists.symbol + "</b> " + BondType.Exists.name() + "</html>";
    // String possibleString = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.Possible.symbol + "</b> " + BondType.Possible.name() + "</html>";
    String noneString = mcp.getBondType() == BondType.None ? "<html><b>" + "Site is unbound" + "</b></html>" : "<html>" + "Site is unbound" + "</html>";
    // Site is bound
    String existsString = mcp.getBondType() == BondType.Exists ? "<html><b>" + "Site has external bond" + "</b></html>" : "<html>" + "Site has external bond" + "</html>";
    String possibleString = mcp.getBondType() == BondType.Possible ? "<html><b>" + "Site may be bound" + "</b></html>" : "<html>" + "Site may be bound" + "</html>";
    itemMap.put(noneString, null);
    itemMap.put(existsString, null);
    itemMap.put(possibleString, null);
    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(mtp, mc, sp, index), b);
            itemMap.put(b.toHtmlStringLong(sp, mtp, mc, index), b);
        // itemMap.put(b.toHtmlStringLong(sp, index), b);
        }
    }
    int index = 0;
    Graphics gc = splitPaneHorizontal.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 if (index == 1) {
            menuItem.setIcon(VCellIcons.rbmBondExistsIcon);
            menuItem.setToolTipText("Exists");
            popupFromShapeMenu.add(menuItem);
        } else if (index == 2) {
            menuItem.setIcon(VCellIcons.rbmBondPossibleIcon);
            menuItem.setToolTipText("Possible");
            popupFromShapeMenu.add(menuItem);
        } else if (index > 2) {
            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, observable, false, issueManager);
            ((SpeciesPatternSmallShape) icon).setDisplayRequirements(DisplayRequirements.highlightBonds);
            menuItem.setIcon(icon);
            editBondMenu.add(menuItem);
        // } else {
        // if(index == 0) {
        // menuItem.setForeground(Color.blue);
        // }
        // popupFromShapeMenu.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 possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.None);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                } else if (name.equals(existsString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> exists
                        // change the partner to possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Exists);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                } else if (name.equals(possibleString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> possible
                        // change the partner to possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Possible);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.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 possible, continue using the bond id
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        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() {
                            observableTreeModel.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) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) JMenuItem(javax.swing.JMenuItem) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) JMenu(javax.swing.JMenu)

Example 4 with Bond

use of org.vcell.model.rbm.SpeciesPattern.Bond in project vcell by virtualcell.

the class RbmTreeCellRenderer method toHtmlWorkShort.

private static final String toHtmlWorkShort(BondLocal bl) {
    // used for tooltips
    MolecularComponentPattern mcp = bl.getMolecularComponentPattern();
    String bondText = "";
    String colorTextStart = "<font color=" + "\"rgb(" + GraphConstants.red.getRed() + "," + GraphConstants.red.getGreen() + "," + GraphConstants.red.getBlue() + ")\">";
    String colorTextEnd = "</font>";
    bondText = colorTextStart + "<b>" + "(unbound)" + "</b>" + colorTextEnd;
    if (mcp != null) {
        BondType bondType = mcp.getBondType();
        if (bondType == BondType.Specified) {
            Bond bond = mcp.getBond();
            if (bond == null) {
                colorTextStart = "<font color=" + "\"rgb(" + GraphConstants.red.getRed() + "," + GraphConstants.red.getGreen() + "," + GraphConstants.red.getBlue() + ")\">";
                colorTextEnd = "</font>";
                bondText = colorTextStart + "<b>" + "bond (missing)" + "</b>" + colorTextEnd;
            } else {
                int id = mcp.getBondId();
                colorTextStart = "<font color=" + "\"rgb(" + GraphConstants.bondHtmlColors[id].getRed() + "," + GraphConstants.bondHtmlColors[id].getGreen() + "," + GraphConstants.bondHtmlColors[id].getBlue() + ")\">";
                colorTextEnd = "</font>";
                // <sub>&nbsp;</sub>
                bondText = colorTextStart + "<b>" + "Bond<sub>" + id + "</sub></b>" + colorTextEnd;
            }
        } else if (bondType == BondType.None) {
            bondText = "Unbound";
        // bondText =  "<b>" + "unbound" + "</b>";
        } else if (bondType == BondType.Exists) {
            Color c = AbstractComponentShape.plusSignGreen;
            colorTextStart = "<font color=" + "\"rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ")\">";
            colorTextEnd = "</font>";
            // green '+'
            bondText = colorTextStart + "<b>" + mcp.getBondType().symbol + "</b>" + colorTextEnd;
            bondText = "Bond: '" + bondText + "'";
        } else if (bondType == BondType.Possible) {
            Color c = Color.gray;
            colorTextStart = "<font color=" + "\"rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ")\">";
            colorTextEnd = "</font>";
            // gray '?'
            bondText = colorTextStart + "<b>" + mcp.getBondType().symbol + "</b>" + colorTextEnd;
            bondText = "Bond: '" + bondText + "'";
        }
    }
    return bondText;
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Color(java.awt.Color) Bond(org.vcell.model.rbm.SpeciesPattern.Bond)

Example 5 with Bond

use of org.vcell.model.rbm.SpeciesPattern.Bond 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)

Aggregations

Bond (org.vcell.model.rbm.SpeciesPattern.Bond)9 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)8 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)7 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)5 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)5 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)4 MolecularComponent (org.vcell.model.rbm.MolecularComponent)4 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)3 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)3 Graphics (java.awt.Graphics)3 Point (java.awt.Point)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 LinkedHashMap (java.util.LinkedHashMap)3 Icon (javax.swing.Icon)3 JMenu (javax.swing.JMenu)3 JMenuItem (javax.swing.JMenuItem)3 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)3 ParticleBondType (cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType)2 Element (org.jdom.Element)2