Commits

Anonymous committed 4075001

fixes to TestKeyboard for Windows 7 -- force the text to come up
highlighted

  • Participants
  • Parent commits 95ca603

Comments (0)

Files changed (2)

src/test/java/org/sikuli/api/robot/CopySource.java

 import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.border.EmptyBorder;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Simple JFrame so that we have something to copy text from in the test
 	private JTextField textField2;
 	private JLabel lblField_2;
 	private JTextField textField3;
+	private FocusListener focusSelector = new FocusAdapter() {
+		@Override
+		public void focusGained(FocusEvent event) {
+			JTextField target = (JTextField) event.getComponent();
+			target.selectAll();
+			isReady.set(true);
+		}
+	};
+	private final AtomicBoolean isReady = new AtomicBoolean(false);
 
+	public boolean isReady() {
+		return isReady.get();
+	}
+	
 	/**
 	 * Create the frame.
 	 */
 		}
 		{
 			textField1 = new JTextField();
+			textField1.addFocusListener(focusSelector);
 			textField1.setText("hello");
 			contentPane.add(textField1);
 			textField1.setColumns(10);
 		}
 		{
 			textField2 = new JTextField();
+			textField2.addFocusListener(focusSelector);
 			textField2.setText("world");
 			contentPane.add(textField2);
 			textField2.setColumns(10);
 		}
 		{
 			textField3 = new JTextField();
+			textField3.addFocusListener(focusSelector);
 			textField3.setText("test ü");
 			contentPane.add(textField3);
 			textField3.setColumns(10);

src/test/java/org/sikuli/api/robot/TestKeyboard.java

 			public void run() {
 				cs.setVisible(true);
 			}});
-		// Dodgy attempt to make sure that the JFame is completely up before we attempt any test
-		while (!cs.isFocused())
-			Thread.sleep(500);
-		Thread.sleep(500);
+		// make sure that the JFame is completely up before we attempt any test
+		while (!cs.isReady())
+			Thread.sleep(100);
 		kb = new DesktopKeyboard();
 	}