Skip to content

Commit

Permalink
Properly refresh after updating tags with the edit tag menu.
Browse files Browse the repository at this point in the history
Before this commit, the 'refresh' runnable provided in the
registerTagSetMenu() methods was not used.
  • Loading branch information
tinevez committed Oct 18, 2024
1 parent 6ab6ce4 commit 5618c0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/mastodon/mamut/views/MamutBranchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ protected void registerTagSetMenu(
menuHandle.getMenu(),
model.getTagSetModel(),
appModel.getSelectionModel(),
model.getGraph().getLock(), model );
model.getGraph().getLock(),
model,
refresh );
tagSetModel.listeners().add( tagSetMenu );
onClose( () -> tagSetModel.listeners().remove( tagSetMenu ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mastodon/mamut/views/MamutView.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected void registerTagSetMenu(
final Model model = appModel.getModel();
final TagSetModel< Spot, Link > tagSetModel = model.getTagSetModel();
final TagSetMenu< Spot, Link > tagSetMenu = new TagSetMenu<>( menuHandle.getMenu(), tagSetModel, selectionModel,
model.getGraph().getLock(), model );
model.getGraph().getLock(), model, refresh );
tagSetModel.listeners().add( tagSetMenu );
onClose( () -> tagSetModel.listeners().remove( tagSetMenu ) );
}
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/org/mastodon/ui/TagSetMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ public class TagSetMenu< V extends Vertex< E >, E extends Edge< V > > implements

private final ReentrantReadWriteLock lock;

private final Runnable refresh;

public TagSetMenu( final JMenu menu, final TagSetModel< V, E > tagSetModel,
final SelectionModel< V, E > selectionModel, final ReentrantReadWriteLock lock, final UndoPointMarker undo )
final SelectionModel< V, E > selectionModel, final ReentrantReadWriteLock lock, final UndoPointMarker undo, final Runnable refresh )
{
this.menu = menu;
this.tagSetModel = tagSetModel;
this.selectionModel = selectionModel;
this.lock = lock;
this.undo = undo;
this.refresh = refresh;
rebuild();
}

Expand All @@ -91,15 +94,15 @@ public void rebuild()
for ( final Tag tag : ts.getTags() )
{
final JMenuItem menuItem =
new JMenuItem( new SetTagAction<>( tagSetModel, ts, tag, selectionModel, lock, undo ) );
new JMenuItem( new SetTagAction<>( tagSetModel, ts, tag, selectionModel, lock, undo, refresh ) );
subMenuMnemo.add( menuItem );
tsMenu.add( menuItem );
}

tsMenu.add( new JSeparator() );

final JMenuItem clearTagMenuItem =
new JMenuItem( new ClearTagAction<>( tagSetModel, ts, selectionModel, lock, undo ) );
new JMenuItem( new ClearTagAction<>( tagSetModel, ts, selectionModel, lock, undo, refresh ) );
subMenuMnemo.add( clearTagMenuItem );
tsMenu.add( clearTagMenuItem );
menu.add( tsMenu );
Expand Down Expand Up @@ -131,9 +134,11 @@ private static class SetTagAction< V extends Vertex< E >, E extends Edge< V > >

private final ReentrantReadWriteLock lock;

private final Runnable refresh;

public SetTagAction( final TagSetModel< V, E > tagSetModel, final TagSet tagSet, final Tag tag,
final SelectionModel< V, E > selectionModel, final ReentrantReadWriteLock lock,
final UndoPointMarker undo )
final UndoPointMarker undo, final Runnable refresh )
{
super( tag.label(), new ColorIcon( new Color( tag.color(), true ) ) );
this.tagSetModel = tagSetModel;
Expand All @@ -142,6 +147,7 @@ public SetTagAction( final TagSetModel< V, E > tagSetModel, final TagSet tagSet,
this.selectionModel = selectionModel;
this.lock = lock;
this.undo = undo;
this.refresh = refresh;
}

@Override
Expand All @@ -159,6 +165,7 @@ public void actionPerformed( final ActionEvent evtt )
{
lock.readLock().unlock();
}
refresh.run();
undo.setUndoPoint();
}
}
Expand All @@ -178,16 +185,19 @@ private static class ClearTagAction< V extends Vertex< E >, E extends Edge< V >

private final ReentrantReadWriteLock lock;

private final Runnable refresh;

public ClearTagAction( final TagSetModel< V, E > tagSetModel, final TagSet tagSet,
final SelectionModel< V, E > selectionModel, final ReentrantReadWriteLock lock,
final UndoPointMarker undo )
final UndoPointMarker undo, final Runnable refresh )
{
super( "Clear tags for " + tagSet.getName() );
this.tagSetModel = tagSetModel;
this.tagSet = tagSet;
this.selectionModel = selectionModel;
this.lock = lock;
this.undo = undo;
this.refresh = refresh;
}

@Override
Expand All @@ -205,6 +215,7 @@ public void actionPerformed( final ActionEvent evtt )
{
lock.readLock().unlock();
}
refresh.run();
undo.setUndoPoint();
}
}
Expand Down

0 comments on commit 5618c0f

Please sign in to comment.