Search in sources :

Example 1 with ComponentStateLargeShape

use of cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape in project vcell by virtualcell.

the class MolecularTypePropertiesPanel method editInPlace.

private void editInPlace(final LargeShape selectedShape) {
    if (shapePanel.getComponentCount() > 0) {
        // remove if there's one already present
        // this is the only component that may exist in this panel
        shapePanel.remove(0);
    }
    Rectangle labelOutline = selectedShape.getLabelOutline();
    Font font = selectedShape.getLabelFont();
    // Add press 'Enter' action, 'Escape' action, editor gets focus and mouse 'Exit' parent action
    final JTextField jTextField = new JTextField(selectedShape.getFullName());
    jTextField.setFont(font);
    jTextField.selectAll();
    jTextField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                String name = jTextField.getText();
                // Type specific edit actions
                if (selectedShape instanceof MolecularTypeLargeShape) {
                    ((MolecularTypeLargeShape) selectedShape).getMolecularType().setName(name);
                } else if (selectedShape instanceof MolecularComponentLargeShape) {
                    ((MolecularComponentLargeShape) selectedShape).getMolecularComponent().setName(name);
                } else if (selectedShape instanceof ComponentStateLargeShape) {
                    ((ComponentStateLargeShape) selectedShape).getComponentStateDefinition().setName(name);
                }
            } catch (Exception e2) {
                e2.printStackTrace();
                DialogUtils.showErrorDialog(shapePanel, e2.getMessage());
                shapePanel.remove(0);
                updateInterface();
            }
            if (shapePanel.getComponentCount() > 0) {
                shapePanel.remove(0);
            }
        }
    });
    InputMap im = jTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = jTextField.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), "cancelChange");
    am.put("cancelChange", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            shapePanel.remove(0);
            updateInterface();
        }
    });
    final int MinWidth = 30;
    jTextField.setBounds(labelOutline.x, labelOutline.y, Math.max(labelOutline.width, MinWidth), labelOutline.height);
    shapePanel.add(jTextField);
    // shapePanel.validate();
    jTextField.requestFocus();
    return;
}
Also used : ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) JTextField(javax.swing.JTextField) Font(java.awt.Font) ExpandVetoException(javax.swing.tree.ExpandVetoException) Point(java.awt.Point) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape)

Example 2 with ComponentStateLargeShape

use of cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape in project vcell by virtualcell.

