FileDocCategorySizeDatePackage
MenuComponent.javaAPI DocJava SE 5 API33399Fri Aug 26 14:56:46 BST 2005java.awt

MenuComponent

public abstract class MenuComponent extends Object implements Serializable
The abstract class MenuComponent is the superclass of all menu-related components. In this respect, the class MenuComponent is analogous to the abstract superclass Component for AWT components.

Menu components receive and process AWT events, just as components do, through the method processEvent.

version
1.77, 05/18/04
author
Arthur van Hoff
since
JDK1.0

Fields Summary
transient MenuComponentPeer
peer
transient MenuContainer
parent
transient AppContext
appContext
The AppContext of the MenuComponent. This is set in the constructor and never changes.
Font
font
The menu component's font. This value can be null at which point a default will be used. This defaults to null.
private String
name
The menu component's name, which defaults to null.
private boolean
nameExplicitlySet
A variable to indicate whether a name is explicitly set. If true the name will be set explicitly. This defaults to false.
boolean
newEventsOnly
Defaults to false.
static final String
actionListenerK
static final String
itemListenerK
private static final long
serialVersionUID
private transient Object
privateKey
This object is used as a key for internal hashtables.
AccessibleContext
accessibleContext
Constructors Summary
public MenuComponent()
Creates a MenuComponent.

exception
HeadlessException if GraphicsEnvironment.isHeadless returns true
see
java.awt.GraphicsEnvironment#isHeadless


                          
        
        GraphicsEnvironment.checkHeadless();
	appContext = AppContext.getAppContext();
    
Methods Summary
java.lang.StringconstructComponentName()
Constructs a name for this MenuComponent. Called by getName when the name is null.

return
a name for this MenuComponent

        return null; // For strict compliance with prior platform versions, a MenuComponent
                     // that doesn't set its name should return null from
                     // getName()
    
public final voiddispatchEvent(java.awt.AWTEvent e)

        dispatchEventImpl(e);
    
voiddispatchEventImpl(java.awt.AWTEvent e)

        EventQueue.setCurrentEventAndMostRecentTime(e);

        Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);

        if (newEventsOnly || 
            (parent != null && parent instanceof MenuComponent &&
             ((MenuComponent)parent).newEventsOnly)) {
            if (eventEnabled(e)) {
                processEvent(e);
            } else if (e instanceof ActionEvent && parent != null) {
                e.setSource(parent);
                ((MenuComponent)parent).dispatchEvent(e);
            }
                
        } else { // backward compatibility
            Event olde = e.convertToOld();
            if (olde != null) {
                postEvent(olde);
            }
        }
    
booleaneventEnabled(java.awt.AWTEvent e)

        return false;
    
intgetAccessibleChildIndex(java.awt.MenuComponent child)
Gets the index of the child within this MenuComponent.

param
child MenuComponent whose index we are interested in.
return
-1 if this object doesn't contain the child, otherwise, index of the child.

        return -1; // Overridden in subclasses.
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this MenuComponent. The method implemented by this base class returns null. Classes that extend MenuComponent should implement this method to return the AccessibleContext associated with the subclass.

return
the AccessibleContext of this MenuComponent


                                                     
       
        return accessibleContext;
    
intgetAccessibleIndexInParent()
Gets the index of this object in its accessible parent.

return
-1 if this object does not have an accessible parent; otherwise, the index of the child in its accessible parent.

        MenuContainer localParent = parent;
        if (!(localParent instanceof MenuComponent)) {
            // MenuComponents only have accessible index when inside MenuComponents
            return -1; 
        }
        MenuComponent localParentMenu = (MenuComponent)localParent;
        return localParentMenu.getAccessibleChildIndex(this);
    
javax.accessibility.AccessibleStateSetgetAccessibleStateSet()
Gets the state of this object.

return
an instance of AccessibleStateSet containing the current state set of the object
see
AccessibleState

        AccessibleStateSet states = new AccessibleStateSet();
        return states;
    
public java.awt.FontgetFont()
Gets the font used for this menu component.

return
the font used in this menu component, if there is one; null otherwise
see
java.awt.MenuComponent#setFont

	Font font = this.font;
	if (font != null) {
	    return font;
	}
	MenuContainer parent = this.parent;
	if (parent != null) {
	    return parent.getFont();
	}
	return null;
    
