Search in sources :

Example 6 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class RbmMolecularTypeTreeCellEditor method getTreeCellEditorComponent.

@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
    Component component = null;
    realEditor = defaultCellEditor;
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            text = ((MolecularType) userObject).getName();
            icon = VCellIcons.rbmMolecularTypeIcon;
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            Object parentObject = parentNode == null ? null : parentNode.getUserObject();
            icon = VCellIcons.rbmComponentErrorIcon;
            text = ((MolecularComponent) userObject).getName();
        } else if (userObject instanceof ComponentStateDefinition) {
            text = ((ComponentStateDefinition) userObject).getName();
            icon = VCellIcons.rbmComponentStateIcon;
        } else {
            System.out.println("unexpected thing here " + userObject);
        }
        renderer.setOpenIcon(icon);
        renderer.setClosedIcon(icon);
        renderer.setLeafIcon(icon);
        component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
        if (editingComponent instanceof JTextField) {
            JTextField textField = (JTextField) editingComponent;
            textField.setText(text);
        }
    }
    return component;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) MolecularComponent(org.vcell.model.rbm.MolecularComponent) Component(java.awt.Component) JTextField(javax.swing.JTextField) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 7 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class RbmMolecularTypeTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    setBorder(null);
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        String toolTip = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            MolecularType mt = (MolecularType) userObject;
            text = toHtml(mt, true);
            toolTip = toHtmlWithTip(mt, true);
            if (owner == null) {
                icon = VCellIcons.rbmMolecularTypeSimpleIcon;
                ;
            } else {
                Graphics gc = owner.getGraphics();
                icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
            }
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            MolecularComponent mc = (MolecularComponent) userObject;
            text = toHtml(mc, true);
            toolTip = toHtmlWithTip(mc, true);
            icon = VCellIcons.rbmComponentGreenIcon;
            if (mc.getComponentStateDefinitions().size() > 0) {
                icon = VCellIcons.rbmComponentGreenStateIcon;
            }
            // here is how to set the cell minimum size !!!
            FontMetrics fm = getFontMetrics(getFont());
            int width = fm.stringWidth(text);
            setMinimumSize(new Dimension(width + 50, fm.getHeight() + 5));
        } else if (userObject instanceof ComponentStateDefinition) {
            ComponentStateDefinition cs = (ComponentStateDefinition) userObject;
            text = toHtml(cs);
            toolTip = toHtmlWithTip(cs);
            icon = VCellIcons.rbmComponentStateIcon;
        } else {
            System.out.println("unknown thingie " + userObject);
        }
        setText(text);
        setIcon(icon);
        setToolTipText(toolTip == null ? text : toolTip);
    }
    return this;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) FontMetrics(java.awt.FontMetrics) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) Dimension(java.awt.Dimension) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 8 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class BioModelEditorSpeciesTableModel method checkInputValue.

