Java Code Examples for javax.swing.JMenuItem

The following are top voted examples for showing how to use javax.swing.JMenuItem. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: JPopupMenuEndlessLoopTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {

        JPopupMenu popup = new JPopupMenu("Popup Menu");
        JMenu menu = new JMenu("Menu");
        menu.add(new JMenuItem("Menu Item"));
        popup.add(menu);
        menu.doClick();
        MenuElement[] elems = MenuSelectionManager
                .defaultManager().getSelectedPath();

        if (elems == null || elems.length == 0) {
            throw new RuntimeException("Empty Selection");
        }

        if (elems[0] != popup || elems[1] != menu) {
            throw new RuntimeException("Necessary menus are not selected!");
        }
    });
}
 
Example 2
Project: geomapapp   File: MapLocations.java   View source code 6 votes vote down vote up
void initMenu() {
	addLoc = new JMenuItem("Add Place");
	menu.add( addLoc );
	addLoc.addActionListener( this );
	loadLoc = new JMenuItem("Load Places");
	menu.add( loadLoc );
	loadLoc.addActionListener( this );
	editLoc = new JMenuItem("Edit Places");
	menu.add( editLoc );
	editLoc.addActionListener( this );
	editLoc.setEnabled(false);
	showLoc = new JCheckBoxMenuItem("Show Places", false);
	menu.add( showLoc );
	showLoc.addActionListener( this );
//	showLoc.setEnabled(false);
	menu.addSeparator();
	list = new JCheckBox("add to list", true);
	save = new JCheckBox("save to file", false);
	newSave = new JCheckBox("save to new file", false);
	addPresetLocations();
//	addMyLocations();
}
 
Example 3
Project: javaportfolio   File: PortfolioGuiApp.java   View source code 6 votes vote down vote up
/**
 * Handle menu command.
 * 
 * @param item
 *            the item
 */
public void handleMenuCommand(JMenuItem item) {
	if (item.getText().equals(MenuCreator.MENU_ITEM_NEW_PORTFOLIO)) {
		handleNewPortfolio();
	} else if (item.getText().equals(MenuCreator.MENU_ITEM_OPEN_PORTFOLIO)) {
		handleOpenPortfolio();
	} else if (item.getText()
			.equals(MenuCreator.MENU_ITEM_IMPORT_PORTFOLIO)) {
		handleImportPortfolio();
	} else if (item.getText().equals(MenuCreator.MENU_ITEM_QUIT)) {
		System.exit(0);
	} else if (item.getText().equals(MenuCreator.MENU_ITEM_UPDATE_OMX_HEX)) {
		updateQuotes();
	} else if (item.getText().equals(MenuCreator.MENU_ITEM_ABOUT)) {
		handleAbout();
	} else {
		if (portfolioDocument != null) {
			portfolioDocument.handleMenuCommand(item);
		}
	}
}
 
Example 4
Project: incubator-netbeans   File: SchedulingPickerImpl.java   View source code 6 votes vote down vote up
private void showSchedulingPopup () {
    final DashboardUtils.SchedulingMenu menu = new DashboardUtils.SchedulingMenu(currentValue);
    menu.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged (ChangeEvent e) {
            updateCurrentValue(menu.getScheduleInfo());
            menu.removeChangeListener(this);
        }
    });
    JPopupMenu popup = new JPopupMenu();
    for (JMenuItem item : menu.getMenuItems()) {
        if (item == null) {
            popup.addSeparator();
        } else {
            popup.add(item);
        }
    }
    Point p = scheduleTextComponent.getLocation();
    popup.show(scheduleTextComponent.getParent(), p.x, p.y + scheduleTextComponent.getSize().height + 1);
}
 