the class MolecularTypePropertiesPanel 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 Object selectedObject;
    if (deepestShape == null) {
        selectedObject = null;
        // when cursor is outside there's nothing to do  ???
        System.out.println("outside");
        return;
    } else if (deepestShape instanceof ComponentStateLargeShape) {
        System.out.println("inside state");
        if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStateDefinition();
        } else {
            // right click only works on highlighted entity, if it's not highlighted we simply return
            return;
        }
    } else if (deepestShape instanceof MolecularComponentLargeShape) {
        System.out.println("inside component");
        if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponent();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularTypeLargeShape) {
        System.out.println("inside molecule");
        if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularType();
        } else {
            return;
        }
    } else if (deepestShape instanceof SpeciesPatternLargeShape) {
        // this cannot happen, here just for symmetry
        System.out.println("inside species pattern");
        if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
        } else {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    System.out.println(selectedObject);
    boolean bDelete = false;
    boolean bAdd = false;
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    if (selectedObject instanceof MolecularType) {
        // rename, add
        if (selectedObject != molecularType) {
            throw new RuntimeException("The selected object from shape different from the current object");
        }
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + MolecularComponent.typeName);
        // Icon icon = new MolecularTypeSmallShape(1, 4, mt, gc, mt);
        // menuItem.setIcon(icon);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent molecularComponent = molecularType.createMolecularComponent();
                molecularType.addMolecularComponent(molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof MolecularComponent) {
        // move left / right / separator / rename, delete, separator, add
        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) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (mcList.size() == fromIndex + 1) {
                    // already the last element
                    return;
                }
                int toIndex = fromIndex + 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        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) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (fromIndex == 0) {
                    // already the first element
                    return;
                }
                int toIndex = fromIndex - 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        popupFromShapeMenu.add(moveLeftMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + ComponentStateDefinition.typeName);
        JMenuItem deleteMenuItem = new JMenuItem("Delete ");
        popupFromShapeMenu.add(deleteMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                // detailed verifications will be done there, to see if they are being used in reactions, species, observables
                if (!mc.getComponentStateDefinitions().isEmpty()) {
                    String[] options = { "OK" };
                    String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
                    errMsg += "<br>Please delete each individual State first.";
                    errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
                    errMsg = "<html>" + errMsg + "</html>";
                    JOptionPane.showOptionDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                    return;
                }
                // we find and display component usage information to help the user decide
                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                bioModel.getModel().getRbmModelContainer().findComponentUsage(molecularType, mc, usedHere);
                if (!usedHere.isEmpty()) {
                    String errMsg = mc.dependenciesToHtml(usedHere);
                    errMsg += "<br><br>Delete anyway?";
                    errMsg = "<html>" + errMsg + "</html>";
                    int dialogButton = JOptionPane.YES_NO_OPTION;
                    int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                            molecularType.removeMolecularComponent(mc);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                        molecularType.removeMolecularComponent(mc);
                    }
                }
            }
        });
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                ComponentStateDefinition componentStateDefinition = mc.createComponentStateDefinition();
                mc.addComponentStateDefinition(componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustSpeciesPatterns(molecularType, mc, componentStateDefinition);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof ComponentStateDefinition) {
        // rename, delete
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem deleteMenuItem = new JMenuItem("Delete");
        popupFromShapeMenu.add(deleteMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ComponentStateDefinition csd = (ComponentStateDefinition) selectedObject;
                // must exist, we're deleting one of its states
                MolecularComponent mc = locationContext.mcs.getMolecularComponent();
                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                bioModel.getModel().getRbmModelContainer().findStateUsage(molecularType, mc, csd, usedHere);
                if (!usedHere.isEmpty()) {
                    String errMsg = csd.dependenciesToHtml(usedHere);
                    errMsg += "<br><br>Delete anyway?";
                    errMsg = "<html>" + errMsg + "</html>";
                    int dialogButton = JOptionPane.YES_NO_OPTION;
                    int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                            mc.deleteComponentStateDefinition(csd);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                        mc.deleteComponentStateDefinition(csd);
                    }
                }
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) JSeparator(javax.swing.JSeparator) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) JMenuItem(javax.swing.JMenuItem) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) Pair(org.vcell.util.Pair) Displayable(org.vcell.util.Displayable) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MolecularType(org.vcell.model.rbm.MolecularType) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) LargeShape(cbit.vcell.graph.LargeShape) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Icon(javax.swing.Icon) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap)

Example 3 with ComponentStateLargeShape

use of cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape 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 4 with ComponentStateLargeShape

use of cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape in project vcell by virtualcell.

