Skip to content

Commit 15229fb

Browse files
committed
Fix some menu items being inactive in the BDV views.
The menu builder must be called apparently AFTER the corresponding actions have been installed. Lest these actions are inactive when called from the menu (but this works with a shortcut). This requires some gymnastic, because the coloring requires the menu handles to be built before. So we declare those early in the initialization process. And to keep the future menu order, we build an empty menu but already with all su-bmenus in order. Then at the end of the initialization process we flesh out all the menu items.
1 parent 6a4312f commit 15229fb

1 file changed

Lines changed: 60 additions & 47 deletions

File tree

src/main/java/org/mastodon/mamut/MamutViewBdv.java

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -155,43 +155,38 @@ public MamutViewBdv( final MamutAppModel appModel, final Map< String, Object > g
155155
MastodonFrameViewActions.install( viewActions, this );
156156
BigDataViewerActionsMamut.install( viewActions, bdv );
157157

158-
final ViewMenu menu = new ViewMenu( this );
159-
final ActionMap actionMap = frame.getKeybindings().getConcatenatedActionMap();
160-
158+
159+
/*
160+
* We have to build the coloring menu handles now. But the other actions
161+
* need to be included in the menus later, after they have been
162+
* installed (otherwise they won't be active). To keep the future menu
163+
* order, we build an empty menu but already with all su-bmenus in
164+
* order.
165+
*/
161166
final JMenuHandle menuHandle = new JMenuHandle();
162167
final JMenuHandle tagSetMenuHandle = new JMenuHandle();
163168
final JMenuHandle colorbarMenuHandle = new JMenuHandle();
164-
MainWindow.addMenus( menu, actionMap );
169+
final ViewMenu menu = new ViewMenu( this );
170+
final ActionMap actionMap = frame.getKeybindings().getConcatenatedActionMap();
165171
MamutMenuBuilder.build( menu, actionMap,
166-
fileMenu(
167-
separator(),
168-
item( BigDataViewerActions.LOAD_SETTINGS ),
169-
item( BigDataViewerActions.SAVE_SETTINGS ),
170-
separator(),
171-
item( RecordMovieDialog.RECORD_MOVIE_DIALOG ),
172-
item( RecordMaxProjectionMovieDialog.RECORD_MIP_MOVIE_DIALOG ) ),
172+
fileMenu(),
173173
viewMenu(
174174
colorMenu( menuHandle ),
175-
colorbarMenu( colorbarMenuHandle ),
176-
separator(),
177-
item( MastodonFrameViewActions.TOGGLE_SETTINGS_PANEL ) ),
178-
editMenu(
179-
item( UndoActions.UNDO ),
180-
item( UndoActions.REDO ),
181-
separator(),
182-
item( SelectionActions.DELETE_SELECTION ),
183-
item( SelectionActions.SELECT_WHOLE_TRACK ),
184-
item( SelectionActions.SELECT_TRACK_DOWNWARD ),
185-
item( SelectionActions.SELECT_TRACK_UPWARD ),
186-
separator(),
187-
tagSetMenu( tagSetMenuHandle ) ),
188-
ViewMenuBuilder.menu( "Settings",
189-
item( BigDataViewerActions.BRIGHTNESS_SETTINGS ),
190-
item( BigDataViewerActions.VISIBILITY_AND_GROUPING ) ) );
191-
appModel.getPlugins().addMenus( menu );
175+
colorbarMenu( colorbarMenuHandle ) ),
176+
editMenu(),
177+
ViewMenuBuilder.menu( "Settings" ) );
192178

179+
// The view panel.
193180
viewer = bdv.getViewer();
194181