Example 5
Project: incubator-netbeans   File: BindAction.java   View source code 6 votes vote down vote up
private void createBindingsSubmenu(JMenu menu) {
    if (menu.getMenuComponentCount() > 0)
        menu.removeAll();

    Node[] nodes = getActivatedNodes();
    if (nodes.length != 1)
        return;

    RADComponentCookie radCookie = nodes[0].getCookie(RADComponentCookie.class);
    if (radCookie == null)
        return;

    BindingProperty[][] bindingProps = radCookie.getRADComponent().getBindingProperties();
    BindingProperty[] props = bindingProps[(bindingProps[0].length==0) ? 1 : 0];
    if (props.length > 0) {
        for (BindingProperty prop : props) {
            BindingMenuItem mi = new BindingMenuItem(prop);
            mi.addActionListener(mi);
            menu.add(mi);
        }
    } else {
        JMenuItem item = new JMenuItem(NbBundle.getMessage(BindAction.class, "MSG_NoBinding")); // NOI18N
        item.setEnabled(false);
        menu.add(item);
    }
}
 
Example 6
Project: DeutschSim   File: GUI.java   View source code 6 votes vote down vote up
private void add_item_new(final JMenu file_menu) {
	JMenuItem item_new = new JMenuItem(new AbstractAction("New") {
		private static final long serialVersionUID = 3699016056959009199L;

		@Override
		public void actionPerformed(ActionEvent arg0) {
			frame.getContentPane().removeAll();
			setup();
			// TODO add restoration of JSplitPanes' panels' sizes
			frame.validate();
			set_current_file(null);
		}
	});
	item_new.setAccelerator(KeyStroke.getKeyStroke('N', menu_mask));
	file_menu.add(item_new);
}
 
Example 7
Project: incubator-netbeans   File: DropTargetLayer.java   View source code 6 votes vote down vote up
private static int getIconLeft(JMenuItem item) {
    if(Utilities.isWindows()) {
        if(isVista()) {
            return 1;
        }
        if(hasRadioOrCheckSibling(item)) {
            return 20;
        } else {
            return 20;
        }
    }
    
    if(isAqua()) {
        if(item instanceof JRadioButtonMenuItem) {
            return 11;
        }
        return 14;
    }
    
    //metal or other (hopefully) basic derived L&Fs
    if(isRadioOrCheck(item)) {
        return 20;
    }
    return 10;
}
 
Example 8
Project: incubator-netbeans   File: InfoPanel.java   View source code 6 votes vote down vote up
private JButton createArrowButton() {
    arrowMenu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
        ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/unvisited_bpkt_arrow_small_16.png", false), arrowMenu);
    button.setPreferredSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setMaximumSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setFocusable(false);
    button.setOpaque(false);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (arrowMenu.getComponentCount() > 0) {
                Object item = arrowMenu.getComponent(0);
                for (Map.Entry<DVThread, JMenuItem> entry : threadToMenuItem.entrySet()) {
                    if (entry.getValue() == item) {
                        debuggingView.makeThreadCurrent(entry.getKey());
                    } // if
                } // for
            } // if
        } // actionPerformed
    });
    return button;
}
 
Example 9
Project: Luyten4Forge   File: FileSaver.java   View source code 6 votes vote down vote up
public FileSaver(JProgressBar bar, JLabel label) {
	this.bar = bar;
	this.label = label;
	final JPopupMenu menu = new JPopupMenu("Cancel");
	final JMenuItem item = new JMenuItem("Cancel");
	item.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setCancel(true);
		}
	});
	menu.add(item);
	this.label.addMouseListener(new MouseAdapter() {
		public void mouseClicked(MouseEvent ev) {
			if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
				menu.show(ev.getComponent(), ev.getX(), ev.getY());
		}
	});
}
 
Example 10
Project: s-store   File: DatabaseManagerSwing.java   View source code 6 votes vote down vote up
private void addToRecent(String s) {

        for (int i = 0; i < iMaxRecent; i++) {
            if (s.equals(sRecent[i])) {
                return;
            }
        }

        if (sRecent[iRecent] != null) {
            mRecent.remove(iRecent);
        }

        sRecent[iRecent] = s;

        if (s.length() > 43) {
            s = s.substring(0, 40) + "...";
        }

        JMenuItem item = new JMenuItem(s);

        item.setActionCommand("#" + iRecent);
        item.addActionListener(this);
        mRecent.insert(item, iRecent);

        iRecent = (iRecent + 1) % iMaxRecent;
    }
 
