001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing;
021:
022: import java.awt.LayoutManager;
023: import java.awt.FlowLayout;
024: import java.io.Serializable;
025:
026: import javax.accessibility.Accessible;
027: import javax.accessibility.AccessibleContext;
028: import javax.accessibility.AccessibleRole;
029: import javax.swing.plaf.PanelUI;
030:
031: /**
032: * <code>JPanel</code> is a simple lightweight container.
033: *
034: */
035: public class JPanel extends JComponent implements Accessible,
036: Serializable {
037:
038: protected class AccessibleJPanel extends
039: JComponent.AccessibleJComponent {
040: public AccessibleRole getAccessibleRole() {
041: return AccessibleRole.PANEL;
042: }
043: }
044:
045: private final static String UI_CLASS_ID = "PanelUI";
046:
047: /**
048: * Creates <code>JPanel</code> with given layout and buffering strategy
049: *
050: * @param layout specifies layout for the panel
051: * @param isDoubleBuffered specifies buffering strategy for the panel
052: */
053: public JPanel(final LayoutManager layout,
054: final boolean isDoubleBuffered) {
055: setDoubleBuffered(isDoubleBuffered);
056: setLayout(layout);
057: LookAndFeel.installProperty(this , "opaque", Boolean.TRUE);
058: updateUI();
059: }
060:
061: /**
062: *
063: * Creates buffered <code>JPanel</code> with given layout
064: *
065: * @param layout specifies layout for the panel
066: */
067: public JPanel(final LayoutManager layout) {
068: this (layout, true);
069: }
070:
071: /**
072: *
073: * Creates <code>JPanel</code> with flowlayout and given buffering strategy
074: *
075: * @param isDoubleBuffered specifies the value for buffering strategy
076: */
077: public JPanel(final boolean isDoubleBuffered) {
078: this (new FlowLayout(), isDoubleBuffered);
079: }
080:
081: /**
082: * Creates doubleBuffered <code>JPanel</code> with flowlayout
083: */
084: public JPanel() {
085: this (new FlowLayout(), true);
086: }
087:
088: /**
089: *
090: * Sets new value for look-and-feel object for the panel
091: *
092: * @param ui new look-and-feel renderer
093: */
094: public void setUI(final PanelUI ui) {
095: super .setUI(ui);
096: }
097:
098: /**
099: *
100: * Gets the value of the look-and-feel object of the panel
101: *
102: * @return the <code>PanelUI</code> - components look-and-feel object
103: */
104: public PanelUI getUI() {
105: return (PanelUI) ui;
106: }
107:
108: /**
109: *
110: * Gets <code>AccessibleContext</code> of the panel.
111: *
112: * @return an <code>AccessibleJPanel</code> object as the <code>AccessibleContext</code> for this JPanel
113: */
114: public AccessibleContext getAccessibleContext() {
115: return (accessibleContext == null) ? (accessibleContext = new AccessibleJPanel())
116: : accessibleContext;
117: }
118:
119: /**
120: *
121: * Returns string that describes <code>JPanel</code>. Is usefull for debugging purposes.
122: *
123: * @return <code>JPanel</code> string representation
124: */
125: protected String paramString() {
126: return super .paramString();
127: }
128:
129: /**
130: *
131: * Returns name for panel look-and-feel class
132: *
133: * @return <code>"PanelUI"</code>
134: */
135: public String getUIClassID() {
136: return UI_CLASS_ID;
137: }
138:
139: /**
140: * Sets value taken from current L&F to UI property of the panel
141: */
142: public void updateUI() {
143: setUI((PanelUI) UIManager.getUI(this));
144: }
145: }
|