Search in sources :

Example 91 with JPopupMenu

use of javax.swing.JPopupMenu in project vcell by virtualcell.

the class SpatialProcessDisplayPanel method initialize.

private void initialize() {
    setName("SpatialProcessDisplayPanel");
    setLayout(new GridBagLayout());
    int gridy = 0;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.LINE_END;
    gbc.insets = new Insets(4, 4, 4, 4);
    add(new JLabel("Search "), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.weightx = 1.0;
    gbc.gridwidth = 2;
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(4, 4, 4, 4);
    add(textFieldSearch, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.gridy = gridy;
    gbc.insets = new Insets(4, 50, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    add(addNewButton, gbc);
    addNewButton.setIcon(new DownArrowIcon());
    addNewButton.setHorizontalTextPosition(SwingConstants.LEFT);
    addNewButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();
            JMenuItem newPointLocationMenuItem = new JMenuItem(new AbstractAction("new Point Location") {

                public void actionPerformed(ActionEvent e) {
                    createNewPointLocation();
                }
            });
            JMenuItem newPointKinematicsMenuItem = new JMenuItem(new AbstractAction("new Point Kinematics") {

                public void actionPerformed(ActionEvent e) {
                    createNewPointKinematics();
                }
            });
            JMenuItem newSurfaceKinematicsMenuItem = new JMenuItem(new AbstractAction("new Surface Kinematics") {

                public void actionPerformed(ActionEvent e) {
                    createNewSurfaceKinematics();
                }
            });
            JMenuItem newVolumeKinematicsMenuItem = new JMenuItem(new AbstractAction("new Volume Kinematics") {

                public void actionPerformed(ActionEvent e) {
                    createNewVolumeKinematics();
                }
            });
            newPointLocationMenuItem.setIcon(VCellIcons.addIcon(VCellIcons.spatialPointIcon, VCellIcons.spatialLocationIcon));
            newPointKinematicsMenuItem.setIcon(VCellIcons.addIcon(VCellIcons.spatialPointIcon, VCellIcons.spatialKinematicsIcon));
            newSurfaceKinematicsMenuItem.setIcon(VCellIcons.addIcon(VCellIcons.spatialMembraneIcon, VCellIcons.spatialKinematicsIcon));
            newVolumeKinematicsMenuItem.setIcon(VCellIcons.addIcon(VCellIcons.spatialVolumeIcon, VCellIcons.spatialKinematicsIcon));
            popup.add(newPointLocationMenuItem);
            popup.add(newPointKinematicsMenuItem);
            popup.add(newSurfaceKinematicsMenuItem);
            popup.add(newVolumeKinematicsMenuItem);
            popup.show(addNewButton, 0, addNewButton.getHeight());
        }
    });
    // for now disable 'add' button
    // addNewButton.setEnabled(false);
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.LINE_END;
    add(deleteButton, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridy = gridy;
    gbc.weighty = 1.0;
    gbc.weightx = 1.0;
    gbc.gridwidth = 6;
    gbc.fill = GridBagConstraints.BOTH;
    add(table.getEnclosingScrollPane(), gbc);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) DownArrowIcon(org.vcell.util.gui.DownArrowIcon) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JPopupMenu(javax.swing.JPopupMenu)

Example 92 with JPopupMenu

use of javax.swing.JPopupMenu 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 93 with JPopupMenu

use of javax.swing.JPopupMenu in project vcell by virtualcell.

the class TestingFrameworkPanel method getLoadTestMenu.

private JPopupMenu getLoadTestMenu() {
    JPopupMenu mainLoadTestMenu = new JPopupMenu();
    if (getTreeSelection() instanceof String && ((String) getTreeSelection()).equals(TestingFrmwkTreeModel.LOAD_TEST_SUBTREE_NAME)) {
        JMenuItem refreshThresholdMenuItem = new JMenuItem("Refresh (with load time threshold)...");
        refreshThresholdMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    String result = DialogUtils.showInputDialog0(TestingFrameworkPanel.this, "Enter load time threshold (millseconds)", "10000");
                    slowLoadThreshold = (result == null || result.length() == 0 ? null : new Integer(result));
                    ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.REFRESH_XML_LOAD_TEST);
                    TestingFrameworkPanel.this.refireActionPerformed(refresh);
                } catch (UtilCancelException uce) {
                // ignore
                } catch (Exception e2) {
                    e2.printStackTrace();
                    DialogUtils.showErrorDialog(TestingFrameworkPanel.this, e2.getMessage(), e2);
                }
            }
        });
        mainLoadTestMenu.add(refreshThresholdMenuItem);
        JMenuItem loadTestSQLMenuItem = new JMenuItem("Add SQL Condition...");
        loadTestSQLMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    String result = DialogUtils.showInputDialog0(TestingFrameworkPanel.this, "Enter SQL Condition", loadTestSQLCondition);
                    loadTestSQLCondition = (result == null || result.length() == 0 ? null : result);
                    ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.REFRESH_XML_LOAD_TEST);
                    TestingFrameworkPanel.this.refireActionPerformed(refresh);
                } catch (UtilCancelException uce) {
                // ignore
                } catch (Exception e2) {
                    e2.printStackTrace();
                    DialogUtils.showErrorDialog(TestingFrameworkPanel.this, e2.getMessage(), e2);
                }
            }
        });
        mainLoadTestMenu.add(loadTestSQLMenuItem);
        JMenuItem runXMLLoadTestAllMenuItem = new JMenuItem("Run XML Load Test for all models...");
        runXMLLoadTestAllMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.RUN_XML_LOAD_TEST_All);
                TestingFrameworkPanel.this.refireActionPerformed(refresh);
            }
        });
        mainLoadTestMenu.add(runXMLLoadTestAllMenuItem);
    }
    if (getTreeSelection() instanceof LoadTestTreeInfo && ((LoadTestTreeInfo) getTreeSelection()).userid == null) {
        JMenuItem deleteLoadTestMenuItem = new JMenuItem("Delete Load Test...");
        deleteLoadTestMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.DELETE_XML_LOAD_TEST);
                TestingFrameworkPanel.this.refireActionPerformed(refresh);
            }
        });
        mainLoadTestMenu.add(deleteLoadTestMenuItem);
    }
    if (getTreeSelection() instanceof LoadTestTreeInfo && ((LoadTestTreeInfo) getTreeSelection()).userid != null) {
        JMenuItem loadModelSelectedMenuItem = new JMenuItem(TestingFrameworkPanel.LOAD_MODEL);
        loadModelSelectedMenuItem.setEnabled(getJTree1().getSelectionCount() == 1);
        loadModelSelectedMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.LOAD_MODEL);
                TestingFrameworkPanel.this.refireActionPerformed(refresh);
            }
        });
        mainLoadTestMenu.add(loadModelSelectedMenuItem);
        JMenuItem runXMLLoadTestModelsSelectedMenuItem = new JMenuItem("Run XML Load Test for selected models...");
        runXMLLoadTestModelsSelectedMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.RUN_XML_LOAD_TEST_MODELS);
                TestingFrameworkPanel.this.refireActionPerformed(refresh);
            }
        });
        mainLoadTestMenu.add(runXMLLoadTestModelsSelectedMenuItem);
        JMenuItem runXMLLoadTestUsersSelectedMenuItem = new JMenuItem("Run XML Load Test for selected Users...");
        runXMLLoadTestUsersSelectedMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ActionEvent refresh = new ActionEvent(TestingFrameworkPanel.this, ActionEvent.ACTION_PERFORMED, TestingFrameworkPanel.RUN_XML_LOAD_TEST_USERS);
                TestingFrameworkPanel.this.refireActionPerformed(refresh);
            }
        });
        mainLoadTestMenu.add(runXMLLoadTestUsersSelectedMenuItem);
    }
    return mainLoadTestMenu;
}
Also used : UtilCancelException(org.vcell.util.UtilCancelException) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) LoadTestTreeInfo(cbit.vcell.client.desktop.testingframework.TestingFrmwkTreeModel.LoadTestTreeInfo) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) UtilCancelException(org.vcell.util.UtilCancelException)

