use of org.vcell.model.rbm.MolecularType 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());
}
}
use of org.vcell.model.rbm.MolecularType 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);
}
}
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class BioModel method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
//
if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals("mathDescription") && evt.getNewValue() != null) {
if (fieldSimulations != null) {
for (int i = 0; i < fieldSimulations.length; i++) {
if (fieldSimulations[i].getMathDescription() == evt.getOldValue()) {
try {
fieldSimulations[i].setMathDescription((MathDescription) evt.getNewValue());
} catch (PropertyVetoException e) {
System.out.println("error propagating math from SimulationContext '" + ((SimulationContext) evt.getSource()).getName() + "' to Simulation '" + fieldSimulations[i].getName());
e.printStackTrace(System.out);
}
}
}
}
}
//
if (evt.getSource() == this && evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_SIMULATIONS) && evt.getNewValue() != null) {
//
if (evt.getOldValue() != null) {
Simulation[] simulations = (Simulation[]) evt.getOldValue();
for (int i = 0; i < simulations.length; i++) {
simulations[i].removeVetoableChangeListener(this);
simulations[i].removePropertyChangeListener(this);
}
}
//
if (evt.getOldValue() != null) {
Simulation[] simulations = (Simulation[]) evt.getNewValue();
for (int i = 0; i < simulations.length; i++) {
simulations[i].addVetoableChangeListener(this);
simulations[i].addPropertyChangeListener(this);
}
}
}
if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_SIMULATION_CONTEXTS) && evt.getNewValue() != null) {
//
if (evt.getOldValue() != null) {
SimulationContext[] simulationContexts = (SimulationContext[]) evt.getOldValue();
for (int i = 0; i < simulationContexts.length; i++) {
simulationContexts[i].removeVetoableChangeListener(this);
simulationContexts[i].removePropertyChangeListener(this);
}
}
//
if (evt.getOldValue() != null) {
SimulationContext[] simulationContexts = (SimulationContext[]) evt.getNewValue();
for (int i = 0; i < simulationContexts.length; i++) {
simulationContexts[i].addVetoableChangeListener(this);
simulationContexts[i].addPropertyChangeListener(this);
}
}
}
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS) || evt.getPropertyName().equals(Model.PROPERTY_NAME_REACTION_STEPS))) {
// remove the relationship objects if the biomodelEntity objects were removed
Set<BioModelEntityObject> removedObjects = relationshipModel.getBioModelEntityObjects();
for (SpeciesContext sc : fieldModel.getSpeciesContexts()) {
removedObjects.remove(sc);
}
for (ReactionStep rs : fieldModel.getReactionSteps()) {
removedObjects.remove(rs);
}
for (MolecularType mt : fieldModel.getRbmModelContainer().getMolecularTypeList()) {
removedObjects.remove(mt);
}
for (ReactionRule rr : fieldModel.getRbmModelContainer().getReactionRuleList()) {
removedObjects.remove(rr);
}
relationshipModel.removeRelationshipObjects(removedObjects);
}
// adjust the relationship model when a molecule gets deleted
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST))) {
@SuppressWarnings("unchecked") List<MolecularType> oldListCopy = new ArrayList<MolecularType>((List<MolecularType>) evt.getOldValue());
@SuppressWarnings("unchecked") List<MolecularType> newList = (List<MolecularType>) evt.getNewValue();
if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
// something got deleted
oldListCopy.removeAll(newList);
for (MolecularType removedMt : oldListCopy) {
relationshipModel.removeRelationshipObject(removedMt);
}
}
}
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST))) {
@SuppressWarnings("unchecked") List<ReactionRule> oldListCopy = new ArrayList<ReactionRule>((List<ReactionRule>) evt.getOldValue());
@SuppressWarnings("unchecked") List<ReactionRule> newList = (List<ReactionRule>) evt.getNewValue();
if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
// something got deleted
oldListCopy.removeAll(newList);
for (ReactionRule removedRr : oldListCopy) {
relationshipModel.removeRelationshipObject(removedRr);
}
}
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class BioModel method getVCID.
public VCID getVCID(Identifiable identifiable) {
String localName;
String className;
if (identifiable instanceof SpeciesContext) {
localName = ((SpeciesContext) identifiable).getName();
className = "SpeciesContext";
} else if (identifiable instanceof Species) {
localName = ((Species) identifiable).getCommonName();
className = VCID.CLASS_SPECIES;
} else if (identifiable instanceof Structure) {
localName = ((Structure) identifiable).getName();
className = "Structure";
} else if (identifiable instanceof ReactionStep) {
localName = ((ReactionStep) identifiable).getName();
className = VCID.CLASS_REACTION_STEP;
} else if (identifiable instanceof BioModel) {
localName = ((BioModel) identifiable).getName();
className = VCID.CLASS_BIOMODEL;
// }else if (identifiable instanceof SimulationContext){
// localName = ((SimulationContext)identifiable).getName();
// className = "Application";
} else if (identifiable instanceof BioPaxObject) {
localName = ((BioPaxObject) identifiable).getID();
className = "BioPaxObject";
} else if (identifiable instanceof MolecularType) {
localName = ((MolecularType) identifiable).getName();
className = "MolecularType";
} else if (identifiable instanceof ReactionRule) {
localName = ((ReactionRule) identifiable).getName();
className = "ReactionRule";
} else if (identifiable instanceof RbmObservable) {
localName = ((RbmObservable) identifiable).getName();
className = "RbmObservable";
} else {
throw new RuntimeException("unsupported Identifiable class");
}
localName = TokenMangler.mangleVCId(localName);
VCID vcid;
try {
vcid = VCID.fromString(className + "(" + localName + ")");
} catch (VCID.InvalidVCIDException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
return vcid;
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class MolecularComponentSmallShape method paintComponent.
// ----------------------------------------------------------------------------------------------
private void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g.getColor();
Color componentColor = setComponentColor();
g2.setColor(componentColor);
// g.fillRect(xPos, yPos, width, height);
g2.fillOval(xPos, yPos, componentDiameter, componentDiameter);
g2.setColor(getDefaultColor(Color.black));
g2.drawOval(xPos, yPos, componentDiameter, componentDiameter);
if (mc.getComponentStateDefinitions().size() > 0) {
if (getDisplayRequirements() == DisplayRequirements.highlightBonds) {
g2.setColor(componentVeryLightGray);
} else {
g2.setColor(componentVeryLightGray);
if (owner instanceof MolecularType) {
if (hasErrorIssues(owner, mc)) {
g2.setColor(Color.red);
} else {
if (shapeManager != null && !shapeManager.isShowMoleculeColor()) {
g2.setColor(componentVeryLightGray);
} else {
g2.setColor(Color.yellow);
}
}
} else if (mcp != null) {
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp != null && !csp.isAny()) {
if (shapeManager != null && !shapeManager.isShowMoleculeColor()) {
g2.setColor(componentVeryLightGray);
} else {
g2.setColor(Color.yellow);
}
}
}
}
g2.fillOval(xPos + width - 5, yPos - 2, 5, 5);
g.setColor(getDefaultColor(Color.darkGray));
g2.drawOval(xPos + width - 5, yPos - 2, 5, 5);
}
g.setColor(colorOld);
}
Aggregations