Example usage for javax.swing JMenuItem setEnabled

List of usage examples for javax.swing JMenuItem setEnabled

Introduction

In this page you can find the example usage for javax.swing JMenuItem setEnabled.

Prototype

@BeanProperty(preferred = true, description = "The enabled state of the component.")
public void setEnabled(boolean b) 

Source Link

Document

Enables or disables the menu item.

Usage

From source file:org.openmicroscopy.shoola.agents.fsimporter.util.FileImportComponent.java

/**
 * Creates or recycles the menu corresponding to the import status.
 * //from   w w w  .j  av  a2 s .  c  om
 * @return See above.
 */
private JPopupMenu createActionMenu() {
    if (menu != null)
        return menu;
    menu = new JPopupMenu();
    JMenuItem item;
    String logText = "View Import Log";
    String checksumText = "View Checksum";
    String exceptionText = "View Exception";
    Object result = statusLabel.getImportResult();
    switch (resultIndex) {
    case FAILURE_LIBRARY:
        menu.add(new JMenuItem(new AbstractAction(exceptionText) {
            public void actionPerformed(ActionEvent e) {
                viewError();
            }
        }));
        break;
    case FAILURE:
        menu.add(new JMenuItem(new AbstractAction("Submit") {
            public void actionPerformed(ActionEvent e) {
                submitError();
            }
        }));
        menu.add(new JMenuItem(new AbstractAction(exceptionText) {
            public void actionPerformed(ActionEvent e) {
                viewError();
            }
        }));
        break;
    case UPLOAD_FAILURE:
        menu.add(new JMenuItem(new AbstractAction("Retry") {
            public void actionPerformed(ActionEvent e) {
                retry();
            }
        }));
        break;
    case SUCCESS:
        logText = "Import Log";
        checksumText = "Checksum";
        item = new JMenuItem(new AbstractAction("In Full Viewer") {
            public void actionPerformed(ActionEvent e) {
                launchFullViewer();
            }
        });
        boolean b = false;
        if (result instanceof Collection)
            b = ((Collection) result).size() == 1;
        item.setEnabled(b && !statusLabel.isHCS());
        menu.add(item);
        item = new JMenuItem(new AbstractAction("In Data Browser") {
            public void actionPerformed(ActionEvent e) {
                browse();
            }
        });
        item.setEnabled(browsable);
        menu.add(item);
    }
    item = new JMenuItem(new AbstractAction(logText) {
        public void actionPerformed(ActionEvent e) {
            displayLogFile();
        }
    });
    item.setEnabled(statusLabel.getLogFileID() > 0 || statusLabel.getFileset() != null);
    menu.add(item);

    item = new JMenuItem(new AbstractAction(checksumText) {
        public void actionPerformed(ActionEvent e) {
            showChecksumDetails();
        }
    });
    item.setEnabled(statusLabel.hasChecksum());
    menu.add(item);
    return menu;
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Helper method to create the show View menu. 
 * //from  ww  w  . j a  v  a  2  s . co m
 * @return See above.
 */
private JMenu createShowViewMenu() {
    JMenu menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_S);
    JMenuItem item = new JMenuItem(controller.getAction(ImViewerControl.TAB_GRID));
    if (model.isBigImage() || (model.isLifetimeImage() && model.getModuloT() == null))
        item.setEnabled(false);
    else
        item.setEnabled(model.getMaxC() > 1);
    menu.add(item);
    item = new JMenuItem(controller.getAction(ImViewerControl.TAB_PROJECTION));
    item.setEnabled(model.getMaxZ() > 1 && !model.isBigImage());
    menu.add(item);
    return menu;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** Creates or recycles the save as menu. */
private JPopupMenu createSaveAsMenu() {
    saveAsMenu = new JPopupMenu();
    IconManager icons = IconManager.getInstance();
    downloadItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD));
    downloadItem.setToolTipText("Download the Archived File(s).");
    downloadItem.setText("Download...");
    downloadItem.addActionListener(controller);
    downloadItem.setActionCommand("" + EditorControl.DOWNLOAD);
    downloadItem.setBackground(UIUtilities.BACKGROUND_COLOR);
    List<DataObject> nodes = model.getSelectedObjects();
    boolean b = false;
    if (!CollectionUtils.isEmpty(nodes)) {
        Iterator<DataObject> i = nodes.iterator();
        while (i.hasNext()) {
            if (model.isArchived(i.next())) {
                b = true;//  w  ww  .j  a va2 s  .  c  om
                break;
            }
        }
    }
    downloadItem.setEnabled(b);
    saveAsMenu.add(downloadItem);

    downloadOriginalMetadataItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD));
    downloadOriginalMetadataItem.setToolTipText("Download the " + "metadata read from the image files.");
    downloadOriginalMetadataItem.setText("Download Original metadata...");
    downloadOriginalMetadataItem.addActionListener(controller);
    downloadOriginalMetadataItem.setActionCommand("" + EditorControl.DOWNLOAD_METADATA);
    downloadOriginalMetadataItem.setBackground(UIUtilities.BACKGROUND_COLOR);
    downloadOriginalMetadataItem.setEnabled(model.hasOriginalMetadata());
    saveAsMenu.add(downloadOriginalMetadataItem);

    exportAsOmeTiffItem = new JMenuItem(icons.getIcon(IconManager.EXPORT_AS_OMETIFF));
    exportAsOmeTiffItem.setText("Export as OME-TIFF...");
    exportAsOmeTiffItem.setToolTipText(EXPORT_AS_OME_TIFF_TOOLTIP);
    exportAsOmeTiffItem.addActionListener(controller);
    exportAsOmeTiffItem.setActionCommand("" + EditorControl.EXPORT_AS_OMETIFF);
    if (model.isMultiSelection())
        b = false;
    else {
        b = model.getRefObject() instanceof ImageData && !model.isLargeImage();
    }
    exportAsOmeTiffItem.setEnabled(b);
    saveAsMenu.add(exportAsOmeTiffItem);
    JMenu menu = new JMenu();
    menu.setIcon(icons.getIcon(IconManager.SAVE_AS));
    menu.setText("Save as...");
    menu.setToolTipText("Save the images at full size as JPEG. PNG or" + "TIFF.");
    ActionListener l = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int index = Integer.parseInt(e.getActionCommand());
            controller.saveAs(index);
        }
    };
    Map<Integer, String> formats = FigureParam.FORMATS;
    Entry<Integer, String> e;
    Iterator<Entry<Integer, String>> i = formats.entrySet().iterator();
    JMenuItem item;
    Object ho = model.getRefObject();
    boolean enabled = (ho instanceof ImageData || ho instanceof WellSampleData || ho instanceof DatasetData);
    while (i.hasNext()) {
        e = i.next();
        item = new JMenuItem();
        item.setText(e.getValue());
        item.addActionListener(l);
        item.setActionCommand("" + e.getKey());
        item.setEnabled(enabled);
        menu.add(item);
    }
    saveAsMenu.add(menu);
    setRootObject();
    return saveAsMenu;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Creates the items for the menu.//from ww  w  .  j a  v  a 2 s. co  m
 * 
 * @param add Pass <code>true</code> to build items for the <code>Add</code>
 * menu, <code>false</code> otherwise.
 * @return See above
 */
