This class provides a base for the accessibility support of menu
components.
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.
- Specified by:
- addAccessibleSelection in interface AccessibleSelection
- Parameters:
index
- the index of the specified child within a
zero-based list of the component's children
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.
- Specified by:
- clearAccessibleSelection in interface AccessibleSelection
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.
- Specified by:
- contains in interface AccessibleComponent
- Parameters:
point
- the point to check against this component
- Returns:
- true if the point is within this component
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.
- Specified by:
- getAccessibleAt in interface AccessibleComponent
- Parameters:
point
- the point at which the returned accessible
is located
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.
- Overrides:
- getAccessibleChild in interface AccessibleContext
- Parameters:
index
- the index of the Accessible
child
to retrieve
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'.
- Overrides:
- getAccessibleDescription in interface AccessibleContext
- Returns:
- a description of the component. Currently,
this is just the contents of the name property
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.
- Overrides:
- getAccessibleName in interface AccessibleContext
- Returns:
- a localized name for this component. Currently, this
is just the contents of the name property
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.
- Overrides:
- getAccessibleRole in interface AccessibleContext
- Returns:
AccessibleRole.AWT_COMPONENT
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.
- Specified by:
- getAccessibleSelection in interface AccessibleSelection
- 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.
- Specified by:
- getAccessibleSelectionCount in interface AccessibleSelection
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
PropertyChangeListener
s.
- Overrides:
- getAccessibleStateSet in interface AccessibleContext
- 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.
- Specified by:
- getBackground in interface AccessibleComponent
- Returns:
- the default system background color for menus
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.
- Specified by:
- getBounds in interface AccessibleComponent
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.
- Specified by:
- getCursor in interface AccessibleComponent
- Returns:
- the default system cursor
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.
- Specified by:
- getFontMetrics in interface AccessibleComponent
- 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
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.
- Specified by:
- getForeground in interface AccessibleComponent
- Returns:
- the default system text color for menus
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.
- Overrides:
- getLocale in interface AccessibleContext
- 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.
- Specified by:
- getLocation in interface AccessibleComponent
- Returns:
- the location of the component, relative to its parent
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.
- Specified by:
- getLocationOnScreen in interface AccessibleComponent
- 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.
- Specified by:
- getSize in interface AccessibleComponent
- Returns:
- the size of the component
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.
- Specified by:
- isAccessibleChildSelected in interface AccessibleSelection
- Parameters:
index
- the index of the accessible child to check for selection
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.
- Specified by:
- isEnabled in interface AccessibleComponent
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.
- Specified by:
- isFocusTraversable in interface AccessibleComponent
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.
- Specified by:
- isShowing in interface AccessibleComponent
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.
- Specified by:
- isVisible in interface AccessibleComponent
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.
- Specified by:
- removeAccessibleSelection in interface AccessibleSelection
- Parameters:
index
- the index of the Accessible
child
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.
- Specified by:
- requestFocus in interface AccessibleComponent
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.
- Specified by:
- selectAllAccessibleSelection in interface AccessibleSelection
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.
- Specified by:
- setBackground in interface AccessibleComponent
- Parameters:
color
- the new color to use for the background
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.
- Specified by:
- setBounds in interface AccessibleComponent
- Parameters:
rectangle
- a rectangle which specifies the new bounds of
the component
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.
- Specified by:
- setCursor in interface AccessibleComponent
- Parameters:
cursor
- the new cursor to use
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.
- Specified by:
- setEnabled in interface AccessibleComponent
- Parameters:
enabled
- true if the component should be enabled,
false otherwise
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.
- Specified by:
- setFont in interface AccessibleComponent
- Parameters:
font
- the new font to use for text.
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.
- Specified by:
- setForeground in interface AccessibleComponent
- Parameters:
color
- the new foreground color
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.
- Specified by:
- setLocation in interface AccessibleComponent
- Parameters:
point
- the location of the component, relative to its parent
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.
- Specified by:
- setSize in interface AccessibleComponent
- Parameters:
size
- the new size of the component
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.
- Specified by:
- setVisible in interface AccessibleComponent
- Parameters:
visibility
- the new visibility of the component -- true if
the component is visible, false if not
MenuComponent.java -- Superclass of all AWT menu components
Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.