use of cbit.vcell.model.ReactionRule 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 cbit.vcell.model.ReactionRule 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 cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class MolecularTypeLargeShape method flash.
public void flash(String matchKey) {
if (!(owner instanceof ReactionRule)) {
return;
}
if (mtp != null && mtp.hasExplicitParticipantMatch() && mtp.getParticipantMatchLabel().equals(matchKey)) {
Graphics g = shapePanel.getGraphics();
Graphics2D g2 = (Graphics2D) g;
Font fontOld = g2.getFont();
Color colorOld = g2.getColor();
Color color = (Color.red).darker();
Font font = deriveMoleculeFontBold(g, shapePanel);
Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
g.setFont(smallerFont);
FontMetrics fm = g.getFontMetrics(font);
int stringWidth = fm.stringWidth(name);
int textX = xPos + 11;
int textY = yPos + baseHeight - (baseHeight - smallerFont.getSize()) / 2;
g.setColor(color);
g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
g.setFont(fontOld);
g.setColor(colorOld);
}
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ReactionCartoonFull method setPositionsFromReactionCartoon.
public void setPositionsFromReactionCartoon(Diagram diagram) {
List<NodeReference> nodeList = new ArrayList<NodeReference>();
NodeReference.Mode mode = NodeReference.Mode.full;
for (Shape shape : getShapes()) {
if (shape instanceof FluxReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SimpleReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof ReactionRuleDiagramShape) {
nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SpeciesContextShape) {
nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
} else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
System.out.println("ReactionCartoonFull, Invalid shape type 'RuleParticipantSignatureShortDiagramShape'");
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
}
}
diagram.setNodeReferences(mode, nodeList);
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ReactionCartoonMolecule method setPositionsFromReactionCartoon.
public void setPositionsFromReactionCartoon(Diagram diagram) {
List<NodeReference> nodeList = new ArrayList<NodeReference>();
NodeReference.Mode mode = NodeReference.Mode.molecule;
for (Shape shape : getShapes()) {
if (shape instanceof FluxReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SimpleReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof ReactionRuleDiagramShape) {
nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SpeciesContextShape) {
nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
System.out.println("ReactionCartoonMolecule, Invalid shape type 'RuleParticipantSignatureFullDiagramShape'");
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
} else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
}
}
diagram.setNodeReferences(mode, nodeList);
}
Aggregations