Search in sources :

Example 51 with MolecularTypePattern

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

the class ObservablePropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    boolean bDelete = false;
    boolean bAdd = false;
    boolean bEdit = false;
    boolean bRename = false;
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    final Object deepestShape = locationContext.getDeepestShape();
    final RbmElementAbstract selectedObject;
    if (deepestShape == null) {
        selectedObject = null;
        // when cursor is outside any species pattern we offer to add a new one
        System.out.println("outside");
        popupFromShapeMenu.add(getAddSpeciesPatternFromShapeMenuItem());
    } else if (deepestShape instanceof ComponentStateLargeShape) {
        System.out.println("inside state");
        if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStatePattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularComponentLargeShape) {
        System.out.println("inside component");
        if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponentPattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularTypeLargeShape) {
        System.out.println("inside molecule");
        if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularTypePattern();
        } else {
            return;
        }
    } else if (deepestShape instanceof SpeciesPatternLargeShape) {
        System.out.println("inside species pattern");
        if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
        } else {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    if (selectedObject instanceof SpeciesPattern) {
        getAddFromShapeMenu().setText(VCellErrorMessages.AddMolecularTypes);
        getAddFromShapeMenu().removeAll();
        for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
            JMenuItem menuItem = new JMenuItem(mt.getName());
            Graphics gc = splitPaneHorizontal.getGraphics();
            Icon icon = new MolecularTypeSmallShape(4, 4, mt, null, gc, mt, null, issueManager);
            menuItem.setIcon(icon);
            getAddFromShapeMenu().add(menuItem);
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
                    ((SpeciesPattern) selectedObject).addMolecularTypePattern(molecularTypePattern);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                        }
                    });
                }
            });
        }
        JMenu compartmentMenuItem = new JMenu("Specify structure (for all)");
        compartmentMenuItem.removeAll();
        for (final Structure struct : bioModel.getModel().getStructures()) {
            JMenuItem menuItem = new JMenuItem(struct.getName());
            compartmentMenuItem.add(menuItem);
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    String nameStruct = e.getActionCommand();
                    Structure struct = bioModel.getModel().getStructure(nameStruct);
                    observable.setStructure(struct);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            // repaint tree
                            observableTreeModel.populateTree();
                        // observableTree.scrollPathToVisible(path);	// scroll back up to show the observable
                        }
                    });
                }
            });
        }
        JMenuItem deleteMenuItem = new JMenuItem("Delete Species Pattern");
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                // observable.getSpeciesPatternList().remove((SpeciesPattern)selectedObject);
                observable.removeSpeciesPattern((SpeciesPattern) selectedObject);
                final TreePath path = observableTreeModel.findObjectPath(null, observable);
                observableTree.setSelectionPath(path);
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        // repaint tree
                        observableTreeModel.populateTree();
                        // scroll back up to show the observable
                        observableTree.scrollPathToVisible(path);
                    }
                });
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(getAddFromShapeMenu());
        popupFromShapeMenu.add(compartmentMenuItem);
    } else if (selectedObject instanceof MolecularTypePattern) {
        MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
        String moveRightMenuText = "Move <b>" + "right" + "</b>";
        moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
        JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
        Icon icon = VCellIcons.moveRightIcon;
        moveRightMenuItem.setIcon(icon);
        moveRightMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.shiftRight(from);
                observableTreeModel.populateTree();
            }
        });
        popupFromShapeMenu.add(moveRightMenuItem);
        String moveLeftMenuText = "Move <b>" + "left" + "</b>";
        moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
        JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
        icon = VCellIcons.moveLeftIcon;
        moveLeftMenuItem.setIcon(icon);
        moveLeftMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.shiftLeft(from);
                observableTreeModel.populateTree();
            }
        });
        popupFromShapeMenu.add(moveLeftMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
        deleteMenuText = "<html>" + deleteMenuText + "</html>";
        JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.removeMolecularTypePattern(mtp);
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
    } else if (selectedObject instanceof MolecularComponentPattern) {
        manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
        bDelete = false;
    } else if (selectedObject instanceof ComponentStatePattern) {
        MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
        manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
    }
    if (bRename) {
        popupFromShapeMenu.add(getRenameFromShapeMenuItem());
    }
    if (bDelete) {
        popupFromShapeMenu.add(getDeleteFromShapeMenuItem());
    }
    if (bEdit) {
        popupFromShapeMenu.add(getEditFromShapeMenuItem());
    }
    if (bAdd) {
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(getAddFromShapeMenu());
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) JMenuItem(javax.swing.JMenuItem) Structure(cbit.vcell.model.Structure) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmElementAbstract(org.vcell.model.rbm.RbmElementAbstract) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) JMenu(javax.swing.JMenu)

