Search in sources :

Example 36 with MolecularComponentPattern

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

the class RbmObservableTreeCellRenderer method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    int x = 4;
    int y = 16;
    if (!(obj instanceof MolecularComponentPattern)) {
        return;
    }
    MolecularComponentPattern mcp = (MolecularComponentPattern) obj;
    Graphics2D g2 = (Graphics2D) g;
    Color colorOld = g2.getColor();
    if (mcp.getBondType() == BondType.Specified) {
        Color bondColor = GraphConstants.bondHtmlColors[mcp.getBondId()];
        // g2.setColor(bondColor);
        // int x = 7;						// oblique line
        // int y = 14;
        // g2.drawLine(x+1, y, x+1+3, y+3);
        // g2.drawLine(x, y, x+3, y+3);
        // g2.drawLine(x, y+1, x+3, y+1+3);
        g2.setColor(bondColor);
        // 2 lines, L-shaped
        g2.drawLine(x, y, x, y + 2);
        g2.drawLine(x + 1, y, x + 1, y + 2);
        g2.drawLine(x, y + 2, x + 7, y + 2);
        g2.drawLine(x, y + 3, x + 7, y + 3);
    } else if (mcp.getBondType().equals(BondType.Exists)) {
        // draw a green '+' sign
        g2.setColor(AbstractComponentShape.plusSignGreen);
        // g2.drawLine(x-3, y+2, x-1, y+2);		// horizontal
        // g2.drawLine(x-2, y+1, x-2, y+3);		// vertical
        // g2.drawLine(x-4, y+1, x+1, y+1);		// horizontal (double line, it's too large)
        // g2.drawLine(x-4, y+2, x+1, y+2);
        // vertical
        g2.drawLine(x, y - 1, x, y + 4);
        g2.drawLine(x - 1, y - 1, x - 1, y + 4);
    }
    g2.setColor(colorOld);
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 37 with MolecularComponentPattern

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

the class RbmTableRenderer method toHtml.

public static String toHtml(SpeciesPattern speciesPattern, boolean bSelected) {
    StringBuilder buffer = new StringBuilder("");
    List<MolecularTypePattern> molecularTypePatterns = speciesPattern.getMolecularTypePatterns();
    for (int i = 0; i < molecularTypePatterns.size(); ++i) {
        if (i > 0) {
            buffer.append(".");
        }
        MolecularTypePattern molecularTypePattern = molecularTypePatterns.get(i);
        buffer.append(molecularTypePattern.getMolecularType().getName());
        buffer.append("(");
        List<MolecularComponentPattern> componentPatterns = molecularTypePattern.getComponentPatternList();
        boolean bAddComma = false;
        for (MolecularComponentPattern mcp : componentPatterns) {
            if (mcp.isImplied()) {
                continue;
            }
            if (bAddComma) {
                buffer.append(",");
            }
            boolean bShowColor = false;
            if (mcp.getBondType() == BondType.Specified && !bSelected) {
                bShowColor = true;
                Color color = GraphConstants.bondHtmlColors[mcp.getBondId()];
                buffer.append("<font color=\"rgb(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")\">");
            }
            buffer.append(mcp.getMolecularComponent().getName());
            if (mcp.getComponentStatePattern() != null) {
                buffer.append(RbmUtils.toBnglString(mcp.getComponentStatePattern().getComponentStateDefinition()));
            }
            switch(mcp.getBondType()) {
                case Exists:
                    buffer.append("!+");
                    break;
                case None:
                    break;
                case Possible:
                    buffer.append("!?");
                    break;
                case Specified:
                    buffer.append("!" + mcp.getBondId());
                    break;
            }
            if (bShowColor) {
                buffer.append("</font>");
            }
            bAddComma = true;
        }
        buffer.append(")");
    }
    return buffer.toString();
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Color(java.awt.Color) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 38 with MolecularComponentPattern

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

the class RbmTreeCellRenderer method toHtmlWork.

private static final String toHtmlWork(BondLocal bl, boolean bSelected) {
    MolecularComponentPattern mcp = bl.getMolecularComponentPattern();
    BondType defaultType = BondType.Possible;
    String bondText = " Bond(<b>" + defaultType.symbol + "</b>): " + "<b>" + BondType.Possible.name() + "</b>";
    if (mcp != null) {
        BondType bondType = mcp.getBondType();
        if (bondType == BondType.Specified) {
            Bond bond = mcp.getBond();
            if (bond == null) {
                bondText = "";
            } else {
                int id = mcp.getBondId();
                String colorTextStart = bSelected ? "" : "<font color=" + "\"rgb(" + GraphConstants.bondHtmlColors[id].getRed() + "," + GraphConstants.bondHtmlColors[id].getGreen() + "," + GraphConstants.bondHtmlColors[id].getBlue() + ")\">";
                String colorTextEnd = bSelected ? "" : "</font>";
                // <sub>&nbsp;</sub>
                bondText = colorTextStart + "<b>" + mcp.getBondId() + "</b>" + colorTextEnd;
                bondText = " Bound(" + bondText + ") to: " + colorTextStart + toHtml(bond) + colorTextEnd;
            }
        } else {
            bondText = " Bond(<b>" + bondType.symbol + "</b>): " + "<b>" + bondType.name() + "</b>";
        }
    }
    return bondText;
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond)

Example 39 with MolecularComponentPattern

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

the class RbmTreeCellRenderer method toHtmlWork.

