/*
* Get the bounding rectangle of the child viewport, relative to the
* top left corner of the JScrollPane.
*/
Rectangle viewport = _childViewport.getBounds();
//Dimension viewportExtent = _childViewport.getExtentSize();
Point viewPosition = _childViewport.getViewPosition();
Point headerPosition = null;
if (_headerViewport != null)
headerPosition = _headerViewport.getViewPosition();
/*
* If the limit is inside the viewport, the component doesn't need to
* be scrolled. First do the left/right scrolling.
*/
if (limit.x > viewport.getRight()) {
if ((direction == ScrollEvent.LEFT
|| direction == ScrollEvent.UP_LEFT || direction == ScrollEvent.DOWN_LEFT)) {
viewPosition.x -= (limit.x - viewport.getRight());
if (_headerViewport != null)
headerPosition.x -= (limit.x - viewport.getRight());
} else if (direction == ScrollEvent.RIGHT
|| direction == ScrollEvent.UP_RIGHT
|| direction == ScrollEvent.DOWN_RIGHT) {
viewPosition.x += (viewport.getLeft() - limit.x);
if (_headerViewport != null)
headerPosition.x += (viewport.getLeft() - limit.x);
}
} else if (limit.x < viewport.getLeft()) {
if (direction == ScrollEvent.RIGHT
|| direction == ScrollEvent.UP_RIGHT
|| direction == ScrollEvent.DOWN_RIGHT) {
viewPosition.x += (viewport.getLeft() - limit.x);
if (_headerViewport != null)
headerPosition.x += (viewport.getLeft() - limit.x);
} else if (direction == ScrollEvent.LEFT
|| direction == ScrollEvent.UP_LEFT
|| direction == ScrollEvent.DOWN_LEFT) {
viewPosition.x -= (limit.x - viewport.getRight());
if (_headerViewport != null)
headerPosition.x -= (limit.x - viewport.getRight());
}
}
// Now do the up/down scrolling
if (limit.y < viewport.getTop()
&& (direction == ScrollEvent.DOWN
|| direction == ScrollEvent.DOWN_LEFT || direction == ScrollEvent.DOWN_RIGHT)) {
viewPosition.y += (viewport.getTop() - limit.y);
} else if (limit.y > viewport.getBottom()
&& (direction == ScrollEvent.UP
|| direction == ScrollEvent.UP_LEFT || direction == ScrollEvent.UP_RIGHT)) {
viewPosition.y -= (limit.y - viewport.getBottom());
}
_childViewport.setViewPosition(viewPosition);
if (_headerViewport != null)
_headerViewport.setViewPosition(headerPosition);