author | rriggs |
Tue, 03 Jun 2014 11:18:03 -0400 | |
changeset 25122 | 1ecc464c69d2 |
parent 22574 | 7f8ce0c8c20a |
child 25201 | 4adc75e0c4e5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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.*; |
|
28 |
||
29 |
import javax.swing.plaf.*; |
|
30 |
import javax.accessibility.*; |
|
31 |
||
32 |
import java.io.Serializable; |
|
33 |
import java.io.ObjectOutputStream; |
|
34 |
import java.io.ObjectInputStream; |
|
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 |
* @beaninfo |
|
60 |
* description: A generic lightweight container. |
|
61 |
* |
|
62 |
* @author Arnaud Weber |
|
63 |
* @author Steve Wilson |
|
64 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
65 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 66 |
public class JPanel extends JComponent implements Accessible |
67 |
{ |
|
68 |
/** |
|
69 |
* @see #getUIClassID |
|
70 |
* @see #readObject |
|
71 |
*/ |
|
72 |
private static final String uiClassID = "PanelUI"; |
|
73 |
||
74 |
/** |
|
75 |
* Creates a new JPanel with the specified layout manager and buffering |
|
76 |
* strategy. |
|
77 |
* |
|
78 |
* @param layout the LayoutManager to use |
|
79 |
* @param isDoubleBuffered a boolean, true for double-buffering, which |
|
80 |
* uses additional memory space to achieve fast, flicker-free |
|
81 |
* updates |
|
82 |
*/ |
|
83 |
public JPanel(LayoutManager layout, boolean isDoubleBuffered) { |
|
84 |
setLayout(layout); |
|
85 |
setDoubleBuffered(isDoubleBuffered); |
|
86 |
setUIProperty("opaque", Boolean.TRUE); |
|
87 |
updateUI(); |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Create a new buffered JPanel with the specified layout manager |
|
92 |
* |
|
93 |
* @param layout the LayoutManager to use |
|
94 |
*/ |
|
95 |
public JPanel(LayoutManager layout) { |
|
96 |
this(layout, true); |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Creates a new <code>JPanel</code> with <code>FlowLayout</code> |
|
101 |
* and the specified buffering strategy. |
|
102 |
* If <code>isDoubleBuffered</code> is true, the <code>JPanel</code> |
|
103 |
* will use a double buffer. |
|
104 |
* |
|
105 |
* @param isDoubleBuffered a boolean, true for double-buffering, which |
|
106 |
* uses additional memory space to achieve fast, flicker-free |
|
107 |
* updates |
|
108 |
*/ |
|
109 |
public JPanel(boolean isDoubleBuffered) { |
|
110 |
this(new FlowLayout(), isDoubleBuffered); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Creates a new <code>JPanel</code> with a double buffer |
|
115 |
* and a flow layout. |
|
116 |
*/ |
|
117 |
public JPanel() { |
|
118 |
this(true); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Resets the UI property with a value from the current look and feel. |
|
123 |
* |
|
124 |
* @see JComponent#updateUI |
|
125 |
*/ |
|
126 |
public void updateUI() { |
|
127 |
setUI((PanelUI)UIManager.getUI(this)); |
|
128 |
} |
|
129 |
||
130 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
131 |
* Returns the look and feel (L&amp;F) object that renders this component. |
2 | 132 |
* |
133 |
* @return the PanelUI object that renders this component |
|
134 |
* @since 1.4 |
|
135 |
*/ |
|
136 |
public PanelUI getUI() { |
|
137 |
return (PanelUI)ui; |
|
138 |
} |
|
139 |
||
140 |
||
141 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
142 |
* Sets the look and feel (L&F) object that renders this component. |
2 | 143 |
* |
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
144 |
* @param ui the PanelUI L&F object |
2 | 145 |
* @see UIDefaults#getUI |
146 |
* @since 1.4 |
|
147 |
* @beaninfo |
|
148 |
* bound: true |
|
149 |
* hidden: true |
|
150 |
* attribute: visualUpdate true |
|
151 |
* description: The UI object that implements the Component's LookAndFeel. |
|
152 |
*/ |
|
153 |
public void setUI(PanelUI ui) { |
|
154 |
super.setUI(ui); |
|
155 |
} |
|
156 |
||
157 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
158 |
* Returns a string that specifies the name of the L&F class |
2 | 159 |
* that renders this component. |
160 |
* |
|
161 |
* @return "PanelUI" |
|
162 |
* @see JComponent#getUIClassID |
|
163 |
* @see UIDefaults#getUI |
|
164 |
* @beaninfo |
|
165 |
* expert: true |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
5506
diff
changeset
|
166 |
* description: A string that specifies the name of the L&F class. |
2 | 167 |
*/ |
168 |
public String getUIClassID() { |
|
169 |
return uiClassID; |
|
170 |
} |
|
171 |
||
172 |
||
173 |
/** |
|
174 |
* See readObject() and writeObject() in JComponent for more |
|
175 |
* information about serialization in Swing. |
|
176 |
*/ |
|
177 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
178 |
s.defaultWriteObject(); |
|
179 |
if (getUIClassID().equals(uiClassID)) { |
|
180 |
byte count = JComponent.getWriteObjCounter(this); |
|
181 |
JComponent.setWriteObjCounter(this, --count); |
|
182 |
if (count == 0 && ui != null) { |
|
183 |
ui.installUI(this); |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
||
189 |
/** |
|
190 |
* Returns a string representation of this JPanel. This method |
|
191 |
* is intended to be used only for debugging purposes, and the |
|
192 |
* content and format of the returned string may vary between |
|
193 |
* implementations. The returned string may be empty but may not |
|
194 |
* be <code>null</code>. |
|
195 |
* |
|
196 |
* @return a string representation of this JPanel. |
|
197 |
*/ |
|
198 |
protected String paramString() { |
|
199 |
return super.paramString(); |
|
200 |
} |
|
201 |
||
202 |
///////////////// |
|
203 |
// Accessibility support |
|
204 |
//////////////// |
|
205 |
||
206 |
/** |
|
207 |
* Gets the AccessibleContext associated with this JPanel. |
|
208 |
* For JPanels, the AccessibleContext takes the form of an |
|
209 |
* AccessibleJPanel. |
|
210 |
* A new AccessibleJPanel instance is created if necessary. |
|
211 |
* |
|
212 |
* @return an AccessibleJPanel that serves as the |
|
213 |
* AccessibleContext of this JPanel |
|
214 |
*/ |
|
215 |
public AccessibleContext getAccessibleContext() { |
|
216 |
if (accessibleContext == null) { |
|
217 |
accessibleContext = new AccessibleJPanel(); |
|
218 |
} |
|
219 |
return accessibleContext; |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* This class implements accessibility support for the |
|
224 |
* <code>JPanel</code> class. It provides an implementation of the |
|
225 |
* Java Accessibility API appropriate to panel user-interface |
|
226 |
* elements. |
|
227 |
* <p> |
|
228 |
* <strong>Warning:</strong> |
|
229 |
* Serialized objects of this class will not be compatible with |
|
230 |
* future Swing releases. The current serialization support is |
|
231 |
* appropriate for short term storage or RMI between applications running |
|
232 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 233 |
* of all JavaBeans™ |
2 | 234 |
* has been added to the <code>java.beans</code> package. |
235 |
* Please see {@link java.beans.XMLEncoder}. |
|
236 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
237 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 238 |
protected class AccessibleJPanel extends AccessibleJComponent { |
239 |
||
240 |
/** |
|
241 |
* Get the role of this object. |
|
242 |
* |
|
243 |
* @return an instance of AccessibleRole describing the role of the |
|
244 |
* object |
|
245 |
*/ |
|
246 |
public AccessibleRole getAccessibleRole() { |
|
247 |
return AccessibleRole.PANEL; |
|
248 |
} |
|
249 |
} |
|
250 |
} |