From ad40064c515aa03abb7513a59c2e0fa66acb7171 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 12 Sep 2024 15:46:02 +0200 Subject: [PATCH] Introduce new method areListenersPaused() to interface SelectionModel * Use areListenersPaused() in BranchGraphSelectionAdapter to find out, if listeners have been paused outside of this method and only in case they are not: pause listeners, select the branch vertex and resume listeners * Without this change a selection of many branch spots at the same time caused that resumeListeners() was called with high frequency resulting in low performance, when selecting many branch spots at the same time --- .../org/mastodon/adapter/SelectionModelAdapter.java | 6 ++++++ .../org/mastodon/model/DefaultSelectionModel.java | 6 ++++++ .../java/org/mastodon/model/SelectionModel.java | 2 ++ .../model/branch/BranchGraphSelectionAdapter.java | 13 +++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mastodon/adapter/SelectionModelAdapter.java b/src/main/java/org/mastodon/adapter/SelectionModelAdapter.java index 75d67df50..c259d3f26 100644 --- a/src/main/java/org/mastodon/adapter/SelectionModelAdapter.java +++ b/src/main/java/org/mastodon/adapter/SelectionModelAdapter.java @@ -162,4 +162,10 @@ public void pauseListeners() { selection.pauseListeners(); } + + @Override + public boolean areListenersPaused() + { + return selection.areListenersPaused(); + } } diff --git a/src/main/java/org/mastodon/model/DefaultSelectionModel.java b/src/main/java/org/mastodon/model/DefaultSelectionModel.java index 08cf2dfe7..7d1a151ae 100644 --- a/src/main/java/org/mastodon/model/DefaultSelectionModel.java +++ b/src/main/java/org/mastodon/model/DefaultSelectionModel.java @@ -389,4 +389,10 @@ public void pauseListeners() { emitEvents = false; } + + @Override + public boolean areListenersPaused() + { + return !emitEvents; + } } diff --git a/src/main/java/org/mastodon/model/SelectionModel.java b/src/main/java/org/mastodon/model/SelectionModel.java index 91a5a50bf..3783b0e47 100644 --- a/src/main/java/org/mastodon/model/SelectionModel.java +++ b/src/main/java/org/mastodon/model/SelectionModel.java @@ -166,4 +166,6 @@ public interface SelectionModel< V extends Vertex< E >, E extends Edge< V > > public void resumeListeners(); public void pauseListeners(); + + boolean areListenersPaused(); } diff --git a/src/main/java/org/mastodon/model/branch/BranchGraphSelectionAdapter.java b/src/main/java/org/mastodon/model/branch/BranchGraphSelectionAdapter.java index 1660aa244..be2d53a85 100644 --- a/src/main/java/org/mastodon/model/branch/BranchGraphSelectionAdapter.java +++ b/src/main/java/org/mastodon/model/branch/BranchGraphSelectionAdapter.java @@ -75,6 +75,12 @@ public void pauseListeners() selection.pauseListeners(); } + @Override + public boolean areListenersPaused() + { + return selection.areListenersPaused(); + } + @Override public boolean isSelected( final BV vertex ) { @@ -123,9 +129,12 @@ public boolean isSelected( final BE edge ) @Override public void setSelected( final BV vertex, final boolean selected ) { - selection.pauseListeners(); + boolean areListenersPaused = selection.areListenersPaused(); + if ( !areListenersPaused ) + selection.pauseListeners(); setVertexSelected( vertex, selected ); - selection.resumeListeners(); + if ( !areListenersPaused ) + selection.resumeListeners(); } private boolean setVertexSelected( final BV branchVertex, final boolean selected )