Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 623   Methods: 27
NCLOC: 254   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MouseWheelEventData.java 79.2% 84.5% 81.5% 83.1%
coverage coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import junit.extensions.jfcunit.JFCTestCase;
 4   
 
 5   
 import java.awt.AWTEvent;
 6   
 import java.awt.Component;
 7   
 import java.awt.Container;
 8   
 import java.awt.Point;
 9   
 import java.awt.Rectangle;
 10   
 import java.awt.event.MouseEvent;
 11   
 
 12   
 import java.lang.reflect.Method;
 13   
 
 14   
 import javax.swing.JViewport;
 15   
 
 16   
 
 17   
 /**
 18   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 19   
  *
 20   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 21   
  */
 22   
 public class MouseWheelEventData extends MouseEventData {
 23   
     /**
 24   
      * The amount to scroll by default.
 25   
      */
 26   
     public static final int DEFAULT_MOUSE_CLICKS = 0;
 27   
 
 28   
     /**
 29   
      * MouseWheelEvent event id.
 30   
      */
 31   
     private static int s_mouseWheelEvent;
 32   
 
 33   
     /**
 34   
      * Class of the MouseWheelEvent.
 35   
      * Used so that the code is backward compatible.
 36   
      */
 37   
     private static Class s_mweClass;
 38   
 
 39   
     /**
 40   
      * Method for getting the rotation of the mouse from the
 41   
      * event. Used so that the code is backward compatible.
 42   
      */
 43   
     private static Method s_getWheelRotationMethod;
 44   
 
 45   
     /**
 46   
      * Method for getting the scroll amount from the
 47   
      * event. Used so that the code is backward compatible.
 48   
      */
 49   
     private static Method s_getScrollAmountMethod;
 50   
 
 51   
     static {
 52  5
         try {
 53  5
             s_mweClass                   = Class.forName(
 54   
                     "java.awt.event.MouseWheelEvent");
 55  5
             s_mouseWheelEvent            = s_mweClass.getField("MOUSE_WHEEL")
 56   
                                                      .getInt(null);
 57  5
             s_getWheelRotationMethod     = s_mweClass.getMethod(
 58   
                     "getWheelRotation",
 59   
                     new Class[0]);
 60  5
             s_getScrollAmountMethod = s_mweClass.getMethod(
 61   
                     "getScrollAmount",
 62   
                     new Class[0]);
 63   
         } catch (Exception e) {
 64  0
             s_mouseWheelEvent = 0;
 65   
         }
 66   
     }
 67   
 
 68   
     /**
 69   
      * The Component on which to trigger the event.
 70   
      */
 71   
     private Component m_comp;
 72   
 
 73   
     /**
 74   
      * Amount to scroll for each wheel rotation.
 75   
      */
 76   
     private int m_scrollAmount = 0;
 77   
 
 78   
     /**
 79   
      * Number of wheel clicks to rotate.
 80   
      */
 81   
     private int m_wheelRotation = 0;
 82   
 
 83   
     /**
 84   
      * Default Constructor.
 85   
      */
 86  313
     public MouseWheelEventData() {
 87  313
         super();
 88   
     }
 89   
 
 90   
     /**
 91   
      * Constructor.
 92   
      *
 93   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code>
 94   
      *                 has to be invoked.
 95   
      * @param comp     The component on which to trigger the event.
 96   
      */
 97  2
     public MouseWheelEventData(final JFCTestCase testCase,
 98   
                                final Component comp) {
 99  2
         this(testCase, comp, DEFAULT_SCROLL_AMOUNT, DEFAULT_WHEEL_ROTATION);
 100   
     }
 101   
 
 102   
     /**
 103   
      * Constructor.
 104   
      *
 105   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 106   
      * @param comp     The component on which to trigger the event.
 107   
      * @param wheelRotation The amount to rotate the wheel positive
 108   
      * for values towards the user. Negative for away from the user.
 109   
      */
 110  14
     public MouseWheelEventData(final JFCTestCase testCase,
 111   
         final Component comp, final int wheelRotation) {
 112  14
         this(testCase, comp, DEFAULT_SCROLL_AMOUNT, wheelRotation,
 113   
             DEFAULT_MOUSE_CLICKS);
 114   
     }
 115   
 
 116   
     /**
 117   
      * Constructor.
 118   
      *
 119   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 120   
      * @param comp     The component on which to trigger the event.
 121   
      * @param amount   The amount to scroll for each rotation.
 122   
      * @param wheelRotation The amount to rotate the wheel positive
 123   
      * for values towards the user. Negative for away from the user.
 124   
      */
 125  4
     public MouseWheelEventData(final JFCTestCase testCase,
 126   
         final Component comp, final int amount, final int wheelRotation) {
 127  4
         this(testCase, comp, amount, wheelRotation, DEFAULT_MOUSE_CLICKS);
 128   
     }
 129   
 
 130   
     /**
 131   
      * Constructor.
 132   
      *
 133   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code>
 134   
      *                 has to be invoked.
 135   
      * @param comp     The component on which to trigger the event.
 136   
      * @param amount   The amount to scroll for each rotation.
 137   
      * @param wheelRotation The amount to rotate the wheel positive
 138   
      * for values towards the user. Negative for away from the user.
 139   
      * @param numberOfClicks
 140   
      *                 Number of clicks in the MouseEvent (1 for single-click,
 141   
      *                 2 for double clicks)
 142   
      */
 143  20
     public MouseWheelEventData(final JFCTestCase testCase,
 144   
         final Component comp, final int amount, final int wheelRotation,
 145   
         final int numberOfClicks) {
 146  20
         this(testCase, comp, amount, wheelRotation, numberOfClicks,
 147   
             DEFAULT_MOUSE_MODIFIERS);
 148   
     }
 149   
 
 150   
     /**
 151   
      * Constructor.
 152   
      *
 153   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 154   
      *                  has to be invoked.
 155   
      * @param comp      The component on which to trigger the event.
 156   
      * @param amount   The amount to scroll for each rotation.
 157   
      * @param wheelRotation The amount to rotate the wheel positive
 158   
      * for values towards the user. Negative for away from the user.
 159   
      * @param numberOfClicks
 160   
      *                  Number of clicks in the MouseEvent (1 for single-click,
 161   
      *                  2 for double clicks)
 162   
      * @param modifiers The modifier key values that need to be passed onto the
 163   
      *                  event.
 164   
      */
 165  22
     public MouseWheelEventData(final JFCTestCase testCase,
 166   
         final Component comp, final int amount, final int wheelRotation,
 167   
         final int numberOfClicks, final int modifiers) {
 168  22
         this(testCase, comp, amount, wheelRotation, numberOfClicks, modifiers,
 169   
             DEFAULT_ISPOPUPTRIGGER);
 170   
     }
 171   
 
 172   
     /**
 173   
      * Constructor.
 174   
      *
 175   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code>
 176   
      *                 has to be invoked.
 177   
      * @param comp     The component on which to trigger the event.
 178   
      * @param amount   The amount to scroll for each rotation.
 179   
      * @param wheelRotation The amount to rotate the wheel positive
 180   
      * for values towards the user. Negative for away from the user.
 181   
      * @param numberOfClicks
 182   
      *                 Number of clicks in the MouseEvent (1 for single-click,
 183   
      *                 2 for double clicks)
 184   
      * @param isPopupTrigger
 185   
      *                 boolean specifying whether this event will show a popup.
 186   
      */
 187  0
     public MouseWheelEventData(final JFCTestCase testCase,
 188   
         final Component comp, final int amount, final int wheelRotation,
 189   
         final int numberOfClicks, final boolean isPopupTrigger) {
 190  0
         this(testCase, comp, amount, wheelRotation, numberOfClicks,
 191   
             getDefaultModifiers(isPopupTrigger), isPopupTrigger);
 192   
     }
 193   
 
 194   
     /**
 195   
      * Constructor.
 196   
      *
 197   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 198   
      *                  has to be invoked.
 199   
      * @param comp      The component on which to trigger the event.
 200   
      * @param amount   The amount to scroll for each rotation.
 201   
      * @param wheelRotation The amount to rotate the wheel positive
 202   
      * for values towards the user. Negative for away from the user.
 203   
      * @param numberOfClicks
 204   
      *                  Number of clicks in the MouseEvent (1 for single-click,
 205   
      *                  2 for double clicks)
 206   
      * @param sleepTime
 207   
      *                  The wait time in ms between each event.
 208   
      */
 209  0
     public MouseWheelEventData(final JFCTestCase testCase,
 210   
         final Component comp, final int amount, final int wheelRotation,
 211   
         final int numberOfClicks, final long sleepTime) {
 212  0
         this(testCase, comp, amount, wheelRotation, numberOfClicks,
 213   
             DEFAULT_MOUSE_MODIFIERS, DEFAULT_ISPOPUPTRIGGER, sleepTime);
 214   
     }
 215   
 
 216   
     /**
 217   
      * Constructor.
 218   
      *
 219   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 220   
      *                  has to be invoked.
 221   
      * @param comp      The component on which to trigger the event.
 222   
      * @param amount   The amount to scroll for each rotation.
 223   
      * @param wheelRotation The amount to rotate the wheel positive
 224   
      * for values towards the user. Negative for away from the user.
 225   
      * @param numberOfClicks
 226   
      *                  Number of clicks in the MouseEvent (1 for single-click,
 227   
      *                  2 for double clicks)
 228   
      * @param modifiers The modifier key values that need to be passed onto the
 229   
      *                  event.
 230   
      * @param isPopupTrigger
 231   
      *                  boolean specifying whether this event will show a popup.
 232   
      */
 233  24
     public MouseWheelEventData(final JFCTestCase testCase,
 234   
         final Component comp, final int amount, final int wheelRotation,
 235   
         final int numberOfClicks, final int modifiers,
 236   
         final boolean isPopupTrigger) {
 237  24
         this(testCase, comp, amount, wheelRotation, numberOfClicks, modifiers,
 238   
             isPopupTrigger, DEFAULT_SLEEPTIME);
 239   
     }
 240   
 
 241   
     /**
 242   
      * Constructor.
 243   
      *
 244   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 245   
      *                  has to be invoked.
 246   
      * @param comp      The component on which to trigger the event.
 247   
      * @param amount   The amount to scroll for each rotation.
 248   
      * @param wheelRotation The amount to rotate the wheel positive
 249   
      * for values towards the user. Negative for away from the user.
 250   
      * @param numberOfClicks
 251   
      *                  Number of clicks in the MouseEvent (1 for single-click,
 252   
      *                  2 for double clicks)
 253   
      * @param isPopupTrigger
 254   
      *                  boolean specifying whether this event will show a popup.
 255   
      * @param sleepTime
 256   
      *                  The wait time in ms between each event.
 257   
      */
 258  0
     public MouseWheelEventData(final JFCTestCase testCase,
 259   
         final Component comp, final int amount, final int wheelRotation,
 260   
         final int numberOfClicks, final boolean isPopupTrigger,
 261   
         final long sleepTime) {
 262  0
         this(testCase, comp, amount, wheelRotation, numberOfClicks,
 263   
             getDefaultModifiers(isPopupTrigger), isPopupTrigger, sleepTime);
 264   
     }
 265   
 
 266   
     /**
 267   
      * Constructor.
 268   
      *
 269   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 270   
      *                  has to be invoked.
 271   
      * @param comp      The component on which to trigger the event.
 272   
      * @param amount   The amount to scroll for each rotation.
 273   
      * @param wheelRotation The amount to rotate the wheel positive
 274   
      * for values towards the user. Negative for away from the user.
 275   
      * @param numberOfClicks
 276   
      *                   Number of clicks in the MouseEvent (1 for single-click,
 277   
      *                   2 for double clicks)
 278   
      * @param modifiers The modifier key values that need to be passed onto the event.
 279   
      * @param isPopupTrigger
 280   
      *                   boolean specifying whether this event will show a popup.
 281   
      * @param sleepTime
 282   
      *                   The wait time in ms between each event.
 283   
      */
 284  26
     public MouseWheelEventData(final JFCTestCase testCase,
 285   
         final Component comp, final int amount, final int wheelRotation,
 286   
         final int numberOfClicks, final int modifiers,
 287   
         final boolean isPopupTrigger, final long sleepTime) {
 288  26
         this(testCase, comp, amount, wheelRotation, numberOfClicks, modifiers,
 289   
             isPopupTrigger, sleepTime, DEFAULT_POSITION, null);
 290   
     }
 291   
 
 292   
     /**
 293   
      * Constructor.
 294   
      *
 295   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 296   
      * @param comp      The component on which to trigger the event.
 297   
      * @param amount   The amount to scroll for each rotation.
 298   
      * @param wheelRotation The amount to rotate the wheel positive
 299   
      * for values towards the user. Negative for away from the user.
 300   
      * @param numberOfClicks
 301   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 302   
      * @param modifiers The modifier key values that need to be passed onto the event.
 303   
      * @param isPopupTrigger
 304   
      *                   boolean specifying whether this event will show a popup.
 305   
      * @param sleepTime
 306   
      *                   The wait time in ms between each event.
 307   
      * @param position  The relative mouse position within the cell.
 308   
      */
 309  2
     public MouseWheelEventData(final JFCTestCase testCase,
 310   
         final Component comp, final int amount, final int wheelRotation,
 311   
         final int numberOfClicks, final int modifiers,
 312   
         final boolean isPopupTrigger, final long sleepTime, final int position) {
 313  2
         this(testCase, comp, amount, wheelRotation, numberOfClicks, modifiers,
 314   
             isPopupTrigger, sleepTime, position, null);
 315   
     }
 316   
 
 317   
     /**
 318   
      * Constructor.
 319   
      *
 320   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 321   
      * @param comp      The component on which to trigger the event.
 322   
      * @param amount   The amount to scroll for each rotation.
 323   
      * @param wheelRotation The amount to rotate the wheel positive
 324   
      * for values towards the user. Negative for away from the user.
 325   
      * @param numberOfClicks
 326   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 327   
      * @param modifiers The modifier key values that need to be passed onto the event.
 328   
      * @param isPopupTrigger
 329   
      *                   boolean specifying whether this event will show a popup.
 330   
      * @param sleepTime
 331   
      *                   The wait time in ms between each event.
 332   
      * @param referencePoint     The CUSTOM mouse position within the cell.
 333   
      */
 334  2
     public MouseWheelEventData(final JFCTestCase testCase,
 335   
         final Component comp, final int amount, final int wheelRotation,
 336   
         final int numberOfClicks, final int modifiers,
 337   
         final boolean isPopupTrigger, final long sleepTime,
 338   
         final Point referencePoint) {
 339  2
         this(testCase, comp, amount, wheelRotation, numberOfClicks, modifiers,
 340   
             isPopupTrigger, sleepTime, CUSTOM, referencePoint);
 341   
     }
 342   
 
 343   
     /**
 344   
      * Constructor.
 345   
      *
 346   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code>
 347   
      *                  has to be invoked.
 348   
      * @param comp      The component on which to trigger the event.
 349   
      * @param amount    The amount to scroll for each rotation.
 350   
      * @param wheelRotation The amount to rotate the wheel positive
 351   
      * for values towards the user. Negative for away from the user.
 352   
      * @param numberOfClicks
 353   
      *                  Number of clicks in the MouseEvent (1 for single-click,
 354   
      *                  2 for double clicks)
 355   
      * @param modifiers The modifier key values that need to be passed
 356   
      *                  onto the event.
 357   
      * @param isPopupTrigger
 358   
      *                   boolean specifying whether this event will show a popup.
 359   
      * @param sleepTime
 360   
      *                   The wait time in ms between each event.
 361   
      * @param position  The relative mouse position within the cell.
 362   
      * @param referencePoint
 363   
      *                   If position is CUSTOM then the point is a offset from
 364   
      *                   the location of the component. If the position is PERCENT
 365   
      *                   then the location is a percentage offset of the hight and width.
 366   
      *                   Otherwise, the referencePoint is unused.
 367   
      */
 368  49
     public MouseWheelEventData(final JFCTestCase testCase,
 369   
         final Component comp, final int amount, final int wheelRotation,
 370   
         final int numberOfClicks, final int modifiers,
 371   
         final boolean isPopupTrigger, final long sleepTime, final int position,
 372   
         final Point referencePoint) {
 373  49
         setTestCase(testCase);
 374  49
         setSource(comp);
 375  49
         setScrollAmount(amount);
 376  49
         setWheelRotation(wheelRotation);
 377  49
         setNumberOfClicks(numberOfClicks);
 378  49
         setModifiers(modifiers);
 379  49
         setPopupTrigger(isPopupTrigger);
 380  49
         setSleepTime(sleepTime);
 381  49
         setPosition(position);
 382  49
         setReferencePoint(referencePoint);
 383  49
         setValid(true);
 384   
     }
 385   
 
 386   
     /**
 387   
      * Set the attribute value.
 388   
      *
 389   
      * @param comp   The new value of the attribute.
 390   
      */
 391  61
     public final void setSource(final Component comp) {
 392  61
         m_comp = comp;
 393   
     }
 394   
 
 395   
     /**
 396   
      * Get the attribute value.
 397   
      *
 398   
      * @return Component    The value of the attribute.
 399   
      */
 400  723
     public final Component getSource() {
 401  723
         return m_comp;
 402   
     }
 403   
 
 404   
     /**
 405   
      * The component on which the event has to be fired.
 406   
      *
 407   
      * @return The component.
 408   
      */
 409  40
     public Component getComponent() {
 410   
         // by default, the component is the same as the source
 411  40
         return getSource();
 412   
     }
 413   
 
 414   
     /**
 415   
      * Set the scroll amount.
 416   
      *
 417   
      * @param scrollAmount Amount to scroll for each wheel click.
 418   
      */
 419  649
     public final void setScrollAmount(final int scrollAmount) {
 420  649
         this.m_scrollAmount = scrollAmount;
 421   
     }
 422   
 
 423   
     /**
 424   
      * Get the scroll amount.
 425   
      *
 426   
      * @return int scroll amount.
 427   
      */
 428  904
     public final int getScrollAmount() {
 429  904
         return m_scrollAmount;
 430   
     }
 431   
 
 432   
     /**
 433   
      * Set the wheel rotation.
 434   
      *
 435   
      * @param wheelRotation amount to rotate the wheel.
 436   
      */
 437  649
     public final void setWheelRotation(final int wheelRotation) {
 438  649
         this.m_wheelRotation = wheelRotation;
 439   
     }
 440   
 
 441   
     /**
 442   
      * Get the wheel rotation.
 443   
      * @return int number of wheel rotations.
 444   
      */
 445  1214
     public final int getWheelRotation() {
 446  1214
         return m_wheelRotation;
 447   
     }
 448   
 
 449   
     /**
 450   
      * Returns true if the event can be consumed by
 451   
      * this instnace of event data.
 452   
      *
 453   
      * @param ae Event to be consumed.
 454   
      * @return true if the event was consumed.
 455   
      */
 456  902
     public boolean canConsume(final AWTEvent ae) {
 457   
         // Cannot consume if the event ID cannot be accessed
 458   
         // or the event is not a mouse wheel event.
 459  902
         if ((s_mouseWheelEvent == 0) || (ae.getID() != s_mouseWheelEvent)) {
 460  300
             return false;
 461   
         }
 462   
 
 463  602
         if (isValid()) {
 464  590
             int modifiers = ((MouseEvent) ae).getModifiers();
 465   
 
 466  590
             if (ae.getSource() != getSource()) {
 467  0
                 return false;
 468   
             }
 469   
 
 470  590
             if (modifiers != getModifiers()) {
 471  0
                 return false;
 472   
             }
 473   
 
 474  590
             try {
 475  590
                 int wheelRotation = ((Integer) s_getWheelRotationMethod.invoke(
 476   
                         ae,
 477   
                         new Object[0])).intValue();
 478   
 
 479   
                 // Change of direction if result is negative.
 480  590
                 if ((wheelRotation * getWheelRotation()) < 0) {
 481  2
                     return false;
 482   
                 }
 483   
             } catch (Exception e) {
 484  0
                 e.printStackTrace();
 485   
             }
 486   
         }
 487   
 
 488  600
         return true;
 489   
     }
 490   
 
 491   
     /**
 492   
      * Consume the event.
 493   
      *
 494   
      * @param ae AWTEvent to be consumed.
 495   
      * @return boolean true if the event was consumed.
 496   
      */
 497  600
     public boolean consume(final AWTEvent ae) {
 498  600
         MouseEvent me = (MouseEvent) ae;
 499   
 
 500  600
         try {
 501  600
             int amount = ((Integer) s_getScrollAmountMethod.invoke(
 502   
                     ae,
 503   
                     new Object[0])).intValue();
 504  600
             setScrollAmount(amount);
 505   
 
 506  600
             int wheelRotation = ((Integer) s_getWheelRotationMethod.invoke(
 507   
                     ae,
 508   
                     new Object[0])).intValue();
 509  600
             setWheelRotation(wheelRotation + getWheelRotation());
 510   
         } catch (Exception e) {
 511  0
             e.printStackTrace();
 512   
         }
 513   
 
 514   
         // If the event is valid then we do not need to
 515   
         // reprocess the rest of the event.
 516  600
         if (isValid()) {
 517  588
             return true;
 518   
         }
 519   
 
 520  12
         Component source = (Component) me.getSource();
 521  12
         setSource(source);
 522  12
         setModifiers(me.getModifiers());
 523  12
         setNumberOfClicks(me.getClickCount());
 524  12
         setPopupTrigger(me.isPopupTrigger());
 525   
 
 526  12
         Point p = new Point(
 527   
                 me.getX(),
 528   
                 me.getY());
 529  12
         setSleepTime(getDefaultSleepTime());
 530   
 
 531  12
         Point screen = source.getLocationOnScreen();
 532  12
         screen.translate(p.x, p.y);
 533  12
         setLocationOnScreen(screen);
 534   
 
 535  12
         setPosition(CENTER);
 536  12
         setReferencePoint(null);
 537  12
         setValid(true);
 538   
 
 539  12
         return true;
 540   
     }
 541   
 
 542   
     /**
 543   
      * Compare to event data and deterime if they are equal.
 544   
      *
 545   
      * @param o Object to be compared.
 546   
      * @return true if the events are the same.
 547   
      */
 548  12
     public boolean equals(final Object o) {
 549  12
         if (!super.equals(o)) {
 550  9
             return false;
 551   
         }
 552   
 
 553  3
         MouseWheelEventData data = (MouseWheelEventData) o;
 554   
 
 555  3
         return (data.getWheelRotation() == getWheelRotation())
 556   
             && (data.getScrollAmount() == getScrollAmount());
 557   
     }
 558   
 
 559   
     /**
 560   
      * Get the hashCode for this object.
 561   
      * @return int hashCode.
 562   
      */
 563  0
     public int hashCode() {
 564  0
         return super.hashCode();
 565   
     }
 566   
 
 567   
     /**
 568   
      * Prepare the component for firing the mouse event.
 569   
      *
 570   
      * @return boolean true if the component is ready.
 571   
      */
 572  19
     public boolean prepareComponent() {
 573  19
         if (!isValidForProcessing(getSource())) {
 574  1
             return false;
 575   
         }
 576   
 
 577   
         // Locate the ViewPort
 578  18
         Container parent = null;
 579   
 
 580  18
         if (getSource() instanceof Container) {
 581  18
             parent = (Container) getSource();
 582   
         } else {
 583  0
             parent = getSource().getParent();
 584   
         }
 585   
 
 586  18
         while ((parent.getParent() != null) && !(parent instanceof JViewport)) {
 587  12
             parent = parent.getParent();
 588   
         }
 589   
 
 590  18
         if (!(parent instanceof JViewport)) {
 591  0
             return false;
 592   
         }
 593   
 
 594  18
         JFCTestCase testCase = getTestCase();
 595   
 
 596  18
         if (testCase != null) {
 597  18
             testCase.awtSleep(getSleepTime());
 598   
         }
 599   
 
 600  18
         Rectangle bounds   = parent.getBounds();
 601  18
         Point     location = parent.getLocationOnScreen();
 602  18
         bounds.x += location.x;
 603  18
         bounds.y += location.y;
 604  18
         setLocationOnScreen(calculatePoint(bounds));
 605   
 
 606  18
         return true;
 607   
     }
 608   
 
 609   
     /**
 610   
      * Generate a string representation of the event.
 611   
      *
 612   
      * @return String form of the event data.
 613   
      */
 614  0
     public String toString() {
 615  0
         StringBuffer buf = new StringBuffer(1000);
 616  0
         buf.append(super.toString());
 617  0
         buf.append(" amount:" + getScrollAmount());
 618  0
         buf.append(" rotation:" + getWheelRotation());
 619   
 
 620  0
         return buf.toString();
 621   
     }
 622   
 }
 623