jdk/src/java.desktop/share/classes/javax/accessibility/AccessibleComponent.java
changeset 45649 499d43823920
parent 25859 3317bb8137f4
equal deleted inserted replaced
45648:87c997b74bb8 45649:499d43823920
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package javax.accessibility;
    26 package javax.accessibility;
    27 
    27 
    28 import java.awt.*;
    28 import java.awt.Color;
    29 import java.awt.event.*;
    29 import java.awt.Cursor;
       
    30 import java.awt.Dimension;
       
    31 import java.awt.Font;
       
    32 import java.awt.FontMetrics;
       
    33 import java.awt.Point;
       
    34 import java.awt.Rectangle;
       
    35 import java.awt.event.FocusListener;
    30 
    36 
    31 /**
    37 /**
    32  * The AccessibleComponent interface should be supported by any object
    38  * The {@code AccessibleComponent} interface should be supported by any object
    33  * that is rendered on the screen.  This interface provides the standard
    39  * that is rendered on the screen. This interface provides the standard
    34  * mechanism for an assistive technology to determine and set the
    40  * mechanism for an assistive technology to determine and set the graphical
    35  * graphical representation of an object.  Applications can determine
    41  * representation of an object. Applications can determine if an object supports
    36  * if an object supports the AccessibleComponent interface by first
    42  * the {@code AccessibleComponent} interface by first obtaining its
    37  * obtaining its AccessibleContext
    43  * {@code AccessibleContext} and then calling the
    38  * and then calling the
    44  * {@link AccessibleContext#getAccessibleComponent} method. If the return value
    39  * {@link AccessibleContext#getAccessibleComponent} method.
    45  * is not {@code null}, the object supports this interface.
    40  * If the return value is not null, the object supports this interface.
    46  *
    41  *
    47  * @author Peter Korn
       
    48  * @author Hans Muller
       
    49  * @author Willie Walker
    42  * @see Accessible
    50  * @see Accessible
    43  * @see Accessible#getAccessibleContext
    51  * @see Accessible#getAccessibleContext
    44  * @see AccessibleContext
    52  * @see AccessibleContext
    45  * @see AccessibleContext#getAccessibleComponent
    53  * @see AccessibleContext#getAccessibleComponent
    46  *
       
    47  * @author      Peter Korn
       
    48  * @author      Hans Muller
       
    49  * @author      Willie Walker
       
    50  */
    54  */
    51 public interface AccessibleComponent {
    55 public interface AccessibleComponent {
    52 
    56 
    53     /**
    57     /**
    54      * Gets the background color of this object.
    58      * Gets the background color of this object.
    55      *
    59      *
    56      * @return the background color, if supported, of the object;
    60      * @return the background color, if supported, of the object; otherwise,
    57      * otherwise, null
    61      *         {@code null}
    58      * @see #setBackground
    62      * @see #setBackground
    59      */
    63      */
    60     public Color getBackground();
    64     public Color getBackground();
    61 
    65 
    62     /**
    66     /**
    63      * Sets the background color of this object.
    67      * Sets the background color of this object.
    64      *
    68      *
    65      * @param c the new Color for the background
    69      * @param  c the new color for the background
    66      * @see #setBackground
    70      * @see #setBackground
    67      */
    71      */
    68     public void setBackground(Color c);
    72     public void setBackground(Color c);
    69 
    73 
    70     /**
    74     /**
    71      * Gets the foreground color of this object.
    75      * Gets the foreground color of this object.
    72      *
    76      *
    73      * @return the foreground color, if supported, of the object;
    77      * @return the foreground color, if supported, of the object; otherwise,
    74      * otherwise, null
    78      *         {@code null}
    75      * @see #setForeground
    79      * @see #setForeground
    76      */
    80      */
    77     public Color getForeground();
    81     public Color getForeground();
    78 
    82 
    79     /**
    83     /**
    80      * Sets the foreground color of this object.
    84      * Sets the foreground color of this object.
    81      *
    85      *
    82      * @param c the new Color for the foreground
    86      * @param  c the new color for the foreground
    83      * @see #getForeground
    87      * @see #getForeground
    84      */
    88      */
    85     public void setForeground(Color c);
    89     public void setForeground(Color c);
    86 
    90 
    87     /**
    91     /**
    88      * Gets the Cursor of this object.
    92      * Gets the cursor of this object.
    89      *
    93      *
    90      * @return the Cursor, if supported, of the object; otherwise, null
    94      * @return the cursor, if supported, of the object; otherwise, {@code null}
    91      * @see #setCursor
    95      * @see #setCursor
    92      */
    96      */
    93     public Cursor getCursor();
    97     public Cursor getCursor();
    94 
    98 
    95     /**
    99     /**
    96      * Sets the Cursor of this object.
   100      * Sets the cursor of this object.
    97      *
   101      *
    98      * @param cursor  the new Cursor for the object
   102      * @param  cursor the new cursor for the object
    99      * @see #getCursor
   103      * @see #getCursor
   100      */
   104      */
   101     public void setCursor(Cursor cursor);
   105     public void setCursor(Cursor cursor);
   102 
   106 
   103     /**
   107     /**
   104      * Gets the Font of this object.
   108      * Gets the font of this object.
   105      *
   109      *
   106      * @return the Font,if supported, for the object; otherwise, null
   110      * @return the font, if supported, for the object; otherwise, {@code null}
   107      * @see #setFont
   111      * @see #setFont
   108      */
   112      */
   109     public Font getFont();
   113     public Font getFont();
   110 
   114 
   111     /**
   115     /**
   112      * Sets the Font of this object.
   116      * Sets the font of this object.
   113      *
   117      *
   114      * @param f the new Font for the object
   118      * @param  f the new font for the object
   115      * @see #getFont
   119      * @see #getFont
   116      */
   120      */
   117     public void setFont(Font f);
   121     public void setFont(Font f);
   118 
   122 
   119     /**
   123     /**
   120      * Gets the FontMetrics of this object.
   124      * Gets the {@code FontMetrics} of this object.
   121      *
   125      *
   122      * @param f the Font
   126      * @param  f the font for which font metrics is to be obtained
   123      * @return the FontMetrics, if supported, the object; otherwise, null
   127      * @return the {@code FontMetrics}, if supported, the object; otherwise,
       
   128      *         {@code null}
   124      * @see #getFont
   129      * @see #getFont
   125      */
   130      */
   126     public FontMetrics getFontMetrics(Font f);
   131     public FontMetrics getFontMetrics(Font f);
   127 
   132 
   128     /**
   133     /**
   129      * Determines if the object is enabled.  Objects that are enabled
   134      * Determines if the object is enabled. Objects that are enabled will also
   130      * will also have the AccessibleState.ENABLED state set in their
   135      * have the {@code AccessibleState.ENABLED} state set in their
   131      * AccessibleStateSets.
   136      * {@code AccessibleStateSets}.
   132      *
   137      *
   133      * @return true if object is enabled; otherwise, false
   138      * @return {@code true} if object is enabled; otherwise, {@code false}
   134      * @see #setEnabled
   139      * @see #setEnabled
   135      * @see AccessibleContext#getAccessibleStateSet
   140      * @see AccessibleContext#getAccessibleStateSet
   136      * @see AccessibleState#ENABLED
   141      * @see AccessibleState#ENABLED
   137      * @see AccessibleStateSet
   142      * @see AccessibleStateSet
   138      */
   143      */
   139     public boolean isEnabled();
   144     public boolean isEnabled();
   140 
   145 
   141     /**
   146     /**
   142      * Sets the enabled state of the object.
   147      * Sets the enabled state of the object.
   143      *
   148      *
   144      * @param b if true, enables this object; otherwise, disables it
   149      * @param  b if {@code true}, enables this object; otherwise, disables it
   145      * @see #isEnabled
   150      * @see #isEnabled
   146      */
   151      */
   147     public void setEnabled(boolean b);
   152     public void setEnabled(boolean b);
   148 
   153 
   149     /**
   154     /**
   150      * Determines if the object is visible.  Note: this means that the
   155      * Determines if the object is visible. Note: this means that the object
   151      * object intends to be visible; however, it may not be
   156      * intends to be visible; however, it may not be showing on the screen
   152      * showing on the screen because one of the objects that this object
   157      * because one of the objects that this object is contained by is currently
   153      * is contained by is currently not visible.  To determine if an object is
   158      * not visible. To determine if an object is showing on the screen, use
   154      * showing on the screen, use isShowing().
   159      * {@link #isShowing()}
   155      * <p>Objects that are visible will also have the
   160      * <p>
   156      * AccessibleState.VISIBLE state set in their AccessibleStateSets.
   161      * Objects that are visible will also have the
   157      *
   162      * {@code AccessibleState.VISIBLE} state set in their
   158      * @return true if object is visible; otherwise, false
   163      * {@code AccessibleStateSets}.
       
   164      *
       
   165      * @return {@code true} if object is visible; otherwise, {@code false}
   159      * @see #setVisible
   166      * @see #setVisible
   160      * @see AccessibleContext#getAccessibleStateSet
   167      * @see AccessibleContext#getAccessibleStateSet
   161      * @see AccessibleState#VISIBLE
   168      * @see AccessibleState#VISIBLE
   162      * @see AccessibleStateSet
   169      * @see AccessibleStateSet
   163      */
   170      */
   164     public boolean isVisible();
   171     public boolean isVisible();
   165 
   172 
   166     /**
   173     /**
   167      * Sets the visible state of the object.
   174      * Sets the visible state of the object.
   168      *
   175      *
   169      * @param b if true, shows this object; otherwise, hides it
   176      * @param  b if {@code true}, shows this object; otherwise, hides it
   170      * @see #isVisible
   177      * @see #isVisible
   171      */
   178      */
   172     public void setVisible(boolean b);
   179     public void setVisible(boolean b);
   173 
   180 
   174     /**
   181     /**
   175      * Determines if the object is showing.  This is determined by checking
   182      * Determines if the object is showing. This is determined by checking the
   176      * the visibility of the object and its ancestors.
   183      * visibility of the object and its ancestors. Note: this will return
   177      * Note: this
   184      * {@code true} even if the object is obscured by another (for example, it
   178      * will return true even if the object is obscured by another (for example,
   185      * is underneath a menu that was pulled down).
   179      * it is underneath a menu that was pulled down).
   186      *
   180      *
   187      * @return {@code true} if object is showing; otherwise, {@code false}
   181      * @return true if object is showing; otherwise, false
       
   182      */
   188      */
   183     public boolean isShowing();
   189     public boolean isShowing();
   184 
   190 
   185     /**
   191     /**
   186      * Checks whether the specified point is within this object's bounds,
   192      * Checks whether the specified point is within this object's bounds, where
   187      * where the point's x and y coordinates are defined to be relative to the
   193      * the point's x and y coordinates are defined to be relative to the
   188      * coordinate system of the object.
   194      * coordinate system of the object.
   189      *
   195      *
   190      * @param p the Point relative to the coordinate system of the object
   196      * @param  p the point relative to the coordinate system of the object
   191      * @return true if object contains Point; otherwise false
   197      * @return {@code true} if object contains point; otherwise {@code false}
   192      * @see #getBounds
   198      * @see #getBounds
   193      */
   199      */
   194     public boolean contains(Point p);
   200     public boolean contains(Point p);
   195 
   201 
   196     /**
   202     /**
   197      * Returns the location of the object on the screen.
   203      * Returns the location of the object on the screen.
   198      *
   204      *
   199      * @return the location of the object on screen; null if this object
   205      * @return the location of the object on screen; {@code null} if this object
   200      * is not on the screen
   206      *         is not on the screen
   201      * @see #getBounds
   207      * @see #getBounds
   202      * @see #getLocation
   208      * @see #getLocation
   203      */
   209      */
   204     public Point getLocationOnScreen();
   210     public Point getLocationOnScreen();
   205 
   211 
   206     /**
   212     /**
   207      * Gets the location of the object relative to the parent in the form
   213      * Gets the location of the object relative to the parent in the form of a
   208      * of a point specifying the object's top-left corner in the screen's
   214      * point specifying the object's top-left corner in the screen's coordinate
   209      * coordinate space.
   215      * space.
   210      *
   216      *
   211      * @return An instance of Point representing the top-left corner of the
   217      * @return An instance of {@code Point} representing the top-left corner of
   212      * object's bounds in the coordinate space of the screen; null if
   218      *         the object's bounds in the coordinate space of the screen;
   213      * this object or its parent are not on the screen
   219      *         {@code null} if this object or its parent are not on the screen
   214      * @see #getBounds
   220      * @see #getBounds
   215      * @see #getLocationOnScreen
   221      * @see #getLocationOnScreen
   216      */
   222      */
   217     public Point getLocation();
   223     public Point getLocation();
   218 
   224 
   219     /**
   225     /**
   220      * Sets the location of the object relative to the parent.
   226      * Sets the location of the object relative to the parent.
   221      * @param p the new position for the top-left corner
   227      *
       
   228      * @param  p the new position for the top-left corner
   222      * @see #getLocation
   229      * @see #getLocation
   223      */
   230      */
   224     public void setLocation(Point p);
   231     public void setLocation(Point p);
   225 
   232 
   226     /**
   233     /**
   227      * Gets the bounds of this object in the form of a Rectangle object.
   234      * Gets the bounds of this object in the form of a {@code Rectangle} object.
   228      * The bounds specify this object's width, height, and location
   235      * The bounds specify this object's width, height, and location relative to
   229      * relative to its parent.
   236      * its parent.
   230      *
   237      *
   231      * @return A rectangle indicating this component's bounds; null if
   238      * @return A rectangle indicating this component's bounds; {@code null} if
   232      * this object is not on the screen.
   239      *         this object is not on the screen.
   233      * @see #contains
   240      * @see #contains
   234      */
   241      */
   235     public Rectangle getBounds();
   242     public Rectangle getBounds();
   236 
   243 
   237     /**
   244     /**
   238      * Sets the bounds of this object in the form of a Rectangle object.
   245      * Sets the bounds of this object in the form of a {@code Rectangle} object.
   239      * The bounds specify this object's width, height, and location
   246      * The bounds specify this object's width, height, and location relative to
   240      * relative to its parent.
   247      * its parent.
   241      *
   248      *
   242      * @param r rectangle indicating this component's bounds
   249      * @param  r rectangle indicating this component's bounds
   243      * @see #getBounds
   250      * @see #getBounds
   244      */
   251      */
   245     public void setBounds(Rectangle r);
   252     public void setBounds(Rectangle r);
   246 
   253 
   247     /**
   254     /**
   248      * Returns the size of this object in the form of a Dimension object.
   255      * Returns the size of this object in the form of a {@code Dimension}
   249      * The height field of the Dimension object contains this object's
   256      * object. The {@code height} field of the {@code Dimension} object contains
   250      * height, and the width field of the Dimension object contains this
   257      * this object's height, and the {@code width} field of the
   251      * object's width.
   258      * {@code Dimension} object contains this object's width.
   252      *
   259      *
   253      * @return A Dimension object that indicates the size of this component;
   260      * @return A {@code Dimension} object that indicates the size of this
   254      * null if this object is not on the screen
   261      *         component; {@code null} if this object is not on the screen
   255      * @see #setSize
   262      * @see #setSize
   256      */
   263      */
   257     public Dimension getSize();
   264     public Dimension getSize();
   258 
   265 
   259     /**
   266     /**
   260      * Resizes this object so that it has width and height.
   267      * Resizes this object so that it has width and height.
   261      *
   268      *
   262      * @param d The dimension specifying the new size of the object.
   269      * @param  d The dimension specifying the new size of the object
   263      * @see #getSize
   270      * @see #getSize
   264      */
   271      */
   265     public void setSize(Dimension d);
   272     public void setSize(Dimension d);
   266 
   273 
   267     /**
   274     /**
   268      * Returns the Accessible child, if one exists, contained at the local
   275      * Returns the {@code Accessible} child, if one exists, contained at the
   269      * coordinate Point.
   276      * local coordinate {@code Point}.
   270      *
   277      *
   271      * @param p The point relative to the coordinate system of this object.
   278      * @param  p The point relative to the coordinate system of this object
   272      * @return the Accessible, if it exists, at the specified location;
   279      * @return the {@code Accessible}, if it exists, at the specified location;
   273      * otherwise null
   280      *         otherwise {@code null}
   274      */
   281      */
   275     public Accessible getAccessibleAt(Point p);
   282     public Accessible getAccessibleAt(Point p);
   276 
   283 
   277     /**
   284     /**
   278      * Returns whether this object can accept focus or not.   Objects that
   285      * Returns whether this object can accept focus or not. Objects that can
   279      * can accept focus will also have the AccessibleState.FOCUSABLE state
   286      * accept focus will also have the {@code AccessibleState.FOCUSABLE} state
   280      * set in their AccessibleStateSets.
   287      * set in their {@code AccessibleStateSets}.
   281      *
   288      *
   282      * @return true if object can accept focus; otherwise false
   289      * @return {@code true} if object can accept focus; otherwise {@code false}
   283      * @see AccessibleContext#getAccessibleStateSet
   290      * @see AccessibleContext#getAccessibleStateSet
   284      * @see AccessibleState#FOCUSABLE
   291      * @see AccessibleState#FOCUSABLE
   285      * @see AccessibleState#FOCUSED
   292      * @see AccessibleState#FOCUSED
   286      * @see AccessibleStateSet
   293      * @see AccessibleStateSet
   287      */
   294      */
   288     public boolean isFocusTraversable();
   295     public boolean isFocusTraversable();
   289 
   296 
   290     /**
   297     /**
   291      * Requests focus for this object.  If this object cannot accept focus,
   298      * Requests focus for this object. If this object cannot accept focus,
   292      * nothing will happen.  Otherwise, the object will attempt to take
   299      * nothing will happen. Otherwise, the object will attempt to take focus.
   293      * focus.
   300      *
   294      * @see #isFocusTraversable
   301      * @see #isFocusTraversable
   295      */
   302      */
   296     public void requestFocus();
   303     public void requestFocus();
   297 
   304 
   298     /**
   305     /**
   299      * Adds the specified focus listener to receive focus events from this
   306      * Adds the specified focus listener to receive focus events from this
   300      * component.
   307      * component.
   301      *
   308      *
   302      * @param l the focus listener
   309      * @param  l the focus listener
   303      * @see #removeFocusListener
   310      * @see #removeFocusListener
   304      */
   311      */
   305     public void addFocusListener(FocusListener l);
   312     public void addFocusListener(FocusListener l);
   306 
   313 
   307     /**
   314     /**
   308      * Removes the specified focus listener so it no longer receives focus
   315      * Removes the specified focus listener so it no longer receives focus
   309      * events from this component.
   316      * events from this component.
   310      *
   317      *
   311      * @param l the focus listener
   318      * @param  l the focus listener
   312      * @see #addFocusListener
   319      * @see #addFocusListener
   313      */
   320      */
   314     public void removeFocusListener(FocusListener l);
   321     public void removeFocusListener(FocusListener l);
   315 }
   322 }