Example usage for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem

List of usage examples for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem

Introduction

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

Prototype

public JCheckBoxMenuItem(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the Action supplied.

Usage

From source file:org.kepler.gui.MenuMapper.java

public static JMenuItem addMenuFor(String key, Action action, JComponent topLvlContainer,
        Map<String, JMenuItem> keplerMenuMap) {

    if (topLvlContainer == null) {
        if (isDebugging) {
            log.debug("NULL container received (eg JMenuBar) - returning NULL");
        }//  w ww  .j ava 2s  .c om
        return null;
    }
    if (key == null) {
        if (isDebugging) {
            log.debug("NULL key received");
        }
        return null;
    }
    key = key.trim();

    if (key.length() < 1) {
        if (isDebugging) {
            log.debug("BLANK key received");
        }
        return null;
    }
    if (action == null && key.indexOf(MENU_SEPARATOR_KEY) < 0) {
        if (isDebugging) {
            log.debug("NULL action received, but was not a separator: " + key);
        }
        return null;
    }

    if (keplerMenuMap.containsKey(key)) {
        if (isDebugging) {
            log.debug("Menu already added; skipping: " + key);
        }
        return null;
    }

    // split delimited parts and ensure menus all exist
    String[] menuLevel = key.split(MENU_PATH_DELIMITER);

    int totLevels = menuLevel.length;

    // create a menu for each "menuLevel" if it doesn't already exist
    final StringBuffer nextLevelBuff = new StringBuffer();
    String prevLevelStr = null;
    JMenuItem leafMenuItem = null;

    for (int levelIdx = 0; levelIdx < totLevels; levelIdx++) {

        // save previous value
        prevLevelStr = nextLevelBuff.toString();

        String nextLevelStr = menuLevel[levelIdx];
        // get the index of the first MNEMONIC_SYMBOL
        int mnemonicIdx = nextLevelStr.indexOf(MNEMONIC_SYMBOL);
        char mnemonicChar = 0;

        // if an MNEMONIC_SYMBOL exists, remove all underscores. Then, idx
        // of
        // first underscore becomes idx of letter it used to precede - this
        // is the mnemonic letter
        if (mnemonicIdx > -1) {
            nextLevelStr = nextLevelStr.replaceAll(MNEMONIC_SYMBOL, "");
            mnemonicChar = nextLevelStr.charAt(mnemonicIdx);
        }
        if (levelIdx != 0) {
            nextLevelBuff.append(MENU_PATH_DELIMITER);
        }
        nextLevelBuff.append(nextLevelStr);

        // don't add multiple separators together...
        if (nextLevelStr.indexOf(MENU_SEPARATOR_KEY) > -1) {
            if (separatorJustAdded == false) {

                // Check if we're at the top level, since this makes sense
                // only for
                // context menu - we can't add a separator to a JMenuBar
                if (levelIdx == 0) {
                    if (topLvlContainer instanceof JContextMenu) {
                        ((JContextMenu) topLvlContainer).addSeparator();
                    }
                } else {
                    JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);

                    if (parent != null) {
                        if (parent.getMenuComponentCount() < 1) {
                            if (isDebugging) {
                                log.debug("------ NOT adding separator to parent " + parent.getText()
                                        + ", since it does not contain any menu items");
                            }
                        } else {
                            if (isDebugging) {
                                log.debug("------ adding separator to parent " + parent.getText());
                            }
                            // add separator to parent
                            parent.addSeparator();
                            separatorJustAdded = true;
                        }
                    }
                }
            }
        } else if (!keplerMenuMap.containsKey(nextLevelBuff.toString())) {
            // If menu has not already been created, we need
            // to create it and then add it to the parent level...

            JMenuItem menuItem = null;

            // if we're at a "leaf node" - need to create a JMenuItem
            if (levelIdx == totLevels - 1) {

                // save old display name to use as actionCommand on
                // menuitem,
                // since some parts of PTII still
                // use "if (actionCommand.equals("SaveAs")) {..." etc
                String oldDisplayName = (String) action.getValue(Action.NAME);

                // action.putValue(Action.NAME, nextLevelStr);

                if (mnemonicChar > 0) {
                    action.putValue(GUIUtilities.MNEMONIC_KEY, new Integer(mnemonicChar));
                }

                // Now we look to see if it's a checkbox
                // menu item, or just a regular one
                String menuItemType = (String) (action.getValue(MENUITEM_TYPE));

                if (menuItemType != null && menuItemType == CHECKBOX_MENUITEM_TYPE) {
                    menuItem = new JCheckBoxMenuItem(action);
                } else {
                    menuItem = new JMenuItem(action);
                }

                // --------------------------------------------------------------
                /** @todo - setting menu names - TEMPORARY FIX - FIXME */
                // Currently, if we use the "proper" way of setting menu
                // names -
                // ie by using action.putValue(Action.NAME, "somename");,
                // then
                // the name appears on the port buttons on the toolbar,
                // making
                // them huge. As a temporary stop-gap, I am just setting the
                // new
                // display name using setText() instead of
                // action.putValue(..,
                // but this needs to be fixed elsewhere - we want to be able
                // to
                // use action.putValue(Action.NAME (ie uncomment the line
                // above
                // that reads:
                // action.putValue(Action.NAME, nextLevelStr);
                // and delete the line below that reads:
                // menuItem.setText(nextLevelStr);
                // otherwise this may bite us in future...
                menuItem.setText(nextLevelStr);
                // --------------------------------------------------------------

                // set old display name as actionCommand on
                // menuitem, for ptii backward-compatibility
                menuItem.setActionCommand(oldDisplayName);

                // add JMenuItem to the Action, so it can be accessed by
                // Action code
                action.putValue(NEW_JMENUITEM_KEY, menuItem);
                leafMenuItem = menuItem;
            } else {
                // if we're *not* at a "leaf node" - need to create a JMenu
                menuItem = new JMenu(nextLevelStr);
                if (mnemonicChar > 0) {
                    menuItem.setMnemonic(mnemonicChar);
                }
            }
            // level 0 is a special case, since the container (JMenuBar or
            // JContextMenu) is not a JMenu or a JMenuItem, so we can't
            // use the same code to add child to parent...
            if (levelIdx == 0) {
                if (topLvlContainer instanceof JMenuBar) {
                    // this handles JMenuBar menus
                    ((JMenuBar) topLvlContainer).add(menuItem);
                } else if (topLvlContainer instanceof JContextMenu) {
                    // this handles popup context menus
                    ((JContextMenu) topLvlContainer).add(menuItem);
                }
                // add to Map
                keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                separatorJustAdded = false;
            } else {
                JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);
                if (parent != null) {
                    // add to parent
                    parent.add(menuItem);
                    // add to Map
                    keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                    separatorJustAdded = false;
                } else {
                    if (isDebugging) {
                        log.debug("Parent menu is NULL" + prevLevelStr);
                    }
                }
            }
        }
    }
    return leafMenuItem;
}

