Search in sources :

Example 46 with SpeciesPattern

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

the class ViewGeneratedSpeciesPanel method initialize.

private void initialize() {
    try {
        setName("ViewGeneratedSpeciesPanel");
        setLayout(new GridBagLayout());
        shapePanel = new LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spls != null) {
                    spls.paintSelf(g);
                }
            }

            @Override
            public DisplayMode getDisplayMode() {
                return DisplayMode.other;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleParticipantSignature getSignature() {
                return null;
            }

            @Override
            public GroupingCriteria getCriteria() {
                return null;
            }

            @Override
            public boolean isViewSingleRow() {
                return true;
            }
        };
        Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
        shapePanel.setLayout(new GridBagLayout());
        shapePanel.setBackground(Color.white);
        // not really editable but we don't want the brown contours here
        shapePanel.setEditable(true);
        shapePanel.setShowMoleculeColor(true);
        shapePanel.setShowNonTrivialOnly(true);
        JScrollPane scrollPane = new JScrollPane(shapePanel);
        scrollPane.setBorder(loweredBevelBorder);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new GridBagLayout());
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(false);
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomLargerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomSmallerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(4, 4, 4, 10);
        optionsPanel.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanel = new JPanel();
        containerOfScrollPanel.setLayout(new BorderLayout());
        containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
        containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
        Dimension dim = new Dimension(500, 135);
        // dimension of shape panel
        containerOfScrollPanel.setPreferredSize(dim);
        containerOfScrollPanel.setMinimumSize(dim);
        containerOfScrollPanel.setMaximumSize(dim);
        // ------------------------------------------------------------------------
        table = new EditorScrollTable();
        tableModel = new GeneratedSpeciesTableModel(table, owner);
        table.setModel(tableModel);
        table.getSelectionModel().addListSelectionListener(eventHandler);
        table.getModel().addTableModelListener(eventHandler);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        int gridy = 0;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        table.setPreferredScrollableViewportSize(new Dimension(400, 200));
        add(table.getEnclosingScrollPane(), gbc);
        // gbc = new java.awt.GridBagConstraints();
        // gbc.gridx = 9;
        // gbc.gridy = gridy;
        // add toolTipText for each table cell
        table.addMouseMotionListener(new MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                Point p = e.getPoint();
                int row = table.rowAtPoint(p);
                int column = table.columnAtPoint(p);
                table.setToolTipText(String.valueOf(table.getValueAt(row, column)));
            }
        });
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        add(new JLabel("Search "), gbc);
        textFieldSearch = new JTextField(70);
        textFieldSearch.addActionListener(eventHandler);
        textFieldSearch.getDocument().addDocumentListener(eventHandler);
        textFieldSearch.putClientProperty("JTextField.variant", "search");
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 0, 4, 4);
        add(textFieldSearch, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        add(totalSpeciesLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        // gbc.weightx = 1.0;
        gbc.gridwidth = 8;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        add(containerOfScrollPanel, gbc);
        // rendering the small shapes of the flattened species in the Depiction column of this viewer table)
        // TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
        // of a species context in the Depiction column of the species 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() == tableModel) {
                        selectedObject = tableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof GeneratedSpeciesTableRow) {
                            SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
                            // sp cannot be null
                            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);
                }
            }
        };
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setPreferredWidth(400);
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setMinWidth(400);
        table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDefinition).setPreferredWidth(30);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JPanel(javax.swing.JPanel) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) JTextField(javax.swing.JTextField) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LargeShapePanel(cbit.vcell.graph.gui.LargeShapePanel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) RuleAnalysisChanged(cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) GroupingCriteria(cbit.vcell.model.GroupingCriteria) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Point(java.awt.Point) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border)

Example 47 with SpeciesPattern

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

the class ViewObservablesMapPanel method updateShapeSpecies.

