Animator: added constructor that allows passing a runnable that is invoked at the end of the animation, which allows using lambdas in most cases

This commit is contained in:
Karl Tauber
2020-07-25 10:53:06 +02:00
parent 9f41ec3986
commit 5a9e620c17
3 changed files with 33 additions and 22 deletions

View File

@@ -115,26 +115,20 @@ public class FlatAnimatedLafChange
return;
// create animator
animator = new Animator( duration, new Animator.TimingTarget() {
@Override
public void timingEvent( float fraction ) {
if( fraction < 0.1 || fraction > 0.9 )
return; // ignore initial and last events
animator = new Animator( duration, fraction -> {
if( fraction < 0.1 || fraction > 0.9 )
return; // ignore initial and last events
alpha = 1f - fraction;
alpha = 1f - fraction;
// repaint snapshots
for( Map.Entry<JLayeredPane, JComponent> e : map.entrySet() ) {
if( e.getKey().isShowing() )
e.getValue().repaint();
}
}
@Override
public void end() {
hideSnapshot();
animator = null;
// repaint snapshots
for( Map.Entry<JLayeredPane, JComponent> e : map.entrySet() ) {
if( e.getKey().isShowing() )
e.getValue().repaint();
}
}, () -> {
hideSnapshot();
animator = null;
} );
animator.setResolution( resolution );