this( comp, new Insets( AUTOSCROLL_MARGIN, AUTOSCROLL_MARGIN, AUTOSCROLL_MARGIN, AUTOSCROLL_MARGIN ) );
}
public void autoscroll( Point cursorLoc )
{
JViewport viewport = getViewport();
if( viewport == null )
return;
Point viewPos = viewport.getViewPosition();
int viewHeight = viewport.getExtentSize().height;
int viewWidth = viewport.getExtentSize().width;
// resolve scrolling
if( ( cursorLoc.y - viewPos.y ) < insets.top )
{ // scroll up
viewport.setViewPosition( new Point( viewPos.x, Math.max( viewPos.y - scrollUnits.top, 0 ) ) );
}
else if( ( viewPos.y + viewHeight - cursorLoc.y ) < insets.bottom )
{ // scroll down
viewport.setViewPosition( new Point( viewPos.x, Math.min( viewPos.y + scrollUnits.bottom, comp.getHeight()
- viewHeight ) ) );
}
else if( ( cursorLoc.x - viewPos.x ) < insets.left )
{ // scroll left
viewport.setViewPosition( new Point( Math.max( viewPos.x - scrollUnits.left, 0 ), viewPos.y ) );
}
else if( ( viewPos.x + viewWidth - cursorLoc.x ) < insets.right )
{ // scroll right
viewport.setViewPosition( new Point( Math.min( viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth ),
viewPos.y ) );
}
}