/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.accessibility.*;
/**
* The <code>MenuBar</code> class encapsulates the platform's
* concept of a menu bar bound to a frame. In order to associate
* the menu bar with a <code>Frame</code> object, call the
* frame's <code>setMenuBar</code> method.
* <p>
* <A NAME="mbexample"></A><!-- target for cross references -->
* This is what a menu bar might look like:
* <p>
* <img src="doc-files/MenuBar-1.gif"
* <alt="Diagram of MenuBar containing 2 menus: Examples and Options.
* Examples menu is expanded showing items: Basic, Simple, Check, and More Examples."
* ALIGN=center HSPACE=10 VSPACE=7>
* <p>
* A menu bar handles keyboard shortcuts for menu items, passing them
* along to its child menus.
* (Keyboard shortcuts, which are optional, provide the user with
* an alternative to the mouse for invoking a menu item and the
* action that is associated with it.)
* Each menu item can maintain an instance of <code>MenuShortcut</code>.
* The <code>MenuBar</code> class defines several methods,
* {@link MenuBar#shortcuts} and
* {@link MenuBar#getShortcutMenuItem}
* that retrieve information about the shortcuts a given
* menu bar is managing.
*
* @author Sami Shaio
* @see java.awt.Frame
* @see java.awt.Frame#setMenuBar(java.awt.MenuBar)
* @see java.awt.Menu
* @see java.awt.MenuItem
* @see java.awt.MenuShortcut
* @since JDK1.0
*/
static {
/* ensure that the necessary native libraries are loaded */
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
new AWTAccessor.MenuBarAccessor() {
}
}
});
}
/**
* This field represents a vector of the
* actual menus that will be part of the MenuBar.
*
* @serial
* @see #countMenus()
*/
/**
* This menu is a special menu dedicated to
* help. The one thing to note about this menu
* is that on some platforms it appears at the
* right edge of the menubar.
*
* @serial
* @see #getHelpMenu()
* @see #setHelpMenu(Menu)
*/
/*
* JDK 1.1 serialVersionUID
*/
/**
* Creates a new menu bar.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
}
/**
* Construct a name for this MenuComponent. Called by getName() when
* the name is null.
*/
synchronized (MenuBar.class) {
return base + nameCounter++;
}
}
/**
* 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.
*/
public void addNotify() {
synchronized (getTreeLock()) {
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
}
}
}
/**
* 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 removeNotify() {
synchronized (getTreeLock()) {
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
getMenu(i).removeNotify();
}
super.removeNotify();
}
}
/**
* Gets the help menu on the menu bar.
* @return the help menu on this menu bar.
*/
return helpMenu;
}
/**
* 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.
* @param m the menu to be set as the help menu
*/
synchronized (getTreeLock()) {
if (helpMenu == m) {
return;
}
}
if (m.parent != this) {
add(m);
}
helpMenu = m;
if (m != null) {
m.isHelpMenu = true;
m.parent = this;
m.addNotify();
}
peer.addHelpMenu(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.
*
* @param m the menu to be added
* @return the menu added
* @see java.awt.MenuBar#remove(int)
* @see java.awt.MenuBar#remove(java.awt.MenuComponent)
*/
synchronized (getTreeLock()) {
}
menus.addElement(m);
m.parent = this;
m.addNotify();
}
}
return m;
}
}
/**
* Removes the menu located at the specified
* index from this menu bar.
* @param index the position of the menu to be removed.
* @see java.awt.MenuBar#add(java.awt.Menu)
*/
synchronized (getTreeLock()) {
m.removeNotify();
}
}
}
/**
* Removes the specified menu component from this menu bar.
* @param m the menu component to be removed.
* @see java.awt.MenuBar#add(java.awt.Menu)
*/
synchronized (getTreeLock()) {
if (index >= 0) {
}
}
}
/**
* Gets the number of menus on the menu bar.
* @return the number of menus on the menu bar.
* @since JDK1.1
*/
public int getMenuCount() {
return countMenus();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getMenuCount()</code>.
*/
public int countMenus() {
return getMenuCountImpl();
}
/*
* This is called by the native code, so client code can't
* be called on the toolkit thread.
*/
final int getMenuCountImpl() {
}
/**
* Gets the specified menu.
* @param i the index position of the menu to be returned.
* @return the menu at the specified index of this menu bar.
*/
return getMenuImpl(i);
}
/*
* This is called by the native code, so client code can't
* be called on the toolkit thread.
*/
}
/**
* Gets an enumeration of all menu shortcuts this menu bar
* is managing.
* @return an enumeration of menu shortcuts that this
* menu bar is managing.
* @see java.awt.MenuShortcut
* @since JDK1.1
*/
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
while (e.hasMoreElements()) {
}
}
}
/**
* Gets the instance of <code>MenuItem</code> associated
* with the specified <code>MenuShortcut</code> object,
* or <code>null</code> if none of the menu items being managed
* by this menu bar is associated with the specified menu
* shortcut.
* @param s the specified menu shortcut.
* @see java.awt.MenuItem
* @see java.awt.MenuShortcut
* @since JDK1.1
*/
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
return mi;
}
}
return null; // MenuShortcut wasn't found
}
/*
* Post an ACTION_EVENT to the target of the MenuPeer
* associated with the specified keyboard event (on
* keydown). Returns true if there is an associated
* keyboard event.
*/
// Is it a key event?
return false;
}
// Is the accelerator modifier key pressed?
return false;
}
// Pass MenuShortcut on to child menus.
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
if (m.handleShortcut(e)) {
return true;
}
}
return false;
}
/**
* Deletes the specified menu shortcut.
* @param s the menu shortcut to delete.
* @since JDK1.1
*/
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
getMenu(i).deleteShortcut(s);
}
}
/* Serialization support. Restore the (transient) parent
* fields of Menubar menus here.
*/
/**
* The MenuBar's serialized data version.
*
* @serial
*/
/**
* Writes default serializable fields to stream.
*
* @param s the <code>ObjectOutputStream</code> to write
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see #readObject(java.io.ObjectInputStream)
*/
{
s.defaultWriteObject();
}
/**
* Reads the <code>ObjectInputStream</code>.
* Unrecognized keys or values will be ignored.
*
* @param s the <code>ObjectInputStream</code> to read
* @exception HeadlessException if
* <code>GraphicsEnvironment.isHeadless</code> returns
* <code>true</code>
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #writeObject(java.io.ObjectOutputStream)
*/
{
// HeadlessException will be thrown from MenuComponent's readObject
s.defaultReadObject();
m.parent = this;
}
}
/**
* Initialize JNI field and method IDs
*/
private static native void initIDs();
/////////////////
// Accessibility support
////////////////
/**
* 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.
*
* @return an AccessibleAWTMenuBar that serves as the
* AccessibleContext of this MenuBar
* @since 1.3
*/
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTMenuBar();
}
return accessibleContext;
}
/**
* Defined in MenuComponent. Overridden here.
*/
}
/**
* Inner class of MenuBar used to provide default support for
* accessibility. This class is not meant to be used directly by
* application developers, but is instead meant only to be
* subclassed by menu component developers.
* <p>
* This class implements accessibility support for the
* <code>MenuBar</code> class. It provides an implementation of the
* Java Accessibility API appropriate to menu bar user-interface elements.
* @since 1.3
*/
{
/*
* JDK 1.3 serialVersionUID
*/
/**
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
* @since 1.4
*/
return AccessibleRole.MENU_BAR;
}
} // class AccessibleAWTMenuBar
}