Example 94 with JPopupMenu

use of javax.swing.JPopupMenu in project vcell by virtualcell.

the class TestingFrameworkPanel method actionsOnMouseClick.

/**
 * Comment
 */
private void actionsOnMouseClick(MouseEvent mouseEvent) {
    if (mouseEvent.isPopupTrigger()) {
        if (getJTree1().getSelectionCount() <= 1) {
            getJTree1().setSelectionPath(getJTree1().getPathForLocation(mouseEvent.getPoint().x, mouseEvent.getPoint().y));
        }
        if (!checkAllSameType()) {
            JPopupMenu jPopupMenu = new JPopupMenu();
            jPopupMenu.add(selectIncompatibleWarning);
            jPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
            return;
        }
        if (isLoadTestPopup()) {
            getLoadTestMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
        } else if (getTreeSelection() instanceof String) {
            if (((String) getTreeSelection()).equals(TestingFrmwkTreeModel.TEST_SUITE_SUBTREE_NAME)) {
                getMainPopupMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
            }
        } else if (getTreeSelection() instanceof TestingFrmwkTreeModel.TestCriteriaVarUserObj) {
            getTCritVarPopupMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
        } else if (getTreeSelection() instanceof TestSuiteInfoNew) {
            getRemoveDiffTestCriteriaJMenuItem().setEnabled(false);
            if (getJTree1().getSelectionCount() == 2) {
                TestSuiteInfoNew testSuiteInfoNew0 = (TestSuiteInfoNew) ((BioModelNode) getSelectedTreePaths()[0].getLastPathComponent()).getUserObject();
                TestSuiteInfoNew testSuiteInfoNew1 = (TestSuiteInfoNew) ((BioModelNode) getSelectedTreePaths()[1].getLastPathComponent()).getUserObject();
                if (testSuiteInfoNew0.getTSDate().compareTo(testSuiteInfoNew1.getTSDate()) < 0) {
                    getRemoveDiffTestCriteriaJMenuItem().setEnabled(!testSuiteInfoNew1.isLocked());
                } else {
                    getRemoveDiffTestCriteriaJMenuItem().setEnabled(!testSuiteInfoNew0.isLocked());
                }
            }
            boolean bMenuValid = getJTree1().getSelectionCount() == 1;
            getRefreshTestSuiteJMenuItem().setEnabled(bMenuValid);
            boolean isLocked = false;
            if (getJTree1().getSelectionCount() == 1) {
                isLocked = ((TestSuiteInfoNew) getTreeSelection()).isLocked();
            }
            // Disable if TestSuite locked
            getDuplicateTSMenuItem().setEnabled(bMenuValid);
            getRunAllMenuItem().setEnabled(bMenuValid && !isLocked);
            getGenTSReportMenuItem().setEnabled(!checkAnyLocked());
            getAddTestCaseMenuItem().setEnabled(bMenuValid && !isLocked);
            getRemoveTSMenuItem().setEnabled(bMenuValid && !isLocked);
            getEditAnnotationTestSuiteMenuItem().setEnabled(bMenuValid && !isLocked);
            getLockTestSuiteMenuItem().setEnabled(bMenuValid && !isLocked);
            getRemoveCompiledSolversJMenuItem().setEnabled(bMenuValid && !isLocked);
            // Set enable based on conditions if not locked
            if (bMenuValid && !isLocked) {
                if (((TreeNode) getJTree1().getSelectionPath().getLastPathComponent()).getChildCount() == 0) {
                    getDuplicateTSMenuItem().setEnabled(false);
                    getRunAllMenuItem().setEnabled(false);
                    getGenTSReportMenuItem().setEnabled(false);
                } else {
                    getDuplicateTSMenuItem().setEnabled(true);
                    getRunAllMenuItem().setEnabled(true);
                    getGenTSReportMenuItem().setEnabled(true);
                }
            }
            getTestSuitePopupMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
        } else if (getTreeSelection() instanceof TestCaseNew) {
            boolean bMenuValid = getJTree1().getSelectionCount() == 1;
            getRefreshTestCaseJMenuItem().setEnabled(bMenuValid);
            getLoadMenuItem().setEnabled(bMenuValid);
            boolean isLocked = false;
            if (getJTree1().getSelectionCount() == 1) {
                isLocked = ((TestSuiteInfoNew) ((BioModelNode) ((TreeNode) getJTree1().getSelectionPath().getLastPathComponent()).getParent()).getUserObject()).isLocked();
            }
            getRemoveMenuItem().setEnabled(!checkAnyLocked());
            getRunSimsMenuItem().setEnabled(bMenuValid && !isLocked);
            getGenerateTCReportMenuItem().setEnabled(!checkAnyLocked());
            getChangeTypeToSteadyMenuItem().setEnabled(bMenuValid && !isLocked);
            getEditAnnotationTestCaseMenuItem().setEnabled(bMenuValid && !isLocked);
            if (bMenuValid && !isLocked) {
                TestCaseNew tcNew = (TestCaseNew) getTreeSelection();
                if (tcNew.getType().equals(TestCaseNew.EXACT) || tcNew.getType().equals(TestCaseNew.EXACT_STEADY)) {
                    getChangeTypeToSteadyMenuItem().setEnabled(true);
                } else {
                    getChangeTypeToSteadyMenuItem().setEnabled(false);
                }
            }
            getTestCasePopupMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
        } else if (getTreeSelection() instanceof TestCriteriaNew) {
            boolean bMenuValid = getJTree1().getSelectionCount() == 1;
            getRefreshTestCriteriaJMenuItem().setEnabled(bMenuValid);
            getViewMenuItem().setEnabled(bMenuValid);
            getCompareMenuItem().setEnabled(bMenuValid);
            getCompareUserDefinedMenuItem().setEnabled(bMenuValid);
            getQueryTCritCrossRefMenuItem1().setEnabled(bMenuValid);
            getTestCriteriaCopySimKeyMenuItem().setEnabled(bMenuValid);
            boolean isLocked = false;
            if (getJTree1().getSelectionCount() == 1) {
                isLocked = ((TestSuiteInfoNew) ((BioModelNode) ((TreeNode) getJTree1().getSelectionPath().getLastPathComponent()).getParent().getParent()).getUserObject()).isLocked();
            }
            getRunSimMenuItem().setEnabled(!checkAnyLocked());
            getEditTCrMenuItem().setEnabled(bMenuValid && !isLocked);
            getRemoveTestCritMenuItem().setEnabled(!checkAnyLocked());
            getGenerateTCRitReportMenuItem1().setEnabled(!checkAnyLocked());
            getGenerateTCRitReportUserDefinedReferenceMenuItem1().setEnabled(!checkAnyLocked());
            if (bMenuValid && !isLocked) {
                TestCriteriaNew testCriteria = (TestCriteriaNew) getTreeSelection();
                if (testCriteria.getRegressionSimInfo() == null) {
                    getCompareMenuItem().setEnabled(false);
                } else {
                    getCompareMenuItem().setEnabled(true);
                }
            }
            getSimulationPopupMenu().show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
        }
    } else {
        getMainPopupMenu().setVisible(false);
        getTestSuitePopupMenu().setVisible(false);
        getTestCasePopupMenu().setVisible(false);
        getTCritVarPopupMenu().setVisible(false);
        getSimulationPopupMenu().setVisible(false);
    }
}
Also used : TreeNode(javax.swing.tree.TreeNode) TestCriteriaNew(cbit.vcell.numericstest.TestCriteriaNew) BioModelNode(cbit.vcell.desktop.BioModelNode) TestCaseNew(cbit.vcell.numericstest.TestCaseNew) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew) JPopupMenu(javax.swing.JPopupMenu)

