| Method from java.awt.MenuBar Detail: |
public Menu add(Menu m) {
synchronized (getTreeLock()) {
if (m.parent != null) {
m.parent.remove(m);
}
menus.addElement(m);
m.parent = this;
MenuBarPeer peer = (MenuBarPeer)this.peer;
if (peer != null) {
if (m.peer == null) {
m.addNotify();
}
peer.addMenu(m);
}
return m;
}
}
Adds the specified menu to the menu bar.
If the menu has been part of another menu bar,
removes it from that menu bar. |
public void addNotify() {
synchronized (getTreeLock()) {
if (peer == null)
peer = Toolkit.getDefaultToolkit().createMenuBar(this);
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
getMenu(i).addNotify();
}
}
}
Creates the menu bar's peer. The peer allows us to change the
appearance of the menu bar without changing any of the menu bar's
functionality. |
String constructComponentName() {
synchronized (MenuBar.class) {
return base + nameCounter++;
}
}
Construct a name for this MenuComponent. Called by getName() when
the name is null. |
public int countMenus() {
return getMenuCountImpl();
} Deprecated! As - of JDK version 1.1,
replaced by getMenuCount().
|
public void deleteShortcut(MenuShortcut s) {
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
getMenu(i).deleteShortcut(s);
}
}
Deletes the specified menu shortcut. |
int getAccessibleChildIndex(MenuComponent child) {
return menus.indexOf(child);
}
Defined in MenuComponent. Overridden here. |
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTMenuBar();
}
return accessibleContext;
}
Gets the AccessibleContext associated with this MenuBar.
For menu bars, the AccessibleContext takes the form of an
AccessibleAWTMenuBar.
A new AccessibleAWTMenuBar instance is created if necessary. |
public Menu getHelpMenu() {
return helpMenu;
}
Gets the help menu on the menu bar. |
public Menu getMenu(int i) {
return getMenuImpl(i);
}
|
public int getMenuCount() {
return countMenus();
}
Gets the number of menus on the menu bar. |
final int getMenuCountImpl() {
return menus.size();
}
|
final Menu getMenuImpl(int i) {
return (Menu)menus.elementAt(i);
}
|
public MenuItem getShortcutMenuItem(MenuShortcut s) {
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
MenuItem mi = getMenu(i).getShortcutMenuItem(s);
if (mi != null) {
return mi;
}
}
return null; // MenuShortcut wasn't found
}
Gets the instance of MenuItem associated
with the specified MenuShortcut object,
or null if none of the menu items being managed
by this menu bar is associated with the specified menu
shortcut. |
boolean handleShortcut(KeyEvent e) {
// Is it a key event?
int id = e.getID();
if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
return false;
}
// Is the accelerator modifier key pressed?
int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if ((e.getModifiers() & accelKey) == 0) {
return false;
}
// Pass MenuShortcut on to child menus.
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
Menu m = getMenu(i);
if (m.handleShortcut(e)) {
return true;
}
}
return false;
}
|
public void remove(int index) {
synchronized (getTreeLock()) {
Menu m = getMenu(index);
menus.removeElementAt(index);
MenuBarPeer peer = (MenuBarPeer)this.peer;
if (peer != null) {
m.removeNotify();
m.parent = null;
peer.delMenu(index);
}
}
}
Removes the menu located at the specified
index from this menu bar. |
public void remove(MenuComponent m) {
synchronized (getTreeLock()) {
int index = menus.indexOf(m);
if (index >= 0) {
remove(index);
}
}
}
Removes the specified menu component from this menu bar. |
public void removeNotify() {
synchronized (getTreeLock()) {
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
getMenu(i).removeNotify();
}
super.removeNotify();
}
}
Removes the menu bar's peer. The peer allows us to change the
appearance of the menu bar without changing any of the menu bar's
functionality. |
public void setHelpMenu(Menu m) {
synchronized (getTreeLock()) {
if (helpMenu == m) {
return;
}
if (helpMenu != null) {
remove(helpMenu);
}
if (m.parent != this) {
add(m);
}
helpMenu = m;
if (m != null) {
m.isHelpMenu = true;
m.parent = this;
MenuBarPeer peer = (MenuBarPeer)this.peer;
if (peer != null) {
if (m.peer == null) {
m.addNotify();
}
peer.addHelpMenu(m);
}
}
}
}
Sets the specified menu to be this menu bar's help menu.
If this menu bar has an existing help menu, the old help menu is
removed from the menu bar, and replaced with the specified menu. |
public synchronized Enumeration<MenuShortcut> shortcuts() {
Vector shortcuts = new Vector();
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
Enumeration e = getMenu(i).shortcuts();
while (e.hasMoreElements()) {
shortcuts.addElement(e.nextElement());
}
}
return shortcuts.elements();
}
Gets an enumeration of all menu shortcuts this menu bar
is managing. |