private static Menu initProjectMenu() { Menu mnProject = new Menu(Resources.get("menu_project")); CheckboxMenuItem compress = new CheckboxMenuItem(Resources.get("menu_compressProjectFile")); compress.setState(userPreferences.isCompressFile()); compress.addItemListener(e -> userPreferences.setCompressFile(compress.getState())); CheckboxMenuItem sync = new CheckboxMenuItem(Resources.get("menu_syncMaps")); sync.setState(userPreferences.isSyncMaps()); sync.addItemListener(e -> userPreferences.setSyncMaps(sync.getState())); MenuItem importSpriteFile = new MenuItem(Resources.get("menu_assets_importSpriteFile")); importSpriteFile.addActionListener(a -> EditorScreen.instance().importSpriteFile()); MenuItem importSprite = new MenuItem(Resources.get("menu_assets_importSprite")); importSprite.addActionListener(a -> EditorScreen.instance().importSprites()); mnProject.add(importSprite); mnProject.add(importSpriteFile); mnProject.addSeparator(); mnProject.add(compress); mnProject.add(sync); return mnProject; }
void addMenu(MenuBar b, String name, String[] items) { /* It's a very poor design to encapsulate menu creation this way. * Can't customize the menus this way (e.g. shortcut keys, * mnemonics, disabling, etc. */ Menu menu = new Menu(name); if (name.equals("Tools") && !TT_AVAILABLE) { // Terrible place to do this. Forced to due to method design. menu.setEnabled(false); } addMenuItems(menu, items); b.add(menu); }
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); } }
/** * Method declaration * * * @param b * @param name * @param items */ void addMenu(MenuBar b, String name, String[] items) { /* It's a very poor design to encapsulate menu creation this way. * Can't customize the menus this way (e.g. shortcut keys, * mnemonics, disabling, etc. */ Menu menu = new Menu(name); if (name.equals("Tools") && !TT_AVAILABLE) { // Terrible place to do this. Forced to due to method design. menu.setEnabled(false); } addMenuItems(menu, items); b.add(menu); }
private static void test3(final MenuBar menuBar) { final Menu helpMenu1 = new Menu("Help Menu1"); final Menu helpMenu2 = new Menu("Help Menu2"); menuBar.setHelpMenu(helpMenu1); checkCurrentMenu(menuBar, helpMenu1); checkMenuCount(menuBar, 1); checkHelpMenu(helpMenu1, true); checkHelpMenu(helpMenu2, false); menuBar.setHelpMenu(helpMenu2); checkCurrentMenu(menuBar, helpMenu2); checkMenuCount(menuBar, 1); checkHelpMenu(helpMenu1, false); checkHelpMenu(helpMenu2, true); menuBar.remove(helpMenu2); checkCurrentMenu(menuBar, null); checkMenuCount(menuBar, 0); checkHelpMenu(helpMenu1, false); checkHelpMenu(helpMenu2, false); }
/** * Adds a help menu to this MenuBar. Gnome styleguides say the help * menu is just the last item in the menubar (they are NOT right * justified). */ public void addHelpMenu (Menu menu) { if (hasHelpMenu) { // Remove the (help) menu, which is after all the other items. delMenu(((MenuBar) awtWidget).getMenuCount()); hasHelpMenu = false; } if (menu != null) { addMenu(menu); hasHelpMenu = true; } }
/** * Handles mouse events. * * @param ev the mouse event */ public void handleMouseEvent(MouseEvent ev) { Point point = ev.getPoint(); for (int i = 0; i < awtMenuBar.getMenuCount(); i++) { Menu menu = awtMenuBar.getMenu(i); SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer(); int x1 = peer.getX(); int x2 = x1 + peer.getWidth(); if (point.x >= x1 && point.x <= x2) { ev.translatePoint(peer.getX(), peer.getY()); peer.handleMouseEvent(ev); break; } } }
/** * Handles mouse motion events. * * @param ev the mouse motion event */ public void handleMouseMotionEvent(MouseEvent ev) { Point point = ev.getPoint(); for (int i = 0; i < awtMenuBar.getMenuCount(); i++) { Menu menu = awtMenuBar.getMenu(i); SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer(); int x1 = peer.getX(); int x2 = x1 + peer.getWidth(); if (point.x >= x1 && point.x <= x2) { ev.translatePoint(peer.getX(), peer.getY()); peer.handleMouseMotionEvent(ev); break; } } }
private static MenuItem generateMenuItem(TreeElement element) { if(element.isLeaf()) { MenuItem item = new MenuItem(element.getCaption()); item.addActionListener(new MasterFrameMenu(element.getFullID())); if(element.isHidden()) { item.setEnabled(false); } else if(!element.getEnabled()) { item.setEnabled(false); } items.put(element.getFullID(), item); return(item); } else { Menu menu = new Menu(element.getCaption()); Iterator<TreeElement> i = element.getChilds(); while(i.hasNext()) { menu.add(generateMenuItem(i.next())); } if(element.isHidden()) { menu.setEnabled(false); } items.put(element.getFullID(), menu); return(menu); } }
/** * 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); } } }
public static void main(String[] args) { Container container = new Container(); Panel panel = new Panel(); Menu menu = new Menu(); //!!! its not component TextField textField = new TextField(); container.add(textField); Window win = new Window(null); win.pack(); menu.setShortcut(new MenuShortcut(12)); new MenuItem("label", new MenuShortcut(33, true)); Menu file = new Menu("File"); MenuItem print; file.add(print = new MenuItem("Print", new MenuShortcut('p'))); }
protected static PopupMenu createPopupMenu() { final PopupMenu popup = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip"); Menu displayMenu = new Menu("Display"); MenuItem errorItem = new MenuItem("Error"); MenuItem warningItem = new MenuItem("Warning"); MenuItem infoItem = new MenuItem("Info"); MenuItem noneItem = new MenuItem("None"); MenuItem exitItem = new MenuItem("Exit"); // Add components to pop-up menu popup.add(aboutItem); popup.addSeparator(); popup.add(cb1); popup.add(cb2); popup.addSeparator(); popup.add(displayMenu); displayMenu.add(errorItem); displayMenu.add(warningItem); displayMenu.add(infoItem); displayMenu.add(noneItem); popup.add(exitItem); return popup; }
public OpenPartnerFrame (Go go) { super(Global.resourceString("Open_Partners")); G = go; MenuBar mb = new MenuBar(); setMenuBar(mb); Menu m = new MyMenu(Global.resourceString("Options")); m.add(new MenuItemAction(this, Global.resourceString("Close"))); mb.add(m); setLayout(new BorderLayout()); L = new java.awt.List(); L.setFont(Global.SansSerif); refresh(); add("Center", L); JPanel bp = new MyPanel(); bp.add(new ButtonAction(this, Global.resourceString("Connect"))); bp.add(new ButtonAction(this, Global.resourceString("Refresh"))); bp.add(new MyLabel(" ")); bp.add(new ButtonAction(this, Global.resourceString("Close"))); add("South", bp); Global.setwindow(this, "openpartner", 300, 200); seticon("ijago.gif"); setVisible(true); OPFU = new OpenPartnerFrameUpdate(this); }
private static Menu initFileMenu() { Menu mnFile = new Menu(Resources.get("menu_file")); MenuItem create = new MenuItem(Resources.get("menu_createProject")); create.setShortcut(new MenuShortcut(KeyEvent.VK_N)); create.addActionListener(a -> EditorScreen.instance().create()); MenuItem load = new MenuItem(Resources.get("menu_loadProject")); load.setShortcut(new MenuShortcut(KeyEvent.VK_O)); load.addActionListener(a -> EditorScreen.instance().load()); MenuItem save = new MenuItem(Resources.get("menu_save")); save.setShortcut(new MenuShortcut(KeyEvent.VK_S)); save.addActionListener(a -> EditorScreen.instance().save(false)); MenuItem saveAs = new MenuItem(Resources.get("menu_saveAs")); saveAs.addActionListener(a -> EditorScreen.instance().save(true)); MenuItem exit = new MenuItem(Resources.get("menu_exit")); exit.setShortcut(new MenuShortcut(KeyEvent.VK_Q)); exit.addActionListener(a -> Game.terminate()); mnFile.add(load); mnFile.add(create); mnFile.add(save); mnFile.add(saveAs); mnFile.addSeparator(); recentFiles = new Menu(Resources.get("menu_recentFiles")); loadRecentFiles(); mnFile.add(recentFiles); mnFile.addSeparator(); mnFile.add(exit); return mnFile; }