Class KeyBindingUtils
- java.lang.Object
-
- docking.util.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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PREFERENCES_FILE_EXTENSION
-
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 componentsstatic 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.
-
-
-
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 boundaction
- 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 boundaction
- the action to bindcontextProvider
- 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 boundaction
- the action to bindcontextProvider
- the provider of the contextfocusCondition
- seeJComponent
for more info; the default is usuallyJComponent.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 registeredkeyStroke
- the keystroke for to which the action will be boundaction
- the action to execute when the given keystroke is triggeredfocusCondition
- the focus condition under which to bind the action (JComponent.getInputMap(int)
)focusCondition
- seeJComponent
for more info; the default is usuallyJComponent.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 bindingkeyStroke
- 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 bindingkeyStroke
- the keystroke of the binding to be clearedfocusCondition
- the particular focus condition under which the given keystroke is used (seeJComponent.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 bindingkeyStroke
- the keystroke for which to find a bound actionfocusCondition
- 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 componentsThe 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 SwingAction
- Returns:
- the new action
-
-