Search in sources :

Example 16 with Reactant

use of cbit.vcell.model.Reactant in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method returns the XML represntation of a Simple reaction object.
 * Creation date: (2/27/2001 2:27:28 PM)
 * @return Element
 * @param param cbit.vcell.model.SimpleReaction
 */
private Element getXML(SimpleReaction param) throws XmlParseException {
    Element simplereaction = new Element(XMLTags.SimpleReactionTag);
    // Add attribute
    String nameStr = (param.getName() != null) ? (mangle(param.getName())) : "unnamed_SimpleReaction";
    simplereaction.setAttribute(XMLTags.StructureAttrTag, mangle(param.getStructure().getName()));
    simplereaction.setAttribute(XMLTags.NameAttrTag, nameStr);
    simplereaction.setAttribute(XMLTags.ReversibleAttrTag, mangle(Boolean.valueOf(param.isReversible()).toString()));
    if (param.getPhysicsOptions() == SimpleReaction.PHYSICS_ELECTRICAL_ONLY) {
        simplereaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionElectricalOnly);
    } else if (param.getPhysicsOptions() == SimpleReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
        simplereaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularAndElectrical);
    } else if (param.getPhysicsOptions() == SimpleReaction.PHYSICS_MOLECULAR_ONLY) {
        simplereaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularOnly);
    }
    // If keyFlag is on print the Keyvalue
    if (param.getKey() != null && this.printKeysFlag) {
        simplereaction.setAttribute(XMLTags.KeyValueAttrTag, param.getKey().toString());
    }
    // Add subelements: Reactants/Products/Catalysts
    // separate the order of the reactants, products, and modifiers.
    ReactionParticipant[] rpArray = param.getReactionParticipants();
    ArrayList<Element> products = new ArrayList<Element>();
    ArrayList<Element> modifiers = new ArrayList<Element>();
    for (int i = 0; i < rpArray.length; i++) {
        Element rp = getXML(rpArray[i]);
        if (rp != null) {
            if (rpArray[i] instanceof Reactant)
                simplereaction.addContent(rp);
            else if (rpArray[i] instanceof Product)
                products.add(rp);
            else if (rpArray[i] instanceof Catalyst)
                modifiers.add(rp);
        }
    }
    for (int i = 0; i < products.size(); i++) simplereaction.addContent((Element) products.get(i));
    for (int i = 0; i < modifiers.size(); i++) simplereaction.addContent((Element) modifiers.get(i));
    // Add kinetics
    simplereaction.addContent(getXML(param.getKinetics()));
    return simplereaction;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant) Catalyst(cbit.vcell.model.Catalyst)

Example 17 with Reactant

use of cbit.vcell.model.Reactant in project vcell by virtualcell.

the class SimulationContext method checkValidity.

