public final class Display extends Object
Form
) on the "display". Before any Form is shown the Developer must
invoke Display.init(Object m) in order to register the current MIDlet.
This class handles the main thread for the toolkit referenced here on as the EDT (Event Dispatch Thread) similar to the Swing EDT. This thread encapsulates the platform specific event delivery and painting semantics and enables threading features such as animations etc...
The EDT should not be blocked since paint operations and events would also be blocked
in much the same way as they would be in other platforms. In order to serialize calls back
into the EDT use the methods callSerially(java.lang.Runnable)
& callSeriallyAndWait(java.lang.Runnable)
.
Notice that all LWUIT calls occur on the EDT (events, painting, animations etc...), LWUIT
should normally be manipulated on the EDT as well (hence the callSerially(java.lang.Runnable)
&
callSeriallyAndWait(java.lang.Runnable)
methods). Theoretically it should be possible to manipulate
some LWUIT features from other threads but this can't be guaranteed to work for all use cases.
Modifier and Type | Field and Description |
---|---|
static int |
GAME_DOWN
Game action for down key
|
static int |
GAME_FIRE
Game action for fire
|
static int |
GAME_LEFT
Game action for left key
|
static int |
GAME_RIGHT
Game action for right key
|
static int |
GAME_UP
Game action for UP key
|
static int |
KEY_POUND
An attribute that encapsulates '#' int value.
|
static int |
KEYBOARD_TYPE_HALF_QWERTY
Half QWERTY which needs software assistance for completion
|
static int |
KEYBOARD_TYPE_NUMERIC
Numeric keypad keyboard type
|
static int |
KEYBOARD_TYPE_QWERTY
Full QWERTY keypad keyboard type, even if a numeric keyboard also exists
|
static int |
KEYBOARD_TYPE_UNKNOWN
Unknown keyboard type is the default indicating the software should try
to detect the keyboard type if necessary
|
static int |
KEYBOARD_TYPE_VIRTUAL
Touch device without a physical keyboard that should popup a keyboad
|
static int |
SHOW_DURING_EDIT_ALLOW_DISCARD
Allow show to occur during edit and discard all user input at this moment
|
static int |
SHOW_DURING_EDIT_ALLOW_SAVE
Allow show to occur during edit and save all user input at this moment
|
static int |
SHOW_DURING_EDIT_EXCEPTION
If show is called while editing text in the native text box an exception is thrown
|
static int |
SHOW_DURING_EDIT_IGNORE
Ignore all calls to show occurring during edit, they are discarded immediately
|
static int |
SHOW_DURING_EDIT_SET_AS_NEXT
Show will update the current form to which the OK button of the text box
will return
|
Modifier and Type | Method and Description |
---|---|
void |
addEdtErrorHandler(ActionListener e)
An error handler will receive an action event with the source exception from the EDT
once an error handler is installed the default LWUIT error dialog will no longer appear
|
void |
callSerially(Runnable r)
Causes the runnable to be invoked on the event dispatch thread.
|
void |
callSeriallyAndWait(Runnable r)
Identical to callSerially with the added benefit of waiting for the Runnable method to complete.
|
String |
convertBidiLogicalToVisual(String s)
Converts the given string from logical bidi layout to visual bidi layout so
it can be rendered properly on the screen.
|
static void |
deinitialize()
Closes down the EDT and LWUIT, under normal conditions this method is completely unnecessary
since exiting the application will shut down LWUIT.
|
static void |
detachEventListeners() |
void |
editString(Component cmp,
int maxSize,
int constraint,
String text)
Encapsulates the editing code which is specific to the platform, some platforms
would allow "in place editing" MIDP does not.
|
void |
flashBacklight(int duration)
Flash the backlight of the device for the given length of time
|
int |
getCharLocation(String source,
int index)
Returns the index of the given char within the source string, the actual
index isn't necessarily the same when bidi is involved
See this
for more on visual vs.
|
Form |
getCurrent()
Return the form currently displayed on the screen or null if no form is
currently displayed.
|
int |
getDisplayHeight()
Return the height of the display
|
int |
getDisplayWidth()
Return the width of the display
|
float |
getDragSpeed(boolean yAxis)
This method returns the dragging speed based on the latest dragged
events
|
int |
getDragStartPercentage()
This method allows us to manipulate the drag started detection logic.
|
int |
getFrameRate()
Indicates the maximum frames the API will try to draw every second
|
int |
getGameAction(int keyCode)
Returns the game action code matching the given key combination
|
static Display |
getInstance()
Return the Display instance
|
int |
getKeyboardType()
Returns the type of the input device one of:
KEYBOARD_TYPE_UNKNOWN, KEYBOARD_TYPE_NUMERIC, KEYBOARD_TYPE_QWERTY,
KEYBOARD_TYPE_VIRTUAL, KEYBOARD_TYPE_HALF_QWERTY
|
int |
getKeyCode(int gameAction)
Deprecated.
this method doesn't work properly across device and is mocked up here
mostly for the case of unit testing. Do not use it for anything other than that! Do
not rely on getKeyCode(GAME_*) == keyCodeFromKeyEvent, this will never actually happen!
|
InputStream |
getResourceAsStream(Class cls,
String resource)
This method is essentially equivalent to cls.getResourceAsStream(String)
however some platforms might define unique ways in which to load resources
within the implementation.
|
int |
getShowDuringEditBehavior()
Returns the status of the show during edit flag
|
void |
hideNotify()
Broadcasts hide notify into LWUIT, this method is invoked by the LWUIT implementation
to notify LWUIT of hideNotify events
|
static void |
init(Object m)
This is the Display initialization method.
|
void |
invokeAndBlock(Runnable r)
Invokes runnable and blocks the current thread, if the current thread is the
edt it will still be blocked however a separate thread would be launched
to perform the duties of the EDT while it is blocked.
|
boolean |
isAllowMinimizing()
Allows a LWUIT application to minimize without forcing it to the front whenever
a new dialog is poped up
|
boolean |
isBidiAlgorithm()
Indicates whether LWUIT should consider the bidi RTL algorithm
when drawing text or navigating with the text field cursor.
|
boolean |
isClickTouchScreen()
Indicates whether the device has a double layer screen thus allowing two
stages to touch events: click and hover.
|
boolean |
isEdt()
Returns true if we are currently in the event dispatch thread.
|
boolean |
isLightMode()
Deprecated.
this method is no longer used, it was too unreliable
|
boolean |
isMinimized()
Indicates whether an application is minimized
|
boolean |
isMultiTouch()
Indicates whether the device supports multi-touch events, this is only
relevant when touch events are supported
|
boolean |
isNativeInputSupported()
Indicates whether the device supports native in place editing in which case
lightweight input logic shouldn't be used for input.
|
boolean |
isPureTouch()
A pure touch device has no focus showing when the user is using the touch
interface.
|
boolean |
isRTL(char c)
Returns true if the given character is an RTL character
|
boolean |
isThirdSoftButton()
Indicates whether the 3rd softbutton should be supported on this device
|
boolean |
isTouchScreenDevice()
Indicates if this is a touch screen device that will return pen events,
defaults to true if the device has pen events but can be overriden by
the developer.
|
boolean |
isVirtualKeyboardShowing()
Indicates if the virtual keyboard is currently showing or not
|
boolean |
isVirtualKeyboardShowingSupported()
Indicates whether showing a virtual keyboard programmatically is supported
|
void |
keyPressed(int keyCode)
Pushes a key press event with the given keycode into LWUIT
|
void |
keyReleased(int keyCode)
Pushes a key release event with the given keycode into LWUIT
|
boolean |
minimizeApplication()
Minimizes the current application if minimization is supported by the platform (may fail).
|
int |
numAlphaLevels()
Return the number of alpha levels supported by the implementation.
|
int |
numColors()
Returns the number of colors applicable on the device, note that the API
does not support gray scale devices.
|
void |
onEditingComplete(Component c,
String text)
Called by the underlying implementation to indicate that editing in the native
system has completed and changes should propogate into LWUIT
|
void |
pointerDragged(int[] x,
int[] y)
Pushes a pointer drag event with the given coordinates into LWUIT
|
void |
pointerHover(int[] x,
int[] y)
Pushes a pointer hover event with the given coordinates into LWUIT
|
void |
pointerHoverReleased(int[] x,
int[] y)
Pushes a pointer hover release event with the given coordinates into LWUIT
|
void |
pointerPressed(int[] x,
int[] y)
Pushes a pointer press event with the given coordinates into LWUIT
|
void |
pointerReleased(int[] x,
int[] y)
Pushes a pointer release event with the given coordinates into LWUIT
|
void |
removeEdtErrorHandler(ActionListener e)
An error handler will receive an action event with the source exception from the EDT
once an error handler is installed the default LWUIT error dialog will no longer appear
|
void |
restoreMinimizedApplication()
Restore the minimized application if minimization is supported by the platform
|
void |
setAllowMinimizing(boolean allowMinimizing)
Allows a LWUIT application to minimize without forcing it to the front whenever
a new dialog is poped up
|
void |
setBidiAlgorithm(boolean activate)
Indicates whether LWUIT should consider the bidi RTL algorithm
when drawing text or navigating with the text field cursor.
|
void |
setDragStartPercentage(int dragStartPercentage)
This method allows us to manipulate the drag started detection logic.
|
void |
setFlashGraphicsBug(boolean flushGraphicsBug)
Deprecated.
this method is no longer supported use GameCanvasImplementation.setFlashGraphicsBug(f) instead
|
void |
setFramerate(int rate)
Indicates the maximum frames the API will try to draw every second
by default this is set to 10.
|
void |
setLightMode(boolean lightMode)
Deprecated.
this method is no longer used, it was too unreliable
|
void |
setNoSleep(boolean noSleep)
Calling this method with noSleep=true will cause the edt to run without sleeping.
|
void |
setPureTouch(boolean pureTouch)
A pure touch device has no focus showing when the user is using the touch
interface.
|
void |
setShowDuringEditBehavior(int showDuringEdit)
Invoking the show() method of a form/dialog while the user is editing
text in the native text box can have several behaviors: SHOW_DURING_EDIT_IGNORE,
SHOW_DURING_EDIT_EXCEPTION, SHOW_DURING_EDIT_ALLOW_DISCARD,
SHOW_DURING_EDIT_ALLOW_SAVE, SHOW_DURING_EDIT_SET_AS_NEXT
|
void |
setShowVirtualKeyboard(boolean show)
Displays the virtual keyboard on devices that support manually poping up
the vitual keyboard
|
void |
setThirdSoftButton(boolean thirdSoftButton)
Indicates whether the 3rd softbutton should be supported on this device
|
void |
setTouchScreenDevice(boolean touchScreen)
Indicates if this is a touch screen device that will return pen events,
defaults to true if the device has pen events but can be overriden by
the developer.
|
void |
setTransitionYield(int transitionD)
Indicates whether a delay should exist between calls to flush graphics during
transition.
|
void |
showNotify()
Broadcasts show notify into LWUIT, this method is invoked by the LWUIT implementation
to notify LWUIT of showNotify events
|
void |
sizeChanged(int w,
int h)
Notifies LWUIT of display size changes, this method is invoked by the implementation
class and is for internal use
|
void |
vibrate(int duration)
Vibrates the device for the given length of time
|
public static final int KEYBOARD_TYPE_UNKNOWN
public static final int KEYBOARD_TYPE_NUMERIC
public static final int KEYBOARD_TYPE_QWERTY
public static final int KEYBOARD_TYPE_VIRTUAL
public static final int KEYBOARD_TYPE_HALF_QWERTY
public static final int GAME_FIRE
public static final int GAME_LEFT
public static final int GAME_RIGHT
public static final int GAME_UP
public static final int GAME_DOWN
public static final int KEY_POUND
public static final int SHOW_DURING_EDIT_IGNORE
public static final int SHOW_DURING_EDIT_EXCEPTION
public static final int SHOW_DURING_EDIT_ALLOW_DISCARD
public static final int SHOW_DURING_EDIT_ALLOW_SAVE
public static final int SHOW_DURING_EDIT_SET_AS_NEXT
public static void init(Object m)
m
- the main running MIDletpublic static void deinitialize()
public static Display getInstance()
public int getDragStartPercentage()
public void setDragStartPercentage(int dragStartPercentage)
dragStartPercentage
- percentage of the screen required to initiate dragpublic static void detachEventListeners()
public void setFramerate(int rate)
rate
- the frame ratepublic void vibrate(int duration)
duration
- length of time to vibratepublic void flashBacklight(int duration)
duration
- length of time to flash the backlightpublic void setShowDuringEditBehavior(int showDuringEdit)
showDuringEdit
- one of the following: SHOW_DURING_EDIT_IGNORE,
SHOW_DURING_EDIT_EXCEPTION, SHOW_DURING_EDIT_ALLOW_DISCARD,
SHOW_DURING_EDIT_ALLOW_SAVE, SHOW_DURING_EDIT_SET_AS_NEXTpublic int getShowDuringEditBehavior()
public int getFrameRate()
public boolean isEdt()
public void callSerially(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventspublic void callSeriallyAndWait(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventsIllegalStateException
- if this method is invoked on the event dispatch thread (e.g. during
paint or event handling).public void onEditingComplete(Component c, String text)
c
- edited componenttext
- new text for the componentpublic void invokeAndBlock(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked synchroniously by this methodpublic boolean isTouchScreenDevice()
public void setTouchScreenDevice(boolean touchScreen)
touchScreen
- false if this is not a touch screen devicepublic void setNoSleep(boolean noSleep)
noSleep
- causes the edt to stop the sleeping periods between 2 cyclespublic void setFlashGraphicsBug(boolean flushGraphicsBug)
flushGraphicsBug
- true if the bug exists on this device (the safe choice)
false for slightly higher performance.public void setTransitionYield(int transitionD)
transitionD
- -1 for no delay otherwise delay in millisecondspublic void editString(Component cmp, int maxSize, int constraint, String text)
cmp
- the TextArea
componentpublic boolean minimizeApplication()
public boolean isMinimized()
public void restoreMinimizedApplication()
public void keyPressed(int keyCode)
keyCode
- keycode of the key eventpublic void keyReleased(int keyCode)
keyCode
- keycode of the key eventpublic void pointerDragged(int[] x, int[] y)
x
- the x position of the pointery
- the y position of the pointerpublic void pointerHover(int[] x, int[] y)
x
- the x position of the pointery
- the y position of the pointerpublic void pointerHoverReleased(int[] x, int[] y)
x
- the x position of the pointery
- the y position of the pointerpublic void pointerPressed(int[] x, int[] y)
x
- the x position of the pointery
- the y position of the pointerpublic void pointerReleased(int[] x, int[] y)
x
- the x position of the pointery
- the y position of the pointerpublic void sizeChanged(int w, int h)
w
- the width of the drawing surfaceh
- the height of the drawing surfacepublic void hideNotify()
public void showNotify()
public Form getCurrent()
public int numAlphaLevels()
public int numColors()
public boolean isLightMode()
public void setLightMode(boolean lightMode)
lightMode
- true to activate light modepublic int getDisplayWidth()
public int getDisplayHeight()
public int getGameAction(int keyCode)
keyCode
- key code received from the eventpublic int getKeyCode(int gameAction)
gameAction
- game action constant from this classpublic boolean isThirdSoftButton()
public void setThirdSoftButton(boolean thirdSoftButton)
thirdSoftButton
- true if a third softbutton should be usedpublic void setShowVirtualKeyboard(boolean show)
show
- toggles the virtual keyboards visibilitypublic boolean isVirtualKeyboardShowing()
public boolean isVirtualKeyboardShowingSupported()
public int getKeyboardType()
public boolean isNativeInputSupported()
public boolean isMultiTouch()
public boolean isClickTouchScreen()
A click touch screen will also send pointer hover events to the underlying software and will only send the standard pointer events on click.
public float getDragSpeed(boolean yAxis)
yAxis
- indicates what axis speed is requiredpublic boolean isBidiAlgorithm()
public void setBidiAlgorithm(boolean activate)
activate
- set to true to activate the bidi algorithm, false to
disable itpublic String convertBidiLogicalToVisual(String s)
s
- a "logical" string with RTL characterspublic int getCharLocation(String source, int index)
source
- the string in which we are looking for the positionindex
- the "logical" location of the cursorpublic boolean isRTL(char c)
c
- character to testpublic InputStream getResourceAsStream(Class cls, String resource)
cls
- class to load the resource fromresource
- relative/absolute URL based on the Java conventionpublic void addEdtErrorHandler(ActionListener e)
e
- listener receiving the errorspublic void removeEdtErrorHandler(ActionListener e)
e
- listener receiving the errorspublic void setAllowMinimizing(boolean allowMinimizing)
allowMinimizing
- valuepublic boolean isAllowMinimizing()
public boolean isPureTouch()
public void setPureTouch(boolean pureTouch)
pureTouch
- the value for pureTouch