From a46bdef0792a17907c9472f7d1d7f5dc8ed63356 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 11 Oct 2020 22:51:33 +0200 Subject: [PATCH] Animator: reuse timer instance (cherry picked from commit 0888fd8fb5d18c36886bf958ac5a5e44bf75618d) --- .../com/formdev/flatlaf/util/Animator.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/Animator.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/Animator.java index abf00b18..66e19040 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/Animator.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/Animator.java @@ -184,14 +184,17 @@ public class Animator timeToStop = false; startTime = System.nanoTime() / 1000000; - timer = new Timer( resolution, e -> { - if( !hasBegun ) { - begin(); - hasBegun = true; - } + if( timer == null ) { + timer = new Timer( resolution, e -> { + if( !hasBegun ) { + begin(); + hasBegun = true; + } - timingEvent( getTimingFraction() ); - } ); + timingEvent( getTimingFraction() ); + } ); + } else + timer.setDelay( resolution ); timer.setInitialDelay( 0 ); timer.start(); } @@ -213,10 +216,8 @@ public class Animator } private void stop( boolean cancel ) { - if( timer != null ) { + if( timer != null ) timer.stop(); - timer = null; - } if( !cancel ) end();