Example usage for javax.swing JMenuItem isSelected

List of usage examples for javax.swing JMenuItem isSelected

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Returns the state of the button.

Usage

From source file:org.omegat.gui.properties.SegmentPropertiesArea.java

private void populateLocalContextMenuOptions(JPopupMenu contextMenu, Point p) {
    final String key = viewImpl.getKeyAtPoint(p);
    if (key == null) {
        return;// w ww  .ja v  a2  s.  co  m
    }
    String displayKey = key;
    if (!Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)) {
        try {
            displayKey = OStrings
                    .getString(ISegmentPropertiesView.PROPERTY_TRANSLATION_KEY + key.toUpperCase());
        } catch (MissingResourceException ignore) {
            // If this is not a known key then we can't translate it,
            // so use the "raw" key instead.
        }
    }
    String label = StringUtil.format(OStrings.getString("SEGPROP_CONTEXTMENU_NOTIFY_ON_PROP"), displayKey);
    final JMenuItem notifyOnItem = new JCheckBoxMenuItem(label);
    notifyOnItem.setSelected(getKeysToNotify().contains(key));
    notifyOnItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setKeyToNotify(key, notifyOnItem.isSelected());
        }
    });
    contextMenu.add(notifyOnItem);
}

From source file:org.omegat.gui.properties.SegmentPropertiesArea.java

@Override
public void populatePaneMenu(JPopupMenu contextMenu) {
    JMenuItem tableModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_TABLE_MODE"));
    tableModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesTableView.class));
    tableModeItem.addActionListener(new ActionListener() {
        @Override// w ww . java 2s. c  o  m
        public void actionPerformed(ActionEvent e) {
            toggleMode(SegmentPropertiesTableView.class);
        }
    });
    JMenuItem listModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_LIST_MODE"));
    listModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesListView.class));
    listModeItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleMode(SegmentPropertiesListView.class);
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(tableModeItem);
    group.add(listModeItem);
    contextMenu.add(tableModeItem);
    contextMenu.add(listModeItem);
    contextMenu.addSeparator();
    final JMenuItem toggleKeyTranslationItem = new JCheckBoxMenuItem(
            OStrings.getString("SEGPROP_CONTEXTMENU_RAW_KEYS"));
    toggleKeyTranslationItem.setSelected(Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS));
    toggleKeyTranslationItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Preferences.setPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS,
                    toggleKeyTranslationItem.isSelected());
            viewImpl.update();
        }
    });
    contextMenu.add(toggleKeyTranslationItem);
}

From source file:processing.app.Base.java

private void filterVisibilityOfSubsequentBoardMenus(List<JMenu> boardsCustomMenus, TargetBoard board,
        int fromIndex) {
    for (int i = fromIndex; i < boardsCustomMenus.size(); i++) {
        JMenu menu = boardsCustomMenus.get(i);
        for (int m = 0; m < menu.getItemCount(); m++) {
            JMenuItem menuItem = menu.getItem(m);
            menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
        }//from   www. j av  a 2 s .  co  m
        menu.setVisible(ifThereAreVisibleItemsOn(menu));

        if (menu.isVisible()) {
            JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem(menu);
            if (!visibleSelectedOrFirstMenuItem.isSelected()) {
                visibleSelectedOrFirstMenuItem.setSelected(true);
                visibleSelectedOrFirstMenuItem.getAction().actionPerformed(null);
            }
        }
    }
}

From source file:processing.app.Base.java

private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
    JMenuItem firstVisible = null;
    for (int i = 0; i < menu.getItemCount(); i++) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isVisible()) {
            if (item.isSelected()) {
                return item;
            }//from   w  w  w.j  a va  2  s . c  o  m
            if (firstVisible == null) {
                firstVisible = item;
            }
        }
    }

    if (firstVisible != null) {
        return firstVisible;
    }

    throw new IllegalStateException("Menu has no enabled items");
}

From source file:processing.app.Editor.java

