Autoscrollerpublic class Autoscroller extends Object implements ActionListenerAutoscroller 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. |
Fields Summary |
---|
private static Autoscroller | sharedInstanceGlobal 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 void | actionPerformed(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 boolean | isRunning(javax.swing.JComponent c)Stops autoscroll events from happening on the specified component.
return sharedInstance._isRunning(c);
| public static void | processMouseDragged(java.awt.event.MouseEvent e)Invoked when a mouse dragged event occurs, will start the autoscroller
if necessary.
sharedInstance._processMouseDragged(e);
| private void | start(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 void | stop(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);
|
|