Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

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

Prototype

public JMenu(Action a) 

Source Link

Document

Constructs a menu whose properties are taken from the Action supplied.

Usage

From source file:com.haulmont.cuba.desktop.App.java

protected Container createStartContentPane() {
    JPanel pane = new JPanel(new BorderLayout());
    menuBar = new JMenuBar();
    pane.add(menuBar, BorderLayout.NORTH);

    Locale loc = Locale.getDefault();

    JMenu menu = new JMenu(messages.getMainMessage("mainMenu.file", loc));
    menuBar.add(menu);/*  ww w. jav  a  2s. c  om*/

    JMenuItem item;

    item = new JMenuItem(messages.getMainMessage("mainMenu.connect", loc));
    item.addActionListener(e -> showLoginDialog());
    menu.add(item);

    item = new JMenuItem(messages.getMainMessage("mainMenu.exit", loc));
    item.addActionListener(new ValidationAwareActionListener() {
        @Override
        public void actionPerformedAfterValidation(ActionEvent e) {
            exit();
        }
    });
    menu.add(item);

    if (isTestMode()) {
        menuBar.setName("startMenu");
    }

    return pane;
}

From source file:edu.purdue.cc.bionet.ui.CorrelationDisplayPanel.java

/**
 * Adds all of the necessary Components to this Component.
 *///from   w w w.  jav  a 2  s  .c om
