26
26
* @bug 6647340
27
27
* @summary Checks that iconified internal frame follows
28
28
* the main frame borders properly.
29
- * @author Mikhail Lapshin
30
- * @library /lib/client/
31
- * @build ExtendedRobot
32
29
* @run main bug6647340
33
30
*/
34
31
38
35
39
36
public class bug6647340 {
40
37
private JFrame frame ;
41
- private Point location ;
38
+ private volatile Point location ;
39
+ private volatile Point iconloc ;
42
40
private JInternalFrame jif ;
43
- private static ExtendedRobot robot = createRobot () ;
41
+ private static Robot robot ;
44
42
45
43
public static void main (String [] args ) throws Exception {
44
+ robot = new Robot ();
46
45
final bug6647340 test = new bug6647340 ();
47
46
try {
48
- SwingUtilities .invokeAndWait (new Runnable () {
49
- public void run () {
50
- test .setupUI ();
51
- }
52
- });
47
+ SwingUtilities .invokeAndWait (() -> test .setupUI ());
48
+ robot .waitForIdle ();
49
+ robot .delay (1000 );
53
50
test .test ();
54
51
} finally {
55
52
if (test .frame != null ) {
56
- test .frame .dispose ();
53
+ SwingUtilities . invokeAndWait (() -> test .frame .dispose () );
57
54
}
58
55
}
59
56
}
@@ -77,77 +74,69 @@ private void setupUI() {
77
74
}
78
75
79
76
private void test () throws Exception {
80
- sync ();
81
77
test1 ();
82
- sync ();
78
+
79
+ robot .waitForIdle ();
80
+ robot .delay (500 );
83
81
check1 ();
84
- sync ();
82
+ robot .waitForIdle ();
83
+
85
84
test2 ();
86
- sync ();
85
+ robot .waitForIdle ();
86
+ robot .delay (500 );
87
87
check2 ();
88
88
}
89
89
90
90
private void test1 () throws Exception {
91
- SwingUtilities .invokeAndWait (new Runnable () {
92
- public void run () {
93
- setIcon (true );
94
- location = jif .getDesktopIcon ().getLocation ();
95
- Dimension size = frame .getSize ();
96
- frame .setSize (size .width + 100 , size .height + 100 );
97
- }
91
+ SwingUtilities .invokeAndWait (() -> {
92
+ setIcon (true );
93
+ location = jif .getDesktopIcon ().getLocation ();
94
+ Dimension size = frame .getSize ();
95
+ frame .setSize (size .width + 100 , size .height + 100 );
98
96
});
99
97
}
100
98
101
99
private void test2 () throws Exception {
102
- SwingUtilities .invokeAndWait (new Runnable () {
103
- public void run () {
104
- setIcon (false );
105
- }
100
+ SwingUtilities .invokeAndWait (() -> {
101
+ setIcon (false );
106
102
});
107
- sync ();
108
- SwingUtilities . invokeAndWait ( new Runnable () {
109
- public void run () {
110
- Dimension size = frame . getSize ();
111
- frame .setSize ( size . width - 100 , size . height - 100 );
112
- }
103
+ robot . waitForIdle ();
104
+ robot . delay ( 500 );
105
+
106
+ SwingUtilities . invokeAndWait (() -> {
107
+ Dimension size = frame .getSize ( );
108
+ frame . setSize ( size . width - 100 , size . height - 100 );
113
109
});
114
- sync ();
115
- SwingUtilities . invokeAndWait ( new Runnable () {
116
- public void run () {
117
- setIcon ( true );
118
- }
110
+ robot . waitForIdle ();
111
+ robot . delay ( 500 );
112
+
113
+ SwingUtilities . invokeAndWait (() -> {
114
+ setIcon ( true );
119
115
});
120
116
}
121
117
122
- private void check1 () {
123
- if (!jif .getDesktopIcon ().getLocation ().equals (location )) {
118
+ private void check1 () throws Exception {
119
+ SwingUtilities .invokeAndWait (() -> {
120
+ iconloc = jif .getDesktopIcon ().getLocation ();
121
+ });
122
+ if (!iconloc .equals (location )) {
124
123
System .out .println ("First test passed" );
125
124
} else {
126
125
throw new RuntimeException ("Icon isn't shifted with the frame bounds" );
127
126
}
128
127
}
129
128
130
- private void check2 () {
131
- if (jif .getDesktopIcon ().getLocation ().equals (location )) {
129
+ private void check2 () throws Exception {
130
+ SwingUtilities .invokeAndWait (() -> {
131
+ iconloc = jif .getDesktopIcon ().getLocation ();
132
+ });
133
+ if (iconloc .equals (location )) {
132
134
System .out .println ("Second test passed" );
133
135
} else {
134
136
throw new RuntimeException ("Icon isn't located near the frame bottom" );
135
137
}
136
138
}
137
139
138
- private static void sync () {
139
- robot .waitForIdle ();
140
- }
141
- private static ExtendedRobot createRobot () {
142
- try {
143
- ExtendedRobot robot = new ExtendedRobot ();
144
- return robot ;
145
- }catch (Exception ex ) {
146
- ex .printStackTrace ();
147
- throw new Error ("Unexpected Failure" );
148
- }
149
- }
150
-
151
140
private void setIcon (boolean b ) {
152
141
try {
153
142
jif .setIcon (b );
0 commit comments