Example 11
Project: incubator-netbeans   File: Actions.java   View source code 6 votes vote down vote up
/** @param changedProperty the name of property that has changed
* or null if it is not known
*/
@Override
public void updateState(String changedProperty) {
    super.updateState(changedProperty);

    if ((changedProperty == null) || !changedProperty.equals(Action.ACCELERATOR_KEY)) {
        updateKey((JMenuItem) comp, action);
    }

    if ((changedProperty == null) || changedProperty.equals(Action.NAME)) {
        Object s = action.getValue(Action.NAME);

        if (s instanceof String) {
            setMenuText(((JMenuItem) comp), (String) s, true);
        }
    }
}
 
Example 12
Project: incubator-netbeans   File: ActionFactory.java   View source code 6 votes vote down vote up
public JMenuItem getPopupMenuItem(JTextComponent target) {
    
    item = new JCheckBoxMenuItem(NbBundle.getBundle(BaseKit.class).
            getString("line-numbers-menuitem"), isLineNumbersVisible());
    item.addItemListener( new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            actionPerformed(null,null);
        }
    });
    return item;
}
 
Example 13
Project: rapidminer   File: DockableResultDisplay.java   View source code 6 votes vote down vote up
public DockableResultDisplay() {
	this.dockKey.setDockGroup(MainFrame.DOCK_GROUP_RESULTS);
	DockableActionCustomizer customizer = new DockableActionCustomizer() {

		@Override
		public void visitTabSelectorPopUp(JPopupMenu popUpMenu, Dockable dockable) {
			popUpMenu.add(new JMenuItem(new CloseAllResultsAction(RapidMinerGUI.getMainFrame())));
		}
	};
	customizer.setTabSelectorPopUpCustomizer(true); // enable tabbed dock custom popup menu
													 // entries
	this.dockKey.setActionCustomizer(customizer);
	setLayout(new BorderLayout());
	ExtendedJScrollPane overviewScrollpane = new ExtendedJScrollPane(overview);
	overviewScrollpane.setBorder(null);
	overviewScrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
	overviewScrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	add(overviewScrollpane, BorderLayout.CENTER);
	tableUpdateQueue.start();
}
 
Example 14
Project: incubator-netbeans   File: MenuChecker.java   View source code 6 votes vote down vote up
/** Open all menus in menubar
 * @param menu  to be visited */
public static void visitMenuBar(JMenuBar menu) {
    MenuElement[] elements = menu.getSubElements();

    JMenuBarOperator op = new JMenuBarOperator(menu);

    for (int k = 0; k < elements.length; k++) {
        if (elements[k] instanceof JMenuItem) {
            op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
            try {
                op.wait(200);
            } catch (Exception e) {
            }
        }
    }
}
 
Example 15
Project: FreeCol   File: QuickActionMenu.java   View source code 6 votes vote down vote up
/**
 * Add an item to pay arrears on the given goods type.
 *
 * @param goodsType The {@code GoodsType} to pay arrears on.
 */
private void addPayArrears(final GoodsType goodsType) {
    final InGameController igc = freeColClient.getInGameController();

    JMenuItem menuItem = Utility.localizedMenuItem("payArrears");
    menuItem.addActionListener((ActionEvent ae) -> {
            igc.payArrears(goodsType);
            // FIXME: fix pcls so this hackery can go away
            if (parentPanel instanceof CargoPanel) {
                CargoPanel cargoPanel = (CargoPanel) parentPanel;
                cargoPanel.initialize();
            }
            parentPanel.revalidate();
        });
    this.add(menuItem);
}
 