private void buildPanel() {

    Language language = Settings.getLanguage();
    this.correlationMethodMenu = new JMenu(language.get("Correlation Method"));
    this.correlationMethodMenuButtonGroup = new ButtonGroup();
    this.pearsonCalculationMenuItem = new JRadioButtonMenuItem(language.get("Pearson"), true);
    this.spearmanCalculationMenuItem = new JRadioButtonMenuItem(language.get("Spearman"));
    this.kendallCalculationMenuItem = new JRadioButtonMenuItem(language.get("Kendall"));

    // layout menu itmes
    this.layoutMenu = new JMenu(language.get("Layout"));
    this.layoutMenuButtonGroup = new ButtonGroup();
    this.multipleCirclesLayoutMenuItem = new JRadioButtonMenuItem(language.get("Multiple Circles"));
    this.singleCircleLayoutMenuItem = new JRadioButtonMenuItem(language.get("Single Circle"), true);
    this.randomLayoutMenuItem = new JRadioButtonMenuItem(language.get("Random"));
    this.heatMapLayoutMenuItem = new JRadioButtonMenuItem(language.get("Heat Map"));
    this.kkLayoutMenuItem = new JRadioButtonMenuItem(language.get("Kamada-Kawai"));
    //      this.frLayoutMenuItem = 
    //            new JRadioButtonMenuItem( language.get( "Fruchterman-Reingold" ));
    //      this.springLayoutMenuItem = 
    //               new JRadioButtonMenuItem( language.get( "Spring Layout" ));
    this.frSpringLayoutMenuItem = new JRadioButtonMenuItem(language.get("Spring Layout"));
    //      this.animatedLayoutMenuItem = new JCheckBoxMenuItem( 
    //         language.get( "Fruchterman-Reingold Spring Embedding" ));

    // view menu items
    this.viewMenu = new JMenu(language.get("View"));
    this.zoomInViewMenuItem = new JMenuItem(language.get("Zoom In"), KeyEvent.VK_I);
    this.zoomOutViewMenuItem = new JMenuItem(language.get("Zoom Out"), KeyEvent.VK_O);
    this.fitToWindowViewMenuItem = new JMenuItem(language.get("Fit to Window"), KeyEvent.VK_F);
    this.selectAllViewMenuItem = new JMenuItem(language.get("Select All"), KeyEvent.VK_A);
    this.clearSelectionViewMenuItem = new JMenuItem(language.get("Clear Selection"), KeyEvent.VK_C);
    this.invertSelectionViewMenuItem = new JMenuItem(language.get("Invert Selection"), KeyEvent.VK_I);
    this.selectCorrelatedViewMenuItem = new JMenuItem(language.get("Select Correlated to Selection"),
            KeyEvent.VK_R);
    this.hideSelectedViewMenuItem = new JMenuItem(language.get("Hide Selected"), KeyEvent.VK_H);
    this.hideUnselectedViewMenuItem = new JMenuItem(language.get("Hide Unselected"), KeyEvent.VK_U);
    this.hideUncorrelatedViewMenuItem = new JMenuItem(language.get("Hide Uncorrelated to Selection"),
            KeyEvent.VK_L);
    this.hideOrphansViewMenuItem = new JMenuItem(language.get("Hide Orphans"), KeyEvent.VK_P);
    this.showCorrelatedViewMenuItem = new JMenuItem(language.get("Show All Correlated to Visible"),
            KeyEvent.VK_S);
    this.saveImageAction = new SaveImageAction(language.get("Save Main Graph Image") + "...", null);

    // groups menu items
    this.groupsMenu = new JMenu(language.get("Groups"));
    this.resetSampleGroupsMenuItem = new JMenuItem(language.get("Reset Sample Groups"), KeyEvent.VK_R);
    this.chooseSampleGroupsMenuItem = new JMenuItem(language.get("Choose Sample Groups") + "...",
            KeyEvent.VK_C);

    // color menu items
    this.colorMenu = new JMenu(language.get("Color"));
    this.colorMenuButtonGroup = new ButtonGroup();
    this.normalColorMenuItem = new JRadioButtonMenuItem(language.get("Normal Color"), true);
    this.highContrastColorMenuItem = new JRadioButtonMenuItem(language.get("High Contrast Color"));

    // CORRELATION FILTER ELEMENTS
    JPanel leftPanel = new JPanel(new BorderLayout());
    this.moleculeFilterPanel = new MoleculeFilterPanel();
    leftPanel.add(moleculeFilterPanel, BorderLayout.CENTER);
    this.correlationFilterPanel = new CorrelationFilterPanel();
    leftPanel.add(this.correlationFilterPanel, BorderLayout.SOUTH);

    //CALCULATION MENU
    this.correlationMethodMenu.setMnemonic(KeyEvent.VK_C);
    this.correlationMethodMenu.getAccessibleContext()
            .setAccessibleDescription(language.get("Perform Data Calculations"));
    this.correlationMethodMenuButtonGroup.add(this.pearsonCalculationMenuItem);
    this.correlationMethodMenuButtonGroup.add(this.spearmanCalculationMenuItem);
    this.correlationMethodMenuButtonGroup.add(this.kendallCalculationMenuItem);
    this.pearsonCalculationMenuItem.setMnemonic(KeyEvent.VK_P);
    this.spearmanCalculationMenuItem.setMnemonic(KeyEvent.VK_S);
    this.kendallCalculationMenuItem.setMnemonic(KeyEvent.VK_K);
    this.correlationMethodMenu.add(this.pearsonCalculationMenuItem);
    this.correlationMethodMenu.add(this.spearmanCalculationMenuItem);
    this.correlationMethodMenu.add(this.kendallCalculationMenuItem);
    this.pearsonCalculationMenuItem.addItemListener(this);
    this.spearmanCalculationMenuItem.addItemListener(this);
    this.kendallCalculationMenuItem.addItemListener(this);

    //LAYOUT MENU
    LayoutChangeListener lcl = new LayoutChangeListener();
    this.layoutMenu.setMnemonic(KeyEvent.VK_L);
    this.layoutMenu.getAccessibleContext()
            .setAccessibleDescription(language.get("Change the layout of the graph"));
    this.layoutMenuButtonGroup.add(this.multipleCirclesLayoutMenuItem);
    this.layoutMenuButtonGroup.add(this.singleCircleLayoutMenuItem);
    this.layoutMenuButtonGroup.add(this.randomLayoutMenuItem);
    this.layoutMenuButtonGroup.add(this.kkLayoutMenuItem);
    //      this.layoutMenuButtonGroup.add( this.frLayoutMenuItem );
    //      this.layoutMenuButtonGroup.add( this.springLayoutMenuItem );
    this.layoutMenuButtonGroup.add(this.frSpringLayoutMenuItem);
    this.layoutMenuButtonGroup.add(this.heatMapLayoutMenuItem);

    Enumeration<AbstractButton> e = this.layoutMenuButtonGroup.getElements();
    this.layoutMenu.add(this.multipleCirclesLayoutMenuItem);
    this.layoutMenu.add(this.singleCircleLayoutMenuItem);
    this.layoutMenu.add(this.randomLayoutMenuItem);
    this.layoutMenu.add(this.kkLayoutMenuItem);
    //      this.layoutMenu.add( this.frLayoutMenuItem );
    //      this.layoutMenu.add( this.springLayoutMenuItem );
    this.layoutMenu.add(this.frSpringLayoutMenuItem);
    this.layoutMenu.add(this.heatMapLayoutMenuItem);
    //      this.layoutMenu.addSeparator( );
    //      this.layoutMenu.add( this.animatedLayoutMenuItem );
    this.multipleCirclesLayoutMenuItem.addActionListener(lcl);
    this.multipleCirclesLayoutMenuItem.setEnabled(false);
    this.singleCircleLayoutMenuItem.addActionListener(lcl);
    this.randomLayoutMenuItem.addActionListener(lcl);
    this.kkLayoutMenuItem.addActionListener(lcl);
    //      this.frLayoutMenuItem.addActionListener( lcl );
    this.frSpringLayoutMenuItem.addActionListener(lcl);
    this.heatMapLayoutMenuItem.addActionListener(lcl);
    //      this.animatedLayoutMenuItem.addActionListener( lcl );

    //VIEW MENU
    this.viewMenu.add(this.colorMenu);
    this.viewMenu.addSeparator();
    this.viewMenu.setMnemonic(KeyEvent.VK_V);
    this.viewMenu.getAccessibleContext()
            .setAccessibleDescription(language.get("Change the data view settings"));
    this.viewMenu.add(this.zoomOutViewMenuItem);
    this.viewMenu.add(this.zoomInViewMenuItem);
    this.viewMenu.add(this.fitToWindowViewMenuItem);
    this.viewMenu.addSeparator();
    this.viewMenu.add(this.selectAllViewMenuItem);
    this.viewMenu.add(this.clearSelectionViewMenuItem);
    this.viewMenu.add(this.invertSelectionViewMenuItem);
    this.viewMenu.add(this.selectCorrelatedViewMenuItem);
    this.viewMenu.addSeparator();
    this.viewMenu.add(this.hideSelectedViewMenuItem);
    this.viewMenu.add(this.hideUnselectedViewMenuItem);
    this.viewMenu.add(this.hideUncorrelatedViewMenuItem);
    this.viewMenu.add(this.hideOrphansViewMenuItem);
    this.viewMenu.add(this.showCorrelatedViewMenuItem);
    this.viewMenu.addSeparator();
    this.viewMenu.add(this.saveImageAction);
    this.resetSampleGroupsMenuItem.addActionListener(this);
    this.chooseSampleGroupsMenuItem.addActionListener(this);
    this.zoomOutViewMenuItem.addActionListener(this);
    this.zoomInViewMenuItem.addActionListener(this);
    this.fitToWindowViewMenuItem.addActionListener(this);
    this.selectAllViewMenuItem.addActionListener(this);
    this.clearSelectionViewMenuItem.addActionListener(this);
    this.invertSelectionViewMenuItem.addActionListener(this);
    this.selectCorrelatedViewMenuItem.addActionListener(this);
    this.hideSelectedViewMenuItem.addActionListener(this);
    this.hideUnselectedViewMenuItem.addActionListener(this);
    this.hideUncorrelatedViewMenuItem.addActionListener(this);
    this.hideOrphansViewMenuItem.addActionListener(this);
    this.showCorrelatedViewMenuItem.addActionListener(this);
    this.selectAllViewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK));
    this.clearSelectionViewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));

    // GROUPS MENU
    this.groupsMenu.setMnemonic(KeyEvent.VK_G);
    this.groupsMenu.add(this.resetSampleGroupsMenuItem);
    this.groupsMenu.add(this.chooseSampleGroupsMenuItem);

    this.zoomOutViewMenuItem
            .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK));
    this.zoomInViewMenuItem
            .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.CTRL_DOWN_MASK));
    this.fitToWindowViewMenuItem
            .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, InputEvent.CTRL_DOWN_MASK));
    this.hideSelectedViewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

    //COLOR MENU
    this.colorMenu.setMnemonic(KeyEvent.VK_R);
    this.colorMenu.getAccessibleContext()
            .setAccessibleDescription(language.get("Change the color of the graph"));
    this.colorMenuButtonGroup.add(this.normalColorMenuItem);
    this.colorMenuButtonGroup.add(this.highContrastColorMenuItem);
    this.colorMenu.add(this.normalColorMenuItem);
    this.colorMenu.add(this.highContrastColorMenuItem);
    this.normalColorMenuItem.addItemListener(this);
    this.highContrastColorMenuItem.addItemListener(this);

    this.menuBar.add(this.correlationMethodMenu);
    this.menuBar.add(this.layoutMenu);
    this.menuBar.add(this.viewMenu);
    this.menuBar.add(this.groupsMenu);

    // Add the panels to the main panel
    this.add(menuBar, BorderLayout.NORTH);
    //      this.add( this.correlationViewPanel, BorderLayout.CENTER );
    this.add(leftPanel, BorderLayout.WEST);
}