public String checkInputValue(String inputValue, int row, int column) {
    SpeciesContext speciesContext = getValueAt(row);
    String errMsg = null;
    switch(column) {
        case COLUMN_NAME:
            if (speciesContext == null || !speciesContext.getName().equals(inputValue)) {
                if (getModel().getSpeciesContext(inputValue) != null) {
                    errMsg = "Species '" + inputValue + "' already exists!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
            }
            break;
        case COLUMN_STRUCTURE:
            if (getModel().getStructure(inputValue) == null) {
                errMsg = "Structure '" + inputValue + "' does not exist!";
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
        case COLUMN_DEFINITION:
            try {
                inputValue = inputValue.trim();
                if (inputValue.length() > 0) {
                    // parsing will throw appropriate exception if molecular type or component don't exist
                    // our change
                    SpeciesPattern spThis = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
                    // here we can restrict what the user can do
                    for (MolecularTypePattern mtpThis : spThis.getMolecularTypePatterns()) {
                        MolecularType mtThis = mtpThis.getMolecularType();
                        for (MolecularComponent mcThis : mtThis.getComponentList()) {
                            // we check that each component is present in the molecular type pattern (as component pattern)
                            if (mtpThis.getMolecularComponentPattern(mcThis) == null) {
                                // not found
                                errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
                                errMsg += VCellErrorMessages.PressEscToUndo;
                                errMsg = "<html>" + errMsg + "</html>";
                                return errMsg;
                            } else if (mtpThis.getMolecularComponentPattern(mcThis).isImplied()) {
                                errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
                                errMsg += VCellErrorMessages.PressEscToUndo;
                                errMsg = "<html>" + errMsg + "</html>";
                                return errMsg;
                            } else {
                                // now need to also check the states
                                if (mcThis.getComponentStateDefinitions().size() == 0) {
                                    // nothing to do if the molecular component has no component state definition
                                    continue;
                                // note that we raise exception in parseSpeciesPattern() if we attempt to use an undefined state
                                // so no need to check that here
                                }
                                boolean found = false;
                                for (ComponentStateDefinition csThis : mcThis.getComponentStateDefinitions()) {
                                    MolecularComponentPattern mcpThis = mtpThis.getMolecularComponentPattern(mcThis);
                                    if ((mcpThis.getComponentStatePattern() == null) || mcpThis.getComponentStatePattern().isAny()) {
                                        // no component state pattern means no state, there's no point to check for this component again
                                        break;
                                    // we get out of the for and complain that we found no matching state
                                    }
                                    if (csThis.getName().equals(mcpThis.getComponentStatePattern().getComponentStateDefinition().getName())) {
                                        found = true;
                                    }
                                }
                                if (found == false) {
                                    // we should have found a matching state for the molecular component pattern
                                    errMsg = MolecularComponent.typeName + " " + mcThis.getDisplayName() + " of " + mtThis.getDisplayType() + " " + mtThis.getDisplayName() + " must be in one of the following states: ";
                                    for (int i = 0; i < mcThis.getComponentStateDefinitions().size(); i++) {
                                        ComponentStateDefinition csThis = mcThis.getComponentStateDefinitions().get(i);
                                        errMsg += csThis.getName();
                                        if (i < mcThis.getComponentStateDefinitions().size() - 1) {
                                            errMsg += ", ";
                                        }
                                    }
                                    errMsg += VCellErrorMessages.PressEscToUndo;
                                    errMsg = "<html>" + errMsg + "</html>";
                                    return errMsg;
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
    }
    return null;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 9 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class MolecularTypePropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    if (popupMenu == null) {
        popupMenu = new JPopupMenu();
    }
    if (popupMenu.isShowing()) {
        return;
    }
    selectClickPath(e);
    TreePath[] selectedPaths = molecularTypeTree.getSelectionPaths();
    boolean bDelete = true;
    boolean bAdd = true;
    if (selectedPaths == null) {
        return;
    }
    for (TreePath tp : selectedPaths) {
        Object obj = tp.getLastPathComponent();
        if (obj == null || !(obj instanceof BioModelNode)) {
            continue;
        }
        BioModelNode selectedNode = (BioModelNode) obj;
        Object userObject = selectedNode.getUserObject();
        if (userObject instanceof MolecularType) {
            getAddFromTreeMenuItem().setText("Add " + MolecularComponent.typeName);
            bAdd = true;
            bDelete = false;
        } else if (userObject instanceof MolecularComponent) {
            getAddFromTreeMenuItem().setText("Add " + ComponentStateDefinition.typeName);
            bAdd = true;
            bDelete = true;
        } else if (userObject instanceof ComponentStateDefinition) {
            bAdd = false;
            bDelete = true;
        }
    }
    popupMenu.removeAll();
    // everything can be renamed
    popupMenu.add(getRenameFromTreeMenuItem());
    if (bDelete) {
        popupMenu.add(getDeleteFromTreeMenuItem());
    }
    popupMenu.add(new JSeparator());
    if (bAdd) {
        popupMenu.add(getAddFromTreeMenuItem());
    }
    Point mousePoint = e.getPoint();
    popupMenu.show(molecularTypeTree, mousePoint.x, mousePoint.y);
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) TreePath(javax.swing.tree.TreePath) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) BioModelNode(cbit.vcell.desktop.BioModelNode) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 10 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition 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)

Aggregations

ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)31 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 MolecularType (org.vcell.model.rbm.MolecularType)15 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)10 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 BioModelNode (cbit.vcell.desktop.BioModelNode)8 LinkedHashMap (java.util.LinkedHashMap)7 Icon (javax.swing.Icon)7 Point (java.awt.Point)6 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)6 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)5 List (java.util.List)5 Graphics (java.awt.Graphics)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JMenuItem (javax.swing.JMenuItem)4 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)4 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4