Search in sources :

Example 6 with SpeciesPatternLargeShape

use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.

the class ObservablePropertiesPanel method initialize.

private void initialize() {
    observableTree = new BioModelNodeEditableTree();
    observableTreeModel = new ObservableTreeModel(observableTree);
    observableTree.setModel(observableTreeModel);
    setLayout(new GridBagLayout());
    // --------------------------------------------------------------------------------------------------------
    splitPaneHorizontal.setOneTouchExpandable(true);
    splitPaneHorizontal.setDividerLocation(120);
    splitPaneHorizontal.setResizeWeight(0.1);
    Border border = BorderFactory.createLineBorder(Color.gray);
    Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
    Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
    TitledBorder annotationBorder = BorderFactory.createTitledBorder(loweredEtchedBorder, " Annotation ");
    annotationBorder.setTitleJustification(TitledBorder.LEFT);
    annotationBorder.setTitlePosition(TitledBorder.TOP);
    annotationBorder.setTitleFont(getFont().deriveFont(Font.BOLD));
    shapePanel = 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;
        }
    };
    shapePanel.setBorder(border);
    shapePanel.setBackground(Color.white);
    shapePanel.setLayout(null);
    shapePanel.setZoomFactor(-1);
    shapePanel.setEditable(true);
    shapePanel.setShowMoleculeColor(true);
    shapePanel.setShowNonTrivialOnly(true);
    shapePanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getButton() == 1) {
                // left click selects the object (we highlight it)
                Point whereClicked = e.getPoint();
                PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                manageMouseActivity(locationContext);
            } else if (e.getButton() == 3) {
                // right click invokes popup menu (only if the object is highlighted)
                Point whereClicked = e.getPoint();
                PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                manageMouseActivity(locationContext);
                if (locationContext.getDeepestShape() != null && !locationContext.getDeepestShape().isHighlighted()) {
                // TODO: (maybe) add code here to highlight the shape if it's not highlighted already but don't show the menu
                // return;
                }
                showPopupMenu(e, locationContext);
            }
        }

        private void manageMouseActivity(PointLocationInShapeContext locationContext) {
            Graphics g = shapePanel.getGraphics();
            for (SpeciesPatternLargeShape sps : spsList) {
                sps.turnHighlightOffRecursive(g);
            }
            for (SpeciesPatternLargeShape sps : spsList) {
                if (sps.contains(locationContext)) {
                    // check if mouse is inside shape
                    break;
                }
            }
            locationContext.highlightDeepestShape();
            locationContext.paintDeepestShape(g);
        }
    });
    // shapePanel.addMouseListener(eventHandler);		// alternately use this
    shapePanel.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent e) {
            Point overWhat = e.getPoint();
            PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
            for (SpeciesPatternLargeShape sps : spsList) {
                if (sps.contains(locationContext)) {
                    break;
                }
            }
            HighlightableShapeInterface hsi = locationContext.getDeepestShape();
            if (hsi == null) {
                shapePanel.setToolTipText(null);
            } else {
                shapePanel.setToolTipText("Right click for " + hsi.getDisplayType() + " menus");
            }
            for (SpeciesPatternLargeShape sps : spsList) {
                for (MolecularTypeLargeShape mtls : sps.getMolecularTypeLargeShapes()) {
                    Rectangle r = mtls.getAnchorHotspot();
                    if (r != null && r.contains(overWhat)) {
                        mtls.getMolecularType();
                        shapePanel.setToolTipText(mtls.getAnchorsHTML());
                        break;
                    }
                }
            }
        }
    });
    JPanel optionsPanel = new JPanel();
    // gray options panel
    optionsPanel.setPreferredSize(new Dimension(140, 200));
    optionsPanel.setLayout(new GridBagLayout());
    getZoomSmallerButton().setEnabled(true);
    getZoomLargerButton().setEnabled(true);
    int gridy = 0;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 3;
    // top, left bottom, right
    gbc.insets = new Insets(4, 4, 2, 4);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    optionsPanel.add(getAddSpeciesButton(), gbc);
    ButtonGroup bg = new ButtonGroup();
    bg.add(getSequenceMultimolecularButton());
    bg.add(getSequencePolimerEqualButton());
    bg.add(getSequencePolimerGreaterButton());
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(8, 4, 2, 4);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionsPanel.add(getSequenceMultimolecularButton(), gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(4, 10, 2, 4);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    JLabel label = new JLabel("Polymer of");
    label.setToolTipText("Compact notation available below for single-Molecule polymers");
    optionsPanel.add(label, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(2, 4, 1, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionsPanel.add(getSequencePolimerEqualButton(), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(2, 4, 1, 4);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionsPanel.add(getLengthEqualTextField(), gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(1, 4, 4, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionsPanel.add(getSequencePolimerGreaterButton(), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(1, 4, 4, 4);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionsPanel.add(getLengthGreaterTextField(), gbc);
    // --- zoom buttons in their own panel, for alignment ---
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc2 = new GridBagConstraints();
    gbc2.gridx = 0;
    gbc2.gridy = 0;
    gbc2.insets = new Insets(1, 1, 1, 1);
    gbc2.anchor = GridBagConstraints.WEST;
    buttonPanel.add(getZoomLargerButton(), gbc2);
    gbc2 = new GridBagConstraints();
    gbc2.gridx = 1;
    gbc2.gridy = 0;
    gbc2.insets = new Insets(1, 1, 1, 1);
    gbc2.anchor = GridBagConstraints.WEST;
    buttonPanel.add(getZoomSmallerButton(), gbc2);
    // ---------------------------------------------------
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(1, 4, 4, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    // zoom buttons panel
    optionsPanel.add(buttonPanel, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 3;
    gbc.weightx = 1;
    // fake cell used for filling all the vertical empty space
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(2, 1, 2, 10);
    optionsPanel.add(new JLabel(""), gbc);
    // -----------------------------------------------------------------------------------------
    // right bottom panel, contains just the annotation
    JPanel generalPanel = new JPanel();
    generalPanel.setBorder(annotationBorder);
    generalPanel.setLayout(new GridBagLayout());
    gridy = 0;
    annotationTextArea = new javax.swing.JTextArea("", 1, 30);
    annotationTextArea.setLineWrap(true);
    annotationTextArea.setWrapStyleWord(true);
    annotationTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
    annotationTextArea.setEditable(false);
    javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(annotationTextArea);
    gbc = new java.awt.GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.weighty = 0.1;
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.insets = new Insets(4, 4, 4, 4);
    generalPanel.add(jsp, gbc);
    // where we display the shapes
    scrollPane = new JScrollPane(shapePanel);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    JPanel containerOfScrollPanel = new JPanel();
    containerOfScrollPanel.setLayout(new BorderLayout());
    containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
    containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
    splitPaneHorizontal.setTopComponent(containerOfScrollPanel);
    splitPaneHorizontal.setBottomComponent(generalPanel);
    splitPaneHorizontal.setResizeWeight(0.9d);
    splitPaneHorizontal.setDividerLocation(0.8d);
    setName("ObservablePropertiesPanel");
    setLayout(new BorderLayout());
    add(splitPaneHorizontal, BorderLayout.CENTER);
    setBackground(Color.white);
    annotationTextArea.addFocusListener(eventHandler);
    annotationTextArea.addMouseListener(eventHandler);
}
Also used : JPanel(javax.swing.JPanel) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Rectangle(java.awt.Rectangle) TitledBorder(javax.swing.border.TitledBorder) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) Font(java.awt.Font) LargeShapePanel(cbit.vcell.graph.gui.LargeShapePanel) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) BorderLayout(java.awt.BorderLayout) 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) MouseAdapter(java.awt.event.MouseAdapter) HighlightableShapeInterface(cbit.vcell.graph.HighlightableShapeInterface) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) PointLocationInShapeContext(cbit.vcell.graph.PointLocationInShapeContext) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) JScrollPane(javax.swing.JScrollPane) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) ButtonGroup(javax.swing.ButtonGroup) JTextArea(javax.swing.JTextArea) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) EtchedBorder(javax.swing.border.EtchedBorder)

Example 7 with SpeciesPatternLargeShape

use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.

the class SpeciesPropertiesPanel method updateShape.

private void updateShape() {
    if (fieldSpeciesContext != null) {
        SpeciesPattern sp = fieldSpeciesContext.getSpeciesPattern();
        spls = new SpeciesPatternLargeShape(xOffsetInitial, yOffsetInitial, -1, sp, shapePanel, fieldSpeciesContext, issueManager);
        int maxXOffset = xOffsetInitial + spls.getWidth();
        int maxYOffset = yOffsetInitial + 80;
        Dimension preferredSize = new Dimension(maxXOffset + 120, maxYOffset + 20);
        shapePanel.setPreferredSize(preferredSize);
        shapePanel.repaint();
    // scrollPane.repaint();
    }
}
Also used : Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point)