Example 16
Project: brModelo   File: Controler.java   View source code 6 votes vote down vote up
public void PopuleBarra(JMenu obj) {
    int i = 0;
    for (ConfigAcao ca : Lista) {
        if (ca.tipo == TipoConfigAcao.tpMenuBarra || ca.tipo == TipoConfigAcao.tpAny) {
            Acao ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
            ac.IDX = i++;
            JMenuItem mi = new JMenuItem(ac);
            //obj.add(mi);
            listaMenus.put(ca.command, mi);
            //ListaDeAcoes.add(ac);
        }
    }
    obj.setText(Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.texto"));
    char b = Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.mtecla").charAt(0);
    obj.setMnemonic(b);
    BarraMenu = obj;
}
 
Example 17
Project: marathonv5   File: JMenuItemJavaElementTest.java   View source code 6 votes vote down vote up
@BeforeMethod public void showDialog() throws Throwable {
    JavaElementFactory.add(JMenuItem.class, JMenuItemJavaElement.class);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame = new JFrame(JMenuItemJavaElementTest.class.getSimpleName());
            frame.setName("frame-" + JMenuItemJavaElementTest.class.getSimpleName());
            MenuDemo demo = new MenuDemo();
            frame.setJMenuBar(demo.createMenuBar());
            frame.setContentPane(demo.createContentPane());
            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
    MenuSelectionManager.defaultManager().clearSelectedPath();
    driver = new JavaAgent();
    menus = driver.findElementsByTagName("menu");
    AMenu = menus.get(0);

}
 
Example 18
Project: openjdk-jdk10   File: CloseOnMouseClickPropertyTest.java   View source code 6 votes vote down vote up
private static void createAndShowGUI(TestItem testItem) {

        frame = new JFrame();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar();
        menu = new JMenu("Menu");
        JMenuItem menuItem = testItem.getMenuItem();
        testItem.setProperties(menuItem);
        menu.add(menuItem);
        menuBar.add(menu);

        frame.setJMenuBar(menuBar);
        frame.setVisible(true);
    }
 
Example 19
Project: OpenJSharp   File: XTextFieldEditor.java   View source code 5 votes vote down vote up
@Override
public void  actionPerformed(ActionEvent e) {
    super.actionPerformed(e);
    if ((e.getSource() instanceof JMenuItem) ||
        (e.getSource() instanceof JTextField)) {
        fireEditingStopped();
    }
}
 
Example 20
Project: incubator-netbeans   File: IgnoreMenu.java   View source code 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenu menu = createMenu();
    menu.setText(Bundle.CTL_MenuItem_IgnoreMenu_popupName());
    enableMenu(menu);
    return menu;
}
 
Example 21
Project: poi-visualizer   File: POIContextMenu.java   View source code 5 votes vote down vote up
@PostConstruct
public void init() {
   	if (isInit) {
   		return;
   	}

   	isInit = true;

   	saveStream = new JMenuItem("Save ...", KeyEvent.VK_S);
   	saveStream.addActionListener(e -> saveFile());

   	add(saveStream);
}
 
Example 22
Project: rapidminer   File: ClipboardActionsPopup.java   View source code 5 votes vote down vote up
public ClipboardActionsPopup(JTextComponent parent) {
	this.parent = parent;

	this.cutMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.cut",
			new javax.swing.text.DefaultEditorKit.CutAction()));
	this.copyMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.copy",
			new javax.swing.text.DefaultEditorKit.CopyAction()));
	this.pasteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.paste",
			new javax.swing.text.DefaultEditorKit.PasteAction()));
	this.deleteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.delete",
			new TextActions.DeleteTextAction()));

	// this.clearMenuItem = new JMenuItem(new TextActions.ClearAction());

	this.selectAllMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.select_all",
			new TextActions.SelectAllAction()));

	this.add(this.cutMenuItem);
	this.add(this.copyMenuItem);
	this.add(this.pasteMenuItem);
	this.add(this.deleteMenuItem);
	this.addSeparator();
	// this.add(this.clearMenuItem);
	this.add(this.selectAllMenuItem);

	// this.setPreferredSize(new Dimension((int) this.getPreferredSize().getWidth() + 30, (int)
	// this.getPreferredSize().getHeight()));
}
 
Example 23
Project: incubator-netbeans   File: DynamicMenu.java   View source code 5 votes vote down vote up
@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = createMenu();
    org.openide.awt.Mnemonics.setLocalizedText(menu, menu.getText());
    enableMenu(menu);
    return menu;
}
 
Example 24
Project: scorekeeperfrontend   File: ProSoloInterface.java   View source code 5 votes vote down vote up
protected JMenuItem createMenu(String title, int key, int modifier)
{
    JMenuItem item = new JMenuItem(title);
    if (key != 0) item.setAccelerator(KeyStroke.getKeyStroke(key, modifier));
    item.addActionListener(this);
    return item;
}
 
