|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eesgmbh.gimv.client.controls.KeystrokeControl
public class KeystrokeControl
This control can be used to move the image with keystrokes, eg. with the arrow keys.
It is implemented as a Event.NativePreviewHandler, which will do something if the target Element
of the keystroke (the receiver of the key event) is one of the elements registered here. To register an Element invoke addTargetElement(Element).
The target element of the browser's key events is the one which is currently focused, e.g. because the user clicked on the element.
Not all elements are focusable (e.g. an image is not, wheras a drop down menu is). If the user clicked on a non-focusable element,
the target element is the document's HTML section (in FF) or the BODY section (in Chrome), IE seems to be able to focus on any element but
its behavior is generally quirky.
If you register no element at all, the control will take action on the registered key strokes ignoring the target element. You may encounter problems with that approach. E.g. if the user scrolls through a drop down menu using the arrow keys the GIMV-image will react as well.
For optimal user experience register focusable elements like Viewport and also invoke addDocumentAndBodyAsTarget(). Test your setup
by clicking on your user interface and verify that the keystroke control is still working (or not working where it should not). There might also be differences
across browsers.
After target elements are specified, the respective keys including modifier key state can be registered in registerKey(int, Direction, int) or
registerKey(int, boolean, boolean, boolean, boolean, Direction, int) with the respective move operations that should be invoked
A delay for firing LoadImageDataEvent can be specified. The default is 500ms. This means that (possibly expensive) image rendering is
only triggered after the user did not hit a key for 500ms. The value can be change with setLoadImageDataEventFiringDelay(int).
Thus, when the user presses a key, only the last of the resulting successive key events will lead to a LoadImageDataEvent.
Registers with the HandlerManager to receive the following events
SetDomainBoundsEvent (mandatory, won't work otherwise)
SetViewportPixelBoundsEvent (mandatory, won't work otherwise)
SetMaxDomainBoundsEvent (optional, if not received, there will be no restriction)
SetDataAreaPixelBoundsEvent (optional, if the vieport contains an image which contains a data area related to SetDomainBoundsEvent, e.g. without axis areas)
Fires the following events
SetDomainBoundsEvent recomputed after recieving a key stroke event
ChangeImagePixelBoundsEvent fired after firing SetDomainBoundsEvent
LoadImageDataEvent fired after firing ChangeImagePixelBoundsEvent
| Constructor Summary | |
|---|---|
KeystrokeControl(HandlerManager handlerManager)
Instantiates the control with default configuration. |
|
| Method Summary | |
|---|---|
void |
addDocumentAndBodyAsTarget()
React to keystroke events, even if the browser does not have an element under focus. |
void |
addTargetElement(Element element)
Adds a target element. |
void |
registerKey(int keycode,
boolean ctrl,
boolean alt,
boolean shift,
boolean meta,
Direction direction,
int offsetInPixel)
Registers a keystroke with a move operations. |
void |
registerKey(int keycode,
Direction direction,
int offsetInPixel)
Registers a keystroke with a move operations. |
void |
setCancelEvent(boolean cancelEvent)
Specify whether keystroke events will be canceled. |
void |
setFireChangeImagePixelBoundsEvent(boolean fireChangeImagePixelBoundsEvent)
Specify whether the image gets immediately repositioned prior to loading the newly rendered one. |
void |
setFireLoadImageDataEvent(boolean fireLoadImageDataEvent)
Specify whether a LoadImageDataEvent is fired. |
void |
setLoadImageDataEventFiringDelay(int delayInMillis)
Sets the time in milliseconds for how long to defer firing a LoadImageDataEvent. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public KeystrokeControl(HandlerManager handlerManager)
handlerManager - A HandlerManager| Method Detail |
|---|
public void addTargetElement(Element element)
element - Target element. Can be obtained from a widget by calling UIObject.getElement()public void addDocumentAndBodyAsTarget()
public void registerKey(int keycode,
Direction direction,
int offsetInPixel)
keycode - One of the constants in KeyCodesdirection - The direction to move the image tooffsetInPixel - How much to move the image in pixels
public void registerKey(int keycode,
boolean ctrl,
boolean alt,
boolean shift,
boolean meta,
Direction direction,
int offsetInPixel)
keycode - One of the constants in KeyCodesctrl - Should the modifier be downalt - Should the modifier be downshift - Should the modifier be downmeta - Should the modifier be downdirection - The direction to move the image tooffsetInPixel - How much to move the image in pixelspublic void setCancelEvent(boolean cancelEvent)
This means that if you register the arrow keys and set cancelEvent to true, scrolling the browser's window with the arrow keys becomes impossible (as the browser is not informed about the keystroke).
The default is false.
cancelEvent - public void setFireLoadImageDataEvent(boolean fireLoadImageDataEvent)
Specify whether a LoadImageDataEvent is fired.
Default is true.
fireLoadImageDataEvent - fire it, or notpublic void setFireChangeImagePixelBoundsEvent(boolean fireChangeImagePixelBoundsEvent)
Specify whether the image gets immediately repositioned prior to loading the newly rendered one.
Default is true.
fireChangeImagePixelBoundsEvent - public void setLoadImageDataEventFiringDelay(int delayInMillis)
LoadImageDataEvent.
The default value is 500 ms. This means that 500 ms have to pass after the last keystroke until a
LoadImageDataEvent is fired causing the image to be newly rendered. If multiple keystrokes were received during
that period, the new image bounds will be the 'sum' of all these keystrokes.
The value of 500ms was chosen to match the auto-repeat of most keyboards.
This helps to reduce server load where image rendering might take place.
delayInMillis - A millisecond value. Pass in 0 (zero) to deactivate delayed firing of LoadImageDataEvent
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||