Search in sources :

Example 1 with MolecularComponentPattern

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

the class ViewObservablesMapPanel method initialize.

private void initialize() {
    try {
        // --------------------------------------- the split panels
        setName("ViewGeneratedSpeciesPanel");
        setLayout(new BorderLayout());
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new GridBagLayout());
        JPanel bottomPanel = new JPanel();
        bottomPanel.setLayout(new GridBagLayout());
        JSplitPane splitPaneHorizontal = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneHorizontal.setDividerSize(10);
        splitPaneHorizontal.setOneTouchExpandable(true);
        splitPaneHorizontal.setDividerLocation(260);
        splitPaneHorizontal.setResizeWeight(0.5);
        splitPaneHorizontal.setTopComponent(topPanel);
        splitPaneHorizontal.setBottomComponent(bottomPanel);
        add(splitPaneHorizontal, BorderLayout.CENTER);
        // ---------------------------------------- species shape panel
        shapePanelSpecies = 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;
            }
        };
        shapePanelSpecies.setLayout(new GridBagLayout());
        shapePanelSpecies.setBackground(Color.white);
        // not really editable but we don't want the brown contours here
        shapePanelSpecies.setEditable(true);
        shapePanelSpecies.setShowMoleculeColor(true);
        shapePanelSpecies.setShowNonTrivialOnly(true);
        Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
        JScrollPane scrollPaneSpecies = new JScrollPane(shapePanelSpecies);
        scrollPaneSpecies.setBorder(loweredBevelBorder);
        scrollPaneSpecies.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPaneSpecies.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanelSpecies = new JPanel();
        optionsPanelSpecies.setLayout(new GridBagLayout());
        getZoomSmallerButtonSpecies().setEnabled(true);
        getZoomLargerButtonSpecies().setEnabled(true);
        shapePanelSpecies.zoomSmaller();
        shapePanelSpecies.zoomSmaller();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelSpecies.add(getZoomLargerButtonSpecies(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelSpecies.add(getZoomSmallerButtonSpecies(), 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);
        optionsPanelSpecies.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanelSpecies = new JPanel();
        containerOfScrollPanelSpecies.setLayout(new BorderLayout());
        containerOfScrollPanelSpecies.add(optionsPanelSpecies, BorderLayout.WEST);
        containerOfScrollPanelSpecies.add(scrollPaneSpecies, BorderLayout.CENTER);
        Dimension dimS = new Dimension(500, 125);
        // dimension of shape panel
        containerOfScrollPanelSpecies.setPreferredSize(dimS);
        containerOfScrollPanelSpecies.setMinimumSize(dimS);
        containerOfScrollPanelSpecies.setMaximumSize(dimS);
        shapePanelObservable = new LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (SpeciesPatternLargeShape sps : spsList) {
                    if (sps == null) {
                        continue;
                    }
                    sps.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;
            }
        };
        // 
        DefaultScrollTableCellRenderer rbmSpeciesPatternCellRenderer = new DefaultScrollTableCellRenderer() {

            @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 GeneratedSpeciesTableModel2) {
                    Object selectedObject = null;
                    if (table.getModel() == speciesTableModel) {
                        selectedObject = speciesTableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof GeneratedSpeciesTableRow && value instanceof String) {
                            SpeciesPattern sp = ((GeneratedSpeciesTableRow) selectedObject).getSpecies().getSpeciesPattern();
                            String text = "<html>";
                            text += RbmTableRenderer.toHtml(sp, isSelected);
                            text += "</html>";
                            setText(text);
                        }
                    }
                }
                return this;
            }
        };
        // shapePanelObservable.setLayout(null);
        shapePanelObservable.setLayout(new GridBagLayout());
        shapePanelObservable.setBackground(Color.white);
        shapePanelObservable.setEditable(true);
        shapePanelObservable.setShowMoleculeColor(true);
        shapePanelObservable.setShowNonTrivialOnly(true);
        JScrollPane scrollPaneObservable = new JScrollPane(shapePanelObservable);
        scrollPaneObservable.setBorder(loweredBevelBorder);
        scrollPaneObservable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPaneObservable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanelObservable = new JPanel();
        optionsPanelObservable.setLayout(new GridBagLayout());
        getZoomSmallerButtonObservable().setEnabled(true);
        getZoomLargerButtonObservable().setEnabled(true);
        shapePanelObservable.zoomSmaller();
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelObservable.add(getZoomLargerButtonObservable(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelObservable.add(getZoomSmallerButtonObservable(), 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);
        optionsPanelObservable.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanelObservable = new JPanel();
        containerOfScrollPanelObservable.setLayout(new BorderLayout());
        containerOfScrollPanelObservable.add(optionsPanelObservable, BorderLayout.WEST);
        containerOfScrollPanelObservable.add(scrollPaneObservable, BorderLayout.CENTER);
        Dimension dimO = new Dimension(500, 100);
        // dimension of shape panel
        containerOfScrollPanelObservable.setPreferredSize(dimO);
        containerOfScrollPanelObservable.setMinimumSize(dimO);
        containerOfScrollPanelObservable.setMaximumSize(dimO);
        // -------------- connection between tables, table models, selection models, renderers, event handlers
        speciesTable = new EditorScrollTable();
        speciesTableModel = new GeneratedSpeciesTableModel2(speciesTable, owner);
        speciesTable.setModel(speciesTableModel);
        speciesTable.getSelectionModel().addListSelectionListener(eventHandlerS);
        speciesTable.getModel().addTableModelListener(eventHandlerS);
        observablesTable = new EditorScrollTable();
        observablesTableModel = new ObservablesGroupTableModel(observablesTable, owner, speciesTableModel);
        observablesTable.setModel(observablesTableModel);
        observablesTable.getSelectionModel().addListSelectionListener(eventHandlerO);
        observablesTable.getModel().addTableModelListener(eventHandlerO);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setCellRenderer(rbmSpeciesPatternCellRenderer);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        // speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setCellRenderer(rightRenderer);	// right align
        // left column wide enough for title
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setMaxWidth(70);
        speciesTable.addMouseMotionListener(new // add toolTipText for each table cell
        MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                Point p = e.getPoint();
                int row = speciesTable.rowAtPoint(p);
                int column = speciesTable.columnAtPoint(p);
                speciesTable.setToolTipText(String.valueOf(speciesTable.getValueAt(row, column)));
            }
        });
        // ---------------------------------------------- top panel
        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);
        observablesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
        topPanel.add(observablesTable.getEnclosingScrollPane(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        topPanel.add(new JLabel("Search "), gbc);
        textFieldSearchObservables = new JTextField(70);
        textFieldSearchObservables.addActionListener(eventHandlerO);
        textFieldSearchObservables.getDocument().addDocumentListener(eventHandlerO);
        textFieldSearchObservables.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);
        topPanel.add(textFieldSearchObservables, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        topPanel.add(totalObservablesLabel, 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);
        topPanel.add(containerOfScrollPanelObservable, gbc);
        // -------------------------------------------- bottom panel
        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);
        speciesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
        bottomPanel.add(speciesTable.getEnclosingScrollPane(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        bottomPanel.add(new JLabel("Search "), gbc);
        textFieldSearchSpecies = new JTextField(70);
        textFieldSearchSpecies.addActionListener(eventHandlerS);
        textFieldSearchSpecies.getDocument().addDocumentListener(eventHandlerS);
        textFieldSearchSpecies.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);
        bottomPanel.add(textFieldSearchSpecies, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        bottomPanel.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);
        bottomPanel.add(containerOfScrollPanelSpecies, 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() == speciesTableModel) {
                        selectedObject = speciesTableModel.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);
                }
            }
        };
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setPreferredWidth(400);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setMinWidth(400);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setPreferredWidth(30);
        speciesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        DefaultScrollTableCellRenderer rbmObservableShapeDepictionCellRenderer = 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() == observablesTableModel) {
                        selectedObject = observablesTableModel.getValueAt(row);
                    }
                    if (selectedObject != null && selectedObject instanceof ObservablesGroupTableRow) {
                        ObservablesGroupTableRow ogtr = ((ObservablesGroupTableRow) selectedObject);
                        String obsName = ogtr.getObservableGroupObject().getObservableGroupName();
                        RbmObservable observable = ogtr.getObservable(obsName);
                        Graphics panelContext = table.getGraphics();
                        int xPos = 4;
                        spssList.clear();
                        for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
                            SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, observable, isSelected, issueManager);
                            xPos += spss.getWidth() + 6;
                            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);
                }
            }
        };
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setCellRenderer(rbmObservableShapeDepictionCellRenderer);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setPreferredWidth(150);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setMinWidth(150);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDefinition).setPreferredWidth(80);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColExpression).setPreferredWidth(100);
        observablesTable.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) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) 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) List(java.util.List) ArrayList(java.util.ArrayList) 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) RbmObservable(cbit.vcell.model.RbmObservable) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Point(java.awt.Point) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) JSplitPane(javax.swing.JSplitPane) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border)

