/*
* 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.*;
/**
* An implementation of a menu -- a popup window containing
* <code>JMenuItem</code>s that
* is displayed when the user selects an item on the <code>JMenuBar</code>.
* In addition to <code>JMenuItem</code>s, a <code>JMenu</code> can
* also contain <code>JSeparator</code>s.
* <p>
* In essence, a menu is a button with an associated <code>JPopupMenu</code>.
* When the "button" is pressed, the <code>JPopupMenu</code> appears. If the
* "button" is on the <code>JMenuBar</code>, the menu is a top-level window.
* If the "button" is another menu item, then the <code>JPopupMenu</code> is
* "pull-right" menu.
* <p>
* Menus can be configured, and to some degree controlled, by
* <code><a href="Action.html">Action</a></code>s. Using an
* <code>Action</code> with a menu has many benefits beyond directly
* configuring a menu. Refer to <a href="Action.html#buttonActions">
* Swing Components Supporting <code>Action</code></a> for more
* details, and you can find more information in <a
* to Use Actions</a>, a section in <em>The Java Tutorial</em>.
* <p>
* For information and examples of using menus see
* <a href="http://java.sun.com/doc/books/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
* a section in <em>The Java Tutorial.</em>
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
* Policy</a>.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer true
* description: A popup window containing menu items displayed in a menu bar.
*
* @author Georges Saab
* @author David Karlton
* @author Arnaud Weber
* @see JMenuItem
* @see JSeparator
* @see JMenuBar
* @see JPopupMenu
*/
{
/**
* @see #getUIClassID
* @see #readObject
*/
/*
* The popup menu portion of the menu.
*/
/*
* The button's model listeners. Default is <code>null</code>.
*/
/*
* Only one <code>MenuEvent</code> is needed for each menu since the
* event's only state is the source property. The source of events
* generated is always "this". Default is <code>null</code>.
*/
/* Registry of listeners created for <code>Action-JMenuItem</code>
* linkage. This is needed so that references can
* be cleaned up at remove time to allow garbage collection
* Default is <code>null</code>.
*/
/*
* Used by the look and feel (L&F) code to handle
* implementation specific menu behaviors.
*/
private int delay;
/*
* Location of the popup component. Location is <code>null</code>
* if it was not customized by <code>setMenuLocation</code>
*/
/* Diagnostic aids -- should be false for production builds. */
/**
* Constructs a new <code>JMenu</code> with no text.
*/
public JMenu() {
this("");
}
/**
* Constructs a new <code>JMenu</code> with the supplied string
* as its text.
*
* @param s the text for the menu label
*/
super(s);
}
/**
* Constructs a menu whose properties are taken from the
* <code>Action</code> supplied.
* @param a an <code>Action</code>
*
* @since 1.3
*/
this();
setAction(a);
}
/**
* Constructs a new <code>JMenu</code> with the supplied string as
* its text and specified as a tear-off menu or not.
*
* @param s the text for the menu label
* @param b can the menu be torn off (not yet implemented)
*/
this(s);
}
/**
* Overriden to do nothing. We want JMenu to be focusable, but
* <code>JMenuItem</code> doesn't want to be, thus we override this
* do nothing. We don't invoke <code>setFocusable(true)</code> after
* super's constructor has completed as this has the side effect that
* <code>JMenu</code> will be considered traversable via the
* keyboard, which we don't want. Making a Component traversable by
* the keyboard after invoking <code>setFocusable(true)</code> is OK,
* as <code>setFocusable</code> is new API
* and is speced as such, but internally we don't want to use it like
* this else we change the keyboard traversability.
*/
void initFocusability() {
}
/**
* Resets the UI property with a value from the current look and feel.
*
* @see JComponent#updateUI
*/
public void updateUI() {
{
}
}
/**
* Returns the name of the L&F class that renders this component.
*
* @return the string "MenuUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
return uiClassID;
}
// public void repaint(long tm, int x, int y, int width, int height) {
// Thread.currentThread().dumpStack();
// super.repaint(tm,x,y,width,height);
// }
/**
* Sets the data model for the "menu button" -- the label
* that the user clicks to open or close the menu.
*
* @param newModel the <code>ButtonModel</code>
* @see #getModel
* @beaninfo
* description: The menu's model
* bound: true
* expert: true
* hidden: true
*/
}
}
}
/**
* Returns true if the menu is currently selected (highlighted).
*
* @return true if the menu is selected, else false
*/
public boolean isSelected() {
return getModel().isSelected();
}
/**
* Sets the selection status of the menu.
*
* @param b true to select (highlight) the menu; false to de-select
* the menu
* @beaninfo
* description: When the menu is selected, its popup child is shown.
* expert: true
* hidden: true
*/
public void setSelected(boolean b) {
// TIGER - 4840653
// Removed code which fired an AccessibleState.SELECTED
// PropertyChangeEvent since this resulted in two
// identical events being fired since
// AbstractButton.fireItemStateChanged also fires the
// same event. This caused screen readers to speak the
// name of the item twice.
if (b != model.isSelected()) {
getModel().setSelected(b);
}
}
/**
* Returns true if the menu's popup window is visible.
*
* @return true if the menu is visible, else false
*/
public boolean isPopupMenuVisible() {
}
/**
* Sets the visibility of the menu's popup. If the menu is
* not enabled, this method will have no effect.
*
* @param b a boolean value -- true to make the menu visible,
* false to hide it
* @beaninfo
* description: The popup menu's visibility
* expert: true
* hidden: true
*/
public void setPopupMenuVisible(boolean b) {
if (DEBUG) {
// Thread.dumpStack();
}
boolean isVisible = isPopupMenuVisible();
if ((b==true) && isShowing()) {
// Set location of popupMenu (pulldown or pullright)
Point p = getCustomMenuLocation();
if (p == null) {
p = getPopupMenuOrigin();
}
getPopupMenu().show(this, p.x, p.y);
} else {
getPopupMenu().setVisible(false);
}
}
}
/**
* Computes the origin for the <code>JMenu</code>'s popup menu.
* This method uses Look and Feel properties named
* <code>Menu.menuPopupOffsetX</code>,
* <code>Menu.menuPopupOffsetY</code>,
* <code>Menu.submenuPopupOffsetX</code>, and
* <code>Menu.submenuPopupOffsetY</code>
* to adjust the exact location of popup.
*
* @return a <code>Point</code> in the coordinate space of the
* menu which should be used as the origin
* of the <code>JMenu</code>'s popup menu
*
* @since 1.3
*/
int x;
int y;
// Figure out the sizes needed to caclulate the menu position
// For the first time the menu is popped up,
// the size has not yet been initiated
}
gd[i].getDefaultConfiguration();
break;
}
}
}
// take screen insets (e.g. taskbar) into account
}
if (parent instanceof JPopupMenu) {
// We are a submenu (pull-right)
if( SwingUtilities.isLeftToRight(this) ) {
// First determine x:
+ screenBounds.x &&
// popup doesn't fit - place it wherever there's more room
- screenBounds.x)) {
}
} else {
// First determine x:
if (position.x + x < screenBounds.x &&
// popup doesn't fit - place it wherever there's more room
screenBounds.x)) {
}
}
// Then the y:
y = yOffset; // Prefer dropping down
+ screenBounds.y &&
// popup doesn't fit - place it wherever there's more room
- screenBounds.y)) {
}
} else {
// We are a toplevel menu (pull-down)
if( SwingUtilities.isLeftToRight(this) ) {
// First determine the x:
x = xOffset; // Extend to the right
+ screenBounds.x &&
// popup doesn't fit - place it wherever there's more room
- screenBounds.x)) {
}
} else {
// First determine the x:
if (position.x + x < screenBounds.x &&
// popup doesn't fit - place it wherever there's more room
- screenBounds.x)) {
x = xOffset;
}
}
// Then the y:
// popup doesn't fit - place it wherever there's more room
- screenBounds.y)) {
}
}
return new Point(x,y);
}
/**
* Returns the suggested delay, in milliseconds, before submenus
* are popped up or down.
* Each look and feel (L&F) may determine its own policy for
* observing the <code>delay</code> property.
* In most cases, the delay is not observed for top level menus
* or while dragging. The default for <code>delay</code> is 0.
* This method is a property of the look and feel code and is used
* to manage the idiosyncracies of the various UI implementations.
*
*
* @return the <code>delay</code> property
*/
public int getDelay() {
return delay;
}
/**
* Sets the suggested delay before the menu's <code>PopupMenu</code>
* is popped up or down. Each look and feel (L&F) may determine
* it's own policy for observing the delay property. In most cases,
* the delay is not observed for top level menus or while dragging.
* This method is a property of the look and feel code and is used
* to manage the idiosyncracies of the various UI implementations.
*
* @param d the number of milliseconds to delay
* @exception IllegalArgumentException if <code>d</code>
* is less than 0
* @beaninfo
* description: The delay between menu selection and making the popup menu visible
* expert: true
*/
public void setDelay(int d) {
if (d < 0)
throw new IllegalArgumentException("Delay must be a positive integer");
delay = d;
}
/**
* The window-closing listener for the popup.
*
* @see WinListener
*/
private void ensurePopupMenuCreated() {
this.popupMenu = new JPopupMenu();
popupMenu.setInvoker(this);
}
}
/*
* Return the customized location of the popup component.
*/
return customMenuLocation;
}
/**
* Sets the location of the popup component.
*
* @param x the x coordinate of the popup's new position
* @param y the y coordinate of the popup's new position
*/
public void setMenuLocation(int x, int y) {
customMenuLocation = new Point(x, y);
popupMenu.setLocation(x, y);
}
/**
* Appends a menu item to the end of this menu.
* Returns the menu item added.
*
* @param menuItem the <code>JMenuitem</code> to be added
* @return the <code>JMenuItem</code> added
*/
}
/**
* Appends a component to the end of this menu.
* Returns the component added.
*
* @param c the <code>Component</code> to add
* @return the <code>Component</code> added
*/
return c;
}
/**
* Adds the specified component to this container at the given
* position. If <code>index</code> equals -1, the component will
* be appended to the end.
* @param c the <code>Component</code> to add
* @param index the position at which to insert the component
* @return the <code>Component</code> added
* @see #remove
* @see java.awt.Container#add(Component, int)
*/
return c;
}
/**
* Creates a new menu item with the specified text and appends
* it to the end of this menu.
*
* @param s the string for the menu item to be added
*/
}
/**
* Creates a new menu item attached to the specified
* <code>Action</code> object and appends it to the end of this menu.
*
* @param a the <code>Action</code> for the menu item to be added
* @see Action
*/
return mi;
}
/**
* Factory method which creates the <code>JMenuItem</code> for
* <code>Action</code>s added to the <code>JMenu</code>.
*
* @param a the <code>Action</code> for the menu item to be added
* @return the new menu item
* @see Action
*
* @since 1.3
*/
pcl = super.createActionPropertyChangeListener(a);
}
return pcl;
}
};
return mi;
}
/**
* Returns a properly configured <code>PropertyChangeListener</code>
* which updates the control as changes to the <code>Action</code> occur.
*/
return b.createActionPropertyChangeListener0(b.getAction());
}
/**
* Appends a new separator to the end of the menu.
*/
public void addSeparator()
{
}
/**
* Inserts a new menu item with the specified text at a
* given position.
*
* @param s the text for the menu item to add
* @param pos an integer specifying the position at which to add the
* new menu item
* @exception IllegalArgumentException when the value of
* <code>pos</code> < 0
*/
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
}
/**
* Inserts the specified <code>JMenuitem</code> at a given position.
*
* @param mi the <code>JMenuitem</code> to add
* @param pos an integer specifying the position at which to add the
* new <code>JMenuitem</code>
* @return the new menu item
* @exception IllegalArgumentException if the value of
* <code>pos</code> < 0
*/
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
return mi;
}
/**
* Inserts a new menu item attached to the specified <code>Action</code>
* object at a given position.
*
* @param a the <code>Action</code> object for the menu item to add
* @param pos an integer specifying the position at which to add the
* new menu item
* @exception IllegalArgumentException if the value of
* <code>pos</code> < 0
*/
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
return mi;
}
/**
* Inserts a separator at the specified position.
*
* @param index an integer specifying the position at which to
* insert the menu separator
* @exception IllegalArgumentException if the value of
* <code>index</code> < 0
*/
if (index < 0) {
throw new IllegalArgumentException("index less than zero.");
}
}
/**
* Returns the <code>JMenuItem</code> at the specified position.
* If the component at <code>pos</code> is not a menu item,
* <code>null</code> is returned.
* This method is included for AWT compatibility.
*
* @param pos an integer specifying the position
* @exception IllegalArgumentException if the value of
* <code>pos</code> < 0
* @return the menu item at the specified position; or <code>null</code>
* if the item as the specified position is not a menu item
*/
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
if (c instanceof JMenuItem) {
return mi;
}
// 4173633
return null;
}
/**
* Returns the number of items on the menu, including separators.
* This method is included for AWT compatibility.
*
* @return an integer equal to the number of items on the menu
* @see #getMenuComponentCount
*/
public int getItemCount() {
return getMenuComponentCount();
}
/**
* Returns true if the menu can be torn off. This method is not
* yet implemented.
*
* @return true if the menu can be torn off, else false
* @exception Error if invoked -- this method is not yet implemented
*/
public boolean isTearOff() {
throw new Error("boolean isTearOff() {} not yet implemented");
}
/**
* Removes the specified menu item from this menu. If there is no
* popup menu, this method will have no effect.
*
* @param item the <code>JMenuItem</code> to be removed from the menu
*/
}
/**
* Removes the menu item at the specified index from this menu.
*
* @param pos the position of the item to be removed
* @exception IllegalArgumentException if the value of
* <code>pos</code> < 0, or if <code>pos</code>
* is greater than the number of menu items
*/
if (pos < 0) {
throw new IllegalArgumentException("index less than zero.");
}
if (pos > getItemCount()) {
throw new IllegalArgumentException("index greater than the number of items.");
}
}
/**
* Removes the component <code>c</code> from this menu.
*
* @param c the component to be removed
*/
}
/**
* Removes all menu items from this menu.
*/
public void removeAll() {
}
/**
* Returns the number of components on the menu.
*
* @return an integer containing the number of components on the menu
*/
public int getMenuComponentCount() {
int componentCount = 0;
return componentCount;
}
/**
* Returns the component at position <code>n</code>.
*
* @param n the position of the component to be returned
* @return the component requested, or <code>null</code>
* if there is no popup menu
*
*/
return popupMenu.getComponent(n);
return null;
}
/**
* Returns an array of <code>Component</code>s of the menu's
* subcomponents. Note that this returns all <code>Component</code>s
* in the popup menu, including separators.
*
* @return an array of <code>Component</code>s or an empty array
* if there is no popup menu
*/
return popupMenu.getComponents();
return new Component[0];
}
/**
* Returns true if the menu is a 'top-level menu', that is, if it is
* the direct child of a menubar.
*
* @return true if the menu is activated from the menu bar;
* false if the menu is activated from a menu item
* on another menu
*/
public boolean isTopLevelMenu() {
}
/**
* Returns true if the specified component exists in the
* submenu hierarchy.
*
* @param c the <code>Component</code> to be tested
* @return true if the <code>Component</code> exists, false otherwise
*/
// Are we in the MenuItem part of the menu
if (c == this)
return true;
// Are we in the PopupMenu?
if (c instanceof JPopupMenu) {
if (comp == this.getPopupMenu())
return true;
}
// Are we in a Component on the PopupMenu
int ncomponents = this.getMenuComponentCount();
for (int i = 0 ; i < ncomponents ; i++) {
// Are we in the current component?
if (comp == c)
return true;
// Hmmm, what about Non-menu containers?
// Recursive call for the Menu case
if (subMenu.isMenuComponent(c))
return true;
}
}
return false;
}
/*
* Returns a point in the coordinate space of this menu's popupmenu
* which corresponds to the point <code>p</code> in the menu's
* coordinate space.
*
* @param p the point to be translated
* @return the point in the coordinate space of this menu's popupmenu
*/
return translateToPopupMenu(p.x, p.y);
}
/*
* Returns a point in the coordinate space of this menu's popupmenu
* which corresponds to the point (x,y) in the menu's coordinate space.
*
* @param x the x coordinate of the point to be translated
* @param y the y coordinate of the point to be translated
* @return the point in the coordinate space of this menu's popupmenu
*/
int newX;
int newY;
if (getParent() instanceof JPopupMenu) {
newY = y;
} else {
newX = x;
}
}
/**
* Returns the popupmenu associated with this menu. If there is
* no popupmenu, it will create one.
*/
return popupMenu;
}
/**
* Adds a listener for menu events.
*
* @param l the listener to be added
*/
}
/**
* Removes a listener for menu events.
*
* @param l the listener to be removed
*/
}
/**
* Returns an array of all the <code>MenuListener</code>s added
* to this JMenu with addMenuListener().
*
* @return all of the <code>MenuListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
* is created lazily.
*
* @exception Error if there is a <code>null</code> listener
* @see EventListenerList
*/
protected void fireMenuSelected() {
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuListener.class) {
} else {
// Lazily create the event:
}
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
* is created lazily.
*
* @exception Error if there is a <code>null</code> listener
* @see EventListenerList
*/
protected void fireMenuDeselected() {
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuListener.class) {
} else {
// Lazily create the event:
}
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
* is created lazily.
*
* @exception Error if there is a <code>null</code> listener
* @see EventListenerList
*/
protected void fireMenuCanceled() {
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuListener.class) {
+ i);
} else {
// Lazily create the event:
}
}
}
}
// Overriden to do nothing, JMenu doesn't support an accelerator
}
boolean isSelected = false;
if (modelSelected != isSelected) {
if (modelSelected == true) {
} else {
}
}
}
}
return new MenuChangeListener();
}
/**
* Creates a window-closing listener for the popup.
*
* @param p the <code>JPopupMenu</code>
* @return the new window-closing listener
*
* @see WinListener
*/
return new WinListener(p);
}
/**
* A listener class that watches for a popup window closing.
* When the popup is closing, the listener deselects the menu.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
/**
* Create the window listener for the specified popup.
* @since 1.4
*/
this.popupMenu = p;
}
/**
* Deselect the menu when the popup is closed from outside.
*/
setSelected(false);
}
}
/**
* Messaged when the menubar selection changes to activate or
* deactivate this menu.
* Overrides <code>JMenuItem.menuSelectionChanged</code>.
*
* @param isIncluded true if this menu is active, false if
* it is not
*/
if (DEBUG) {
}
}
/**
* Returns an array of <code>MenuElement</code>s containing the submenu
* for this menu component. If popup menu is <code>null</code> returns
* an empty array. This method is required to conform to the
* <code>MenuElement</code> interface. Note that since
* <code>JSeparator</code>s do not conform to the <code>MenuElement</code>
* interface, this array will only contain <code>JMenuItem</code>s.
*
* @return an array of <code>MenuElement</code> objects
*/
return new MenuElement[0];
else {
return result;
}
}
// implements javax.swing.MenuElement
/**
* Returns the <code>java.awt.Component</code> used to
* paint this <code>MenuElement</code>.
* The returned component is used to convert events and detect if
* an event is inside a menu component.
*/
return this;
}
/**
* Sets the <code>ComponentOrientation</code> property of this menu
* and all components contained within it. This includes all
* components returned by {@link #getMenuComponents getMenuComponents}.
*
* @param o the new component orientation of this menu and
* the components contained within it.
* @exception NullPointerException if <code>orientation</code> is null.
* @see java.awt.Component#setComponentOrientation
* @see java.awt.Component#getComponentOrientation
* @since 1.4
*/
super.applyComponentOrientation(o);
int ncomponents = getMenuComponentCount();
for (int i = 0 ; i < ncomponents ; ++i) {
}
}
}
super.setComponentOrientation(o);
}
}
/**
* <code>setAccelerator</code> is not defined for <code>JMenu</code>.
* Use <code>setMnemonic</code> instead.
* @param keyStroke the keystroke combination which will invoke
* the <code>JMenuItem</code>'s actionlisteners
* without navigating the menu hierarchy
* @exception Error if invoked -- this method is not defined for JMenu.
* Use <code>setMnemonic</code> instead
*
* @beaninfo
* description: The keystroke combination which will invoke the JMenuItem's
* actionlisteners without navigating the menu hierarchy
* hidden: true
*/
throw new Error("setAccelerator() is not defined for JMenu. Use setMnemonic() instead.");
}
/**
* Processes key stroke events such as mnemonics and accelerators.
*
* @param evt the key event to be processed
*/
if (evt.isConsumed())
return;
super.processKeyEvent(evt);
}
/**
* Programmatically performs a "click". This overrides the method
* <code>AbstractButton.doClick</code> in order to make the menu pop up.
* @param pressTime indicates the number of milliseconds the
* button was pressed for
*/
}
/*
* Build an array of menu elements - from <code>PopupMenu</code> to
* the root <code>JMenuBar</code>.
* @param leaf the leaf node from which to start building up the array
* @return the array of menu items
*/
while (true) {
if (current instanceof JPopupMenu) {
return me;
}
}
}
/**
* See <code>readObject</code> and <code>writeObject</code> in
* <code>JComponent</code> for more
* information about serialization in Swing.
*/
s.defaultWriteObject();
}
}
}
/**
* Returns a string representation of this <code>JMenu</code>. 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 <code>null</code>.
*
* @return a string representation of this JMenu.
*/
return super.paramString();
}
/////////////////
// Accessibility support
////////////////
/**
* Gets the AccessibleContext associated with this JMenu.
* For JMenus, the AccessibleContext takes the form of an
* AccessibleJMenu.
* A new AccessibleJMenu instance is created if necessary.
*
* @return an AccessibleJMenu that serves as the
* AccessibleContext of this JMenu
*/
if (accessibleContext == null) {
accessibleContext = new AccessibleJMenu();
}
return accessibleContext;
}
/**
* This class implements accessibility support for the
* <code>JMenu</code> class. It provides an implementation of the
* Java Accessibility API appropriate to menu user-interface elements.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
implements AccessibleSelection {
/**
* Returns the number of accessible children in the object. If all
* of the children of this object implement Accessible, than this
* method should return the number of children of this object.
*
* @return the number of accessible children in the object.
*/
public int getAccessibleChildrenCount() {
int count = 0;
if (child instanceof Accessible) {
count++;
}
}
return count;
}
/**
* Returns the nth Accessible child of the object.
*
* @param i zero-based index of child
* @return the nth Accessible child of the object
*/
int count = 0;
if (child instanceof Accessible) {
if (count == i) {
if (child instanceof JComponent) {
// FIXME: [[[WDW - probably should set this when
// the component is added to the menu. I tried
// to do this in most cases, but the separators
// added by addSeparator are hard to get to.]]]
}
return (Accessible) child;
} else {
count++;
}
}
}
return null;
}
/**
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
* @see AccessibleRole
*/
return AccessibleRole.MENU;
}
/**
* Get the AccessibleSelection associated with this object. In the
* implementation of the Java Accessibility API for this class,
* return this object, which is responsible for implementing the
* AccessibleSelection interface on behalf of itself.
*
* @return this object
*/
return this;
}
/**
* Returns 1 if a sub-menu is currently selected in this menu.
*
* @return 1 if a menu is currently selected, else 0
*/
public int getAccessibleSelectionCount() {
MenuElement me[] =
return 1;
}
}
}
}
return 0;
}
/**
* Returns the currently selected sub-menu if one is selected,
* otherwise null (there can only be one selection, and it can
* only be a sub-menu, as otherwise menu items don't remain
* selected).
*/
// if i is a sub-menu & popped, return it
if (i < 0 || i >= getItemCount()) {
return null;
}
MenuElement me[] =
// so find the next JMenuItem in the MenuElement
// array, and return it!
return (Accessible) me[j];
}
}
}
}
}
return null;
}
/**
* Returns true if the current child of this object is selected
* (that is, if this child is a popped-up submenu).
*
* @param i the zero-based index of the child in this Accessible
* object.
* @see AccessibleContext#getAccessibleChild
*/
public boolean isAccessibleChildSelected(int i) {
// if i is a sub-menu and is pop-ed up, return true, else false
MenuElement me[] =
return true;
}
}
}
return false;
}
/**
* Selects the <code>i</code>th menu in the menu.
* If that item is a submenu,
* it will pop up in response. If a different item is already
* popped up, this will force it to close. If this is a sub-menu
* that is already popped up (selected), this method has no
* effect.
*
* @param i the index of the item to be selected
* @see #getAccessibleStateSet
*/
public void addAccessibleSelection(int i) {
if (i < 0 || i >= getItemCount()) {
return;
}
} else {
}
}
}
/**
* Removes the nth item from the selection. In general, menus
* can only have one item within them selected at a time
* (e.g. one sub-menu popped open).
*
* @param i the zero-based index of the selected item
*/
public void removeAccessibleSelection(int i) {
if (i < 0 || i >= getItemCount()) {
return;
}
if (mi.isSelected()) {
MenuElement old[] =
}
}
}
}
/**
* Clears the selection in the object, so that nothing in the
* object is selected. This will close any open sub-menu.
*/
public void clearAccessibleSelection() {
// if this menu is selected, reset selection to only go
// to this menu; else do nothing
MenuElement old[] =
}
}
}
}
/**
* Normally causes every selected item in the object to be selected
* if the object supports multiple selections. This method
* makes no sense in a menu bar, and so does nothing.
*/
public void selectAllAccessibleSelection() {
}
} // inner class AccessibleJMenu
}