protected JMenu buildToolsMenu() throws Exception {
    toolsMenu = new JMenu(_("Tools"));

    addInternalTools(toolsMenu);/* w  ww  . j a  v a 2  s .  c o  m*/

    JMenuItem item = newJMenuItemShift(_("Serial Monitor"), 'M');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleSerial();
        }
    });
    toolsMenu.add(item);

    addTools(toolsMenu, BaseNoGui.getToolsFolder());
    File sketchbookTools = new File(BaseNoGui.getSketchbookFolder(), "tools");
    addTools(toolsMenu, sketchbookTools);

    toolsMenu.addSeparator();

    numTools = toolsMenu.getItemCount();

    // XXX: DAM: these should probably be implemented using the Tools plugin
    // API, if possible (i.e. if it supports custom actions, etc.)

    for (JMenu menu : base.getBoardsCustomMenus()) {
        toolsMenu.add(menu);
    }

    if (serialMenu == null)
        serialMenu = new JMenu(_("Port"));
    populatePortMenu();
    toolsMenu.add(serialMenu);
    toolsMenu.addSeparator();

    JMenu programmerMenu = new JMenu(_("Programmer"));
    base.rebuildProgrammerMenu(programmerMenu);
    toolsMenu.add(programmerMenu);

    item = new JMenuItem(_("Burn Bootloader"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleBurnBootloader();
        }
    });
    toolsMenu.add(item);

    toolsMenu.addMenuListener(new StubMenuListener() {
        public void menuSelected(MenuEvent e) {
            //System.out.println("Tools menu selected.");
            populatePortMenu();
            for (Component c : toolsMenu.getMenuComponents()) {
                if ((c instanceof JMenu) && c.isVisible()) {
                    JMenu menu = (JMenu) c;
                    String name = menu.getText();
                    if (name == null)
                        continue;
                    String basename = name;
                    int index = name.indexOf(':');
                    if (index > 0)
                        basename = name.substring(0, index);
                    String sel = null;
                    int count = menu.getItemCount();
                    for (int i = 0; i < count; i++) {
                        JMenuItem item = menu.getItem(i);
                        if (item != null && item.isSelected()) {
                            sel = item.getText();
                            if (sel != null)
                                break;
                        }
                    }
                    if (sel == null) {
                        if (!name.equals(basename))
                            menu.setText(basename);
                    } else {
                        if (sel.length() > 50)
                            sel = sel.substring(0, 50) + "...";
                        String newname = basename + ": \"" + sel + "\"";
                        if (!name.equals(newname))
                            menu.setText(newname);
                    }
                }
            }
        }
    });

    return toolsMenu;
}

From source file:psidev.psi.mi.tab.client.gui.DragAndDropConverter.java

public static void addFileMenu(final JFrame frame, JMenuBar menuBar) {

    // Create a menu
    JMenu menu = new JMenu("File");
    menuBar.add(menu);/*from   w  w  w  .j av a 2  s . co  m*/

    // Create a file open iten
    JMenuItem openFileItem = new JMenuItem("Open files...");
    openFileItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            JFileChooser chooser = new JFileChooser();

            chooser.setApproveButtonText("Convert to MITAB25");

            // Enable multiple selections
            chooser.setMultiSelectionEnabled(true);

            // Show the dialog; wait until dialog is closed
            chooser.showOpenDialog(frame);

            // Retrieve the selected files. This method returns empty
            // if multiple-selection mode is not enabled.
            File[] files = chooser.getSelectedFiles();

            if (files != null && files.length > 0) {
                FilesProcessor processor = new FilesProcessor();
                processor.process(frame, files, expansionStrategy, postProcessorStrategy,
                        aggregateSelectedFiles);
            }
        }
    });
    menu.add(openFileItem);

    // Create an exit
    final JMenuItem mergeItem = new JCheckBoxMenuItem("Aggregate all selected files", aggregateSelectedFiles);
    mergeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // If selected, all files dropped or selected at once are aggregated into a single MITAB file
            aggregateSelectedFiles = mergeItem.isSelected();
            log.debug("Aggregate is " + aggregateSelectedFiles);
        }
    });
    menu.add(mergeItem);

    // Create an exit
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(exitItem);
}

