1. /*
  2. * @(#)Panel.java 1.31 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 java.awt;
  8. import java.awt.peer.PanelPeer;
  9. import javax.accessibility.*;
  10. /**
  11. * <code>Panel</code> is the simplest container class. A panel
  12. * provides space in which an application can attach any other
  13. * component, including other panels.
  14. * <p>
  15. * The default layout manager for a panel is the
  16. * <code>FlowLayout</code> layout manager.
  17. *
  18. * @version 1.31, 01/23/03
  19. * @author Sami Shaio
  20. * @see java.awt.FlowLayout
  21. * @since JDK1.0
  22. */
  23. public class Panel extends Container implements Accessible {
  24. private static final String base = "panel";
  25. private static int nameCounter = 0;
  26. /*
  27. * JDK 1.1 serialVersionUID
  28. */
  29. private static final long serialVersionUID = -2728009084054400034L;
  30. /**
  31. * Creates a new panel using the default layout manager.
  32. * The default layout manager for all panels is the
  33. * <code>FlowLayout</code> class.
  34. */
  35. public Panel() {
  36. this(new FlowLayout());
  37. }
  38. /**
  39. * Creates a new panel with the specified layout manager.
  40. * @param layout the layout manager for this panel.
  41. * @since JDK1.1
  42. */
  43. public Panel(LayoutManager layout) {
  44. setLayout(layout);
  45. }
  46. /**
  47. * Construct a name for this component. Called by getName() when the
  48. * name is null.
  49. */
  50. String constructComponentName() {
  51. synchronized (getClass()) {
  52. return base + nameCounter++;
  53. }
  54. }
  55. /**
  56. * Creates the Panel's peer. The peer allows you to modify the
  57. * appearance of the panel without changing its functionality.
  58. */
  59. public void addNotify() {
  60. synchronized (getTreeLock()) {
  61. if (peer == null)
  62. peer = getToolkit().createPanel(this);
  63. super.addNotify();
  64. }
  65. }
  66. /////////////////
  67. // Accessibility support
  68. ////////////////
  69. /**
  70. * Gets the AccessibleContext associated with this Panel.
  71. * For panels, the AccessibleContext takes the form of an
  72. * AccessibleAWTPanel.
  73. * A new AccessibleAWTPanel instance is created if necessary.
  74. *
  75. * @return an AccessibleAWTPanel that serves as the
  76. * AccessibleContext of this Panel
  77. */
  78. public AccessibleContext getAccessibleContext() {
  79. if (accessibleContext == null) {
  80. accessibleContext = new AccessibleAWTPanel();
  81. }
  82. return accessibleContext;
  83. }
  84. /**
  85. * This class implements accessibility support for the
  86. * <code>Panel</code> class. It provides an implementation of the
  87. * Java Accessibility API appropriate to panel user-interface elements.
  88. */
  89. protected class AccessibleAWTPanel extends AccessibleAWTContainer {
  90. /**
  91. * Get the role of this object.
  92. *
  93. * @return an instance of AccessibleRole describing the role of the
  94. * object
  95. */
  96. public AccessibleRole getAccessibleRole() {
  97. return AccessibleRole.PANEL;
  98. }
  99. }
  100. }