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..3ccc37c24 100644 --- a/src/main/java/org/mastodon/model/SelectionModel.java +++ b/src/main/java/org/mastodon/model/SelectionModel.java @@ -163,7 +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(); + + /** + * 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(); - public void pauseListeners(); + /** + * 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(); } 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 )