From source file:org.languagetool.gui.Main.java

private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(getLabel("guiMenuFile"));
    fileMenu.setMnemonic(getMnemonic("guiMenuFile"));
    JMenu editMenu = new JMenu(getLabel("guiMenuEdit"));
    editMenu.setMnemonic(getMnemonic("guiMenuEdit"));
    JMenu grammarMenu = new JMenu(getLabel("guiMenuGrammar"));
    grammarMenu.setMnemonic(getMnemonic("guiMenuGrammar"));
    JMenu helpMenu = new JMenu(getLabel("guiMenuHelp"));
    helpMenu.setMnemonic(getMnemonic("guiMenuHelp"));

    fileMenu.add(openAction);//from  w  w  w.  ja v a2  s  . c o  m
    fileMenu.add(saveAction);
    fileMenu.add(saveAsAction);
    recentFilesMenu = new JMenu(getLabel("guiMenuRecentFiles"));
    recentFilesMenu.setMnemonic(getMnemonic("guiMenuRecentFiles"));
    fileMenu.add(recentFilesMenu);
    updateRecentFilesMenu();
    fileMenu.addSeparator();
    fileMenu.add(new HideAction());
    fileMenu.addSeparator();
    fileMenu.add(new QuitAction());

    grammarMenu.add(checkAction);
    JCheckBoxMenuItem item = new JCheckBoxMenuItem(autoCheckAction);
    grammarMenu.add(item);
    JCheckBoxMenuItem showResult = new JCheckBoxMenuItem(showResultAction);
    grammarMenu.add(showResult);
    grammarMenu.add(new CheckClipboardAction());
    grammarMenu.add(new TagTextAction());
    grammarMenu.add(new AddRulesAction());
    grammarMenu.add(new OptionsAction());
    grammarMenu.add(new SelectFontAction());
    JMenu lafMenu = new JMenu(messages.getString("guiLookAndFeelMenu"));
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    ButtonGroup buttonGroup = new ButtonGroup();
    for (UIManager.LookAndFeelInfo laf : lafInfo) {
        if (!"Nimbus".equals(laf.getName())) {
            continue;
        }
        addLookAndFeelMenuItem(lafMenu, laf, buttonGroup);
    }
    for (UIManager.LookAndFeelInfo laf : lafInfo) {
        if ("Nimbus".equals(laf.getName())) {
            continue;
        }
        addLookAndFeelMenuItem(lafMenu, laf, buttonGroup);
    }
    grammarMenu.add(lafMenu);

    helpMenu.add(new AboutAction());

    undoRedo.undoAction.putValue(Action.NAME, getLabel("guiMenuUndo"));
    undoRedo.undoAction.putValue(Action.MNEMONIC_KEY, getMnemonic("guiMenuUndo"));
    undoRedo.redoAction.putValue(Action.NAME, getLabel("guiMenuRedo"));
    undoRedo.redoAction.putValue(Action.MNEMONIC_KEY, getMnemonic("guiMenuRedo"));

    editMenu.add(undoRedo.undoAction);
    editMenu.add(undoRedo.redoAction);
    editMenu.addSeparator();

    Action cutAction = new DefaultEditorKit.CutAction();
    cutAction.putValue(Action.SMALL_ICON, getImageIcon("sc_cut.png"));
    cutAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_cut.png"));
    cutAction.putValue(Action.NAME, getLabel("guiMenuCut"));
    cutAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T);
    editMenu.add(cutAction);

    Action copyAction = new DefaultEditorKit.CopyAction();
    copyAction.putValue(Action.SMALL_ICON, getImageIcon("sc_copy.png"));
    copyAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_copy.png"));
    copyAction.putValue(Action.NAME, getLabel("guiMenuCopy"));
    copyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
    editMenu.add(copyAction);

    Action pasteAction = new DefaultEditorKit.PasteAction();
    pasteAction.putValue(Action.SMALL_ICON, getImageIcon("sc_paste.png"));
    pasteAction.putValue(Action.LARGE_ICON_KEY, getImageIcon("lc_paste.png"));
    pasteAction.putValue(Action.NAME, getLabel("guiMenuPaste"));
    pasteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P);
    editMenu.add(pasteAction);

    editMenu.addSeparator();

    editMenu.add(new SelectAllAction());

    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(grammarMenu);
    menuBar.add(helpMenu);
    return menuBar;
}

