Search in sources :

Example 71 with JMenuItem

use of javax.swing.JMenuItem in project jabref by JabRef.

the class BasicAction method initPopupMenuAndToolbar.

private void initPopupMenuAndToolbar() {
    // copy/paste Menu
    PasteAction pasteAction = new PasteAction();
    ClearAction clearAction = new ClearAction();
    JMenuItem pasteMI = new JMenuItem(pasteAction);
    inputMenu.add(clearAction);
    inputMenu.addSeparator();
    inputMenu.add(pasteMI);
    inputMenu.addSeparator();
    // Right-click append/override
    JMenu appendMenu = new JMenu(Localization.lang("Append"));
    appendMenu.setToolTipText(Localization.lang("Append the selected text to BibTeX field"));
    JMenu overrideMenu = new JMenu(Localization.lang("Override"));
    overrideMenu.setToolTipText(Localization.lang("Override the BibTeX field by the selected text"));
    for (String field : allFields) {
        appendMenu.add(new JMenuItem(new MenuTextForTagAction(field, false)));
        overrideMenu.add(new JMenuItem(new MenuTextForTagAction(field, true)));
    }
    inputMenu.add(appendMenu);
    inputMenu.add(overrideMenu);
    // Toolbar
    toolBar.add(clearAction);
    toolBar.setBorderPainted(false);
    toolBar.addSeparator();
    toolBar.add(pasteAction);
    toolBar.add(new LoadAction());
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 72 with JMenuItem

use of javax.swing.JMenuItem in project JMRI by JMRI.

the class PowerManagerMenu method getManager.

public PowerManager getManager() {
    // start with default
    PowerManager manager = InstanceManager.getNullableDefault(jmri.PowerManager.class);
    if (manager == null) {
        return null;
    }
    String name = manager.getUserName();
    // find active name
    for (JMenuItem item : items) {
        if (item.isSelected()) {
            name = item.getActionCommand();
            break;
        }
    }
    // find PowerManager and return
    List<PowerManager> managers = InstanceManager.getList(PowerManager.class);
    for (PowerManager mgr : managers) {
        if (name.equals(mgr.getUserName())) {
            return mgr;
        }
    }
    // should not happen
    return null;
}
Also used : PowerManager(jmri.PowerManager) JMenuItem(javax.swing.JMenuItem)

Example 73 with JMenuItem

use of javax.swing.JMenuItem in project JMRI by JMRI.

the class JMenuUtil method jMenuFromElement.

@Nonnull
static JMenu jMenuFromElement(@CheckForNull Element main, WindowInterface wi, Object context) {
    boolean addSep = false;
    String name = "<none>";
    if (main == null) {
        log.warn("Menu from element called without an element");
        return new JMenu(name);
    }
    name = LocaleSelector.getAttribute(main, "name");
    //Next statement left in if the xml file hasn't been converted
    if ((name == null) || (name.equals(""))) {
        if (main.getChild("name") != null) {
            name = main.getChild("name").getText();
        }
    }
    JMenu menu = new JMenu(name);
    ArrayList<Integer> mnemonicList = new ArrayList<Integer>();
    for (Object item : main.getChildren("node")) {
        JMenuItem menuItem = null;
        Element child = (Element) item;
        if (child.getChildren("node").size() == 0) {
            // leaf
            if ((child.getText().trim()).equals("separator")) {
                addSep = true;
            } else {
                if (!(SystemType.isMacOSX() && UIManager.getLookAndFeel().isNativeLookAndFeel() && ((child.getChild("adapter") != null && child.getChild("adapter").getText().equals("apps.gui3.TabbedPreferencesAction")) || (child.getChild("current") != null && child.getChild("current").getText().equals("quit"))))) {
                    if (addSep) {
                        menu.addSeparator();
                        addSep = false;
                    }
                    Action act = actionFromNode(child, wi, context);
                    menu.add(menuItem = new JMenuItem(act));
                }
            }
        } else {
            if (addSep) {
                menu.addSeparator();
                addSep = false;
            }
            if (child.getChild("group") != null && child.getChild("group").getText().equals("yes")) {
                //A seperate method is required for creating radio button groups
                menu.add(createMenuGroupFromElement(child, wi, context));
            } else {
                // not leaf
                menu.add(menuItem = jMenuFromElement(child, wi, context));
            }
        }
        if (menuItem != null && child.getChild("current") != null) {
            setMenuItemInterAction(context, child.getChild("current").getText(), menuItem);
        }
        if (menuItem != null && child.getChild("mnemonic") != null) {
            int mnemonic = convertStringToKeyEvent(child.getChild("mnemonic").getText());
            if (mnemonicList.contains(mnemonic)) {
                log.error("Menu Item '" + menuItem.getText() + "' Mnemonic '" + child.getChild("mnemonic").getText() + "' has already been assigned");
            } else {
                menuItem.setMnemonic(mnemonic);
                mnemonicList.add(mnemonic);
            }
        }
    }
    return menu;
}
Also used : Action(javax.swing.Action) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Nonnull(javax.annotation.Nonnull)

Example 74 with JMenuItem

use of javax.swing.JMenuItem in project jabref by JabRef.

the class ChangeEntryTypeMenu method createEntryTypeSection.

private void createEntryTypeSection(BasePanel panel, JMenu menu, String title, List<? extends EntryType> types) {
    // bibtex
    JMenuItem header = new JMenuItem(title);
    Font font = new Font(menu.getFont().getName(), Font.ITALIC, menu.getFont().getSize());
    header.setFont(font);
    header.setEnabled(false);
    if (!types.isEmpty()) {
        menu.add(header);
    }
    for (EntryType type : types) {
        menu.add(new ChangeTypeAction(type, panel));
    }
}
Also used : EntryType(org.jabref.model.entry.EntryType) ChangeTypeAction(org.jabref.gui.actions.ChangeTypeAction) JMenuItem(javax.swing.JMenuItem) Font(java.awt.Font)

Example 75 with JMenuItem

use of javax.swing.JMenuItem in project jabref by JabRef.

the class FileHistoryMenu method addItem.

private void addItem(String filename, int num) {
    String number = Integer.toString(num);
    JMenuItem item = new JMenuItem(number + ". " + filename);
    char mnemonic = Character.toUpperCase(number.charAt(0));
    item.setMnemonic((int) mnemonic);
    item.addActionListener(this);
    add(item);
//history.addFirst(item);
}
Also used : JMenuItem(javax.swing.JMenuItem)

Aggregations

JMenuItem (javax.swing.JMenuItem)1130 ActionEvent (java.awt.event.ActionEvent)559 ActionListener (java.awt.event.ActionListener)464 JMenu (javax.swing.JMenu)369 JPopupMenu (javax.swing.JPopupMenu)225 JMenuBar (javax.swing.JMenuBar)103 AbstractAction (javax.swing.AbstractAction)90 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)76 ArrayList (java.util.ArrayList)71 JPanel (javax.swing.JPanel)70 Point (java.awt.Point)65 JSeparator (javax.swing.JSeparator)63 File (java.io.File)61 JLabel (javax.swing.JLabel)61 BorderLayout (java.awt.BorderLayout)57 JButton (javax.swing.JButton)54 Component (java.awt.Component)53 ButtonGroup (javax.swing.ButtonGroup)50 Dimension (java.awt.Dimension)46 MouseEvent (java.awt.event.MouseEvent)45