java.awt

Class MenuComponent.AccessibleAWTMenuComponent

protected abstract class MenuComponent.AccessibleAWTMenuComponent extends AccessibleContext implements Serializable, AccessibleComponent, AccessibleSelection

This class provides a base for the accessibility support of menu components.
Constructor Summary
protected AccessibleAWTMenuComponent()
This is the default constructor.
Method Summary
voidaddAccessibleSelection(int index)
Replaces or supplements the component's selection with the Accessible child at the supplied index.
voidaddFocusListener(FocusListener listener)
Registers the specified focus listener to receive focus events from this component.
voidclearAccessibleSelection()
Clears the component's current selection.
booleancontains(Point point)
Returns true if the specified point lies within the component.
AccessiblegetAccessibleAt(Point point)
Returns the Accessible child of this component present at the specified point.
AccessiblegetAccessibleChild(int index)
Returns the Accessible child at the supplied index within the list of children of this component.
intgetAccessibleChildrenCount()
Returns the number of children of this component which implement the Accessible interface.
AccessibleComponentgetAccessibleComponent()
Retrieves the AccessibleComponent associated with this accessible context and its component.
StringgetAccessibleDescription()
Returns the accessible name for this menu component.
intgetAccessibleIndexInParent()
Retrieves the index of this component within its parent.
StringgetAccessibleName()
Returns the accessible name of this component.
AccessiblegetAccessibleParent()
Returns the Accessible parent of this component.
AccessibleRolegetAccessibleRole()
Returns the accessible role of this component.
AccessibleSelectiongetAccessibleSelection()
Retrieves the AccessibleSelection associated with this accessible context and its component.
AccessiblegetAccessibleSelection(int index)
Retrieves the Accessible selected child at the specified index.
intgetAccessibleSelectionCount()
Returns a count of the number of Accessible children of this component which are currently selected.
AccessibleStateSetgetAccessibleStateSet()
Retrieves the current state of this component in an accessible form.
ColorgetBackground()
Returns the background color of the component, or null if this property is unsupported.
RectanglegetBounds()
Returns a Rectangle which represents the bounds of this component.
CursorgetCursor()
Returns the Cursor displayed when the pointer is positioned over this component.
FontgetFont()
Returns the Font used for text created by this component.
FontMetricsgetFontMetrics(Font font)
Retrieves information on the rendering and metrics of the supplied font.
ColorgetForeground()
Returns the foreground color of the component, or null if this property is unsupported.
LocalegetLocale()
Returns the locale currently in use by this component.
PointgetLocation()
Returns the location of the component, with co-ordinates relative to the parent component and using the co-ordinate space of the screen.
PointgetLocationOnScreen()
Returns the location of the component, with co-ordinates relative to the screen.
DimensiongetSize()
Returns the size of the component.
booleanisAccessibleChildSelected(int index)
Returns true if the accessible child specified by the supplied index is currently selected.
booleanisEnabled()
Returns true if this component is currently enabled.
booleanisFocusTraversable()
Returns true if this component is included in the traversal of the current focus from one component to the other.
booleanisShowing()
Returns true if the component is being shown on screen.
booleanisVisible()
Returns true if the component is visible.
voidremoveAccessibleSelection(int index)
Removes the accessible child specified by the supplied index from the list of currently selected children.
voidremoveFocusListener(FocusListener listener)
Removes the specified focus listener from the list of registered focus listeners for this component.
voidrequestFocus()
Requests that this component gains focus.
voidselectAllAccessibleSelection()
Selects all Accessible children of this component which it is possible to select.
voidsetBackground(Color color)
Sets the background color of the component to that specified.
voidsetBounds(Rectangle rectangle)
Sets the height and width of the component, and its position relative to this component's parent, to the values specified by the supplied rectangle.
voidsetCursor(Cursor cursor)
Sets the Cursor used when the pointer is positioned over the component.
voidsetEnabled(boolean enabled)
Sets the enabled/disabled state of this component.
voidsetFont(Font font)
Sets the Font used for text created by this component.
voidsetForeground(Color color)
Sets the foreground color of the component to that specified.
voidsetLocation(Point point)
Sets the location of the component, with co-ordinates relative to the parent component and using the co-ordinate space of the screen.
voidsetSize(Dimension size)
Sets the size of the component.
voidsetVisible(boolean visibility)
Sets the visibility state of the component.

Constructor Detail

AccessibleAWTMenuComponent

protected AccessibleAWTMenuComponent()
This is the default constructor. It should be called by concrete subclasses to ensure necessary groundwork is completed.

Method Detail

addAccessibleSelection