From source file:org.n52.ifgicopter.spf.gui.SPFMainFrame.java

/**
 * the gui representation of the framework
 *//* w  w  w.ja  v  a  2s .c o  m*/
public SPFMainFrame() {

    /*
     * handled by worker thread.
     */
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    this.setTitle("Sensor Platform Framework");

    this.menu = new JMenuBar();

    try {
        File f = new File("img/icon.png");
        InputStream in;
        if (!f.exists()) {
            in = ImageMapMarker.class.getResourceAsStream("/img/icon.png");
        } else {
            in = new FileInputStream(f);
        }

        this.setIconImage(ImageIO.read(in));
    } catch (IOException e) {
        this.log.warn(e.getMessage(), e);
    }

    /*
     * simple menu bar
     */
    JMenu file = new JMenu("File");
    JMenuItem exit = new JMenuItem("Exit");

    /*
     * shutdown the engine if closed
     */
    exit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            shutdownFrame();
        }
    });

    this.pnp = new JCheckBoxMenuItem("Plug'n'Play mode");
    this.pnp.setSelected(false);

    /*
     * switch the pnp mode
     */
    this.pnp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean flag = SPFMainFrame.this.pnp.isSelected();

            if (flag && !SPFMainFrame.this.dontShow) {
                JCheckBox checkbox = new JCheckBox("Do not show this message again.");
                String message = "During Plug'n'Play mode the output generation is blocked.";
                Object[] params = { message, checkbox };
                JOptionPane.showMessageDialog(SPFMainFrame.this, params);
                SPFMainFrame.this.dontShow = checkbox.isSelected();
            }

            /*
             * check if we need to restart the output plugins
             */
            if (!flag && SPFMainFrame.this.inputChanged) {
                SPFRegistry.getInstance().restartOutputPlugins();
            }

            SPFRegistry.getInstance().setPNPMode(flag);
        }
    });

    JMenuItem restart = new JMenuItem("Restart");
    restart.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            shutdownFrame(RESTART_CODE);
        }
    });

    JMenuItem managePlugins = new JMenuItem("Manage available Plugins");
    managePlugins.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PluginRegistrationDialog prd = new PluginRegistrationDialog(SPFMainFrame.this);

            if (prd.isCanceled())
                return;

            updateConfigurationFile(prd.getSelectedNewPlugins(), prd.getSelectedOldPlugins());

            int ret = JOptionPane.showConfirmDialog(SPFMainFrame.this,
                    "<html><body><div>" + "Changes will have effect after restart of the application. "
                            + "</div><div>A restart is highly recommended due to memory usage."
                            + "</div><div><br />Restart now?</div></body></html>",
                    "Restart application", JOptionPane.YES_NO_OPTION);

            if (ret == 0) {
                shutdownFrame(RESTART_CODE);
            }
        }
    });
    file.add(managePlugins);

    file.add(this.pnp);
    file.add(new FixedSeparator());
    file.add(restart);
    file.add(new FixedSeparator());
    file.add(exit);
    this.menu.add(file);
    this.inputPluginMenu = new JMenu("InputPlugins");
    this.outputPluginMenu = new JMenu("OutputPlugins");
    this.menu.add(this.inputPluginMenu);
    this.menu.add(this.outputPluginMenu);

    /*
     * help
     */
    this.aboutDialog = new AboutDialog(SPFMainFrame.this);
    JMenu help = new JMenu("Help");
    JMenuItem about = new JMenuItem("About");
    about.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SPFMainFrame.this.aboutDialog.showSelf(SPFMainFrame.this);
        }
    });

    help.add(about);
    this.menu.add(help);
    this.setJMenuBar(this.menu);

    /*
     * the tabbed pane. every tab represents a input plugin
     */
    this.pane = new JTabbedPane();
    this.pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    /*
     * shutdown the engine if closed
     */
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            SPFMainFrame.this.shutdownFrame();
        }

    });

    /*
     * the framework core tab
     */
    this.corePanel = new FrameworkCorePanel();
    this.addTab(this.corePanel, "Framework Core", BLUE_IMAGE);

    /*
     * the map panel
     */
    if (Boolean.parseBoolean(SPFRegistry.getInstance().getConfigProperty(SPFRegistry.OVERVIEW_MAP_ENABLED))) {
        this.mapPanel = new MapPanel();
        this.addTab(this.mapPanel, "Overview Map", BLUE_IMAGE);
    }

    /*
     * other stuff
     */
    this.getContentPane().add(this.pane);

    JPanel statusBar = new JPanel();
    statusBar.setLayout(new BorderLayout());
    statusBar.setPreferredSize(new Dimension(200, 25));
    JPanel statusBarWrapper = new JPanel(new BorderLayout());
    statusBarWrapper.add(Box.createRigidArea(new Dimension(3, 3)), BorderLayout.WEST);
    statusBarWrapper.add(statusBar);
    statusBarWrapper.add(Box.createRigidArea(new Dimension(3, 3)), BorderLayout.EAST);

    this.statusLabel = new JLabel("SPFramework startup finished.");
    statusBar.add(this.statusLabel, BorderLayout.EAST);

    this.outputLabel = new JLabel("(no output yet)");
    statusBar.add(this.outputLabel, BorderLayout.WEST);

    this.getContentPane().add(statusBarWrapper, BorderLayout.SOUTH);

    this.getContentPane().setBackground(this.pane.getBackground());

    this.setPreferredSize(new Dimension(1280, 720));
    this.pack();

    /*
     * full screen?
     */
    if (Boolean.parseBoolean(SPFRegistry.getInstance().getConfigProperty(SPFRegistry.MAXIMIZED))) {
        this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
    }

    this.setLocationRelativeTo(null);
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup Menu Bar//from  w w w .ja  va2  s  . c  o  m
 * @return JMenu Bar
 */
