Path: blob/master/src/java.desktop/share/classes/javax/accessibility/AccessibleComponent.java
41153 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.accessibility;2627import java.awt.Color;28import java.awt.Cursor;29import java.awt.Dimension;30import java.awt.Font;31import java.awt.FontMetrics;32import java.awt.Point;33import java.awt.Rectangle;34import java.awt.event.FocusListener;3536/**37* The {@code AccessibleComponent} interface should be supported by any object38* that is rendered on the screen. This interface provides the standard39* mechanism for an assistive technology to determine and set the graphical40* representation of an object. Applications can determine if an object supports41* the {@code AccessibleComponent} interface by first obtaining its42* {@code AccessibleContext} and then calling the43* {@link AccessibleContext#getAccessibleComponent} method. If the return value44* is not {@code null}, the object supports this interface.45*46* @author Peter Korn47* @author Hans Muller48* @author Willie Walker49* @see Accessible50* @see Accessible#getAccessibleContext51* @see AccessibleContext52* @see AccessibleContext#getAccessibleComponent53*/54public interface AccessibleComponent {5556/**57* Gets the background color of this object.58*59* @return the background color, if supported, of the object; otherwise,60* {@code null}61* @see #setBackground62*/63public Color getBackground();6465/**66* Sets the background color of this object.67*68* @param c the new color for the background69* @see #setBackground70*/71public void setBackground(Color c);7273/**74* Gets the foreground color of this object.75*76* @return the foreground color, if supported, of the object; otherwise,77* {@code null}78* @see #setForeground79*/80public Color getForeground();8182/**83* Sets the foreground color of this object.84*85* @param c the new color for the foreground86* @see #getForeground87*/88public void setForeground(Color c);8990/**91* Gets the cursor of this object.92*93* @return the cursor, if supported, of the object; otherwise, {@code null}94* @see #setCursor95*/96public Cursor getCursor();9798/**99* Sets the cursor of this object.100*101* @param cursor the new cursor for the object102* @see #getCursor103*/104public void setCursor(Cursor cursor);105106/**107* Gets the font of this object.108*109* @return the font, if supported, for the object; otherwise, {@code null}110* @see #setFont111*/112public Font getFont();113114/**115* Sets the font of this object.116*117* @param f the new font for the object118* @see #getFont119*/120public void setFont(Font f);121122/**123* Gets the {@code FontMetrics} of this object.124*125* @param f the font for which font metrics is to be obtained126* @return the {@code FontMetrics}, if supported, the object; otherwise,127* {@code null}128* @see #getFont129*/130public FontMetrics getFontMetrics(Font f);131132/**133* Determines if the object is enabled. Objects that are enabled will also134* have the {@code AccessibleState.ENABLED} state set in their135* {@code AccessibleStateSets}.136*137* @return {@code true} if object is enabled; otherwise, {@code false}138* @see #setEnabled139* @see AccessibleContext#getAccessibleStateSet140* @see AccessibleState#ENABLED141* @see AccessibleStateSet142*/143public boolean isEnabled();144145/**146* Sets the enabled state of the object.147*148* @param b if {@code true}, enables this object; otherwise, disables it149* @see #isEnabled150*/151public void setEnabled(boolean b);152153/**154* Determines if the object is visible. Note: this means that the object155* intends to be visible; however, it may not be showing on the screen156* because one of the objects that this object is contained by is currently157* not visible. To determine if an object is showing on the screen, use158* {@link #isShowing()}159* <p>160* Objects that are visible will also have the161* {@code AccessibleState.VISIBLE} state set in their162* {@code AccessibleStateSets}.163*164* @return {@code true} if object is visible; otherwise, {@code false}165* @see #setVisible166* @see AccessibleContext#getAccessibleStateSet167* @see AccessibleState#VISIBLE168* @see AccessibleStateSet169*/170public boolean isVisible();171172/**173* Sets the visible state of the object.174*175* @param b if {@code true}, shows this object; otherwise, hides it176* @see #isVisible177*/178public void setVisible(boolean b);179180/**181* Determines if the object is showing. This is determined by checking the182* visibility of the object and its ancestors. Note: this will return183* {@code true} even if the object is obscured by another (for example, it184* is underneath a menu that was pulled down).185*186* @return {@code true} if object is showing; otherwise, {@code false}187*/188public boolean isShowing();189190/**191* Checks whether the specified point is within this object's bounds, where192* the point's x and y coordinates are defined to be relative to the193* coordinate system of the object.194*195* @param p the point relative to the coordinate system of the object196* @return {@code true} if object contains point; otherwise {@code false}197* @see #getBounds198*/199public boolean contains(Point p);200201/**202* Returns the location of the object on the screen.203*204* @return the location of the object on screen; {@code null} if this object205* is not on the screen206* @see #getBounds207* @see #getLocation208*/209public Point getLocationOnScreen();210211/**212* Gets the location of the object relative to the parent in the form of a213* point specifying the object's top-left corner in the screen's coordinate214* space.215*216* @return An instance of {@code Point} representing the top-left corner of217* the object's bounds in the coordinate space of the screen;218* {@code null} if this object or its parent are not on the screen219* @see #getBounds220* @see #getLocationOnScreen221*/222public Point getLocation();223224/**225* Sets the location of the object relative to the parent.226*227* @param p the new position for the top-left corner228* @see #getLocation229*/230public void setLocation(Point p);231232/**233* Gets the bounds of this object in the form of a {@code Rectangle} object.234* The bounds specify this object's width, height, and location relative to235* its parent.236*237* @return A rectangle indicating this component's bounds; {@code null} if238* this object is not on the screen.239* @see #contains240*/241public Rectangle getBounds();242243/**244* Sets the bounds of this object in the form of a {@code Rectangle} object.245* The bounds specify this object's width, height, and location relative to246* its parent.247*248* @param r rectangle indicating this component's bounds249* @see #getBounds250*/251public void setBounds(Rectangle r);252253/**254* Returns the size of this object in the form of a {@code Dimension}255* object. The {@code height} field of the {@code Dimension} object contains256* this object's height, and the {@code width} field of the257* {@code Dimension} object contains this object's width.258*259* @return A {@code Dimension} object that indicates the size of this260* component; {@code null} if this object is not on the screen261* @see #setSize262*/263public Dimension getSize();264265/**266* Resizes this object so that it has width and height.267*268* @param d The dimension specifying the new size of the object269* @see #getSize270*/271public void setSize(Dimension d);272273/**274* Returns the {@code Accessible} child, if one exists, contained at the275* local coordinate {@code Point}.276*277* @param p The point relative to the coordinate system of this object278* @return the {@code Accessible}, if it exists, at the specified location;279* otherwise {@code null}280*/281public Accessible getAccessibleAt(Point p);282283/**284* Returns whether this object can accept focus or not. Objects that can285* accept focus will also have the {@code AccessibleState.FOCUSABLE} state286* set in their {@code AccessibleStateSets}.287*288* @return {@code true} if object can accept focus; otherwise {@code false}289* @see AccessibleContext#getAccessibleStateSet290* @see AccessibleState#FOCUSABLE291* @see AccessibleState#FOCUSED292* @see AccessibleStateSet293*/294public boolean isFocusTraversable();295296/**297* Requests focus for this object. If this object cannot accept focus,298* nothing will happen. Otherwise, the object will attempt to take focus.299*300* @see #isFocusTraversable301*/302public void requestFocus();303304/**305* Adds the specified focus listener to receive focus events from this306* component.307*308* @param l the focus listener309* @see #removeFocusListener310*/311public void addFocusListener(FocusListener l);312313/**314* Removes the specified focus listener so it no longer receives focus315* events from this component.316*317* @param l the focus listener318* @see #addFocusListener319*/320public void removeFocusListener(FocusListener l);321}322323324