public void addAccessibleSelection(int index)
Replaces or supplements the component's selection with the Accessible child at the supplied index. If the component supports multiple selection, the child is added to the current selection. Otherwise, the current selection becomes the specified child. If the child is already selected, nothing happens.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: index the index of the specified child within a zero-based list of the component's children

addFocusListener

public void addFocusListener(FocusListener listener)
Registers the specified focus listener to receive focus events from this component.

Parameters: listener the new focus listener

clearAccessibleSelection

public void clearAccessibleSelection()
Clears the component's current selection. Following the calling of this method, no children of the component will be selected.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

contains

public boolean contains(Point point)
Returns true if the specified point lies within the component. The supplied co-ordinates are assumed to be relative to the co-ordinate system of the component itself. Thus, the point (0,0) is the upper left corner of this component.

Please note that this method depends on a correctly implemented version of the getBounds() method. Subclasses must provide the bounding rectangle via getBounds() in order for this method to work.

Parameters: point the point to check against this component

Returns: true if the point is within this component

See Also: getBounds

getAccessibleAt

public Accessible getAccessibleAt(Point point)
Returns the Accessible child of this component present at the specified point. The supplied co-ordinates are assumed to be relative to the co-ordinate system of this component (the parent of any returned accessible). Thus, the point (0,0) is the upper left corner of this menu component.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: point the point at which the returned accessible is located

Returns: null

getAccessibleChild

public Accessible getAccessibleChild(int index)
Returns the Accessible child at the supplied index within the list of children of this component.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: index the index of the Accessible child to retrieve

Returns: null

getAccessibleChildrenCount

public int getAccessibleChildrenCount()
Returns the number of children of this component which implement the Accessible interface. If all children of this component are accessible, then the returned value will be the same as the number of children.

Returns: 0

getAccessibleComponent

public AccessibleComponent getAccessibleComponent()
Retrieves the AccessibleComponent associated with this accessible context and its component. As the context itself implements AccessibleComponent, this is the return value.

Returns: the context itself

getAccessibleDescription

public String getAccessibleDescription()
Returns the accessible name for this menu component. This is the name given to the component, which may be null if not set using setName().