Example 25
Project: parabuild-ci   File: DatabaseManagerSwing.java   View source code 5 votes vote down vote up
private void addMenuItems(JMenu f, String m[]) {

        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

        for (int i = 0; i < m.length; i++) {
            if (m[i].equals("--")) {
                f.addSeparator();
            } else if (m[i].equals("---")) {

                // (ulrivo): full size on screen with less than 640 width
                if (d.width >= 640) {
                    f.addSeparator();
                } else {
                    return;
                }
            } else {
                JMenuItem item = new JMenuItem(m[i].substring(1));
                char      c    = m[i].charAt(0);

                if (c != '-') {
                    KeyStroke key =
                        KeyStroke.getKeyStroke(c, Event.CTRL_MASK);

                    item.setAccelerator(key);
                }

                item.addActionListener(this);
                f.add(item);
            }
        }
    }
 
Example 26
Project: Random-Music-Generator   File: GeneratorMenu.java   View source code 5 votes vote down vote up
public GeneratorMenu(Window window, ControllPanel genPanel, ArrayList<IMusicGenerator> musicGens,
		ArrayList<ISongChangeObserver> songChangeObservers){
	super("Generator");
	components = new ArrayList<JMenuItem>();
	this.window = window;
	this.genPanel = genPanel;
	this.musicGenList = musicGens;
	songChangeObserverList = songChangeObservers;
	for(IMusicGenerator musicGen: musicGenList){
		JMenuItem menuItem = new JMenuItem(musicGen.getGeneratorName());
		menuItem.addActionListener(new ActionHandler(musicGen));
		components.add(menuItem);
		add(menuItem);
	}
}
 
Example 27
Project: routerapp   File: MenuManagementWindow.java   View source code 5 votes vote down vote up
/**
 * Builds a list from the components array.
 * @param components the components array
 * @return a list to be placed on the GUI
 */
JList buildListFromComponents (Component [] components) {
	JList list = new JList();
	
	if (components != null) {
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setSize(100,200);
		
		listData = new Vector();
		menuItems = new Hashtable();
		
		// build a hash look-up table and fill list with components's text
		for (int i=0 ; i<components.length ; i++) {
			if (components[i] instanceof JMenuItem) {
				listData.addElement(((JMenuItem)components[i]).getText());
				menuItems.put(((JMenuItem)components[i]).getText(),components[i]);
			}
			else {
				listData.addElement(SEPARATOR_STRING);
				menuItems.put(SEPARATOR_STRING,components[i]);
			}
		}
		
		list.setListData(listData);
	}
		
	return list;
}
 
Example 28
Project: jmt   File: WhatIfPlot.java   View source code 5 votes vote down vote up
public PlotPopupMenu() {
	restore = new JMenuItem("Original view");
	zoomIn = new JMenuItem("Zoom in");
	zoomOut = new JMenuItem("Zoom out");
	saveAs = new JMenuItem("Save as...");
	saveAsWithLegend = new JMenuItem("Save as with legend...");
	this.add(restore);
	this.add(zoomIn);
	this.add(zoomOut);
	this.addSeparator();
	this.add(saveAs);
	this.add(saveAsWithLegend);
	addListeners();
}
 
Example 29
Project: incubator-netbeans   File: MoreAction.java   View source code 5 votes vote down vote up
/**
 * Remove DELETE accelerator from Delete action, because it is used by Hide
 * action in this context.
 */
private void removeDeleteAccelerator(Component item) {
    if (item instanceof JMenuItem) {
        JMenuItem mItem = (JMenuItem) item;
        if (DELETE_KS.equals(mItem.getAccelerator())) {
            mItem.setAccelerator(null);
        }
    }
}
 
