Search in sources :

Example 1 with StructureToolShapeIcon

use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.

the class BioModelEditorModelPanel method newButton2Pressed.

private void newButton2Pressed() throws ModelException, PropertyVetoException {
    computeCurrentSelectedTable();
    if (currentSelectedTable == reactionsTable) {
        if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
            PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
            return;
        }
        if (bioModel.getModel().getNumStructures() == 1) {
            Structure s = bioModel.getModel().getStructure(0);
            newObject = makeReactionRule(s);
            if (newObject != null) {
                for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
                    if (currentSelectedTableModel.getValueAt(i) == newObject) {
                        currentSelectedTable.setRowSelectionInterval(i, i);
                        break;
                    }
                }
            }
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                Structure s = bioModel.getModel().getStructure(i);
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        newObject = makeReactionRule(s);
                        if (newObject != null) {
                            for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
                                if (currentSelectedTableModel.getValueAt(i) == newObject) {
                                    currentSelectedTable.setRowSelectionInterval(i, i);
                                    break;
                                }
                            }
                        }
                    }
                });
            }
            menu.show(newButton2, 0, newButton2.getHeight());
        }
    }
}
Also used : StructureToolShapeIcon(cbit.vcell.graph.gui.StructureToolShapeIcon) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Structure(cbit.vcell.model.Structure) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 2 with StructureToolShapeIcon

use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.

the class BioModelEditorModelPanel method newButtonPressed.

private void newButtonPressed() throws ModelException, PropertyVetoException {
    newObject = null;
    computeCurrentSelectedTable();
    if (currentSelectedTable == speciesTable) {
        if (bioModel.getModel().getNumStructures() == 1) {
            newObject = bioModel.getModel().createSpeciesContext(bioModel.getModel().getStructures()[0]);
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                Structure s = bioModel.getModel().getStructure(i);
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        newObject = bioModel.getModel().createSpeciesContext(s);
                    }
                });
            }
            menu.show(newButton, 0, newButton.getHeight());
        }
    } else if (currentSelectedTable == molecularTypeTable) {
        if (bioModel.getModel().getRbmModelContainer() != null) {
            MolecularType mt = bioModel.getModel().getRbmModelContainer().createMolecularType();
            bioModel.getModel().getRbmModelContainer().addMolecularType(mt, true);
            newObject = mt;
        }
    } else if (currentSelectedTable == observablesTable) {
        if (bioModel.getModel().getRbmModelContainer() != null) {
            if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
                PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
                return;
            }
            if (bioModel.getModel().getNumStructures() == 1) {
                RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
                bioModel.getModel().getRbmModelContainer().addObservable(o);
                SpeciesPattern sp = new SpeciesPattern();
                o.addSpeciesPattern(sp);
                newObject = o;
            } else if (bioModel.getModel().getNumStructures() > 1) {
                final JPopupMenu menu = new JPopupMenu("Choose compartment");
                for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                    Structure s = bioModel.getModel().getStructure(i);
                    String sName = s.getName();
                    JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                    menuItem.setIcon(new StructureToolShapeIcon(17));
                    menu.add(menuItem);
                    menuItem.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules, null, s);
                            o.setStructure(s);
                            try {
                                bioModel.getModel().getRbmModelContainer().addObservable(o);
                            } catch (ModelException | PropertyVetoException e1) {
                                e1.printStackTrace();
                                throw new RuntimeException(e1.getMessage(), e1);
                            }
                            SpeciesPattern sp = new SpeciesPattern();
                            o.addSpeciesPattern(sp);
                            newObject = o;
                            if (newObject != null) {
                                for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
                                    if (currentSelectedTableModel.getValueAt(i) == newObject) {
                                        currentSelectedTable.setRowSelectionInterval(i, i);
                                        break;
                                    }
                                }
                            }
                        }
                    });
                }
                menu.show(newButton, 0, newButton.getHeight());
            }
        }
    } else if (currentSelectedTable == structuresTable) {
        try {
            Feature feature = bioModel.getModel().createFeature();
            newObject = feature;
        } catch (Exception e) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(this, e.getMessage(), e);
        }
    } else if (currentSelectedTable == reactionsTable) {
        if (bioModel.getModel().getNumStructures() == 1) {
            SimpleReaction reactionStep = bioModel.getModel().createSimpleReaction(bioModel.getModel().getStructures()[0]);
            newObject = reactionStep;
        } else {
            addNewReaction();
        }
    }
    if (newObject != null) {
        for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
            if (currentSelectedTableModel.getValueAt(i) == newObject) {
                currentSelectedTable.setRowSelectionInterval(i, i);
                break;
            }
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) ModelException(cbit.vcell.model.ModelException) ActionEvent(java.awt.event.ActionEvent) RbmObservable(cbit.vcell.model.RbmObservable) Feature(cbit.vcell.model.Feature) JPopupMenu(javax.swing.JPopupMenu) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException) StructureToolShapeIcon(cbit.vcell.graph.gui.StructureToolShapeIcon) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) ActionListener(java.awt.event.ActionListener) Structure(cbit.vcell.model.Structure) JMenuItem(javax.swing.JMenuItem)

