Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Scout/Concepts/KeyStroke"
(→Description) |
|||
(2 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
== Description == | == Description == | ||
− | In Eclipse Scout you can set KeyStrokes to components (such as | + | In Eclipse Scout you can set KeyStrokes to components (such as Menus, Buttons, StringFields, GroupBoxes...). A KeyStroke represents a certain key sequence on the keyboard and can be associated with an action if the key sequence is pressed. For example one can associate a KeyStroke (F5) on a table in order to refresh it. |
A KeyStroke in Scout is defined as a String and set via | A KeyStroke in Scout is defined as a String and set via | ||
<source lang="java"> | <source lang="java"> | ||
− | + | @Override | |
− | + | protected String getConfiguredKeyStroke() { | |
− | + | return "<keyStrokeDefinition>"; | |
− | + | } | |
</source> | </source> | ||
Below you will see some examples of keyStrokes: | Below you will see some examples of keyStrokes: | ||
− | * Alt | + | * <tt>"Alt-F4"</tt> --> alternate-f4 |
− | * Ctrl+Alt+1 --> control-alternate-1 | + | * <tt>"Ctrl+Alt+1"</tt> --> control-alternate-1 |
− | * F1 --> f1 | + | * <tt>"F1"</tt> --> f1 |
− | * F10 --> f10 | + | * <tt>"F10"</tt> --> f10 |
− | * Ctrl | + | * <tt>"Ctrl-Shift-1"</tt> --> control-shift-1 |
− | * Ctrl | + | * <tt>"Ctrl-Shift-a"</tt> --> control-shift-a |
+ | |||
+ | If you want to map keys from the numeric keypad you need to use those keys identifiers in scout: | ||
+ | * <tt>"ADD"</tt> --> the "+" key in the numpad | ||
+ | * <tt>"SUBTRACT"</tt> --> the "-" key in the numpad | ||
+ | * <tt>"DIVIDE"</tt> --> the "/" key in the numpad | ||
+ | * <tt>"MULTIPLY"</tt> --> the "*" key in the numpad | ||
Scout defines predefined Strings which will be mapped to keyStrokes: | Scout defines predefined Strings which will be mapped to keyStrokes: | ||
Line 31: | Line 37: | ||
* f1 - f12 --> F1 - F12 | * f1 - f12 --> F1 - F12 | ||
* shift --> Shift | * shift --> Shift | ||
− | |||
− | |||
== Examples == | == Examples == | ||
Line 41: | Line 45: | ||
public class StringField extends AbstractStringField { | public class StringField extends AbstractStringField { | ||
− | + | @Override | |
− | + | protected String getConfiguredLabel() { | |
− | + | return "StringField"; | |
− | + | } | |
− | + | public class KeyStroke extends AbstractKeyStroke { | |
− | + | @Override | |
− | + | protected String getConfiguredKeyStroke() { | |
− | + | return "f5"; | |
− | + | } | |
− | + | @Override | |
− | + | protected void execAction() throws ProcessingException { | |
− | + | MessageBox.showOkMessage("KeyStroke", "F5 pressed on TextField", ""); | |
− | + | } | |
− | + | } | |
− | + | } | |
</source> | </source> | ||
Line 65: | Line 69: | ||
<source lang="java"> | <source lang="java"> | ||
− | public class | + | public class SmartFieldMenu extends AbstractExtensibleMenu { |
− | + | @Override | |
− | + | protected void execAction() throws ProcessingException { | |
− | + | MessageBox.showOkMessage("KeyStroke", "Alt+2 pressed on SmartField", ""); | |
− | + | } | |
− | + | @Override | |
− | + | protected String getConfiguredKeyStroke() { | |
+ | return "alt-2"; | ||
+ | } | ||
− | + | @Override | |
− | + | protected String getConfiguredText() { | |
− | + | return TEXTS.get("ContextMenu with KeyStroke"); | |
− | + | } | |
− | + | } | |
− | + | }</source> | |
− | + | Will result in: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </source> | + | |
− | Will result in | + | |
[[File:Keystroke_menu.png]] | [[File:Keystroke_menu.png]] | ||
Revision as of 02:57, 23 July 2014
The Scout documentation has been moved to https://eclipsescout.github.io/.
Special type of The Scout documentation has been moved to https://eclipsescout.github.io/. for key actions.
- implements: The Scout documentation has been moved to https://eclipsescout.github.io/.
- extends: The Scout documentation has been moved to https://eclipsescout.github.io/.
Contents
Description
In Eclipse Scout you can set KeyStrokes to components (such as Menus, Buttons, StringFields, GroupBoxes...). A KeyStroke represents a certain key sequence on the keyboard and can be associated with an action if the key sequence is pressed. For example one can associate a KeyStroke (F5) on a table in order to refresh it.
A KeyStroke in Scout is defined as a String and set via
@Override protected String getConfiguredKeyStroke() { return "<keyStrokeDefinition>"; }
Below you will see some examples of keyStrokes:
- "Alt-F4" --> alternate-f4
- "Ctrl+Alt+1" --> control-alternate-1
- "F1" --> f1
- "F10" --> f10
- "Ctrl-Shift-1" --> control-shift-1
- "Ctrl-Shift-a" --> control-shift-a
If you want to map keys from the numeric keypad you need to use those keys identifiers in scout:
- "ADD" --> the "+" key in the numpad
- "SUBTRACT" --> the "-" key in the numpad
- "DIVIDE" --> the "/" key in the numpad
- "MULTIPLY" --> the "*" key in the numpad
Scout defines predefined Strings which will be mapped to keyStrokes:
- alternate --> Alt
- control --> Ctrl
- f1 - f12 --> F1 - F12
- shift --> Shift
Examples
KeyStroke on StringField
The following snippet shows a StringField with a keyStroke "F5", which will open a MessageBox if pressed:
public class StringField extends AbstractStringField { @Override protected String getConfiguredLabel() { return "StringField"; } public class KeyStroke extends AbstractKeyStroke { @Override protected String getConfiguredKeyStroke() { return "f5"; } @Override protected void execAction() throws ProcessingException { MessageBox.showOkMessage("KeyStroke", "F5 pressed on TextField", ""); } } }
KeyStroke on ContextMenu
The following snippet shows a SmartField with a context menu and a keyStroke "F5", which will open a MessageBox if pressed:
public class SmartFieldMenu extends AbstractExtensibleMenu { @Override protected void execAction() throws ProcessingException { MessageBox.showOkMessage("KeyStroke", "Alt+2 pressed on SmartField", ""); } @Override protected String getConfiguredKeyStroke() { return "alt-2"; } @Override protected String getConfiguredText() { return TEXTS.get("ContextMenu with KeyStroke"); } } }
Screenshot
Properties
Defined with The Scout documentation has been moved to https://eclipsescout.github.io/. methods.
Events
Defined with The Scout documentation has been moved to https://eclipsescout.github.io/. methods.
See Also
- The Scout documentation has been moved to https://eclipsescout.github.io/.
- The Scout documentation has been moved to https://eclipsescout.github.io/.