Difference between revisions of "Scout/Concepts/KeyStroke"
m (Category changed) |
(→Description) |
||
Line 7: | Line 7: | ||
== Description == | == Description == | ||
− | {{ | + | In Eclipse Scout you can set KeyStrokes to components (such as Button, StringField, GroupBox...). 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 | ||
+ | <source lang="java"> | ||
+ | @Override | ||
+ | protected String getConfiguredKeyStroke() { | ||
+ | return "<keyStrokeDefinition>"; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | 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 | ||
+ | |||
+ | 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: | ||
+ | |||
+ | <source lang="java"> | ||
+ | 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> | ||
+ | |||
+ | === KeyStroke on ContextMenu === | ||
+ | The following snippet shows a SmartField with a context menu and a keyStroke "F5", which will open a MessageBox if pressed: | ||
+ | |||
+ | <source lang="java"> | ||
+ | public class SmartField extends AbstractSmartField<Long> { | ||
+ | |||
+ | @Override | ||
+ | protected String getConfiguredLabel() { | ||
+ | return "SmartField"; | ||
+ | } | ||
+ | |||
+ | @Order(10.0) | ||
+ | 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 "ContextMenu with KeyStroke"); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | Will result in | ||
+ | [[File:Keystroke_menu.png]] | ||
== Screenshot == | == Screenshot == |
Revision as of 05:48, 15 November 2013
Scout |
Wiki Home |
Website |
Download • Git |
Community |
Forums • Blog • Twitter • G+ |
Bugzilla |
Bugzilla |
Special type of Action for key actions.
Contents
Description
In Eclipse Scout you can set KeyStrokes to components (such as Button, StringField, GroupBox...). 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
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 SmartField extends AbstractSmartField<Long> { @Override protected String getConfiguredLabel() { return "SmartField"; } @Order(10.0) 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 "ContextMenu with KeyStroke"); } } }
Screenshot
Properties
Defined with getConfiguredXxxxxx() methods.
Events
Defined with execXxxxxx() methods.