Java Code Examples for java.awt.Menu#add()

The following examples show how to use java.awt.Menu#add() . 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: GUI.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
	private static Menu makesToolsMenu() {

		Menu toolsMenu = new Menu("Tools");

		
		MenuItem optionsItem = new MenuItem("Options");
		toolsMenu.add(optionsItem);
		optionsItem.addActionListener(e -> IdeOptions.showOptions());

//		MenuItem chaseItem = new MenuItem("ED Chaser");
//		toolsMenu.add(chaseItem);
//		chaseItem.addActionListener(x -> Chase.dostuff());

		//MenuItem sqlLoaderItem = new MenuItem("SQL Loader");
		//toolsMenu.add(sqlLoaderItem);
		//sqlLoaderItem.addActionListener(x -> SqlLoader.showLoader());

		/* MenuItem sqlMapperItem = new MenuItem("SQL Mapper");
		toolsMenu.add(sqlMapperItem);
		sqlMapperItem.addActionListener(x -> SqlMapper.showGuesser());
*/
		MenuItem sqlCheckItem = new MenuItem("SQL Checker");
		toolsMenu.add(sqlCheckItem);
		sqlCheckItem.addActionListener(x -> new SqlChecker()); 

		MenuItem shredItem = new MenuItem("NR Shredder");
		toolsMenu.add(shredItem);
		shredItem.addActionListener(x -> new NraViewer());

		MenuItem easikItem = new MenuItem("EASIK");
		toolsMenu.add(easikItem);
		easikItem.addActionListener(x -> easik.Easik.main(new String[0]));

		return toolsMenu;
	}
 
Example 2
Source File: ActionEventTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ActionEventTest() {
    menuBar = new MenuBar();
    Menu menu = new Menu("Menu1");
    MenuItem menuItem = new MenuItem("MenuItem");

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            System.out.println("actionPerformed");
            int md = ae.getModifiers();
            int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                    | ActionEvent.SHIFT_MASK;

            isProgInterruption = true;
            mainThread.interrupt();
            if ((md & expectedMask) != expectedMask) {
                throw new RuntimeException("Action Event modifiers are not"
                    + " set correctly.");
            }
        }
    });
    menu.add(menuItem);
    menuBar.add(menu);
    setMenuBar(menuBar);

    instructions = new TextArea(10, 50);
    instructions.setText(
    " This is a manual test\n" +
    " Keep the Alt, Shift & Ctrl Keys pressed while doing next steps\n" +
    " Click 'Menu1' Menu from the Menu Bar\n" +
    " It will show 'MenuItem'\n" +
    " Left mouse Click the 'MenuItem'\n" +
    " Test exits automatically after mouse click.");
    add(instructions);

    setSize(400, 400);
    setVisible(true);
    validate();
}
 
Example 3
Source File: DatabaseManager.java    From evosql with Apache License 2.0 5 votes vote down vote up
void addMenuItems(Menu f, String[] m) {

        for (int i = 0; i < m.length; i++) {
            MenuItem item = new MenuItem(m[i].substring(1));
            char     c    = m[i].charAt(0);

            if (c != '-') {
                item.setShortcut(new MenuShortcut(c));
            }

            item.addActionListener(this);
            f.add(item);
        }
    }
 
Example 4
Source File: Transfer.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Method declaration
 *
 *
 * @param f
 * @param m
 */
private void addMenuItems(Menu f, String[] m) {

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

            item.addActionListener(this);
            f.add(item);
        }
    }
}
 
