FileDocCategorySizeDatePackage
MenuComponent.javaAPI DocAndroid 1.5 API24129Wed May 06 22:41:54 BST 2009java.awt

MenuComponent

public abstract class MenuComponent extends Object implements Serializable
The MenuComponent abstract class is the superclass for menu components. Menu components receive and process AWT events.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
The Constant serialVersionUID.
private String
name
The name.
private Font
font
The font.
MenuContainer
parent
The parent.
boolean
deprecatedEventHandler
The deprecated event handler.
private int
selectedItemIndex
The selected item index.
final Toolkit
toolkit
The toolkit.
Constructors Summary
public MenuComponent()
Instantiates a new MenuComponent object.

throws
HeadlessException if the graphical interface environment can't support MenuComponents.


    // ???AWT
    /*
     * protected abstract class AccessibleAWTMenuComponent extends
     * AccessibleContext implements Serializable, AccessibleComponent,
     * AccessibleSelection { private static final long serialVersionUID =
     * -4269533416223798698L; public void addFocusListener(FocusListener
     * listener) { } public boolean contains(Point pt) { return false; } public
     * Accessible getAccessibleAt(Point pt) { return null; } public Color
     * getBackground() { return null; } public Rectangle getBounds() { return
     * null; } public Cursor getCursor() { return null; } public Font getFont()
     * { return MenuComponent.this.getFont(); } public FontMetrics
     * getFontMetrics(Font font) { return null; } public Color getForeground() {
     * return null; } public Point getLocation() { return null; } public Point
     * getLocationOnScreen() { return null; } public Dimension getSize() {
     * return null; } public boolean isEnabled() { return true; // always
     * enabled } public boolean isFocusTraversable() { return true; // always
     * focus traversable } public boolean isShowing() { return true;// always
     * showing } public boolean isVisible() { return true; // always visible }
     * public void removeFocusListener(FocusListener listener) { } public void
     * requestFocus() { } public void setBackground(Color color) { } public void
     * setBounds(Rectangle rect) { } public void setCursor(Cursor cursor) { }
     * public void setEnabled(boolean enabled) { } public void setFont(Font
     * font) { MenuComponent.this.setFont(font); } public void
     * setForeground(Color color) { } public void setLocation(Point pt) { }
     * public void setSize(Dimension pt) { } public void setVisible(boolean
     * visible) { } public void addAccessibleSelection(int index) { } public
     * void clearAccessibleSelection() { } public Accessible
     * getAccessibleSelection(int index) { return null; } public int
     * getAccessibleSelectionCount() { return 0; } public boolean
     * isAccessibleChildSelected(int index) { return false; } public void
     * removeAccessibleSelection(int index) { } public void
     * selectAllAccessibleSelection() { }
     * @Override public Accessible getAccessibleChild(int index) { return null;
     * }
     * @Override public int getAccessibleChildrenCount() { return 0; }
     * @Override public AccessibleComponent getAccessibleComponent() { return
     * this; }
     * @Override public String getAccessibleDescription() { return
     * super.getAccessibleDescription(); }
     * @Override public int getAccessibleIndexInParent() { toolkit.lockAWT();
     * try { Accessible aParent = getAccessibleParent(); int aIndex = -1; if
     * (aParent instanceof MenuComponent) { MenuComponent parent =
     * (MenuComponent) aParent; int count = parent.getItemCount(); for (int i =
     * 0; i < count; i++) { MenuComponent comp = parent.getItem(i); if (comp
     * instanceof Accessible) { aIndex++; if (comp == MenuComponent.this) {
     * return aIndex; } } } } return -1; } finally { toolkit.unlockAWT(); } }
     * @Override public String getAccessibleName() { return
     * super.getAccessibleName(); }
     * @Override public Accessible getAccessibleParent() { toolkit.lockAWT();
     * try { Accessible aParent = super.getAccessibleParent(); if (aParent !=
     * null) { return aParent; } MenuContainer parent = getParent(); if (parent
     * instanceof Accessible) { aParent = (Accessible) parent; } return aParent;
     * } finally { toolkit.unlockAWT(); } }
     * @Override public AccessibleRole getAccessibleRole() { return
     * AccessibleRole.AWT_COMPONENT; }
     * @Override public AccessibleSelection getAccessibleSelection() { return
     * this; }
     * @Override public AccessibleStateSet getAccessibleStateSet() { return new
     * AccessibleStateSet(); }
     * @Override public Locale getLocale() { return Locale.getDefault(); } }
     */

                                      
    // ???AWT
    /*
     * class State implements MenuState { Dimension size; Dimension getSize() {
     * if (size == null) { calculate(); } return size; } public int getWidth() {
     * return getSize().width; } public int getHeight() { return
     * getSize().height; } public Font getFont() { return
     * MenuComponent.this.getFont(); } public int getItemCount() { return
     * MenuComponent.this.getItemCount(); } public int getSelectedItemIndex() {
     * return MenuComponent.this.getSelectedItemIndex(); } public boolean
     * isFontSet() { return MenuComponent.this.isFontSet(); }
     * @SuppressWarnings("deprecation") public FontMetrics getFontMetrics(Font
     * f) { return MenuComponent.this.toolkit.getFontMetrics(f); } public Point
     * getLocation() { return MenuComponent.this.getLocation(); } public
     * MenuItemState getItem(int index) { MenuItem item =
     * MenuComponent.this.getItem(index); return item.itemState; } public void
     * setSize(int w, int h) { this.size = new Dimension(w, h); } void
     * calculate() { size = new Dimension();
     * size.setSize(toolkit.theme.calculateMenuSize(this)); } void reset() { for
     * (int i = 0; i < getItemCount(); i++) { ((MenuItem.State)
     * getItem(i)).reset(); } } }
     */

                           
    // ???AWT
    /*
     * class MenuPopupBox extends PopupBox { private final Point lastMousePos =
     * new Point();
     * @Override boolean isMenu() { return true; }
     * @Override void paint(Graphics gr) { MenuComponent.this.paint(gr); }
     * @Override void onKeyEvent(int eventId, int vKey, long when, int
     * modifiers) { MenuComponent.this.onKeyEvent(eventId, vKey, when,
     * modifiers); }
     * @Override void onMouseEvent(int eventId, Point where, int mouseButton,
     * long when, int modifiers, int wheelRotation) { // prevent conflict of
     * mouse and keyboard // when sub-menu drops down due to keyboard navigation
     * if (lastMousePos.equals(where) && (eventId == MouseEvent.MOUSE_MOVED ||
     * eventId == MouseEvent.MOUSE_ENTERED)) { return; }
     * lastMousePos.setLocation(where); MenuComponent.this.onMouseEvent(eventId,
     * where, mouseButton, when, modifiers); } }
     */

                                                 
        
        toolkit.lockAWT();
        try {
            Toolkit.checkHeadless();
            name = autoName();
            selectedItemIndex = -1;
        } finally {
            toolkit.unlockAWT();
        }
    
