From b723c152d3d6adc1b97b078cb9e00a810a39c324 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 12 Sep 2024 15:46:02 +0200 Subject: [PATCH 1/2] 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 --- .../adapter/SelectionModelAdapter.java | 6 ++++++ .../mastodon/model/DefaultSelectionModel.java | 6 ++++++ .../org/mastodon/model/SelectionModel.java | 2 ++ .../branch/BranchGraphSelectionAdapter.java | 18 +++++++++++++++--- 4 files changed, 29 insertions(+), 3 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..5a29bf02a 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,15 @@ public boolean isSelected( final BE edge ) @Override public void setSelected( final BV vertex, final boolean selected ) { - selection.pauseListeners(); - setVertexSelected( vertex, selected ); - selection.resumeListeners(); + boolean areListenersPaused = selection.areListenersPaused(); + if ( areListenersPaused ) + setVertexSelected( vertex, selected ); + else + { + selection.pauseListeners(); + setVertexSelected( vertex, selected ); + selection.resumeListeners(); + } } private boolean setVertexSelected( final BV branchVertex, final boolean selected ) From 6674c87a4635e68956d1b00d3467707fdf05f262 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Tue, 24 Sep 2024 13:59:57 +0200 Subject: [PATCH 2/2] Add javadoc to methods pauseListeners(), resumeListeners() and areListenersPaused() in the interface SelectionModel --- .../org/mastodon/model/SelectionModel.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mastodon/model/SelectionModel.java b/src/main/java/org/mastodon/model/SelectionModel.java index 3783b0e47..3ccc37c24 100644 --- a/src/main/java/org/mastodon/model/SelectionModel.java +++ b/src/main/java/org/mastodon/model/SelectionModel.java @@ -163,9 +163,33 @@ public interface SelectionModel< V extends Vertex< E >, E extends Edge< V > > */ public Listeners< SelectionListener > listeners(); - public void resumeListeners(); + /** + * Pauses the selection listeners. While paused, no listener that are contained in {@link #listeners()} will be notified + * of selection changes. + *
+ * However, this {@link SelectionModel} may record changes in selection state, and listeners may be notified of such a change, when the listeners are resumed with {@link #resumeListeners()}. + *
+ * Changes the state of {@link #areListenersPaused()} to {@code true}. + *
+ * Call {@link #resumeListeners()} to resume the listeners. + */ + void pauseListeners(); - public void pauseListeners(); + /** + * Unpauses the selection listeners. All listeners that are contained in {@link #listeners()} will be notified of selection changes again. + *
+ * If this {@link SelectionModel} has recorded changes in selection state while the listeners were paused, listeners will be notified of these changes. + *
+ * Changes the state of {@link #areListenersPaused()} to {@code false}. + */ + void resumeListeners(); + /** + * Checks if the selection listeners are paused. + *
+ * When paused, no listener that are contained in {@link #listeners()} will be notified of selection changes. + * + * @return {@code true} if the listeners are paused, {@code false} otherwise. + */ boolean areListenersPaused(); }