diff --git a/src/main/java/org/mastodon/views/grapher/display/DataDisplayPanel.java b/src/main/java/org/mastodon/views/grapher/display/DataDisplayPanel.java index b2fee9f7e..607168c52 100644 --- a/src/main/java/org/mastodon/views/grapher/display/DataDisplayPanel.java +++ b/src/main/java/org/mastodon/views/grapher/display/DataDisplayPanel.java @@ -33,6 +33,7 @@ import java.awt.Graphics; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -194,6 +195,8 @@ public class DataDisplayPanel< V extends Vertex< E > & HasTimepoint & HasLabel, private final SelectionModel< DataVertex, DataEdge > selection; + private CountDownLatch latch; + /** * If true the display will be updated live when the window * target of context changes. @@ -363,6 +366,8 @@ public void paint() if ( flags.graphChanged ) { layout.layout(); + if ( latch != null ) + latch.countDown(); layoutMinX = layout.getCurrentLayoutMinX(); layoutMaxX = layout.getCurrentLayoutMaxX(); layoutMinY = layout.getCurrentLayoutMinY(); @@ -947,13 +952,22 @@ void plot( final FeatureGraphConfig gc, final FeatureModel featureModel, final S ylabel += " (" + yunits + ")"; graphOverlay.setYLabel( ylabel ); + latch = new CountDownLatch( 1 ); graphChanged(); Executors.newSingleThreadScheduledExecutor().schedule( () -> { - if ( transform == null ) - transformEventHandler.zoomOutFully(); - else - transformEventHandler.zoomTo( transform.getMinX(), transform.getMaxX(), transform.getMinY(), transform.getMaxY() ); - }, 100, TimeUnit.MILLISECONDS ); + try + { + latch.await(); + if ( transform == null ) + transformEventHandler.zoomOutFully(); + else + transformEventHandler.zoomTo( transform.getMinX(), transform.getMaxX(), transform.getMinY(), transform.getMaxY() ); + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + } + }, 0, TimeUnit.SECONDS ); } private RefSet< DataVertex > fromContext()