final java.awt.FontgetFont_NoClientCode()

	Font font = this.font;
	if (font != null) {
	    return font;
	}

	// The MenuContainer interface does not have getFont_NoClientCode()
	// and it cannot, because it must be package-private. Because of
	// this, we must manually cast classes that implement 
	// MenuContainer.
	Object parent = this.parent;
	if (parent != null) {
	    if (parent instanceof Component) {
		font = ((Component)parent).getFont_NoClientCode();
	    } else if (parent instanceof MenuComponent) {
		font = ((MenuComponent)parent).getFont_NoClientCode();
	    }
	}
	return font;
    
public java.lang.StringgetName()
Gets the name of the menu component.

return
the name of the menu component
see
java.awt.MenuComponent#setName(java.lang.String)
since
JDK1.1

        if (name == null && !nameExplicitlySet) {
            synchronized(this) {
                if (name == null && !nameExplicitlySet)
                    name = constructComponentName();
            }
        }
        return name;
    
public java.awt.MenuContainergetParent()
Returns the parent container for this menu component.

return
the menu component containing this menu component, or null if this menu component is the outermost component, the menu bar itself

	return getParent_NoClientCode();
    
final java.awt.MenuContainergetParent_NoClientCode()

	return parent;
    
public java.awt.peer.MenuComponentPeergetPeer()

deprecated
As of JDK version 1.1, programs should not directly manipulate peers.

	return peer;
    
protected final java.lang.ObjectgetTreeLock()
Gets this component's locking object (the object that owns the thread sychronization monitor) for AWT component-tree and layout operations.

return
this component's locking object

        return Component.LOCK;
    
private static native voidinitIDs()
Initialize JNI field and method IDs.

protected java.lang.StringparamString()
Returns a string representing the state of this MenuComponent. 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.

return
the parameter string of this menu component

        String thisName = getName();
        return (thisName != null? thisName : "");
    
public booleanpostEvent(java.awt.Event evt)
Posts the specified event to the menu. This method is part of the Java 1.0 event system and it is maintained only for backwards compatibility. Its use is discouraged, and it may not be supported in the future.

param
evt the event which is to take place
deprecated
As of JDK version 1.1, replaced by {@link #dispatchEvent(AWTEvent) dispatchEvent}.

	MenuContainer parent = this.parent;
	if (parent != null) {
	    parent.postEvent(evt);
	}
	return false;
    
protected voidprocessEvent(java.awt.AWTEvent e)
Processes events occurring on this menu component.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

param
e the event
since
JDK1.1

    
private voidreadObject(java.io.ObjectInputStream s)
Reads the menu component from an object input stream.

param
s the ObjectInputStream to read
exception
HeadlessException if GraphicsEnvironment.isHeadless returns true
serial
see
java.awt.GraphicsEnvironment#isHeadless

        GraphicsEnvironment.checkHeadless();
        s.defaultReadObject();

        privateKey = new Object();
	appContext = AppContext.getAppContext();
    
public voidremoveNotify()
Removes the menu component's peer. The peer allows us to modify the appearance of the menu component without changing the functionality of the menu component.

        synchronized (getTreeLock()) {
	    MenuComponentPeer p = (MenuComponentPeer)this.peer;
	    if (p != null) {
	        Toolkit.getEventQueue().removeSourceEvents(this, true);
		this.peer = null;
		p.dispose();
	    }
	}
    
public voidsetFont(java.awt.Font f)
Sets the font to be used for this menu component to the specified font. This font is also used by all subcomponents of this menu component, unless those subcomponents specify a different font.

Some platforms may not support setting of all font attributes of a menu component; in such cases, calling setFont will have no effect on the unsupported font attributes of this menu component. Unless subcomponents of this menu component specify a different font, this font will be used by those subcomponents if supported by the underlying platform.

param
f the font to be set
see
#getFont
see
Font#getAttributes
see
java.awt.font.TextAttribute

	font = f;
        if (peer != null) {
            peer.setFont(f);
        }
    
public voidsetName(java.lang.String name)
Sets the name of the component to the specified string.

param
name the name of the menu component
see
java.awt.MenuComponent#getName
since
JDK1.1

        synchronized(this) {
            this.name = name;
            nameExplicitlySet = true;
        }
    
public java.lang.StringtoString()
Returns a representation of this menu component as a string.

return
a string representation of this menu component

	return getClass().getName() + "[" + paramString() + "]";