Methods Summary
java.lang.StringautoName()
Auto name.

return
the string.

        String name = getClass().getName();
        if (name.indexOf("$") != -1) { //$NON-NLS-1$
            return null;
        }
        // ???AWT: int number = toolkit.autoNumber.nextMenuComponent++;
        int number = 0;
        name = name.substring(name.lastIndexOf(".") + 1) + Integer.toString(number); //$NON-NLS-1$
        return name;
    
public final voiddispatchEvent(java.awt.AWTEvent event)
Dispatches AWT event.

param
event the AWTEvent.

        toolkit.lockAWT();
        try {
            processEvent(event);
            if (deprecatedEventHandler) {
                postDeprecatedEvent(event);
            }
        } finally {
            toolkit.unlockAWT();
        }
    
voidendMenu()
Hide all menu hierarchy.

        // ???AWT: toolkit.dispatcher.popupDispatcher.deactivateAll();
    
public java.awt.FontgetFont()
Gets the font of the MenuComponent object.

return
the Font of the MenuComponent object.

        toolkit.lockAWT();
        try {
            if (font == null && hasDefaultFont()) {
                return toolkit.getDefaultFont();
            }
            if (font == null && parent != null) {
                return parent.getFont();
            }
            return font;
        } finally {
            toolkit.unlockAWT();
        }
    
java.awt.GraphicsgetGraphics(org.apache.harmony.awt.gl.MultiRectArea clip)
Creates the Graphics object for the pop-up box of this menu component.

param
clip the clip to set on this Graphics.
return
the created Graphics object, or null if such object is not available.

        // to be overridden
        return null;
    
intgetHeight()
Gets the height.

return
the height.

        // to be overridden
        return 1;
    
java.awt.RectanglegetItemRect(int index)

return
the menu bar which is the root of current menu's hierarchy; or null if the hierarchy root is not a menu bar.

        // to be overridden
        return null;
    
java.awt.PointgetLocation()
Gets the location.

return
the location.

        // to be overridden
        return new Point(0, 0);
    
public java.lang.StringgetName()
Gets the name of the MenuComponent object.

return
the name of the MenuComponent object.

        toolkit.lockAWT();
        try {
            return name;
        } finally {
            toolkit.unlockAWT();
        }
    
public java.awt.MenuContainergetParent()
Gets the parent menu container.

return
the parent.

        toolkit.lockAWT();
        try {
            return parent;
        } finally {
            toolkit.unlockAWT();
        }
    
public java.awt.peer.MenuComponentPeergetPeer()
Gets the peer of the MenuComponent; an application must not use this method directly.

return
the MenuComponentPeer object.
throws
NotImplementedException if this method is not implemented by a subclass.
deprecated
an application must not use this method directly.

        toolkit.lockAWT();
        try {
        } finally {
            toolkit.unlockAWT();
        }
        if (true) {
            throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$
        }
        return null;
    
intgetSelectedItemIndex()
Gets the selected item index.

return
the selected item index.

        return selectedItemIndex;
    
