Java Code Examples for javax.swing.JMenuItem#setName()

The following examples show how to use javax.swing.JMenuItem#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TabbedPane.java    From javamelody with Apache License 2.0 6 votes vote down vote up
@Override
protected JPopupMenu createPopupMenu() {
	final JPopupMenu menu = super.createPopupMenu();
	final CloseMenuSelectionHandler closeMenuSelectionHandler = new CloseMenuSelectionHandler();
	final JMenuItem closeMenuItem = new JMenuItem(I18N.getString("Fermer"));
	final JMenuItem closeOthersMenuItem = new JMenuItem(I18N.getString("Fermer_les_autres"));
	final JMenuItem closeAllMenuItem = new JMenuItem(I18N.getString("Fermer_tout"));
	closeMenuItem.setName(CLOSE);
	closeOthersMenuItem.setName(CLOSE_OTHERS);
	closeAllMenuItem.setName(CLOSE_ALL);
	closeMenuItem.addActionListener(closeMenuSelectionHandler);
	closeOthersMenuItem.addActionListener(closeMenuSelectionHandler);
	closeAllMenuItem.addActionListener(closeMenuSelectionHandler);
	menu.add(new JSeparator(), 0);
	menu.add(closeAllMenuItem, 0);
	menu.add(closeOthersMenuItem, 0);
	menu.add(closeMenuItem, 0);
	if (getTabComponentAt(getSelectedIndex()) == null) {
		closeMenuItem.setEnabled(false);
	}

	return menu;
}
 
Example 2
Source File: JSONTree.java    From rest-client with Apache License 2.0 6 votes vote down vote up
/**
* 
* @Title      : initPopupMenu 
* @Description: PopupMenu Initialization 
* @Param      :  
* @Return     : void
* @Throws     :
 */
public void initPopupMenu()
{
    pm = new JPopupMenu();

    miExpand = new JMenuItem(RESTConst.EXPAND_ALL);
    miExpand.setName(RESTConst.EXPAND_ALL);
    miExpand.addActionListener(this);

    miCollapse = new JMenuItem(RESTConst.COLLAPSE_ALL);
    miCollapse.setName(RESTConst.COLLAPSE_ALL);
    miCollapse.addActionListener(this);

    pm.add(miExpand);
    pm.addSeparator();
    pm.add(miCollapse);
}
 
Example 3
Source File: BasePluginManager.java    From yeti with MIT License 6 votes vote down vote up
public ArrayList<JMenuItem> getPlugins() {
    ArrayList<JMenuItem> result = new ArrayList<>();

    for (String filename : UtilFunctions.filesFromDir(scriptLocation)) {
        JMenuItem miPlugin = new JMenuItem();
        miPlugin.setText(filename);
        miPlugin.setName(filename);
        miPlugin.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pluginMenuEvent(evt);
            }
        });
        result.add(miPlugin);
    }
    return result;
}
 
Example 4
Source File: SettingsPage.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
private void showMoveQPopup(JButton btn) {
	int index = qList.getSelectedIndex();
	if (index < 0) {
		return;
	}
	DownloadQueue q = queueModel.get(index);
	String qid = q.getQueueId();
	if (qid == null)
		return;
	JPopupMenu popupMenu = new JPopupMenu();
	for (int i = 0; i < QueueManager.getInstance().getQueueList().size(); i++) {
		DownloadQueue tq = QueueManager.getInstance().getQueueList().get(i);
		if (qid.equals(tq.getQueueId())) {
			continue;
		}
		JMenuItem item = new JMenuItem(tq.getName());
		item.setName("Q_MOVE_TO:" + tq.getQueueId());
		item.addActionListener(this);
		item.setForeground(Color.WHITE);
		item.setFont(FontResource.getNormalFont());
		popupMenu.add(item);
	}
	popupMenu.setInvoker(btn);
	popupMenu.show(btn, 0, btn.getHeight());
}
 
Example 5
Source File: VideoDownloadWindow.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
private void createPopup() {
	pop = new JPopupMenu();
	pop.setBackground(ColorResource.getDarkerBgColor());
	JMenu dl = new JMenu(StringResource.get("ND_DOWNLOAD_LATER"));
	dl.setForeground(Color.WHITE);
	dl.setBorder(new EmptyBorder(getScaledInt(5), getScaledInt(5), getScaledInt(5), getScaledInt(5)));
	dl.addActionListener(this);
	dl.setBackground(ColorResource.getDarkerBgColor());
	dl.setBorderPainted(false);
	// dl.setBackground(C);
	pop.add(dl);

	createQueueItems(dl);

	JMenuItem ig = new JMenuItem(StringResource.get("ND_IGNORE_URL"));
	ig.setName("IGNORE_URL");
	ig.setForeground(Color.WHITE);
	ig.addActionListener(this);
	pop.add(ig);
	pop.setInvoker(btnMore);
}
 
