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: /**
019: * @author Vadim L. Bogdanov
020: * @version $Revision$
021: */package javax.swing;
022:
023: import java.awt.Component;
024: import java.awt.Container;
025: import java.awt.Frame;
026: import java.awt.Graphics;
027: import java.awt.GraphicsConfiguration;
028: import java.awt.KeyboardFocusManager;
029: import java.awt.LayoutManager;
030: import java.awt.Window;
031:
032: import javax.accessibility.Accessible;
033: import javax.accessibility.AccessibleContext;
034:
035: /**
036: * <code>JWindow</code> implements a top-level container without
037: * any decorations.
038: *
039: */
040: public class JWindow extends Window implements Accessible,
041: RootPaneContainer {
042:
043: protected JRootPane rootPane;
044: protected boolean rootPaneCheckingEnabled;
045: protected AccessibleContext accessibleContext;
046:
047: /**
048: * Constructs a new window in the specified GraphicsConfiguration with
049: * the specified owner.
050: *
051: * @param window - owner of the window
052: * @param gc - the GraphicsConfiguration to construct the frame;
053: * if gc is null, the system default GraphicsConfiguration is assumed
054: */
055: public JWindow(final Window window, final GraphicsConfiguration gc) {
056: super (window == null ? JFrame.getSharedOwner() : window, gc);
057: windowInit();
058: }
059:
060: /**
061: * Constructs a new window (initially invisible) with the specified owner.
062: * If owner is null, the shared owner will be used
063: *
064: * @param window - owner of the window
065: */
066: public JWindow(final Window window) {
067: // It seems that this constructor is not equivalent to
068: // JWindow(window, null).
069: // In this constructor GraphicsConfiguration is taken from the owner;
070: // in JWindow(window, null) GraphicsConfiguration is system default.
071: super (window == null ? JFrame.getSharedOwner() : window);
072: windowInit();
073: }
074:
075: /**
076: * Constructs a new window in the specified GraphicsConfiguration.
077: *
078: * @param gc - the GraphicsConfiguration to construct the frame;
079: * if gc is null, the system default GraphicsConfiguration is assumed
080: */
081: public JWindow(final GraphicsConfiguration gc) {
082: this (null, gc);
083: }
084:
085: /**
086: * Constructs a new window (initially invisible) with the specified owner.
087: * If owner is null, the shared owner will be used
088: *
089: * @param frame - owner of the window
090: */
091: public JWindow(final Frame frame) {
092: super (frame == null ? JFrame.getSharedOwner() : frame);
093: windowInit();
094: }
095:
096: /**
097: * Constructs a new window with no specified owner.
098: */
099: public JWindow() {
100: this ((Frame) null);
101: }
102:
103: /**
104: * This class implements accessibility support for <code>JWindow</code>.
105: */
106: protected class AccessibleJWindow extends AccessibleAWTWindow {
107: protected AccessibleJWindow() {
108: super ();
109: }
110: }
111:
112: /**
113: *
114: */
115: protected void addImpl(final Component comp,
116: final Object constraints, final int index) {
117: if (isRootPaneCheckingEnabled()) {
118: getContentPane().add(comp, constraints, index);
119: return;
120: }
121:
122: super .addImpl(comp, constraints, index);
123: }
124:
125: /**
126: * Set rootPane property.
127: *
128: * @param root
129: */
130: protected void setRootPane(final JRootPane root) {
131: if (rootPane != null) {
132: remove(rootPane);
133: }
134:
135: rootPane = root;
136:
137: if (root != null) {
138: super .addImpl(root, null, 0);
139: }
140: }
141:
142: /**
143: * Get rootPane property.
144: *
145: * @return rootPane property
146: */
147: public JRootPane getRootPane() {
148: return rootPane;
149: }
150:
151: /**
152: * Called by the constructors to create the default rootPane property.
153: *
154: * @return default JRootPane
155: */
156: protected JRootPane createRootPane() {
157: return new JRootPane();
158: }
159:
160: /**
161: * Sets layeredPane property.
162: *
163: * @param layeredPane - new layeredPane property value
164: */
165: public void setLayeredPane(final JLayeredPane layeredPane) {
166: getRootPane().setLayeredPane(layeredPane);
167: }
168:
169: /**
170: * Returns layeredPane property.
171: *
172: * @return layeredPane property
173: */
174: public JLayeredPane getLayeredPane() {
175: return getRootPane().getLayeredPane();
176: }
177:
178: /**
179: * Returns the accessible context for the window.
180: *
181: * @return the accessible context for the window
182: */
183: public AccessibleContext getAccessibleContext() {
184: if (accessibleContext == null) {
185: accessibleContext = new AccessibleJWindow();
186: }
187:
188: return accessibleContext;
189: }
190:
191: /**
192: * Returns string representation of this window.
193: *
194: * @return string representation of this window
195: */
196: protected String paramString() {
197: return super .paramString();
198: }
199:
200: /**
201: *
202: */
203: public void setLayout(final LayoutManager layout) {
204: if (isRootPaneCheckingEnabled()) {
205: getContentPane().setLayout(layout);
206: } else {
207: super .setLayout(layout);
208: }
209: }
210:
211: /**
212: * Just calls paint(g). This method was overridden to prevent an
213: * unnecessary call to clear the background.
214: *
215: * @param g - the graphics context to paint
216: */
217: public void update(final Graphics g) {
218: paint(g);
219: }
220:
221: /**
222: * Sets contentPane property.
223: *
224: * @param contentPane - new contentPane property value
225: */
226: public void setContentPane(final Container contentPane) {
227: getRootPane().setContentPane(contentPane);
228: }
229:
230: /**
231: * Returns the contentPane property.
232: *
233: * @return the contentPane property
234: */
235: public Container getContentPane() {
236: return getRootPane().getContentPane();
237: }
238:
239: /**
240: * Set glassPane property.
241: *
242: * @param glassPane - new glassPane property value
243: */
244: public void setGlassPane(final Component glassPane) {
245: getRootPane().setGlassPane(glassPane);
246: }
247:
248: /**
249: *
250: */
251: public void remove(final Component comp) {
252: if (comp == getRootPane()) {
253: // remove directly from JWindow
254: super .remove(comp);
255: } else {
256: getContentPane().remove(comp);
257: }
258: }
259:
260: /**
261: * Returns glassPane property.
262: *
263: * @return glassPane property
264: */
265: public Component getGlassPane() {
266: return getRootPane().getGlassPane();
267: }
268:
269: /**
270: * Sets rootPaneCheckingEnabled.
271: *
272: * @param enabled - new rootPaneCheckingEnabled value
273: */
274: protected void setRootPaneCheckingEnabled(final boolean enabled) {
275: rootPaneCheckingEnabled = enabled;
276: }
277:
278: /**
279: * Returns rootPaneCheckingEnabled value.
280: *
281: * @return value of rootPaneCheckingEnabled
282: */
283: protected boolean isRootPaneCheckingEnabled() {
284: return rootPaneCheckingEnabled;
285: }
286:
287: /**
288: * Called by the constructors to init JWindow
289: */
290: protected void windowInit() {
291: setRootPaneCheckingEnabled(true);
292:
293: setRootPane(createRootPane());
294:
295: setLocale(JComponent.getDefaultLocale());
296:
297: setFocusTraversalPolicy(KeyboardFocusManager
298: .getCurrentKeyboardFocusManager()
299: .getDefaultFocusTraversalPolicy());
300:
301: // background shouldn't be initialized
302: }
303: }
|