AccessibleComponent.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* AccessibleComponent.java -- aids in accessibly rendering Java components
  2. Copyright (C) 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.accessibility;
  32. import java.awt.Color;
  33. import java.awt.Cursor;
  34. import java.awt.Dimension;
  35. import java.awt.Font;
  36. import java.awt.FontMetrics;
  37. import java.awt.Point;
  38. import java.awt.Rectangle;
  39. import java.awt.event.FocusListener;
  40. /**
  41. * Objects which are to be rendered to a screen as part of a graphical
  42. * user interface should implement this interface. Accessibility
  43. * software can use the implementations of this interface to determine
  44. * and set the screen representation for an object.
  45. *
  46. * <p>The <code>AccessibleContext.getAccessibleComponent()</code> method
  47. * should return <code>null</code> if an object does not implement this
  48. * interface.
  49. *
  50. * @author Eric Blake (ebb9@email.byu.edu)
  51. * @see Accessible
  52. * @see AccessibleContext
  53. * @see AccessibleContext#getAccessibleComponent()
  54. * @since 1.2
  55. * @status updated to 1.4
  56. */
  57. public interface AccessibleComponent
  58. {
  59. /**
  60. * Get the background color of this component.
  61. *
  62. * @return the background color of this component, or null if not supported
  63. * @see #setBackground(Color)
  64. */
  65. Color getBackground();
  66. /**
  67. * Set the background color of this component to the specified color.
  68. *
  69. * @param color the color to set the background to
  70. * @see #getBackground()
  71. */
  72. void setBackground(Color color);
  73. /**
  74. * Get the foreground color of this component.
  75. *
  76. * @return the foreground color of this component, or null if not supported
  77. * @see #setForeground(Color)
  78. */
  79. Color getForeground();
  80. /**
  81. * Set the foreground color of this component.
  82. *
  83. * @param color the color to set the foreground to
  84. * @see #getForeground()
  85. */
  86. void setForeground(Color color);
  87. /**
  88. * Get the cursor of this component.
  89. *
  90. * @return the Cursor of this component, or null if not supported
  91. * @see #setCursor(Cursor)
  92. */
  93. Cursor getCursor();
  94. /**
  95. * Set the cursor of the component.
  96. *
  97. * @param cursor the graphical representation of the cursor to use
  98. * @see #getCursor()
  99. */
  100. void setCursor(Cursor cursor);
  101. /**
  102. * Get the font of this component
  103. *
  104. * @return the font of the component, or null if not supported
  105. * @see #setFont(Font)
  106. */
  107. Font getFont();
  108. /**
  109. * Set the font of this component.
  110. *
  111. * @param font the font to use
  112. * @see #getFont()
  113. */
  114. void setFont(Font font);
  115. /**
  116. * Get the <code>FontMetrics</code> of the specified font in this component.
  117. *
  118. * @param font the specified font
  119. * @return the metrics for the specified font, or null if not supported
  120. * @throws NullPointerException if font is null
  121. * @see #getFont()
  122. */
  123. FontMetrics getFontMetrics(Font font);
  124. /**
  125. * Indicates whether or not this component is enabled. An object which is
  126. * enabled also has AccessibleState.ENABLED in its StateSet.
  127. *
  128. * @return true if the component is enabled
  129. * @see #setEnabled(boolean)
  130. * @see AccessibleContext#getAccessibleStateSet()
  131. * @see AccessibleState#ENABLED
  132. */
  133. boolean isEnabled();
  134. /**
  135. * Set this component to an enabled or disabled state.
  136. *
  137. * @param b true to enable the component, else disable it
  138. * @see #isEnabled()
  139. */
  140. void setEnabled(boolean b);
  141. /**
  142. * Indicates whether or not this component is visible or intends to be
  143. * visible although one of its ancestors may not be. An object which is
  144. * visible also has AccessibleState.VISIBLE in its StateSet. Check
  145. * <code>isShowing()</code> to see if the object is on screen.
  146. *
  147. * @return true if the component is visible
  148. * @see #setVisible(boolean)
  149. * @see AccessibleContext#getAccessibleStateSet()
  150. * @see AccessibleState#VISIBLE
  151. */
  152. boolean isVisible();
  153. /**
  154. * Set the visible state of this component.
  155. *
  156. * @param b true to make the component visible, else hide it
  157. * @see #isVisible()
  158. */
  159. void setVisible(boolean b);
  160. /**
  161. * Indicates whether or not this component is visible by checking
  162. * the visibility of this component and its ancestors. The component may
  163. * be hidden on screen by another component like pop-up help. An object
  164. * which is showing on screen also has AccessibleState.SHOWING in its
  165. * StateSet.
  166. *
  167. * @return true if component and ancestors are visible
  168. * @see #isVisible()
  169. * @see #setVisible(boolean)
  170. * @see AccessibleContext#getAccessibleStateSet()
  171. * @see AccessibleState#SHOWING
  172. */
  173. boolean isShowing();
  174. /**
  175. * Tests whether or not the specified point is contained within
  176. * this component. The coordinates are specified relative to this
  177. * component's coordinate system.
  178. *
  179. * @param point the Point to locate
  180. * @return true if the point is within this component
  181. * @throws NullPointerException if point is null
  182. * @see #getBounds()
  183. */
  184. boolean contains(Point point);
  185. /**
  186. * Get the location of this component in the screen's coordinate space.
  187. * The point specified is the top-left corner of this component.
  188. *
  189. * @return the location on screen, or null if off-screen
  190. * @see #getBounds()
  191. * @see #getLocation()
  192. */
  193. Point getLocationOnScreen();
  194. /**
  195. * Get the location of this component in the parent's coordinate system.
  196. * The point specified is the top-left corner of this component.
  197. *
  198. * @return the location in the parent on screen, or null if off-screen
  199. * @see #getBounds()
  200. * @see #getLocationOnScreen()
  201. * @see #setLocation(Point)
  202. */
  203. Point getLocation();
  204. /**
  205. * Set the location of this component relative to its parent. The point
  206. * specified represents the top-left corner of this component.
  207. *
  208. * @param point the top-left corner of this component relative to the parent
  209. * @throws NullPointerException if point is null
  210. * @see #getLocation()
  211. */
  212. void setLocation(Point point);
  213. /**
  214. * Get the bounds of this component relative to its parent - it's width,
  215. * height, and relative location to its parent.
  216. *
  217. * @return the bounds of this component, or null if not on screen
  218. * @see #contains(Point)
  219. */
  220. Rectangle getBounds();
  221. /**
  222. * Set the bounds of this component to the specified height and width, and
  223. * relative location to its parent.
  224. *
  225. * @param rectangle the new height, width, and relative location
  226. * @throws NullPointerException if rectangle is null
  227. */
  228. void setBounds(Rectangle rectangle);
  229. /**
  230. * Get the size of this component - it's width and height.
  231. *
  232. * @return the dimensions of this component, or null if not on screen
  233. * @see #setSize(Dimension)
  234. */
  235. Dimension getSize();
  236. /**
  237. * Set the size of this component to the given dimensions.
  238. *
  239. * @param dimension the new size of the component
  240. * @throws NullPointerException if dimension is null
  241. * @see #getSize()
  242. */
  243. void setSize(Dimension dimension);
  244. /**
  245. * If an object exists at the specified point which is a child of this
  246. * parent component, and it is accessible, then it is returned.
  247. *
  248. * @param point the location within this component's coordinate system
  249. * @return the accessible child object at that point, or null
  250. */
  251. Accessible getAccessibleAt(Point point);
  252. /**
  253. * Indicates whether or not this component can accept focus. An object
  254. * which can accept focus also has AccessibleState.FOCUSABLE in its
  255. * StateSet.
  256. *
  257. * @return true if the component can accept focus
  258. * @see AccessibleContext#getAccessibleStateSet()
  259. * @see AccessibleState#FOCUSABLE
  260. * @see AccessibleState#FOCUSED
  261. */
  262. boolean isFocusTraversable();
  263. /**
  264. * If this method is called this component will attempt to gain focus,
  265. * but if it cannot accept focus nothing happens. On success, the StateSet
  266. * will contain AccessibleState.FOCUSED
  267. *
  268. * @see #isFocusTraversable()
  269. * @see AccessibleState#FOCUSED
  270. */
  271. void requestFocus();
  272. /**
  273. * Adds the specified listener to this component.
  274. *
  275. * @param listener the listener to add to this component
  276. * @see #removeFocusListener(FocusListener)
  277. */
  278. void addFocusListener(FocusListener listener);
  279. /**
  280. * Removes the specified listener from this component.
  281. *
  282. * @param listener the listener to remove
  283. * @see #addFocusListener(FocusListener)
  284. */
  285. void removeFocusListener(FocusListener listener);
  286. } // interface AccessibleComponent