Skip to content

Commit

Permalink
Introduce new method areListenersPaused() to interface SelectionModel
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stefanhahmann committed Sep 12, 2024
1 parent 9caa9c5 commit ad40064
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
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;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/mastodon/model/SelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,6 @@ public interface SelectionModel< V extends Vertex< E >, E extends Edge< V > >
public void resumeListeners();

public void pauseListeners();

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,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 )
Expand Down

0 comments on commit ad40064

Please sign in to comment.