The name is not the most appropriate description of this object. Subclasses should preferably provide a more accurate description. For example, a File menu could have the description `Lists commands related to the file system'.

Returns: a description of the component. Currently, this is just the contents of the name property

See Also: setName

getAccessibleIndexInParent

public int getAccessibleIndexInParent()
Retrieves the index of this component within its parent. If no parent exists, -1 is returned.

Returns: -1 as the parent, a MenuContainer is not Accessible

getAccessibleName

public String getAccessibleName()
Returns the accessible name of this component. This is the name given to the component, which may be null if not set using setName().

The name property is not the most suitable string to return for this method. The string should be localized, and relevant to the operation of the component. For example, it could be the text of a menu item. However, this can not be used at this level of abstraction, so it is the responsibility of subclasses to provide a more appropriate name.

Returns: a localized name for this component. Currently, this is just the contents of the name property

See Also: setName

getAccessibleParent

public Accessible getAccessibleParent()
Returns the Accessible parent of this component. As the parent of a MenuComponent is a MenuContainer, which doesn't implement Accessible, this method returns null.

Returns: null

getAccessibleRole

public AccessibleRole getAccessibleRole()
Returns the accessible role of this component.

The abstract implementation of this method returns AccessibleRole.AWT_COMPONENT, as the abstract component has no specific role. This method should be overridden by concrete subclasses, so as to return an appropriate role for the component.

Returns: AccessibleRole.AWT_COMPONENT

getAccessibleSelection

public AccessibleSelection getAccessibleSelection()
Retrieves the AccessibleSelection associated with this accessible context and its component. As the context itself implements AccessibleSelection, this is the return value.

Returns: the context itself

getAccessibleSelection

public Accessible getAccessibleSelection(int index)
Retrieves the Accessible selected child at the specified index. If there are no selected children or the index is outside the range of selected children, null is returned. Please note that the index refers to the index of the child in the list of selected children, and not the index of the child in the list of all Accessible children.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: index the index of the selected Accessible child

getAccessibleSelectionCount

public int getAccessibleSelectionCount()
Returns a count of the number of Accessible children of this component which are currently selected. If there are no children currently selected, 0 is returned.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Returns: 0

getAccessibleStateSet

public AccessibleStateSet getAccessibleStateSet()
Retrieves the current state of this component in an accessible form. For example, a given component may be visible, selected, disabled, etc.

As this class tells us virtually nothing about the component, except for its name and font, no state information can be provided. This implementation thus returns an empty state set, and it is left to concrete subclasses to provide a more acceptable and relevant state set. Changes to these properties also need to be handled using PropertyChangeListeners.

Returns: an empty AccessibleStateSet

getBackground

public Color getBackground()
Returns the background color of the component, or null if this property is unsupported.

This abstract class knows nothing about how the component is drawn on screen, so this method simply returns the default system background color used for rendering menus. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Returns: the default system background color for menus

See Also: setBackground

getBounds

public Rectangle getBounds()
Returns a Rectangle which represents the bounds of this component. The returned rectangle has the height and width of the component's bounds, and is positioned at a location relative to this component's parent, the MenuContainer. null is returned if bounds are not supported by the component.

This abstract class knows nothing about how the component is drawn on screen, so this method simply returns null. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Returns: null

See Also: setBounds

getCursor

public Cursor getCursor()
Returns the Cursor displayed when the pointer is positioned over this component. Alternatively, null is returned if the component doesn't support the cursor property.

This abstract class knows nothing about how the component is drawn on screen, so this method simply returns the default system cursor. Concrete subclasses which handle the drawing of an onscreen menu component may override this method and provide the appropriate information.

Returns: the default system cursor

See Also: setCursor

getFont

public Font getFont()
Returns the Font used for text created by this component.

Returns: the current font

See Also: setFont

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Retrieves information on the rendering and metrics of the supplied font. If font metrics are not supported by this component, null is returned.

The abstract implementation of this method simply uses the toolkit to obtain the FontMetrics. Concrete subclasses may find it more efficient to invoke their peer class directly, if one is available.

Parameters: font the font about which to retrieve rendering and metric information

Returns: the metrics of the given font, as provided by the system toolkit

Throws: NullPointerException if the supplied font was null

getForeground

public Color getForeground()
Returns the foreground color of the component, or null if this property is unsupported.

This abstract class knows nothing about how the component is drawn on screen, so this method simply returns the default system text color used for rendering menus. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Returns: the default system text color for menus

See Also: setForeground

getLocale

public Locale getLocale()
Returns the locale currently in use by this component.

This abstract class has no property relating to the locale used by the component, so this method simply returns the default locale for the current instance of the Java Virtual Machine (JVM). Concrete subclasses which maintain such a property should override this method and provide the locale information more accurately.

Returns: the default locale for this JVM instance

getLocation

public Point getLocation()
Returns the location of the component, with co-ordinates relative to the parent component and using the co-ordinate space of the screen. Thus, the point (0,0) is the upper left corner of the parent component.

Please note that this method depends on a correctly implemented version of the getBounds() method. Subclasses must provide the bounding rectangle via getBounds() in order for this method to work.

Returns: the location of the component, relative to its parent

See Also: setLocation

getLocationOnScreen

public Point getLocationOnScreen()
Returns the location of the component, with co-ordinates relative to the screen. Thus, the point (0,0) is the upper left corner of the screen. null is returned if the component is either not on screen or if this property is unsupported.

This abstract class knows nothing about how the component is drawn on screen, so this method simply returns null. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Returns: the location of the component, relative to the screen

getSize

public Dimension getSize()
Returns the size of the component.

Please note that this method depends on a correctly implemented version of the getBounds() method. Subclasses must provide the bounding rectangle via getBounds() in order for this method to work.

Returns: the size of the component

See Also: setSize

isAccessibleChildSelected

public boolean isAccessibleChildSelected(int index)
Returns true if the accessible child specified by the supplied index is currently selected.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: index the index of the accessible child to check for selection

Returns: false

isEnabled

public boolean isEnabled()
Returns true if this component is currently enabled.

As this abstract component has no properties related to its enabled or disabled state, the implementation of this method is left to subclasses.

Returns: false

See Also: AccessibleAWTMenuComponent

isFocusTraversable

public boolean isFocusTraversable()
Returns true if this component is included in the traversal of the current focus from one component to the other.

As this abstract component has no properties related to its ability to accept the focus, the implementation of this method is left to subclasses.

Returns: false

isShowing

public boolean isShowing()
Returns true if the component is being shown on screen. A component is determined to be shown if it is visible, and each parent component is also visible. Please note that, even when a component is showing, it may still be obscured by other components in front. This method only determines if the component is being drawn on the screen.

As this abstract component and its parent have no properties relating to visibility, the implementation of this method is left to subclasses.

Returns: false

See Also: isVisible

isVisible

public boolean isVisible()
Returns true if the component is visible. A component may be visible but not drawn on the screen if one of its parent components is not visible. To determine if the component is actually drawn on screen, isShowing() should be used.

As this abstract component has no properties relating to its visibility, the implementation of this method is left to subclasses.

Returns: false

See Also: isShowing AccessibleAWTMenuComponent

removeAccessibleSelection

public void removeAccessibleSelection(int index)
Removes the accessible child specified by the supplied index from the list of currently selected children. If the child specified is not selected, nothing happens.

As the existence of children can not be determined from this abstract class, the implementation of this method is left to subclasses.

Parameters: index the index of the Accessible child

removeFocusListener

public void removeFocusListener(FocusListener listener)
Removes the specified focus listener from the list of registered focus listeners for this component.

Parameters: listener the listener to remove

requestFocus

public void requestFocus()
Requests that this component gains focus. This depends on the component being focus traversable.

As this abstract component has no properties relating to its focus traversability, or access to a peer with request focusing abilities, the implementation of this method is left to subclasses.

selectAllAccessibleSelection

public void selectAllAccessibleSelection()
Selects all Accessible children of this component which it is possible to select. The component needs to support multiple selections.

This abstract component provides a simplistic implementation of this method, which ignores the ability of the component to support multiple selections and simply uses addAccessibleSelection to add each Accessible child to the selection. The last Accessible component is thus selected for components which don't support multiple selections. Concrete implementations should override this with a more appopriate and efficient implementation, which properly takes into account the ability of the component to support multiple selections.

setBackground

public void setBackground(Color color)
Sets the background color of the component to that specified. Unspecified behaviour occurs when null is given as the new background color.

This abstract class knows nothing about how the component is drawn on screen, so this method simply ignores the supplied color and continues to use the default system color. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Parameters: color the new color to use for the background

See Also: getBackground

setBounds

public void setBounds(Rectangle rectangle)
Sets the height and width of the component, and its position relative to this component's parent, to the values specified by the supplied rectangle. Unspecified behaviour occurs when null is given as the new bounds.

This abstract class knows nothing about how the component is drawn on screen, so this method simply ignores the new rectangle and continues to return null from getBounds(). Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Parameters: rectangle a rectangle which specifies the new bounds of the component

See Also: getBounds

setCursor

public void setCursor(Cursor cursor)
Sets the Cursor used when the pointer is positioned over the component. Unspecified behaviour occurs when null is given as the new cursor.

This abstract class knows nothing about how the component is drawn on screen, so this method simply ignores the new cursor and continues to return the default system cursor. Concrete subclasses which handle the drawing of an onscreen menu component may override this method and provide the appropriate information.

Parameters: cursor the new cursor to use

See Also: getCursor

setEnabled

public void setEnabled(boolean enabled)
Sets the enabled/disabled state of this component.

As this abstract component has no properties related to its enabled or disabled state, the implementation of this method is left to subclasses.

Parameters: enabled true if the component should be enabled, false otherwise

See Also: isEnabled

setFont

public void setFont(Font font)
Sets the Font used for text created by this component. Unspecified behaviour occurs when null is given as the new font.

Parameters: font the new font to use for text.

See Also: getFont

setForeground

public void setForeground(Color color)
Sets the foreground color of the component to that specified. Unspecified behaviour occurs when null is given as the new background color.

This abstract class knows nothing about how the component is drawn on screen, so this method simply ignores the supplied color and continues to return the default system text color used for rendering menus. Concrete subclasses which handle the drawing of an onscreen menu component should override this method and provide the appropriate information.

Parameters: color the new foreground color

See Also: getForeground

setLocation

public void setLocation(Point point)
Sets the location of the component, with co-ordinates relative to the parent component and using the co-ordinate space of the screen. Thus, the point (0,0) is the upper left corner of the parent component.

Please note that this method depends on a correctly implemented version of the getBounds() method. Subclasses must provide the bounding rectangle via getBounds() in order for this method to work.

Parameters: point the location of the component, relative to its parent

See Also: getLocation

setSize

public void setSize(Dimension size)
Sets the size of the component.

Please note that this method depends on a correctly implemented version of the getBounds() method. Subclasses must provide the bounding rectangle via getBounds() in order for this method to work.

Parameters: size the new size of the component

See Also: getSize

setVisible

public void setVisible(boolean visibility)
Sets the visibility state of the component. A component may be visible but not drawn on the screen if one of its parent components is not visible. To determine if the component is actually drawn on screen, isShowing() should be used.

As this abstract component has no properties relating to its visibility, the implementation of this method is left to subclasses.

Parameters: visibility the new visibility of the component -- true if the component is visible, false if not

See Also: isShowing isVisible