diff --git a/src/main/java/sc/fiji/labkit/ui/BasicLabelingComponent.java b/src/main/java/sc/fiji/labkit/ui/BasicLabelingComponent.java index 09cf2481..078d51dc 100644 --- a/src/main/java/sc/fiji/labkit/ui/BasicLabelingComponent.java +++ b/src/main/java/sc/fiji/labkit/ui/BasicLabelingComponent.java @@ -29,26 +29,43 @@ package sc.fiji.labkit.ui; +import java.awt.Adjustable; +import java.awt.BorderLayout; +import java.util.Collection; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JSlider; + +import org.scijava.ui.behaviour.util.AbstractNamedAction; +import org.scijava.ui.behaviour.util.Actions; +import org.scijava.ui.behaviour.util.Behaviours; +import org.scijava.ui.behaviour.util.InputActionBindings; +import org.scijava.ui.behaviour.util.TriggerBehaviourBindings; + +import bdv.ui.keymap.Keymap; +import bdv.ui.keymap.KeymapManager; import bdv.ui.splitpanel.SplitPanel; import bdv.util.BdvHandle; import bdv.util.BdvHandlePanel; import bdv.util.BdvOptions; import bdv.util.BdvStackSource; import bdv.viewer.DisplayMode; +import bdv.viewer.NavigationActions; +import bdv.viewer.ViewerPanel; +import net.miginfocom.swing.MigLayout; import sc.fiji.labkit.ui.bdv.BdvAutoContrast; import sc.fiji.labkit.ui.bdv.BdvLayer; import sc.fiji.labkit.ui.bdv.BdvLayerLink; -import sc.fiji.labkit.ui.brush.*; +import sc.fiji.labkit.ui.brush.ChangeLabel; +import sc.fiji.labkit.ui.brush.FloodFillController; +import sc.fiji.labkit.ui.brush.LabelBrushController; +import sc.fiji.labkit.ui.brush.PlanarModeController; +import sc.fiji.labkit.ui.brush.SelectLabelController; import sc.fiji.labkit.ui.labeling.LabelsLayer; import sc.fiji.labkit.ui.models.Holder; import sc.fiji.labkit.ui.models.ImageLabelingModel; import sc.fiji.labkit.ui.panel.LabelToolsPanel; -import net.miginfocom.swing.MigLayout; -import org.scijava.ui.behaviour.util.AbstractNamedAction; - -import javax.swing.*; -import java.awt.*; -import java.util.Collection; /** * A swing UI component that shows a Big Data Viewer panel and a tool bar for @@ -68,11 +85,19 @@ public class BasicLabelingComponent extends JPanel implements AutoCloseable { private JSlider zSlider; + private KeymapManager keymapManager; + public BasicLabelingComponent(final JFrame dialogBoxOwner, final ImageLabelingModel model) { + this(dialogBoxOwner, model, null); + } + + public BasicLabelingComponent(final JFrame dialogBoxOwner, final ImageLabelingModel model, + KeymapManager keymapManager) { this.model = model; this.dialogBoxOwner = dialogBoxOwner; + this.keymapManager = keymapManager; initBdv(model.spatialDimensions().numDimensions() < 3); actionsAndBehaviours = new ActionsAndBehaviours(bdvHandle); @@ -85,8 +110,33 @@ public BasicLabelingComponent(final JFrame dialogBoxOwner, private void initBdv(boolean is2D) { final BdvOptions options = BdvOptions.options(); if (is2D) options.is2D(); + if (keymapManager != null) options.keymapManager(keymapManager); + bdvHandle = new BdvHandlePanel(dialogBoxOwner, options); bdvHandle.getViewerPanel().setDisplayMode(DisplayMode.FUSED); + + if (keymapManager != null) { + ViewerPanel viewer = bdvHandle.getViewerPanel(); + + InputActionBindings keybindings = bdvHandle.getKeybindings(); + TriggerBehaviourBindings triggerbindings = bdvHandle.getTriggerbindings(); + + Keymap keymap = keymapManager.getForwardSelectedKeymap(); + + final Actions actions = new Actions(keymap.getConfig(), "bdv"); + actions.install(keybindings, "view"); + + Behaviours behaviours = new Behaviours(keymap.getConfig(), "bdv"); + behaviours.install(triggerbindings, "view"); + + viewer.getTransformEventHandler().install(behaviours); + NavigationActions.install(actions, viewer, is2D); + + keymap.updateListeners().add(() -> { + actions.updateKeyConfig(keymap.getConfig()); + behaviours.updateKeyConfig(keymap.getConfig()); + }); + } } private void initPanel() { @@ -115,6 +165,7 @@ public Holder> addBdvLayer(BdvLayer layer) { } private JPanel initToolsPanel() { + final PlanarModeController planarModeController = new PlanarModeController( bdvHandle, model, zSlider); final LabelBrushController brushController = new LabelBrushController( @@ -123,9 +174,31 @@ private JPanel initToolsPanel() { bdvHandle, model, actionsAndBehaviours); final SelectLabelController selectLabelController = new SelectLabelController(bdvHandle, model, actionsAndBehaviours); - final JPanel toolsPanel = new LabelToolsPanel(brushController, + final LabelToolsPanel toolsPanel = new LabelToolsPanel(brushController, floodFillController, selectLabelController, planarModeController); - actionsAndBehaviours.addAction(new ChangeLabel(model)); + ChangeLabel changeLabel = new ChangeLabel(model); + actionsAndBehaviours.addAction(changeLabel); + + if (keymapManager != null) { + InputActionBindings keybindings = bdvHandle.getKeybindings(); + TriggerBehaviourBindings triggerbindings = bdvHandle.getTriggerbindings(); + + Keymap keymap = keymapManager.getForwardSelectedKeymap(); + + final Actions actions = new Actions(keymap.getConfig(), "labkit"); + actions.install(keybindings, "annotating"); + + Behaviours behaviours = new Behaviours(keymap.getConfig(), "labkit"); + behaviours.install(triggerbindings, "annotating"); + + keymap.updateListeners().add(() -> { + actions.updateKeyConfig(keymap.getConfig()); + behaviours.updateKeyConfig(keymap.getConfig()); + }); + + toolsPanel.install(actions); + changeLabel.install(actions); + } return toolsPanel; } diff --git a/src/main/java/sc/fiji/labkit/ui/LabKitKeymapManager.java b/src/main/java/sc/fiji/labkit/ui/LabKitKeymapManager.java new file mode 100644 index 00000000..0a4bbb59 --- /dev/null +++ b/src/main/java/sc/fiji/labkit/ui/LabKitKeymapManager.java @@ -0,0 +1,42 @@ +package sc.fiji.labkit.ui; + +import org.scijava.Context; +import org.scijava.plugin.PluginService; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider.Scope; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionsBuilder; + +import bdv.KeyConfigScopes; +import bdv.ui.keymap.KeymapManager; + +public class LabKitKeymapManager extends KeymapManager +{ + + private static final String LABKIT_KEYMAP_DIR = System.getProperty( "user.home" ) + "/.labkit/keymaps"; + + /** The key-config scope for LabKit actions. */ + public static final Scope LABKIT_SCOPE = new Scope( "sc.fiji.labkit" ); + + /** The key-config context for LabKit actions. */ + public static final String LABKIT_CONTEXT = "labkit"; + + public LabKitKeymapManager() + { + super( LABKIT_KEYMAP_DIR ); + } + + /** + * Discover all {@code CommandDescriptionProvider}s with the LabKit scope. + */ + @Override + public synchronized void discoverCommandDescriptions() + { + final CommandDescriptionsBuilder builder = new CommandDescriptionsBuilder(); + try (final Context context = new Context( PluginService.class )) + { + context.inject( builder ); + builder.discoverProviders(LABKIT_SCOPE, KeyConfigScopes.BIGDATAVIEWER); + context.dispose(); + setCommandDescriptions( builder.build() ); + } + } +} diff --git a/src/main/java/sc/fiji/labkit/ui/SegmentationComponent.java b/src/main/java/sc/fiji/labkit/ui/SegmentationComponent.java index ec633edd..b797825a 100644 --- a/src/main/java/sc/fiji/labkit/ui/SegmentationComponent.java +++ b/src/main/java/sc/fiji/labkit/ui/SegmentationComponent.java @@ -6,13 +6,13 @@ * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -29,7 +29,40 @@ package sc.fiji.labkit.ui; -import sc.fiji.labkit.ui.actions.*; +import java.awt.BorderLayout; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.SwingUtilities; + +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.Actions; +import org.scijava.ui.behaviour.util.InputActionBindings; + +import bdv.ui.keymap.Keymap; +import bdv.ui.keymap.Keymap.UpdateListener; +import bdv.ui.keymap.KeymapManager; +import net.miginfocom.swing.MigLayout; +import sc.fiji.labkit.ui.actions.AddLabelingIoAction; +import sc.fiji.labkit.ui.actions.BatchSegmentAction; +import sc.fiji.labkit.ui.actions.BitmapImportExportAction; +import sc.fiji.labkit.ui.actions.ClassifierIoAction; +import sc.fiji.labkit.ui.actions.ClassifierSettingsAction; +import sc.fiji.labkit.ui.actions.ExampleAction; +import sc.fiji.labkit.ui.actions.LabelEditAction; +import sc.fiji.labkit.ui.actions.LabelingIoAction; +import sc.fiji.labkit.ui.actions.ResetViewAction; +import sc.fiji.labkit.ui.actions.SegmentationAsLabelAction; +import sc.fiji.labkit.ui.actions.SegmentationExportAction; +import sc.fiji.labkit.ui.actions.ShowHelpAction; +import sc.fiji.labkit.ui.actions.ShowPreferencesDialogAction; import sc.fiji.labkit.ui.menu.MenuKey; import sc.fiji.labkit.ui.models.ColoredLabelsModel; import sc.fiji.labkit.ui.models.Holder; @@ -42,10 +75,6 @@ import sc.fiji.labkit.ui.plugin.MeasureConnectedComponents; import sc.fiji.labkit.ui.segmentation.PredictionLayer; import sc.fiji.labkit.ui.segmentation.TrainClassifier; -import net.miginfocom.swing.MigLayout; - -import javax.swing.*; -import java.awt.*; /** * {@link SegmentationComponent} is the central Labkit UI component. Provides UI @@ -67,16 +96,38 @@ public class SegmentationComponent extends JPanel implements AutoCloseable { private final SegmentationModel segmentationModel; + private final KeymapManager keymapManager; + + private final Actions actions; + + private final InputActionBindings keybindings; + + private final JFrame dialogBoxOwner; + + public SegmentationComponent(JFrame dialogBoxOwner, SegmentationModel segmentationModel, boolean unmodifiableLabels) { + this.dialogBoxOwner = dialogBoxOwner; this.extensible = new DefaultExtensible(segmentationModel.context(), dialogBoxOwner); this.unmodifiableLabels = unmodifiableLabels; this.segmentationModel = segmentationModel; + + keybindings = new InputActionBindings(); + SwingUtilities.replaceUIActionMap( this, keybindings.getConcatenatedActionMap() ); + SwingUtilities.replaceUIInputMap( this, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, keybindings.getConcatenatedInputMap() ); + keymapManager = new LabKitKeymapManager(); + final Keymap keymap = keymapManager.getForwardSelectedKeymap(); + actions = new Actions( keymap.getConfig(), new String[] { LabKitKeymapManager.LABKIT_CONTEXT } ); + actions.install( keybindings, "labkit" ); + final UpdateListener updateListener = () -> actions.updateKeyConfig( keymap.getConfig() ); + keymap.updateListeners().add( updateListener ); + ImageLabelingModel imageLabelingModel = segmentationModel.imageLabelingModel(); - labelingComponent = new BasicLabelingComponent(dialogBoxOwner, imageLabelingModel); + labelingComponent = new BasicLabelingComponent(dialogBoxOwner, imageLabelingModel, keymapManager); labelingComponent.addBdvLayer(PredictionLayer.createPredictionLayer(segmentationModel)); + initActions(); setLayout(new BorderLayout()); add(initGui()); @@ -93,14 +144,17 @@ private void initActions() { new LabelingIoAction(extensible, labelingModel); new AddLabelingIoAction(extensible, labelingModel.labeling()); new SegmentationExportAction(extensible, labelingModel); - new ResetViewAction(extensible, labelingModel); + new ResetViewAction(actions, extensible, labelingModel); new BatchSegmentAction(extensible, selectedSegmenter); new SegmentationAsLabelAction(extensible, segmentationModel); new BitmapImportExportAction(extensible, labelingModel); - new LabelEditAction(extensible, unmodifiableLabels, new ColoredLabelsModel( + new LabelEditAction(actions, extensible, unmodifiableLabels, new ColoredLabelsModel( labelingModel)); MeasureConnectedComponents.addAction(extensible, labelingModel); new ShowHelpAction(extensible); + ShowPreferencesDialogAction.install(actions, extensible, keymapManager, dialogBoxOwner); + ExampleAction.install(actions); + actions.runnableAction(() -> labelingComponent.autoContrast(), AUTO_CONTRAST_ACTION, AUTO_CONTRAST_KEYS); labelingComponent.addShortcuts(extensible.getShortCuts()); } @@ -152,4 +206,20 @@ public JMenuBar getMenuBar() { public void autoContrast() { labelingComponent.autoContrast(); } + + private static final String AUTO_CONTRAST_ACTION = "auto contrast"; + private static final String[] AUTO_CONTRAST_KEYS = new String[] { "not mapped" }; + private static final String AUTO_CONTRAST_DESCRIPTION = "Perform auto-contrast on the current image."; + + @Plugin(type = CommandDescriptionProvider.class) + public static class Descriptions extends CommandDescriptionProvider { + public Descriptions() { + super(LabKitKeymapManager.LABKIT_SCOPE, LabKitKeymapManager.LABKIT_CONTEXT); + } + + @Override + public void getCommandDescriptions(final CommandDescriptions descriptions) { + descriptions.add(AUTO_CONTRAST_ACTION, AUTO_CONTRAST_KEYS, AUTO_CONTRAST_DESCRIPTION); + } + } } diff --git a/src/main/java/sc/fiji/labkit/ui/actions/ExampleAction.java b/src/main/java/sc/fiji/labkit/ui/actions/ExampleAction.java new file mode 100644 index 00000000..314537ed --- /dev/null +++ b/src/main/java/sc/fiji/labkit/ui/actions/ExampleAction.java @@ -0,0 +1,47 @@ +package sc.fiji.labkit.ui.actions; + +import java.awt.event.ActionEvent; + +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.AbstractNamedAction; +import org.scijava.ui.behaviour.util.Actions; + +import sc.fiji.labkit.ui.LabKitKeymapManager; + +public class ExampleAction extends AbstractNamedAction { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "example action"; + + public static final String[] ACTION_DEFAULT_KEYS = new String[] { "A" }; + + public static final String ACTION_DESCRIPTION = "Print a useless message."; + + public static void install(Actions actions) { + actions.namedAction(new ExampleAction(), ACTION_DEFAULT_KEYS); + } + + public ExampleAction() { + super(ACTION_NAME); + } + + @Override + public void actionPerformed(final ActionEvent e) { + System.out.println("TROLOLO"); // DEBUG + } + + @Plugin(type = CommandDescriptionProvider.class) + public static class Descriptions extends CommandDescriptionProvider { + public Descriptions() { + super(LabKitKeymapManager.LABKIT_SCOPE, LabKitKeymapManager.LABKIT_CONTEXT); + } + + @Override + public void getCommandDescriptions(final CommandDescriptions descriptions) { + descriptions.add(ACTION_NAME, ACTION_DEFAULT_KEYS, ACTION_DESCRIPTION); + } + } +} diff --git a/src/main/java/sc/fiji/labkit/ui/actions/LabelEditAction.java b/src/main/java/sc/fiji/labkit/ui/actions/LabelEditAction.java index 27e3d73f..f5c2b125 100644 --- a/src/main/java/sc/fiji/labkit/ui/actions/LabelEditAction.java +++ b/src/main/java/sc/fiji/labkit/ui/actions/LabelEditAction.java @@ -29,23 +29,34 @@ package sc.fiji.labkit.ui.actions; +import javax.swing.JOptionPane; + +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.Actions; + import sc.fiji.labkit.ui.Extensible; +import sc.fiji.labkit.ui.LabKitKeymapManager; import sc.fiji.labkit.ui.labeling.Label; import sc.fiji.labkit.ui.models.ColoredLabelsModel; -import javax.swing.*; - /** * Implements menu items for renaming and removing individual labels. Also * allows to change the order of the labels. */ public class LabelEditAction { + private final Extensible extensible; private final ColoredLabelsModel model; - public LabelEditAction(Extensible extensible, boolean fixedLabels, + public LabelEditAction(Extensible extensible, boolean fixedLabels, ColoredLabelsModel model) { + this(null, extensible, fixedLabels, model); + } + + public LabelEditAction(Actions actions, Extensible extensible, boolean fixedLabels, ColoredLabelsModel model) { this.extensible = extensible; @@ -60,6 +71,23 @@ public LabelEditAction(Extensible extensible, boolean fixedLabels, null, null); if (!fixedLabels) extensible.addMenuItem(Label.LABEL_MENU, "Remove", 201, model::removeLabel, null, null); + + // Actions. + if (actions != null) { + if (!fixedLabels) { + actions.runnableAction(() -> renameLabel(model.selected().get()), RENAME_LABEL_ACTION, + RENAME_LABEL_KEYS); + actions.runnableAction(() -> model.moveLabel(model.selected().get(), -1), MOVE_LABEL_UP_ACTION, + MOVE_LABEL_UP_KEYS); + actions.runnableAction(() -> model.moveLabel(model.selected().get(), 1), MOVE_LABEL_DOWN_ACTION, + MOVE_LABEL_DOWN_KEYS); + actions.runnableAction(() -> model.removeLabel(model.selected().get()), REMOVE_LABEL_ACTION, + REMOVE_LABEL_KEYS); + } + actions.runnableAction(() -> model.clearLabel(model.selected().get()), CLEAR_LABEL_ACTION, + CLEAR_LABEL_KEYS); + } + } private void renameLabel(Label label) { @@ -69,4 +97,42 @@ private void renameLabel(Label label) { if (newName == null) return; model.renameLabel(label, newName); } + + @Plugin(type = CommandDescriptionProvider.class) + public static class Descriptions extends CommandDescriptionProvider { + + public Descriptions() { + super(LabKitKeymapManager.LABKIT_SCOPE, LabKitKeymapManager.LABKIT_CONTEXT); + } + + @Override + public void getCommandDescriptions(final CommandDescriptions descriptions) { + descriptions.add(RENAME_LABEL_ACTION, RENAME_LABEL_KEYS, RENAME_LABEL_DESCRIPTION); + descriptions.add(MOVE_LABEL_UP_ACTION, MOVE_LABEL_UP_KEYS, MOVE_LABEL_UP_DESCRIPTION); + descriptions.add(MOVE_LABEL_DOWN_ACTION, MOVE_LABEL_DOWN_KEYS, MOVE_LABEL_DOWN_DESCRIPTION); + descriptions.add(REMOVE_LABEL_ACTION, REMOVE_LABEL_KEYS, REMOVE_LABEL_DESCRIPTION); + descriptions.add(CLEAR_LABEL_ACTION, CLEAR_LABEL_KEYS, CLEAR_LABEL_DESCRIPTION); + } + } + + private static final String RENAME_LABEL_ACTION = "rename current label"; + private static final String MOVE_LABEL_UP_ACTION = "move selected label up"; + private static final String MOVE_LABEL_DOWN_ACTION = "move selected label down"; + private static final String REMOVE_LABEL_ACTION = "remove selected label"; + private static final String CLEAR_LABEL_ACTION = "clear selected label"; + + private static final String[] RENAME_LABEL_KEYS = new String[] { "not mapped" }; + private static final String[] MOVE_LABEL_UP_KEYS = new String[] { "not mapped" }; + private static final String[] MOVE_LABEL_DOWN_KEYS = new String[] { "not mapped" }; + private static final String[] REMOVE_LABEL_KEYS = new String[] { "not mapped" }; + private static final String[] CLEAR_LABEL_KEYS = new String[] { "not mapped" }; + + private static final String RENAME_LABEL_DESCRIPTION = "Rename the label currently selected."; + private static final String MOVE_LABEL_UP_DESCRIPTION = "Move the label currently selected up in the list."; + private static final String MOVE_LABEL_DOWN_DESCRIPTION = "Move the label currently selected down in the list."; + private static final String REMOVE_LABEL_DESCRIPTION = "Remove the label currently selected."; + private static final String CLEAR_LABEL_DESCRIPTION = "Clear the annotations for the label currently selected."; + + + } diff --git a/src/main/java/sc/fiji/labkit/ui/actions/ResetViewAction.java b/src/main/java/sc/fiji/labkit/ui/actions/ResetViewAction.java index d71b2871..4f6d0b18 100644 --- a/src/main/java/sc/fiji/labkit/ui/actions/ResetViewAction.java +++ b/src/main/java/sc/fiji/labkit/ui/actions/ResetViewAction.java @@ -29,7 +29,13 @@ package sc.fiji.labkit.ui.actions; +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.Actions; + import sc.fiji.labkit.ui.Extensible; +import sc.fiji.labkit.ui.LabKitKeymapManager; import sc.fiji.labkit.ui.MenuBar; import sc.fiji.labkit.ui.models.ImageLabelingModel; import sc.fiji.labkit.ui.models.TransformationModel; @@ -41,7 +47,12 @@ */ public class ResetViewAction { + public ResetViewAction(Extensible extensible, ImageLabelingModel model) { + this(null, extensible, model); + } + + public ResetViewAction(Actions actions, Extensible extensible, ImageLabelingModel model) { Runnable action = () -> { TransformationModel transformationModel = model.transformationModel(); transformationModel.transformToShowInterval(model.labeling().get() @@ -49,5 +60,25 @@ public ResetViewAction(Extensible extensible, ImageLabelingModel model) { }; extensible.addMenuItem(MenuBar.VIEW_MENU, "Reset View", 100, ignore -> action.run(), null, ""); + + if (actions != null) { + actions.runnableAction(() -> action.run(), RESET_VIEW_ACTION, RESET_VIEW_KEYS); + } + } + + private static final String RESET_VIEW_ACTION = "reset view"; + private static final String[] RESET_VIEW_KEYS = new String[] { "not mapped" }; + private static final String RESET_VIEW_DESCRIPTION = "Reset the current image position, zoom and rotation."; + + @Plugin(type = CommandDescriptionProvider.class) + public static class Descriptions extends CommandDescriptionProvider { + public Descriptions() { + super(LabKitKeymapManager.LABKIT_SCOPE, LabKitKeymapManager.LABKIT_CONTEXT); + } + + @Override + public void getCommandDescriptions(final CommandDescriptions descriptions) { + descriptions.add(RESET_VIEW_ACTION, RESET_VIEW_KEYS, RESET_VIEW_DESCRIPTION); + } } } diff --git a/src/main/java/sc/fiji/labkit/ui/actions/ShowPreferencesDialogAction.java b/src/main/java/sc/fiji/labkit/ui/actions/ShowPreferencesDialogAction.java new file mode 100644 index 00000000..43516b15 --- /dev/null +++ b/src/main/java/sc/fiji/labkit/ui/actions/ShowPreferencesDialogAction.java @@ -0,0 +1,87 @@ +/*- + * #%L + * The Labkit image segmentation tool for Fiji. + * %% + * Copyright (C) 2017 - 2023 Matthias Arzt + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package sc.fiji.labkit.ui.actions; + +import java.awt.Frame; + +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.Actions; + +import bdv.tools.PreferencesDialog; +import bdv.tools.ToggleDialogAction; +import bdv.ui.keymap.Keymap; +import bdv.ui.keymap.KeymapManager; +import bdv.ui.keymap.KeymapSettingsPage; +import sc.fiji.labkit.ui.Extensible; +import sc.fiji.labkit.ui.LabKitKeymapManager; +import sc.fiji.labkit.ui.MenuBar; + +public class ShowPreferencesDialogAction +{ + + public static final String ACTION_NAME = "show preferences dialog"; + + public static final String[] ACTION_DEFAULT_KEYS = new String[] { "control P" }; + + public static final String ACTION_DESCRIPTION = "Shows the preferences dialog."; + + public static void install(Actions actions, Extensible extensible, KeymapManager keymapManager, Frame owner) { + final Keymap keymap = keymapManager.getForwardSelectedKeymap(); + final PreferencesDialog preferencesDialog = new PreferencesDialog(owner, keymap, + new String[] { LabKitKeymapManager.LABKIT_CONTEXT }); + preferencesDialog + .addPage(new KeymapSettingsPage("Keymap", keymapManager, keymapManager.getCommandDescriptions())); + final ToggleDialogAction action = new ToggleDialogAction(ACTION_NAME, preferencesDialog); + actions.namedAction(action, ACTION_DEFAULT_KEYS); + extensible.addMenuItem( MenuBar.HELP_MENU, + "Preferences", + 99, + ignore -> action.actionPerformed( null ), + null, null ); + } + + @Plugin( type = CommandDescriptionProvider.class ) + public static class Descriptions extends CommandDescriptionProvider + { + public Descriptions() + { + super( LabKitKeymapManager.LABKIT_SCOPE, LabKitKeymapManager.LABKIT_CONTEXT ); + } + + @Override + public void getCommandDescriptions( final CommandDescriptions descriptions ) + { + descriptions.add( ACTION_NAME, ACTION_DEFAULT_KEYS, ACTION_DESCRIPTION ); + descriptions.add( "close dialog window", new String[] { "control W" }, "Closes the preferences dialog." ); + } + } +} diff --git a/src/main/java/sc/fiji/labkit/ui/brush/ChangeLabel.java b/src/main/java/sc/fiji/labkit/ui/brush/ChangeLabel.java index 94706f3f..b69ea4ab 100644 --- a/src/main/java/sc/fiji/labkit/ui/brush/ChangeLabel.java +++ b/src/main/java/sc/fiji/labkit/ui/brush/ChangeLabel.java @@ -29,23 +29,35 @@ package sc.fiji.labkit.ui.brush; -import sc.fiji.labkit.ui.labeling.Label; -import sc.fiji.labkit.ui.models.LabelingModel; -import org.scijava.ui.behaviour.util.AbstractNamedAction; - -import javax.swing.*; import java.awt.event.ActionEvent; import java.util.List; +import javax.swing.AbstractAction; +import javax.swing.KeyStroke; + +import org.scijava.plugin.Plugin; +import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider; +import org.scijava.ui.behaviour.io.gui.CommandDescriptions; +import org.scijava.ui.behaviour.util.AbstractNamedAction; +import org.scijava.ui.behaviour.util.Actions; + +import sc.fiji.labkit.ui.LabKitKeymapManager; +import sc.fiji.labkit.ui.labeling.Label; +import sc.fiji.labkit.ui.models.LabelingModel; + /** * {@link AbstractAction} that goes to the next label when "N" is pressed. */ public class ChangeLabel extends AbstractNamedAction { + private static final String CHANGE_LABEL_ACTION = "next Label"; + private static final String[] CHANGE_LABEL_KEYS = new String[] { "N" }; + private static final String CHANGE_LABEL_DESCRIPTION = "Select the next label in the list."; + private final LabelingModel model; public ChangeLabel(LabelingModel model) { - super("Next Label"); + super(CHANGE_LABEL_ACTION); this.model = model; super.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("N")); } @@ -63,4 +75,20 @@ private Label next(List