From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java

/**
 * Rebuild all the action components such as toobar, context menu
 *//*w  ww  . j  a v  a  2 s . c  om*/

public void rebuildActionComponents() {
    //  Clear the current state of the component
    log.debug("Rebuild action components");
    toolBar.removeAll();
    //
    Vector enabledActions = new Vector();
    for (Iterator i = actions.iterator(); i.hasNext();) {
        StandardAction a = (StandardAction) i.next();
        String n = (String) a.getValue(Action.NAME);
        Boolean s = (Boolean) actionsVisible.get(n);
        if (s == null) {
            s = Boolean.TRUE;
        }
        if (Boolean.TRUE.equals(s)) {
            log.debug("Action " + n + " is enabled.");
            enabledActions.add(a);
        } else {
            log.debug("Action " + n + " not enabled.");
        }
    }
    //  Build the tool bar, grouping the actions
    Vector v = new Vector();
    for (Iterator i = enabledActions.iterator(); i.hasNext();) {
        StandardAction a = (StandardAction) i.next();
        if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_TOOLBAR))) {
            v.addElement(a);
        }
    }

    Collections.sort(v, new ToolBarActionComparator());
    Integer grp = null;
    for (Iterator i = v.iterator(); i.hasNext();) {
        StandardAction z = (StandardAction) i.next();
        if ((grp != null) && !grp.equals((Integer) z.getValue(StandardAction.TOOLBAR_GROUP))) {
            toolBar.add(new ToolBarSeparator());
        }
        if (Boolean.TRUE.equals((Boolean) z.getValue(StandardAction.IS_TOGGLE_BUTTON))) {
            ToolToggleButton tBtn = new ToolToggleButton(z);
            toolBar.add(tBtn);
        } else {
            ToolButton btn = new ToolButton(z);
            toolBar.add(btn);
        }
        grp = (Integer) z.getValue(StandardAction.TOOLBAR_GROUP);
    }
    toolBar.revalidate();
    toolBar.repaint();
    //  Build the context menu, grouping the actions
    Vector c = new Vector();
    contextMenu.removeAll();
    for (Iterator i = enabledActions.iterator(); i.hasNext();) {
        StandardAction a = (StandardAction) i.next();
        if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_CONTEXT_MENU))) {
            c.addElement(a);
        }
    }
    Collections.sort(c, new ContextActionComparator());
    grp = null;
    for (Iterator i = c.iterator(); i.hasNext();) {
        StandardAction z = (StandardAction) i.next();
        if ((grp != null) && !grp.equals((Integer) z.getValue(StandardAction.CONTEXT_MENU_GROUP))) {
            contextMenu.addSeparator();
        }
        contextMenu.add(z);
        grp = (Integer) z.getValue(StandardAction.CONTEXT_MENU_GROUP);
    }
    contextMenu.revalidate();
    //  Build the menu bar
    menuBar.removeAll();
    v.removeAllElements();
    for (Enumeration e = enabledActions.elements(); e.hasMoreElements();) {
        StandardAction a = (StandardAction) e.nextElement();

        if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_MENUBAR))) {
            v.addElement(a);
        }
    }
    Vector menus = (Vector) actionMenus.clone();
    Collections.sort(menus);
    HashMap map = new HashMap();
    for (Iterator i = v.iterator(); i.hasNext();) {
        StandardAction z = (StandardAction) i.next();
        String menuName = (String) z.getValue(StandardAction.MENU_NAME);
        if (menuName == null) {
            log.error("Action " + z.getName() + " doesnt specify a value for " + StandardAction.MENU_NAME);
        } else {
            String m = (String) z.getValue(StandardAction.MENU_NAME);
            ActionMenu menu = getActionMenu(menus.iterator(), m);
            if (menu == null) {
                log.error("Action menu " + z.getName() + " does not exist");
            } else {
                Vector x = (Vector) map.get(menu.name);
                if (x == null) {
                    x = new Vector();
                    map.put(menu.name, x);
                }
                x.addElement(z);
            }
        }
    }

    for (Iterator i = menus.iterator(); i.hasNext();) {
        ActionMenu m = (ActionMenu) i.next();
        Vector x = (Vector) map.get(m.name);
        if (x != null) {
            Collections.sort(x, new MenuItemActionComparator());
            JMenu menu = new JMenu(m.displayName);
            menu.setMnemonic(m.mnemonic);
            grp = null;
            for (Iterator j = x.iterator(); j.hasNext();) {
                StandardAction a = (StandardAction) j.next();
                Integer g = (Integer) a.getValue(StandardAction.MENU_ITEM_GROUP);
                if ((grp != null) && !g.equals(grp)) {
                    menu.addSeparator();
                }
                grp = g;
                if (a instanceof MenuAction) {
                    JMenu mnu = (JMenu) a.getValue(MenuAction.MENU);
                    menu.add(mnu);
                } else {
                    JMenuItem item = new JMenuItem(a);
                    menu.add(item);
                }
            }
            menuBar.add(menu);
        } else {
            log.error("Can't find menu " + m.name);
        }
    }
    menuBar.validate();
    menuBar.repaint();
}

