diff options
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java')
-rw-r--r-- | libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java index 78e5168fc80..400ede03ce9 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -760,10 +760,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, scrollbar.setOpaque(true); scrollbar.setLayout(this); - thumbColor = UIManager.getColor("ScrollBar.thumb"); - thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow"); - thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight"); - thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow"); + configureScrollBarColors(); maximumThumbSize = UIManager.getDimension("ScrollBar.maximumThumbSize"); minimumThumbSize = UIManager.getDimension("ScrollBar.minimumThumbSize"); @@ -1228,8 +1225,36 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void scrollByBlock(int direction) { - scrollbar.setValue(scrollbar.getValue() - + scrollbar.getBlockIncrement(direction)); + scrollByBlock(scrollbar, direction); + } + + /** + * Scrolls the specified <code>scrollBar</code> by one block (according + * to the scrollable protocol) in the specified <code>direction</code>. + * + * This method is here statically to support wheel scrolling from the + * BasicScrollPaneUI without code duplication. + * + * @param scrollBar the scrollbar to scroll + * @param direction the scroll direction + */ + static final void scrollByBlock(JScrollBar scrollBar, int direction) + { + int delta; + if (direction > 0) + delta = scrollBar.getBlockIncrement(direction); + else + delta = - scrollBar.getBlockIncrement(direction); + int oldValue = scrollBar.getValue(); + int newValue = oldValue + delta; + + // Overflow check. + if (delta > 0 && newValue < oldValue) + newValue = scrollBar.getMaximum(); + else if (delta < 0 && newValue > oldValue) + newValue = scrollBar.getMinimum(); + + scrollBar.setValue(newValue); } /** @@ -1239,8 +1264,46 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void scrollByUnit(int direction) { - scrollbar.setValue(scrollbar.getValue() - + scrollbar.getUnitIncrement(direction)); + scrollByUnits(scrollbar, direction, 1); + } + + /** + * Scrolls the specified <code>scrollbac/code> by <code>units</code> units + * in the specified <code>direction</code>. + * + * This method is here statically to support wheel scrolling from the + * BasicScrollPaneUI without code duplication. + * + * @param scrollBar the scrollbar to scroll + * @param direction the direction + * @param units the number of units to scroll + */ + static final void scrollByUnits(JScrollBar scrollBar, int direction, + int units) + { + // Do this inside a loop so that we don't clash with the scrollable + // interface, which can return different units at times. For instance, + // a Scrollable could return a unit of 2 pixels only to adjust the + // visibility of an item. If we would simply multiply this by units, + // then we would only get 6 pixels, which is complete crap. + for (int i = 0; i < units; i++) + { + int delta; + if (direction > 0) + delta = scrollBar.getUnitIncrement(direction); + else + delta = - scrollBar.getUnitIncrement(direction); + int oldValue = scrollBar.getValue(); + int newValue = oldValue + delta; + + // Overflow check. + if (delta > 0 && newValue < oldValue) + newValue = scrollBar.getMaximum(); + else if (delta < 0 && newValue > oldValue) + newValue = scrollBar.getMinimum(); + + scrollBar.setValue(newValue); + } } /** |