public void updateShapeSpecies(int selectedRow) {
    GeneratedSpeciesTableRow speciesTableRow = speciesTableModel.getValueAt(selectedRow);
    String inputString = speciesTableRow.getExpression();
    // System.out.println(selectedRows[0] + ": " + inputString);
    Model tempModel = null;
    try {
        tempModel = new Model("MyTempModel");
        tempModel.addFeature("c0");
    } catch (ModelException | PropertyVetoException e1) {
        e1.printStackTrace();
    }
    if (owner != null && owner.getSimulationContext() != null) {
        List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
        try {
            tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
        } catch (PropertyVetoException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
        }
    } else {
        System.out.println("something is wrong, we just do nothing rather than crash");
        return;
    }
    try {
        String strStructure = null;
        if (inputString.contains(RbmUtils.SiteStruct)) {
            // we are in the mode where we emulate compartments by adding the compartment name as a fake site
            Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
            // we'll just assume there's only one, may want to throw exception if more
            strStructure = p.one.get(0);
            inputString = p.two;
        } else {
            // should be the normal @comp:expression format - if it's not it will return null
            strStructure = RbmUtils.parseCompartment(inputString, tempModel);
        }
        Structure structure;
        if (strStructure != null) {
            if (tempModel.getStructure(strStructure) == null) {
                if (owner.getSimulationContext().getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                    tempModel.addMembrane(strStructure);
                } else {
                    tempModel.addFeature(strStructure);
                }
            }
            structure = tempModel.getStructure(strStructure);
        } else {
            structure = tempModel.getStructure(0);
        }
        SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
        sp.resolveBonds();
        SpeciesContext sc = new SpeciesContext(new Species("a", ""), structure, sp);
        spls = new SpeciesPatternLargeShape(20, 20, -1, sp, shapePanelSpecies, sc, issueManager);
    } catch (ParseException | PropertyVetoException | ModelException e1) {
        e1.printStackTrace();
        // error (red circle)
        spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanelSpecies, true, issueManager);
        shapePanelSpecies.repaint();
    }
    int xOffset = spls.getRightEnd() + 45;
    Dimension preferredSize = new Dimension(xOffset + 90, 50);
    shapePanelSpecies.setPreferredSize(preferredSize);
    shapePanelSpecies.repaint();
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ObservableTableModel(cbit.vcell.client.desktop.biomodel.ObservableTableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Example 48 with SpeciesPattern

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

the class RulebasedMathMapping method addObservables.

private List<ParticleObservable> addObservables(GeometryClass geometryClass, Domain domain, HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap) throws MappingException, MathException {
    ArrayList<ParticleObservable> observables = new ArrayList<>();
    // 
    for (MathMappingParameter mathMappingParameter : getMathMappingParameters()) {
        if (mathMappingParameter instanceof ObservableCountParameter) {
            ObservableCountParameter observableCountParameter = (ObservableCountParameter) mathMappingParameter;
            RbmObservable rbmObservable = observableCountParameter.getObservable();
            ParticleObservable.ObservableType particleObservableType = null;
            if (rbmObservable.getType() == RbmObservable.ObservableType.Molecules) {
                particleObservableType = ParticleObservable.ObservableType.Molecules;
            } else {
                particleObservableType = ParticleObservable.ObservableType.Species;
            }
            ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(observableCountParameter, geometryClass), domain, particleObservableType);
            switch(rbmObservable.getSequence()) {
                case Multimolecular:
                    {
                        particleObservable.setSequence(Sequence.Multimolecular);
                        break;
                    }
                case PolymerLengthEqual:
                    {
                        particleObservable.setSequence(Sequence.PolymerLengthEqual);
                        particleObservable.setQuantity(rbmObservable.getSequenceLength());
                        break;
                    }
                case PolymerLengthGreater:
                    {
                        particleObservable.setSequence(Sequence.PolymerLengthGreater);
                        particleObservable.setQuantity(rbmObservable.getSequenceLength());
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("unexpected sequence " + rbmObservable.getSequence());
                    }
            }
            for (SpeciesPattern speciesPattern : rbmObservable.getSpeciesPatternList()) {
                VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
                particleObservable.addParticleSpeciesPattern(vpsp);
            }
            observables.add(particleObservable);
        }
        if (mathMappingParameter instanceof SpeciesCountParameter) {
            SpeciesCountParameter speciesCountParameter = (SpeciesCountParameter) mathMappingParameter;
            ParticleObservable.ObservableType particleObservableType = ParticleObservable.ObservableType.Species;
            ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(speciesCountParameter, geometryClass), domain, particleObservableType);
            particleObservable.setSequence(Sequence.Multimolecular);
            SpeciesPattern speciesPattern = speciesCountParameter.getSpeciesContext().getSpeciesPattern();
            VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
            particleObservable.addParticleSpeciesPattern(vpsp);
            observables.add(particleObservable);
        }
    }
    return observables;
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable) ParticleObservable(cbit.vcell.math.ParticleObservable) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 49 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern 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 50 with SpeciesPattern

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

the class BioModelEditorSpeciesTableModel method setValueAt.

public void setValueAt(Object value, int row, int column) {
    if (getModel() == null || value == null) {
        return;
    }
    try {
        SpeciesContext speciesContext = getValueAt(row);
        if (speciesContext != null) {
            // row with existing species
            switch(column) {
                case COLUMN_NAME:
                    {
                        String inputValue = ((String) value);
                        inputValue = inputValue.trim();
                        if (inputValue.length() == 0) {
                            return;
                        }
                        speciesContext.setName(inputValue);
                        break;
                    }
                case COLUMN_STRUCTURE:
                    {
                        // value might be null because no popup in JCombo editor ui.
                        // the first time.
                        Structure structure = (Structure) value;
                        speciesContext.setStructure(structure);
                        break;
                    }
                case COLUMN_DEFINITION:
                    String inputValue = ((String) value);
                    inputValue = inputValue.trim();
                    if (inputValue.length() == 0) {
                        speciesContext.setSpeciesPattern(null);
                        return;
                    }
                    SpeciesPattern sp = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
                    speciesContext.setSpeciesPattern(sp);
                    break;
            }
        } else {
            // empty row being edited - Deprecated, we now must use the "New Species" button
            switch(column) {
                case // only "name" column is editable
                COLUMN_NAME:
                    String inputValue = ((String) value);
                    if (inputValue.length() == 0 || inputValue.equals(ADD_NEW_HERE_TEXT)) {
                        return;
                    }
                    inputValue = inputValue.trim();
                    SpeciesContext freeSpeciesContext = getModel().createSpeciesContext(getModel().getStructures()[0]);
                    freeSpeciesContext.setName(inputValue);
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
    }
}
Also used : SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11