001 /*
002 * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package java.awt;
026
027 import javax.accessibility.*;
028
029 /**
030 * <code>Panel</code> is the simplest container class. A panel
031 * provides space in which an application can attach any other
032 * component, including other panels.
033 * <p>
034 * The default layout manager for a panel is the
035 * <code>FlowLayout</code> layout manager.
036 *
037 * @version 1.46, 06/05/07
038 * @author Sami Shaio
039 * @see java.awt.FlowLayout
040 * @since JDK1.0
041 */
042 public class Panel extends Container implements Accessible {
043 private static final String base = "panel";
044 private static int nameCounter = 0;
045
046 /*
047 * JDK 1.1 serialVersionUID
048 */
049 private static final long serialVersionUID = -2728009084054400034L;
050
051 /**
052 * Creates a new panel using the default layout manager.
053 * The default layout manager for all panels is the
054 * <code>FlowLayout</code> class.
055 */
056 public Panel() {
057 this (new FlowLayout());
058 }
059
060 /**
061 * Creates a new panel with the specified layout manager.
062 * @param layout the layout manager for this panel.
063 * @since JDK1.1
064 */
065 public Panel(LayoutManager layout) {
066 setLayout(layout);
067 }
068
069 /**
070 * Construct a name for this component. Called by getName() when the
071 * name is null.
072 */
073 String constructComponentName() {
074 synchronized (Panel.class) {
075 return base + nameCounter++;
076 }
077 }
078
079 /**
080 * Creates the Panel's peer. The peer allows you to modify the
081 * appearance of the panel without changing its functionality.
082 */
083
084 public void addNotify() {
085 synchronized (getTreeLock()) {
086 if (peer == null)
087 peer = getToolkit().createPanel(this );
088 super .addNotify();
089 }
090 }
091
092 /////////////////
093 // Accessibility support
094 ////////////////
095
096 /**
097 * Gets the AccessibleContext associated with this Panel.
098 * For panels, the AccessibleContext takes the form of an
099 * AccessibleAWTPanel.
100 * A new AccessibleAWTPanel instance is created if necessary.
101 *
102 * @return an AccessibleAWTPanel that serves as the
103 * AccessibleContext of this Panel
104 * @since 1.3
105 */
106 public AccessibleContext getAccessibleContext() {
107 if (accessibleContext == null) {
108 accessibleContext = new AccessibleAWTPanel();
109 }
110 return accessibleContext;
111 }
112
113 /**
114 * This class implements accessibility support for the
115 * <code>Panel</code> class. It provides an implementation of the
116 * Java Accessibility API appropriate to panel user-interface elements.
117 * @since 1.3
118 */
119 protected class AccessibleAWTPanel extends AccessibleAWTContainer {
120
121 private static final long serialVersionUID = -6409552226660031050L;
122
123 /**
124 * Get the role of this object.
125 *
126 * @return an instance of AccessibleRole describing the role of the
127 * object
128 */
129 public AccessibleRole getAccessibleRole() {
130 return AccessibleRole.PANEL;
131 }
132 }
133
134 }
|