Example 52 with MolecularTypePattern

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

the class ObservableTableModel method isCellEditable.

public boolean isCellEditable(int row, int columnIndex) {
    Column col = Column.values()[columnIndex];
    if (col == Column.name) {
        return true;
    }
    RbmObservable o = getValueAt(row);
    if (o == null) {
        return false;
    }
    if (col == Column.structure) {
        return false;
    }
    if (col == Column.type) {
        return true;
    }
    if (col == Column.depiction) {
        return false;
    }
    final List<SpeciesPattern> spList = o.getSpeciesPatternList();
    for (SpeciesPattern sp : spList) {
        final List<MolecularTypePattern> mtpList = sp.getMolecularTypePatterns();
        for (MolecularTypePattern mtp : mtpList) {
            MolecularType mt = mtp.getMolecularType();
            if (mt.getComponentList().size() != 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) RbmObservable(cbit.vcell.model.RbmObservable) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 53 with MolecularTypePattern

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

the class ObservableTableModel method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    super.propertyChange(evt);
    Object source = evt.getSource();
    // if (source == getModel().getRbmModelContainer()) {
    if (source == getModel()) {
        if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST)) {
            refreshData();
            List<RbmObservable> oldValue = (List<RbmObservable>) evt.getOldValue();
            if (oldValue != null) {
                for (RbmObservable observable : oldValue) {
                    observable.removePropertyChangeListener(this);
                    SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
                    RbmUtils.removePropertyChangeListener(speciesPattern, this);
                }
            }
            List<RbmObservable> newValue = (List<RbmObservable>) evt.getNewValue();
            if (newValue != null) {
                for (RbmObservable observable : newValue) {
                    observable.addPropertyChangeListener(this);
                    SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
                    RbmUtils.addPropertyChangeListener(speciesPattern, this);
                }
            }
        } else if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST)) {
            // we need this?
            refreshData();
        }
    } else if (source instanceof RbmObservable) {
        RbmObservable mt = (RbmObservable) source;
        int changeRow = getRowIndex(mt);
        if (changeRow >= 0) {
            fireTableRowsUpdated(changeRow, changeRow);
        }
    // if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
    // SpeciesPattern oldValue = (SpeciesPattern) evt.getOldValue();
    // if (oldValue != null) {
    // RbmUtils.removePropertyChangeListener(oldValue, this);
    // }
    // SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
    // if (newValue != null) {
    // RbmUtils.addPropertyChangeListener(newValue, this);
    // }
    // }
    } else if (source instanceof SpeciesPattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
            List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
            if (oldValue != null) {
                for (MolecularTypePattern mtp : oldValue) {
                    RbmUtils.removePropertyChangeListener(mtp, this);
                }
            }
            List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
            if (newValue != null) {
                for (MolecularTypePattern mtp : newValue) {
                    RbmUtils.addPropertyChangeListener(mtp, this);
                }
            }
        }
    } else if (source instanceof MolecularTypePattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
            List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
            if (oldValue != null) {
                for (MolecularComponentPattern mcp : oldValue) {
                    RbmUtils.removePropertyChangeListener(mcp, this);
                }
            }
            List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
            if (newValue != null) {
                for (MolecularComponentPattern mcp : newValue) {
                    RbmUtils.addPropertyChangeListener(mcp, this);
                }
            }
        }
    } else if (source instanceof MolecularComponentPattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (source.equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
            ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
            if (oldValue != null) {
                oldValue.removePropertyChangeListener(this);
            }
            ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
            if (newValue != null) {
                newValue.addPropertyChangeListener(this);
            }
        }
    } else if (evt.getSource() instanceof MolecularComponent) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    } else if (evt.getSource() instanceof ComponentStateDefinition) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    }