From source file:maltcms.ui.nb.pipelineRunner.actions.RunMaltcmsPipelinesAction.java

protected static JMenu actionsToMenu(String menuName, Action[] actions, Lookup context) {
    //code from Utilities.actionsToPopup
    // keeps actions for which was menu item created already (do not add them twice)
    Set<Action> counted = new HashSet<>();
    // components to be added (separators are null)
    List<Component> components = new ArrayList<>();

    for (Action action : actions) {
        if (action != null && counted.add(action)) {
            // switch to replacement action if there is some
            if (action instanceof ContextAwareAction) {
                //               System.out.println("Context aware action");
                Action contextAwareAction = ((ContextAwareAction) action).createContextAwareInstance(context);
                if (contextAwareAction == null) {
                    Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.WARNING,
                            "ContextAwareAction.createContextAwareInstance(context) returns null. That is illegal!"
                                    + " action={0}, context={1}",
                            new Object[] { action, context });
                } else {
                    action = contextAwareAction;
                }// w  w w .jav  a2  s .  co  m
            }

            JMenuItem item;
            if (action instanceof JMenuItem || action instanceof JMenu) {
                item = (JMenuItem) action;
            } else if (action instanceof Presenter.Popup) {
                //               System.out.println("Popup menu");
                item = ((Presenter.Popup) action).getPopupPresenter();
                if (item == null) {
                    Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.WARNING,
                            "findContextMenuImpl, getPopupPresenter returning null for {0}", action);
                    continue;
                }
            } else if (action instanceof DynamicMenuContent) {
                //               System.out.println("Dynamic content menu");
                DynamicMenuContent dmc = (DynamicMenuContent) action;
                JComponent[] presenters = dmc.getMenuPresenters();
                String name = action.getValue("name").toString();
                item = new JMenuItem(name);
                for (JComponent jc : presenters) {
                    item.add(jc);
                }
            } else {
                //               System.out.println("Plain menu action");
                // We need to correctly handle mnemonics with '&' etc.
                item = ActionPresenterProvider.getDefault().createPopupPresenter(action);
            }

            for (Component c : ActionPresenterProvider.getDefault().convertComponents(item)) {
                if (c instanceof JSeparator) {
                    components.add(null);
                } else {
                    components.add(c);
                }
            }
        } else {
            components.add(null);
        }
    }

    // Now create actual menu. Strip adjacent, leading, and trailing separators.
    JMenu menu = new JMenu(menuName);
    boolean nonempty = false; // has anything been added yet?
    boolean pendingSep = false; // should there be a separator before any following item?
    for (Component c : components) {
        try {
            if (c == null) {
                pendingSep = nonempty;
            } else {
                nonempty = true;
                if (pendingSep) {
                    pendingSep = false;
                    menu.addSeparator();
                }
                menu.add(c);
            }
        } catch (RuntimeException ex) {
            Exceptions.attachMessage(ex, "Current component: " + c); // NOI18N
            Exceptions.attachMessage(ex, "List of components: " + components); // NOI18N
            Exceptions.attachMessage(ex, "List of actions: " + Arrays.asList(actions)); // NOI18N
            Exceptions.printStackTrace(ex);
        }
    }
    return menu;
}