java.awt.PointgetSubmenuLocation(int index)
Gets the submenu location.

param
index the index.
return
the submenu location.

        // to be overridden
        return new Point(0, 0);
    
protected final java.lang.ObjectgetTreeLock()
Gets the locking object of this MenuComponent.

return
the locking object of this MenuComponent.

        return toolkit.awtTreeLock;
    
final org.apache.harmony.awt.gl.MultiRectAreagetUpdateClip(int index1, int index2)
Determine the clip region when menu selection is changed from index1 to index2.

param
index1 old selected item.
param
index2 new selected item.
return
the region to repaint.

        MultiRectArea clip = new MultiRectArea();
        if (index1 >= 0) {
            clip.add(getItemRect(index1));
        }
        if (index2 >= 0) {
            clip.add(getItemRect(index2));
        }
        return clip;
    
intgetWidth()
Gets the width.

return
the width.

        // to be overridden
        return 1;
    
booleanhasDefaultFont()
Checks for default font.

return
true, if successful.

        return false;
    
voidhide()
Hide.

        selectedItemIndex = -1;
        if (parent instanceof MenuComponent) {
            ((MenuComponent)parent).itemHidden(this);
        }
    
booleanisActive()
Checks if is active.

return
true, if is active.

        return true;
    
booleanisFontSet()
Checks if is font set.

return
true, if is font set

        return font != null
                || ((parent instanceof MenuComponent) && ((MenuComponent)parent).isFontSet());
    
booleanisVisible()
Checks if is visible.

return
true, if is visible.

        return true;
    
voiditemHidden(java.awt.MenuComponent mc)
Item hidden.

param
mc the mc.

        // to be overridden
    
voiditemSelected(long when, int modifiers)
Handle the mouse click or Enter key event on a menu's item.

param
when the event time.
param
modifiers input event modifiers.

        endMenu();
    
voidonKeyEvent(int eventId, int vKey, long when, int modifiers)
Keyboard event handler.

param
eventId one of the KeyEvent.KEY_* constants.
param
vKey the key code.
param
when event time.
param
modifiers input event modifiers.

        // to be overridden
    
voidonMouseEvent(int eventId, java.awt.Point where, int mouseButton, long when, int modifiers)
Mouse events handler.

param
eventId one of the MouseEvent.MOUSE_* constants.
param
where mouse location.
param
mouseButton mouse button that was pressed or released.
param
when event time.
param
modifiers input event modifiers.

        // to be overridden
    
voidpaint(java.awt.Graphics gr)
Recursively find the menu item for a menu shortcut.

param
gr the gr.
return
the menu item; or null if the item is not available for this shortcut.

        gr.setColor(Color.LIGHT_GRAY);
        gr.fillRect(0, 0, getWidth(), getHeight());
        gr.setColor(Color.BLACK);
    
protected java.lang.StringparamString()
Returns the string representation of the MenuComponent state.

return
returns the string representation of the MenuComponent state.

        toolkit.lockAWT();
        try {
            return getName();
        } finally {
            toolkit.unlockAWT();
        }
    
voidpostDeprecatedEvent(java.awt.AWTEvent event)
Post deprecated event.

param
event the event.

        Event evt = event.getEvent();
        if (evt != null) {
            postEvent(evt);
        }
    
public booleanpostEvent(java.awt.Event e)
Posts the Event to the MenuComponent.

param
e the Event.
return
true, if the event is posted successfully, false otherwise.
deprecated
Replaced dispatchEvent method.

        toolkit.lockAWT();
        try {
            if (parent != null) {
                return parent.postEvent(e);
            }
            return false;
        } finally {
            toolkit.unlockAWT();
        }
    
protected voidprocessEvent(java.awt.AWTEvent event)
Processes an AWTEevent on this menu component.

param
event the AWTEvent.

        toolkit.lockAWT();
        try {
            // do nothing
        } finally {
            toolkit.unlockAWT();
        }
    
public voidremoveNotify()
Removes the peer of the MenuComponent.

        toolkit.lockAWT();
        try {
        } finally {
            toolkit.unlockAWT();
        }
    
public voidsetFont(java.awt.Font font)
Sets the Font for this MenuComponent object.

param
font the new Font to be used for this MenuComponent.

        toolkit.lockAWT();
        try {
            this.font = font;
        } finally {
            toolkit.unlockAWT();
        }
    
public voidsetName(java.lang.String name)
Sets the name of the MenuComponent to the specified string.

param
name the new name of the MenuComponent object.

        toolkit.lockAWT();
        try {
            this.name = name;
        } finally {
            toolkit.unlockAWT();
        }
    
voidsetParent(java.awt.MenuContainer parent)
Sets the parent.

param
parent the new parent.

        this.parent = parent;
    
public java.lang.StringtoString()
Returns a String representation of the MenuComponent object.

return
a String representation of the MenuComponent object.

        toolkit.lockAWT();
        try {
            return getClass().getName() + "[" + paramString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
        } finally {
            toolkit.unlockAWT();
        }