1 /*
2 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
31 * RobotLWTest.java
32 *
33 * summary:
34 */
35
36 import java.applet.Applet;
37 import java.awt.*;
38 import java.awt.event.*;
39 import test.java.awt.regtesthelpers.Util;
40
41 public class RobotLWTest extends Applet
42 {
43 //Declare things used in the test, like buttons and labels here
44
45 public void init()
46 {
47 }//End init()
48
49 public void start ()
50 {
51 //What would normally go into main() will probably go here.
52 //Use System.out.println for diagnostic messages that you want
53 //to read after the test is done.
54 //Use Sysout.println for messages you want the tester to read.
55 Frame frame = new Frame();
56 MyLWContainer c = new MyLWContainer();
57 MyLWComponent b = new MyLWComponent();
58 c.add(b);
59 frame.add(c);
60 frame.setSize(400,400);
61 frame.setVisible(true);
62
63 try {
64 Robot robot = new Robot();
65 robot.setAutoWaitForIdle(true);
66 robot.setAutoDelay(100);
67 robot.waitForIdle();
68
69 Util.waitForIdle(robot);
70
71 Point pt = frame.getLocationOnScreen();
72 Point pt1 = b.getLocationOnScreen();
73
74 //Testing capture with multiple buttons
132 public MouseEvent prev = null;
133
134 MyLWComponent() {
135 setSize(50,30);
136 enableEvents(MouseEvent.MOUSE_EVENT_MASK);
137 }
138
139 public void processMouseEvent(MouseEvent e) {
140 prev = last;
141 last = e;
142 System.out.println(e.toString());
143 super.processMouseEvent(e);
144 }
145
146 public void paint(Graphics g) {
147 Dimension d = getSize();
148 setBackground(isEnabled() ? Color.red : Color.gray);
149 g.clearRect(0, 0, d.width - 1, d.height -1);
150 }
151 }
152
153 /****************************************************
154 Standard Test Machinery
155 DO NOT modify anything below -- it's a standard
156 chunk of code whose purpose is to make user
157 interaction uniform, and thereby make it simpler
158 to read and understand someone else's test.
159 ****************************************************/
160
161 /**
162 This is part of the standard test machinery.
163 It creates a dialog (with the instructions), and is the interface
164 for sending text messages to the user.
165 To print the instructions, send an array of strings to Sysout.createDialog
166 WithInstructions method. Put one line of instructions per array entry.
167 To display a message for the tester to see, simply call Sysout.println
168 with the string to be displayed.
169 This mimics System.out.println but works within the test harness as well
170 as standalone.
171 */
172
173 class Sysout
174 {
175 private static TestDialog dialog;
176
177 public static void createDialogWithInstructions( String[] instructions )
178 {
179 dialog = new TestDialog( new Frame(), "Instructions" );
180 dialog.printInstructions( instructions );
181 dialog.show();
182 println( "Any messages for the tester will display here." );
183 }
184
185 public static void createDialog( )
186 {
187 dialog = new TestDialog( new Frame(), "Instructions" );
188 String[] defInstr = { "Instructions will appear here. ", "" } ;
189 dialog.printInstructions( defInstr );
190 dialog.show();
191 println( "Any messages for the tester will display here." );
192 }
193
194
195 public static void printInstructions( String[] instructions )
196 {
197 dialog.printInstructions( instructions );
198 }
199
200
201 public static void println( String messageIn )
202 {
203 dialog.displayMessage( messageIn );
204 }
205
206 }// Sysout class
207
208 /**
209 This is part of the standard test machinery. It provides a place for the
210 test instructions to be displayed, and a place for interactive messages
211 to the user to be displayed.
212 To have the test instructions displayed, see Sysout.
213 To have a message to the user be displayed, see Sysout.
214 Do not call anything in this dialog directly.
215 */
216 class TestDialog extends Dialog
217 {
218
219 TextArea instructionsText;
220 TextArea messageText;
221 int maxStringLength = 80;
222
223 //DO NOT call this directly, go through Sysout
224 public TestDialog( Frame frame, String name )
225 {
226 super( frame, name );
227 int scrollBoth = TextArea.SCROLLBARS_BOTH;
228 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
229 add( "North", instructionsText );
230
231 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
232 add("South", messageText);
233
234 pack();
235
236 show();
237 }// TestDialog()
238
239 //DO NOT call this directly, go through Sysout
240 public void printInstructions( String[] instructions )
241 {
242 //Clear out any current instructions
243 instructionsText.setText( "" );
244
245 //Go down array of instruction strings
246
247 String printStr, remainingStr;
248 for( int i=0; i < instructions.length; i++ )
249 {
250 //chop up each into pieces maxSringLength long
251 remainingStr = instructions[ i ];
252 while( remainingStr.length() > 0 )
253 {
254 //if longer than max then chop off first max chars to print
255 if( remainingStr.length() >= maxStringLength )
256 {
257 //Try to chop on a word boundary
258 int posOfSpace = remainingStr.
259 lastIndexOf( ' ', maxStringLength - 1 );
260
261 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
262
263 printStr = remainingStr.substring( 0, posOfSpace + 1 );
264 remainingStr = remainingStr.substring( posOfSpace + 1 );
265 }
266 //else just print
267 else
268 {
269 printStr = remainingStr;
270 remainingStr = "";
271 }
272
273 instructionsText.append( printStr + "\n" );
274
275 }// while
276
277 }// for
278
279 }//printInstructions()
280
281 //DO NOT call this directly, go through Sysout
282 public void displayMessage( String messageIn )
283 {
284 messageText.append( messageIn + "\n" );
285 }
286
287 }// TestDialog class
|
1 /*
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
31 * RobotLWTest.java
32 *
33 * summary:
34 */
35
36 import java.applet.Applet;
37 import java.awt.*;
38 import java.awt.event.*;
39 import test.java.awt.regtesthelpers.Util;
40
41 public class RobotLWTest extends Applet
42 {
43 //Declare things used in the test, like buttons and labels here
44
45 public void init()
46 {
47 }//End init()
48
49 public void start ()
50 {
51 Frame frame = new Frame();
52 MyLWContainer c = new MyLWContainer();
53 MyLWComponent b = new MyLWComponent();
54 c.add(b);
55 frame.add(c);
56 frame.setSize(400,400);
57 frame.setVisible(true);
58
59 try {
60 Robot robot = new Robot();
61 robot.setAutoWaitForIdle(true);
62 robot.setAutoDelay(100);
63 robot.waitForIdle();
64
65 Util.waitForIdle(robot);
66
67 Point pt = frame.getLocationOnScreen();
68 Point pt1 = b.getLocationOnScreen();
69
70 //Testing capture with multiple buttons
128 public MouseEvent prev = null;
129
130 MyLWComponent() {
131 setSize(50,30);
132 enableEvents(MouseEvent.MOUSE_EVENT_MASK);
133 }
134
135 public void processMouseEvent(MouseEvent e) {
136 prev = last;
137 last = e;
138 System.out.println(e.toString());
139 super.processMouseEvent(e);
140 }
141
142 public void paint(Graphics g) {
143 Dimension d = getSize();
144 setBackground(isEnabled() ? Color.red : Color.gray);
145 g.clearRect(0, 0, d.width - 1, d.height -1);
146 }
147 }
|