use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class XmlReader method getRbmObservables.
private RbmObservable getRbmObservables(Element e, Model newModel) {
String n = e.getAttributeValue(XMLTags.NameAttrTag);
if (n == null || n.isEmpty()) {
System.out.println("XMLReader: getRbmObservables: name is missing.");
return null;
}
String t = e.getAttributeValue(XMLTags.RbmObservableTypeTag);
if (t == null || t.isEmpty()) {
System.out.println("XMLReader: getRbmObservables: type is missing.");
return null;
}
RbmObservable.ObservableType ot = RbmObservable.ObservableType.Molecules;
if (!t.equals(ot.name())) {
ot = RbmObservable.ObservableType.Species;
}
Structure structure = null;
String structureName = e.getAttributeValue(XMLTags.StructureAttrTag);
if (structureName == null || structureName.isEmpty()) {
// the tag is missing
if (newModel.getStructures().length == 1) {
// possible old single compartment model where we were not saving the structure for observable
structure = newModel.getStructure(0);
} else {
throw new RuntimeException("XMLReader: structure missing for observable " + n);
}
} else {
structure = newModel.getStructure(structureName);
}
RbmObservable o = new RbmObservable(newModel, n, structure, ot);
// Sequence
RbmObservable.Sequence se = RbmObservable.Sequence.Multimolecular;
String ses = e.getAttributeValue(XMLTags.RbmObservableSequenceAttrTag);
if (ses != null && ses.equals(RbmObservable.Sequence.PolymerLengthEqual.name())) {
se = RbmObservable.Sequence.PolymerLengthEqual;
} else if (ses != null && ses.equals(RbmObservable.Sequence.PolymerLengthGreater.name())) {
se = RbmObservable.Sequence.PolymerLengthGreater;
}
o.setSequence(se);
String lens = e.getAttributeValue(XMLTags.RbmObservableLenEqualAttrTag);
if (lens != null) {
// may be null for older models in which case the observable has default initial values
int len = Integer.parseInt(lens);
o.setSequenceLength(RbmObservable.Sequence.PolymerLengthEqual, len);
}
lens = e.getAttributeValue(XMLTags.RbmObservableLenGreaterAttrTag);
if (lens != null) {
int len = Integer.parseInt(lens);
o.setSequenceLength(RbmObservable.Sequence.PolymerLengthGreater, len);
}
// Element element = e.getChild(XMLTags.RbmSpeciesPatternTag, vcNamespace);
// SpeciesPattern sp = getSpeciesPattern(element, newModel);
List<Element> children = e.getChildren(XMLTags.RbmSpeciesPatternTag, vcNamespace);
for (Element e2 : children) {
SpeciesPattern sp = getSpeciesPattern(e2, newModel);
// setSpeciesPattern() will call resolveBonds()
if (sp != null) {
o.addSpeciesPattern(sp);
}
}
return o;
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class RbmNetworkGenerator method writeObservables.
public static void writeObservables(PrintWriter writer, RbmModelContainer rbmModelContainer, CompartmentMode compartmentMode) {
writer.println(BEGIN_OBSERVABLES);
List<RbmObservable> observablesList = rbmModelContainer.getObservableList();
for (RbmObservable oo : observablesList) {
writer.println(RbmUtils.toBnglString(oo, compartmentMode));
}
writer.println(END_OBSERVABLES);
writer.println();
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class Xmlproducer method getXML.
// private Element getXMLShort(SpeciesPattern param) {
// Element e = new Element(XMLTags.RbmSpeciesPatternTag);
// e.setAttribute(XMLTags.NameAttrTag, mangle(param.getId()));
// return e;
// }
private Element getXML(RbmObservable param) {
// if RbmObservableEmbedded we don't save the model or the structure
// we know which they are once we use the XmlReader to recreate the object
Element e = new Element(XMLTags.RbmObservableTag);
e.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
RbmObservable.ObservableType ot = param.getType();
e.setAttribute(XMLTags.RbmObservableTypeTag, mangle(ot.name()));
String sequenceName = param.getSequence().name();
e.setAttribute(XMLTags.RbmObservableSequenceAttrTag, sequenceName);
e.setAttribute(XMLTags.RbmObservableLenEqualAttrTag, "" + param.getSequenceLength(RbmObservable.Sequence.PolymerLengthEqual));
e.setAttribute(XMLTags.RbmObservableLenGreaterAttrTag, "" + param.getSequenceLength(RbmObservable.Sequence.PolymerLengthGreater));
e.setAttribute(XMLTags.StructureAttrTag, mangle(param.getStructure().getName()));
// SpeciesPattern sp = param.getSpeciesPattern(0);
// Element e1 = new Element(XMLTags.RbmSpeciesPatternTag);
// e1.setAttribute(XMLTags.NameAttrTag, mangle(sp.getId()));
// e.addContent(getXML(sp));
List<SpeciesPattern> spl = param.getSpeciesPatternList();
for (SpeciesPattern sp : spl) {
e.addContent(getXML(sp));
}
return e;
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class RbmObservableTreeCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setBorder(null);
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
obj = userObject;
String text = null;
Icon icon = null;
String toolTip = null;
if (userObject instanceof RbmObservable) {
RbmObservable ob = (RbmObservable) userObject;
text = toHtml(ob);
toolTip = toHtmlWithTip(ob);
icon = VCellIcons.rbmObservableIcon;
} else if (userObject instanceof SpeciesPatternLocal) {
SpeciesPatternLocal spl = (SpeciesPatternLocal) userObject;
text = toHtml(spl, true);
toolTip = toHtmlWithTip(spl, true);
icon = VCellIcons.rbmProductIcon;
} else if (userObject instanceof MolecularTypePattern) {
MolecularTypePattern molecularTypePattern = (MolecularTypePattern) userObject;
text = toHtml(molecularTypePattern, true);
toolTip = toHtmlWithTip(molecularTypePattern, true);
if (owner == null) {
icon = VCellIcons.rbmMolecularTypeSimpleIcon;
;
} else {
Graphics gc = owner.getGraphics();
icon = new MolecularTypeSmallShape(1, 5, molecularTypePattern.getMolecularType(), null, gc, molecularTypePattern.getMolecularType(), null, issueManager);
}
} else if (userObject instanceof MolecularComponentPattern) {
MolecularComponentPattern mcp = (MolecularComponentPattern) userObject;
text = toHtml(mcp, true);
toolTip = toHtmlWithTip(mcp, true);
icon = VCellIcons.rbmComponentGrayIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGrayStateIcon;
}
if (mcp.isbVisible()) {
icon = VCellIcons.rbmComponentGreenIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGreenStateIcon;
}
}
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp != null && !csp.isAny()) {
icon = VCellIcons.rbmComponentGreenIcon;
if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGreenStateIcon;
}
}
BioModelNode parent = (BioModelNode) ((BioModelNode) value).getParent().getParent().getParent();
if (parent == null) {
icon = VCellIcons.rbmComponentErrorIcon;
return this;
}
Object parentObject = parent.getUserObject();
if (!(parentObject instanceof RbmObservable)) {
icon = VCellIcons.rbmComponentErrorIcon;
return this;
}
if (hasErrorIssues((RbmObservable) parentObject, mcp, mcp.getMolecularComponent())) {
icon = VCellIcons.rbmComponentErrorIcon;
}
} else if (userObject instanceof StateLocal) {
StateLocal sl = (StateLocal) userObject;
text = toHtml(sl, true);
toolTip = toHtmlWithTip(sl, true);
icon = VCellIcons.rbmComponentStateIcon;
} else if (userObject instanceof BondLocal) {
BondLocal bl = (BondLocal) userObject;
text = toHtml(bl, sel);
toolTip = toHtmlWithTip(bl, true);
icon = VCellIcons.rbmBondIcon;
} else {
if (userObject != null) {
System.out.println(userObject.toString());
text = userObject.toString();
} else {
text = "null user object";
}
}
setText(text);
setIcon(icon);
setToolTipText(toolTip == null ? text : toolTip);
}
return this;
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class RbmTreeCellEditor method getTreeCellEditorComponent.
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component component = null;
realEditor = defaultCellEditor;
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
String text = null;
Icon icon = null;
if (userObject instanceof MolecularType) {
text = ((MolecularType) userObject).getName();
icon = VCellIcons.rbmMolecularTypeIcon;
} else if (userObject instanceof MolecularTypePattern) {
text = ((MolecularTypePattern) userObject).getMolecularType().getName();
icon = VCellIcons.rbmMolecularTypeIcon;
} else if (userObject instanceof MolecularComponent) {
BioModelNode parentNode = (BioModelNode) node.getParent();
Object parentObject = parentNode == null ? null : parentNode.getUserObject();
// TODO: look for the proper icon
icon = VCellIcons.rbmComponentErrorIcon;
if (parentObject instanceof MolecularType) {
text = ((MolecularComponent) userObject).getName();
} else if (parentObject instanceof MolecularTypePattern) {
realEditor = getMolecularComponentPatternCellEditor();
getMolecularComponentPatternCellEditor().molecularTypePattern = ((MolecularTypePattern) parentObject);
// find SpeciesPattern
while (true) {
parentNode = (BioModelNode) parentNode.getParent();
if (parentNode == null) {
break;
}
if (parentNode.getUserObject() instanceof RbmObservable) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.observable;
getMolecularComponentPatternCellEditor().speciesPattern = ((RbmObservable) parentNode.getUserObject()).getSpeciesPattern(0);
break;
}
if (parentNode.getUserObject() instanceof ReactionRule) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.reaction;
ReactionRulePropertiesTreeModel tm = (ReactionRulePropertiesTreeModel) tree.getModel();
switch(tm.getParticipantType()) {
case Reactant:
getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getReactantPattern(0).getSpeciesPattern();
break;
case Product:
getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getProductPattern(0).getSpeciesPattern();
break;
}
}
if (parentNode.getUserObject() instanceof SpeciesContext) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.species;
getMolecularComponentPatternCellEditor().speciesPattern = ((SpeciesContext) parentNode.getUserObject()).getSpeciesPattern();
break;
}
}
}
} else if (userObject instanceof ComponentStateDefinition) {
text = ((ComponentStateDefinition) userObject).getName();
icon = VCellIcons.rbmComponentStateIcon;
} else if (userObject instanceof RbmObservable) {
text = ((RbmObservable) userObject).getName();
icon = VCellIcons.rbmObservableIcon;
}
renderer.setOpenIcon(icon);
renderer.setClosedIcon(icon);
renderer.setLeafIcon(icon);
component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
if (editingComponent instanceof JTextField) {
JTextField textField = (JTextField) editingComponent;
textField.setText(text);
}
}
return component;
}
Aggregations