MenuComponent.java revision 1338
0N/A * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * The abstract class <code>MenuComponent</code> is the superclass 0N/A * of all menu-related components. In this respect, the class 0N/A * <code>MenuComponent</code> is analogous to the abstract superclass 0N/A * <code>Component</code> for AWT components. 0N/A * Menu components receive and process AWT events, just as components do, 0N/A * through the method <code>processEvent</code>. 0N/A * @author Arthur van Hoff 0N/A /* ensure that the necessary native libraries are loaded */ 0N/A * The <code>AppContext</code> of the <code>MenuComponent</code>. 0N/A * This is set in the constructor and never changes. 0N/A * The menu component's font. This value can be 0N/A * <code>null</code> at which point a default will be used. 0N/A * This defaults to <code>null</code>. 0N/A * @see #setFont(Font) 0N/A * The menu component's name, which defaults to <code>null</code>. 0N/A * @see #setName(String) 0N/A * A variable to indicate whether a name is explicitly set. 0N/A * If <code>true</code> the name will be set explicitly. 0N/A * This defaults to <code>false</code>. 0N/A * @see #setName(String) 0N/A * Defaults to <code>false</code>. 0N/A * @see #dispatchEvent(AWTEvent) 0N/A * Internal constants for serialization. 0N/A * JDK 1.1 serialVersionUID 0N/A * Creates a <code>MenuComponent</code>. 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> 0N/A * returns <code>true</code> 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * Constructs a name for this <code>MenuComponent</code>. 0N/A * Called by <code>getName</code> when the name is <code>null</code>. 0N/A * @return a name for this <code>MenuComponent</code> 0N/A return null;
// For strict compliance with prior platform versions, a MenuComponent 0N/A // that doesn't set its name should return null from 0N/A * Gets the name of the menu component. 0N/A * @return the name of the menu component 0N/A * @see java.awt.MenuComponent#setName(java.lang.String) 0N/A synchronized(
this) {
0N/A * Sets the name of the component to the specified string. 0N/A * @param name the name of the menu component 0N/A * @see java.awt.MenuComponent#getName 0N/A synchronized(
this) {
0N/A * Returns the parent container for this menu component. 0N/A * @return the menu component containing this menu component, 0N/A * or <code>null</code> if this menu component 0N/A * is the outermost component, the menu bar itself 0N/A // NOTE: This method may be called by privileged threads. 0N/A // This functionality is implemented in a package-private method 0N/A // to insure that it cannot be overridden by client subclasses. 0N/A // DO NOT INVOKE CLIENT CODE ON THIS THREAD! 0N/A * @deprecated As of JDK version 1.1, 0N/A * programs should not directly manipulate peers. 0N/A * Gets the font used for this menu component. 0N/A * @return the font used in this menu component, if there is one; 0N/A * <code>null</code> otherwise 0N/A * @see java.awt.MenuComponent#setFont 0N/A // NOTE: This method may be called by privileged threads. 0N/A // This functionality is implemented in a package-private method 0N/A // to insure that it cannot be overridden by client subclasses. 0N/A // DO NOT INVOKE CLIENT CODE ON THIS THREAD! 0N/A // The MenuContainer interface does not have getFont_NoClientCode() 0N/A // and it cannot, because it must be package-private. Because of 0N/A // this, we must manually cast classes that implement 0N/A }
// getFont_NoClientCode() 0N/A * Sets the font to be used for this menu component to the specified 0N/A * font. This font is also used by all subcomponents of this menu 0N/A * component, unless those subcomponents specify a different font. 0N/A * Some platforms may not support setting of all font attributes 0N/A * of a menu component; in such cases, calling <code>setFont</code> 0N/A * will have no effect on the unsupported font attributes of this 0N/A * menu component. Unless subcomponents of this menu component 0N/A * specify a different font, this font will be used by those 0N/A * subcomponents if supported by the underlying platform. 0N/A * @param f the font to be set 0N/A * @see Font#getAttributes 0N/A * @see java.awt.font.TextAttribute 0N/A //Fixed 6312943: NullPointerException in method MenuComponent.setFont(Font) 0N/A * Removes the menu component's peer. The peer allows us to modify the 0N/A * appearance of the menu component without changing the functionality of 0N/A * the menu component. 0N/A * Posts the specified event to the menu. 0N/A * This method is part of the Java 1.0 event system 0N/A * and it is maintained only for backwards compatibility. 0N/A * Its use is discouraged, and it may not be supported 0N/A * @param evt the event which is to take place 0N/A * @deprecated As of JDK version 1.1, replaced by {@link 0N/A * #dispatchEvent(AWTEvent) dispatchEvent}. 0N/A * Delivers an event to this component or one of its sub components. 0N/A * @param e the event 0N/A }
else {
// backward compatibility 0N/A // REMIND: remove when filtering is done at lower level 0N/A * Processes events occurring on this menu component. 0N/A * <p>Note that if the event parameter is <code>null</code> 0N/A * the behavior is unspecified and may result in an 0N/A * @param e the event 0N/A * Returns a string representing the state of this 0N/A * <code>MenuComponent</code>. This method is intended to be used 0N/A * only for debugging purposes, and the content and format of the 0N/A * returned string may vary between implementations. The returned 0N/A * string may be empty but may not be <code>null</code>. 0N/A * @return the parameter string of this menu component 0N/A * Returns a representation of this menu component as a string. 0N/A * @return a string representation of this menu component 0N/A * Gets this component's locking object (the object that owns the thread 0N/A * sychronization monitor) for AWT component-tree and layout 0N/A * @return this component's locking object 0N/A * Reads the menu component from an object input stream. 0N/A * @param s the <code>ObjectInputStream</code> to read 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * Initialize JNI field and method IDs. 0N/A * --- Accessibility Support --- 0N/A * MenuComponent will contain all of the methods in interface Accessible, 0N/A * though it won't actually implement the interface - that will be up 0N/A * to the individual objects which extend MenuComponent. 0N/A * Gets the <code>AccessibleContext</code> associated with 0N/A * this <code>MenuComponent</code>. 0N/A * The method implemented by this base class returns <code>null</code>. 0N/A * Classes that extend <code>MenuComponent</code> 0N/A * should implement this method to return the 0N/A * <code>AccessibleContext</code> associated with the subclass. 0N/A * @return the <code>AccessibleContext</code> of this 0N/A * <code>MenuComponent</code> 0N/A * Inner class of <code>MenuComponent</code> used to provide 0N/A * default support for accessibility. This class is not meant 0N/A * to be used directly by application developers, but is instead 0N/A * meant only to be subclassed by menu component developers. 0N/A * The class used to obtain the accessible role for this object. 0N/A * JDK 1.3 serialVersionUID 0N/A * Although the class is abstract, this should be called by 0N/A // AccessibleContext methods 0N/A * Gets the <code>AccessibleSelection</code> associated with this 0N/A * object which allows its <code>Accessible</code> children to be selected. 0N/A * @return <code>AccessibleSelection</code> if supported by object; 0N/A * else return <code>null</code> 0N/A * @see AccessibleSelection 0N/A * Gets the accessible name of this object. This should almost never 0N/A * return <code>java.awt.MenuComponent.getName</code>, as that 0N/A * generally isn't a localized name, and doesn't have meaning for the 0N/A * user. If the object is fundamentally a text object (e.g. a menu item), the 0N/A * accessible name should be the text of the object (e.g. "save"). 0N/A * If the object has a tooltip, the tooltip text may also be an 0N/A * appropriate String to return. 0N/A * @return the localized name of the object -- can be <code>null</code> 0N/A * if this object does not have a name 0N/A * @see AccessibleContext#setAccessibleName 0N/A * Gets the accessible description of this object. This should be 0N/A * a concise, localized description of what this object is - what 0N/A * is its meaning to the user. If the object has a tooltip, the 0N/A * tooltip text may be an appropriate string to return, assuming 0N/A * it contains a concise description of the object (instead of just 0N/A * the name of the object - e.g. a "Save" icon on a toolbar that 0N/A * had "save" as the tooltip text shouldn't return the tooltip 0N/A * text as the description, but something like "Saves the current 0N/A * text document" instead). 0N/A * @return the localized description of the object -- can be 0N/A * <code>null</code> if this object does not have a description 0N/A * @see AccessibleContext#setAccessibleDescription 0N/A * Gets the role of this object. 0N/A * @return an instance of <code>AccessibleRole</code> 0N/A * describing the role of the object 0N/A * @see AccessibleRole 0N/A * Gets the state of this object. 0N/A * @return an instance of <code>AccessibleStateSet</code> 0N/A * containing the current state set of the object 0N/A * @see AccessibleState 0N/A * Gets the <code>Accessible</code> parent of this object. 0N/A * If the parent of this object implements <code>Accessible</code>, 0N/A * this method should simply return <code>getParent</code>. 0N/A * @return the <code>Accessible</code> parent of this object -- can 0N/A * be <code>null</code> if this object does not have an 0N/A * <code>Accessible</code> parent 0N/A * Gets the index of this object in its accessible parent. 0N/A * @return the index of this object in its parent; -1 if this 0N/A * object does not have an accessible parent 0N/A * @see #getAccessibleParent 0N/A * Returns the number of accessible children in the object. If all 0N/A * of the children of this object implement <code>Accessible</code>, 0N/A * then this method should return the number of children of this object. 0N/A * @return the number of accessible children in the object 0N/A return 0;
// MenuComponents don't have children 0N/A * Returns the nth <code>Accessible</code> child of the object. 0N/A * @param i zero-based index of child 0N/A * @return the nth Accessible child of the object 0N/A return null;
// MenuComponents don't have children 0N/A * Returns the locale of this object. 0N/A * @return the locale of this object 0N/A * Gets the <code>AccessibleComponent</code> associated with 0N/A * this object if one exists. Otherwise return <code>null</code>. 0N/A * @return the component 0N/A // AccessibleComponent methods 0N/A * Gets the background color of this object. 0N/A * @return the background color, if supported, of the object; 0N/A * otherwise, <code>null</code> 0N/A return null;
// Not supported for MenuComponents 0N/A * Sets the background color of this object. 0N/A * (For transparency, see <code>isOpaque</code>.) 0N/A * @param c the new <code>Color</code> for the background 0N/A * @see Component#isOpaque 0N/A // Not supported for MenuComponents 0N/A * Gets the foreground color of this object. 0N/A * @return the foreground color, if supported, of the object; 0N/A * otherwise, <code>null</code> 0N/A return null;
// Not supported for MenuComponents 0N/A * Sets the foreground color of this object. 0N/A * @param c the new <code>Color</code> for the foreground 0N/A // Not supported for MenuComponents 0N/A * Gets the <code>Cursor</code> of this object. 0N/A * @return the <code>Curso</code>, if supported, of the object; 0N/A * otherwise, <code>null</code> 0N/A return null;
// Not supported for MenuComponents 0N/A * Sets the <code>Cursor</code> of this object. 0N/A * The method may have no visual effect if the Java platform 0N/A * implementation and/or the native system do not support 0N/A * changing the mouse cursor shape. 0N/A * @param cursor the new <code>Cursor</code> for the object 0N/A // Not supported for MenuComponents 0N/A * Gets the <code>Font</code> of this object. 0N/A * @return the <code>Font</code>,if supported, for the object; 0N/A * otherwise, <code>null</code> 0N/A * Sets the <code>Font</code> of this object. 0N/A * @param f the new <code>Font</code> for the object 0N/A * Gets the <code>FontMetrics</code> of this object. 0N/A * @param f the <code>Font</code> 0N/A * @return the FontMetrics, if supported, the object; 0N/A * otherwise, <code>null</code> 0N/A return null;
// Not supported for MenuComponents 0N/A * Determines if the object is enabled. 0N/A * @return true if object is enabled; otherwise, false 0N/A return true;
// Not supported for MenuComponents 0N/A * Sets the enabled state of the object. 0N/A * @param b if true, enables this object; otherwise, disables it 0N/A // Not supported for MenuComponents 0N/A * Determines if the object is visible. Note: this means that the 0N/A * object intends to be visible; however, it may not in fact be 0N/A * showing on the screen because one of the objects that this object 0N/A * is contained by is not visible. To determine if an object is 0N/A * showing on the screen, use <code>isShowing</code>. 0N/A * @return true if object is visible; otherwise, false 0N/A return true;
// Not supported for MenuComponents 0N/A * Sets the visible state of the object. 0N/A * @param b if true, shows this object; otherwise, hides it 0N/A // Not supported for MenuComponents 0N/A * Determines if the object is showing. This is determined by checking 0N/A * the visibility of the object and ancestors of the object. Note: 0N/A * this will return true even if the object is obscured by another 0N/A * (for example, it happens to be underneath a menu that was pulled 0N/A * @return true if object is showing; otherwise, false 0N/A return true;
// Not supported for MenuComponents 0N/A * Checks whether the specified point is within this object's bounds, 0N/A * where the point's x and y coordinates are defined to be relative to 0N/A * the coordinate system of the object. 0N/A * @param p the <code>Point</code> relative to the coordinate 0N/A * system of the object 0N/A * @return true if object contains <code>Point</code>; otherwise false 0N/A return false;
// Not supported for MenuComponents 0N/A * Returns the location of the object on the screen. 0N/A * @return location of object on screen -- can be <code>null</code> 0N/A * if this object is not on the screen 0N/A return null;
// Not supported for MenuComponents 0N/A * Gets the location of the object relative to the parent in the form 0N/A * of a point specifying the object's top-left corner in the screen's 0N/A * @return an instance of <code>Point</code> representing the 0N/A * top-left corner of the object's bounds in the coordinate 0N/A * space of the screen; <code>null</code> if 0N/A * this object or its parent are not on the screen 0N/A return null;
// Not supported for MenuComponents 0N/A * Sets the location of the object relative to the parent. 0N/A // Not supported for MenuComponents 0N/A * Gets the bounds of this object in the form of a 0N/A * <code>Rectangle</code> object. 0N/A * The bounds specify this object's width, height, and location 0N/A * relative to its parent. 0N/A * @return a rectangle indicating this component's bounds; 0N/A * <code>null</code> if this object is not on the screen 0N/A return null;
// Not supported for MenuComponents 0N/A * Sets the bounds of this object in the form of a 0N/A * <code>Rectangle</code> object. 0N/A * The bounds specify this object's width, height, and location 0N/A * relative to its parent. 0N/A * @param r a rectangle indicating this component's bounds 0N/A // Not supported for MenuComponents 0N/A * Returns the size of this object in the form of a 0N/A * <code>Dimension</code> object. The height field of 0N/A * the <code>Dimension</code> object contains this object's 0N/A * height, and the width field of the <code>Dimension</code> 0N/A * object contains this object's width. 0N/A * @return a <code>Dimension</code> object that indicates the 0N/A * size of this component; <code>null</code> 0N/A * if this object is not on the screen 0N/A return null;
// Not supported for MenuComponents 0N/A * Resizes this object. 0N/A * @param d - the <code>Dimension</code> specifying the 0N/A * new size of the object 0N/A // Not supported for MenuComponents 0N/A * Returns the <code>Accessible</code> child, if one exists, 0N/A * contained at the local coordinate <code>Point</code>. 0N/A * If there is no <code>Accessible</code> child, <code>null</code> 0N/A * @param p the point defining the top-left corner of the 0N/A * <code>Accessible</code>, given in the coordinate space 0N/A * of the object's parent 0N/A * @return the <code>Accessible</code>, if it exists, 0N/A * at the specified location; else <code>null</code> 0N/A return null;
// MenuComponents don't have children 0N/A * Returns whether this object can accept focus or not. 0N/A * @return true if object can accept focus; otherwise false 0N/A return true;
// Not supported for MenuComponents 0N/A * Requests focus for this object. 0N/A // Not supported for MenuComponents 0N/A * Adds the specified focus listener to receive focus events from this 0N/A * @param l the focus listener 0N/A // Not supported for MenuComponents 0N/A * Removes the specified focus listener so it no longer receives focus 0N/A * events from this component. 0N/A * @param l the focus listener 0N/A // Not supported for MenuComponents 0N/A // AccessibleSelection methods 0N/A * Returns the number of <code>Accessible</code> children currently selected. 0N/A * If no children are selected, the return value will be 0. 0N/A * @return the number of items currently selected 0N/A return 0;
// To be fully implemented in a future release 0N/A * Returns an <code>Accessible</code> representing the specified 0N/A * selected child in the object. If there isn't a selection, or there are 0N/A * fewer children selected than the integer passed in, the return 0N/A * value will be <code>null</code>. 0N/A * <p>Note that the index represents the i-th selected child, which 0N/A * is different from the i-th child. 0N/A * @param i the zero-based index of selected children 0N/A * @return the i-th selected child 0N/A * @see #getAccessibleSelectionCount 0N/A return null;
// To be fully implemented in a future release 0N/A * Determines if the current child of this object is selected. 0N/A * @return true if the current child of this object is selected; 0N/A * @param i the zero-based index of the child in this 0N/A * <code>Accessible</code> object 0N/A * @see AccessibleContext#getAccessibleChild 0N/A return false;
// To be fully implemented in a future release 0N/A * Adds the specified <code>Accessible</code> child of the object 0N/A * to the object's selection. If the object supports multiple selections, 0N/A * the specified child is added to any existing selection, otherwise 0N/A * it replaces any existing selection in the object. If the 0N/A * specified child is already selected, this method has no effect. 0N/A * @param i the zero-based index of the child 0N/A * @see AccessibleContext#getAccessibleChild 0N/A // To be fully implemented in a future release 0N/A * Removes the specified child of the object from the object's 0N/A * selection. If the specified item isn't currently selected, this 0N/A * method has no effect. 0N/A * @param i the zero-based index of the child 0N/A * @see AccessibleContext#getAccessibleChild 0N/A // To be fully implemented in a future release 0N/A * Clears the selection in the object, so that no children in the 0N/A * object are selected. 0N/A // To be fully implemented in a future release 0N/A * Causes every child of the object to be selected 0N/A * if the object supports multiple selections. 0N/A // To be fully implemented in a future release 0N/A }
// inner class AccessibleAWTComponent 0N/A * Gets the index of this object in its accessible parent. 0N/A * @return -1 if this object does not have an accessible parent; 0N/A * otherwise, the index of the child in its accessible parent. 0N/A // MenuComponents only have accessible index when inside MenuComponents 0N/A * Gets the index of the child within this MenuComponent. 0N/A * @param child MenuComponent whose index we are interested in. 0N/A * @return -1 if this object doesn't contain the child, 0N/A * otherwise, index of the child. 0N/A return -
1;
// Overridden in subclasses. 0N/A * Gets the state of this object. 0N/A * @return an instance of <code>AccessibleStateSet</code> 0N/A * containing the current state set of the object 0N/A * @see AccessibleState