private List<JMenuItem> createMenuItem(boolean add) {
    List<JMenuItem> items = new ArrayList<JMenuItem>();
    List<GroupSelectionAction> l = controller.getUserGroupAction(add);
    Iterator<GroupSelectionAction> i = l.iterator();
    GroupSelectionAction a;
    JMenuItem item;
    if (add) {
        //Check the groups that already in the view.
        Browser browser = model.getSelectedBrowser();
        List<Long> ids = new ArrayList<Long>();
        if (browser != null) {
            ExperimenterVisitor v = new ExperimenterVisitor(browser, -1);
            browser.accept(v, ExperimenterVisitor.TREEIMAGE_SET_ONLY);
            List<TreeImageDisplay> nodes = v.getNodes();
            Iterator<TreeImageDisplay> j = nodes.iterator();
            TreeImageDisplay node;
            while (j.hasNext()) {
                node = j.next();
                ids.add(((GroupData) node.getUserObject()).getId());
            }
        }

        while (i.hasNext()) {
            a = i.next();
            item = new JMenuItem(a);
            if (ids.size() > 0) {
                item.setEnabled(!ids.contains(a.getGroupId()));
            } else
                item.setEnabled(true);
            initMenuItem(item);
            items.add(item);
        }
    } else {
        ButtonGroup buttonGroup = new ButtonGroup();
        long id = model.getSelectedGroupId();
        while (i.hasNext()) {
            a = i.next();
            item = new JCheckBoxMenuItem(a);
            item.setEnabled(true);
            item.setSelected(a.isSameGroup(id));
            initMenuItem(item);
            buttonGroup.add(item);
            items.add(item);
        }
    }

    return items;
}

From source file:org.openscience.jmol.app.Jmol.java