Example 95 with JPopupMenu

use of javax.swing.JPopupMenu in project vcell by virtualcell.

the class CSGObjectPropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    if (popupMenu == null) {
        popupMenu = new JPopupMenu();
    }
    if (popupMenu.isShowing()) {
        return;
    }
    selectClickPath(e);
    TreePath[] selectedPaths = csgObjectTree.getSelectionPaths();
    boolean bShowPopup = true;
    boolean bTransform = false;
    boolean bApplySetOperator = false;
    boolean bAddPrimitive = false;
    boolean bAddTransformation = false;
    boolean bAddOperator = false;
    boolean bEdit = false;
    boolean bDelete = true;
    if (selectedPaths == null) {
        return;
    }
    for (TreePath tp : selectedPaths) {
        Object obj = tp.getLastPathComponent();
        if (obj == null || !(obj instanceof BioModelNode)) {
            continue;
        }
        BioModelNode selectedNode = (BioModelNode) obj;
        Object userObject = selectedNode.getUserObject();
        if (userObject == csgObject) {
            bDelete = false;
            if (csgObject.getRoot() == null) {
                bAddPrimitive = true;
                bAddOperator = true;
                bAddTransformation = true;
            }
        } else if (userObject instanceof CSGPrimitive) {
            bApplySetOperator = true;
            bTransform = true;
            bAddPrimitive = false;
            bAddOperator = false;
            bAddTransformation = false;
        } else if (userObject instanceof CSGSetOperator) {
            bApplySetOperator = true;
            bTransform = true;
            bAddPrimitive = true;
            bAddOperator = true;
            bAddTransformation = true;
        } else if (userObject instanceof CSGTransformation) {
            bApplySetOperator = true;
            bTransform = true;
            bEdit = true;
            if (((CSGTransformation) userObject).getChild() == null) {
                bAddPrimitive = true;
                bAddOperator = true;
                bAddTransformation = true;
            }
        }
    }
    if (bShowPopup) {
        popupMenu.removeAll();
        if (bAddPrimitive || bAddTransformation || bAddOperator) {
            getAddPrimitiveMenu().setEnabled(bAddPrimitive);
            getAddTransformationMenu().setEnabled(bAddTransformation);
            getAddSetOperatorMenu().setEnabled(bAddOperator);
            popupMenu.add(getAddMenu());
        }
        if (popupMenu.getComponents().length > 0) {
            popupMenu.add(new JSeparator());
        }
        // everything can be renamed
        popupMenu.add(getRenameMenuItem());
        if (bEdit) {
            popupMenu.add(getEditMenuItem());
        }
        if (bDelete) {
            popupMenu.add(getDeleteMenuItem());
        }
        if (bTransform) {
            if (popupMenu.getComponents().length > 0) {
                popupMenu.add(new JSeparator());
            }
            popupMenu.add(getTransformMenu());
        }
        if (bApplySetOperator) {
            if (popupMenu.getComponents().length > 0 && !bTransform) {
                popupMenu.add(new JSeparator());
            }
            popupMenu.add(getApplySetOperatorMenu());
        }
        Point mousePoint = e.getPoint();
        popupMenu.show(csgObjectTree, mousePoint.x, mousePoint.y);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGObject(cbit.vcell.geometry.CSGObject) BioModelNode(cbit.vcell.desktop.BioModelNode) Point(java.awt.Point) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)203 JMenuItem (javax.swing.JMenuItem)105 ActionEvent (java.awt.event.ActionEvent)61 ActionListener (java.awt.event.ActionListener)46 JMenu (javax.swing.JMenu)28 Point (java.awt.Point)24 Component (java.awt.Component)20 JLabel (javax.swing.JLabel)20 JSeparator (javax.swing.JSeparator)19 JScrollPane (javax.swing.JScrollPane)18 MouseEvent (java.awt.event.MouseEvent)17 JButton (javax.swing.JButton)16 AbstractAction (javax.swing.AbstractAction)15 BorderLayout (java.awt.BorderLayout)13 JPanel (javax.swing.JPanel)13 JTable (javax.swing.JTable)13 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)12 MouseAdapter (java.awt.event.MouseAdapter)11 ArrayList (java.util.ArrayList)11 Icon (javax.swing.Icon)11