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