182+
// we need the coloring now.
183+
final GraphColorGeneratorAdapter< Spot, Link, OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > coloring =
184+
new GraphColorGeneratorAdapter<>( viewGraph.getVertexMap(), viewGraph.getEdgeMap() );
185+
coloringModel = registerColoring( coloring, menuHandle,
186+
() -> viewer.getDisplay().repaint() );
187+
colorBarOverlay = new ColorBarOverlay( coloringModel, () -> viewer.getBackground() );
188+
registerColorbarOverlay( colorBarOverlay, colorbarMenuHandle, () -> viewer.getDisplay().repaint() );
189+
195190
// Restore BDV state.
196191
final Element stateEl = ( Element ) guiState.get( BDV_STATE_KEY );
197192
if ( null != stateEl )
@@ -204,9 +199,6 @@ public MamutViewBdv( final MamutAppModel appModel, final Map< String, Object > g
204199
else
205200
viewer.state().setViewerTransform( tLoaded );
206201

207-
final GraphColorGeneratorAdapter< Spot, Link, OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > coloring =
208-
new GraphColorGeneratorAdapter<>( viewGraph.getVertexMap(), viewGraph.getEdgeMap() );
209-
210202
final OverlayGraphRenderer< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > tracksOverlay = createRenderer(
211203
viewGraph,
212204
highlightModel,
@@ -221,20 +213,6 @@ public MamutViewBdv( final MamutAppModel appModel, final Map< String, Object > g
221213
final Model model = appModel.getModel();
222214
final ModelGraph modelGraph = model.getGraph();
223215

224-
coloringModel = registerColoring( coloring, menuHandle,
225-
() -> viewer.getDisplay().repaint() );
226-
colorBarOverlay = new ColorBarOverlay( coloringModel, () -> viewer.getBackground() );
227-
registerColorbarOverlay( colorBarOverlay, colorbarMenuHandle, () -> viewer.getDisplay().repaint() );
228-
229-
registerTagSetMenu( tagSetMenuHandle,
230-
() -> viewer.getDisplay().repaint() );
231-
232-
// Restore coloring.
233-
restoreColoring( coloringModel, guiState );
234-
235-
// Restore colorbar state.
236-
restoreColorbarState( colorBarOverlay, guiState );
237-
viewer.getDisplay().overlays().add( colorBarOverlay );
238216

239217
highlightModel.listeners().add( () -> viewer.getDisplay().repaint() );
240218
focusModel.listeners().add( () -> viewer.getDisplay().repaint() );
@@ -305,8 +283,43 @@ public MamutViewBdv( final MamutAppModel appModel, final Map< String, Object > g
305283

306284
frame.setVisible( true );
307285

308-
// if ( !bdv.tryLoadSettings( bdvFile ) ) // TODO
309-
// InitializeViewerState.initBrightness( 0.001, 0.999, bdv.getViewer(), bdv.getSetupAssignments() );
286+
MainWindow.addMenus( menu, actionMap );
287+
MamutMenuBuilder.build( menu, actionMap,
288+
fileMenu(
289+
separator(),
290+
item( BigDataViewerActions.LOAD_SETTINGS ),
291+
item( BigDataViewerActions.SAVE_SETTINGS ),
292+
separator(),
293+
item( RecordMovieDialog.RECORD_MOVIE_DIALOG ),
294+
item( RecordMaxProjectionMovieDialog.RECORD_MIP_MOVIE_DIALOG ) ),
295+
viewMenu(
296+
separator(),
297+
item( MastodonFrameViewActions.TOGGLE_SETTINGS_PANEL ) ),
298+
editMenu(
299+
item( UndoActions.UNDO ),
300+
item( UndoActions.REDO ),
301+
separator(),
302+
item( SelectionActions.DELETE_SELECTION ),
303+
item( SelectionActions.SELECT_WHOLE_TRACK ),
304+
item( SelectionActions.SELECT_TRACK_DOWNWARD ),
305+
item( SelectionActions.SELECT_TRACK_UPWARD ),
306+
separator(),
307+
tagSetMenu( tagSetMenuHandle ) ),
308+
ViewMenuBuilder.menu( "Settings",
309+
item( BigDataViewerActions.BRIGHTNESS_SETTINGS ),
310+
item( BigDataViewerActions.VISIBILITY_AND_GROUPING ) ) );
311+
appModel.getPlugins().addMenus( menu );
312+
313+
registerTagSetMenu( tagSetMenuHandle,
314+
() -> viewer.getDisplay().repaint() );
315+
316+
// Restore coloring.
317+
restoreColoring( coloringModel, guiState );
318+
319+
// Restore colorbar state.
320+
restoreColorbarState( colorBarOverlay, guiState );
321+
viewer.getDisplay().overlays().add( colorBarOverlay );
322+
310323
}
311324

312325
protected OverlayGraphRenderer< OverlayVertexWrapper< Spot, Link >, OverlayEdgeWrapper< Spot, Link > > createRenderer(

0 commit comments

Comments
 (0)