public void checkValidity() throws MappingException {
    // spatial
    if (getGeometry().getDimension() > 0) {
    // 
    // fail if any enabled Reactions have LumpedKinetics.
    // 
    // StringBuffer buffer = new StringBuffer();
    // ReactionSpec[] reactionSpecs = getReactionContext().getReactionSpecs();
    // for (int i = 0; i < reactionSpecs.length; i++) {
    // if (!reactionSpecs[i].isExcluded() && reactionSpecs[i].getReactionStep().getKinetics() instanceof LumpedKinetics){
    // buffer.append("reaction \""+reactionSpecs[i].getReactionStep().getName()+"\" in compartment \""+reactionSpecs[i].getReactionStep().getStructure().getName()+"\"\n");
    // }
    // }
    // if (buffer.length()>0){
    // throw new MappingException("Spatial application \""+getName()+"\" cannot process reactions with spatially lumped kinetics, see kinetics for :\n"+buffer.toString());
    // 
    // }
    } else {
        // old-style ODE models should still work
        if (applicationType == Application.NETWORK_DETERMINISTIC && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().isAllSizeSpecifiedNull()) {
            // old style ODE models
            return;
        }
        // otherwise, all sizes should be present and positive.
        if (!getGeometryContext().isAllSizeSpecifiedPositive()) {
            throw new MappingException("Application " + getName() + ":\nAll structure sizes must be assigned positive values.\nPlease go to StructureMapping tab to check the sizes.");
        }
        // if rate rules are present, if any species has a rate rules, it should not be a reaction participant in any reaction.
        RateRule[] rateRules = getRateRules();
        if (rateRules != null && rateRules.length > 0) {
            if (getModel() != null) {
                ReactionStep[] reactionSteps = getModel().getReactionSteps();
                ReactionParticipant[] reactionParticipants = null;
                for (ReactionStep rs : reactionSteps) {
                    reactionParticipants = rs.getReactionParticipants();
                    for (ReactionParticipant rp : reactionParticipants) {
                        if (rp instanceof Reactant || rp instanceof Product) {
                            if (getRateRule(rp.getSpeciesContext()) != null) {
                                throw new RuntimeException("Species '" + rp.getSpeciesContext().getName() + "' is a reactant/product in reaction '" + rs.getName() + "' ; cannot also have a rate rule.");
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant)

Example 18 with Reactant

use of cbit.vcell.model.Reactant in project vcell by virtualcell.

the class SBMLImporter method addReactionParticipants.

/**
 * addReactionParticipant : Adds reactants and products and modifiers to a
 * reaction. Input args are the sbml reaction, vc reaction This method was
 * created mainly to handle reactions where there are reactants and/or
 * products that appear multiple times in a reaction. Virtual Cell now
 * allows the import of such reactions.
 */
private void addReactionParticipants(org.sbml.jsbml.Reaction sbmlRxn, ReactionStep vcRxn) throws Exception {
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    // if (!(vcRxn instanceof FluxReaction)) {
    if (true) {
        // reactants in sbmlRxn
        HashMap<String, Integer> sbmlReactantsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumReactants(); j++) {
            SpeciesReference spRef = sbmlRxn.getReactant(j);
            String sbmlReactantSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlReactantSpId) != null) {
                // check
                // if
                // spRef
                // is in
                // sbml
                // model
                // If stoichiometry of speciesRef is not an integer, it is
                // not handled in the VCell at this time; no point going
                // further
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for SBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the reactant '" + sbmlReactantSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the reactant '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlReactantsHash.get(sbmlReactantSpId) == null) {
                    // if sbmlReactantSpId is NOT in sbmlReactantsHash, add
                    // it with its stoichiometry
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlReactantSpId IS in sbmlReactantsHash, update
                    // its stoichiometry value to (existing-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlReactantsHash.get(sbmlReactantSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // sbmlReactionParticipantsHash as reactants to vcRxn
        for (Entry<String, Integer> es : sbmlReactantsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addReactant(speciesContext, stoich);
        }
        /*
			Iterator<String> sbmlReactantsIter = sbmlReactantsHash.keySet()
					.iterator();
			while (sbmlReactantsIter.hasNext()) {
				String sbmlReactantStr = sbmlReactantsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlReactantStr);
				int stoich = sbmlReactantsHash.get(sbmlReactantStr).intValue();
				((SimpleReaction) vcRxn).addReactant(speciesContext, stoich);
			}
			*/
        // products in sbmlRxn
        HashMap<String, Integer> sbmlProductsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumProducts(); j++) {
            SpeciesReference spRef = sbmlRxn.getProduct(j);
            String sbmlProductSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlProductSpId) != null) {
                /* check if spRef is in sbml model
					If stoichiometry of speciesRef is not an integer, it is
					not handled in the VCell at this time; no point going
					further */
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for sBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the product '" + sbmlProductSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the product '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlProductsHash.get(sbmlProductSpId) == null) {
                    // if sbmlProductSpId is NOT in sbmlProductsHash, add it
                    // with its stoichiometry
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlProductSpId IS in sbmlProductsHash, update its
                    // stoichiometry value to (existing-value-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlProductsHash.get(sbmlProductSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // as products to vcRxn
        for (Entry<String, Integer> es : sbmlProductsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addProduct(speciesContext, stoich);
        }
    /*
			Iterator<String> sbmlProductsIter = sbmlProductsHash.keySet()
					.iterator();
			while (sbmlProductsIter.hasNext()) {
				String sbmlProductStr = sbmlProductsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlProductStr);
				int stoich = sbmlProductsHash.get(sbmlProductStr).intValue();
				((SimpleReaction) vcRxn).addProduct(speciesContext, stoich);
			}
			*/
    // proxy.addProducts(sbmlProductsHash);
    }
    // modifiers
    for (int j = 0; j < (int) sbmlRxn.getNumModifiers(); j++) {
        ModifierSpeciesReference spRef = sbmlRxn.getModifier(j);
        String sbmlSpId = spRef.getSpecies();
        if (sbmlModel.getSpecies(sbmlSpId) != null) {
            // check if this modifier species is preesent in vcRxn (could
            // have been added as reactamt/product/catalyst).
            // If alreay a catalyst in vcRxn, do nothing
            ArrayList<ReactionParticipant> vcRxnParticipants = getVCReactionParticipantsFromSymbol(vcRxn, sbmlSpId);
            SpeciesContext speciesContext = vcModel.getSpeciesContext(sbmlSpId);
            if (vcRxnParticipants == null || vcRxnParticipants.size() == 0) {
                // If not in reactionParticipantList of vcRxn, add as
                // catalyst.
                vcRxn.addCatalyst(speciesContext);
            } else {
                for (ReactionParticipant rp : vcRxnParticipants) {
                    if (rp instanceof Reactant || rp instanceof Product) {
                        // If already a reactant or product in vcRxn, add
                        // warning to localIssuesList, don't do anything
                        localIssueList.add(new Issue(speciesContext, issueContext, IssueCategory.SBMLImport_Reaction, "Species " + speciesContext.getName() + " was already added as a reactant and/or product to " + vcRxn.getName() + "; Cannot add it as a catalyst also.", Issue.SEVERITY_INFO));
                        break;
                    }
                }
            }
        } else {
            // spRef is not in model, throw exception
            throw new SBMLImportException("Modifier '" + sbmlSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
        }
    // end - if (spRef is species in model)
    }
// end - for modifiers
}
Also used : Issue(org.vcell.util.Issue) HashMap(java.util.HashMap) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) SpeciesReference(org.sbml.jsbml.SpeciesReference) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 19 with Reactant

use of cbit.vcell.model.Reactant in project vcell by virtualcell.

the class ModelProcessEquation method computeEquationString.

private void computeEquationString() {
    if (modelProcess instanceof ReactionStep) {
        ReactionStep reactionStep = (ReactionStep) modelProcess;
        ReactionParticipant[] reactantParticipants = reactionStep.getReactionParticipants();
        ArrayList<ReactionParticipant> reactantList = new ArrayList<ReactionParticipant>();
        ArrayList<ReactionParticipant> productList = new ArrayList<ReactionParticipant>();
        // if (reactionStep instanceof SimpleReaction) {
        for (ReactionParticipant rp : reactantParticipants) {
            if (rp instanceof Reactant) {
                reactantList.add(rp);
            } else if (rp instanceof Product) {
                productList.add(rp);
            }
        }
        // } else {
        // Membrane membrane = (Membrane) ((FluxReaction)reactionStep).getStructure();
        // StructureTopology structTopology = reactionStep.getModel().getStructureTopology();
        // for (ReactionParticipant rp : reactantParticipants) {
        // if (rp instanceof Flux) {
        // Flux flux = (Flux)rp;
        // Feature scf = (Feature) flux.getSpeciesContext().getStructure();
        // if (structTopology.getInsideFeature(membrane) == scf) {
        // productList.add(rp);
        // } else {
        // reactantList.add(rp);
        // }
        // }
        // }
        // }
        StringBuffer sb = new StringBuffer();
        for (ReactionParticipant r : reactantList) {
            if (sb.length() > 0) {
                sb.append(" + ");
            }
            int stoichiometry = r.getStoichiometry();
            sb.append((stoichiometry > 1 ? stoichiometry : "") + r.getName());
        }
        equationleftHand = sb.toString();
        sb = new StringBuffer();
        for (ReactionParticipant p : productList) {
            if (sb.length() > 0) {
                sb.append(" + ");
            }
            int stoichiometry = p.getStoichiometry();
            sb.append((stoichiometry > 1 ? stoichiometry : "") + p.getName());
        }
        equationRightHand = sb.toString();
        equationString = equationleftHand + " " + REACTION_GOESTO + " " + equationRightHand;
    } else if (modelProcess instanceof ReactionRule) {
        ReactionRule reactionRuleEmbedded = (ReactionRule) modelProcess;
        equationString = RbmUtils.toBnglStringShort(reactionRuleEmbedded, CompartmentMode.hide);
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ReactionStep(cbit.vcell.model.ReactionStep) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant)

Example 20 with Reactant

use of cbit.vcell.model.Reactant in project vcell by virtualcell.

the class BioModelEditorModelPanel method initialize.

private void initialize() {
    newButton = new JButton("New");
    newButton2 = new JButton("New Rule");
    newMemButton = new JButton("New Membrane");
    deleteButton = new JButton("Delete");
    duplicateButton = new JButton("Duplicate");
    pathwayButton = new JButton("Pathway Links", new DownArrowIcon());
    pathwayButton.setHorizontalTextPosition(SwingConstants.LEFT);
    textFieldSearch = new JTextField();
    textFieldSearch.putClientProperty("JTextField.variant", "search");
    structuresTable = new EditorScrollTable();
    reactionsTable = new EditorScrollTable();
    speciesTable = new EditorScrollTable();
    molecularTypeTable = new EditorScrollTable();
    observablesTable = new EditorScrollTable();
    structureTableModel = new BioModelEditorStructureTableModel(structuresTable);
    reactionTableModel = new BioModelEditorReactionTableModel(reactionsTable);
    speciesTableModel = new BioModelEditorSpeciesTableModel(speciesTable);
    molecularTypeTableModel = new MolecularTypeTableModel(molecularTypeTable);
    observableTableModel = new ObservableTableModel(observablesTable);
    structuresTable.setModel(structureTableModel);
    reactionsTable.setModel(reactionTableModel);
    speciesTable.setModel(speciesTableModel);
    molecularTypeTable.setModel(molecularTypeTableModel);
    observablesTable.setModel(observableTableModel);
    reactionCartoonEditorPanel = new ReactionCartoonEditorPanel();
    reactionCartoonEditorPanel.addPropertyChangeListener(eventHandler);
    reactionCartoonEditorPanel.getReactionCartoonFull().addPropertyChangeListener(eventHandler);
    reactionCartoonEditorPanel.getReactionCartoonMolecule().addPropertyChangeListener(eventHandler);
    reactionCartoonEditorPanel.getReactionCartoonRule().addPropertyChangeListener(eventHandler);
    // cartoonEditorPanel  = new CartoonEditorPanelFixed();
    // cartoonEditorPanel.getStructureCartoon().addPropertyChangeListener(eventHandler);
    /* button panel */
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(newButton, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(newButton2, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(newMemButton, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(duplicateButton, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(deleteButton, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 5;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(pathwayButton, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 6;
    gbc.gridy = 0;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(4, 4, 4, 4);
    buttonPanel.add(Box.createRigidArea(new Dimension(5, 5)), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 7;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.LINE_END;
    gbc.insets = new Insets(4, 4, 4, 4);
    buttonPanel.add(new JLabel("Search "), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 8;
    gbc.gridy = 0;
    gbc.weightx = 1.5;
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(4, 4, 4, 4);
    buttonPanel.add(textFieldSearch, gbc);
    /* button panel */
    tabbedPane = new JTabbedPaneEnhanced();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    modelPanelTabs[ModelPanelTabID.reaction_diagram.ordinal()] = new ModelPanelTab(ModelPanelTabID.reaction_diagram, reactionCartoonEditorPanel, VCellIcons.diagramIcon);
    // modelPanelTabs[ModelPanelTabID.structure_diagram.ordinal()] = new ModelPanelTab(ModelPanelTabID.structure_diagram, cartoonEditorPanel, VCellIcons.structureIcon);
    modelPanelTabs[ModelPanelTabID.reaction_table.ordinal()] = new ModelPanelTab(ModelPanelTabID.reaction_table, reactionsTable.getEnclosingScrollPane(), VCellIcons.tableIcon);
    modelPanelTabs[ModelPanelTabID.structure_table.ordinal()] = new ModelPanelTab(ModelPanelTabID.structure_table, structuresTable.getEnclosingScrollPane(), VCellIcons.tableIcon);
    modelPanelTabs[ModelPanelTabID.species_table.ordinal()] = new ModelPanelTab(ModelPanelTabID.species_table, speciesTable.getEnclosingScrollPane(), VCellIcons.tableIcon);
    modelPanelTabs[ModelPanelTabID.species_definitions_table.ordinal()] = new ModelPanelTab(ModelPanelTabID.species_definitions_table, molecularTypeTable.getEnclosingScrollPane(), VCellIcons.tableIcon);
    modelPanelTabs[ModelPanelTabID.observables_table.ordinal()] = new ModelPanelTab(ModelPanelTabID.observables_table, observablesTable.getEnclosingScrollPane(), VCellIcons.tableIcon);
    tabbedPane.addChangeListener(eventHandler);
    tabbedPane.addMouseListener(eventHandler);
    for (ModelPanelTab tab : modelPanelTabs) {
        tab.getComponent().setBorder(GuiConstants.TAB_PANEL_BORDER);
        tabbedPane.addTab(tab.getName(), tab.getIcon(), tab.getComponent());
    }
    // tabbedPane.addChangeListener(changeListener);
    setLayout(new BorderLayout());
    add(tabbedPane, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
    newButton.addActionListener(eventHandler);
    newButton2.addActionListener(eventHandler);
    newMemButton.addActionListener(eventHandler);
    duplicateButton.addActionListener(eventHandler);
    duplicateButton.setEnabled(false);
    deleteButton.addActionListener(eventHandler);
    deleteButton.setEnabled(false);
    pathwayButton.addActionListener(eventHandler);
    pathwayButton.setEnabled(false);
    textFieldSearch.addActionListener(eventHandler);
    textFieldSearch.getDocument().addDocumentListener(eventHandler);
    structuresTable.getSelectionModel().addListSelectionListener(eventHandler);
    reactionsTable.getSelectionModel().addListSelectionListener(eventHandler);
    speciesTable.getSelectionModel().addListSelectionListener(eventHandler);
    molecularTypeTable.getSelectionModel().addListSelectionListener(eventHandler);
    observablesTable.getSelectionModel().addListSelectionListener(eventHandler);
    DefaultScrollTableCellRenderer tableRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof Structure) {
                setText(((Structure) value).getName());
            } else if (value instanceof Kinetics) {
                setText(((Kinetics) value).getKineticsDescription().getDescription());
            } else if (value instanceof RbmKineticLaw) {
                setText(((RbmKineticLaw) value).getRateLawType().name());
            }
            return this;
        }
    };
    RbmTableRenderer rbmTableRenderer = new RbmTableRenderer();
    structuresTable.setDefaultRenderer(Structure.class, tableRenderer);
    speciesTable.setDefaultRenderer(Structure.class, tableRenderer);
    reactionsTable.setDefaultRenderer(Structure.class, tableRenderer);
    reactionsTable.setDefaultRenderer(Kinetics.class, tableRenderer);
    reactionsTable.setDefaultRenderer(RbmKineticLaw.class, tableRenderer);
    reactionsTable.setDefaultRenderer(ModelProcessDynamics.class, tableRenderer);
    // Link to biopax object Table Cell Renderer
    DefaultScrollTableCellRenderer linkTableCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            BioModelEntityObject bioModelEntityObject = null;
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                if (table.getModel() == reactionTableModel && reactionTableModel.getValueAt(row) instanceof BioModelEntityObject) {
                    bioModelEntityObject = (BioModelEntityObject) reactionTableModel.getValueAt(row);
                } else if (table.getModel() == speciesTableModel) {
                    bioModelEntityObject = speciesTableModel.getValueAt(row);
                } else if (table.getModel() == molecularTypeTableModel) {
                    bioModelEntityObject = molecularTypeTableModel.getValueAt(row);
                }
                if (bioModelEntityObject != null) {
                    Set<RelationshipObject> relationshipSet = bioModel.getRelationshipModel().getRelationshipObjects(bioModelEntityObject);
                    if (relationshipSet.size() > 0) {
                        StringBuilder tooltip = new StringBuilder("<html>Links to Pathway objects:<br>");
                        for (RelationshipObject ro : relationshipSet) {
                            tooltip.append("<li>" + ro.getBioPaxObject() + "</li>");
                        }
                        if (!isSelected) {
                            setForeground(Color.blue);
                        }
                        String finalName = null;
                        BioPaxObject bioPaxObject = relationshipSet.iterator().next().getBioPaxObject();
                        if (bioPaxObject instanceof EntityImpl && ((EntityImpl) bioPaxObject).getName() != null && ((EntityImpl) bioPaxObject).getName().size() > 0) {
                            finalName = ((EntityImpl) bioPaxObject).getName().get(0);
                        } else if (bioPaxObject instanceof Conversion) {
                            Conversion mp = (Conversion) bioPaxObject;
                            finalName = "[" + bioPaxObject.getIDShort() + "]";
                        } else {
                            finalName = bioModelEntityObject.getName();
                        }
                        final int LIMIT = 40;
                        final String DOTS = "...";
                        if (finalName != null && finalName.length() > LIMIT) {
                            finalName = finalName.substring(0, LIMIT - DOTS.length() - 1) + DOTS;
                        }
                        setText("<html><u>" + finalName + "</u></html>");
                        setToolTipText(tooltip.toString());
                    }
                }
            }
            return this;
        }
    };
    // Annotations icon column renderer
    DefaultScrollTableCellRenderer annotationTableCellRenderer = new DefaultScrollTableCellRenderer() {

        final Color lightBlueBackground = new Color(214, 234, 248);

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            Identifiable entity = null;
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                if (table.getModel() == reactionTableModel) {
                    entity = (BioModelEntityObject) reactionTableModel.getValueAt(row);
                } else if (table.getModel() == speciesTableModel) {
                    entity = speciesTableModel.getValueAt(row);
                } else if (table.getModel() == molecularTypeTableModel) {
                    entity = molecularTypeTableModel.getValueAt(row);
                } else if (table.getModel() == observableTableModel) {
                    entity = observableTableModel.getValueAt(row);
                } else if (table.getModel() == structureTableModel) {
                    entity = structureTableModel.getValueAt(row);
                }
                if (entity != null) {
                    if (isSelected) {
                        setBackground(lightBlueBackground);
                    }
                    Identifiable identifiable = AnnotationsPanel.getIdentifiable(entity);
                    String freeText = bioModel.getVCMetaData().getFreeTextAnnotation(identifiable);
                    MiriamManager miriamManager = bioModel.getVCMetaData().getMiriamManager();
                    TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>> miriamDescrHeir = miriamManager.getMiriamTreeMap();
                    Map<MiriamRefGroup, MIRIAMQualifier> refGroupMap = miriamDescrHeir.get(identifiable);
                    Icon icon1 = VCellIcons.issueGoodIcon;
                    Icon icon2 = VCellIcons.issueGoodIcon;
                    if (freeText != null && !freeText.isEmpty()) {
                        icon2 = VCellIcons.noteIcon;
                    // icon = VCellIcons.bookmarkIcon;
                    // icon = VCellIcons.addIcon(icon, VCellIcons.linkIcon);
                    // icon = VCellIcons.addIcon(icon, VCellIcons.certificateIcon);
                    // icon = VCellIcons.addIcon(icon, VCellIcons.noteIcon);
                    }
                    if (refGroupMap != null && !refGroupMap.isEmpty()) {
                        icon1 = VCellIcons.linkIcon;
                    }
                    Icon icon = VCellIcons.addIcon(icon1, icon2);
                    setIcon(icon);
                }
            }
            return this;
        }
    };
    DefaultScrollTableCellRenderer rbmReactionExpressionCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == reactionTableModel) {
                    selectedObject = reactionTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof ReactionRule && value instanceof ModelProcessEquation) {
                        String text = "<html>";
                        text += "Reaction Rule";
                        text += "</html>";
                        setText(text);
                    } else {
                        // plain reaction, check if reactants have species pattern
                        ReactionStep rs = (ReactionStep) selectedObject;
                        String text = "<html>";
                        for (int i = 0; i < rs.getNumReactants(); i++) {
                            Reactant p = rs.getReactant(i);
                            if (p.getSpeciesContext().hasSpeciesPattern()) {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                // text += "<b>" + p.getName() + "</b>";
                                text += p.getName();
                            } else {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            }
                            if (i < rs.getNumReactants() - 1) {
                                text += " + ";
                            }
                        }
                        text += " -&gt; ";
                        for (int i = 0; i < rs.getNumProducts(); i++) {
                            Product p = rs.getProduct(i);
                            if (p.getSpeciesContext().hasSpeciesPattern()) {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                // text += "<b>" + p.getName() + "</b>";
                                text += p.getName();
                            } else {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            }
                            if (i < rs.getNumProducts() - 1) {
                                text += " + ";
                            }
                        }
                        text += "</html>";
                        setText(text);
                    }
                }
            }
            return this;
        }
    };
    DefaultScrollTableCellRenderer rbmReactionDefinitionCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == reactionTableModel) {
                    selectedObject = reactionTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof ReactionRule && value instanceof ModelProcessEquation) {
                        ReactionRule rr = (ReactionRule) selectedObject;
                        String text = "<html>";
                        for (int i = 0; i < rr.getReactantPatterns().size(); i++) {
                            ReactantPattern rp = rr.getReactantPattern(i);
                            if (rp.getStructure() != null && !rp.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
                                text += "@" + rp.getStructure().getName() + ":";
                            }
                            text += RbmUtils.toBnglString(rp.getSpeciesPattern(), null, CompartmentMode.hide, 0);
                            // text += RbmTableRenderer.toHtml(rp.getSpeciesPattern(), isSelected);
                            if (i < rr.getReactantPatterns().size() - 1) {
                                text += "+";
                            }
                        }
                        if (rr.isReversible()) {
                            // &lt;-&gt;  <->
                            text += " &lt;-&gt; ";
                        } else {
                            text += " -&gt; ";
                        }
                        for (int i = 0; i < rr.getProductPatterns().size(); i++) {
                            ProductPattern pp = rr.getProductPattern(i);
                            if (pp.getStructure() != null && !pp.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
                                text += "@" + pp.getStructure().getName() + ":";
                            }
                            text += RbmUtils.toBnglString(pp.getSpeciesPattern(), null, CompartmentMode.hide, 0);
                            if (i < rr.getProductPatterns().size() - 1) {
                                text += "+";
                            }
                        }
                        text += "</html>";
                        setText(text);
                    } else {
                        // plain reaction, check if reactants have species pattern
                        ReactionStep rs = (ReactionStep) selectedObject;
                        String text = "<html>";
                        for (int i = 0; i < rs.getNumReactants(); i++) {
                            Reactant p = rs.getReactant(i);
                            if (p.getSpeciesContext().hasSpeciesPattern()) {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            } else {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            }
                            if (i < rs.getNumReactants() - 1) {
                                text += " + ";
                            }
                        }
                        if (rs.isReversible()) {
                            // &lt;-&gt;  <->
                            text += " &lt;-&gt; ";
                        } else {
                            text += " -&gt; ";
                        }
                        for (int i = 0; i < rs.getNumProducts(); i++) {
                            Product p = rs.getProduct(i);
                            if (p.getSpeciesContext().hasSpeciesPattern()) {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            } else {
                                text += p.getStoichiometry() > 1 ? (p.getStoichiometry() + "") : "";
                                text += p.getName();
                            }
                            if (i < rs.getNumProducts() - 1) {
                                text += " + ";
                            }
                        }
                        text += "</html>";
                        setText(text);
                    }
                }
            }
            return this;
        }
    };
    DefaultScrollTableCellRenderer rbmObservablePatternCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == observableTableModel) {
                    selectedObject = observableTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof RbmObservable && value instanceof String) {
                        RbmObservable o = (RbmObservable) selectedObject;
                        String text = "<html>";
                        for (int i = 0; i < o.getSpeciesPatternList().size(); i++) {
                            SpeciesPattern sp = o.getSpeciesPattern(i);
                            text += RbmTableRenderer.toHtml(sp, isSelected);
                            if (i < o.getSpeciesPatternList().size() - 1) {
                                text += " ";
                            }
                        }
                        text = RbmUtils.appendSequence(text, o);
                        text += "</html>";
                        setText(text);
                    }
                }
            }
            return this;
        }
    };
    DefaultScrollTableCellRenderer rbmSpeciesNameCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == speciesTableModel) {
                    selectedObject = speciesTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof SpeciesContext) {
                        SpeciesContext sc = (SpeciesContext) selectedObject;
                        String text = "<html>";
                        if (sc.hasSpeciesPattern()) {
                            text += "<b>" + sc.getName() + "</b>";
                        } else {
                            text += sc.getName();
                        }
                        text += "</html>";
                        setText(text);
                    }
                }
            }
            return this;
        }
    };
    DefaultScrollTableCellRenderer reactionNameCellRenderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == reactionTableModel) {
                    selectedObject = reactionTableModel.getValueAt(row);
                }
                setToolTipText(null);
                if (selectedObject != null) {
                    if (selectedObject instanceof ReactionStep) {
                        ReactionStep rs = (ReactionStep) selectedObject;
                        String sbmlName = rs.getSbmlName();
                        if (sbmlName != null && !sbmlName.isEmpty()) {
                            String text = "<html>";
                            text += sbmlName;
                            text += "</html>";
                            setToolTipText(text);
                        } else {
                            setToolTipText(rs.getDisplayName());
                        }
                    } else if (selectedObject instanceof ReactionRule) {
                        ReactionRule rr = (ReactionRule) selectedObject;
                        setToolTipText(rr.getDisplayName());
                    }
                }
            }
            return this;
        }
    };
    // 
    // this renderer only paints the molecular type small shape in the MolecularType Table
    // 
    DefaultScrollTableCellRenderer rbmMolecularTypeShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

        MolecularTypeSmallShape stls = null;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == molecularTypeTableModel) {
                    selectedObject = molecularTypeTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof MolecularType) {
                        MolecularType mt = (MolecularType) selectedObject;
                        Graphics cellContext = table.getGraphics();
                        if (mt != null) {
                            stls = new MolecularTypeSmallShape(4, 3, mt, null, cellContext, mt, null, issueManager);
                        }
                    }
                } else {
                    stls = null;
                }
            }
            return this;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            if (stls != null) {
                stls.paintSelf(g);
            }
        }
    };
    // painting of species patterns small shapes inside the species context table
    DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

        SpeciesPatternSmallShape spss = null;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == speciesTableModel) {
                    selectedObject = speciesTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof SpeciesContext) {
                        SpeciesContext sc = (SpeciesContext) selectedObject;
                        // sp may be null for "plain" species contexts
                        SpeciesPattern sp = sc.getSpeciesPattern();
                        Graphics panelContext = table.getGraphics();
                        spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
                    }
                } else {
                    spss = null;
                }
            }
            setText("");
            return this;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            if (spss != null) {
                spss.paintSelf(g);
            }
        }
    };
    // ---------------------------------------------------------------------------------------------------------------------------------
    DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

        List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();

        SpeciesPatternSmallShape spss = null;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == reactionTableModel) {
                    selectedObject = reactionTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof ReactionRule) {
                        ReactionRule rr = (ReactionRule) selectedObject;
                        Graphics panelContext = table.getGraphics();
                        spssList.clear();
                        List<ReactantPattern> rpList = rr.getReactantPatterns();
                        int xPos = 4;
                        for (int i = 0; i < rpList.size(); i++) {
                            SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
                            if (i < rpList.size() - 1) {
                                spss.addEndText("+");
                            } else {
                                if (rr.isReversible()) {
                                    spss.addEndText("<->");
                                    xPos += 7;
                                } else {
                                    spss.addEndText("->");
                                }
                            }
                            xPos += spss.getWidth() + 15;
                            spssList.add(spss);
                        }
                        List<ProductPattern> ppList = rr.getProductPatterns();
                        xPos += 7;
                        for (int i = 0; i < ppList.size(); i++) {
                            SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
                            if (i < ppList.size() - 1) {
                                spss.addEndText("+");
                            }
                            xPos += spss.getWidth() + 15;
                            spssList.add(spss);
                        }
                    } else {
                        ReactionStep rs = (ReactionStep) selectedObject;
                        Graphics panelContext = table.getGraphics();
                        spssList.clear();
                        int xPos = 4;
                        int extraSpace = 0;
                        for (int i = 0; i < rs.getNumReactants(); i++) {
                            SpeciesPattern sp = rs.getReactant(i).getSpeciesContext().getSpeciesPattern();
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, rs, isSelected, issueManager);
                            if (i < rs.getNumReactants() - 1) {
                                spss.addEndText("+");
                            } else {
                                if (rs.isReversible()) {
                                    spss.addEndText("<->");
                                    extraSpace += 7;
                                } else {
                                    spss.addEndText("->");
                                }
                            }
                            int offset = sp == null ? 17 : 15;
                            offset += extraSpace;
                            int w = spss.getWidth();
                            xPos += w + offset;
                            spssList.add(spss);
                        }
                        xPos += 8;
                        for (int i = 0; i < rs.getNumProducts(); i++) {
                            SpeciesPattern sp = rs.getProduct(i).getSpeciesContext().getSpeciesPattern();
                            if (i == 0 && rs.getNumReactants() == 0) {
                                xPos += 14;
                            }
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, rs, isSelected, issueManager);
                            if (i == 0 && rs.getNumReactants() == 0) {
                                spss.addStartText("->");
                            }
                            if (i < rs.getNumProducts() - 1) {
                                spss.addEndText("+");
                            }
                            int offset = sp == null ? 17 : 15;
                            int w = spss.getWidth();
                            xPos += w + offset;
                            spssList.add(spss);
                        }
                    }
                } else {
                    spssList.clear();
                }
            }
            setText("");
            return this;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (SpeciesPatternSmallShape spss : spssList) {
                if (spss == null) {
                    continue;
                }
                spss.paintSelf(g);
            }
        }
    };
    // -------------------------------------------------------------------------------------------------------------------------------
    DefaultScrollTableCellRenderer rbmObservableShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

        List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();

        SpeciesPatternSmallShape spss = null;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (table.getModel() instanceof VCellSortTableModel<?>) {
                Object selectedObject = null;
                if (table.getModel() == observableTableModel) {
                    selectedObject = observableTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof RbmObservable) {
                        RbmObservable observable = (RbmObservable) selectedObject;
                        Graphics panelContext = table.getGraphics();
                        int xPos = 4;
                        spssList.clear();
                        for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
                            SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, observable, isSelected, issueManager);
                            xPos += spss.getWidth() + 6;
                            spssList.add(spss);
                        }
                    }
                } else {
                    spssList.clear();
                }
            }
            setText("");
            return this;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (SpeciesPatternSmallShape spss : spssList) {
                if (spss == null) {
                    continue;
                }
                spss.paintSelf(g);
            }
        }
    };
    // TODO: here are the renderers associated with the columns
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_NAME).setCellRenderer(reactionNameCellRenderer);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_LINK).setCellRenderer(linkTableCellRenderer);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_EQUATION).setCellRenderer(rbmReactionExpressionCellRenderer);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_DEFINITION).setCellRenderer(rbmReactionDefinitionCellRenderer);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_NOTES).setCellRenderer(annotationTableCellRenderer);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_NAME).setCellRenderer(rbmSpeciesNameCellRenderer);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_LINK).setCellRenderer(linkTableCellRenderer);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_NOTES).setCellRenderer(annotationTableCellRenderer);
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.link.ordinal()).setCellRenderer(linkTableCellRenderer);
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.notes.ordinal()).setCellRenderer(annotationTableCellRenderer);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.species_pattern.ordinal()).setCellRenderer(rbmObservablePatternCellRenderer);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.structure.ordinal()).setCellRenderer(tableRenderer);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.notes.ordinal()).setCellRenderer(annotationTableCellRenderer);
    structuresTable.getColumnModel().getColumn(BioModelEditorStructureTableModel.COLUMN_NOTES).setCellRenderer(annotationTableCellRenderer);
    // fixed width columns
    final int notesWidth = 65;
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.depiction.ordinal()).setMaxWidth(180);
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.notes.ordinal()).setPreferredWidth(notesWidth);
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.notes.ordinal()).setMaxWidth(notesWidth);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_NOTES).setPreferredWidth(notesWidth);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_NOTES).setMaxWidth(notesWidth);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.notes.ordinal()).setPreferredWidth(notesWidth);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.notes.ordinal()).setMaxWidth(notesWidth);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_DEPICTION).setPreferredWidth(180);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_NOTES).setPreferredWidth(notesWidth);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_NOTES).setMaxWidth(notesWidth);
    structuresTable.getColumnModel().getColumn(BioModelEditorStructureTableModel.COLUMN_NOTES).setPreferredWidth(notesWidth);
    structuresTable.getColumnModel().getColumn(BioModelEditorStructureTableModel.COLUMN_NOTES).setMaxWidth(notesWidth);
    // all "depictions" have their own renderer
    molecularTypeTable.getColumnModel().getColumn(MolecularTypeTableModel.Column.depiction.ordinal()).setCellRenderer(rbmMolecularTypeShapeDepictionCellRenderer);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_DEPICTION).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
    speciesTable.getColumnModel().getColumn(BioModelEditorSpeciesTableModel.COLUMN_DEFINITION).setCellRenderer(rbmTableRenderer);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.depiction.ordinal()).setCellRenderer(rbmObservableShapeDepictionCellRenderer);
    reactionsTable.getColumnModel().getColumn(BioModelEditorReactionTableModel.COLUMN_DEPICTION).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
    observablesTable.getColumnModel().getColumn(ObservableTableModel.Column.type.ordinal()).setCellEditor(observableTableModel.getObservableTypeComboBoxEditor());
    observableTableModel.updateObservableTypeComboBox();
    reactionsTable.addMouseListener(eventHandler);
    reactionsTable.addKeyListener(eventHandler);
    speciesTable.addMouseListener(eventHandler);
    speciesTable.addKeyListener(eventHandler);
    molecularTypeTable.addMouseListener(eventHandler);
    molecularTypeTable.addKeyListener(eventHandler);
    observablesTable.addMouseListener(eventHandler);
    observablesTable.addKeyListener(eventHandler);
    structuresTable.addMouseListener(eventHandler);
    structuresTable.addKeyListener(eventHandler);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) RelationshipObject(org.vcell.relationship.RelationshipObject) Reactant(cbit.vcell.model.Reactant) JTabbedPaneEnhanced(org.vcell.util.gui.JTabbedPaneEnhanced) BorderLayout(java.awt.BorderLayout) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) EntityImpl(org.vcell.pathway.EntityImpl) Color(java.awt.Color) RbmObservable(cbit.vcell.model.RbmObservable) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) Conversion(org.vcell.pathway.Conversion) Identifiable(org.vcell.util.document.Identifiable) ReactionCartoonEditorPanel(cbit.vcell.graph.gui.ReactionCartoonEditorPanel) MolecularType(org.vcell.model.rbm.MolecularType) JTable(javax.swing.JTable) ReactionStep(cbit.vcell.model.ReactionStep) RelationshipObject(org.vcell.relationship.RelationshipObject) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) BioPaxObject(org.vcell.pathway.BioPaxObject) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) Kinetics(cbit.vcell.model.Kinetics) DownArrowIcon(org.vcell.util.gui.DownArrowIcon) Icon(javax.swing.Icon) StructureToolShapeIcon(cbit.vcell.graph.gui.StructureToolShapeIcon) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier) MiriamManager(cbit.vcell.biomodel.meta.MiriamManager) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) BioPaxObject(org.vcell.pathway.BioPaxObject) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Structure(cbit.vcell.model.Structure) MiriamRefGroup(cbit.vcell.biomodel.meta.MiriamManager.MiriamRefGroup) ReactantPattern(cbit.vcell.model.ReactantPattern) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) RbmKineticLaw(cbit.vcell.model.RbmKineticLaw) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) DownArrowIcon(org.vcell.util.gui.DownArrowIcon) ModelProcessEquation(cbit.gui.ModelProcessEquation) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer)

Aggregations

Reactant (cbit.vcell.model.Reactant)37 Product (cbit.vcell.model.Product)33 ReactionParticipant (cbit.vcell.model.ReactionParticipant)32 ReactionStep (cbit.vcell.model.ReactionStep)25 SpeciesContext (cbit.vcell.model.SpeciesContext)22 SimpleReaction (cbit.vcell.model.SimpleReaction)14 FluxReaction (cbit.vcell.model.FluxReaction)12 Model (cbit.vcell.model.Model)12 Structure (cbit.vcell.model.Structure)12 ArrayList (java.util.ArrayList)12 Catalyst (cbit.vcell.model.Catalyst)11 Expression (cbit.vcell.parser.Expression)10 HashMap (java.util.HashMap)9 Kinetics (cbit.vcell.model.Kinetics)8 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)8 ReactionRule (cbit.vcell.model.ReactionRule)8 Membrane (cbit.vcell.model.Membrane)7 Issue (org.vcell.util.Issue)7 Feature (cbit.vcell.model.Feature)6 LumpedKinetics (cbit.vcell.model.LumpedKinetics)6