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); } }
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'))); }
@Override protected Expression instantiate(Object oldInstance, Encoder enc) { MenuShortcut shortcut = (MenuShortcut) oldInstance; int keyCode = shortcut.getKey(); boolean useShiftModifier = shortcut.usesShiftModifier(); return new Expression(shortcut, shortcut.getClass(), BeansUtils.NEW, new Object[] { keyCode, useShiftModifier }); }
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; }
public void setLabel(String label, char keyChar, int keyCode, int modifiers) { int keyMask = modifiers; if (keyCode == KeyEvent.VK_UNDEFINED) { MenuShortcut shortcut = ((MenuItem)getTarget()).getShortcut(); if (shortcut != null) { keyCode = shortcut.getKey(); keyMask |= InputEvent.META_MASK; if (shortcut.usesShiftModifier()) { keyMask |= InputEvent.SHIFT_MASK; } } } if (label == null) { label = ""; } // <rdar://problem/3654824> // Native code uses a keyChar of 0 to indicate that the // keyCode should be used to generate the shortcut. Translate // CHAR_UNDEFINED into 0. if (keyChar == KeyEvent.CHAR_UNDEFINED) { keyChar = 0; } nativeSetLabel(getModel(), label, keyChar, keyCode, keyMask); }
/** * Method declaration * * * @param f * @param m */ 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 f * @param m */ 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); } }
public void setLabel(String label, char keyChar, int keyCode, int modifiers) { int keyMask = modifiers; if (keyCode == KeyEvent.VK_UNDEFINED) { MenuShortcut shortcut = ((MenuItem)getTarget()).getShortcut(); if (shortcut != null) { keyCode = shortcut.getKey(); keyMask |= InputEvent.META_MASK; if (shortcut.usesShiftModifier()) { keyMask |= InputEvent.SHIFT_MASK; } } } if (label == null) { label = ""; } // <rdar://problem/3654824> // Native code uses a keyChar of 0 to indicate that the // keyCode should be used to generate the shortcut. Translate // CHAR_UNDEFINED into 0. if (keyChar == KeyEvent.CHAR_UNDEFINED) { keyChar = 0; } final String finalLabel = label; final char finalKeyChar = keyChar; final int finalKeyCode = keyCode; final int finalKeyMask = keyMask; execute(ptr -> nativeSetLabel(ptr, finalLabel, finalKeyChar, finalKeyCode, finalKeyMask)); }
@SuppressWarnings("deprecation") public void setLabel(String label, char keyChar, int keyCode, int modifiers) { int keyMask = modifiers; if (keyCode == KeyEvent.VK_UNDEFINED) { MenuShortcut shortcut = ((MenuItem)getTarget()).getShortcut(); if (shortcut != null) { keyCode = shortcut.getKey(); keyMask |= InputEvent.META_MASK; if (shortcut.usesShiftModifier()) { keyMask |= InputEvent.SHIFT_MASK; } } } if (label == null) { label = ""; } // <rdar://problem/3654824> // Native code uses a keyChar of 0 to indicate that the // keyCode should be used to generate the shortcut. Translate // CHAR_UNDEFINED into 0. if (keyChar == KeyEvent.CHAR_UNDEFINED) { keyChar = 0; } final String finalLabel = label; final char finalKeyChar = keyChar; final int finalKeyCode = keyCode; final int finalKeyMask = keyMask; execute(ptr -> nativeSetLabel(ptr, finalLabel, finalKeyChar, finalKeyCode, finalKeyMask)); }
public void addItem (MenuItem item) { int key = 0; boolean shiftModifier = false; MenuShortcut ms = item.getShortcut (); if (ms != null) { key = ms.getKey (); shiftModifier = ms.usesShiftModifier (); } addItem ((MenuItemPeer) item.getPeer (), key, shiftModifier); }
public void addItem (MenuItemPeer item, MenuShortcut ms) { int key = 0; boolean shiftModifier = false; if (ms != null) { key = ms.getKey (); shiftModifier = ms.usesShiftModifier (); } addItem (item, key, shiftModifier); }
@Override @SuppressWarnings("boxing") protected Expression instantiate(Object oldInstance, Encoder enc) { MenuShortcut shortcut = (MenuShortcut) oldInstance; int keyCode = shortcut.getKey(); boolean useShiftModifier = shortcut.usesShiftModifier(); return new Expression(shortcut, shortcut.getClass(), Statement.CONSTRUCTOR_NAME, new Object[] {keyCode, useShiftModifier}); }
private static void registerAwtPDs() { delegates.put(Choice.class, new AwtChoicePersistenceDelegate()); delegates.put(Color.class, new AwtColorPersistenceDelegate()); delegates.put(Container.class, new AwtContainerPersistenceDelegate()); delegates.put(Component.class, new AwtComponentPersistenceDelegate()); delegates.put(Cursor.class, new AwtCursorPersistenceDelegate()); delegates.put(Dimension.class, new AwtDimensionPersistenceDelegate()); delegates.put(Font.class, new AwtFontPersistenceDelegate()); delegates.put(Insets.class, new AwtInsetsPersistenceDelegate()); delegates.put(List.class, new AwtListPersistenceDelegate()); delegates.put(Menu.class, new AwtMenuPersistenceDelegate()); delegates.put(MenuBar.class, new AwtMenuBarPersistenceDelegate()); delegates.put(MenuShortcut.class, new AwtMenuShortcutPersistenceDelegate()); delegates.put(Point.class, new AwtPointPersistenceDelegate()); delegates.put(Rectangle.class, new AwtRectanglePersistenceDelegate()); delegates.put(SystemColor.class, new AwtSystemColorPersistenceDelegate()); delegates.put(TextAttribute.class, new AwtFontTextAttributePersistenceDelegate()); delegates.put(ScrollPane.class, new AwtScrollPanePersistenceDelegate()); }
private static PopupMenu getMenu() { menu = new PopupMenu(ZAYF_TRAY_TOOLTIP); exitItem = new MenuItem("exit", new MenuShortcut('x')); menu.add(exitItem); return menu; }