author | aghaisas |
Mon, 10 Jul 2017 14:55:29 +0530 | |
changeset 47151 | 362dcbee0613 |
parent 33253 | 78e735319356 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing; |
|
26 |
||
27 |
import java.awt.*; |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
28 |
import java.beans.JavaBean; |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
29 |
import java.beans.BeanProperty; |
2 | 30 |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.accessibility.*; |
|
33 |
||
34 |
import java.io.ObjectOutputStream; |
|
35 |
import java.io.IOException; |
|
36 |
||
37 |
||
38 |
/** |
|
39 |
* <code>JPanel</code> is a generic lightweight container. |
|
40 |
* For examples and task-oriented documentation for JPanel, see |
|
41 |
* <a |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
20157
diff
changeset
|
42 |
href="http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html">How to Use Panels</a>, |
2 | 43 |
* a section in <em>The Java Tutorial</em>. |
44 |
* <p> |
|
45 |
* <strong>Warning:</strong> Swing is not thread safe. For more |
|
46 |
* information see <a |
|
47 |
* href="package-summary.html#threading">Swing's Threading |
|
48 |
* Policy</a>. |
|
49 |
* <p> |
|
50 |
* <strong>Warning:</strong> |
|
51 |
* Serialized objects of this class will not be compatible with |
|
52 |
* future Swing releases. The current serialization support is |
|
53 |
* appropriate for short term storage or RMI between applications running |
|
54 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 55 |
* of all JavaBeans™ |
2 | 56 |
* has been added to the <code>java.beans</code> package. |
57 |
* Please see {@link java.beans.XMLEncoder}. |
|
58 |
* |
|
59 |
* @author Arnaud Weber |
|
60 |
* @author Steve Wilson |
|
25201
4adc75e0c4e5
8046485: Add missing @since tag under javax.swing.*
henryjen
parents:
22574
diff
changeset
|
61 |
* @since 1.2 |
2 | 62 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
63 |
@JavaBean(defaultProperty = "UI", description = "A generic lightweight container.") |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
64 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 65 |
public class JPanel extends JComponent implements Accessible |
66 |
{ |
|
67 |
/** |
|
68 |
* @see #getUIClassID |
|
69 |
* @see #readObject |
|
70 |
*/ |
|
71 |
private static final String uiClassID = "PanelUI"; |
|
72 |
||
73 |
/** |
|
74 |
* Creates a new JPanel with the specified layout manager and buffering |
|
75 |
* strategy. |
|
76 |
* |
|
77 |
* @param layout the LayoutManager to use |
|
78 |
* @param isDoubleBuffered a boolean, true for double-buffering, which |
|
79 |
* uses additional memory space to achieve fast, flicker-free |
|
80 |
* updates |
|
81 |
*/ |
|
82 |
public JPanel(LayoutManager layout, boolean isDoubleBuffered) { |
|
83 |
setLayout(layout); |
|
84 |
setDoubleBuffered(isDoubleBuffered); |
|
85 |
setUIProperty("opaque", Boolean.TRUE); |
|
86 |
updateUI(); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Create a new buffered JPanel with the specified layout manager |
|
91 |
* |
|
92 |
* @param layout the LayoutManager to use |
|
93 |
*/ |
|
94 |
public JPanel(LayoutManager layout) { |
|
95 |
this(layout, true); |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* Creates a new <code>JPanel</code> with <code>FlowLayout</code> |
|
100 |
* and the specified buffering strategy. |
|
101 |
* If <code>isDoubleBuffered</code> is true, the <code>JPanel</code> |
|
102 |
* will use a double buffer. |
|
103 |
* |
|
104 |
* @param isDoubleBuffered a boolean, true for double-buffering, which |
|
105 |
* uses additional memory space to achieve fast, flicker-free |
|
106 |
* updates |
|
107 |
*/ |
|
108 |
public JPanel(boolean isDoubleBuffered) { |
|
109 |
this(new FlowLayout(), isDoubleBuffered); |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Creates a new <code>JPanel</code> with a double buffer |
|
114 |
* and a flow layout. |
|
115 |
*/ |
|
116 |
public JPanel() { |
|
117 |
this(true); |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Resets the UI property with a value from the current look and feel. |
|
122 |
* |
|
123 |
* @see JComponent#updateUI |
|
124 |
*/ |
|
125 |
public void updateUI() { |
|
126 |
setUI((PanelUI)UIManager.getUI(this)); |
|
127 |
} |
|
128 |
||
129 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
130 |
* Returns the look and feel (L&amp;F) object that renders this component. |
2 | 131 |
* |
132 |
* @return the PanelUI object that renders this component |
|
133 |
* @since 1.4 |
|
134 |
*/ |
|
135 |
public PanelUI getUI() { |
|
136 |
return (PanelUI)ui; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
141 |
* Sets the look and feel (L&F) object that renders this component. |
2 | 142 |
* |
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
143 |
* @param ui the PanelUI L&F object |
2 | 144 |
* @see UIDefaults#getUI |
145 |
* @since 1.4 |
|
146 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
147 |
@BeanProperty(hidden = true, visualUpdate = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
148 |
= "The UI object that implements the Component's LookAndFeel.") |
2 | 149 |
public void setUI(PanelUI ui) { |
150 |
super.setUI(ui); |
|
151 |
} |
|
152 |
||
153 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
154 |
* Returns a string that specifies the name of the L&F class |
2 | 155 |
* that renders this component. |
156 |
* |
|
157 |
* @return "PanelUI" |
|
158 |
* @see JComponent#getUIClassID |
|
159 |
* @see UIDefaults#getUI |
|
160 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
161 |
@BeanProperty(bound = false, expert = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
162 |
= "A string that specifies the name of the L&F class.") |
2 | 163 |
public String getUIClassID() { |
164 |
return uiClassID; |
|
165 |
} |
|
166 |
||
167 |
||
168 |
/** |
|
169 |
* See readObject() and writeObject() in JComponent for more |
|
170 |
* information about serialization in Swing. |
|
171 |
*/ |
|
172 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
173 |
s.defaultWriteObject(); |
|
174 |
if (getUIClassID().equals(uiClassID)) { |
|
175 |
byte count = JComponent.getWriteObjCounter(this); |
|
176 |
JComponent.setWriteObjCounter(this, --count); |
|
177 |
if (count == 0 && ui != null) { |
|
178 |
ui.installUI(this); |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
||
184 |
/** |
|
185 |
* Returns a string representation of this JPanel. This method |
|
186 |
* is intended to be used only for debugging purposes, and the |
|
187 |
* content and format of the returned string may vary between |
|
188 |
* implementations. The returned string may be empty but may not |
|
189 |
* be <code>null</code>. |
|
190 |
* |
|
191 |
* @return a string representation of this JPanel. |
|
192 |
*/ |
|
193 |
protected String paramString() { |
|
194 |
return super.paramString(); |
|
195 |
} |
|
196 |
||
197 |
///////////////// |
|
198 |
// Accessibility support |
|
199 |
//////////////// |
|
200 |
||
201 |
/** |
|
202 |
* Gets the AccessibleContext associated with this JPanel. |
|
203 |
* For JPanels, the AccessibleContext takes the form of an |
|
204 |
* AccessibleJPanel. |
|
205 |
* A new AccessibleJPanel instance is created if necessary. |
|
206 |
* |
|
207 |
* @return an AccessibleJPanel that serves as the |
|
208 |
* AccessibleContext of this JPanel |
|
209 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
25859
diff
changeset
|
210 |
@BeanProperty(bound = false) |
2 | 211 |
public AccessibleContext getAccessibleContext() { |
212 |
if (accessibleContext == null) { |
|
213 |
accessibleContext = new AccessibleJPanel(); |
|
214 |
} |
|
215 |
return accessibleContext; |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* This class implements accessibility support for the |
|
220 |
* <code>JPanel</code> class. It provides an implementation of the |
|
221 |
* Java Accessibility API appropriate to panel user-interface |
|
222 |
* elements. |
|
223 |
* <p> |
|
224 |
* <strong>Warning:</strong> |
|
225 |
* Serialized objects of this class will not be compatible with |
|
226 |
* future Swing releases. The current serialization support is |
|
227 |
* appropriate for short term storage or RMI between applications running |
|
228 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 229 |
* of all JavaBeans™ |
2 | 230 |
* has been added to the <code>java.beans</code> package. |
231 |
* Please see {@link java.beans.XMLEncoder}. |
|
232 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
233 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 234 |
protected class AccessibleJPanel extends AccessibleJComponent { |
235 |
||
236 |
/** |
|
237 |
* Get the role of this object. |
|
238 |
* |
|
239 |
* @return an instance of AccessibleRole describing the role of the |
|
240 |
* object |
|
241 |
*/ |
|
242 |
public AccessibleRole getAccessibleRole() { |
|
243 |
return AccessibleRole.PANEL; |
|
244 |
} |
|
245 |
} |
|
246 |
} |