// updateStructureComboBox();
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 54 with MolecularTypePattern

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

the class ObservableTreeModel method populateTree.

public void populateTree() {
    if (observable == null || bioModel == null) {
        return;
    }
    rootNode.setUserObject(observable);
    rootNode.removeAllChildren();
    int count = 0;
    for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
        BioModelNode spNode = new BioModelNode(new SpeciesPatternLocal(sp, ++count));
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            BioModelNode node = createMolecularTypePatternNode(mtp);
            spNode.add(node);
        }
        rootNode.add(spNode);
    }
    nodeStructureChanged(rootNode);
    // GuiUtils.treeExpandAll(ownerTree, rootNode, true);
    GuiUtils.treeExpandAllRows(ownerTree);
    observable.firePropertyChange("entityChange", null, "bbb");
}
Also used : BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 55 with MolecularTypePattern

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

the class ObservableTreeModel method propertyChange.

public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
        nodeChanged(rootNode);
    } else if (evt.getSource() == observable && evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_TYPE)) {
        nodeChanged(rootNode);
    } else if (evt.getPropertyName().equals("entityChange")) {
        nodeChanged(rootNode);
    } else {
        populateTree();
        Object source = evt.getSource();
        if (source == observable) {
            if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
                List<SpeciesPattern> oldValue = (List<SpeciesPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (SpeciesPattern sp : oldValue) {
                        RbmUtils.removePropertyChangeListener(sp, this);
                    }
                }
                List<SpeciesPattern> newValue = (List<SpeciesPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (SpeciesPattern sp : newValue) {
                        RbmUtils.addPropertyChangeListener(sp, this);
                    }
                }
            } else if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN)) {
                SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
                if (newValue != null) {
                    RbmUtils.addPropertyChangeListener(newValue, this);
                }
            }
        } else if (source instanceof SpeciesPattern) {
            if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
                List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularTypePattern mtp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mtp, this);
                    }
                }
                List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularTypePattern mtp : newValue) {
                        RbmUtils.addPropertyChangeListener(mtp, this);
                    }
                }
            }
        } else if (source instanceof MolecularTypePattern) {
            if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
                List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularComponentPattern mcp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mcp, this);
                    }
                }
                List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularComponentPattern mcp : newValue) {
                        RbmUtils.addPropertyChangeListener(mcp, this);
                    }
                }
            }
        } else if (source instanceof MolecularComponentPattern) {
            if (evt.getSource().equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
                ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
                if (oldValue != null) {
                    oldValue.removePropertyChangeListener(this);
                }
                ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
                if (newValue != null) {
                    newValue.addPropertyChangeListener(this);
                }
            }
        }
    }
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Aggregations

MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)72 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)39 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)19 Graphics (java.awt.Graphics)16 MolecularType (org.vcell.model.rbm.MolecularType)16 Point (java.awt.Point)14 BioModelNode (cbit.vcell.desktop.BioModelNode)11 RbmObservable (cbit.vcell.model.RbmObservable)10 SpeciesContext (cbit.vcell.model.SpeciesContext)10 Icon (javax.swing.Icon)10 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 MolecularComponent (org.vcell.model.rbm.MolecularComponent)10 ArrayList (java.util.ArrayList)9 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)7 ReactionRule (cbit.vcell.model.ReactionRule)7 LinkedHashMap (java.util.LinkedHashMap)7 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6