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

A command finder for Mastodon windows. #331

Merged
merged 21 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a13d40
A command finder for a Mastodon window.
tinevez Jun 7, 2024
6de7312
Debug the command finder using TrackScheme as a first target.
tinevez Jun 7, 2024
0390fa6
Commands can be run from the selection, the filter text or with the b…
tinevez Jun 7, 2024
2b3823a
Command finder gives the focus to the filter text and closes with esc…
tinevez Jun 7, 2024
2f15789
CommandFinder: UP and DOWN keys move to the shortcut list.
tinevez Jun 9, 2024
c93c7bc
Tweak command finder.
tinevez Jun 9, 2024
5687709
Add command finder to TrackScheme-Branch and -Hierarchy view.
tinevez Jun 9, 2024
6513cba
Add the command finder to the table, BDV and grapher views.
tinevez Jun 9, 2024
3f9ba87
Builder pattern for the command finder.
tinevez Jun 11, 2024
06a2629
Use the new command finder builder into the main views.
tinevez Jun 11, 2024
bebf281
Command finder: display common command names on the same row.
tinevez Jun 11, 2024
155fc89
Install the command finder, AFTER all other commands.
tinevez Jun 11, 2024
b1d3df9
Command finder: Run when the user double-clicks on a row
tinevez Jun 11, 2024
d3fc63d
Also register the plugins actions in the command finder.
tinevez Jun 11, 2024
a379079
Add the command finder to the main window.
tinevez Jun 11, 2024
f6ee232
Add the name of the parent window in the command finder title.
tinevez Jun 11, 2024
a3b0fa1
Commands are updated in the command finder when they are modified.
tinevez Jun 12, 2024
05f6629
Add the command finder command to the list of commands it knows of.
tinevez Jun 12, 2024
66305e2
Make it possible to register manual description providers in the comm…
tinevez Jun 12, 2024
910b125
Make the getCommandDescriptions method in MaMuT view public.
tinevez Jun 12, 2024
0bb2c2c
Declare the new view commands in the command finder.
tinevez Jun 12, 2024
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
36 changes: 30 additions & 6 deletions src/main/java/org/mastodon/mamut/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.mastodon.app.MastodonIcons;
Expand All @@ -74,8 +75,11 @@
import org.mastodon.mamut.views.table.MamutViewTableFactory;
import org.mastodon.mamut.views.trackscheme.MamutBranchViewTrackSchemeFactory;
import org.mastodon.mamut.views.trackscheme.MamutViewTrackSchemeFactory;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.util.RunnableActionPair;
import org.scijava.ui.behaviour.util.Actions;
import org.scijava.ui.behaviour.util.InputActionBindings;

import bdv.ui.keymap.Keymap;
import net.miginfocom.swing.MigLayout;
Expand All @@ -98,7 +102,8 @@ public MainWindow( final ProjectModel appModel )
setLocationByPlatform( true );
setLocationRelativeTo( null );

// Re-register save actions, this time using this frame as parent component.
// Re-register save actions, this time using this frame as parent
// component.
ProjectActions.installAppActions( appModel.getProjectActions(), appModel, this );

// Views:
Expand All @@ -114,7 +119,7 @@ public MainWindow( final ProjectModel appModel )
prepareButton( tableButton, "table", TABLE_ICON_MEDIUM );
buttonsPanel.add( tableButton, "grow" );