Example 8 with SpeciesPatternLargeShape

use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.

the class SpeciesPropertiesPanel method showPopupMenu.

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

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
                    for (MolecularComponentPattern mcp : molecularTypePattern.getComponentPatternList()) {
                        mcp.setBondType(BondType.None);
                    }
                    if (!fieldSpeciesContext.hasSpeciesPattern()) {
                        fieldSpeciesContext.setSpeciesPattern(sp);
                    }
                    fieldSpeciesContext.getSpeciesPattern().addMolecularTypePattern(molecularTypePattern);
                }
            });
        }
    // JMenu compartmentMenuItem = new JMenu("Specify structure");
    // popupFromShapeMenu.add(compartmentMenuItem);
    // compartmentMenuItem.removeAll();
    // for (final Structure struct : bioModel.getModel().getStructures()) {
    // JMenuItem menuItem = new JMenuItem(struct.getName());
    // compartmentMenuItem.add(menuItem);
    // menuItem.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // String nameStruct = e.getActionCommand();
    // Structure struct = bioModel.getModel().getStructure(nameStruct);
    // fieldSpeciesContext.setStructure(struct);
    // }
    // });
    // }
    } else if (selectedObject instanceof MolecularTypePattern) {
        MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
        String moveRightMenuText = "Move <b>" + "right" + "</b>";
        moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
        JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
        Icon icon = VCellIcons.moveRightIcon;
        moveRightMenuItem.setIcon(icon);
        moveRightMenuItem.addActionListener(new ActionListener() {

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

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

            public void actionPerformed(ActionEvent e) {
                MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
                SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                sp.removeMolecularTypePattern(mtp);
                if (sp.getMolecularTypePatterns().isEmpty()) {
                    fieldSpeciesContext.setSpeciesPattern(null);
                }
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
    } else if (selectedObject instanceof MolecularComponentPattern) {
        manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
    } else if (selectedObject instanceof ComponentStatePattern) {
        MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
        manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
    } else {
        System.out.println("Where am I ???");
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ActionEvent(java.awt.event.ActionEvent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Point(java.awt.Point) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) JPopupMenu(javax.swing.JPopupMenu) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmElementAbstract(org.vcell.model.rbm.RbmElementAbstract) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) Icon(javax.swing.Icon) JMenuItem(javax.swing.JMenuItem) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) JMenu(javax.swing.JMenu)

Example 9 with SpeciesPatternLargeShape

use of cbit.vcell.graph.SpeciesPatternLargeShape 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)

Example 10 with SpeciesPatternLargeShape

use of cbit.vcell.graph.SpeciesPatternLargeShape in project vcell by virtualcell.

the class ViewGeneratedSpeciesPanel method updateShape.

public void updateShape(int selectedRow) {
    GeneratedSpeciesTableRow speciesTableRow = tableModel.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, shapePanel, sc, issueManager);
    } catch (ParseException | PropertyVetoException | ModelException e1) {
        e1.printStackTrace();
        // error (red circle)
        spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
        shapePanel.repaint();
    }
    int xOffset = spls.getRightEnd() + 45;
    Dimension preferredSize = new Dimension(xOffset + 90, 50);
    shapePanel.setPreferredSize(preferredSize);
    shapePanel.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) 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)

Aggregations

SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)15 Point (java.awt.Point)14 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)12 Dimension (java.awt.Dimension)11 MolecularType (org.vcell.model.rbm.MolecularType)7 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 Graphics (java.awt.Graphics)6 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)6 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)5 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)4 MolecularComponentLargeShape (cbit.vcell.graph.MolecularComponentLargeShape)4 ComponentStateLargeShape (cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 Structure (cbit.vcell.model.Structure)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Icon (javax.swing.Icon)4 JMenuItem (javax.swing.JMenuItem)4