Class Display
- java.lang.Object
-
- ej.microui.display.Display
-
public class Display extends Object
TheDisplayobject represents the pixelated screen in the platform.
The display of the system may be retrieved by callinggetDisplay().
The display is able to render aDisplayableon its implementation screen. Only oneDisplayablecan be set on the display at a time; it is said to be visible or to be shown. The visibleDisplayablecan be retrieved with the methodgetDisplayable().
requestShow(Displayable)allows the Displayable to be selected for rendering on the display. It can be called at any time by the application, for instance in response to user inputs.
Displayuses aGraphicsContextto draw on its corresponding screen. All draw actions are serialized. The application should not use the display's graphics context outside the events mechanismrequestRender()andrender(). Nevertheless, for exceptional cases a newGraphicsContextmay be created usinggetGraphicsContext(). ThisGraphicsContextbypasses the standard serialized drawing mechanism and allows drawings to be rendered on the display at any time.
All events on the display are serialized: requestRender, callSerially, handleEvent etc. The display uses aFIFOPumpto manage its serialized event mechanism. Some events are internally executed and some events are calling some application code.
When a visible object has to be painted on aDisplay, therendermethod gives aGraphicsContextas argument and should use it to render the visible object.
Direct drawing on the display can be done from application by retrieving aGraphicsContextwithgetGraphicsContext(). Using this mechanism does not ensure drawings will be performed before, during or after the currentrender(), since it bypasses the serialization system events.
-
-
Constructor Summary
Constructors Constructor Description Display()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallOnFlushCompleted(Runnable run)Prepares a call event which will be serialized in the system event stream when the next executed flush will be done.voidcancelCallOnFlushCompleted()Cancels the event previously registered by the call tocallOnFlushCompleted(Runnable).voidflush()Performs immediately a flush updating the display with the draw actions since the last flush if and only if the display is double buffered.intgetBacklight()Returns the current backlight settingintgetContrast()Returns the contrast of the display.static DisplaygetDisplay()Returns the display of the system.DisplayablegetDisplayable()Returns the currentDisplayableobject in theDisplay.
The value returned bygetDisplayable()may benullif noDisplayableis visible.intgetDisplayColor(int color)Gets the color that will be displayed if the specified color is requested.
For example, with a monochrome display, this method will return either 0xFFFFFF (white) or 0x000000 (black) depending on the brightness of the specified color.EventHandlergetEventHandler()Returns the display's event serializer.GraphicsContextgetGraphicsContext()Returns the display'sGraphicsContext.intgetHeight()Returns the height in pixels of the display screen area available to the application.intgetNumberOfColors()Gets the number of colors that can be represented on the device.
Note that the number of colors for a black and white display is 2.intgetPixelDepth()Returns the number of bits per pixel of the display.intgetWidth()Returns the width in pixels of the display screen area available to the application.booleanhasBacklight()Tells whether the display has backlight.booleanisColor()Tells whether the display offers color.booleanisDoubleBuffered()Returns if the display uses an underlying double buffer (either hardware or software).booleanisShown(Displayable displayable)Checks whether the given displayable is visible on the display.voidrequestFlush()Requests a flush updating the display with the draw actions since the last flush if and only if the display is double buffered.voidrequestHide(Displayable displayable)Asks to set the given displayable as hidden on the display.voidrequestRender()Asks to render the current displayable.voidrequestShow(Displayable displayable)Asks to set the given displayable as visible on the display.voidsetBacklight(int backlight)Sets the backlight of the display.voidsetContrast(int contrast)Sets the contrast of the display.voidwaitFlushCompleted()Blocks the current thread (with all its locks) until previous callflush()has been processed.
-
-
-
Method Detail
-
getEventHandler
public EventHandler getEventHandler()
Returns the display's event serializer.- Returns:
- the display's event serializer.
- Since:
- 2.0
-
getHeight
public int getHeight()
Returns the height in pixels of the display screen area available to the application.- Returns:
- height of the display screen area.
-
getWidth
public int getWidth()
Returns the width in pixels of the display screen area available to the application.- Returns:
- width of the display screen area.
-
getPixelDepth
public int getPixelDepth()
Returns the number of bits per pixel of the display.- Returns:
- the number of bits per pixel
-
isColor
public boolean isColor()
Tells whether the display offers color.- Returns:
- if display has color
-
getNumberOfColors
public int getNumberOfColors()
Gets the number of colors that can be represented on the device.
Note that the number of colors for a black and white display is 2.- Returns:
- the number of colors
-
isDoubleBuffered
public boolean isDoubleBuffered()
Returns if the display uses an underlying double buffer (either hardware or software). This technique is useful to avoid flickering while the user is drawing.- Returns:
- true if and only if a double buffer is used for the display
-
getDisplayColor
public int getDisplayColor(int color)
Gets the color that will be displayed if the specified color is requested.
For example, with a monochrome display, this method will return either 0xFFFFFF (white) or 0x000000 (black) depending on the brightness of the specified color.- Parameters:
color- the desired color in 0x00RRGGBB format.- Returns:
- the corresponding color that will be displayed on the graphics context (in 0x00RRGGBB format).
-
hasBacklight
public boolean hasBacklight()
Tells whether the display has backlight.- Returns:
- if display has backlight
-
setContrast
public void setContrast(int contrast)
Sets the contrast of the display.contrastvalue range is 0-100- Parameters:
contrast- the new value of the contrast
-
getContrast
public int getContrast()
Returns the contrast of the display.- Returns:
- the current contrast of the display (range 0-100)
-
setBacklight
public void setBacklight(int backlight)
Sets the backlight of the display.backlightvalue range is 0-100- Parameters:
backlight- the new value of the backlight
-
getBacklight
public int getBacklight()
Returns the current backlight setting- Returns:
- the current backlight setting (range 0-100)
-
getDisplay
public static Display getDisplay()
Returns the display of the system. Throws aMicroUIExceptionwhen there is no display.- Returns:
- the unique display.
- Throws:
MicroUIException- if MicroUI is not started or if there is no display.
-
getDisplayable
@Nullable public Displayable getDisplayable()
Returns the currentDisplayableobject in theDisplay.
The value returned bygetDisplayable()may benullif noDisplayableis visible.- Returns:
- the current
Displayableobject in theDisplay
-
getGraphicsContext
public GraphicsContext getGraphicsContext()
Returns the display'sGraphicsContext. With thisGraphicsContext, it is possible to draw on the screen at any time without following the display events serializer. The graphics context has the same dimensions as the display, which allows to modify every pixel of the display.If the normal system execution is repainting at the same time, the last unflushed draw actions will be visible (the previous one will be hidden by the last one). It is not possible to determine which draw action will be done last.
This method should be only used in
MicroUI.callSerially(Runnable)context to synchronize the use of this graphics context with all display events.- Returns:
- the display's graphics context.
- See Also:
MicroUI.callSerially(Runnable),flush()
-
requestShow
public void requestShow(Displayable displayable)
Asks to set the given displayable as visible on the display. The treatment is synchronized with the otherDisplayevents. If theDisplay's current displayable is not this displayable, the methodsDisplayable.onShown(), thenDisplayable.render(GraphicsContext)and thenflush()will be called.- Parameters:
displayable- the displayable to show- Throws:
SecurityException- if a security manager exists and does not allow the caller to get the display.
-
requestHide
public void requestHide(Displayable displayable)
Asks to set the given displayable as hidden on the display. The treatment is synchronized with the otherDisplayevents. If theDisplay's current displayable is this displayable, the methodDisplayable.onHidden()will be called.- Parameters:
displayable- the displayable to hide
-
isShown
public boolean isShown(Displayable displayable)
Checks whether the given displayable is visible on the display.- Parameters:
displayable- the displayable to check- Returns:
trueif the displayable is currently visible,falseotherwise
-
requestRender
public void requestRender()
Asks to render the current displayable. The treatment is synchronized with the otherDisplayevents. The methodsDisplayable.render(GraphicsContext)and thenflush()will be called when the event is executed.The current displayable is the displayable which is shown when the event is executed and not the displayable which is currently shown (see
getDisplayable()which returns the current displayable). This displayable will be different than the displayable currently shown if the methodrequestShow(Displayable)is called with another displayable.By consequence, this method has not the same behavior than
Displayable.requestRender(): this other method requests the rendering on the displayable itself (if and only if this displayable is the current displayable), and the methodDisplayable.render(GraphicsContext)is called if only if the displayable is the current displayable when the event is executed.
-
requestFlush
public void requestFlush()
-
flush
public void flush()
Performs immediately a flush updating the display with the draw actions since the last flush if and only if the display is double buffered. The treatment is not synchronized with the otherDisplayevents; for this reason, this method should be used inMicroUI.callSerially(Runnable)context.
-
waitFlushCompleted
public void waitFlushCompleted()
Blocks the current thread (with all its locks) until previous callflush()has been processed.The following code does not block the caller (assuming there is no pending flush before calling first line):
display.requestFlush(); display.waitFlushCompleted();
because the call todisplay.requestFlush();only adds the request in the event serializer: noflushis running so there is nothing to wait.On the other hand, the following code blocks the current thread until the call to
flush()has been processed:display.flush(); display.waitFlushCompleted();
- Throws:
MicroUIException- if the current thread is theDisplay's events thread.
-
callOnFlushCompleted
public void callOnFlushCompleted(Runnable run)
Prepares a call event which will be serialized in the system event stream when the next executed flush will be done. This flush can already be launched or serialized (will be executed in few time) or not programmed yet.When the event is processed, the
run()method of theRunnableobject is called.
The call to therun()method of theRunnableobject is performed asynchronously. ThereforecallOnFlushCompleted()will never block waiting for therun()method to finish.Only one event can be serialized at any time. When a new event is added while the previous one has not been executed, the new one replaces the old one. The
Runnableobject of the old event will not be notified about the end of next flush.The event can be cleared by calling
cancelCallOnFlushCompleted(). In this case,TheRunnableobject of the event will not be notified about the end of next flush.The
run()method should return quickly, as with other callback methods.- Parameters:
run- aRunnableobject to call
-
cancelCallOnFlushCompleted
public void cancelCallOnFlushCompleted()
Cancels the event previously registered by the call tocallOnFlushCompleted(Runnable). TheRunnableobject of the old event will not be notified about the end of next flush.
-
-