01: /*
02: * @(#)AWTTestContainer.java 1.6 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package gunit.container;
28:
29: import java.awt.*;
30: import java.awt.event.*;
31:
32: /**
33: * <code>AWTTestContainer</code> is an implementation of
34: * <code>TestContainer</code> that uses AWT Frame as the container
35: */
36: public class AWTTestContainer implements gunit.framework.TestContainer {
37: Frame testContainer;
38:
39: public AWTTestContainer() {
40: this .testContainer = new Frame("GUnit:AWT Test Frame");
41: showTestContainer();
42: }
43:
44: private static final int DEFAULT_WIDTH = 640;
45: private static final int DEFAULT_HEIGHT = 442;
46:
47: public void showTestContainer() {
48: this .testContainer.setLayout(new BorderLayout());
49: int width = DEFAULT_WIDTH;
50: int height = DEFAULT_HEIGHT;
51: String dim = System.getProperty("gunit.awt.frame.window.size",
52: "640x442");
53: if (dim != null && dim.length() > 0) {
54: int index = dim.indexOf("x");
55: if (index > 0) {
56: try {
57: width = Integer.parseInt(dim.substring(0, index));
58: height = Integer.parseInt(dim.substring(index + 1));
59: } catch (Exception ex) {
60: }
61: }
62: }
63:
64: this .testContainer.addWindowListener(new WindowAdapter() {
65: public void windowClosing(WindowEvent e) {
66: System.exit(0);
67: }
68: });
69:
70: // Dont setSize for PBP.
71: if (isJ2SE())
72: this .testContainer.setSize(width, height);
73: this .testContainer.setVisible(true);
74: }
75:
76: // gunit.framework.TestContainer
77: public Container getContainer() {
78: return this .testContainer;
79: }
80:
81: public static boolean isJ2SE() {
82: try {
83: // for now this class does not exist in PP/PBP
84: Class.forName("javax.naming.Context");
85: return true;
86: } catch (Exception ex) {
87: }
88: return false;
89: }
90: }
|