< prev index next >

src/java.desktop/share/classes/javax/swing/Autoscroller.java

Print this page




  65      */
  66     public static boolean isRunning(JComponent c) {
  67         return sharedInstance._isRunning(c);
  68     }
  69 
  70     /**
  71      * Invoked when a mouse dragged event occurs, will start the autoscroller
  72      * if necessary.
  73      */
  74     public static void processMouseDragged(MouseEvent e) {
  75         sharedInstance._processMouseDragged(e);
  76     }
  77 
  78 
  79     Autoscroller() {
  80     }
  81 
  82     /**
  83      * Starts the timer targeting the passed in component.
  84      */

  85     private void start(JComponent c, MouseEvent e) {
  86         Point screenLocation = c.getLocationOnScreen();
  87 
  88         if (component != c) {
  89             _stop(component);
  90         }
  91         component = c;
  92         event = new MouseEvent(component, e.getID(), e.getWhen(),
  93                                e.getModifiers(), e.getX() + screenLocation.x,
  94                                e.getY() + screenLocation.y,
  95                                e.getXOnScreen(),
  96                                e.getYOnScreen(),
  97                                e.getClickCount(), e.isPopupTrigger(),
  98                                MouseEvent.NOBUTTON);
  99 
 100         if (timer == null) {
 101             timer = new Timer(100, this);
 102         }
 103 
 104         if (!timer.isRunning()) {


 139         JComponent component = (JComponent)e.getComponent();
 140         boolean stop = true;
 141         if (component.isShowing()) {
 142             Rectangle visibleRect = component.getVisibleRect();
 143             stop = visibleRect.contains(e.getX(), e.getY());
 144         }
 145         if (stop) {
 146             _stop(component);
 147         } else {
 148             start(component, e);
 149         }
 150     }
 151 
 152     //
 153     // ActionListener
 154     //
 155     /**
 156      * ActionListener method. Invoked when the Timer fires. This will scroll
 157      * if necessary.
 158      */

 159     public void actionPerformed(ActionEvent x) {
 160         JComponent component = Autoscroller.component;
 161 
 162         if (component == null || !component.isShowing() || (event == null)) {
 163             _stop(component);
 164             return;
 165         }
 166         Point screenLocation = component.getLocationOnScreen();
 167         MouseEvent e = new MouseEvent(component, event.getID(),
 168                                       event.getWhen(), event.getModifiers(),
 169                                       event.getX() - screenLocation.x,
 170                                       event.getY() - screenLocation.y,
 171                                       event.getXOnScreen(),
 172                                       event.getYOnScreen(),
 173                                       event.getClickCount(),
 174                                       event.isPopupTrigger(),
 175                                       MouseEvent.NOBUTTON);
 176         component.superProcessMouseMotionEvent(e);
 177     }
 178 


  65      */
  66     public static boolean isRunning(JComponent c) {
  67         return sharedInstance._isRunning(c);
  68     }
  69 
  70     /**
  71      * Invoked when a mouse dragged event occurs, will start the autoscroller
  72      * if necessary.
  73      */
  74     public static void processMouseDragged(MouseEvent e) {
  75         sharedInstance._processMouseDragged(e);
  76     }
  77 
  78 
  79     Autoscroller() {
  80     }
  81 
  82     /**
  83      * Starts the timer targeting the passed in component.
  84      */
  85     @SuppressWarnings("deprecation")
  86     private void start(JComponent c, MouseEvent e) {
  87         Point screenLocation = c.getLocationOnScreen();
  88 
  89         if (component != c) {
  90             _stop(component);
  91         }
  92         component = c;
  93         event = new MouseEvent(component, e.getID(), e.getWhen(),
  94                                e.getModifiers(), e.getX() + screenLocation.x,
  95                                e.getY() + screenLocation.y,
  96                                e.getXOnScreen(),
  97                                e.getYOnScreen(),
  98                                e.getClickCount(), e.isPopupTrigger(),
  99                                MouseEvent.NOBUTTON);
 100 
 101         if (timer == null) {
 102             timer = new Timer(100, this);
 103         }
 104 
 105         if (!timer.isRunning()) {


 140         JComponent component = (JComponent)e.getComponent();
 141         boolean stop = true;
 142         if (component.isShowing()) {
 143             Rectangle visibleRect = component.getVisibleRect();
 144             stop = visibleRect.contains(e.getX(), e.getY());
 145         }
 146         if (stop) {
 147             _stop(component);
 148         } else {
 149             start(component, e);
 150         }
 151     }
 152 
 153     //
 154     // ActionListener
 155     //
 156     /**
 157      * ActionListener method. Invoked when the Timer fires. This will scroll
 158      * if necessary.
 159      */
 160     @SuppressWarnings("deprecation")
 161     public void actionPerformed(ActionEvent x) {
 162         JComponent component = Autoscroller.component;
 163 
 164         if (component == null || !component.isShowing() || (event == null)) {
 165             _stop(component);
 166             return;
 167         }
 168         Point screenLocation = component.getLocationOnScreen();
 169         MouseEvent e = new MouseEvent(component, event.getID(),
 170                                       event.getWhen(), event.getModifiers(),
 171                                       event.getX() - screenLocation.x,
 172                                       event.getY() - screenLocation.y,
 173                                       event.getXOnScreen(),
 174                                       event.getYOnScreen(),
 175                                       event.getClickCount(),
 176                                       event.isPopupTrigger(),
 177                                       MouseEvent.NOBUTTON);
 178         component.superProcessMouseMotionEvent(e);
 179     }
 180 
< prev index next >