[12] | 1 | /*
|
---|
| 2 | * SWTTestCase.java
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
| 6 | * Copyright (c) 2002, 2004 EclipseOS2 Team.
|
---|
| 7 | * This file is made available under the terms of the Common Public License v1.0
|
---|
| 8 | * which accompanies this distribution, and is available at
|
---|
| 9 | * http://www.eclipse.org/legal/cpl-v10.html
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | import java.io.PrintWriter;
|
---|
| 13 | import java.io.StringWriter;
|
---|
| 14 |
|
---|
| 15 | import org.eclipse.swt.*;
|
---|
| 16 | import org.eclipse.swt.widgets.*;
|
---|
| 17 | import org.eclipse.swt.events.*;
|
---|
| 18 | import org.eclipse.swt.graphics.*;
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Common SWT test case class. It overrides init() and done() methods of the
|
---|
| 22 | * base class to create and destroy the display. Also the overriden exec()
|
---|
| 23 | * method calls createTopShell() to create the top shell, initComponents()
|
---|
| 24 | * to initialize shell components and then opens the top shell and starts the
|
---|
| 25 | * main execution loop.
|
---|
| 26 | *
|
---|
| 27 | * Subclasses should normally override only the main() method to call go()
|
---|
| 28 | * as described in the TestCase class, and the initComponents() method to
|
---|
| 29 | * create necessary widgets besides the top shell, register necessary
|
---|
| 30 | * listeners and do other stuff as required by the testcase.
|
---|
| 31 | *
|
---|
| 32 | * By default initComponents() simply calls the setTitle() method. setTitle()
|
---|
| 33 | * (which is not intended to be subclassed) can be used by subclasses to set
|
---|
| 34 | * the current title of the top shell widget, which is composed of the test
|
---|
| 35 | * description string returned by the getFullName() and the argument of the
|
---|
| 36 | * setTitle() method. Default initComponents() implementation calls setTitle()
|
---|
| 37 | * with null argument, which means that only the string returned by
|
---|
| 38 | * getFullName() is set as the widget title.
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 | public class SWTTestCase extends TestCase {
|
---|
| 42 |
|
---|
| 43 | static {
|
---|
| 44 | PART = "SWT";
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | Display display;
|
---|
| 48 | Shell shell;
|
---|
| 49 |
|
---|
| 50 | public static void main (String [] args) {
|
---|
| 51 | go (new SWTTestCase ());
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected void init () {
|
---|
| 55 | display = new Display ();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | protected void done () {
|
---|
| 59 | display.dispose ();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | protected void exec () {
|
---|
| 63 | shell = createTopShell (display);
|
---|
| 64 | initComponents ();
|
---|
| 65 | shell.open ();
|
---|
| 66 | while (!shell.isDisposed ()) {
|
---|
| 67 | if (!display.readAndDispatch ()) display.sleep ();
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | Shell createTopShell (Display display) {
|
---|
| 72 | return new Shell (display);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void initComponents() {
|
---|
| 76 | String t = shell.getText();
|
---|
| 77 | if (t == null || t.length() == 0) setTitle (null);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void setTitle (String title) {
|
---|
| 81 | String t = getFullName();
|
---|
| 82 | if (title != null) {
|
---|
| 83 | t += " [" + title + "]";
|
---|
| 84 | sayObjective (title);
|
---|
| 85 | }
|
---|
| 86 | shell.setText (t);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|