1 /*
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
254 }
255 }
256 }
257
258 /**
259 * Removes the specified menu component from this menu bar.
260 * @param m the menu component to be removed.
261 * @see java.awt.MenuBar#add(java.awt.Menu)
262 */
263 public void remove(MenuComponent m) {
264 synchronized (getTreeLock()) {
265 int index = menus.indexOf(m);
266 if (index >= 0) {
267 remove(index);
268 }
269 }
270 }
271
272 /**
273 * Gets the number of menus on the menu bar.
274 * @return the number of menus on the menu bar.
275 * @since JDK1.1
276 */
277 public int getMenuCount() {
278 return countMenus();
279 }
280
281 /**
282 * @deprecated As of JDK version 1.1,
283 * replaced by <code>getMenuCount()</code>.
284 */
285 @Deprecated
286 public int countMenus() {
287 return getMenuCountImpl();
288 }
289
290 /*
291 * This is called by the native code, so client code can't
292 * be called on the toolkit thread.
293 */
294 final int getMenuCountImpl() {
295 return menus.size();
296 }
297
298 /**
299 * Gets the specified menu.
300 * @param i the index position of the menu to be returned.
301 * @return the menu at the specified index of this menu bar.
322 */
323 public synchronized Enumeration<MenuShortcut> shortcuts() {
324 Vector<MenuShortcut> shortcuts = new Vector<>();
325 int nmenus = getMenuCount();
326 for (int i = 0 ; i < nmenus ; i++) {
327 Enumeration<MenuShortcut> e = getMenu(i).shortcuts();
328 while (e.hasMoreElements()) {
329 shortcuts.addElement(e.nextElement());
330 }
331 }
332 return shortcuts.elements();
333 }
334
335 /**
336 * Gets the instance of <code>MenuItem</code> associated
337 * with the specified <code>MenuShortcut</code> object,
338 * or <code>null</code> if none of the menu items being managed
339 * by this menu bar is associated with the specified menu
340 * shortcut.
341 * @param s the specified menu shortcut.
342 * @see java.awt.MenuItem
343 * @see java.awt.MenuShortcut
344 * @since JDK1.1
345 */
346 public MenuItem getShortcutMenuItem(MenuShortcut s) {
347 int nmenus = getMenuCount();
348 for (int i = 0 ; i < nmenus ; i++) {
349 MenuItem mi = getMenu(i).getShortcutMenuItem(s);
350 if (mi != null) {
351 return mi;
352 }
353 }
354 return null; // MenuShortcut wasn't found
355 }
356
357 /*
358 * Post an ACTION_EVENT to the target of the MenuPeer
359 * associated with the specified keyboard event (on
360 * keydown). Returns true if there is an associated
361 * keyboard event.
|
1 /*
2 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
254 }
255 }
256 }
257
258 /**
259 * Removes the specified menu component from this menu bar.
260 * @param m the menu component to be removed.
261 * @see java.awt.MenuBar#add(java.awt.Menu)
262 */
263 public void remove(MenuComponent m) {
264 synchronized (getTreeLock()) {
265 int index = menus.indexOf(m);
266 if (index >= 0) {
267 remove(index);
268 }
269 }
270 }
271
272 /**
273 * Gets the number of menus on the menu bar.
274 *
275 * @return the number of menus on the menu bar
276 * @since JDK1.1
277 */
278 public int getMenuCount() {
279 return countMenus();
280 }
281
282 /**
283 * Gets the number of menus on the menu bar.
284 *
285 * @return the number of menus on the menu bar.
286 * @deprecated As of JDK version 1.1,
287 * replaced by <code>getMenuCount()</code>.
288 */
289 @Deprecated
290 public int countMenus() {
291 return getMenuCountImpl();
292 }
293
294 /*
295 * This is called by the native code, so client code can't
296 * be called on the toolkit thread.
297 */
298 final int getMenuCountImpl() {
299 return menus.size();
300 }
301
302 /**
303 * Gets the specified menu.
304 * @param i the index position of the menu to be returned.
305 * @return the menu at the specified index of this menu bar.
326 */
327 public synchronized Enumeration<MenuShortcut> shortcuts() {
328 Vector<MenuShortcut> shortcuts = new Vector<>();
329 int nmenus = getMenuCount();
330 for (int i = 0 ; i < nmenus ; i++) {
331 Enumeration<MenuShortcut> e = getMenu(i).shortcuts();
332 while (e.hasMoreElements()) {
333 shortcuts.addElement(e.nextElement());
334 }
335 }
336 return shortcuts.elements();
337 }
338
339 /**
340 * Gets the instance of <code>MenuItem</code> associated
341 * with the specified <code>MenuShortcut</code> object,
342 * or <code>null</code> if none of the menu items being managed
343 * by this menu bar is associated with the specified menu
344 * shortcut.
345 * @param s the specified menu shortcut.
346 * @return the menu item for the specified shortcut.
347 * @see java.awt.MenuItem
348 * @see java.awt.MenuShortcut
349 * @since JDK1.1
350 */
351 public MenuItem getShortcutMenuItem(MenuShortcut s) {
352 int nmenus = getMenuCount();
353 for (int i = 0 ; i < nmenus ; i++) {
354 MenuItem mi = getMenu(i).getShortcutMenuItem(s);
355 if (mi != null) {
356 return mi;
357 }
358 }
359 return null; // MenuShortcut wasn't found
360 }
361
362 /*
363 * Post an ACTION_EVENT to the target of the MenuPeer
364 * associated with the specified keyboard event (on
365 * keydown). Returns true if there is an associated
366 * keyboard event.
|