1 |
/* MenuBar.java -- An AWT menu bar class |
/* MenuBar.java -- An AWT menu bar class |
2 |
Copyright (C) 1999 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
* This class implements a menu bar in the AWT system. |
* This class implements a menu bar in the AWT system. |
39 |
* |
* |
40 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
41 |
|
* @author Tom Tromey <tromey@redhat.com> |
42 |
*/ |
*/ |
43 |
public class MenuBar extends MenuComponent implements MenuContainer, Serializable |
public class MenuBar extends MenuComponent |
44 |
|
implements MenuContainer, Serializable |
45 |
{ |
{ |
46 |
|
|
47 |
/* |
/* |
106 |
* @param helpMenu The new help menu for this menu bar. |
* @param helpMenu The new help menu for this menu bar. |
107 |
*/ |
*/ |
108 |
public synchronized void |
public synchronized void |
109 |
setHelpMenu(Menu helpMenu) |
setHelpMenu(Menu menu) |
110 |
{ |
{ |
111 |
// FIXME: Does this need to be added to the vector of items? |
if (helpMenu != null) |
112 |
this.helpMenu = helpMenu; |
{ |
113 |
|
helpMenu.removeNotify (); |
114 |
|
helpMenu.parent = null; |
115 |
|
} |
116 |
|
|
117 |
MenuBarPeer mbp = (MenuBarPeer)getPeer(); |
if (menu.parent != null) |
118 |
if (mbp != null) |
menu.parent.remove (menu); |
119 |
mbp.addHelpMenu(helpMenu); |
if (menu.parent != null) |
120 |
|
menu.parent.remove (menu); |
121 |
|
menu.parent = this; |
122 |
|
|
123 |
|
if (peer != null) |
124 |
|
{ |
125 |
|
MenuBarPeer mp = (MenuBarPeer) peer; |
126 |
|
mp.addHelpMenu (menu); |
127 |
|
} |
128 |
} |
} |
129 |
|
|
130 |
/*************************************************************************/ |
/*************************************************************************/ |
131 |
|
|
132 |
/** |
/** Add a menu to this MenuBar. If the menu has already has a |
133 |
* Adds the specified menu to this menu bar. |
* parent, it is first removed from its old parent before being |
134 |
* |
* added. |
135 |
* @param menu The menu to add. |
* |
136 |
* |
* @param menu The menu to add. |
137 |
* @return The menu that was added. |
* |
138 |
*/ |
* @return The menu that was added. |
139 |
|
*/ |
140 |
public synchronized Menu |
public synchronized Menu |
141 |
add(Menu menu) |
add(Menu menu) |
142 |
{ |
{ |
143 |
|
if (menu.parent != null) |
144 |
|
menu.parent.remove (menu); |
145 |
|
|
146 |
|
menu.parent = this; |
147 |
menus.addElement(menu); |
menus.addElement(menu); |
148 |
|
|
149 |
MenuBarPeer mbp = (MenuBarPeer)getPeer(); |
if (peer != null) |
150 |
if (mbp != null) |
{ |
151 |
mbp.addMenu(menu); |
MenuBarPeer mp = (MenuBarPeer) peer; |
152 |
|
mp.addMenu (menu); |
153 |
|
} |
154 |
|
|
155 |
return(menu); |
return(menu); |
156 |
} |
} |
165 |
public synchronized void |
public synchronized void |
166 |
remove(int index) |
remove(int index) |
167 |
{ |
{ |
168 |
menus.removeElementAt(index); |
Menu m = (Menu) menus.get (index); |
169 |
|
menus.remove (index); |
170 |
|
m.removeNotify (); |
171 |
|
m.parent = null; |
172 |
|
|
173 |
MenuBarPeer mbp = (MenuBarPeer)getPeer(); |
if (peer != null) |
174 |
if (mbp != null) |
{ |
175 |
mbp.delMenu(index); |
MenuBarPeer mp = (MenuBarPeer) peer; |
176 |
|
mp.delMenu (index); |
177 |
|
} |
178 |
} |
} |
179 |
|
|
180 |
/*************************************************************************/ |
/*************************************************************************/ |
320 |
public void |
public void |
321 |
deleteShortcut(MenuShortcut shortcut) |
deleteShortcut(MenuShortcut shortcut) |
322 |
{ |
{ |
323 |
MenuItem mi = getShortcutMenuItem(shortcut); |
MenuItem it; |
324 |
if (mi != null) |
// This is a slow implementation, but it probably doesn't matter. |
325 |
mi.setShortcut(null); |
while ((it = getShortcutMenuItem (shortcut)) != null) |
326 |
|
it.deleteShortcut (); |
327 |
} |
} |
328 |
|
|
329 |
} // class MenuBar |
} // class MenuBar |
|
|
|