/**
 * This is the hook through which all menu items are
 * created.  It registers the result with the menuitem
 * hashtable so that it can be fetched with getMenuItem().
 * @param cmd/*from  w ww  .  j a  v  a 2s  .c  o  m*/
 * @return Menu item created
 * @see #getMenuItem
 */
protected JMenuItem createMenuItem(String cmd) {

    JMenuItem mi;
    if (cmd.endsWith("Check")) {
        mi = guimap.newJCheckBoxMenuItem(cmd, false);
    } else {
        mi = guimap.newJMenuItem(cmd);
    }

    ImageIcon f = JmolResourceHandler.getIconX(cmd + "Image");
    if (f != null) {
        mi.setHorizontalTextPosition(SwingConstants.RIGHT);
        mi.setIcon(f);
    }

    if (cmd.endsWith("Script")) {
        mi.setActionCommand(JmolResourceHandler.getStringX(cmd));
        mi.addActionListener(executeScriptAction);
    } else {
        mi.setActionCommand(cmd);
        Action a = getAction(cmd);
        if (a != null) {
            mi.addActionListener(a);
            a.addPropertyChangeListener(new ActionChangedListener(mi));
            mi.setEnabled(a.isEnabled());
        } else {
            mi.setEnabled(false);
        }
    }
    menuItems.put(cmd, mi);
    return mi;
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void addColumn() {
    if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) {
        return;//from   ww w  .  j a v  a2s .com
    }

    if (columnGroupCount != 0) {
        panelBox.add(Box.createHorizontalStrut(7));
    }

    final int tableIndex = columnGroupCount;

    final DataTableModel tableModel = new DataTableModel();
    final JTable table = new JTable(tableModel);

    table.setDragEnabled(true);
    table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount));

    if (showThresholdCheckBoxGroup.isSelected()) {
        tableModel.setThresholdVisible(true);
    }

    if (showMinMaxCheckBoxGroup.isSelected()) {
        tableModel.setMaxMinVisible(true);

        table.getColumn("Min").setCellRenderer(doubleCellRenderer);
        table.getColumn("Max").setCellRenderer(doubleCellRenderer);
    }

    table.getColumn("Value").setCellRenderer(dataCellRenderer);

    tables.add(table);
    tableModels.add(tableModel);

    JScrollPane tableScrollPane = new JScrollPane(table);
    panelBox.add(tableScrollPane);

    // popup menu for panel
    JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TransferHandler.getCopyAction().actionPerformed(
                    new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
        }
    });
    popupMenu.add(copyMenuItem);

    popupMenu.addSeparator();

    JMenuItem printMenuItem = new JMenuItem("Print...");
    printMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.FIT_WIDTH);
            } catch (PrinterException pe) {
            }
        }
    });
    popupMenu.add(printMenuItem);
    popupMenu.addSeparator();

    final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false);
    showMaxMinMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMaxMinVisible(showMaxMinMenuItem.isSelected());
        }
    });
    showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem);
    popupMenu.add(showMaxMinMenuItem);

    final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false);
    showThresholdMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setThresholdVisible(showThresholdMenuItem.isSelected());
        }
    });
    showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem);
    popupMenu.add(showThresholdMenuItem);

    popupMenu.addSeparator();

    JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row");
    blankRowMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tableModel.addBlankRow();
        }
    });
    popupMenu.add(blankRowMenuItem);

    final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows");
    removeSelectedRowsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeSelectedRows(tableIndex);
        }
    });
    popupMenu.add(removeSelectedRowsMenuItem);

    popupMenu.addSeparator();

    JMenu numberOfColumnsMenu = new JMenu("Number of columns");
    numberOfColumnsMenu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent me) {
            JMenu menu = (JMenu) me.getSource();
            for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) {
                JMenuItem menuItem = menu.getItem(j);
                boolean selected = (j == (columnGroupCount - 1));
                menuItem.setSelected(selected);
            }
        }

        public void menuDeselected(MenuEvent me) {
        }

        public void menuCanceled(MenuEvent me) {
        }
    });

    for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) {
        final int number = i + 1;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setNumberOfColumns(number);
            }
        });
        numberOfColumnsMenu.add(item);
    }
    popupMenu.add(numberOfColumnsMenu);

    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean anyRowsSelected = table.getSelectedRowCount() > 0;
            copyMenuItem.setEnabled(anyRowsSelected);
            removeSelectedRowsMenuItem.setEnabled(anyRowsSelected);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    table.setComponentPopupMenu(popupMenu);
    tableScrollPane.setComponentPopupMenu(popupMenu);

    panelBox.revalidate();

    columnGroupCount++;

    properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount));
}