Example 2 with MolecularComponentPattern

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

the class XmlReader method getRbmMolecularTypePattern.

private MolecularTypePattern getRbmMolecularTypePattern(Element e, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    Element e1 = e.getChild(XMLTags.RbmMolecularTypeTag, vcNamespace);
    String molecularTypeName = e1.getAttributeValue(XMLTags.NameAttrTag);
    MolecularType mt = mc.getMolecularType(molecularTypeName);
    if (mt == null) {
        System.out.println("XMLReader: getRbmMolecularTypePattern: encountered reference to non-existing MolecularType.");
        return null;
    }
    // we insert the component patterns below
    MolecularTypePattern tp = new MolecularTypePattern(mt, false);
    String index = e.getAttributeValue(XMLTags.RbmIndexAttrTag);
    if (index != null && !index.isEmpty()) {
        tp.setIndex(Integer.parseInt(index));
    }
    String match = e.getAttributeValue(XMLTags.RbmParticipantPatternMatchTag);
    if (match != null && !match.isEmpty()) {
        tp.setParticipantMatchLabel(match);
    }
    List<MolecularComponentPattern> cpl = new ArrayList<MolecularComponentPattern>();
    List<Element> children = e.getChildren(XMLTags.RbmMolecularComponentPatternTag, vcNamespace);
    for (Element e2 : children) {
        MolecularComponentPattern cp = getRbmMolecularComponentPattern(e2, tp, mt, newModel);
        if (cp != null) {
            cpl.add(cp);
        }
    }
    tp.setComponentPatterns(cpl);
    return tp;
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 3 with MolecularComponentPattern

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

the class Xmlproducer method getXML.

private Element getXML(MolecularTypePattern param) {
    Element e = new Element(XMLTags.RbmMolecularTypePatternTag);
    if (param.hasExplicitParticipantMatch()) {
        e.setAttribute(XMLTags.RbmParticipantPatternMatchTag, mangle(param.getParticipantMatchLabel()));
    }
    e.setAttribute(XMLTags.RbmIndexAttrTag, Integer.toString(param.getIndex()));
    Element e1 = new Element(XMLTags.RbmMolecularTypeTag);
    MolecularType mt = param.getMolecularType();
    e1.setAttribute(XMLTags.NameAttrTag, mangle(mt.getName()));
    e.addContent(e1);
    for (MolecularComponentPattern cp : param.getComponentPatternList()) {
        e.addContent(getXML(cp));
    }
    return e;
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) Element(org.jdom.Element)

Example 4 with MolecularComponentPattern

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

the class XmlReader method getRbmMolecularComponentPattern.

private MolecularComponentPattern getRbmMolecularComponentPattern(Element e, MolecularTypePattern mtp, MolecularType mt, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    String s = e.getAttributeValue(XMLTags.RbmMolecularComponentTag);
    if (s == null || s.isEmpty()) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: MolecularComponent name is missing.");
        return null;
    }
    MolecularComponent c = mt.getMolecularComponent(s);
    if (c == null) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponent.");
        return null;
    }
    ComponentStatePattern csp = new ComponentStatePattern();
    MolecularComponentPattern mcp = new MolecularComponentPattern(c);
    s = e.getAttributeValue(XMLTags.RbmMolecularComponentStatePatternTag);
    if (s != null && !s.isEmpty()) {
        // state may be missing, we set it only if is present
        ComponentStateDefinition cs = c.getComponentStateDefinition(s);
        if (cs == null) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponentState.");
            return null;
        }
        csp = new ComponentStatePattern(cs);
        mcp.setComponentStatePattern(csp);
    }
    // s = e.getAttributeValue(XMLTags.RbmMolecularTypeAnyTag);
    // if(s!=null && !s.isEmpty()) {
    // boolean any = Boolean.parseBoolean(s);
    // csp.setAny(any);
    // }
    s = e.getAttributeValue(XMLTags.RbmBondTypeAttrTag);
    BondType bondType = BondType.fromSymbol(s);
    if (bondType == BondType.Specified) {
        int bondId = Integer.parseInt(s);
        mcp.setBondId(bondId);
    }
    mcp.setBondType(bondType);
    // sanity check, we only read the names here and make sure they make sense
    Element bondElement = e.getChild(XMLTags.RbmBondTag, vcNamespace);
    if (bondElement != null) {
        // it's actually the name of the MolecularType inside this pattern
        String molecularTypeName = bondElement.getAttributeValue(XMLTags.RbmMolecularTypePatternTag);
        String molecularComponentName = bondElement.getAttributeValue(XMLTags.RbmMolecularComponentPatternTag);
        if (molecularTypeName == null || molecularTypeName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularTypeName missing.");
            return mcp;
        }
        if (molecularComponentName == null || molecularComponentName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularComponentName missing.");
            return mcp;
        }
        // we'll have a bond here, it will be properly initialized during RbmObservable.resolveBonds() call  !!!
        Bond bond = new Bond();
        mcp.setBond(bond);
    }
    return mcp;
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Element(org.jdom.Element) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 5 with MolecularComponentPattern

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

the class BioModelEditorSpeciesTableModel method checkInputValue.

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

Aggregations

MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)62 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)30 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)25 Graphics (java.awt.Graphics)16 MolecularComponent (org.vcell.model.rbm.MolecularComponent)14 Point (java.awt.Point)13 MolecularType (org.vcell.model.rbm.MolecularType)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 Icon (javax.swing.Icon)9 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)9 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)8 List (java.util.List)7 BioModelNode (cbit.vcell.desktop.BioModelNode)6 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)6 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)6 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)6