Example 30
Project: jaer   File: DavisBaseCamera.java   View source code 5 votes vote down vote up
@Override
public void onRegistration() {
    super.onRegistration();
    if (getAeViewer() == null) {
        return;
    }
    helpMenuItem1 = getAeViewer().addHelpURLItem(DavisBaseCamera.HELP_URL_HW_USERGUIDES, "inilabs hardware user guides overview", "Opens product overview guide");
    helpMenuItem2 = getAeViewer().addHelpURLItem(DavisBaseCamera.USER_GUIDE_URL_DAVIS240, "DAVIS240 user guide",
            "Opens DAVIS240 user guide");
    helpMenuItem3 = getAeViewer().addHelpURLItem(DavisBaseCamera.USER_GUIDE_URL_FLASHY, "Flashy user guide",
            "User guide for external tool flashy for firmware/logic updates to devices using the libusb driver");

    davisMenu = new JMenu("DAVIS");
    davisMenu.add(new JMenuItem(new ToggleEventsAction()));
    davisMenu.add(new JMenuItem(new ToggleFrameCaptureDisplayAction()));
    davisMenu.add(new JSeparator());
    davisMenu.add(new JMenuItem(new ToggleAutoContrast()));
    davisMenu.add(new JMenuItem(new ToggleHistogram()));
    davisMenu.add(new JSeparator());
    davisMenu.add(new JMenuItem(new ToggleGlobalRollingShutter()));
    davisMenu.add(new JSeparator());
    davisMenu.add(new JMenuItem(new ToggleAutoExposure()));
    davisMenu.add(new JMenuItem(new IncreaseAPSExposure()));
    davisMenu.add(new JMenuItem(new DecreaseExposureAction()));
    davisMenu.add(new JSeparator());
    davisMenu.add(new JMenuItem(new IncreaseFrameRateAction()));
    davisMenu.add(new JMenuItem(new DecreaseFrameRateAction()));
    davisMenu.add(new JSeparator());
    davisMenu.add(new JMenuItem(new ToggleIMU()));
    davisMenu.getPopupMenu().setLightWeightPopupEnabled(false);
    getAeViewer().addMenu(davisMenu);
}
 
Example 31
Project: incubator-netbeans   File: CollectSystemAction.java   View source code 5 votes vote down vote up
private JMenuItem[] createMenu (Collection coll) {
    if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (
        "\n--> CollectSystemAction.createMenu: ( " + coll + " )");

    ArrayList items = new ArrayList ();

    Iterator it = coll.iterator();
    while (it.hasNext ()) {
        SystemAction a = (SystemAction) it.next();
        
        if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (
            "-*- CollectSystemAction.createMenu: next action " + a +
                         " -- " + ( a.isEnabled() ? "<enabled>" : "[disabled]" ) );
        
        if ( a.isEnabled() ) {
            JMenuItem item = null;
            if (a instanceof Presenter.Popup) {
                item = ((Presenter.Popup)a).getPopupPresenter ();
            }

            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug
                ("-*- CollectSystemAction.createMenu: menu item = " + item);

            // test if we obtained the item
            if (item != null) {
                items.add (item);
            }
        }
    }

    if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug
        ("<-- CollectSystemAction.createMenu: all items = " + items + "\n");

    JMenuItem[] array = new JMenuItem [items.size ()];
    items.toArray (array);
    return array;
}
 
Example 32
Project: sstore-soft   File: AbstractMenuHandler.java   View source code 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Item event detected.\n"
               + "    Event source: " + source.getText()
               + " (an instance of " + source.getClass().getName() + ")\n"
               + "    New state: "
               + ((e.getStateChange() == ItemEvent.SELECTED) ?
                 "selected":"unselected") + "\n\n";
    System.err.println(s);
 }
 
Example 33
Project: javaportfolio   File: MenuCreator.java   View source code 5 votes vote down vote up
public JMenu createViewMenu() {
	JMenu viewMenu = new JMenu("Näkymä");
	JMenuItem item;
	viewMenu.add(item = new JCheckBoxMenuItem(MENU_ITEM_SHOW_PARTIAL));
    item.addActionListener(this);
    
    return viewMenu;
}
 
Example 34
Project: incubator-netbeans   File: EditorsAction.java   View source code 5 votes vote down vote up
@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = new UpdatingMenu();
    String label = NbBundle.getMessage(EditorsAction.class, "CTL_EditorsAction");
    Mnemonics.setLocalizedText(menu, label);
    return menu;
}
 
Example 35
Project: incubator-netbeans   File: QueuesMenu.java   View source code 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenu menu = createMenu();
    menu.setText(Bundle.CTL_MenuItem_QueuesMenu_popupName());
    enableMenu(menu);
    return menu;
}
 