Example 6
Source File: CMSSTopMenu.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private JMenuItem getMenuExample() {

        menuExample = new JMenuItem();
        menuExample.setName("Fingerprinting tools");
        menuExample.setText("Fingerprinting tools");

        menuExample.addActionListener(
                new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        // This is where you do what you want to do.
                        // In this case we'll just show a popup message.
                        CMSSThread cmssThread = new CMSSThread();
                        cmssThread.start();
                    }
                });

        return menuExample;
    }
 
Example 7
Source File: MTabbedPane.java    From javamelody with Apache License 2.0 6 votes vote down vote up
protected JPopupMenu createPopupMenu() {
	final JPopupMenu menu = new JPopupMenu();
	final MenuSelectionHandler menuSelectionHandler = new MenuSelectionHandler();
	final int tabCount = getTabCount();
	final int selectedIndex = getSelectedIndex();
	for (int i = 0; i < tabCount; i++) {
		final JMenuItem menuItem = new JMenuItem(getTitleAt(i), getIconAt(i));
		if (i == selectedIndex) {
			menuItem.setFont(menuItem.getFont().deriveFont(Font.BOLD));
		}
		if (!isEnabledAt(i)) {
			menuItem.setEnabled(false);
		}
		menuItem.setName(String.valueOf(i));
		menuItem.addActionListener(menuSelectionHandler);
		menu.add(menuItem);
	}
	return menu;
}
 
Example 8
Source File: NewDownloadWindow.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
private void createPopup() {
	pop = new JPopupMenu();
	pop.setBackground(ColorResource.getDarkerBgColor());
	JMenu dl = new JMenu(StringResource.get("ND_DOWNLOAD_LATER"));
	dl.setForeground(Color.WHITE);
	dl.setBorder(new EmptyBorder(getScaledInt(5), getScaledInt(5), getScaledInt(5), getScaledInt(5)));
	dl.addActionListener(this);
	dl.setBackground(ColorResource.getDarkerBgColor());
	dl.setBorderPainted(false);
	// dl.setBackground(C);
	pop.add(dl);

	createQueueItems(dl);

	JMenuItem ig = new JMenuItem(StringResource.get("ND_IGNORE_URL"));
	ig.setName("IGNORE_URL");
	ig.setForeground(Color.WHITE);
	ig.addActionListener(this);
	pop.add(ig);
	pop.setInvoker(btnMore);
}
 
Example 9
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
//        System.err.println("  item text is " + item.getText());
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
//        System.err.println("action " + action + (enabled ? " enabled" : " disabled"));
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
//        System.err.println("action " + action + (visible ? " visible" : " invisible"));
        item.setVisible(visible);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example 10
Source File: AbstractContextMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        //Intentionally use enabled property
        item.setVisible(enabled);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example 11
Source File: LangSelector.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MouseListener createPopupListener (String lang)
{
    // Create a very simple popup menu.
    final JPopupMenu popup = new JPopupMenu();
    final JMenuItem  menuItem = new JMenuItem("Remove " + lang);
    menuItem.setName(lang);
    menuItem.addActionListener(this);
    popup.add(menuItem);

    return new PopupListener(popup);
}
 
Example 12
Source File: RspTextPanel.java    From rest-client with Apache License 2.0 5 votes vote down vote up
/**
* 
* @Title: init 
* @Description: Component Initialization 
* @param
* @return void 
* @throws
 */
private void init(String name)
{
    this.setLayout(new BorderLayout(RESTConst.BORDER_WIDTH, 0));

    txtAra = new JTextArea(RESTConst.AREA_ROWS, 1);
    txtAra.setName(name);
    txtAra.setEditable(false);
    txtAra.addMouseListener(ma);

    miFmt = new JMenuItem(RESTConst.FORMAT);
    miFmt.setName(RESTConst.FORMAT);
    miFmt.addActionListener(this);

    miCpy = new JMenuItem(RESTConst.COPY);
    miCpy.setName(RESTConst.COPY);
    miCpy.addActionListener(this);

    pm = new JPopupMenu();
    pm.add(miCpy);
    pm.addSeparator();
    pm.add(miFmt);

    JPanel pnlCenter = new JPanel();
    pnlCenter.setLayout(new BorderLayout());
    JScrollPane sp = new JScrollPane(txtAra);
    pnlCenter.add(sp);

    this.add(pnlCenter, BorderLayout.CENTER);
}
 
