| Method from java.awt.Menu Detail: |
public MenuItem add(MenuItem mi) {
synchronized (getTreeLock()) {
if (mi.parent != null) {
mi.parent.remove(mi);
}
items.addElement(mi);
mi.parent = this;
MenuPeer peer = (MenuPeer)this.peer;
if (peer != null) {
mi.addNotify();
peer.addItem(mi);
}
return mi;
}
}
Adds the specified menu item to this menu. If the
menu item has been part of another menu, removes it
from that menu. |
public void add(String label) {
add(new MenuItem(label));
}
Adds an item with the specified label to this menu. |
public void addNotify() {
synchronized (getTreeLock()) {
if (peer == null)
peer = Toolkit.getDefaultToolkit().createMenu(this);
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
mi.parent = this;
mi.addNotify();
}
}
}
Creates the menu's peer. The peer allows us to modify the
appearance of the menu without changing its functionality. |
public void addSeparator() {
add("-");
}
Adds a separator line, or a hypen, to the menu at the current position. |
String constructComponentName() {
synchronized (Menu.class) {
return base + nameCounter++;
}
}
Construct a name for this MenuComponent. Called by getName() when
the name is null. |
public int countItems() {
return countItemsImpl();
} Deprecated! As - of JDK version 1.1,
replaced by getItemCount().
|
final int countItemsImpl() {
return items.size();
}
|
void deleteShortcut(MenuShortcut s) {
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
getItem(i).deleteShortcut(s);
}
}
|
int getAccessibleChildIndex(MenuComponent child) {
return items.indexOf(child);
}
Defined in MenuComponent. Overridden here. |
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTMenu();
}
return accessibleContext;
}
Gets the AccessibleContext associated with this Menu.
For menus, the AccessibleContext takes the form of an
AccessibleAWTMenu.
A new AccessibleAWTMenu instance is created if necessary. |
public MenuItem getItem(int index) {
return getItemImpl(index);
}
Gets the item located at the specified index of this menu. |
public int getItemCount() {
return countItems();
}
Get the number of items in this menu. |
final MenuItem getItemImpl(int index) {
return (MenuItem)items.elementAt(index);
}
|
MenuItem getShortcutMenuItem(MenuShortcut s) {
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i).getShortcutMenuItem(s);
if (mi != null) {
return mi;
}
}
return null;
}
|
boolean handleShortcut(KeyEvent e) {
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
if (mi.handleShortcut(e)) {
return true;
}
}
return false;
}
|
public void insert(MenuItem menuitem,
int index) {
synchronized (getTreeLock()) {
if (index < 0) {
throw new IllegalArgumentException("index less than zero.");
}
int nitems = getItemCount();
Vector tempItems = new Vector();
/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
remove(index);
}
add(menuitem);
/* Add the removed items back to the menu, they are
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add((MenuItem)tempItems.elementAt(i));
}
}
}
Inserts a menu item into this menu
at the specified position. |
public void insert(String label,
int index) {
insert(new MenuItem(label), index);
}
Inserts a menu item with the specified label into this menu
at the specified position. This is a convenience method for
insert(menuItem, index). |
public void insertSeparator(int index) {
synchronized (getTreeLock()) {
if (index < 0) {
throw new IllegalArgumentException("index less than zero.");
}
int nitems = getItemCount();
Vector tempItems = new Vector();
/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
remove(index);
}
addSeparator();
/* Add the removed items back to the menu, they are
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add((MenuItem)tempItems.elementAt(i));
}
}
}
Inserts a separator at the specified position. |
public boolean isTearOff() {
return tearOff;
}
Indicates whether this menu is a tear-off menu.
Tear-off functionality may not be supported by all
implementations of AWT. If a particular implementation doesn't
support tear-off menus, this value is silently ignored. |
public String paramString() {
String str = ",tearOff=" + tearOff+",isHelpMenu=" + isHelpMenu;
return super.paramString() + str;
}
Returns a string representing the state of this Menu.
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null. |
public void remove(int index) {
synchronized (getTreeLock()) {
MenuItem mi = getItem(index);
items.removeElementAt(index);
MenuPeer peer = (MenuPeer)this.peer;
if (peer != null) {
mi.removeNotify();
mi.parent = null;
peer.delItem(index);
}
}
}
Removes the menu item at the specified index from this menu. |
public void remove(MenuComponent item) {
synchronized (getTreeLock()) {
int index = items.indexOf(item);
if (index >= 0) {
remove(index);
}
}
}
Removes the specified menu item from this menu. |
public void removeAll() {
synchronized (getTreeLock()) {
int nitems = getItemCount();
for (int i = nitems-1 ; i >= 0 ; i--) {
remove(i);
}
}
}
Removes all items from this menu. |
public void removeNotify() {
synchronized (getTreeLock()) {
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
getItem(i).removeNotify();
}
super.removeNotify();
}
}
Removes the menu's peer. The peer allows us to modify the appearance
of the menu without changing its functionality. |
synchronized Enumeration shortcuts() {
Vector shortcuts = new Vector();
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
if (mi instanceof Menu) {
Enumeration e = ((Menu)mi).shortcuts();
while (e.hasMoreElements()) {
shortcuts.addElement(e.nextElement());
}
} else {
MenuShortcut ms = mi.getShortcut();
if (ms != null) {
shortcuts.addElement(ms);
}
}
}
return shortcuts.elements();
}
|