Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new method areListenersPaused() to interface SelectionModel #324

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/mastodon/adapter/SelectionModelAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,10 @@ public void pauseListeners()
{
selection.pauseListeners();
}

@Override
public boolean areListenersPaused()
{
return selection.areListenersPaused();
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/mastodon/model/DefaultSelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,10 @@ public void pauseListeners()
{
emitEvents = false;
}

@Override
public boolean areListenersPaused()
{
return !emitEvents;
}
}
30 changes: 28 additions & 2 deletions src/main/java/org/mastodon/model/SelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <br>
* 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()}.
* <br>
* Changes the state of {@link #areListenersPaused()} to {@code true}.
* <br>
* 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.
* <br>
* If this {@link SelectionModel} has recorded changes in selection state while the listeners were paused, listeners will be notified of these changes.
* <br>
* Changes the state of {@link #areListenersPaused()} to {@code false}.
*/
void resumeListeners();

public void pauseListeners();
/**
* Checks if the selection listeners are paused.
* <br>
* 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public void pauseListeners()
selection.pauseListeners();
}

@Override
public boolean areListenersPaused()
{
return selection.areListenersPaused();
}

@Override
public boolean isSelected( final BV vertex )
{
Expand Down Expand Up @@ -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 )
Expand Down
Loading