the class ReactionRuleEditorPropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    final Object deepestShape = locationContext.getDeepestShape();
    final RbmObject 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 {
            return;
        }
    } else if (deepestShape instanceof ReactionRulePatternLargeShape) {
        System.out.println("inside reactant line or products line");
        if (((ReactionRulePatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ReactionRulePatternLargeShape) deepestShape).getReactionRule();
        } else {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    boolean bReactantsZone = false;
    int xExtent = SpeciesPatternLargeShape.calculateXExtent(shapePanel);
    Rectangle2D reactantRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetReactantInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
    Rectangle2D productRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetProductInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
    if (locationContext.isInside(reactantRectangle)) {
        // clicked inside the reactant rectangle (above yOffsetProductInitial)
        bReactantsZone = true;
    } else if (locationContext.isInside(productRectangle)) {
        // clicked inside the product rectangle (below yOffsetProductInitial)
        bReactantsZone = false;
    } else {
        return;
    }
    // -------------------------------- reactant zone --------------------------------------------------------
    if (bReactantsZone) {
        if (selectedObject == null) {
            return;
        } else if (selectedObject instanceof ReactionRule) {
            // add reactant pattern
            JMenuItem addMenuItem = new JMenuItem("Add Reactant");
            addMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), reactionRule.getStructure()));
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(addMenuItem);
        } else if (selectedObject instanceof SpeciesPattern) {
            // delete (pattern) / specify molecule
            final SpeciesPattern sp = (SpeciesPattern) selectedObject;
            JMenuItem deleteMenuItem = new JMenuItem("Delete");
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
                        if (rp.getSpeciesPattern() == sp) {
                            reactionRule.removeReactant(rp);
                            Structure st = rp.getStructure();
                            if (reactionRule.getReactantPatterns().isEmpty()) {
                                reactionRule.addReactant(new ReactantPattern(new SpeciesPattern(), st));
                                shapePanel.repaint();
                            }
                        }
                    }
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            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.Possible);
                        }
                        sp.addMolecularTypePattern(molecularTypePattern);
                        shapePanel.repaint();
                    }
                });
            }
            JMenu compartmentMenuItem = new JMenu("Specify structure");
            popupFromShapeMenu.add(compartmentMenuItem);
            if (sp.getMolecularTypePatterns().isEmpty()) {
                compartmentMenuItem.setEnabled(false);
            }
            compartmentMenuItem.removeAll();
            for (final Structure struct : bioModel.getModel().getStructures()) {
                JMenuItem menuItem = new JMenuItem(struct.getName());
                compartmentMenuItem.add(menuItem);
                for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                    MolecularType mt = mtp.getMolecularType();
                    if (mt.isAnchorAll()) {
                        // no restrictions (no anchor exclusion) for this molecular type
                        continue;
                    }
                    if (!mt.getAnchors().contains(struct)) {
                        // sp can't be in this struct if any of its molecules is excluded (not anchored)
                        menuItem.setEnabled(false);
                        break;
                    }
                }
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        String nameStruct = e.getActionCommand();
                        Structure struct = bioModel.getModel().getStructure(nameStruct);
                        ReactantPattern rp = reactionRule.getReactantPattern(sp);
                        rp.setStructure(struct);
                        productTreeModel.populateTree();
                        shapePanel.repaint();
                    }
                });
            }
        } else if (selectedObject instanceof MolecularTypePattern) {
            // move left / right / delete molecule / reassign match
            MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
            int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
            String moveRightMenuText = "Move <b>" + "right" + "</b>";
            moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
            JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
            Icon icon = VCellIcons.moveRightIcon;
            moveRightMenuItem.setIcon(icon);
            moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveRightMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftRight(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            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.setEnabled(numMtp < 2 ? false : true);
            moveLeftMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftLeft(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            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);
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            if (mtp.hasExplicitParticipantMatch()) {
                String newKey = mtp.getParticipantMatchLabel();
                List<String> keyCandidates = new ArrayList<String>();
                List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
                List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
                for (MolecularTypePattern mtpCandidate : mtpReactantList) {
                    // we can look for indexes in any list, we should find the same
                    if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
                        keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
                    }
                }
                if (!keyCandidates.isEmpty()) {
                    JMenu reassignMatchMenuItem = new JMenu();
                    reassignMatchMenuItem.setText("Reassign match to");
                    for (int i = 0; i < keyCandidates.size(); i++) {
                        JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
                        reassignMatchMenuItem.add(menuItem);
                        menuItem.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                String oldKey = e.getActionCommand();
                                MolecularTypePattern orphanReactant = reactionRule.findMatch(oldKey, mtpReactantList);
                                mtp.setParticipantMatchLabel(oldKey);
                                orphanReactant.setParticipantMatchLabel(newKey);
                                // TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
                                // when the tree will be gone
                                reactantTreeModel.populateTree();
                                productTreeModel.populateTree();
                                shapePanel.repaint();
                                SwingUtilities.invokeLater(new Runnable() {

                                    public void run() {
                                        reactantShape.flash(oldKey);
                                        productShape.flash(oldKey);
                                    }
                                });
                            }
                        });
                    }
                    popupFromShapeMenu.add(reassignMatchMenuItem);
                }
            }
        } else if (selectedObject instanceof MolecularComponentPattern) {
            // edit bond / edit state
            manageComponentPatternFromShape(selectedObject, locationContext, reactantTreeModel, ShowWhat.ShowBond, bReactantsZone);
        } else if (selectedObject instanceof ComponentStatePattern) {
            // edit state
            MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
            manageComponentPatternFromShape(mcp, locationContext, reactantTreeModel, ShowWhat.ShowState, bReactantsZone);
        }
    // ---------------------------------------- product zone ---------------------------------------------
    } else if (!bReactantsZone) {
        if (selectedObject == null) {
            return;
        } else if (selectedObject instanceof ReactionRule) {
            // add product pattern
            JMenuItem addMenuItem = new JMenuItem("Add Product");
            addMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), reactionRule.getStructure()));
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(addMenuItem);
        } else if (selectedObject instanceof SpeciesPattern) {
            // delete (pattern) / specify molecule
            final SpeciesPattern sp = (SpeciesPattern) selectedObject;
            JMenuItem deleteMenuItem = new JMenuItem("Delete");
            deleteMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    for (ProductPattern pp : reactionRule.getProductPatterns()) {
                        if (pp.getSpeciesPattern() == sp) {
                            reactionRule.removeProduct(pp);
                            Structure st = pp.getStructure();
                            if (reactionRule.getProductPatterns().isEmpty()) {
                                reactionRule.addProduct(new ProductPattern(new SpeciesPattern(), st));
                                shapePanel.repaint();
                            }
                        }
                    }
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            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.Possible);
                        }
                        sp.addMolecularTypePattern(molecularTypePattern);
                        shapePanel.repaint();
                    }
                });
            }
            // specify structure
            JMenu compartmentMenuItem = new JMenu("Specify structure");
            popupFromShapeMenu.add(compartmentMenuItem);
            compartmentMenuItem.removeAll();
            if (sp.getMolecularTypePatterns().isEmpty()) {
                compartmentMenuItem.setEnabled(false);
            }
            for (final Structure struct : bioModel.getModel().getStructures()) {
                JMenuItem menuItem = new JMenuItem(struct.getName());
                compartmentMenuItem.add(menuItem);
                for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                    MolecularType mt = mtp.getMolecularType();
                    if (mt.isAnchorAll()) {
                        // no restrictions for this molecular type
                        continue;
                    }
                    if (!mt.getAnchors().contains(struct)) {
                        // sp can't be in this struct if any of its molecules is excluded (not anchored)
                        menuItem.setEnabled(false);
                        break;
                    }
                }
                menuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        String nameStruct = e.getActionCommand();
                        Structure struct = bioModel.getModel().getStructure(nameStruct);
                        ProductPattern pp = reactionRule.getProductPattern(sp);
                        pp.setStructure(struct);
                        productTreeModel.populateTree();
                        shapePanel.repaint();
                    }
                });
            }
        } else if (selectedObject instanceof MolecularTypePattern) {
            // move left / right / delete molecule / reassign match
            MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
            int numMtp = locationContext.sps.getSpeciesPattern().getMolecularTypePatterns().size();
            String moveRightMenuText = "Move <b>" + "right" + "</b>";
            moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
            JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
            Icon icon = VCellIcons.moveRightIcon;
            moveRightMenuItem.setIcon(icon);
            moveRightMenuItem.setEnabled(numMtp < 2 ? false : true);
            moveRightMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftRight(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            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.setEnabled(numMtp < 2 ? false : true);
            moveLeftMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern from = (MolecularTypePattern) selectedObject;
                    SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
                    sp.shiftLeft(from);
                    reactantTreeModel.populateTree();
                    productTreeModel.populateTree();
                    shapePanel.repaint();
                }
            });
            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);
                    shapePanel.repaint();
                }
            });
            popupFromShapeMenu.add(deleteMenuItem);
            if (mtp.hasExplicitParticipantMatch()) {
                String newKey = mtp.getParticipantMatchLabel();
                List<String> keyCandidates = new ArrayList<String>();
                List<MolecularTypePattern> mtpReactantList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Reactant);
                List<MolecularTypePattern> mtpProductList = reactionRule.populateMaps(mtp.getMolecularType(), ReactionRuleParticipantType.Product);
                for (MolecularTypePattern mtpCandidate : mtpReactantList) {
                    // we can look for indexes in any list, we should find the same
                    if (mtpCandidate.hasExplicitParticipantMatch() && !mtpCandidate.getParticipantMatchLabel().equals(newKey)) {
                        keyCandidates.add(mtpCandidate.getParticipantMatchLabel());
                    }
                }
                if (!keyCandidates.isEmpty()) {
                    JMenu reassignMatchMenuItem = new JMenu();
                    reassignMatchMenuItem.setText("Reassign match to");
                    for (int i = 0; i < keyCandidates.size(); i++) {
                        JMenuItem menuItem = new JMenuItem(keyCandidates.get(i));
                        reassignMatchMenuItem.add(menuItem);
                        menuItem.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                String oldKey = e.getActionCommand();
                                MolecularTypePattern orphanProduct = reactionRule.findMatch(oldKey, mtpProductList);
                                mtp.setParticipantMatchLabel(oldKey);
                                orphanProduct.setParticipantMatchLabel(newKey);
                                // TODO: replace the populate tree with reactantPatternShapeList.update() and productPatternShapeList.update()
                                // when the tree will be gone
                                reactantTreeModel.populateTree();
                                productTreeModel.populateTree();
                                shapePanel.repaint();
                                SwingUtilities.invokeLater(new Runnable() {

                                    public void run() {
                                        reactantShape.flash(oldKey);
                                        productShape.flash(oldKey);
                                    }
                                });
                            }
                        });
                    }
                    popupFromShapeMenu.add(reassignMatchMenuItem);
                }
            }
        } else if (selectedObject instanceof MolecularComponentPattern) {
            // edit bond / edit state
            manageComponentPatternFromShape(selectedObject, locationContext, productTreeModel, ShowWhat.ShowBond, bReactantsZone);
        } else if (selectedObject instanceof ComponentStatePattern) {
            // edit state
            MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
            manageComponentPatternFromShape(mcp, locationContext, productTreeModel, ShowWhat.ShowState, bReactantsZone);
        }
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) List(java.util.List) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) Structure(cbit.vcell.model.Structure) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) ReactantPattern(cbit.vcell.model.ReactantPattern) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmObject(org.vcell.model.rbm.RbmObject) RbmObject(org.vcell.model.rbm.RbmObject) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ReactionRulePatternLargeShape(cbit.vcell.graph.ReactionRulePatternLargeShape) JMenu(javax.swing.JMenu)

