use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class ReactionRulePropertiesTreeModel method createMolecularComponentPatternNode.
private BioModelNode createMolecularComponentPatternNode(MolecularComponentPattern molecularComponentPattern) {
MolecularComponent mc = molecularComponentPattern.getMolecularComponent();
BioModelNode node = new BioModelNode(molecularComponentPattern, true);
ComponentStatePattern csp = molecularComponentPattern.getComponentStatePattern();
// }
return node;
}
use of org.vcell.model.rbm.MolecularComponent 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);
}
use of org.vcell.model.rbm.MolecularComponent 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());
}
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class SpeciesPropertiesTreeModel method createMolecularTypePatternNode.
private BioModelNode createMolecularTypePatternNode(MolecularTypePattern molecularTypePattern) {
MolecularType molecularType = molecularTypePattern.getMolecularType();
BioModelNode node = new BioModelNode(molecularTypePattern, true);
for (MolecularComponent mc : molecularType.getComponentList()) {
// Attention: we show all components even though the combination State Any + Bond Possible should be "invisible"
// uncomment the "if" to hide the Any + Possible combination
// if (bShowDetails || molecularTypePattern.getMolecularComponentPattern(mc).isbVisible()) {
BioModelNode n = createMolecularComponentPatternNode(molecularTypePattern.getMolecularComponentPattern(mc));
if (n != null) {
node.add(n);
// }
}
}
return node;
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class XmlReader method getRbmMolecularComponent.
private MolecularComponent getRbmMolecularComponent(Element e, Model newModel) {
String s = e.getAttributeValue(XMLTags.NameAttrTag);
if (s == null || s.isEmpty()) {
System.out.println("XMLReader: getRbmMolecularComponent: name is missing.");
return null;
}
MolecularComponent mc = new MolecularComponent(s);
s = e.getAttributeValue(XMLTags.RbmIndexAttrTag);
if (s == null || s.isEmpty()) {
System.out.println("XMLReader: getRbmMolecularComponent: index is missing.");
return null;
}
int index = Integer.parseInt(s);
mc.setIndex(index);
List<Element> children = e.getChildren(XMLTags.RbmMolecularTypeAllowableStateTag, vcNamespace);
for (Element element : children) {
ComponentStateDefinition cs = getRbmComponentStateDefinition(element, newModel);
if (cs != null) {
mc.addComponentStateDefinition(cs);
}
}
return mc;
}
Aggregations