1 | /*
|
---|
2 | * SWT004_01.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 | * This example tests the sizing/positioning methods of Shell widgets.
|
---|
22 | * It creates five windows arranged chessboard fashion with the top window
|
---|
23 | * in the center and secondary windows exactly in the corners of the screen.
|
---|
24 | * First time the sizing/positioning is made using setBounds() method,
|
---|
25 | * second time (after the top window is closed) -- using setLocation()/setSize()
|
---|
26 | * methods.
|
---|
27 | */
|
---|
28 |
|
---|
29 | public class SWT004_01 extends SWTTestCase {
|
---|
30 |
|
---|
31 | static {
|
---|
32 | STEP= "004";
|
---|
33 | TEST = "01";
|
---|
34 | DESC = "Sizing/Positioning";
|
---|
35 | }
|
---|
36 |
|
---|
37 | boolean separate;
|
---|
38 | String title;
|
---|
39 |
|
---|
40 | public static void main (String [] args) {
|
---|
41 | go (new SWT004_01 ());
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected void exec () {
|
---|
45 | sayObjective ("Test of size/position methods");
|
---|
46 | title = "SWT004_01 [Part 1]: ";
|
---|
47 | saySubObjective ("Part 1: Positioning using setBounds():");
|
---|
48 | super.exec ();
|
---|
49 | separate = true;
|
---|
50 | title = "SWT004_01 [Part 2]: ";
|
---|
51 | saySubObjective ("\nPart 2: Positioning using setLocation()/setSize():");
|
---|
52 | super.exec ();
|
---|
53 | }
|
---|
54 |
|
---|
55 | void testSetBounds (Shell shell, int x, int y, int w, int h, boolean separate) {
|
---|
56 | if (separate) {
|
---|
57 | shell.setLocation (x, y);
|
---|
58 | shell.setSize (w, h);
|
---|
59 | }
|
---|
60 | else
|
---|
61 | shell.setBounds (x, y, w, h);
|
---|
62 | }
|
---|
63 |
|
---|
64 | void testMinMax (Shell shell) {
|
---|
65 | System.out.println ("Min/Max Subtest [" + shell.getText () + "]:");
|
---|
66 |
|
---|
67 | System.out.println (" bounds when normal:");
|
---|
68 | System.out.println (" shell.getBounds() = " + shell.getBounds ());
|
---|
69 | System.out.println (" shell.getClientArea() = " + shell.getClientArea ());
|
---|
70 |
|
---|
71 | shell.setMinimized (true);
|
---|
72 | System.out.println (" bounds when minimized:");
|
---|
73 | System.out.println (" shell.getBounds() = " + shell.getBounds ());
|
---|
74 | System.out.println (" shell.getClientArea() = " + shell.getClientArea ());
|
---|
75 |
|
---|
76 | shell.setMaximized (true);
|
---|
77 | System.out.println (" bounds when maximized:");
|
---|
78 | System.out.println (" shell.getBounds() = " + shell.getBounds ());
|
---|
79 | System.out.println (" shell.getClientArea() = " + shell.getClientArea ());
|
---|
80 |
|
---|
81 | shell.setMaximized (false);
|
---|
82 | }
|
---|
83 |
|
---|
84 | Shell createTopShell (Display display) {
|
---|
85 |
|
---|
86 | Shell shell = new Shell (display);
|
---|
87 |
|
---|
88 | DisposeListener dl = new DisposeListener () {
|
---|
89 | public void widgetDisposed (DisposeEvent e)
|
---|
90 | {
|
---|
91 | System.out.println ("DisposeListener.widgetDisposed():");
|
---|
92 | if (e.widget instanceof Control)
|
---|
93 | {
|
---|
94 | System.out.println (" hwnd = " +
|
---|
95 | Integer.toHexString (((Control)e.widget).handle));
|
---|
96 | System.out.println (" bounds = " +
|
---|
97 | ((Control)e.widget).getBounds());
|
---|
98 | }
|
---|
99 | if (e.widget instanceof Decorations)
|
---|
100 | System.out.println (" title = [" +
|
---|
101 | ((Decorations)e.widget).getText() + "]");
|
---|
102 | }
|
---|
103 | };
|
---|
104 | shell.addDisposeListener (dl);
|
---|
105 | shell.setText (title + "Top Shell");
|
---|
106 |
|
---|
107 | //Rectangle r = display.getBounds ();
|
---|
108 | Rectangle r = display.getClientArea ();
|
---|
109 | int sh, sw, ssh, ssw;
|
---|
110 | ssw = r.width / 3;
|
---|
111 | sw = r.width - ssw * 2;
|
---|
112 | ssh = r.height / 3;
|
---|
113 | sh = r.height - ssh * 2;
|
---|
114 |
|
---|
115 | System.out.println ("bounds after creation: " + shell.getBounds());
|
---|
116 | testSetBounds (shell, ssw, ssh, sw, sh, separate);
|
---|
117 |
|
---|
118 | for( int i = 1; i <= 4; i++ )
|
---|
119 | {
|
---|
120 | Shell s = new Shell (shell);
|
---|
121 | System.out.println ("bounds after creation: " + s.getBounds());
|
---|
122 | s.addDisposeListener(dl);
|
---|
123 | s.setText (title + "Secondary Shell #" + i);
|
---|
124 | switch( i ) {
|
---|
125 | case 1:
|
---|
126 | testSetBounds (s, 0, 0, ssw, ssh, separate); break;
|
---|
127 | case 2:
|
---|
128 | testSetBounds (s, ssw+sw, 0, ssw, ssh, separate); break;
|
---|
129 | case 3:
|
---|
130 | testSetBounds (s, 0, ssh+sh, ssw, ssh, separate); break;
|
---|
131 | case 4:
|
---|
132 | testSetBounds (s, ssw+sw, ssh+sh, ssw, ssh, separate); break;
|
---|
133 | }
|
---|
134 | s.open ();
|
---|
135 | testMinMax (s);
|
---|
136 | }
|
---|
137 |
|
---|
138 | shell.open ();
|
---|
139 | testMinMax (shell);
|
---|
140 | return shell;
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|