./test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.java

Print this page
rev 293 : Ensure that scrolling and text selection is really performed on Gnome
using method SunToolkit.realSync().


 124             //   and this is probably a bug). But, starting with 2nd iteration,
 125             //   all events received will be mouse-dragged events.
 126 
 127             moveMouseBelowTextArea( tremble%2!=0 );
 128             Util.waitForIdle( robot );
 129         }
 130 
 131         robot.mouseRelease( MouseEvent.BUTTON1_MASK );
 132         Util.waitForIdle( robot );
 133     }
 134 
 135     void moveMouseToCenterOfTextArea() {
 136         Dimension d = textArea.getSize();
 137         Point l = textArea.getLocationOnScreen();
 138         robot.mouseMove( (int)(l.x+d.width*.5), (int)(l.y+d.height*.5) );
 139     }
 140 
 141     void moveMouseBelowTextArea( boolean shift ) {
 142         Dimension d = textArea.getSize();
 143         Point l = textArea.getLocationOnScreen();

 144         int y = (int)(l.y+d.height*1.5);
 145         if( shift ) y+=15;
 146         robot.mouseMove( (int)(l.x+d.width*.5), y );










 147     }
 148 
 149     void checkResults() {
 150         //try { Thread.sleep( 30*1000 ); }
 151         //catch( Exception e ) { throw new RuntimeException( e ); }
 152 
 153         final int currentSelectionEnd = textArea.getSelectionEnd();
 154 
 155         System.out.println(
 156             "TEST: Selection range after test is: ( "
 157             + textArea.getSelectionStart() + ", "
 158             + currentSelectionEnd + " )"
 159         );
 160 
 161         boolean resultOk = ( currentSelectionEnd == desiredSelectionEnd );
 162         String desiredSelectionEndString = "" + desiredSelectionEnd;
 163 
 164         // On Windows, last empty line is surprisingly not selected.
 165         // Even if it's a bug, it's not for this test.
 166         // So, we have 2 acceptable results in this case.




 124             //   and this is probably a bug). But, starting with 2nd iteration,
 125             //   all events received will be mouse-dragged events.
 126 
 127             moveMouseBelowTextArea( tremble%2!=0 );
 128             Util.waitForIdle( robot );
 129         }
 130 
 131         robot.mouseRelease( MouseEvent.BUTTON1_MASK );
 132         Util.waitForIdle( robot );
 133     }
 134 
 135     void moveMouseToCenterOfTextArea() {
 136         Dimension d = textArea.getSize();
 137         Point l = textArea.getLocationOnScreen();
 138         robot.mouseMove( (int)(l.x+d.width*.5), (int)(l.y+d.height*.5) );
 139     }
 140 
 141     void moveMouseBelowTextArea( boolean shift ) {
 142         Dimension d = textArea.getSize();
 143         Point l = textArea.getLocationOnScreen();
 144         int x = (int)(l.x+d.width*.5);
 145         int y = (int)(l.y+d.height*1.5);
 146         if( shift ) y+=15;
 147         robot.mouseMove( x, y );
 148         // it is needed to add some small delay on Gnome
 149         waitUntilScrollIsPerformed();
 150     }
 151 
 152     /**
 153       * Force window toolkit to synchronize with the native windowing
 154       * sub-system.
 155       */
 156     void waitUntilScrollIsPerformed() {
 157         ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
 158     }
 159 
 160     void checkResults() {
 161         //try { Thread.sleep( 30*1000 ); }
 162         //catch( Exception e ) { throw new RuntimeException( e ); }
 163 
 164         final int currentSelectionEnd = textArea.getSelectionEnd();
 165 
 166         System.out.println(
 167             "TEST: Selection range after test is: ( "
 168             + textArea.getSelectionStart() + ", "
 169             + currentSelectionEnd + " )"
 170         );
 171 
 172         boolean resultOk = ( currentSelectionEnd == desiredSelectionEnd );
 173         String desiredSelectionEndString = "" + desiredSelectionEnd;
 174 
 175         // On Windows, last empty line is surprisingly not selected.
 176         // Even if it's a bug, it's not for this test.
 177         // So, we have 2 acceptable results in this case.