Example 5
Source File: GUI.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({})
	public static Pair<JPanel, MenuBar> makeGUI(JFrame frame) {
		topFrame = frame;

		MenuBar menuBar = new MenuBar();

		Menu fileMenu = makeFileMenu();

		Menu editMenu = makeEditMenu();

		Menu toolsMenu = makesToolsMenu();

		Menu helpMenu = new Menu("Help");
		MenuItem aboutItem = new MenuItem("Help");
		helpMenu.add(aboutItem);
		aboutItem.addActionListener(e -> IdeOptions.showAbout());

		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		menuBar.add(toolsMenu);

		Menu aqlMenu = populateAql();

		menuBar.add(aqlMenu);

		//Menu legacyMenu = new Menu("Legacy");
		//Menu fqlMenu = new Menu("FQL");
		//Menu fqlppMenu = new Menu("FQL++");
//		Menu oplMenu = new Menu("OPL");
//		Menu fpqlMenu = new Menu("FPQL");
		//legacyMenu.add(fqlMenu);
		//legacyMenu.add(fqlppMenu);
//		legacyMenu.add(oplMenu);
//		legacyMenu.add(fpqlMenu);
		//MenuItem optionsItem2 = new MenuItem("Legacy options");
		//legacyMenu.add(optionsItem2);
		//optionsItem2.addActionListener(e -> DefunctGlobalOptions.showOptions());

		// menuBar.add(legacyMenu);

		menuBar.add(helpMenu);

		JPanel pan = new JPanel();

		pan.setLayout(new BorderLayout());

		JPanel toolBar = makeToolBar();

		pan.add(toolBar, BorderLayout.PAGE_START);
		pan.add(editors, BorderLayout.CENTER);

		return new Pair<>(pan, menuBar);
	}
 
Example 6
Source File: GUI.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
	private static Menu makeFileMenu() {
		Menu fileMenu = new Menu("File");

		MenuItem openItem = new MenuItem("Open");
		MenuItem saveItem = new MenuItem("Save");
		MenuItem saveAsItem = new MenuItem("Save As");
		MenuItem saveAllItem = new MenuItem("Save All");
		MenuItem closeItem = new MenuItem("Close");
		MenuItem exitItem = new MenuItem("Quit");

		Map<Language, MenuItem> newItems = new THashMap<>();
		for (Language l : Language.values0()) {
			if (l.toString().contains(" ")) {
				continue;
			}
			if (l.toString().contains("EASIK")) {
				continue;
			}
			MenuItem newItem = new MenuItem("New " + l);
			fileMenu.add(newItem);
			newItems.put(l, newItem);
			newItem.addActionListener((ActionEvent e) -> newAction(null, "", l));
		}

		fileMenu.add(openItem);
		// fileMenu.add(openItem2);
		fileMenu.add(saveItem);
		fileMenu.add(saveAsItem);
		fileMenu.add(saveAllItem);
		fileMenu.add(closeItem);
		fileMenu.add(exitItem);

		closeItem.addActionListener(e -> closeAction());
		saveAsItem.addActionListener(e -> saveAsActionAlternate(getSelectedEditor()));

		KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
		MenuShortcut s = new MenuShortcut(ctrlS.getKeyCode());
		saveItem.setShortcut(s);

		// TODO aql why doesn't shift mask work? order?
		MenuShortcut sA = new MenuShortcut(ctrlS.getKeyCode(), true);
		saveAllItem.setShortcut(sA);
		saveAllItem.addActionListener(e -> saveAllAction());

		KeyStroke ctrlQ = KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
		MenuShortcut q = new MenuShortcut(ctrlQ.getKeyCode());
		exitItem.setShortcut(q);

		KeyStroke ctrlW = KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
//		KeyStroke commandW = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_DOWN_MASK);
		MenuShortcut c = new MenuShortcut(ctrlW.getKeyCode());
		closeItem.setShortcut(c);

		openItem.addActionListener(e -> openActionAlternate());

		saveItem.addActionListener(e -> saveAction());

		exitItem.addActionListener(e -> exitAction());

		KeyStroke ctrlN = KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
		MenuShortcut n = new MenuShortcut(ctrlN.getKeyCode());
		newItems.get(Language.getDefault()).setShortcut(n);
		KeyStroke ctrlO = KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
		MenuShortcut o = new MenuShortcut(ctrlO.getKeyCode());
		openItem.setShortcut(o);
		return fileMenu;

	}
 
Example 7
Source File: AppletFrame.java    From pdfxtk with Apache License 2.0 3 votes vote down vote up
public AppletFrame(String title, 
     Applet applet_, 
     int width, int height) {
  super("applet", title);
  addWindowListener(this);
  applet = applet_;
  
  MenuBar  menubar = new MenuBar();
  Menu     file    = new Menu("File", true);
  MenuItem quit    = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q));

  setBackground(Color.lightGray);

  quit.addActionListener(this);
  
  menubar.add(file);
  file.add(quit);
  setMenuBar(menubar);
  
  add("Center", applet);

  setSize(width, height);

  applet.init();

  setVisible(true);
  
  validate();

  applet.active = true;
  applet.start();

  validate();
}