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.Point;
24:
25: public class PopupTest extends BasicSwingTestCase {
26: private Popup popup;
27:
28: public PopupTest(final String name) {
29: super (name);
30: }
31:
32: @Override
33: protected void tearDown() throws Exception {
34: popup = null;
35: }
36:
37: public void testPopup() throws Exception {
38: Component content = new JButton("content");
39: assertNull(content.getParent());
40: popup = new Popup(null, content, 10, 10);
41: assertNotNull(content.getParent());
42: assertFalse(content.isShowing());
43: popup.show();
44: assertTrue(content.isShowing());
45: assertEquals(new Point(10, 10), content.getLocationOnScreen());
46: popup.show();
47: assertTrue(content.isShowing());
48: popup.hide();
49: assertFalse(content.isShowing());
50: JPanel owner = new JPanel();
51: popup = new Popup(owner, content, 10, 10);
52: assertNotNull(content.getParent());
53: assertFalse(content.isShowing());
54: popup.show();
55: assertTrue(content.isShowing());
56: assertEquals(new Point(10, 10), content.getLocationOnScreen());
57: JFrame ownedFrame = new JFrame();
58: ownedFrame.setLocation(100, 100);
59: ownedFrame.getContentPane().add(owner);
60: ownedFrame.setVisible(true);
61: SwingWaitTestCase.isRealized(ownedFrame);
62: popup = new Popup(owner, content, 10, 10);
63: popup.show();
64: assertEquals(new Point(10, 10), content.getLocationOnScreen());
65: testExceptionalCase(new IllegalArgumentCase() {
66: @Override
67: public void exceptionalAction() throws Exception {
68: new Popup(null, null, 10, 10);
69: }
70: });
71: }
72:
73: public void testShowHide() throws Exception {
74: Component content = new JButton("content");
75: assertNull(SwingUtilities.getWindowAncestor(content));
76: popup = new Popup(null, content, 100, 200);
77: assertNotNull(SwingUtilities.getWindowAncestor(content));
78: popup.show();
79: assertTrue(content.isShowing());
80: assertEquals(new Point(100, 200), content.getLocationOnScreen());
81: popup.hide();
82: assertNull(SwingUtilities.getWindowAncestor(content));
83: assertFalse(content.isShowing());
84: }
85: }
|