private JMenuBar setupMenu() {
    JMenuBar menuBar = new JMenuBar();

    /* -- GridNode Menu -- */

    JMenu gridNodeMenu = new JMenu("GridNode");
    gridNodeMenu.setMnemonic(KeyEvent.VK_N);
    menuBar.add(gridNodeMenu);

    // Discover 
    JMenuItem clusterDiscoverItem = new JMenuItem("Disover and Connect Clusters");
    clusterDiscoverItem.setMnemonic(KeyEvent.VK_D);
    clusterDiscoverItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    gridNodeMenu.add(clusterDiscoverItem);
    clusterDiscoverItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doDiscover(false);
            ((JCheckBoxMenuItem) getUIElement("menu.node.autodiscover")).setSelected(false);
        }
    });
    addUIElement("menu.node.discover", clusterDiscoverItem); // Add to components map

    // Auto-Discovery
    final JCheckBoxMenuItem autodiscoveryItem = new JCheckBoxMenuItem("Auto Discover");
    autodiscoveryItem.setMnemonic(KeyEvent.VK_A);
    autodiscoveryItem.setSelected(true);
    gridNodeMenu.add(autodiscoveryItem);
    autodiscoveryItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            autodiscover = autodiscoveryItem.isSelected();
        }
    });
    addUIElement("menu.node.autodiscover", autodiscoveryItem); // Add to components map

    gridNodeMenu.addSeparator();

    // Cluster-> Shutdown
    JMenuItem nodeShutdownItem = new JMenuItem("Shutdown", 'u');
    nodeShutdownItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    nodeShutdownItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doShutdownNode();
        }
    });
    gridNodeMenu.add(nodeShutdownItem);
    addUIElement("menu.node.shutdown", nodeShutdownItem); // Add to components map

    /* -- Options Menu -- */
    JMenu optionsMenu = new JMenu("Options");
    optionsMenu.setMnemonic(KeyEvent.VK_O);
    menuBar.add(optionsMenu);

    // Configuration
    JMenuItem optionsConfigItem = new JMenuItem("Configuration...", 'C');
    optionsConfigItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showConfiguration();
        }
    });
    optionsMenu.add(optionsConfigItem);
    optionsConfigItem.setEnabled(false); // TODO Create Configuration Options

    /* -- Help Menu -- */
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(helpMenu);

    // Help Contents
    JMenuItem helpContentsItem = new JMenuItem("Help Contents", 'H');
    helpContentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    helpContentsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showHelp();
        }
    });
    helpMenu.add(helpContentsItem);

    helpMenu.addSeparator();

    JMenuItem helpAboutItem = new JMenuItem("About", 'A');
    helpAboutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showAbout();
        }
    });
    helpMenu.add(helpAboutItem);

    return menuBar;
}

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

