FileDocCategorySizeDatePackage
Autoscroller.javaAPI DocJava SE 6 API4807Tue Jun 10 00:26:34 BST 2008javax.swing

Autoscroller

public class Autoscroller extends Object implements ActionListener
Autoscroller is responsible for generating synthetic mouse dragged events. It is the responsibility of the Component (or its MouseListeners) that receive the events to do the actual scrolling in response to the mouse dragged events.
version
1.17 04/06/06
author
Dave Moore
author
Scott Violet

Fields Summary
private static Autoscroller
sharedInstance
Global Autoscroller.
private static MouseEvent
event
private static Timer
timer
private static JComponent
component
Constructors Summary
Autoscroller()

    
Methods Summary
private boolean_isRunning(javax.swing.JComponent c)
Returns true if autoscrolling is currently running for the specified widget.

        return (c == component && timer != null && timer.isRunning());
    
private void_processMouseDragged(java.awt.event.MouseEvent e)
MouseListener method, invokes start/stop as necessary.

        JComponent component = (JComponent)e.getComponent();
        boolean stop = true;
        if (component.isShowing()) {
            Rectangle visibleRect = component.getVisibleRect();
            stop = visibleRect.contains(e.getX(), e.getY());
        }
        if (stop) {
            _stop(component);
	} else {
            start(component, e);
	}
    
private void_stop(javax.swing.JComponent c)
Stops scrolling for the passed in widget.

        if (component == c) {
            if (timer != null) {
                timer.stop();
            }
            timer = null;
            event = null;
            component = null;
        }
    
public voidactionPerformed(java.awt.event.ActionEvent x)
ActionListener method. Invoked when the Timer fires. This will scroll if necessary.

        JComponent component = Autoscroller.component;

        if (component == null || !component.isShowing() || (event == null)) {
            _stop(component);
            return;
        }
        Point screenLocation = component.getLocationOnScreen();
        MouseEvent e = new MouseEvent(component, event.getID(),
                                      event.getWhen(), event.getModifiers(),
                                      event.getX() - screenLocation.x,
                                      event.getY() - screenLocation.y,
                                      event.getXOnScreen(),
                                      event.getYOnScreen(),
                                      event.getClickCount(),
                                      event.isPopupTrigger(),
                                      MouseEvent.NOBUTTON);
        component.superProcessMouseMotionEvent(e);
    
public static booleanisRunning(javax.swing.JComponent c)
Stops autoscroll events from happening on the specified component.

        return sharedInstance._isRunning(c);
    
public static voidprocessMouseDragged(java.awt.event.MouseEvent e)
Invoked when a mouse dragged event occurs, will start the autoscroller if necessary.

        sharedInstance._processMouseDragged(e);
    
private voidstart(javax.swing.JComponent c, java.awt.event.MouseEvent e)
Starts the timer targeting the passed in component.

        Point screenLocation = c.getLocationOnScreen();

        if (component != c) {
            _stop(component);
        }
        component = c;
        event = new MouseEvent(component, e.getID(), e.getWhen(),
                               e.getModifiers(), e.getX() + screenLocation.x,
                               e.getY() + screenLocation.y,
                               e.getXOnScreen(),
                               e.getYOnScreen(),
                               e.getClickCount(), e.isPopupTrigger(),
                               MouseEvent.NOBUTTON);

        if (timer == null) {
            timer = new Timer(100, this);
        }

        if (!timer.isRunning()) {
            timer.start();
        }
    
public static voidstop(javax.swing.JComponent c)
Stops autoscroll events from happening on the specified component.


    //
    // The public API, all methods are cover methods for an instance method
    //
                  
         
        sharedInstance._stop(c);