From source file:org.rdv.viz.image.HighResImageViz.java

public void buildPopupMenu(JPopupMenu menu, MouseEvent e) {
    super.buildPopupMenu(menu, e);

    ActionListener setTimerangeAction = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            double newScale = Double.parseDouble(ae.getActionCommand());
            setLocalTimescale(newScale);
        }/*from  w  w  w  .  jav a2  s.c  om*/
    };

    // regenerate new menu
    JMenu timeRangeMenu = new JMenu("Set Timerange");
    ButtonGroup timeRangeGroup = new ButtonGroup();
    JRadioButtonMenuItem range = new JRadioButtonMenuItem(TimeScale.TIME_SCALE_UNDEFINED_DESC);
    range.setActionCommand(String.valueOf(TimeScale.TIME_SCALE_UNDEFINED));
    range.addActionListener(setTimerangeAction);
    timeRangeGroup.add(range);
    timeRangeMenu.add(range);
    if (localTimeScale_ == TimeScale.TIME_SCALE_UNDEFINED)
        range.setSelected(true);

    Double timeScales[] = TimeScale.getGlobalTimeScales();
    for (int i = 0; i < timeScales.length; i++) {
        range = new JRadioButtonMenuItem(DataViewer.formatSeconds(timeScales[i]));
        range.setActionCommand(String.valueOf(timeScales[i]));
        range.addActionListener(setTimerangeAction);
        timeRangeGroup.add(range);
        timeRangeMenu.add(range);
        if (localTimeScale_ == timeScales[i])
            range.setSelected(true);
    }

    menu.add(timeRangeMenu);
    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();
        }
    });
    menu.add(copyImageMenuItem);
    menu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    menu.add(saveImageMenuItem);

    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    menu.add(printImageMenuItem);

    menu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    menu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    menu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    menu.add(zoomMenuSeparator);

    final JCheckBoxMenuItem autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", imagePanel.isAutoScaling());
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    menu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    menu.add(resetScaleMenuItem);

    final JCheckBoxMenuItem showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    menu.add(showNavigationImageMenuItem);

    //menu.addSeparator();

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    menu.add(useThumbnailImageMenuItem);

    boolean hasImage = displayedImageData != null;
    saveImageMenuItem.setEnabled(hasImage);
    copyImageMenuItem.setEnabled(hasImage);
    printImageMenuItem.setEnabled(hasImage);

    boolean enableZoom = hasImage;
    zoomInMenuItem.setEnabled(enableZoom);
    zoomInMenuItem.setVisible(true);
    zoomOutMenuItem.setEnabled(enableZoom);
    zoomOutMenuItem.setVisible(true);
    zoomMenuSeparator.setVisible(true);

    autoScaleMenuItem.setVisible(true);
    resetScaleMenuItem.setVisible(true);
    showNavigationImageMenuItem.setVisible(true);

    useThumbnailImageMenuItem.setSelected(useThumbnailImage);
    useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

}

From source file:org.rdv.viz.image.ImageViz.java

private void initPopupMenu() {
    final JPopupMenu popupMenu = new JPopupMenu();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();//w w w . ja  v a 2s.  c  o m
        }
    });
    popupMenu.add(copyImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    popupMenu.add(saveImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    popupMenu.add(printImageMenuItem);

    popupMenu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    popupMenu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    popupMenu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    popupMenu.add(zoomMenuSeparator);

    autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true);
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    popupMenu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    popupMenu.add(resetScaleMenuItem);

    showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    popupMenu.add(showNavigationImageMenuItem);

    final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images");
    maximumFilmstripImagesButtonGroup = new ButtonGroup();
    for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) {
        boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue;
        JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem(
                Integer.toString(maximumFilmstripImagesValue), selected);
        maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                filmstripPanel.setMaximumImages(maximumFilmstripImagesValue);
            }
        });
        maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem);
        maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem);
    }
    popupMenu.add(maximumFilmstripImagesMenu);

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode);
    showAsFilmstripMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            boolean filmstripMode = showAsFilmstripMenuItem.isSelected();
            setFilmstripMode(filmstripMode);
        }
    });
    popupMenu.add(showAsFilmstripMenuItem);

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    popupMenu.add(useThumbnailImageMenuItem);

    hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false);
    hideRoboticControlsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setRoboticControls();
        }
    });
    popupMenu.add(hideRoboticControlsMenuItem);

    // enable the save image popup if an image is being displayed
    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean hasImage = displayedImageData != null;
            saveImageMenuItem.setEnabled(hasImage);
            copyImageMenuItem.setEnabled(hasImage);
            printImageMenuItem.setEnabled(hasImage);

            boolean enableZoom = hasImage && !filmstripMode;
            zoomInMenuItem.setEnabled(enableZoom);
            zoomInMenuItem.setVisible(!filmstripMode);
            zoomOutMenuItem.setEnabled(enableZoom);
            zoomOutMenuItem.setVisible(!filmstripMode);
            zoomMenuSeparator.setVisible(!filmstripMode);

            autoScaleMenuItem.setVisible(!filmstripMode);
            resetScaleMenuItem.setVisible(!filmstripMode);
            showNavigationImageMenuItem.setVisible(!filmstripMode);
            maximumFilmstripImagesMenu.setVisible(filmstripMode);

            showAsFilmstripMenuItem.setSelected(filmstripMode);

            useThumbnailImageMenuItem.setSelected(useThumbnailImage);
            useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

            hideRoboticControlsMenuItem.setVisible(flexTPSStream != null);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    panel.setComponentPopupMenu(popupMenu);
    imagePanel.setComponentPopupMenu(popupMenu);
    filmstripPanel.setComponentPopupMenu(popupMenu);
    panel.addMouseListener(new MouseInputAdapter() {
    });
}