Example 13
Source File: SwingSet3.java    From littleluck with Apache License 2.0 5 votes vote down vote up
protected JMenuBar createMenuBar() {

    JMenuBar menubar = new JMenuBar();
    menubar.setName("menubar");
    
    // File menu
    JMenu fileMenu = new JMenu();
    fileMenu.setName("file");
    menubar.add(fileMenu);
    
    // File -> Quit
    if (!runningOnMac()) {
        JMenuItem quitItem = new LuckMenuItem();
        quitItem.setOpaque(true);
        quitItem.setName("quit");
        quitItem.setAction(getAction("quit"));
        fileMenu.add(quitItem);
    }
   
    // View menu
    JMenu viewMenu = new JMenu();
    viewMenu.setName("view");
    // View -> Look and Feel       
    viewMenu.add(createLookAndFeelMenu());
    // View -> Source Code Visible
    sourceCodeCheckboxItem = new LuckCheckBoxMenuItem();
    sourceCodeCheckboxItem.setSelected(isSourceCodeVisible());
    sourceCodeCheckboxItem.setName("sourceCodeCheckboxItem");
    sourceCodeCheckboxItem.addChangeListener(new SourceVisibilityChangeListener());
    viewMenu.add(sourceCodeCheckboxItem);
    menubar.add(viewMenu);

    return menubar;
}
 
Example 14
Source File: DiagramaEap.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populeComandos(JMenuItem menu) {
    super.populeComandos(menu);
    menu.removeAll();
    menu.setEnabled(true);
    String tmp = Editor.fromConfiguracao.getValor("Controler.interface.Diagrama.Command.Eap.Cli.descricao");
    Diagrama.AcaoDiagrama ac = new Diagrama.AcaoDiagrama(this, tmp, "Controler.interface.Diagrama.Command.Eap.Cli.img", tmp, COMM_CLI);
    ac.normal = false;
    JMenuItem mi = new JMenuItem(ac);
    mi.setName(tmp);
    menu.add(mi);
}
 
Example 15
Source File: NewDownloadWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void createQueueItems(JMenuItem queueMenuItem) {
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		JMenuItem mItem = new JMenuItem(q.getName().length() < 1 ? "Default queue" : q.getName());
		mItem.setName("QUEUE:" + q.getQueueId());
		mItem.setForeground(Color.WHITE);
		mItem.addActionListener(this);
		queueMenuItem.add(mItem);
	}
}
 
Example 16
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void loadStopQueueMenu(JMenu menu) {
	menu.removeAll();
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		if (q.isRunning()) {
			JMenuItem mitem = new JMenuItem(q.getName());
			mitem.setForeground(ColorResource.getLightFontColor());
			mitem.setName("STOP:" + q.getQueueId());
			mitem.addActionListener(this);
			menu.add(mitem);
		}
	}
}
 
Example 17
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void addMenuItem(String id, JComponent menu) {
	JMenuItem mitem = new JMenuItem(StringResource.get(id));
	// mitem.setForeground(ColorResource.getLightFontColor());
	mitem.setName(id);
	mitem.setFont(FontResource.getNormalFont());
	mitem.addActionListener(this);
	menu.add(mitem);
}
 
Example 18
Source File: VideoDownloadWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void createQueueItems(JMenuItem queueMenuItem) {
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		JMenuItem mItem = new JMenuItem(q.getName().length() < 1 ? "Default queue" : q.getName());
		mItem.setName("QUEUE:" + q.getQueueId());
		mItem.setForeground(Color.WHITE);
		mItem.addActionListener(this);
		queueMenuItem.add(mItem);
	}
}
 
