1. /*
  2. * @(#)JLayeredPane.java 1.45 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.awt.Component;
  9. import java.util.Hashtable;
  10. import java.awt.Color;
  11. import java.awt.Graphics;
  12. import java.awt.Rectangle;
  13. import javax.accessibility.*;
  14. /**
  15. * <code>JLayeredPane</code> adds depth to a JFC/Swing container,
  16. * allowing components to overlap each other when needed.
  17. * An <code>Integer</code> object specifies each component's depth in the
  18. * container, where higher-numbered components sit "on top" of other
  19. * components.
  20. * For task-oriented documentation and examples of using layered panes see
  21. * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html">How to Use a Layered Pane</a>,
  22. * a section in <em>The Java Tutorial</em>.
  23. * <P>
  24. * <TABLE ALIGN="RIGHT" BORDER="0" SUMMARY="layout">
  25. * <TR>
  26. * <TD ALIGN="CENTER">
  27. * <P ALIGN="CENTER"><IMG SRC="doc-files/JLayeredPane-1.gif"
  28. * alt="The following text describes this image."
  29. * WIDTH="269" HEIGHT="264" ALIGN="BOTTOM" BORDER="0">
  30. * </TD>
  31. * </TR>
  32. * </TABLE>
  33. * For convenience, <code>JLayeredPane</code> divides the depth-range
  34. * into several different layers. Putting a component into one of those
  35. * layers makes it easy to ensure that components overlap properly,
  36. * without having to worry about specifying numbers for specific depths:
  37. * <DL>
  38. * <DT><FONT SIZE="2">DEFAULT_LAYER</FONT></DT>
  39. * <DD>The standard layer, where most components go. This the bottommost
  40. * layer.
  41. * <DT><FONT SIZE="2">PALETTE_LAYER</FONT></DT>
  42. * <DD>The palette layer sits over the default layer. Useful for floating
  43. * toolbars and palettes, so they can be positioned above other components.
  44. * <DT><FONT SIZE="2">MODAL_LAYER</FONT></DT>
  45. * <DD>The layer used for modal dialogs. They will appear on top of any
  46. * toolbars, palettes, or standard components in the container.
  47. * <DT><FONT SIZE="2">POPUP_LAYER</FONT></DT>
  48. * <DD>The popup layer displays above dialogs. That way, the popup windows
  49. * associated with combo boxes, tooltips, and other help text will appear
  50. * above the component, palette, or dialog that generated them.
  51. * <DT><FONT SIZE="2">DRAG_LAYER</FONT></DT>
  52. * <DD>When dragging a component, reassigning it to the drag layer ensures
  53. * that it is positioned over every other component in the container. When
  54. * finished dragging, it can be reassigned to its normal layer.
  55. * </DL>
  56. * The <code>JLayeredPane</code> methods <code>moveToFront(Component)</code>,
  57. * <code>moveToBack(Component)</code> and <code>setPosition</code> can be used
  58. * to reposition a component within its layer. The <code>setLayer</code> method
  59. * can also be used to change the component's current layer.
  60. *
  61. * <h2>Details</h2>
  62. * <code>JLayeredPane</code> manages its list of children like
  63. * <code>Container</code>, but allows for the definition of a several
  64. * layers within itself. Children in the same layer are managed exactly
  65. * like the normal <code>Container</code> object,
  66. * with the added feature that when children components overlap, children
  67. * in higher layers display above the children in lower layers.
  68. * <p>
  69. * Each layer is a distinct integer number. The layer attribute can be set
  70. * on a <code>Component</code> by passing an <code>Integer</code>
  71. * object during the add call.<br> For example:
  72. * <PRE>
  73. * layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
  74. * or
  75. * layeredPane.add(child, new Integer(10));
  76. * </PRE>
  77. * The layer attribute can also be set on a Component by calling<PRE>
  78. * layeredPaneParent.setLayer(child, 10)</PRE>
  79. * on the <code>JLayeredPane</code> that is the parent of component. The layer
  80. * should be set <i>before</i> adding the child to the parent.
  81. * <p>
  82. * Higher number layers display above lower number layers. So, using
  83. * numbers for the layers and letters for individual components, a
  84. * representative list order would look like this:<PRE>
  85. * 5a, 5b, 5c, 2a, 2b, 2c, 1a </PRE>
  86. * where the leftmost components are closest to the top of the display.
  87. * <p>
  88. * A component can be moved to the top or bottom position within its
  89. * layer by calling <code>moveToFront</code> or <code>moveToBack</code>.
  90. * <p>
  91. * The position of a component within a layer can also be specified directly.
  92. * Valid positions range from 0 up to one less than the number of
  93. * components in that layer. A value of -1 indicates the bottommost
  94. * position. A value of 0 indicates the topmost position. Unlike layer
  95. * numbers, higher position values are <i>lower</i> in the display.
  96. * <blockquote>
  97. * <b>Note:</b> This sequence (defined by java.awt.Container) is the reverse
  98. * of the layer numbering sequence. Usually though, you will use <code>moveToFront</code>,
  99. * <code>moveToBack</code>, and <code>setLayer</code>.
  100. * </blockquote>
  101. * Here are some examples using the method add(Component, layer, position):
  102. * Calling add(5x, 5, -1) results in:<PRE>
  103. * 5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
  104. *
  105. * Calling add(5z, 5, 2) results in:<PRE>
  106. * 5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
  107. *
  108. * Calling add(3a, 3, 7) results in:<PRE>
  109. * 5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a </PRE>
  110. *
  111. * Using normal paint/event mechanics results in 1a appearing at the bottom
  112. * and 5a being above all other components.
  113. * <p>
  114. * <b>Note:</b> that these layers are simply a logical construct and LayoutManagers
  115. * will affect all child components of this container without regard for
  116. * layer settings.
  117. * <p>
  118. * <strong>Warning:</strong>
  119. * Serialized objects of this class will not be compatible with
  120. * future Swing releases. The current serialization support is
  121. * appropriate for short term storage or RMI between applications running
  122. * the same version of Swing. As of 1.4, support for long term storage
  123. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  124. * has been added to the <code>java.beans</code> package.
  125. * Please see {@link java.beans.XMLEncoder}.
  126. *
  127. * @version 1.36 02/02/00
  128. * @author David Kloba
  129. */
  130. public class JLayeredPane extends JComponent implements Accessible {
  131. /// Watch the values in getObjectForLayer()
  132. /** Convenience object defining the Default layer. Equivalent to new Integer(0).*/
  133. public final static Integer DEFAULT_LAYER = new Integer(0);
  134. /** Convenience object defining the Palette layer. Equivalent to new Integer(100).*/
  135. public final static Integer PALETTE_LAYER = new Integer(100);
  136. /** Convenience object defining the Modal layer. Equivalent to new Integer(200).*/
  137. public final static Integer MODAL_LAYER = new Integer(200);
  138. /** Convenience object defining the Popup layer. Equivalent to new Integer(300).*/
  139. public final static Integer POPUP_LAYER = new Integer(300);
  140. /** Convenience object defining the Drag layer. Equivalent to new Integer(400).*/
  141. public final static Integer DRAG_LAYER = new Integer(400);
  142. /** Convenience object defining the Frame Content layer.
  143. * This layer is normally only use to positon the contentPane and menuBar
  144. * components of JFrame.
  145. * Equivalent to new Integer(-30000).
  146. * @see JFrame
  147. */
  148. public final static Integer FRAME_CONTENT_LAYER = new Integer(-30000);
  149. /** Bound property */
  150. public final static String LAYER_PROPERTY = "layeredContainerLayer";
  151. // Hashtable to store layer values for non-JComponent components
  152. private Hashtable componentToLayer;
  153. private boolean optimizedDrawingPossible = true;
  154. //////////////////////////////////////////////////////////////////////////////
  155. //// Container Override methods
  156. //////////////////////////////////////////////////////////////////////////////
  157. /** Create a new JLayeredPane */
  158. public JLayeredPane() {
  159. setLayout(null);
  160. }
  161. private void validateOptimizedDrawing() {
  162. boolean layeredComponentFound = false;
  163. synchronized(getTreeLock()) {
  164. int i,d;
  165. Integer layer = null;
  166. for(i=0,d=getComponentCount();i<d;i++) {
  167. layer = null;
  168. if(getComponent(i) instanceof JInternalFrame ||
  169. (getComponent(i) instanceof JComponent &&
  170. (layer = (Integer)((JComponent)getComponent(i)).getClientProperty(LAYER_PROPERTY)) != null)) {
  171. if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
  172. continue;
  173. layeredComponentFound = true;
  174. break;
  175. }
  176. }
  177. }
  178. if(layeredComponentFound)
  179. optimizedDrawingPossible = false;
  180. else
  181. optimizedDrawingPossible = true;
  182. }
  183. protected void addImpl(Component comp, Object constraints, int index) {
  184. int layer = DEFAULT_LAYER.intValue();
  185. int pos;
  186. if(constraints instanceof Integer) {
  187. layer = ((Integer)constraints).intValue();
  188. setLayer(comp, layer);
  189. } else
  190. layer = getLayer(comp);
  191. pos = insertIndexForLayer(layer, index);
  192. super.addImpl(comp, constraints, pos);
  193. comp.validate();
  194. comp.repaint();
  195. validateOptimizedDrawing();
  196. }
  197. /**
  198. * Remove the indexed component from this pane.
  199. * This is the absolute index, ignoring layers.
  200. *
  201. * @param index an int specifying the component to remove
  202. * @see #getIndexOf
  203. */
  204. public void remove(int index) {
  205. Component c = getComponent(index);
  206. super.remove(index);
  207. if (c != null && !(c instanceof JComponent)) {
  208. getComponentToLayer().remove(c);
  209. }
  210. validateOptimizedDrawing();
  211. }
  212. /**
  213. * Returns false if components in the pane can overlap, which makes
  214. * optimized drawing impossible. Otherwise, returns true.
  215. *
  216. * @return false if components can overlap, else true
  217. * @see JComponent#isOptimizedDrawingEnabled
  218. */
  219. public boolean isOptimizedDrawingEnabled() {
  220. return optimizedDrawingPossible;
  221. }
  222. //////////////////////////////////////////////////////////////////////////////
  223. //// New methods for managing layers
  224. //////////////////////////////////////////////////////////////////////////////
  225. /** Sets the layer property on a JComponent. This method does not cause
  226. * any side effects like setLayer() (painting, add/remove, etc).
  227. * Normally you should use the instance method setLayer(), in order to
  228. * get the desired side-effects (like repainting).
  229. *
  230. * @param c the JComponent to move
  231. * @param layer an int specifying the layer to move it to
  232. * @see #setLayer
  233. */
  234. public static void putLayer(JComponent c, int layer) {
  235. /// MAKE SURE THIS AND setLayer(Component c, int layer, int position) are SYNCED
  236. Integer layerObj;
  237. layerObj = new Integer(layer);
  238. c.putClientProperty(LAYER_PROPERTY, layerObj);
  239. }
  240. /** Gets the layer property for a JComponent, it
  241. * does not cause any side effects like setLayer(). (painting, add/remove, etc)
  242. * Normally you should use the instance method getLayer().
  243. *
  244. * @param c the JComponent to check
  245. * @return an int specifying the component's layer
  246. */
  247. public static int getLayer(JComponent c) {
  248. Integer i;
  249. if((i = (Integer)c.getClientProperty(LAYER_PROPERTY)) != null)
  250. return i.intValue();
  251. return DEFAULT_LAYER.intValue();
  252. }
  253. /** Convenience method that returns the first JLayeredPane which
  254. * contains the specified component. Note that all JFrames have a
  255. * JLayeredPane at their root, so any component in a JFrame will
  256. * have a JLayeredPane parent.
  257. *
  258. * @param c the Component to check
  259. * @return the JLayeredPane that contains the component, or
  260. * null if no JLayeredPane is found in the component
  261. * hierarchy
  262. * @see JFrame
  263. * @see JRootPane
  264. */
  265. public static JLayeredPane getLayeredPaneAbove(Component c) {
  266. if(c == null) return null;
  267. Component parent = c.getParent();
  268. while(parent != null && !(parent instanceof JLayeredPane))
  269. parent = parent.getParent();
  270. return (JLayeredPane)parent;
  271. }
  272. /** Sets the layer attribute on the specified component,
  273. * making it the bottommost component in that layer.
  274. * Should be called before adding to parent.
  275. *
  276. * @param c the Component to set the layer for
  277. * @param layer an int specifying the layer to set, where
  278. * lower numbers are closer to the bottom
  279. */
  280. public void setLayer(Component c, int layer) {
  281. setLayer(c, layer, -1);
  282. }
  283. /** Sets the layer attribute for the specified component and
  284. * also sets its position within that layer.
  285. *
  286. * @param c the Component to set the layer for
  287. * @param layer an int specifying the layer to set, where
  288. * lower numbers are closer to the bottom
  289. * @param position an int specifying the position within the
  290. * layer, where 0 is the topmost position and -1
  291. * is the bottommost position
  292. */
  293. public void setLayer(Component c, int layer, int position) {
  294. Integer layerObj;
  295. layerObj = getObjectForLayer(layer);
  296. if(layer == getLayer(c) && position == getPosition(c)) {
  297. if(c instanceof JComponent)
  298. repaint(((JComponent)c)._bounds);
  299. else
  300. repaint(c.getBounds());
  301. return;
  302. }
  303. /// MAKE SURE THIS AND putLayer(JComponent c, int layer) are SYNCED
  304. if(c instanceof JComponent)
  305. ((JComponent)c).putClientProperty(LAYER_PROPERTY, layerObj);
  306. else
  307. getComponentToLayer().put((Component)c, layerObj);
  308. if(c.getParent() == null || c.getParent() != this) {
  309. if(c instanceof JComponent)
  310. repaint(((JComponent)c)._bounds);
  311. else
  312. repaint(c.getBounds());
  313. return;
  314. }
  315. // Remove the Component and re-add after re-setting the layer
  316. // this is necessary now because I have no access to the
  317. // components[] in Container, to reorder things.
  318. remove(c);
  319. // ALERT passing NULL here for the constraints may be bad
  320. // the current hacks to fix this smell bad right now.
  321. // Cannot override
  322. add(c, null, position);
  323. if(c instanceof JComponent)
  324. repaint(((JComponent)c)._bounds);
  325. else
  326. repaint(c.getBounds());
  327. }
  328. /**
  329. * Returns the layer attribute for the specified Component.
  330. *
  331. * @param c the Component to check
  332. * @return an int specifying the component's current layer
  333. */
  334. public int getLayer(Component c) {
  335. Integer i;
  336. if(c instanceof JComponent)
  337. i = (Integer)((JComponent)c).getClientProperty(LAYER_PROPERTY);
  338. else
  339. i = (Integer)getComponentToLayer().get((Component)c);
  340. if(i == null)
  341. return DEFAULT_LAYER.intValue();
  342. return i.intValue();
  343. }
  344. /**
  345. * Returns the index of the specified Component.
  346. * This is the absolute index, ignoring layers.
  347. * Index numbers, like position numbers, have the topmost component
  348. * at index zero. Larger numbers are closer to the bottom.
  349. *
  350. * @param c the Component to check
  351. * @return an int specifying the component's index
  352. */
  353. public int getIndexOf(Component c) {
  354. int i, count;
  355. count = getComponentCount();
  356. for(i = 0; i < count; i++) {
  357. if(c == getComponent(i))
  358. return i;
  359. }
  360. return -1;
  361. }
  362. /**
  363. * Moves the component to the top of the components in its current layer
  364. * (position 0).
  365. *
  366. * @param c the Component to move
  367. * @see #setPosition(Component, int)
  368. */
  369. public void moveToFront(Component c) {
  370. setPosition(c, 0);
  371. }
  372. /**
  373. * Moves the component to the bottom of the components in its current layer
  374. * (position -1).
  375. *
  376. * @param c the Component to move
  377. * @see #setPosition(Component, int)
  378. */
  379. public void moveToBack(Component c) {
  380. setPosition(c, getComponentCountInLayer(getLayer(c)));
  381. }
  382. /**
  383. * Moves the component to <code>position</code> within its current layer,
  384. * where 0 is the topmost position within the layer and -1 is the bottommost
  385. * position.
  386. * <p>
  387. * <b>Note:</b> Position numbering is defined by java.awt.Container, and
  388. * is the opposite of layer numbering. Lower position numbers are closer
  389. * to the top (0 is topmost), and higher position numbers are closer to
  390. * the bottom.
  391. *
  392. * @param c the Component to move
  393. * @param position an int in the range -1..N-1, where N is the number of
  394. * components in the component's current layer
  395. */
  396. public void setPosition(Component c, int position) {
  397. setLayer(c, getLayer(c), position);
  398. }
  399. /**
  400. * Get the relative position of the component within its layer.
  401. *
  402. * @param c the Component to check
  403. * @return an int giving the component's position, where 0 is the
  404. * topmost position and the highest index value = the count
  405. * count of components at that layer, minus 1
  406. *
  407. * @see #getComponentCountInLayer
  408. */
  409. public int getPosition(Component c) {
  410. int i, count, startLayer, curLayer, startLocation, pos = 0;
  411. count = getComponentCount();
  412. startLocation = getIndexOf(c);
  413. if(startLocation == -1)
  414. return -1;
  415. startLayer = getLayer(c);
  416. for(i = startLocation - 1; i >= 0; i--) {
  417. curLayer = getLayer(getComponent(i));
  418. if(curLayer == startLayer)
  419. pos++;
  420. else
  421. return pos;
  422. }
  423. return pos;
  424. }
  425. /** Returns the highest layer value from all current children.
  426. * Returns 0 if there are no children.
  427. *
  428. * @return an int indicating the layer of the topmost component in the
  429. * pane, or zero if there are no children
  430. */
  431. public int highestLayer() {
  432. if(getComponentCount() > 0)
  433. return getLayer(getComponent(0));
  434. return 0;
  435. }
  436. /** Returns the lowest layer value from all current children.
  437. * Returns 0 if there are no children.
  438. *
  439. * @return an int indicating the layer of the bottommost component in the
  440. * pane, or zero if there are no children
  441. */
  442. public int lowestLayer() {
  443. int count = getComponentCount();
  444. if(count > 0)
  445. return getLayer(getComponent(count-1));
  446. return 0;
  447. }
  448. /**
  449. * Returns the number of children currently in the specified layer.
  450. *
  451. * @param layer an int specifying the layer to check
  452. * @return an int specifying the number of components in that layer
  453. */
  454. public int getComponentCountInLayer(int layer) {
  455. int i, count, curLayer;
  456. int layerCount = 0;
  457. count = getComponentCount();
  458. for(i = 0; i < count; i++) {
  459. curLayer = getLayer(getComponent(i));
  460. if(curLayer == layer) {
  461. layerCount++;
  462. /// Short circut the counting when we have them all
  463. } else if(layerCount > 0 || curLayer < layer) {
  464. break;
  465. }
  466. }
  467. return layerCount;
  468. }
  469. /**
  470. * Returns an array of the components in the specified layer.
  471. *
  472. * @param layer an int specifying the layer to check
  473. * @return an array of Components contained in that layer
  474. */
  475. public Component[] getComponentsInLayer(int layer) {
  476. int i, count, curLayer;
  477. int layerCount = 0;
  478. Component[] results;
  479. results = new Component[getComponentCountInLayer(layer)];
  480. count = getComponentCount();
  481. for(i = 0; i < count; i++) {
  482. curLayer = getLayer(getComponent(i));
  483. if(curLayer == layer) {
  484. results[layerCount++] = getComponent(i);
  485. /// Short circut the counting when we have them all
  486. } else if(layerCount > 0 || curLayer < layer) {
  487. break;
  488. }
  489. }
  490. return results;
  491. }
  492. /**
  493. * Paints this JLayeredPane within the specified graphics context.
  494. *
  495. * @param g the Graphics context within which to paint
  496. */
  497. public void paint(Graphics g) {
  498. if(isOpaque()) {
  499. Rectangle r = g.getClipBounds();
  500. Color c = getBackground();
  501. if(c == null)
  502. c = Color.lightGray;
  503. g.setColor(c);
  504. if (r != null) {
  505. g.fillRect(r.x, r.y, r.width, r.height);
  506. }
  507. else {
  508. g.fillRect(0, 0, getWidth(), getHeight());
  509. }
  510. }
  511. super.paint(g);
  512. }
  513. //////////////////////////////////////////////////////////////////////////////
  514. //// Implementation Details
  515. //////////////////////////////////////////////////////////////////////////////
  516. /**
  517. * Returns the hashtable that maps components to layers.
  518. *
  519. * @return the Hashtable used to map components to their layers
  520. */
  521. protected Hashtable getComponentToLayer() {
  522. if(componentToLayer == null)
  523. componentToLayer = new Hashtable(4);
  524. return componentToLayer;
  525. }
  526. /**
  527. * Returns the Integer object associated with a specified layer.
  528. *
  529. * @param layer an int specifying the layer
  530. * @return an Integer object for that layer
  531. */
  532. protected Integer getObjectForLayer(int layer) {
  533. Integer layerObj;
  534. switch(layer) {
  535. case 0:
  536. layerObj = DEFAULT_LAYER;
  537. break;
  538. case 100:
  539. layerObj = PALETTE_LAYER;
  540. break;
  541. case 200:
  542. layerObj = MODAL_LAYER;
  543. break;
  544. case 300:
  545. layerObj = POPUP_LAYER;
  546. break;
  547. case 400:
  548. layerObj = DRAG_LAYER;
  549. break;
  550. default:
  551. layerObj = new Integer(layer);
  552. }
  553. return layerObj;
  554. }
  555. /**
  556. * Primitive method that determines the proper location to
  557. * insert a new child based on layer and position requests.
  558. *
  559. * @param layer an int specifying the layer
  560. * @param position an int specifying the position within the layer
  561. * @return an int giving the (absolute) insertion-index
  562. *
  563. * @see #getIndexOf
  564. */
  565. protected int insertIndexForLayer(int layer, int position) {
  566. int i, count, curLayer;
  567. int layerStart = -1;
  568. int layerEnd = -1;
  569. count = getComponentCount();
  570. for(i = 0; i < count; i++) {
  571. curLayer = getLayer(getComponent(i));
  572. if(layerStart == -1 && curLayer == layer) {
  573. layerStart = i;
  574. }
  575. if(curLayer < layer ) {
  576. if(i == 0) {
  577. // layer is greater than any current layer
  578. // [ ASSERT(layer > highestLayer()) ]
  579. layerStart = 0;
  580. layerEnd = 0;
  581. } else {
  582. layerEnd = i;
  583. }
  584. break;
  585. }
  586. }
  587. // layer requested is lower than any current layer
  588. // [ ASSERT(layer < lowestLayer()) ]
  589. // put it on the bottom of the stack
  590. if(layerStart == -1 && layerEnd == -1)
  591. return count;
  592. // In the case of a single layer entry handle the degenerative cases
  593. if(layerStart != -1 && layerEnd == -1)
  594. layerEnd = count;
  595. if(layerEnd != -1 && layerStart == -1)
  596. layerStart = layerEnd;
  597. // If we are adding to the bottom, return the last element
  598. if(position == -1)
  599. return layerEnd;
  600. // Otherwise make sure the requested position falls in the
  601. // proper range
  602. if(position > -1 && layerStart + position <= layerEnd)
  603. return layerStart + position;
  604. // Otherwise return the end of the layer
  605. return layerEnd;
  606. }
  607. /**
  608. * Returns a string representation of this JLayeredPane. This method
  609. * is intended to be used only for debugging purposes, and the
  610. * content and format of the returned string may vary between
  611. * implementations. The returned string may be empty but may not
  612. * be <code>null</code>.
  613. *
  614. * @return a string representation of this JLayeredPane.
  615. */
  616. protected String paramString() {
  617. String optimizedDrawingPossibleString = (optimizedDrawingPossible ?
  618. "true" : "false");
  619. return super.paramString() +
  620. ",optimizedDrawingPossible=" + optimizedDrawingPossibleString;
  621. }
  622. /////////////////
  623. // Accessibility support
  624. ////////////////
  625. /**
  626. * Gets the AccessibleContext associated with this JLayeredPane.
  627. * For layered panes, the AccessibleContext takes the form of an
  628. * AccessibleJLayeredPane.
  629. * A new AccessibleJLayeredPane instance is created if necessary.
  630. *
  631. * @return an AccessibleJLayeredPane that serves as the
  632. * AccessibleContext of this JLayeredPane
  633. */
  634. public AccessibleContext getAccessibleContext() {
  635. if (accessibleContext == null) {
  636. accessibleContext = new AccessibleJLayeredPane();
  637. }
  638. return accessibleContext;
  639. }
  640. /**
  641. * This class implements accessibility support for the
  642. * <code>JLayeredPane</code> class. It provides an implementation of the
  643. * Java Accessibility API appropriate to layered pane user-interface
  644. * elements.
  645. * <p>
  646. * <strong>Warning:</strong>
  647. * Serialized objects of this class will not be compatible with
  648. * future Swing releases. The current serialization support is
  649. * appropriate for short term storage or RMI between applications running
  650. * the same version of Swing. As of 1.4, support for long term storage
  651. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  652. * has been added to the <code>java.beans</code> package.
  653. * Please see {@link java.beans.XMLEncoder}.
  654. */
  655. protected class AccessibleJLayeredPane extends AccessibleJComponent {
  656. /**
  657. * Get the role of this object.
  658. *
  659. * @return an instance of AccessibleRole describing the role of the
  660. * object
  661. * @see AccessibleRole
  662. */
  663. public AccessibleRole getAccessibleRole() {
  664. return AccessibleRole.LAYERED_PANE;
  665. }
  666. }
  667. }