private static final String toHtmlWork(StateLocal sl, boolean bShowWords) {
    String stateText = "";
    MolecularComponentPattern mcp = sl.getMolecularComponentPattern();
    ComponentStatePattern csp = mcp.getComponentStatePattern();
    if (mcp != null) /*&& !mcp.isImplied()*/
    {
        if (csp == null) {
            if (bShowWords) {
                stateText = ComponentStateDefinition.typeName + "(-): <b>None</b>";
            } else {
                stateText = "<b>None</b>";
            }
        } else if (csp.isAny()) {
            if (bShowWords) {
                stateText = ComponentStateDefinition.typeName + "(~): <b>Any</b>";
            } else {
                stateText = "<b>Any</b>";
            }
        } else {
            if (bShowWords) {
                stateText = ComponentStateDefinition.typeName + "(~): <b>" + csp.getComponentStateDefinition().getName() + "</b>";
            } else {
                stateText = "~ <b>" + csp.getComponentStateDefinition().getName() + "</b>";
            }
        }
    }
    return stateText;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern)

Example 40 with MolecularComponentPattern

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

the class ReactionRuleEditorPropertiesPanel method manageComponentPatternFromShape.

public void manageComponentPatternFromShape(final Object selectedObject, PointLocationInShapeContext locationContext, final ReactionRulePropertiesTreeModel treeModel, ShowWhat showWhat, boolean bIsReactant) {
    popupFromShapeMenu.removeAll();
    final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
    final MolecularComponent mc = mcp.getMolecularComponent();
    boolean anyStateProhibited = false;
    boolean explicitStateProhibited = false;
    boolean existBondProhibited = false;
    boolean noneBondProhibited = false;
    boolean possibleBondProhibited = false;
    boolean specifiedBondProhibited = false;
    if (!bIsReactant) {
        // product has restrictions for states and bonds, depending on reactant
        BondType reactantComponentBondType = reactionRule.getReactantComponentBondType(mcp);
        if (reactantComponentBondType != null && reactantComponentBondType == BondType.Exists) {
            // has external		+
            // existBondProhibited = true;
            noneBondProhibited = true;
            possibleBondProhibited = true;
            specifiedBondProhibited = true;
        } else if (reactantComponentBondType != null && reactantComponentBondType == BondType.None) {
            // is unbound		-
            existBondProhibited = true;
            // noneBondProhibited = true;
            possibleBondProhibited = true;
        // specifiedBondProhibited = true;
        } else if (reactantComponentBondType != null && reactantComponentBondType == BondType.Possible) {
            // may be bound		?
            existBondProhibited = true;
            noneBondProhibited = true;
            // possibleBondProhibited = true;
            specifiedBondProhibited = true;
        } else if (reactantComponentBondType != null && reactantComponentBondType == BondType.Specified) {
            existBondProhibited = true;
            // noneBondProhibited = true;
            possibleBondProhibited = true;
        // specifiedBondProhibited = true;
        }
        // if it's null nothing is prohibited
        ComponentStatePattern reactantComponentStatePattern = reactionRule.getReactantComponentState(mcp);
        if (reactantComponentStatePattern != null && reactantComponentStatePattern.isAny()) {
            explicitStateProhibited = true;
        } else if (reactantComponentStatePattern != null && !reactantComponentStatePattern.isAny()) {
            anyStateProhibited = true;
        }
    // if reactantComponentStatePattern is null nothing is prohibited, we may not have a matching reactant for this product
    }
    // ------------------------------------------------------------------- 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 key : itemMap.keySet()) {
            JMenuItem menuItem = new JMenuItem(key);
            if (!bIsReactant) {
                String name = itemMap.get(key);
                if (name.equals(ComponentStatePattern.strAny) && anyStateProhibited) {
                    menuItem.setEnabled(false);
                } else if (!name.equals(ComponentStatePattern.strAny) && explicitStateProhibited) {
                    menuItem.setEnabled(false);
                }
            }
            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);
                    ComponentStatePattern csp = new ComponentStatePattern();
                    if (!name.equals(ComponentStatePattern.strAny)) {
                        ComponentStateDefinition csd = mcp.getMolecularComponent().getComponentStateDefinition(name);
                        if (csd == null) {
                            throw new RuntimeException("Missing ComponentStateDefinition " + name + " for Component " + mcp.getMolecularComponent().getName());
                        }
                        csp = new ComponentStatePattern(csd);
                    }
                    mcp.setComponentStatePattern(csp);
                    if (bIsReactant) {
                        reflectStateToProduct(mcp, csp);
                        productTreeModel.populateTree();
                    }
                    treeModel.populateTree();
                    shapePanel.repaint();
                }
            });
        }
    }
    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();
    editBondMenu.setEnabled(!specifiedBondProhibited);
    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>";
    // 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 && !specifiedBondProhibited) {
        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 (!bIsReactant) {
            if (name.equals(noneString) && noneBondProhibited) {
                menuItem.setEnabled(false);
            } else if (name.equals(existsString) && existBondProhibited) {
                menuItem.setEnabled(false);
            } else if (name.equals(possibleString) && possibleBondProhibited) {
                menuItem.setEnabled(false);
            } else if (!name.equals(noneString) && !name.equals(existsString) && !name.equals(possibleString) && specifiedBondProhibited) {
                menuItem.setEnabled(false);
            }
        }
        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) {
            // we skip None, Exists, Possible
            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, reactionRule, 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 possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.None);
                    mcp.setBond(null);
                } 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);
                } 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);
                } 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();
                }
                // when the tree will be gone
                if (bIsReactant) {
                    reflectBondToProduct(mcp);
                    productTreeModel.populateTree();
                }
                treeModel.populateTree();
                shapePanel.repaint();
            }
        });
        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)

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