blob: cd12f60e16e846503721689d6c38b5fb8d941103 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 test
26 @bug 6497109
27 @summary Mouse cursor icons for TextArea should be correct in case of hovering or dragging mouse over different subcomponents.
28 @author Konstantin Voloshin: area=awt.TextArea
29 @run applet/manual=yesno HoveringAndDraggingTest.html
30*/
31
32/**
33 * HoveringAndDraggingTest.java
34 *
35 * summary: Mouse cursor icons for TextArea should be correct in case
36 * of hovering or dragging mouse over different subcomponents.
37 */
38
39import java.awt.Frame;
40import java.awt.Panel;
41import java.awt.GridLayout;
42import java.awt.TextArea;
43import java.awt.Dialog;
44
45public class HoveringAndDraggingTest extends java.applet.Applet {
46 public void start() {
47 String[] instructions = new String[] {
48 "1. Notice components in test window: main-panel, box-for-text,"
49 +" 2 scroll-sliders, and 4 scroll-buttons.",
50 "2. Hover mouse over box-for-text."
51 +" Make sure, that mouse cursor is TextCursor (a.k.a. \"beam\").",
52 "3. Hover mouse over each of components (see item 1), except for box-for-text."
53 +" Make sure, that cursor is DefaultCursor (arrow).",
54 "4. Drag mouse (using any mouse button) from box-for-text to every"
55 +" component in item 1, and also outside application window."
56 +" Make sure, that cursor remains TextCursor while mouse button is pressed.",
57 "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
58 +" _but_ now make sure that cursor is DefaultCursor.",
59 "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
60 };
61 Sysout.createDialogWithInstructions( instructions );
62
63 Panel panel = new Panel();
64 panel.setLayout( new GridLayout(3,3) );
65
66 for( int y=0; y<3; ++y ) {
67 for( int x=0; x<3; ++x ) {
68 if( x==1 && y==1 ) {
69 panel.add( new TextArea( bigString() ) );
70 } else {
71 panel.add( new Panel() );
72 }
73 }
74 }
75
76 Frame frame = new Frame( "TextArea cursor icon test" );
77 frame.setSize( 300, 300 );
78 frame.add( panel );
79 frame.setVisible( true );
80 }
81
82 static String bigString() {
83 String s = "";
84 for( int lines=0; ; ++lines ) {
85 for( int symbols=0; symbols<100; ++symbols ) {
86 s += "0";
87 }
88 if( lines<50 ) {
89 s += "\n";
90 } else {
91 break;
92 }
93 }
94 return s;
95 }
96}
97
98
99/****************************************************
100 Standard Test Machinery
101 DO NOT modify anything below -- it's a standard
102 chunk of code whose purpose is to make user
103 interaction uniform, and thereby make it simpler
104 to read and understand someone else's test.
105 ****************************************************/
106
107/**
108 This is part of the standard test machinery.
109 It creates a dialog (with the instructions), and is the interface
110 for sending text messages to the user.
111 To print the instructions, send an array of strings to Sysout.createDialog
112 WithInstructions method. Put one line of instructions per array entry.
113 To display a message for the tester to see, simply call Sysout.println
114 with the string to be displayed.
115 This mimics System.out.println but works within the test harness as well
116 as standalone.
117 */
118
119class Sysout
120{
121 private static TestDialog dialog;
122
123 public static void createDialogWithInstructions( String[] instructions )
124 {
125 dialog = new TestDialog( new Frame(), "Instructions" );
126 dialog.printInstructions( instructions );
127 dialog.setVisible(true);
128 println( "Any messages for the tester will display here." );
129 }
130
131 public static void createDialog( )
132 {
133 dialog = new TestDialog( new Frame(), "Instructions" );
134 String[] defInstr = { "Instructions will appear here. ", "" } ;
135 dialog.printInstructions( defInstr );
136 dialog.setVisible(true);
137 println( "Any messages for the tester will display here." );
138 }
139
140
141 public static void printInstructions( String[] instructions )
142 {
143 dialog.printInstructions( instructions );
144 }
145
146
147 public static void println( String messageIn )
148 {
149 dialog.displayMessage( messageIn );
150 }
151
152}// Sysout class
153
154/**
155 This is part of the standard test machinery. It provides a place for the
156 test instructions to be displayed, and a place for interactive messages
157 to the user to be displayed.
158 To have the test instructions displayed, see Sysout.
159 To have a message to the user be displayed, see Sysout.
160 Do not call anything in this dialog directly.
161 */
162class TestDialog extends Dialog
163{
164
165 TextArea instructionsText;
166 TextArea messageText;
167 int maxStringLength = 80;
168
169 //DO NOT call this directly, go through Sysout
170 public TestDialog( Frame frame, String name )
171 {
172 super( frame, name );
173 int scrollBoth = TextArea.SCROLLBARS_BOTH;
174 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
175 add( "North", instructionsText );
176
177 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
178 add("Center", messageText);
179
180 pack();
181
182 setVisible(true);
183 }// TestDialog()
184
185 //DO NOT call this directly, go through Sysout
186 public void printInstructions( String[] instructions )
187 {
188 //Clear out any current instructions
189 instructionsText.setText( "" );
190
191 //Go down array of instruction strings
192
193 String printStr, remainingStr;
194 for( int i=0; i < instructions.length; i++ )
195 {
196 //chop up each into pieces maxSringLength long
197 remainingStr = instructions[ i ];
198 while( remainingStr.length() > 0 )
199 {
200 //if longer than max then chop off first max chars to print
201 if( remainingStr.length() >= maxStringLength )
202 {
203 //Try to chop on a word boundary
204 int posOfSpace = remainingStr.
205 lastIndexOf( ' ', maxStringLength - 1 );
206
207 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
208
209 printStr = remainingStr.substring( 0, posOfSpace + 1 );
210 remainingStr = remainingStr.substring( posOfSpace + 1 );
211 }
212 //else just print
213 else
214 {
215 printStr = remainingStr;
216 remainingStr = "";
217 }
218
219 instructionsText.append( printStr + "\n" );
220
221 }// while
222
223 }// for
224
225 }//printInstructions()
226
227 //DO NOT call this directly, go through Sysout
228 public void displayMessage( String messageIn )
229 {
230 messageText.append( messageIn + "\n" );
231 System.out.println(messageIn);
232 }
233
234}// TestDialog class