1 /* 2 * Copyright (c) 2011, 2013, 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 */ 23 24 /* 25 @test 26 @summary For each pre-defined Cursor, create a panel and set it's cursor to a predefined curosr 27 @summary com.apple.junit.java.awt.cursor 28 @library ../regtesthelpers 29 @build RobotUtilities 30 @build VisibilityValidator 31 @run main CursorDefaults 32 */ 33 34 import test.java.awt.regtesthelpers.RobotUtilities; 35 import test.java.awt.regtesthelpers.VisibilityValidator; 36 37 import java.awt.Color; 38 import java.awt.Component; 39 import java.awt.Cursor; 40 import java.awt.Frame; 41 import java.awt.GridLayout; 42 import java.awt.Label; 43 import java.awt.Panel; 44 45 public class CursorDefaults { 46 static public final int[] cursors = { 47 java.awt.Cursor.CROSSHAIR_CURSOR, 48 java.awt.Cursor.DEFAULT_CURSOR, 49 java.awt.Cursor.E_RESIZE_CURSOR, 50 java.awt.Cursor.N_RESIZE_CURSOR, 51 java.awt.Cursor.NE_RESIZE_CURSOR, 52 java.awt.Cursor.NW_RESIZE_CURSOR, 53 java.awt.Cursor.S_RESIZE_CURSOR, 54 java.awt.Cursor.SE_RESIZE_CURSOR, 55 java.awt.Cursor.SW_RESIZE_CURSOR, 56 java.awt.Cursor.W_RESIZE_CURSOR, 57 java.awt.Cursor.HAND_CURSOR, 58 java.awt.Cursor.MOVE_CURSOR, 59 java.awt.Cursor.TEXT_CURSOR, 60 java.awt.Cursor.WAIT_CURSOR, 61 }; 62 static public final int cols = 3; 63 static public final int rows = 1 + (cursors.length)/3; 64 static private int cnt = 0; 65 static private Frame testFrame = null; 66 67 public static void main (String[] args) throws RuntimeException { 68 try { 69 setUp(); 70 testCursors(); 71 } 72 catch (Exception e) { 73 if (testFrame != null) { 74 testFrame.dispose(); 75 } 76 77 throw new RuntimeException(e.getMessage()); 78 } 79 } 80 81 public static void setUp() throws Exception { 82 Cursor c; 83 Label l; 84 Panel p; 85 86 // Set up our frame 87 testFrame = new Frame("CursorDefaults"); 88 testFrame.setLayout(new GridLayout(rows,cols)); 89 // 90 for (int i=0; i < cursors.length; i++ ) { 91 c = new Cursor(cursors[i]); 92 l = new Label(c.getName()); 93 p = new Panel(); 94 p.add(l); 95 p.setCursor(c); 96 if (i % 2 == 0) 97 p.setBackground(Color.red); 98 else 99 p.setBackground(Color.blue); 100 testFrame.add(p); 101 } 102 testFrame.pack(); 103 104 } 105 106 // test passes if no exceptions are thrown 107 public static void testCursors() throws Exception { 108 VisibilityValidator.setVisibleAndConfirm(testFrame); 109 110 // Have the Robot move the mouse over each Panel 111 System.out.println("Number of Cursors: " + cursors.length); 112 System.out.println("Number of Components: " + testFrame.getComponentCount()); 113 114 Component c = null; 115 int componentCount = testFrame.getComponentCount(); 116 for (int i=0; i < componentCount; i++ ) { 117 c = testFrame.getComponent(i); 118 RobotUtilities.click(c); 119 RobotUtilities.delay(250); 120 121 } 122 // To do -- add a go away button and have the Robot press it 123 } 124 } 125