# Class LegacyActionTools

java.lang.Object
org.eclipse.jface.action.LegacyActionTools

public final class LegacyActionTools extends Object

Some static utility methods for handling labels on actions. This includes mnemonics and accelerators.

Clients may neither instantiate this class nor extend.

Since:
  3.2

## Field Summary

Fields
Modifier and Type
Field
Description
`static final char`
`MNEMONIC_NONE`
The constant to use if there is no mnemonic for this location.

## Method Summary

Modifier and Type
Method
Description
`static String`
`convertAccelerator(int keyCode)`
Converts an accelerator key code to a string representation.
`static int`
`convertAccelerator(String acceleratorText)`
Parses the given accelerator text, and converts it to an accelerator key code.
`static String`
`escapeMnemonics(String text)`
Convenience method for escaping all mnemonics in the given string.
`static String`
`extractAcceleratorText(String text)`
Extracts the accelerator text from the given text.
`static char`
`extractMnemonic(String text)`
Extracts the mnemonic text from the given string.
`static int`
`findKeyCode(String token)`
Maps a standard keyboard key name to an SWT key code.
`static String`
`findKeyString(int keyCode)`
Maps an SWT key code to a standard keyboard key name.
`static int`
`findModifier(String token)`
Maps standard keyboard modifier key names to the corresponding SWT modifier bit.
`static String`
`findModifierString(int keyCode)`
Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND).
`static String`
`removeAcceleratorText(String text)`
Convenience method for removing any optional accelerator text from the given string.
`static String`
`removeMnemonics(String text)`
Convenience method for removing any mnemonics from the given string.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### MNEMONIC_NONE

public static final char MNEMONIC_NONE
The constant to use if there is no mnemonic for this location.

See Also:
  - Constant Field Values

## Method Details

### convertAccelerator

public static String convertAccelerator(int keyCode)
Converts an accelerator key code to a string representation.

Parameters:
  `keyCode` - the key code to be translated
Returns:
  a string representation of the key code

### convertAccelerator

public static int convertAccelerator(String acceleratorText)
Parses the given accelerator text, and converts it to an accelerator key code.

Parameters:
  `acceleratorText` - the accelerator text
Returns:
  the SWT key code, or 0 if there is no accelerator

### extractAcceleratorText

public static String extractAcceleratorText(String text)
Extracts the accelerator text from the given text. Returns `null` if there is no accelerator text, and the empty string if there is no text after the accelerator delimiter (last tab or last '@' if there's no tab).

Parameters:
  `text` - the text for the action; may be `null`.
Returns:
  the accelerator text, or `null`

### extractMnemonic

public static char extractMnemonic(String text)
Extracts the mnemonic text from the given string.

Parameters:
  `text` - The text from which the mnemonic should be extracted; may be `null`
Returns:
  The text of the mnemonic; will be `MNEMONIC_NONE` if there is no mnemonic;

### findKeyCode

public static int findKeyCode(String token)
Maps a standard keyboard key name to an SWT key code. Key names are converted to upper case before comparison. If the key name is a single letter, for example "S", its character code is returned.

The following key names are known (case is ignored):

- `"BACKSPACE"`
- `"TAB"`
- `"RETURN"`
- `"ENTER"`
- `"ESC"`
- `"ESCAPE"`
- `"DELETE"`
- `"SPACE"`
- `"ARROW_UP"`, `"ARROW_DOWN"`, `"ARROW_LEFT"`, and `"ARROW_RIGHT"`
- `"PAGE_UP"` and `"PAGE_DOWN"`
- `"HOME"`
- `"END"`
- `"INSERT"`
- `"F1"`, `"F2"` through `"F12"`

Parameters:
  `token` - the key name
Returns:
  the SWT key code, `-1` if no match was found
See Also:
  - `SWT`

### findKeyString

public static String findKeyString(int keyCode)
Maps an SWT key code to a standard keyboard key name. The key code is stripped of modifiers (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). If the key code is not an SWT code (for example if it a key code for the key 'S'), a string containing a character representation of the key code is returned.

Parameters:
  `keyCode` - the key code to be translated
Returns:
  the string representation of the key code
Since:
  2.0
See Also:
  - `SWT`

### findModifier

public static int findModifier(String token)
Maps standard keyboard modifier key names to the corresponding SWT modifier bit. The following modifier key names are recognized (case is ignored): `"CTRL"`, `"SHIFT"`, `"ALT"`, and `"COMMAND"`. The given modifier key name is converted to upper case before comparison.

Parameters:
  `token` - the modifier key name
Returns:
  the SWT modifier bit, or `0` if no match was found
See Also:
  - `SWT`

### findModifierString

public static String findModifierString(int keyCode)
Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). Returns `null` if the key code is not an SWT modifier bit.

Parameters:
  `keyCode` - the SWT modifier bit to be translated
Returns:
  the string representation of the SWT modifier bit, or `null` if the key code was not an SWT modifier bit
See Also:
  - `SWT`

### removeAcceleratorText

public static String removeAcceleratorText(String text)
Convenience method for removing any optional accelerator text from the given string. The accelerator text appears at the end of the text, and is separated from the main part by the last tab character `'\t'` (or the last `'@'` if there is no tab).

Parameters:
  `text` - the text
Returns:
  the text sans accelerator

### removeMnemonics

public static String removeMnemonics(String text)
Convenience method for removing any mnemonics from the given string. For example, `removeMnemonics("&Open")` will return `"Open"`.

Parameters:
  `text` - the text
Returns:
  the text sans mnemonics, or empty string

### escapeMnemonics

public static String escapeMnemonics(String text)
Convenience method for escaping all mnemonics in the given string. For example, `escapeMnemonics("a & b & c")` will return `"a && b && c"`.

Parameters:
  `text` - the text
Returns:
  the text with mnemonics escaped
Since:
  3.6