protected JPopupMenu createPopupMenuEntity(final mxCell cell, boolean newCell) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();

    JPopupMenu pop = new JPopupMenu();
    JMenuItem i1 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.14", "Symbol l\u00f6schen"));
    i1.addActionListener(new ActionListener() {

        @Override/* www  .  java  2  s  . c  om*/
        public void actionPerformed(ActionEvent e) {
            mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
            int iEdge = cell.getEdgeCount();
            for (int i = 0; i < iEdge; i++) {
                mxCell cellRelation = (mxCell) cell.getEdgeAt(0);
                model.remove(cellRelation);
            }
            model.remove(cell);
            fireChangeListenEvent();
        }
    });

    if (!newCell)
        pop.add(i1);

    if (cell.getStyle() == null || !(cell.getStyle().indexOf(ENTITYSTYLE) >= 0)) {
        return pop;
    }

    JMenuItem iWizard = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.15", "Wizard \u00f6ffnen"));
    iWizard.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                String sValue = ((EntityMetaDataVO) cell.getValue()).getEntity();
                if (sValue.length() > 0) {
                    try {
                        final EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(sValue);
                        new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                    } catch (Exception e1) {
                        // neue Entity
                        LOG.info("actionPerformed: " + e1 + " (new entity?)");
                    }
                }
            }
        }
    });

    if (!newCell) {
        //pop.addSeparator();
        pop.add(iWizard);
    } else {
        JMenuItem iNew = new JMenuItem(
                localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
        iNew.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                    final EntityMetaDataVO voTMP = (EntityMetaDataVO) cell.getValue();
                    final EntityMetaDataVO vo = MetaDataClientProvider.getInstance()
                            .getEntity(voTMP.getEntity());
                    new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                } else {
                    cell.setValue(
                            localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
                    mxGraph graph = graphComponent.getGraph();
                    graph.refresh();
                }
            }
        });
        pop.add(iNew);
    }
    //pop.addSeparator();

    Collection<EntityMetaDataVO> colMetaVO = MetaDataClientProvider.getInstance().getAllEntities();

    List<EntityMetaDataVO> lst = new ArrayList<EntityMetaDataVO>(colMetaVO);

    Collections.sort(lst, new Comparator<EntityMetaDataVO>() {

        @Override
        public int compare(EntityMetaDataVO o1, EntityMetaDataVO o2) {
            return o1.getEntity().toLowerCase().compareTo(o2.getEntity().toLowerCase());
        }

    });

    for (final EntityMetaDataVO vo : lst) {
        if (vo.getEntity().startsWith("nuclos_"))
            continue;

        JCheckBoxMenuItem menu = new JCheckBoxMenuItem(vo.getEntity());
        menu.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final JMenuItem item = (JMenuItem) e.getSource();
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        cell.setValue(vo);
                        graphComponent.repaint();
                        fireChangeListenEvent();
                    }
                });

            }
        });
        if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
            EntityMetaDataVO sValue = (EntityMetaDataVO) cell.getValue();
            if (vo.getEntity().equals(sValue.getEntity())) {
                menu.setSelected(true);
            }
        }
        //pop.add(menu);
    }

    return pop;

}