From source file:net.sf.jabref.gui.ImportInspectionDialog.java

/**
 * Creates a dialog that displays the given list of fields in the table. The
 * dialog allows another process to add entries dynamically while the dialog
 * is shown.//from  w  w w .java2s  .c o m
 *
 * @param frame
 * @param panel
 */
public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoName, boolean newDatabase) {
    this.frame = frame;
    this.panel = panel;
    this.bibDatabaseContext = (panel == null) ? null : panel.getBibDatabaseContext();
    this.undoName = undoName;
    this.newDatabase = newDatabase;
    setIconImage(new ImageIcon(IconTheme.getIconUrl("jabrefIcon48")).getImage());
    preview = new PreviewPanel(null, bibDatabaseContext, Globals.prefs.get(JabRefPreferences.PREVIEW_0));

    duplLabel.setToolTipText(Localization.lang("Possible duplicate of existing entry. Click to resolve."));

    sortedList = new SortedList<>(entries);
    DefaultEventTableModel<BibEntry> tableModelGl = (DefaultEventTableModel<BibEntry>) GlazedListsSwing
            .eventTableModelWithThreadProxyList(sortedList, new EntryTableFormat());
    glTable = new EntryTable(tableModelGl);
    GeneralRenderer renderer = new GeneralRenderer(Color.white);
    glTable.setDefaultRenderer(JLabel.class, renderer);
    glTable.setDefaultRenderer(String.class, renderer);
    glTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), "delete");
    DeleteListener deleteListener = new DeleteListener();
    glTable.getActionMap().put("delete", deleteListener);

    selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing
            .eventSelectionModelWithThreadProxyList(sortedList);
    glTable.setSelectionModel(selectionModel);
    selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
    comparatorChooser = TableComparatorChooser.install(glTable, sortedList,
            AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
    setupComparatorChooser();
    glTable.addMouseListener(new TableClickListener());

    setWidths();

    getContentPane().setLayout(new BorderLayout());
    progressBar.setIndeterminate(true);
    JPanel centerPan = new JPanel();
    centerPan.setLayout(new BorderLayout());

    contentPane.setTopComponent(new JScrollPane(glTable));
    contentPane.setBottomComponent(preview);

    centerPan.add(contentPane, BorderLayout.CENTER);
    centerPan.add(progressBar, BorderLayout.SOUTH);

    popup.add(deleteListener);
    popup.addSeparator();
    if (!newDatabase && (bibDatabaseContext != null)) {
        GroupTreeNode node = bibDatabaseContext.getMetaData().getGroups();
        JMenu groupsAdd = new JMenu(Localization.lang("Add to group"));
        groupsAdd.setEnabled(false); // Will get enabled if there are groups that can be added to.
        insertNodes(groupsAdd, node);
        popup.add(groupsAdd);
    }

    // Add "Attach file" menu choices to right click menu:
    popup.add(new LinkLocalFile());
    popup.add(new DownloadFile());
    popup.add(new AutoSetLinks());
    popup.add(new AttachUrl());
    getContentPane().add(centerPan, BorderLayout.CENTER);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(stop);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addRelatedGap();
    JButton help = new HelpAction(HelpFile.IMPORT_INSPECTION).getHelpButton();
    bb.addButton(help);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    ButtonStackBuilder builder = new ButtonStackBuilder();
    JButton selectAll = new JButton(Localization.lang("Select all"));
    builder.addButton(selectAll);
    JButton deselectAll = new JButton(Localization.lang("Deselect all"));
    builder.addButton(deselectAll);
    builder.addButton(deselectAllDuplicates);
    builder.addRelatedGap();
    JButton delete = new JButton(Localization.lang("Delete"));
    builder.addButton(delete);
    builder.addRelatedGap();
    builder.addFixed(autoGenerate);
    builder.addButton(generate);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    centerPan.add(builder.getPanel(), BorderLayout.WEST);

    ok.setEnabled(false);
    generate.setEnabled(false);
    ok.addActionListener(new OkListener());
    cancel.addActionListener(e -> {
        signalStopFetching();
        dispose();
        frame.output(Localization.lang("Import canceled by user"));
    });
    generate.addActionListener(e -> {
        generate.setEnabled(false);
        generatedKeys = true; // To prevent the button from getting
        // enabled again.
        generateKeys(); // Generate the keys.
    });
    stop.addActionListener(e -> {
        signalStopFetching();
        entryListComplete();
    });
    selectAll.addActionListener(new SelectionButton(true));
    deselectAll.addActionListener(new SelectionButton(false));
    deselectAllDuplicates.addActionListener(e -> {
        for (int i = 0; i < glTable.getRowCount(); i++) {
            if (glTable.getValueAt(i, DUPL_COL) != null) {
                glTable.setValueAt(false, i, 0);
            }
        }
        glTable.repaint();
    });
    deselectAllDuplicates.setEnabled(false);
    delete.addActionListener(deleteListener);
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

    // Remember and default to last size:
    setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH),
            Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT)));
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            contentPane.setDividerLocation(0.5f);
        }

        @Override
        public void windowClosed(WindowEvent e) {
            Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH, getSize().width);
            Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT, getSize().height);
        }
    });
    // Key bindings:
    Action closeAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    ActionMap am = contentPane.getActionMap();
    InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", closeAction);

}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java

