Search in sources :

Example 36 with SpeciesPattern

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

the class BioModelEditor method popupMenuActionPerformed.

@Override
protected void popupMenuActionPerformed(DocumentEditorPopupMenuAction action, String actionCommand) {
    Model model = bioModel.getModel();
    final SimulationContext selectedSimulationContext = getSelectedSimulationContext();
    switch(action) {
        case add_new:
            try {
                Object obj = documentEditorTree.getLastSelectedPathComponent();
                if (obj == null || !(obj instanceof BioModelNode)) {
                    return;
                }
                BioModelNode selectedNode = (BioModelNode) obj;
                Object userObject = selectedNode.getUserObject();
                if (userObject instanceof DocumentEditorTreeFolderNode) {
                    DocumentEditorTreeFolderClass folderClass = ((DocumentEditorTreeFolderNode) userObject).getFolderClass();
                    Object newObject = null;
                    switch(folderClass) {
                        case REACTIONS_NODE:
                            // TODO: should add a Add New Rule menu item
                            newObject = model.createSimpleReaction(model.getStructure(0));
                            break;
                        case STRUCTURES_NODE:
                            newObject = model.createFeature();
                            break;
                        case SPECIES_NODE:
                            newObject = model.createSpeciesContext(model.getStructure(0));
                            break;
                        case MOLECULAR_TYPES_NODE:
                            MolecularType mt = model.getRbmModelContainer().createMolecularType();
                            model.getRbmModelContainer().addMolecularType(mt, true);
                            newObject = mt;
                            break;
                        case OBSERVABLES_NODE:
                            if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
                                PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
                                return;
                            }
                            RbmObservable o = model.getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
                            model.getRbmModelContainer().addObservable(o);
                            SpeciesPattern sp = new SpeciesPattern();
                            o.addSpeciesPattern(sp);
                            newObject = o;
                            break;
                        case SIMULATIONS_NODE:
                            if (selectedSimulationContext != null) {
                                AsynchClientTask task1 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        selectedSimulationContext.refreshMathDescription(callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                    }
                                };
                                AsynchClientTask task2 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        Object newsim = selectedSimulationContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                        selectionManager.setSelectedObjects(new Object[] { newsim });
                                    }
                                };
                                ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
                            }
                            break;
                        default:
                            break;
                    }
                    if (newObject != null) {
                        selectionManager.setSelectedObjects(new Object[] { newObject });
                    }
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case add_new_app_deterministic:
            newApplication(Application.NETWORK_DETERMINISTIC);
            break;
        case add_new_app_stochastic:
            newApplication(Application.NETWORK_STOCHASTIC);
            break;
        case add_new_app_rulebased:
            {
                // if(model.getStructures().length > 1) {
                // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                // return;
                // }
                newApplication(Application.RULE_BASED_STOCHASTIC);
                break;
            }
        case copy_app:
            ApplicationActionCommand acc = ApplicationActionCommand.lookup(actionCommand);
            switch(acc.actionType()) {
                case COPY_AS_IS:
                    copyApplication();
                    break;
                case COPY_CHANGE:
                    boolean bothSpatial = acc.isSourceSpatial() && acc.isDestSpatial();
                    // if(acc.getAppType().equals(SimulationContext.Application.RULE_BASED_STOCHASTIC) && model.getStructures().length > 1) {
                    // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                    // return;
                    // }
                    copyApplication(bothSpatial, acc.getAppType());
                    break;
                case CREATE:
                    // not used in this menu
                    throw new UnsupportedOperationException();
            }
            break;
        case app_new_biomodel:
            if (actionCommand.equals(GuiConstants.MENU_TEXT_APP_NEWBIOMODEL)) {
                createNewBiomodelFromApp();
            }
            break;
        case delete:
            try {
                if (selectedSimulationContext != null) {
                    String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application", "You are going to delete the Application '" + selectedSimulationContext.getName() + "'. Continue?");
                    if (confirm.equals(UserMessage.OPTION_CANCEL)) {
                        return;
                    }
                    deleteSimulationcontexts(new SimulationContext[] { selectedSimulationContext });
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case deleteChoose:
            try {
                SimulationContext[] allSimContexts = Arrays.copyOf(getBioModelWindowManager().getVCDocument().getSimulationContexts(), getBioModelWindowManager().getVCDocument().getSimulationContexts().length);
                Arrays.sort(allSimContexts, new Comparator<SimulationContext>() {

                    @Override
                    public int compare(SimulationContext o1, SimulationContext o2) {
                        return o1.getName().compareToIgnoreCase(o2.getName());
                    }
                });
                String[][] rowDataOrig = new String[allSimContexts.length][2];
                for (int i = 0; i < allSimContexts.length; i++) {
                    rowDataOrig[i][0] = allSimContexts[i].getName();
                    rowDataOrig[i][1] = allSimContexts[i].getSimulations().length + "";
                }
                final String DELETE = "Delete";
                final String CANCEL = "Cancel";
                TableListResult result = DialogUtils.showComponentOptionsTableList(this, "Select Applications (and associated Simulations) to delete.", new String[] { "Application", "# of Sims" }, rowDataOrig, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, null, new String[] { DELETE, CANCEL }, CANCEL, null);
                if (result != null && result.selectedOption != null && result.selectedOption.equals(DELETE) && result.selectedTableRows != null && result.selectedTableRows.length > 0) {
                    ArrayList<SimulationContext> deleteTheseSimcontexts = new ArrayList<SimulationContext>();
                    for (int i = 0; i < result.selectedTableRows.length; i++) {
                        deleteTheseSimcontexts.add(allSimContexts[result.selectedTableRows[i]]);
                    }
                    deleteSimulationcontexts(deleteTheseSimcontexts.toArray(new SimulationContext[0]));
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        default:
            break;
    }
}
Also used : TableListResult(org.vcell.util.gui.DialogUtils.TableListResult) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ApplicationActionCommand(cbit.vcell.client.constants.ApplicationActionCommand) ArrayList(java.util.ArrayList) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) UnsupportedOperationException(javax.help.UnsupportedOperationException) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) RbmObservable(cbit.vcell.model.RbmObservable) DocumentEditorTreeFolderNode(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode) SimulationContext(cbit.vcell.mapping.SimulationContext) DocumentEditorTreeFolderClass(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass) PropertyVetoException(java.beans.PropertyVetoException) UnsupportedOperationException(javax.help.UnsupportedOperationException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) BioPaxObject(org.vcell.pathway.BioPaxObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) CSGObject(cbit.vcell.geometry.CSGObject)