Example 5 with ComponentStateLargeShape

use of cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape in project vcell by virtualcell.

the class ObservablePropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    boolean bDelete = false;
    boolean bAdd = false;
    boolean bEdit = false;
    boolean bRename = false;
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    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 {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    if (selectedObject instanceof SpeciesPattern) {
        getAddFromShapeMenu().setText(VCellErrorMessages.AddMolecularTypes);
        getAddFromShapeMenu().removeAll();
        for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
            JMenuItem menuItem = new JMenuItem(mt.getName());
            Graphics gc = splitPaneHorizontal.getGraphics();
            Icon icon = new MolecularTypeSmallShape(4, 4, mt, null, gc, mt, null, issueManager);
            menuItem.setIcon(icon);
            getAddFromShapeMenu().add(menuItem);
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
                    ((SpeciesPattern) selectedObject).addMolecularTypePattern(molecularTypePattern);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                        }
                    });
                }
            });
        }
        JMenu compartmentMenuItem = new JMenu("Specify structure (for all)");
        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);
                    observable.setStructure(struct);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            // repaint tree
                            observableTreeModel.populateTree();
                        // observableTree.scrollPathToVisible(path);	// scroll back up to show the observable
                        }
                    });
                }
            });
        }
        JMenuItem deleteMenuItem = new JMenuItem("Delete Species Pattern");
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                // observable.getSpeciesPatternList().remove((SpeciesPattern)selectedObject);
                observable.removeSpeciesPattern((SpeciesPattern) selectedObject);
                final TreePath path = observableTreeModel.findObjectPath(null, observable);
                observableTree.setSelectionPath(path);
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        // repaint tree
                        observableTreeModel.populateTree();
                        // scroll back up to show the observable
                        observableTree.scrollPathToVisible(path);
                    }
                });
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(getAddFromShapeMenu());
        popupFromShapeMenu.add(compartmentMenuItem);
    } 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);
                observableTreeModel.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);
                observableTreeModel.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);
            }
        });
        popupFromShapeMenu.add(deleteMenuItem);
    } else if (selectedObject instanceof MolecularComponentPattern) {
        manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
        bDelete = false;
    } else if (selectedObject instanceof ComponentStatePattern) {
        MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
        manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
    }
    if (bRename) {
        popupFromShapeMenu.add(getRenameFromShapeMenuItem());
    }
    if (bDelete) {
        popupFromShapeMenu.add(getDeleteFromShapeMenuItem());
    }
    if (bEdit) {
        popupFromShapeMenu.add(getEditFromShapeMenuItem());
    }
    if (bAdd) {
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(getAddFromShapeMenu());
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) JMenuItem(javax.swing.JMenuItem) Structure(cbit.vcell.model.Structure) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmElementAbstract(org.vcell.model.rbm.RbmElementAbstract) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) JMenu(javax.swing.JMenu)

Aggregations

MolecularComponentLargeShape (cbit.vcell.graph.MolecularComponentLargeShape)5 ComponentStateLargeShape (cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape)5 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)5 Point (java.awt.Point)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)4 Icon (javax.swing.Icon)4 JMenuItem (javax.swing.JMenuItem)4 JPopupMenu (javax.swing.JPopupMenu)4 JSeparator (javax.swing.JSeparator)4 MolecularType (org.vcell.model.rbm.MolecularType)4 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)4 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)3 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)3 Graphics (java.awt.Graphics)3 JMenu (javax.swing.JMenu)3 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)3 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)3 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)3