01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.awt.Component;
23: import java.awt.Window;
24:
25: import org.apache.harmony.awt.ComponentInternals;
26:
27: import org.apache.harmony.x.swing.internal.nls.Messages;
28:
29: public class Popup {
30: class PopupWindow extends JWindow {
31: public PopupWindow(final Window owner) {
32: super (owner);
33: setFocusableWindowState(false);
34: ComponentInternals.getComponentInternals().makePopup(this );
35: }
36:
37: public void init(final Component c, final int x, final int y) {
38: getContentPane().add(c);
39:
40: pack();
41: setLocation(x, y);
42: }
43:
44: public void reset() {
45: getContentPane().removeAll();
46: }
47:
48: public void hide() {
49: reset();
50: super .hide();
51: }
52:
53: public void dispose() {
54: reset();
55: super .dispose();
56: }
57: }
58:
59: PopupWindow popupWindow;
60:
61: protected Popup() {
62: }
63:
64: protected Popup(final Component owner, final Component content,
65: final int x, final int y) {
66: if (content == null) {
67: throw new IllegalArgumentException(Messages
68: .getString("swing.52")); //$NON-NLS-1$
69: }
70:
71: Window ownerWindow = owner instanceof Window ? (Window) owner
72: : SwingUtilities.getWindowAncestor(owner);
73: popupWindow = new PopupWindow(ownerWindow != null ? ownerWindow
74: : JFrame.getSharedOwner());
75: popupWindow.init(content, x, y);
76: }
77:
78: public void show() {
79: popupWindow.show();
80: }
81:
82: public void hide() {
83: popupWindow.dispose();
84: }
85: }
|