Example 37 with SpeciesPattern

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

the class BioModelEditorModelPanel method deleteButtonPressed.

private void deleteButtonPressed() {
    try {
        ArrayList<Object> deleteList = new ArrayList<Object>();
        int selectedIndex = tabbedPane.getSelectedIndex();
        if (selectedIndex == ModelPanelTabID.reaction_diagram.ordinal()) {
            deleteList.addAll(Arrays.asList(reactionCartoonEditorPanel.getReactionCartoon().getSelectedObjects()));
        // } else if (selectedIndex == ModelPanelTabID.structure_diagram.ordinal()) {
        // deleteList.addAll(Arrays.asList(cartoonEditorPanel.getStructureCartoon().getSelectedObjects()));
        } else {
            computeCurrentSelectedTable();
            int[] rows = currentSelectedTable.getSelectedRows();
            if (rows == null || rows.length == 0) {
                return;
            }
            if (currentSelectedTable == speciesTable) {
                for (int r : rows) {
                    if (r < speciesTableModel.getRowCount()) {
                        SpeciesContext speciesContext = speciesTableModel.getValueAt(r);
                        if (speciesContext != null) {
                            deleteList.add(speciesContext);
                        }
                    }
                }
            } else if (currentSelectedTable == molecularTypeTable) {
                // TODO: delete stuff
                for (int r : rows) {
                    if (r < molecularTypeTableModel.getRowCount()) {
                        MolecularType mt = molecularTypeTableModel.getValueAt(r);
                        if (mt != null) {
                            deleteList.add(mt);
                        }
                    }
                }
            } else if (currentSelectedTable == observablesTable) {
                for (int r : rows) {
                    if (r < observableTableModel.getRowCount()) {
                        RbmObservable o = observableTableModel.getValueAt(r);
                        if (o != null) {
                            deleteList.add(o);
                        }
                    }
                }
            } else if (currentSelectedTable == structuresTable) {
                for (int r : rows) {
                    if (r < structureTableModel.getRowCount()) {
                        Structure rowValue = structureTableModel.getValueAt(r);
                        if (rowValue instanceof Feature || rowValue instanceof Membrane) {
                            deleteList.add(rowValue);
                        }
                    }
                }
            } else if (currentSelectedTable == reactionsTable) {
                for (int r : rows) {
                    if (r < reactionTableModel.getRowCount()) {
                        ModelProcess reaction = reactionTableModel.getValueAt(r);
                        if (reaction != null) {
                            deleteList.add(reaction);
                        }
                    }
                }
            }
        }
        if (deleteList.size() == 0) {
            return;
        }
        StringBuilder deleteListText = new StringBuilder();
        for (Object object : deleteList) {
            if (object instanceof SpeciesContext) {
                deleteListText.append("Species\t'" + ((SpeciesContext) object).getName() + "'\n");
            } else if (object instanceof MolecularType) {
                deleteListText.append(((MolecularType) object).getDisplayType() + "\t'" + ((MolecularType) object).getDisplayName() + "'\n");
            } else if (object instanceof RbmObservable) {
                deleteListText.append("Observable\t'" + ((RbmObservable) object).getName() + "'\n");
            } else if (object instanceof ReactionStep) {
                deleteListText.append("Reaction\t'" + ((ReactionStep) object).getName() + "'\n");
            } else if (object instanceof ReactionRule) {
                deleteListText.append("Reaction rule\t'" + ((ReactionRule) object).getName() + "'\n");
            } else if (object instanceof Structure) {
                deleteListText.append("Structure\t'" + ((Structure) object).getName() + "'\n");
            }
        }
        // TODO: once we display reaction rules in the carton editor panel we'll have to change the way we delete reaction rules
        if (deleteList.get(0) instanceof SpeciesContext || deleteList.get(0) instanceof ReactionStep) {
            try {
                ArrayList<SpeciesContext> speciesContextArrList = new ArrayList<SpeciesContext>();
                ArrayList<ReactionStep> reactionStepArrList = new ArrayList<ReactionStep>();
                for (Object obj : deleteList) {
                    if (obj instanceof SpeciesContext) {
                        speciesContextArrList.add((SpeciesContext) obj);
                    } else if (obj instanceof ReactionStep) {
                        reactionStepArrList.add((ReactionStep) obj);
                    } else {
                        throw new Exception("Unexpected delete object " + obj.getClass().getName());
                    }
                }
                ReactionCartoonTool.deleteReactionsAndSpecies(reactionCartoonEditorPanel, reactionStepArrList.toArray(new ReactionStep[0]), speciesContextArrList.toArray(new SpeciesContext[0]));
            } catch (UserCancelException uce) {
                return;
            }
            return;
        } else {
            String confirm = DialogUtils.showOKCancelWarningDialog(this, "Deleting", "You are going to delete the following:\n\n" + deleteListText + "\n Continue?");
            if (confirm.equals(UserMessage.OPTION_CANCEL)) {
                return;
            }
            for (Object object : deleteList) {
                if (object instanceof ReactionRule) {
                    ReactionRule rr = (ReactionRule) object;
                    bioModel.getModel().getRbmModelContainer().removeReactionRule(rr);
                } else if (object instanceof MolecularType) {
                    Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                    MolecularType mt = (MolecularType) object;
                    if (!bioModel.getModel().getRbmModelContainer().isDeleteAllowed(mt, usedHere)) {
                        String errMsg = mt.getDisplayType() + " <b>'" + mt + "'</b> cannot be deleted because it's already being used by:<br>";
                        final int MaxListSize = 7;
                        int count = 0;
                        for (String key : usedHere.keySet()) {
                            System.out.println(key);
                            if (count >= MaxListSize) {
                                errMsg += "<br> ... and more.";
                                break;
                            }
                            Pair<Displayable, SpeciesPattern> o = usedHere.get(key);
                            Displayable e = o.one;
                            SpeciesPattern sp = o.two;
                            errMsg += "<br> - " + e.getDisplayType().toLowerCase() + " <b>" + e.getDisplayName() + "</b>";
                            errMsg += ", " + sp.getDisplayType().toLowerCase() + " " + " <b>" + sp.getDisplayName() + "</b>";
                            count++;
                        }
                        errMsg = "<html>" + errMsg + "</html>";
                        throw new RuntimeException(errMsg);
                    }
                    bioModel.getModel().getRbmModelContainer().removeMolecularType(mt);
                } else if (object instanceof RbmObservable) {
                    RbmObservable o = (RbmObservable) object;
                    bioModel.getModel().getRbmModelContainer().removeObservable(o);
                } else {
                    bioModel.getModel().removeObject(object);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        DialogUtils.showErrorDialog(this, ex.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) UserCancelException(org.vcell.util.UserCancelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Pair(org.vcell.util.Pair) Displayable(org.vcell.util.Displayable) ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) ModelProcess(cbit.vcell.model.ModelProcess) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) RelationshipObject(org.vcell.relationship.RelationshipObject) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with SpeciesPattern

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

the class InitialConditionsPanel method initialize.

/**
 * Initialize the class.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
    try {
        // user code begin {1}
        // user code end
        setName("InitialConditionsPanel");
        setLayout(new BorderLayout());
        add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
        add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
        getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
        getJMenuItemPaste().addActionListener(ivjEventHandler);
        getJMenuItemCopy().addActionListener(ivjEventHandler);
        getJMenuItemCopyAll().addActionListener(ivjEventHandler);
        getJMenuItemPasteAll().addActionListener(ivjEventHandler);
        getAmountRadioButton().addActionListener(ivjEventHandler);
        getConcentrationRadioButton().addActionListener(ivjEventHandler);
        getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
        DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setIcon(null);
                defaultToolTipText = null;
                if (value instanceof Species) {
                    setText(((Species) value).getCommonName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof SpeciesContext) {
                    setText(((SpeciesContext) value).getName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof Structure) {
                    setText(((Structure) value).getName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof ScopedExpression) {
                    SpeciesContextSpec scSpec = tableModel.getValueAt(row);
                    VCUnitDefinition unit = null;
                    if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
                        SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
                        unit = initialConditionParameter.getUnitDefinition();
                    } else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
                        SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
                        unit = diffusionParameter.getUnitDefinition();
                    }
                    if (unit != null) {
                        setHorizontalTextPosition(JLabel.LEFT);
                        setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
                    }
                    int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
                    defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
                    setToolTipText(defaultToolTipText);
                    if (unit != null) {
                        setText(defaultToolTipText);
                    }
                }
                TableModel tableModel = table.getModel();
                if (tableModel instanceof SortTableModel) {
                    DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
                    setHorizontalTextPosition(JLabel.TRAILING);
                }
                return this;
            }
        };
        DefaultTableCellRenderer 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 SpeciesContextSpec) {
                            SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
                            SpeciesContext sc = scs.getSpeciesContext();
                            // sp may be null for "plain" species contexts
                            SpeciesPattern sp = sc.getSpeciesPattern();
                            Graphics panelContext = table.getGraphics();
                            spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, 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);
                }
            }
        };
        getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
        getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
        getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
        getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
        getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
        getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) TextIcon(cbit.vcell.mapping.gui.StructureMappingTableRenderer.TextIcon) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ScrollTableBooleanCellRenderer(org.vcell.util.gui.ScrollTable.ScrollTableBooleanCellRenderer) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Graphics(java.awt.Graphics) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ScopedExpression(cbit.gui.ScopedExpression) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) TableModel(javax.swing.table.TableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 39 with SpeciesPattern

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

the class ModelProcessSpecsPanel method initConnections.

/**
 * Initializes connections
 * @exception java.lang.Exception The exception description.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
    // user code begin {1}
    // user code end
    this.addPropertyChangeListener(ivjEventHandler);
    getScrollPaneTable().setModel(getModelProcessSpecsTableModel());
    getScrollPaneTable().setDefaultRenderer(ModelProcess.class, new DefaultScrollTableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            defaultToolTipText = null;
            if (value instanceof ModelProcess) {
                setText(((ModelProcess) value).getName());
                defaultToolTipText = getText();
                setToolTipText(defaultToolTipText);
            }
            TableModel tableModel = table.getModel();
            if (tableModel instanceof SortTableModel) {
                DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
            }
            return this;
        }
    });
    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() == ivjModelProcessSpecsTableModel) {
                    selectedObject = ivjModelProcessSpecsTableModel.getValueAt(row);
                }
                if (selectedObject != null) {
                    if (selectedObject instanceof ModelProcessSpec) {
                        ModelProcessSpec mps = (ModelProcessSpec) selectedObject;
                        ModelProcess mp = (ModelProcess) mps.getModelProcess();
                        if (mp instanceof ReactionRule) {
                            ReactionRule rr = (ReactionRule) mp;
                            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, shapeManager, 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, shapeManager, panelContext, rr, isSelected, issueManager);
                                if (i < ppList.size() - 1) {
                                    spss.addEndText("+");
                                }
                                xPos += spss.getWidth() + 15;
                                spssList.add(spss);
                            }
                        } else {
                            ReactionStep rs = (ReactionStep) mp;
                            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, shapeManager, 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, shapeManager, 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);
            }
        }
    };
    getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmReactionShapeDepictionCellRenderer);
    // ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
    // ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setPreferredWidth(180);
    getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
}
Also used : VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) ModelProcessSpec(cbit.vcell.mapping.ModelProcessSpec) ModelProcess(cbit.vcell.model.ModelProcess) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Graphics(java.awt.Graphics) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) JTable(javax.swing.JTable) ReactionStep(cbit.vcell.model.ReactionStep) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) ArrayList(java.util.ArrayList) List(java.util.List) Component(java.awt.Component) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) TableModel(javax.swing.table.TableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) ReactantPattern(cbit.vcell.model.ReactantPattern)

Example 40 with SpeciesPattern

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

the class SpeciesContextSpecPanel method updateShape.

private void updateShape() {
    if (speciesContext == null) {
        return;
    }
    SpeciesPattern sp = speciesContext.getSpeciesPattern();
    spls = new SpeciesPatternLargeShape(xOffsetInitial, yOffsetInitial, -1, sp, shapePanel, speciesContext, issueManager);
    Dimension preferredSize = new Dimension(spls.getRightEnd() + 40, yOffsetInitial + 80);
    shapePanel.setPreferredSize(preferredSize);
    shapePanel.repaint();
}
Also used : Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) 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