/** * Cancels automatic block scrolling. * * @param component The scroll bar. * @param button The button that was released. * @param x The x-coordinate of the event in the scroll bar's coordinate space. * @param y The y-coordinate of the event in the scroll bar's coordinate space. */ @Override public boolean mouseUp(Component component, Mouse.Button button, int x, int y) { boolean consumed = super.mouseUp(component, button, x, y); if (button == Mouse.Button.LEFT) { automaticScroller.stop(); } return consumed; }
/** * Initiates automatic block scrolling. This only happens if the handle is visible since whether * the user clicked before or after the handle determines the direction of the scrolling. * * @param component The scroll bar. * @param button The button that was pressed. * @param x The x-coordinate of the event in the scroll bar's coordinate space. * @param y The y-coordinate of the event in the scroll bar's coordinate space. */ @Override public boolean mouseDown(Component component, Mouse.Button button, int x, int y) { boolean consumed = super.mouseDown(component, button, x, y); if (button == Mouse.Button.LEFT && handle.isVisible()) { ScrollBar scrollBar = (ScrollBar) getComponent(); // Begin automatic block scrolling. Calculate the direction of // the scroll by checking to see if the user pressed the mouse // in the area "before" the handle or "after" it. int direction; int realStopValue; if (scrollBar.getOrientation() == Orientation.HORIZONTAL) { direction = x < handle.getX() ? -1 : 1; int pixelStopValue = x - scrollUpButton.getWidth() + 1; if (direction == 1) { // If we're scrolling down, account for the width of the // handle in our pixel stop value so that we stop as soon // as the *bottom* of the handle reaches our click point pixelStopValue -= handle.getWidth(); } realStopValue = (int) (pixelStopValue / getValueScale()); } else { direction = y < handle.getY() ? -1 : 1; int pixelStopValue = y - scrollUpButton.getHeight() + 1; if (direction == 1) { // If we're scrolling down, account for the height of the // handle in our pixel stop value so that we stop as soon // as the *bottom* of the handle reaches our click point pixelStopValue -= handle.getHeight(); } realStopValue = (int) (pixelStopValue / getValueScale()); } // Start the automatic scroller automaticScroller.start(direction, Mouse.ScrollType.BLOCK, realStopValue); consumed = true; } return consumed; }
@Override public void mouseOut(Component component) { super.mouseOut(component); automaticScroller.stop(); }