private JMenu createViewMenu() {
    GraphicOptions view_opt = theCanvas.getWorkspace().getGraphicOptions();

    JMenu view_menu = new JMenu("View");
    view_menu.setMnemonic(KeyEvent.VK_V);

    // zoom //  w w  w.  j a  v  a  2  s. c  om
    view_menu.add(theActionManager.get("zoomnone"));
    view_menu.add(theActionManager.get("zoomin"));
    view_menu.add(theActionManager.get("zoomout"));

    view_menu.addSeparator();

    // notation 
    JRadioButtonMenuItem last = null;
    ButtonGroup groupn = new ButtonGroup();

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_CFG)));
    last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFG));
    groupn.add(last);

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_CFGBW)));
    last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFGBW));
    groupn.add(last);

    view_menu.add(last = new JRadioButtonMenuItem(
            theActionManager.get("notation=" + GraphicOptions.NOTATION_CFGLINK)));
    last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFGLINK));
    groupn.add(last);

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_UOXF)));
    last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_UOXF));
    groupn.add(last);

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_TEXT)));
    last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_TEXT));
    groupn.add(last);

    view_menu.addSeparator();

    // display 

    display_button_group = new ButtonGroup();
    display_models = new HashMap<String, ButtonModel>();

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_COMPACT)));
    last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_COMPACT));
    display_models.put(GraphicOptions.DISPLAY_COMPACT, last.getModel());
    display_button_group.add(last);

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_NORMAL)));
    last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_NORMAL));
    display_models.put(GraphicOptions.DISPLAY_NORMAL, last.getModel());
    display_button_group.add(last);

    view_menu.add(last = new JRadioButtonMenuItem(
            theActionManager.get("display=" + GraphicOptions.DISPLAY_NORMALINFO)));
    last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_NORMALINFO));
    display_models.put(GraphicOptions.DISPLAY_NORMALINFO, last.getModel());
    display_button_group.add(last);

    view_menu.add(
            last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_CUSTOM)));
    last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_CUSTOM));
    display_models.put(GraphicOptions.DISPLAY_CUSTOM, last.getModel());
    display_button_group.add(last);

    //view_menu.add( lastcb = new JCheckBoxMenuItem(theActionManager.get("showinfo")) );
    //lastcb.setState(view_opt.SHOW_INFO);

    view_menu.addSeparator();

    // orientation

    view_menu.add(theActionManager.get("orientation"));

    view_menu.addSeparator();

    view_menu.add(theActionManager.get("displaysettings"));
    view_menu.add(theActionManager.get("reportsettings"));

    return view_menu;
}

