ScrollBar: fixed issue with updating thumb location (regressing since commit 2c3ef226692fa39b7e6eca3192d197c0b0753aa1)

This commit is contained in:
Karl Tauber
2020-08-09 00:14:44 +02:00
parent 762fe89867
commit 7a582c2d1f

View File

@@ -474,6 +474,7 @@ public class FlatScrollBarUI
if( animator != null ) if( animator != null )
animator.cancel(); animator.cancel();
if( useValueIsAdjusting )
scrollbar.setValueIsAdjusting( true ); scrollbar.setValueIsAdjusting( true );
// if invoked while animation is running, calculation of new value // if invoked while animation is running, calculation of new value
@@ -485,12 +486,18 @@ public class FlatScrollBarUI
r.run(); r.run();
// do not use animation if started dragging thumb
if( isDragging ) {
inRunAndSetValueAnimated = false;
return;
}
int newValue = scrollbar.getValue(); int newValue = scrollbar.getValue();
if( newValue != oldValue ) { if( newValue != oldValue ) {
scrollbar.setValue( oldValue ); scrollbar.setValue( oldValue );
setValueAnimated( newValue ); setValueAnimated( newValue );
} else } else if( useValueIsAdjusting )
scrollbar.setValueIsAdjusting( false ); scrollbar.setValueIsAdjusting( false );
inRunAndSetValueAnimated = false; inRunAndSetValueAnimated = false;
@@ -500,8 +507,10 @@ public class FlatScrollBarUI
private Animator animator; private Animator animator;
private int targetValue = Integer.MIN_VALUE; private int targetValue = Integer.MIN_VALUE;
private int delta; private int delta;
private boolean useValueIsAdjusting = true;
public void setValueAnimated( int value ) { public void setValueAnimated( int value ) {
if( useValueIsAdjusting )
scrollbar.setValueIsAdjusting( true ); scrollbar.setValueIsAdjusting( true );
// create animator // create animator
@@ -518,12 +527,13 @@ public class FlatScrollBarUI
// re-enable valueIsAdjusting if disabled while animation is running // re-enable valueIsAdjusting if disabled while animation is running
// (e.g. in mouse released listener) // (e.g. in mouse released listener)
if( !scrollbar.getValueIsAdjusting() ) if( useValueIsAdjusting && !scrollbar.getValueIsAdjusting() )
scrollbar.setValueIsAdjusting( true ); scrollbar.setValueIsAdjusting( true );
scrollbar.setValue( targetValue - delta + Math.round( delta * fraction ) ); scrollbar.setValue( targetValue - delta + Math.round( delta * fraction ) );
}, () -> { }, () -> {
targetValue = Integer.MIN_VALUE; targetValue = Integer.MIN_VALUE;
if( useValueIsAdjusting )
scrollbar.setValueIsAdjusting( false ); scrollbar.setValueIsAdjusting( false );
}); });
@@ -564,10 +574,24 @@ public class FlatScrollBarUI
{ {
@Override @Override
public void mousePressed( MouseEvent e ) { public void mousePressed( MouseEvent e ) {
// Do not use valueIsAdjusting here (in runAndSetValueAnimated())
// for smooth scrolling because super.mousePressed() enables this itself
// and super.mouseRelease() disables it later.
// If we would disable valueIsAdjusting here (in runAndSetValueAnimated())
// and move the thumb with the mouse, then the thumb location is not updated
// if later scrolled with a key (e.g. HOME key).
useValueIsAdjusting = false;
runAndSetValueAnimated( () -> { runAndSetValueAnimated( () -> {
super.mousePressed( e ); super.mousePressed( e );
} ); } );
} }
@Override
public void mouseReleased( MouseEvent e ) {
super.mouseReleased( e );
useValueIsAdjusting = true;
}
} }
//---- class FlatScrollListener ------------------------------------------- //---- class FlatScrollListener -------------------------------------------