Package docking.util

Class KeyBindingUtils


  • public class KeyBindingUtils
    extends java.lang.Object
    A class to provide utilities for system key bindings, such as importing and exporting key binding configurations.
    Since:
    Tracker Id 329
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.Action adaptDockingActionToNonContextAction​(DockingAction action)
      Takes the existing docking action and allows it to be registered with Swing components
      static void clearKeyBinding​(javax.swing.JComponent component, javax.swing.KeyStroke keyStroke)
      Allows clients to clear Java key bindings.
      static void clearKeyBinding​(javax.swing.JComponent component, javax.swing.KeyStroke keyStroke, int focusCondition)
      Allows clients to clear Java key bindings.
      static ToolOptions createOptionsforKeybindings​(java.io.InputStream inputStream)
      Imports key bindings from a location selected by the user.
      static void exportKeyBindings​(ToolOptions keyBindingOptions)
      Saves the key bindings from the provided options object to a file chosen by the user.
      static javax.swing.Action getAction​(javax.swing.JComponent component, javax.swing.KeyStroke keyStroke, int focusCondition)
      Returns the registered action for the given keystroke, or null of no action is bound to that keystroke.
      static ToolOptions importKeyBindings()  
      static void registerAction​(javax.swing.JComponent component, DockingAction action)
      A convenience method to register the given action with the given component.
      static void registerAction​(javax.swing.JComponent component, DockingAction action, ActionContextProvider contextProvider)
      A convenience method to register the given action with the given component.
      static void registerAction​(javax.swing.JComponent component, DockingAction action, ActionContextProvider contextProvider, int focusCondition)
      A convenience method to register the given action with the given component.
      static void registerAction​(javax.swing.JComponent component, javax.swing.KeyStroke keyStroke, javax.swing.Action action, int focusCondition)
      Registers the given action with the given key binding on the given component.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PREFERENCES_FILE_EXTENSION

        public static final java.lang.String PREFERENCES_FILE_EXTENSION
        See Also:
        Constant Field Values
    • Method Detail

      • importKeyBindings

        public static ToolOptions importKeyBindings()
      • createOptionsforKeybindings

        public static ToolOptions createOptionsforKeybindings​(java.io.InputStream inputStream)
        Imports key bindings from a location selected by the user.

        If there is a problem reading the data then the user will be shown an error dialog.

        Returns:
        An options object that is composed of key binding names and their associated keystrokes.
      • exportKeyBindings

        public static void exportKeyBindings​(ToolOptions keyBindingOptions)
        Saves the key bindings from the provided options object to a file chosen by the user.

        If there is a problem writing the data then the user will be shown an error dialog.

        Parameters:
        keyBindingOptions - The options that contains key binding data.
      • registerAction

        public static void registerAction​(javax.swing.JComponent component,
                                          DockingAction action)
        A convenience method to register the given action with the given component. This is not usually done, as the action system is usually managed by the application's tool. However, for actions that are not registered with a tool, they can instead be bound to a component, hence this method.

        The given action must have a keystroke assigned, or this method will do nothing.

        Parameters:
        component - the component to which the given action will be bound
        action - the action to bind
      • registerAction

        public static void registerAction​(javax.swing.JComponent component,
                                          DockingAction action,
                                          ActionContextProvider contextProvider)
        A convenience method to register the given action with the given component. This is not usually done, as the action system is usually managed by the application's tool. However, for actions that are not registered with a tool, they can instead be bound to a component, hence this method.

        The given action must have a keystroke assigned, or this method will do nothing.

        A typical use-case is to register an existing docking action with a text component, which is needed because the docking key event processing will not execute docking- registered actions if a text component has focus.

        Parameters:
        component - the component to which the given action will be bound
        action - the action to bind
        contextProvider - the provider of the context
      • registerAction

        public static void registerAction​(javax.swing.JComponent component,
                                          DockingAction action,
                                          ActionContextProvider contextProvider,
                                          int focusCondition)
        A convenience method to register the given action with the given component. This is not usually done, as the action system is usually managed by the application's tool. However, for actions that are not registered with a tool, they can instead be bound to a component, hence this method.

        The given action must have a keystroke assigned, or this method will do nothing.

        A typical use-case is to register an existing docking action with a text component, which is needed because the docking key event processing will not execute docking- registered actions if a text component has focus.

        Parameters:
        component - the component to which the given action will be bound
        action - the action to bind
        contextProvider - the provider of the context
        focusCondition - see JComponent for more info; the default is usually JComponent.WHEN_FOCUSED
      • registerAction

        public static void registerAction​(javax.swing.JComponent component,
                                          javax.swing.KeyStroke keyStroke,
                                          javax.swing.Action action,
                                          int focusCondition)
        Registers the given action with the given key binding on the given component.
        Parameters:
        component - the component to which the action will be registered
        keyStroke - the keystroke for to which the action will be bound
        action - the action to execute when the given keystroke is triggered
        focusCondition - the focus condition under which to bind the action (JComponent.getInputMap(int))
        focusCondition - see JComponent for more info; the default is usually JComponent.WHEN_FOCUSED
      • clearKeyBinding

        public static void clearKeyBinding​(javax.swing.JComponent component,
                                           javax.swing.KeyStroke keyStroke)
        Allows clients to clear Java key bindings. This is useful when your application is using tool-level key bindings that share the same keystroke as a built-in Java action, such as Ctrl-C for the copy action.

        Note: this method clears focus for the default (JComponent.WHEN_FOCUSED) focus condition.

        Parameters:
        component - the component for which to clear the key binding
        keyStroke - the keystroke of the binding to be cleared
        See Also:
        clearKeyBinding(JComponent, KeyStroke, int)
      • clearKeyBinding

        public static void clearKeyBinding​(javax.swing.JComponent component,
                                           javax.swing.KeyStroke keyStroke,
                                           int focusCondition)
        Allows clients to clear Java key bindings. This is useful when your application is using tool-level key bindings that share the same keystroke as a built-in Java action, such as Ctrl-C for the copy action.
        Parameters:
        component - the component for which to clear the key binding
        keyStroke - the keystroke of the binding to be cleared
        focusCondition - the particular focus condition under which the given keystroke is used (see JComponent.getInputMap(int)).
      • getAction

        public static javax.swing.Action getAction​(javax.swing.JComponent component,
                                                   javax.swing.KeyStroke keyStroke,
                                                   int focusCondition)
        Returns the registered action for the given keystroke, or null of no action is bound to that keystroke.
        Parameters:
        component - the component for which to check the binding
        keyStroke - the keystroke for which to find a bound action
        focusCondition - the focus condition under which to check for the binding (JComponent.getInputMap(int))
        Returns:
        the action registered to the given keystroke, or null of no action is registered
      • adaptDockingActionToNonContextAction

        public static javax.swing.Action adaptDockingActionToNonContextAction​(DockingAction action)
        Takes the existing docking action and allows it to be registered with Swing components

        The new action will not be correctly wired into the Docking Action Context system. This means that the given docking action should not rely on DockingAction.isEnabledForContext(docking.ActionContext) to work when called from the Swing widget.

        Parameters:
        action - the docking action to adapt to a Swing Action
        Returns:
        the new action