From source file:org.omegat.gui.issues.IssuesPanelController.java

JMenuBar generateMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = menuBar.add(new JMenu(OStrings.getString("ISSUES_WINDOW_MENU_OPTIONS")));

    {//  ww w .  ja  va2 s. co  m
        // Tags item is hard-coded because it is not disableable and is implemented differently from all
        // others.
        JCheckBoxMenuItem tagsItem = new JCheckBoxMenuItem(OStrings.getString(
                "ISSUES_WINDOW_MENU_OPTIONS_TOGGLE_PROVIDER", OStrings.getString("ISSUES_TAGS_PROVIDER_NAME")));
        tagsItem.setSelected(true);
        tagsItem.setEnabled(false);
        menu.add(tagsItem);
    }

    Set<String> disabledProviders = IssueProviders.getDisabledProviderIds();
    IssueProviders.getIssueProviders().stream().sorted(Comparator.comparing(IIssueProvider::getId))
            .forEach(provider -> {
                String label = StringUtil.format(
                        OStrings.getString("ISSUES_WINDOW_MENU_OPTIONS_TOGGLE_PROVIDER"), provider.getName());
                JCheckBoxMenuItem item = new JCheckBoxMenuItem(label);
                item.addActionListener(e -> {
                    IssueProviders.setProviderEnabled(provider.getId(), item.isSelected());
                    refreshData(selectedEntry, selectedType);
                });
                item.setSelected(!disabledProviders.contains(provider.getId()));
                menu.add(item);
            });

    menu.addSeparator();

    {
        JCheckBoxMenuItem askItem = new JCheckBoxMenuItem(OStrings.getString("ISSUES_WINDOW_MENU_DONT_ASK"));
        askItem.setSelected(Preferences.isPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK));
        askItem.addActionListener(
                e -> Preferences.setPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK, askItem.isSelected()));
        menu.add(askItem);
    }
    return menuBar;
}

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;//from   w w  w .  j  a  v a  2  s.c o 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/*from w ww. j a va  2  s  .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:org.openconcerto.task.TodoListPanel.java