From source file:savant.view.swing.FrameCommandBar.java

/**
 * Create Tools menu for commandBar.  This is common to all track types.
 */// w w w.j a va2 s  .  co m
private JMenu createToolsMenu() {
    JMenu menu = new JMenu("Tools");
    JMenuItem item = new JCheckBoxMenuItem("Lock X Axis");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            graphPane.setLocked(!graphPane.isLocked());
        }
    });
    menu.add(item);

    // TODO: experimental feature which doesn't quite work yet
    final JMenuItem itemy = new JCheckBoxMenuItem("Lock Y Axis");
    itemy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Trying to locking Y max: " + !itemy.isSelected());
            graphPane.setYMaxLocked(itemy.isSelected());
        }
    });
    //menu.add(itemy);

    item = new JMenuItem("Copy URL to Clipboard");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Toolkit.getDefaultToolkit().getSystemClipboard()
                    .setContents(new StringSelection(mainTrack.getDataSource().getURI().toString()), null);
        }
    });
    menu.add(item);

    DataFormat df = mainTrack.getDataFormat();
    if (df == DataFormat.SEQUENCE) {
        menu.add(new JSeparator());
        JMenuItem copyItem = new JMenuItem("Copy Sequence to Clipboard");
        copyItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    LocationController lc = LocationController.getInstance();
                    byte[] seq = ((SequenceTrack) mainTrack).getSequence(lc.getReferenceName(), lc.getRange());
                    Toolkit.getDefaultToolkit().getSystemClipboard()
                            .setContents(new StringSelection(new String(seq)), null);
                } catch (Throwable x) {
                    LOG.error(x);
                    DialogUtils.displayError("Unable to copy sequence to clipboard.");
                }
            }
        });
        menu.add(copyItem);

        setAsGenomeButton = new JCheckBoxMenuItem("Set as Genome");
        setAsGenomeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Genome newGenome = Genome.createFromTrack(mainTrack);
                GenomeController.getInstance().setGenome(newGenome);
            }
        });
        menu.add(setAsGenomeButton);
        menu.addMenuListener(new MenuAdapter() {
            @Override
            public void menuSelected(MenuEvent me) {
                Track seqTrack = (Track) GenomeController.getInstance().getGenome().getSequenceTrack();
                if (seqTrack == mainTrack) {
                    setAsGenomeButton.setSelected(true);
                    setAsGenomeButton.setEnabled(false);
                    setAsGenomeButton.setToolTipText("This track is already the reference sequence");
                } else {
                    setAsGenomeButton.setSelected(false);
                    setAsGenomeButton.setEnabled(true);
                    setAsGenomeButton.setToolTipText("Use this track as the reference sequence");
                }
            }
        });
    } else if (df == DataFormat.ALIGNMENT) {
        menu.add(new JSeparator());

        item = new JMenuItem("Filter...");
        item.setToolTipText("Control how records are filtered");

        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new BAMFilterDialog(DialogUtils.getMainWindow(), (BAMTrack) mainTrack).setVisible(true);
            }
        });
        menu.add(item);
    } else if (df == DataFormat.RICH_INTERVAL) {
        menu.add(new JSeparator());

        final JMenuItem bookmarkAll = new JMenuItem("Bookmark All Features");
        bookmarkAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DataSource ds = (DataSource) mainTrack.getDataSource();
                if (DialogUtils.askYesNo("Bookmark All Features ",
                        String.format("This will create %d bookmarks.  Are you sure you want to do this?",
                                ds.getDictionaryCount())) == DialogUtils.YES) {
                    ds.addDictionaryToBookmarks();
                    Savant.getInstance().displayBookmarksPanel();
                }
            }
        });
        menu.add(bookmarkAll);

        menu.addMenuListener(new MenuAdapter() {
            @Override
            public void menuSelected(MenuEvent me) {
                bookmarkAll.setEnabled(mainTrack.getDataSource() instanceof DataSource
                        && ((DataSource) mainTrack.getDataSource()).getDictionaryCount() > 0);
            }
        });
    }
    return menu;
}