final JButton bdvButton = new JButton( new RunnableActionPair( MamutViewBdvFactory.NEW_BDV_VIEW,
final JButton bdvButton = new JButton( new RunnableActionPair( MamutViewBdvFactory.NEW_BDV_VIEW,
() -> projectActionMap.get( MamutViewBdvFactory.NEW_BDV_VIEW ).actionPerformed( null ),
() -> projectActionMap.get( MamutBranchViewBdvFactory.NEW_BRANCH_BDV_VIEW ).actionPerformed( null ) ) );
prepareButton( bdvButton, "bdv", BDV_ICON_MEDIUM );
Expand All @@ -124,9 +129,9 @@ public MainWindow( final ProjectModel appModel )
prepareButton( selectionTableButton, "selection table", TABLE_ICON_MEDIUM );
buttonsPanel.add( selectionTableButton, "grow" );

final JButton trackschemeButton = new JButton( new RunnableActionPair( MamutViewTrackSchemeFactory.NEW_TRACKSCHEME_VIEW,
() -> projectActionMap.get( MamutViewTrackSchemeFactory.NEW_TRACKSCHEME_VIEW ).actionPerformed( null ),
() -> projectActionMap.get( MamutBranchViewTrackSchemeFactory.NEW_BRANCH_TRACKSCHEME_VIEW ).actionPerformed( null ) ) );
final JButton trackschemeButton = new JButton( new RunnableActionPair( MamutViewTrackSchemeFactory.NEW_TRACKSCHEME_VIEW,
() -> projectActionMap.get( MamutViewTrackSchemeFactory.NEW_TRACKSCHEME_VIEW ).actionPerformed( null ),
() -> projectActionMap.get( MamutBranchViewTrackSchemeFactory.NEW_BRANCH_TRACKSCHEME_VIEW ).actionPerformed( null ) ) );
prepareButton( trackschemeButton, "trackscheme", TRACKSCHEME_ICON_MEDIUM );
buttonsPanel.add( trackschemeButton, "grow, wrap" );

Expand Down Expand Up @@ -210,6 +215,25 @@ public void windowClosing( final WindowEvent e )

// Register to when the project model is closed.
appModel.projectClosedListeners().add( () -> dispose() );

// Command finder.
final InputActionBindings keybindings = new InputActionBindings();
SwingUtilities.replaceUIActionMap( content, keybindings.getConcatenatedActionMap() );
SwingUtilities.replaceUIInputMap( content, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
keybindings.getConcatenatedInputMap() );
final Actions mwActions = new Actions( keymap.getConfig(), KeyConfigContexts.MASTODON );
mwActions.install( keybindings, "main" );
CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.keyConfigContext( KeyConfigContexts.MASTODON )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( this )
.installOn( mwActions );
}

/**
Expand Down Expand Up @@ -330,7 +354,7 @@ public static void addMenus( final ViewMenu menu, final ActionMap actionMap )
// item( ProjectActions.IMPORT_SIMI ),
// item( ProjectActions.IMPORT_MAMUT ),
// item( ProjectActions.EXPORT_MAMUT ),
// separator(),
// separator(),
item( WindowManager.PREFERENCES_DIALOG ),
separator(),
item( WindowManager.OPEN_ONLINE_DOCUMENTATION ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mastodon/mamut/MamutViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public < T extends MamutViewI > MamutViewFactory< T > getFactory( final Class< T
return ( MamutViewFactory< T > ) factories.get( klass );
}

CommandDescriptionProvider getCommandDescriptions()
public CommandDescriptionProvider getCommandDescriptions()
{
return new CommandDescriptionProvider( KeyConfigScopes.MAMUT, KeyConfigContexts.MASTODON )
{
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/mastodon/mamut/views/bdv/MamutViewBdv.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.mastodon.ui.coloring.GraphColorGeneratorAdapter;
import org.mastodon.ui.coloring.HasColorBarOverlay;
import org.mastodon.ui.coloring.HasColoringModel;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.views.bdv.BdvContextProvider;
import org.mastodon.views.bdv.BigDataViewerActionsMamut;
Expand Down Expand Up @@ -278,6 +279,21 @@ public MamutViewBdv( final ProjectModel appModel )
// Notifies context provider that context changes when visibility mode changes.
tracksOverlay.getVisibilities().getVisibilityListeners().add( contextProvider::notifyContextChanged );

// Command finder.
final CommandFinder cf = CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.keyConfigContexts( keyConfigContexts )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.register( viewActions )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( frame )
.installOn( viewActions );
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );

MainWindow.addMenus( menu, actionMap );
appModel.getWindowManager().addWindowMenu( menu, actionMap );
MamutMenuBuilder.build( menu, actionMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mastodon.mamut.views.grapher;

import net.imglib2.loops.LoopBuilder;
import java.util.function.BiConsumer;

import org.apache.commons.lang3.function.TriFunction;
import org.mastodon.app.ui.ViewMenuBuilder;
import org.mastodon.mamut.ProjectModel;
Expand All @@ -14,6 +15,7 @@
import org.mastodon.ui.coloring.GraphColorGeneratorAdapter;
import org.mastodon.ui.coloring.HasColorBarOverlay;
import org.mastodon.ui.coloring.HasColoringModel;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.views.context.ContextChooser;
import org.mastodon.views.context.HasContextChooser;
Expand All @@ -25,7 +27,7 @@
import org.mastodon.views.grapher.display.FeatureGraphConfig;
import org.mastodon.views.grapher.display.FeatureSpecPair;

import java.util.function.BiConsumer;
import net.imglib2.loops.LoopBuilder;

public class MamutViewGrapher extends MamutView< DataGraph< Spot, Link >, DataVertex, DataEdge >
implements HasContextChooser< Spot >, HasColoringModel, HasColorBarOverlay
Expand All @@ -52,17 +54,31 @@ public class MamutViewGrapher extends MamutView< DataGraph< Spot, Link >, DataVe
grapherInitializer.installActions( viewActions, viewBehaviours );
grapherInitializer.addSearchPanel( viewActions );

TriFunction< ViewMenuBuilder.JMenuHandle, GraphColorGeneratorAdapter< Spot, Link, DataVertex, DataEdge >,
final TriFunction< ViewMenuBuilder.JMenuHandle, GraphColorGeneratorAdapter< Spot, Link, DataVertex, DataEdge >,
DataDisplayPanel< Spot, Link >, ColoringModel > colorModelRegistration = ( menuHandle, coloringAdaptor,
panel ) -> registerColoring( coloringAdaptor, menuHandle, panel::entitiesAttributesChanged );
LoopBuilder.TriConsumer< ColorBarOverlay, ViewMenuBuilder.JMenuHandle, DataDisplayPanel< Spot, Link > > colorBarRegistration =
final LoopBuilder.TriConsumer< ColorBarOverlay, ViewMenuBuilder.JMenuHandle, DataDisplayPanel< Spot, Link > > colorBarRegistration =
( overlay, menuHandle, panel ) -> registerColorbarOverlay( overlay, menuHandle, panel::repaint );
BiConsumer< ViewMenuBuilder.JMenuHandle, DataDisplayPanel< Spot, Link > > tagSetMenuRegistration =
final BiConsumer< ViewMenuBuilder.JMenuHandle, DataDisplayPanel< Spot, Link > > tagSetMenuRegistration =
( menuHandle, panel ) -> registerTagSetMenu( menuHandle, panel::entitiesAttributesChanged );

grapherInitializer.addMenusAndRegisterColors( colorModelRegistration, colorBarRegistration, tagSetMenuRegistration,
keyConfigContexts );
grapherInitializer.layout();

final CommandFinder cf = CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.keyConfigContexts( keyConfigContexts )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.register( viewActions )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( frame )
.installOn( viewActions );
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );
}

private static FeatureGraphConfig getFeatureGraphConfig()
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/mastodon/mamut/views/table/MamutViewTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.mastodon.ui.coloring.TagSetGraphColorGenerator;
import org.mastodon.ui.coloring.TrackGraphColorGenerator;
import org.mastodon.ui.coloring.feature.FeatureColorModeManager;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.views.context.ContextChooser;
import org.mastodon.views.context.HasContextChooser;
Expand Down Expand Up @@ -183,6 +184,19 @@ protected MamutViewTable( final ProjectModel projectModel, final boolean selecti
// Table actions.
MastodonFrameViewActions.install( viewActions, this );
TableViewActions.install( viewActions, frame );
final CommandFinder cf = CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.keyConfigContexts( keyConfigContexts )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.register( viewActions )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( frame )
.installOn( viewActions );
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );

// Menus
final ViewMenu menu = new ViewMenu( frame.getJMenuBar(), projectModel.getKeymap(), CONTEXTS );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.mastodon.ui.coloring.GraphColorGeneratorAdapter;
import org.mastodon.ui.coloring.HasColorBarOverlay;
import org.mastodon.ui.coloring.HasColoringModel;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.views.trackscheme.LineageTreeLayout;
import org.mastodon.views.trackscheme.LongEdgesLineageTreeLayout;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected MamutBranchViewTrackScheme(
final TimepointModel timepointModel )
{
super( appModel, trackSchemeGraphFactory.createViewGraph( appModel ),
new String[] { KeyConfigContexts.TRACKSCHEME } );
new String[] { KeyConfigContexts.TRACKSCHEME, KeyConfigContexts.MASTODON } );

// TrackScheme options.
final GraphColorGeneratorAdapter< BranchSpot, BranchLink, TrackSchemeVertex, TrackSchemeEdge > coloringAdapter = new GraphColorGeneratorAdapter<>( viewGraph.getVertexMap(), viewGraph.getEdgeMap() );
Expand Down Expand Up @@ -211,6 +212,21 @@ protected MamutBranchViewTrackScheme(
frame.getTrackschemePanel().graphChanged();
} );

// Command finder.
final CommandFinder cf = CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.keyConfigContexts( keyConfigContexts )
.register( viewActions )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( frame )
.installOn( viewActions );
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );

// Menus.
final ViewMenu menu = new ViewMenu( frame.getJMenuBar(), appModel.getKeymap(), keyConfigContexts );
final ActionMap actionMap = frame.getKeybindings().getConcatenatedActionMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.mastodon.ui.coloring.GraphColorGeneratorAdapter;
import org.mastodon.ui.coloring.HasColorBarOverlay;
import org.mastodon.ui.coloring.HasColoringModel;
import org.mastodon.ui.commandfinder.CommandFinder;
import org.mastodon.ui.keymap.KeyConfigContexts;
import org.mastodon.views.context.ContextChooser;
import org.mastodon.views.context.HasContextChooser;
Expand Down Expand Up @@ -201,6 +202,21 @@ public MamutViewTrackScheme( final ProjectModel appModel )
frame.getTrackschemePanel().getNavigationBehaviours().install( viewBehaviours );
frame.getTrackschemePanel().getTransformEventHandler().install( viewBehaviours );

// Command finder.
final CommandFinder cf = CommandFinder.build()
.context( appModel.getContext() )
.inputTriggerConfig( appModel.getKeymap().getConfig() )
.keyConfigContexts( keyConfigContexts )
.descriptionProvider( appModel.getWindowManager().getViewFactories().getCommandDescriptions() )
.register( viewActions )
.register( appModel.getModelActions() )
.register( appModel.getProjectActions() )
.register( appModel.getPlugins().getPluginActions() )
.modificationListeners( appModel.getKeymap().updateListeners() )
.parent( frame )
.installOn( viewActions );
cf.getDialog().setTitle( cf.getDialog().getTitle() + " - " + frame.getTitle() );

final ViewMenu menu = new ViewMenu( this );
final ActionMap actionMap = frame.getKeybindings().getConcatenatedActionMap();

Expand Down
Loading
Loading