Example 36
Project: incubator-netbeans   File: AbstractContextMenuFactory.java   View source code 5 votes vote down vote up
private JMenuItem getOrCreateMenuItem(int type) {
    JMenuItem result = type == ActionProvider.ACTION_TYPE_ITEM ? new JMenuItem() :
        type == ActionProvider.ACTION_TYPE_SUBCONTEXT ? new JMenu() : null;
    if (type == ActionProvider.ACTION_TYPE_ITEM) {
        result.addActionListener (getItemListener());
    } else if (type == ActionProvider.ACTION_TYPE_SUBCONTEXT){
        //attachToMenu ((JMenu) result);
    }
    result.putClientProperty (KEY_CREATOR, this);
    return result;
}
 
Example 37
Project: Java-RPG-Maker-MV-Decrypter   File: GUI_Menu.java   View source code 5 votes vote down vote up
/**
 * Creates the Info-Menu
 */
private void constructInfoMenu() {
	this.info = new JMenu("Info");

	this.help = new JMenuItem("Help");
	this.reportABug = new JMenuItem("Report a Bug...");
	this.about = new JMenuItem("About");
}
 
Example 38
Project: openjdk-jdk10   File: JMenuItemOperator.java   View source code 5 votes vote down vote up
/**
 * Maps
 * {@code JMenuItem.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)}
 * through queue
 */
public void processMouseEvent(final MouseEvent mouseEvent, final MenuElement[] menuElement, final MenuSelectionManager menuSelectionManager) {
    runMapping(new MapVoidAction("processMouseEvent") {
        @Override
        public void map() {
            ((JMenuItem) getSource()).processMouseEvent(mouseEvent, menuElement, menuSelectionManager);
        }
    });
}
 
Example 39
Project: incubator-netbeans   File: LookupSensitiveActionUILogTest.java   View source code 5 votes vote down vote up
public void testMenuPushIsNotified() throws Exception {
       TestSupport.ChangeableLookup lookup = new TestSupport.ChangeableLookup();
       TestLSA tlsa = new TestLSA( lookup );
assertTrue ("TestLSA action is enabled.", tlsa.isEnabled ());
tlsa.refreshCounter = 0;
       TestPropertyChangeListener tpcl = new TestPropertyChangeListener();
       tlsa.addPropertyChangeListener( tpcl );
       lookup.change(d2);
       assertEquals( "Refresh should be called once", 1, tlsa.refreshCounter );
       assertEquals( "One event should be fired", 1, tpcl.getEvents().size() );
       assertTrue("Action is enabled", tlsa.isEnabled());

       tlsa.setDisplayName("Jarda");
    
       
       JMenuItem item = new JMenuItem(tlsa);
       item.doClick();
       
       assertEquals("One record logged:\n" + my.recs, 1, my.recs.size());
       LogRecord r = my.recs.get(0);
       assertEquals("Menu push", "UI_ACTION_BUTTON_PRESS", r.getMessage());
       assertEquals("four args", 5, r.getParameters().length);
       assertEquals("first is the menu item", item, r.getParameters()[0]);
       assertEquals("second is its class", JMenuItem.class.getName(), r.getParameters()[1]);
       assertEquals("3rd is action", tlsa, r.getParameters()[2]);
       assertEquals("4th its class", tlsa.getClass().getName(), r.getParameters()[3]);
       assertEquals("5th name", "Jarda", r.getParameters()[4]);
       
       tlsa.clear();
       tpcl.clear();
       lookup.change(d3);
       assertEquals( "Refresh should be called once", 1, tlsa.refreshCounter );
       assertEquals( "One event should be fired", 1, tpcl.getEvents().size() );        
   }
 
Example 40
Project: marathonv5   File: RMenuItemTest.java   View source code 5 votes vote down vote up
private List<JMenuItem> getMenuComponents(JMenu AMenu) {
    Component[] components = AMenu.getMenuComponents();
    List<JMenuItem> items = new ArrayList<JMenuItem>();
    for (int j = 0; j < components.length; j++) {
        if (!(components[j] instanceof AbstractButton)) {
            continue;
        }
        items.add((JMenuItem) components[j]);
    }
    return items;
}