Search in sources :

Example 21 with MolecularType

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());
    }
}
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 22 with MolecularType

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);
            }
        }
    }
}
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 23 with MolecularType

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);
            }
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with MolecularType

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;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) ReactionRule(cbit.vcell.model.ReactionRule) BioPaxObject(org.vcell.pathway.BioPaxObject) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Example 25 with MolecularType

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);
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Color(java.awt.Color) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Graphics2D(java.awt.Graphics2D)

Aggregations

MolecularType (org.vcell.model.rbm.MolecularType)78 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)25 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 Structure (cbit.vcell.model.Structure)20 ArrayList (java.util.ArrayList)20 ReactionRule (cbit.vcell.model.ReactionRule)19 SpeciesContext (cbit.vcell.model.SpeciesContext)19 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 PropertyVetoException (java.beans.PropertyVetoException)15 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)15 RbmObservable (cbit.vcell.model.RbmObservable)14 List (java.util.List)13 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)12 Point (java.awt.Point)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)12 BioPaxObject (org.vcell.pathway.BioPaxObject)11 RelationshipObject (org.vcell.relationship.RelationshipObject)11 BioModelNode (cbit.vcell.desktop.BioModelNode)10 ModelException (cbit.vcell.model.ModelException)10 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)9