Example usage for javax.swing JMenuItem getText

List of usage examples for javax.swing JMenuItem getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the button's text.

Usage

From source file:org.tros.logo.swing.LogoMenuBar.java

/**
 * Set up the menus for examples./* w  w  w . j  a  v  a 2  s  .c om*/
 *
 * @param name
 * @param base
 * @return
 */
private JMenu setupMenu(String name, String base) {
    JMenu samplesMenu = new JMenu(name);
    try {
        InputStream resourceAsStream = TorgoToolkit.getDefaultResourceAccessor()
                .open(base + "/resource.manifest");
        List<String> readLines = IOUtils.readLines(resourceAsStream, "utf-8");
        Collections.sort(readLines);
        for (String line : readLines) {
            JMenuItem jmi = new JMenuItem(base + "/" + line);
            if (!jmi.getText().endsWith("manifest")) {
                samplesMenu.add(jmi);
                jmi.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String val = e.getActionCommand();
                        URL resource = ClassLoader.getSystemClassLoader().getResource(val);
                        LogoMenuBar.this.controller.openFile(resource);
                    }
                });
            }
        }
    } catch (IOException ex) {
        org.tros.utils.logging.Logging.getLogFactory().getLogger(LogoMenuBar.class).fatal(null, ex);
    }
    return samplesMenu;
}

From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java

private void initAllMenuItems(JMenu menu) {
    for (Component c : menu.getMenuComponents()) {
        if (c instanceof ZapMenuItem) {
            this.registerMenuItem((ZapMenuItem) c);

        } else if (c instanceof JMenu) {
            initAllMenuItems((JMenu) c);

        } else if (c instanceof JMenuItem) {
            JMenuItem menuItem = (JMenuItem) c;
            logger.debug("Unable to set accelerators on menu " + menuItem.getText());
        }/*from   w ww.  j a v a  2s  .  c  o  m*/
    }
}

From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java

private void addAllMenuItems(List<KeyboardShortcut> kss, JMenu menu, boolean reset) {
    for (Component c : menu.getMenuComponents()) {
        if (c instanceof ZapMenuItem) {
            kss.add(menuToShortcut((ZapMenuItem) c, reset));

        } else if (c instanceof JMenu) {
            addAllMenuItems(kss, (JMenu) c, reset);

        } else if (c instanceof JMenuItem) {
            JMenuItem menuItem = (JMenuItem) c;
            logger.debug("Unable to set accelerators on menu " + menuItem.getText());

        }//from  w w  w .  java2  s.  c om
    }
}

From source file:processing.app.Editor.java

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

    addInternalTools(toolsMenu);//w w  w. j  a  v a2s. 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;
}