Example 3 with StructureToolShapeIcon

use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.

the class BioModelEditorModelPanel method duplicateButtonPressed.

private void duplicateButtonPressed() {
    computeCurrentSelectedTable();
    int row = currentSelectedTable.getSelectedRow();
    System.out.println("Duplicate Button Pressed for row " + row);
    if (currentSelectedTable == reactionsTable) {
        ModelProcess mp = reactionTableModel.getValueAt(row);
        if (!(mp instanceof ReactionRule)) {
            return;
        }
        ReactionRule oldRule = (ReactionRule) mp;
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateReactionRule(oldRule, oldRule.getStructure());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                String ourType = oldRule.getStructure().getTypeName();
                Structure s = bioModel.getModel().getStructure(i);
                String theirType = s.getTypeName();
                if (!ourType.equals(theirType)) {
                    // offer to duplicate only within structures of the same type as the original,
                    continue;
                // otherwise units will be meaningless (surface vs volume)
                }
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateReactionRule(oldRule, s);
                    // moves selection on the newly created object
                    // if (newObject != null) {
                    // for (int i = 0; i < currentSelectedTableModel.getRowCount(); i ++) {
                    // if (currentSelectedTableModel.getValueAt(i) == newObject) {
                    // currentSelectedTable.setRowSelectionInterval(i, i);
                    // break;
                    // }
                    // }
                    // }
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    } else if (currentSelectedTable == speciesTable) {
        SpeciesContext sc = speciesTableModel.getValueAt(row);
        if (!sc.hasSpeciesPattern()) {
            return;
        }
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateSpecies(sc, sc.getStructure(), bioModel.getModel());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                String ourType = sc.getStructure().getTypeName();
                Structure s = bioModel.getModel().getStructure(i);
                String theirType = s.getTypeName();
                if (!ourType.equals(theirType)) {
                    continue;
                }
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateSpecies(sc, s, bioModel.getModel());
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    } else if (currentSelectedTable == observablesTable) {
        RbmObservable o = observableTableModel.getValueAt(row);
        if (o.getSpeciesPatternList().isEmpty()) {
            return;
        }
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateObservable(o, o.getStructure(), bioModel.getModel());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                Structure s = bioModel.getModel().getStructure(i);
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateObservable(o, s, bioModel.getModel());
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ActionEvent(java.awt.event.ActionEvent) RbmObservable(cbit.vcell.model.RbmObservable) ModelProcess(cbit.vcell.model.ModelProcess) SpeciesContext(cbit.vcell.model.SpeciesContext) JPopupMenu(javax.swing.JPopupMenu) StructureToolShapeIcon(cbit.vcell.graph.gui.StructureToolShapeIcon) ActionListener(java.awt.event.ActionListener) Structure(cbit.vcell.model.Structure) JMenuItem(javax.swing.JMenuItem)

Aggregations

StructureToolShapeIcon (cbit.vcell.graph.gui.StructureToolShapeIcon)3 Structure (cbit.vcell.model.Structure)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JMenuItem (javax.swing.JMenuItem)3 JPopupMenu (javax.swing.JPopupMenu)3 RbmObservable (cbit.vcell.model.RbmObservable)2 Feature (cbit.vcell.model.Feature)1 ModelException (cbit.vcell.model.ModelException)1 ModelProcess (cbit.vcell.model.ModelProcess)1 ReactionRule (cbit.vcell.model.ReactionRule)1 SimpleReaction (cbit.vcell.model.SimpleReaction)1 SpeciesContext (cbit.vcell.model.SpeciesContext)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 PropertyVetoException (java.beans.PropertyVetoException)1 MolecularType (org.vcell.model.rbm.MolecularType)1 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)1 UserCancelException (org.vcell.util.UserCancelException)1