From 5618c0f24f4de02474d22217ee4fe86fec75b196 Mon Sep 17 00:00:00 2001 From: Jean-Yves Tinevez Date: Fri, 18 Oct 2024 13:49:35 +0200 Subject: [PATCH] Properly refresh after updating tags with the edit tag menu. Before this commit, the 'refresh' runnable provided in the registerTagSetMenu() methods was not used. --- .../mastodon/mamut/views/MamutBranchView.java | 4 +++- .../org/mastodon/mamut/views/MamutView.java | 2 +- src/main/java/org/mastodon/ui/TagSetMenu.java | 21 ++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/views/MamutBranchView.java b/src/main/java/org/mastodon/mamut/views/MamutBranchView.java index 918ea9fb8..470edcbb1 100644 --- a/src/main/java/org/mastodon/mamut/views/MamutBranchView.java +++ b/src/main/java/org/mastodon/mamut/views/MamutBranchView.java @@ -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 ) ); } diff --git a/src/main/java/org/mastodon/mamut/views/MamutView.java b/src/main/java/org/mastodon/mamut/views/MamutView.java index 8acd55051..656d7bd1e 100644 --- a/src/main/java/org/mastodon/mamut/views/MamutView.java +++ b/src/main/java/org/mastodon/mamut/views/MamutView.java @@ -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 ) ); } diff --git a/src/main/java/org/mastodon/ui/TagSetMenu.java b/src/main/java/org/mastodon/ui/TagSetMenu.java index 3703d815f..c775549d3 100644 --- a/src/main/java/org/mastodon/ui/TagSetMenu.java +++ b/src/main/java/org/mastodon/ui/TagSetMenu.java @@ -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(); } @@ -91,7 +94,7 @@ 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 ); } @@ -99,7 +102,7 @@ public void rebuild() 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 ); @@ -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; @@ -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 @@ -159,6 +165,7 @@ public void actionPerformed( final ActionEvent evtt ) { lock.readLock().unlock(); } + refresh.run(); undo.setUndoPoint(); } } @@ -178,9 +185,11 @@ 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; @@ -188,6 +197,7 @@ public ClearTagAction( final TagSetModel< V, E > tagSetModel, final TagSet tagSe this.selectionModel = selectionModel; this.lock = lock; this.undo = undo; + this.refresh = refresh; } @Override @@ -205,6 +215,7 @@ public void actionPerformed( final ActionEvent evtt ) { lock.readLock().unlock(); } + refresh.run(); undo.setUndoPoint(); } }