From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java

private void addStyleMenu() {

    JRadioButtonMenuItem mnuPie = new JRadioButtonMenuItem("Pie");
    JRadioButtonMenuItem mnuPie3d = new JRadioButtonMenuItem("Pie 3D");
    JRadioButtonMenuItem mnuBar = new JRadioButtonMenuItem("Bar");
    JRadioButtonMenuItem mnuBar3d = new JRadioButtonMenuItem("Bar 3d");

    mnuPie.setActionCommand("style.Pie");
    mnuPie.addActionListener(this);
    mnuPie.setSelected(true);//from ww w.j  ava  2  s  .co m

    mnuPie3d.setActionCommand("style.Pie3d");
    mnuPie3d.addActionListener(this);

    mnuBar.setActionCommand("style.Bar");
    mnuBar.addActionListener(this);

    mnuBar3d.setActionCommand("style.Bar3d");
    mnuBar3d.addActionListener(this);

    styleGroup.add(mnuPie);
    styleGroup.add(mnuPie3d);
    styleGroup.add(mnuBar);
    styleGroup.add(mnuBar3d);

    JMenu menuStyle = new JMenu("Style");
    menuStyle.add(mnuPie);
    menuStyle.add(mnuPie3d);
    menuStyle.add(mnuBar);
    menuStyle.add(mnuBar3d);

    menu.add(menuStyle);
}

From source file:JXButtonPanel.java

public JXButtonPanelDemo() {
    super("JXButtonPanel demo");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);/*from  w ww  .  ja v  a2 s . c  o  m*/
    JPanel topPanel = new JPanel(new GridLayout(1, 0));

    final JXButtonPanel radioGroupPanel = createRadioJXButtonPanel();
    topPanel.add(radioGroupPanel);

    final JXButtonPanel checkBoxPanel = createCheckBoxJXButtonPanel();
    topPanel.add(checkBoxPanel);

    add(topPanel);
    add(createButtonJXButtonPanel(), BorderLayout.SOUTH);
    pack();

    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Options");
    JMenuItem item = new JMenuItem("Unselect radioButtons");
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // hack for 1.5 
            // in 1.6 ButtonGroup.clearSelection added
            JRadioButton b = new JRadioButton();
            radioGroup.add(b);
            b.setSelected(true);
            radioGroup.remove(b);
        }
    });
    menu.add(item);
    bar.add(menu);
    setJMenuBar(bar);

    setSize(300, 300);
    setLocationRelativeTo(null);
}

From source file:com.pianobakery.complsa.MainGui.java

