Search in sources :

Example 11 with MolecularComponent

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

the class MolecularTypeTreeModel 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;
    Object userObject = selectedNode.getUserObject();
    try {
        if (newValue instanceof String) {
            String inputString = (String) newValue;
            if (inputString == null || inputString.length() == 0) {
                return;
            }
            if (userObject instanceof MolecularType) {
                String mangled = TokenMangler.fixTokenStrict(inputString);
                if (!mangled.equals(inputString)) {
                    String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
                    throw new RuntimeException(errMsg);
                }
                ((MolecularType) userObject).setName(inputString);
            } else if (userObject instanceof MolecularComponent) {
                String mangled = TokenMangler.fixTokenStrict(inputString);
                if (!mangled.equals(inputString)) {
                    String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
                    throw new RuntimeException(errMsg);
                }
                ((MolecularComponent) userObject).setName(inputString);
            } else if (userObject instanceof ComponentStateDefinition) {
                if (inputString.matches("[A-Z_a-z0-9]+")) {
                    ((ComponentStateDefinition) userObject).setName(inputString);
                }
            }
        }
    } catch (Exception ex) {
        DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Displayable(org.vcell.util.Displayable) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 12 with MolecularComponent

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

the class MolecularTypeTreeModel method propertyChange.

public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
        nodeChanged(rootNode);
    } else if (evt.getPropertyName().equals("entityChange")) {
        nodeChanged(rootNode);
    } else {
        populateTree();
        Object object = evt.getSource();
        if (object instanceof MolecularType) {
            List<MolecularComponent> oldValue = (List<MolecularComponent>) evt.getOldValue();
            for (MolecularComponent molecularComponent : oldValue) {
                molecularComponent.removePropertyChangeListener(this);
                for (ComponentStateDefinition componentState : molecularComponent.getComponentStateDefinitions()) {
                    componentState.removePropertyChangeListener(this);
                }
            }
            List<MolecularComponent> newValue = (List<MolecularComponent>) evt.getNewValue();
            for (MolecularComponent molecularComponent : newValue) {
                molecularComponent.addPropertyChangeListener(this);
                for (ComponentStateDefinition componentState : molecularComponent.getComponentStateDefinitions()) {
                    componentState.addPropertyChangeListener(this);
                }
            }
        } else if (object instanceof MolecularComponent) {
            List<ComponentStateDefinition> oldValue = (List<ComponentStateDefinition>) evt.getOldValue();
            for (ComponentStateDefinition componentState : oldValue) {
                componentState.removePropertyChangeListener(this);
            }
            List<ComponentStateDefinition> newValue = (List<ComponentStateDefinition>) evt.getNewValue();
            for (ComponentStateDefinition componentState : newValue) {
                componentState.addPropertyChangeListener(this);
            }
        }
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) List(java.util.List) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 13 with MolecularComponent

use of org.vcell.model.rbm.MolecularComponent 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 14 with MolecularComponent

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

the class ObservableTreeModel 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;
            }
            String mangled = TokenMangler.fixTokenStrict(inputString);
            if (!mangled.equals(inputString)) {
                String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
                throw new RuntimeException(errMsg);
            }
            if (userObject instanceof RbmObservable) {
                // TODO: untested!!!
                ((RbmObservable) userObject).setName(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);
                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);
                    for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
                        sp.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) RbmObservable(cbit.vcell.model.RbmObservable) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 15 with MolecularComponent

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

the class ObservableTreeModel method createMolecularComponentPatternNode.

private BioModelNode createMolecularComponentPatternNode(MolecularComponentPattern molecularComponentPattern) {
    MolecularComponent mc = molecularComponentPattern.getMolecularComponent();
    BioModelNode node = new BioModelNode(molecularComponentPattern, true);
    ComponentStatePattern csp = molecularComponentPattern.getComponentStatePattern();
    // }
    return node;
}
Also used : MolecularComponent(org.vcell.model.rbm.MolecularComponent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) BioModelNode(cbit.vcell.desktop.BioModelNode)

Aggregations

MolecularComponent (org.vcell.model.rbm.MolecularComponent)42 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)23 MolecularType (org.vcell.model.rbm.MolecularType)23 BioModelNode (cbit.vcell.desktop.BioModelNode)17 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)14 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)11 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)10 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 LinkedHashMap (java.util.LinkedHashMap)7 Icon (javax.swing.Icon)7 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)7 Point (java.awt.Point)6 List (java.util.List)6 ParticleMolecularComponent (cbit.vcell.math.ParticleMolecularComponent)5 ArrayList (java.util.ArrayList)5 RbmObservable (cbit.vcell.model.RbmObservable)4 ReactionRule (cbit.vcell.model.ReactionRule)4 Structure (cbit.vcell.model.Structure)4 Graphics (java.awt.Graphics)4 ActionEvent (java.awt.event.ActionEvent)4