Example 19
Source File: ActionManager.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void registerDomainActions (String domain,
                                    JMenu menu)
{
    // Create all type sections for this menu
    for (int section : Actions.getSections()) {
        logger.debug("Starting section: {}", section);

        // Use a separator between sections
        menu.addSeparator();

        for (ActionDescriptor desc : Actions.getAllDescriptors()) {
            if (desc.domain.equalsIgnoreCase(domain) && (desc.section == section)) {
                // Skip advanced topics, unless explicitly set
                if ((desc.topic != null) && !desc.topic.isSet()) {
                    continue;
                }

                logger.debug("Registering {}", desc);

                try {
                    // Allocate menu item of proper class
                    final Class<? extends JMenuItem> itemClass;

                    if (desc.itemClassName != null) {
                        itemClass = (Class<? extends JMenuItem>) classLoader.loadClass(
                                desc.itemClassName);
                    } else if (desc.menuName != null) {
                        itemClass = JMenu.class;
                    } else {
                        itemClass = JMenuItem.class;
                    }

                    JMenuItem item = itemClass.newInstance();

                    // Inject menu item information
                    if (desc.methodName != null) {
                        item.setText(desc.methodName); // As default

                        ApplicationAction action = registerAction(desc);

                        if (action != null) {
                            action.setSelected(action.isSelected());
                            item.setAction(action);
                            menu.add(item);
                        } else {
                            logger.warn("Could not register {}", desc);
                        }
                    } else if (desc.menuName != null) {
                        item.setText(desc.menuName); // As default
                        item.setName(desc.menuName);
                        menu.add(item);
                    }
                } catch (ClassNotFoundException |
                         IllegalAccessException |
                         InstantiationException ex) {
                    logger.warn("Error with " + desc.itemClassName, ex);
                }
            }
        }
    }
}
 
Example 20
Source File: HistView.java    From rest-client with Apache License 2.0 4 votes vote down vote up
/**
* 
* @Title: init 
* @Description: Component Initialization 
* @param  name
* @return void 
* @throws
 */
private void init()
{
    this.setLayout(new BorderLayout(RESTConst.BORDER_WIDTH, RESTConst.BORDER_WIDTH));
    this.setBorder(BorderFactory.createEmptyBorder(RESTConst.BORDER_WIDTH, RESTConst.BORDER_WIDTH, RESTConst.BORDER_WIDTH, RESTConst.BORDER_WIDTH));

    List<String> colNames = new ArrayList<String>();
    colNames.add(RESTConst.ID);
    colNames.add(RESTConst.REQUEST);
    colNames.add(RESTConst.RESPONSE);
    colNames.add(RESTConst.DATE);
    colNames.add(RESTConst.TIME);
    colNames.add(RESTConst.DESCR);

    tabMdl = new TabModel(colNames);
    tabMdl.setCellEditable(false);
    tab = new JTable(tabMdl);
    tab.setFillsViewportHeight(true);
    tab.setAutoCreateRowSorter(false);
    tab.getTableHeader().setReorderingAllowed(false);
    tab.addMouseListener(ma);
    tab.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tab.getSelectionModel().addListSelectionListener(this);
    UIUtil.setHistTabWidth(tab);

    miRmSel = new JMenuItem(RESTConst.RM_SEL);
    miRmSel.setName(RESTConst.RM_SEL);
    miRmSel.addActionListener(this);

    miRmAll = new JMenuItem(RESTConst.RM_ALL);
    miRmAll.setName(RESTConst.RM_ALL);
    miRmAll.addActionListener(this);

    miMvUp = new JMenuItem(RESTConst.MOVE_UP);
    miMvUp.setName(RESTConst.MOVE_UP);
    miMvUp.addActionListener(this);

    miMvDown = new JMenuItem(RESTConst.MOVE_DOWN);
    miMvDown.setName(RESTConst.MOVE_DOWN);
    miMvDown.addActionListener(this);

    miEdit = new JMenuItem(RESTConst.EDIT);
    miEdit.setName(RESTConst.EDIT);
    miEdit.addActionListener(this);

    miRefresh = new JMenuItem(RESTConst.REFRESH);
    miRefresh.setName(RESTConst.REFRESH);
    miRefresh.addActionListener(this);

    histFrame = new HistFrame();
    
    pm = new JPopupMenu();
    pm.add(miRefresh);
    pm.add(miEdit);
    pm.addSeparator();
    pm.add(miMvUp);
    pm.add(miMvDown);
    pm.addSeparator();
    pm.add(miRmSel);
    pm.add(miRmAll);

    JPanel pnlCenter = new JPanel();
    pnlCenter.setLayout(new GridLayout(1, 1));
    JScrollPane sp = new JScrollPane(tab);
    pnlCenter.add(sp);

    this.add(pnlCenter, BorderLayout.CENTER);
    this.setBorder(BorderFactory.createTitledBorder(null, RESTConst.HTTP_HISTORY, TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));
}