diff options
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicScrollBarUI.java | 102 |
2 files changed, 66 insertions, 58 deletions
@@ -1,3 +1,25 @@ +2005-10-27 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicScrollBarUI.java + (PropertyChangeHandler.propertyChange): If orientation property + changes, re-setup the UI. + (TrackListener.mouseReleased): Removed unused code. + (createIncreaseButton): Simply return a new instance without any + hacks. + (createDecreaseButton): Likewise. + (installComponents): Do not create the incrButton and decrButton + here, only install them on the ScrollBar. + (installDefaults): Also initialize the incrButton and decrButton + fields here. + (uninstallComponents): Added some null checks. + (uninstallDefaults): Uninstall border using the LookAndFeel utility + method. Set incrButton and decrButton to null here. + (uninstallListeners): Added null checks. + (uninstallUI): Changed order of method calls. First uninstall + listeners then uninstallDefaults, because uninstallDefaults sets + the incrButton and decrButton fields to null, and uninstallListeners + removes a listener from them. Avoids NPE. + 2005-10-27 David Gilbert <david.gilbert@object-refinery.com> * javax/swing/plaf/metal/MetalBorders.java: API doc updates, diff --git a/javax/swing/plaf/basic/BasicScrollBarUI.java b/javax/swing/plaf/basic/BasicScrollBarUI.java index 31a548cf0..2f5eaf391 100644 --- a/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -154,23 +154,12 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, } else if (e.getPropertyName().equals("orientation")) { - incrButton.removeMouseListener(buttonListener); - decrButton.removeMouseListener(buttonListener); - int orientation = scrollbar.getOrientation(); - switch (orientation) - { - case (JScrollBar.HORIZONTAL): - incrButton = createIncreaseButton(EAST); - decrButton = createDecreaseButton(WEST); - break; - default: - incrButton = createIncreaseButton(SOUTH); - decrButton = createDecreaseButton(NORTH); - break; - } - incrButton.addMouseListener(buttonListener); - decrButton.addMouseListener(buttonListener); - calculatePreferredSize(); + uninstallListeners(); + uninstallComponents(); + uninstallDefaults(); + installDefaults(); + installComponents(); + installListeners(); } else if (e.getPropertyName().equals("enabled")) { @@ -375,17 +364,12 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, scrollTimer.setDelay(300); currentMouseX = e.getX(); currentMouseY = e.getY(); - - int value; - if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL) - value = valueForXPosition(currentMouseX); - else - value = valueForYPosition(currentMouseY); + if (shouldScroll(POSITIVE_SCROLL)) scrollByBlock(POSITIVE_SCROLL); else if (shouldScroll(NEGATIVE_SCROLL)) scrollByBlock(NEGATIVE_SCROLL); - + trackHighlight = NO_HIGHLIGHT; scrollListener.setScrollByBlock(false); scrollbar.setValueIsAdjusting(true); @@ -547,11 +531,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected JButton createIncreaseButton(int orientation) { - if (incrButton == null) - incrButton = new BasicArrowButton(orientation); - else - ((BasicArrowButton) incrButton).setDirection(orientation); - return incrButton; + return new BasicArrowButton(orientation); } /** @@ -564,11 +544,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected JButton createDecreaseButton(int orientation) { - if (decrButton == null) - decrButton = new BasicArrowButton(orientation); - else - ((BasicArrowButton) decrButton).setDirection(orientation); - return decrButton; + return new BasicArrowButton(orientation); } /** @@ -756,6 +732,18 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void installComponents() { + if (incrButton != null) + scrollbar.add(incrButton); + if (decrButton != null) + scrollbar.add(decrButton); + } + + /** + * This method installs the defaults for the scrollbar specified by the + * Basic Look and Feel. + */ + protected void installDefaults() + { int orientation = scrollbar.getOrientation(); switch (orientation) { @@ -768,16 +756,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, decrButton = createDecreaseButton(NORTH); break; } - scrollbar.add(incrButton); - scrollbar.add(decrButton); - } - /** - * This method installs the defaults for the scrollbar specified by the - * Basic Look and Feel. - */ - protected void installDefaults() - { LookAndFeel.installColors(scrollbar, "ScrollBar.background", "ScrollBar.foreground"); LookAndFeel.installBorder(scrollbar, "ScrollBar.border"); @@ -1151,10 +1130,10 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void uninstallComponents() { - scrollbar.remove(incrButton); - scrollbar.remove(decrButton); - incrButton = null; - decrButton = null; + if (incrButton != null) + scrollbar.remove(incrButton); + if (decrButton != null) + scrollbar.remove(decrButton); } /** @@ -1165,7 +1144,9 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, { scrollbar.setForeground(null); scrollbar.setBackground(null); - scrollbar.setBorder(null); + LookAndFeel.uninstallBorder(scrollbar); + incrButton = null; + decrButton = null; } /** @@ -1182,17 +1163,22 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void uninstallListeners() { - scrollTimer.removeActionListener(scrollListener); - - scrollbar.getModel().removeChangeListener(modelListener); - scrollbar.removePropertyChangeListener(propertyChangeListener); + if (scrollTimer != null) + scrollTimer.removeActionListener(scrollListener); - decrButton.removeMouseListener(buttonListener); - incrButton.removeMouseListener(buttonListener); - - scrollbar.removeMouseListener(trackListener); - scrollbar.removeMouseMotionListener(trackListener); + if (scrollbar != null) + { + scrollbar.getModel().removeChangeListener(modelListener); + scrollbar.removePropertyChangeListener(propertyChangeListener); + scrollbar.removeMouseListener(trackListener); + scrollbar.removeMouseMotionListener(trackListener); + } + if (decrButton != null) + decrButton.removeMouseListener(buttonListener); + if (incrButton != null) + incrButton.removeMouseListener(buttonListener); + propertyChangeListener = null; modelListener = null; buttonListener = null; @@ -1209,8 +1195,8 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ public void uninstallUI(JComponent c) { - uninstallDefaults(); uninstallListeners(); + uninstallDefaults(); uninstallComponents(); scrollTimer = null; |