private void initViewableUsers(final User currentUser) {
    final SwingWorker2<List<Tuple3<String, Integer, String>>, Object> worker = new SwingWorker2<List<Tuple3<String, Integer, String>>, Object>() {

        @Override/*  ww  w .j a  v  a  2 s.co m*/
        protected List<Tuple3<String, Integer, String>> doInBackground() throws Exception {
            final List<Integer> canViewUsers = new ArrayList<Integer>();
            for (final UserTaskRight right : UserTaskRight.getUserTaskRight(currentUser)) {
                if (right.canRead())
                    canViewUsers.add(right.getIdToUser());
            }
            // final Vector users = new Vector();
            final SQLTable userT = UserManager.getInstance().getTable();
            final DBSystemRoot systemRoot = Configuration.getInstance().getSystemRoot();
            final SQLSelect select1 = new SQLSelect(systemRoot, false);
            select1.addSelect(userT.getKey());
            select1.addSelect(userT.getField("NOM"));
            select1.addSelect(userT.getField("PRENOM"));
            select1.addSelect(userT.getField("SURNOM"));
            final Where meWhere = new Where(userT.getKey(), "=", currentUser.getId());
            final Where canViewWhere = new Where(userT.getKey(), canViewUsers);
            select1.setWhere(meWhere.or(canViewWhere));

            final List<Tuple3<String, Integer, String>> result = new ArrayList<Tuple3<String, Integer, String>>();
            userT.getDBSystemRoot().getDataSource().execute(select1.asString(), new ResultSetHandler() {
                public Object handle(ResultSet rs) throws SQLException {
                    while (rs.next()) {
                        String displayName = rs.getString(4).trim();
                        if (displayName.length() == 0) {
                            displayName = rs.getString(3).trim() + " " + rs.getString(2).trim().toUpperCase();
                        }
                        final int uId = rs.getInt(1);
                        final String name = rs.getString(2);
                        result.add(new Tuple3<String, Integer, String>(displayName, uId, name));

                    }
                    return null;
                }
            });
            return result;
        }

        @Override
        protected void done() {
            try {
                final List<Tuple3<String, Integer, String>> tuples = get();
                for (Tuple3<String, Integer, String> tuple3 : tuples) {
                    final JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(tuple3.get0());
                    TodoListPanel.this.comboUser.add(checkBoxMenuItem);

                    final int uId = tuple3.get1();
                    final String name = tuple3.get2();

                    TodoListPanel.this.users.add(new User(uId, name));
                    checkBoxMenuItem.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if (checkBoxMenuItem.isSelected())
                                addUserListenerId(uId);
                            else
                                removeUserListenerId(uId);
                        }

                    });
                }

            } catch (Exception e) {
                ExceptionHandler.handle("Unable to get tasks users", e);
            }

        }
    };

    worker.execute();

}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
 * Brings up the <code>ManagePopupMenu</code>on top of the specified
 * component at the specified location./*from   www.j  av a  2s .  c o m*/
 * 
 * @param c The component that requested the po-pup menu.
 * @param p The point at which to display the menu, relative to the
 *            <code>component</code>'s coordinates.
 */
private void showPersonalMenu(Component c, Point p) {
    if (p == null)
        return;

    if (c == null)
        throw new IllegalArgumentException("No component.");

    personalMenu = new JPopupMenu();
    personalMenu.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    List<GroupSelectionAction> l = controller.getUserGroupAction();
    Iterator<GroupSelectionAction> i = l.iterator();
    GroupSelectionAction a;
    JCheckBoxMenuItem item;
    ButtonGroup buttonGroup = new ButtonGroup();
    long id = model.getGroupId();
    while (i.hasNext()) {
        a = i.next();
        item = new JCheckBoxMenuItem(a);
        item.setEnabled(true);
        item.setSelected(a.isSameGroup(id));
        initMenuItem(item);
        buttonGroup.add(item);
        personalMenu.add(item);
    }
    personalMenu.show(c, p.x, p.y);
}