From source file:org.sikuli.ide.SikuliIDE.java

private void initRunMenu() throws NoSuchMethodException {
    JMenuItem item;
    int scMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    _runMenu.setMnemonic(java.awt.event.KeyEvent.VK_R);
    item = _runMenu.add(createMenuItem(_I("menuRunRun"),
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, scMask), new RunAction(RunAction.RUN)));
    item.setName("RUN");
    item = _runMenu.add(createMenuItem(_I("menuRunRunAndShowActions"),
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, InputEvent.ALT_MASK | scMask),
            new RunAction(RunAction.RUN_SHOW_ACTIONS)));
    item.setName("RUN_SLOWLY");

    PreferencesUser pref = PreferencesUser.getInstance();
    item = createMenuItem(_I("menuRunStop"),
            KeyStroke.getKeyStroke(pref.getStopHotkey(), pref.getStopHotkeyModifiers()),
            new RunAction(RunAction.RUN_SHOW_ACTIONS));
    item.setEnabled(false);
    _runMenu.add(item);/*from w w  w . jav  a 2  s .co  m*/
}

From source file:processing.app.Base.java

public void rebuildImportMenu(JMenu importMenu) {
    if (importMenu == null)
        return;//  w  ww .  j ava 2  s.co  m
    importMenu.removeAll();

    JMenuItem menu = new JMenuItem(tr("Manage Libraries..."));
    // Ctrl+Shift+I on Windows and Linux, Command+Shift+I on macOS
    menu.setAccelerator(KeyStroke.getKeyStroke('I',
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | ActionEvent.SHIFT_MASK));
    menu.addActionListener(e -> openLibraryManager("", ""));
    importMenu.add(menu);
    importMenu.addSeparator();

    JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library..."));
    addLibraryMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.this.handleAddLibrary();
            BaseNoGui.librariesIndexer.rescanLibraries();
            Base.this.onBoardOrPortChange();
            Base.this.rebuildImportMenu(Editor.importMenu);
            Base.this.rebuildExamplesMenu(Editor.examplesMenu);
        }
    });
    importMenu.add(addLibraryMenuItem);
    importMenu.addSeparator();

    // Split between user supplied libraries and IDE libraries
    TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();

    if (targetPlatform != null) {
        LibraryList libs = getSortedLibraries();
        String lastLibType = null;
        for (UserLibrary lib : libs) {
            String libType = lib.getTypes().get(0);
            if (!libType.equals(lastLibType)) {
                if (lastLibType != null) {
                    importMenu.addSeparator();
                }
                lastLibType = libType;
                JMenuItem platformItem = new JMenuItem(I18n.format(tr("{0} libraries"), tr(lastLibType)));
                platformItem.setEnabled(false);
                importMenu.add(platformItem);
            }

            AbstractAction action = new AbstractAction(lib.getName()) {
                public void actionPerformed(ActionEvent event) {
                    UserLibrary l = (UserLibrary) getValue("library");
                    try {
                        activeEditor.getSketchController().importLibrary(l);
                    } catch (IOException e) {
                        showWarning(tr("Error"),
                                I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e);
                    }
                }
            };
            action.putValue("library", lib);

            // Add new element at the bottom
            JMenuItem item = new JMenuItem(action);
            item.putClientProperty("library", lib);
            importMenu.add(item);
        }
    }
}