public static JMenuBar MenuExp() {

    // Creates a menubar for a JFrame
    JMenuBar menuBar = new JMenuBar();

    // Add the menubar to the frame
    //setJMenuBar(menuBar);

    // Define and add two drop down menu to the menubar
    JMenu fileMenu = new JMenu("Project");
    JMenu editMenu = new JMenu("Edit");
    JMenu trainingMenu = new JMenu("Corpus");
    JMenu searchMenu = new JMenu("Search");
    JMenu viewMenu = new JMenu("View");
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(fileMenu);/*w  ww  .  jav a 2  s . c  o  m*/
    menuBar.add(editMenu);
    menuBar.add(trainingMenu);
    menuBar.add(searchMenu);

    menuBar.add(helpMenu);

    newAction.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    openAction
            .setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    exitAction
            .setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    cutAction.setAccelerator(KeyStroke.getKeyStroke('X', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    copyAction
            .setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    pasteAction
            .setAccelerator(KeyStroke.getKeyStroke('V', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    addCorpFolderAction
            .setAccelerator(KeyStroke.getKeyStroke('1', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    updateIndexAction
            .setAccelerator(KeyStroke.getKeyStroke('2', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    trainSemAction
            .setAccelerator(KeyStroke.getKeyStroke('3', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    addSearchCorpFolderAction
            .setAccelerator(KeyStroke.getKeyStroke('4', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    openReaderAction
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeReaderAction
            .setAccelerator(KeyStroke.getKeyStroke('W', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    searchAction
            .setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    fileMenu.add(newAction);
    fileMenu.add(openAction);
    fileMenu.addSeparator();
    //fileMenu.add(downloadAction);
    fileMenu.addSeparator();
    fileMenu.add(exitAction);

    editMenu.add(cutAction);
    editMenu.add(copyAction);
    editMenu.add(pasteAction);
    //editMenu.addSeparator();

    trainingMenu.add(addCorpFolderAction);
    trainingMenu.add(remCorpFolderAction);
    trainingMenu.addSeparator();
    trainingMenu.add(updateIndexAction);
    trainingMenu.add(remCorpIndexAction);
    trainingMenu.addSeparator();
    trainingMenu.add(trainSemAction);

    trainingMenu.add(addSearchCorpFolderAction);
    trainingMenu.add(remSearchCorpFolderAction);

    searchMenu.add(searchAction);
    searchMenu.add(openReaderAction);
    searchMenu.add(closeReaderAction);

    helpMenu.add(helpAction);
    helpMenu.addSeparator();
    helpMenu.add(updateAction);
    helpMenu.add(licenseAction);
    helpMenu.addSeparator();
    helpMenu.add(aboutAction);

    // Create and add CheckButton as a menu item to one of the drop down
    // menu
    //JCheckBoxMenuItem checkAction = new JCheckBoxMenuItem("Check Action");
    // Create and add Radio Buttons as simple menu items to one of the drop
    // down menu
    /*JRadioButtonMenuItem radioAction1 = new JRadioButtonMenuItem(
        "Radio Button1");
    JRadioButtonMenuItem radioAction2 = new JRadioButtonMenuItem(
        "Radio Button2");
        */
    // Create a ButtonGroup and add both radio Button to it. Only one radio
    // button in a ButtonGroup can be selected at a time.
    //ButtonGroup bg = new ButtonGroup();
    //bg.add(radioAction1);
    //bg.add(radioAction2);
    //editMenu.add(radioAction1);
    //editMenu.add(radioAction2);

    // Add a listener to the New menu item. actionPerformed() method will
    // invoked, if user triggred this menu item
    newAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            maingui.newFolderMethod();
        }
    });
    openAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            maingui.selectFolderMethod();
        }
    });
    /*downloadAction.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent arg0) {
        maingui.downloadModelMethod();
    }
    });*/
    exitAction.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.exit(0);
        }
    });

    addCorpFolderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.addTopicCorpusMethod();
        }
    });
    remCorpFolderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.removeTopicCorpusMethod();
        }
    });
    updateIndexAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.updateIndexMethod();
        }
    });
    remCorpIndexAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.removeIndexMethod();
        }
    });
    trainSemAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.trainCorpMethod();
        }
    });

    addSearchCorpFolderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.impSearchCorpMethod();
        }
    });
    remSearchCorpFolderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.removeSearchCorpMethod();
        }
    });

    searchAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.searchMethod();
        }
    });
    openReaderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.openReaderMethod();
        }
    });
    closeReaderAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.closeReaderMethod();
        }
    });

    helpAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.helpMethod();
        }
    });

    updateAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.updateMethod();
        }
    });

    licenseAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.licenseMethod();
        }
    });

    aboutAction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            maingui.aboutMethod();
        }
    });

    return menuBar;
}

From source file:net.sf.jabref.gui.RightClickMenu.java

/**
 * @param move For add: if true, remove from previous groups
 *//*  w  w  w  .j  a  v  a2s.co  m*/
private void insertNodes(JMenu menu, GroupTreeNode node, BibEntry[] selection, boolean add, boolean move) {
    final AbstractAction action = getAction(node, selection, add, move);

    if (node.getChildCount() == 0) {
        JMenuItem menuItem = new JMenuItem(action);
        setGroupFontAndIcon(menuItem, node.getGroup());
        menu.add(menuItem);
        if (action.isEnabled()) {
            menu.setEnabled(true);
        }
        return;
    }

    JMenu submenu;
    if (node.getGroup() instanceof AllEntriesGroup) {
        for (int i = 0; i < node.getChildCount(); ++i) {
            insertNodes(menu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
        }
    } else {
        submenu = new JMenu('[' + node.getGroup().getName() + ']');
        setGroupFontAndIcon(submenu, node.getGroup());
        // setEnabled(true) is done above/below if at least one menu
        // entry (item or submenu) is enabled
        submenu.setEnabled(action.isEnabled());
        JMenuItem menuItem = new JMenuItem(action);
        setGroupFontAndIcon(menuItem, node.getGroup());
        submenu.add(menuItem);
        submenu.add(new Separator());
        for (int i = 0; i < node.getChildCount(); ++i) {
            insertNodes(submenu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
        }
        menu.add(submenu);
        if (submenu.isEnabled()) {
            menu.setEnabled(true);
        }
    }
}