Class Desktop
- java.lang.Object
-
- ej.microui.display.Displayable
-
- ej.mwt.Desktop
-
- All Implemented Interfaces:
ej.microui.event.EventHandler
public class Desktop extends ej.microui.display.DisplayableA desktop is the top-level object that can be displayed on aDisplay.It contains a widget. This widget can be a container to have a more elaborate hierarchy of widgets.
A desktop may be shown or hidden, but at most one desktop is shown per
Display.A desktop provides an animator, which can be used by the widgets to start and stop animations. When the desktop is hidden, every animation is automatically stopped.
A desktop provides a stylesheet, which is used by the widgets of the desktop in order to retrieve their style. By default, the stylesheet is a
VoidStylesheet, but this can be changed at any time.- See Also:
Display
-
-
Constructor Summary
Constructors Constructor Description Desktop()Creates a new desktop.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsWidget(Widget widget)Returns whether or not this desktop contains the given widget.protected EventDispatchercreateEventDispatcher()Creates the event dispatcher which is responsible for dispatching events to the widgets.protected RenderPolicycreateRenderPolicy()Creates the render policy which is responsible for rendering the widgets.AnimatorgetAnimator()Gets the animator instance.EventDispatchergetEventDispatcher()Gets the event dispatcher of this desktop.StylesheetgetStylesheet()Gets the stylesheet instance.WidgetgetWidget()Gets the widget attached to this desktop.WidgetgetWidgetAt(int x, int y)Returns the child widget at the specified position.booleanhandleEvent(int event)Handles an event by delegating it to the event dispatcher.booleanisAttached()Gets whether this desktop is attached or not.booleanisShown()Checks whether the desktop is visible on the display.protected voidonHidden()This method is called by the system as soon as the desktop is hidden from the display.protected voidonShown()This method is called by the system as soon as the desktop is shown on the display.protected voidrender(ej.microui.display.GraphicsContext g)The desktop is rendered using the given graphics context.voidrenderWidget(ej.microui.display.GraphicsContext g, Widget widget)Renders a widget.voidrequestHide()Hides the desktop from the display.voidrequestLayOut()Requests a lay out of all the hierarchy of this desktop.voidrequestRender()voidrequestShow()Shows the desktop on the display.voidsetAttached()Sets this desktop as attached.voidsetDetached()Sets this desktop as detached.voidsetStylesheet(Stylesheet stylesheet)Sets the stylesheet instance.voidsetWidget(Widget widget)Attaches a widget to this desktop.
-
-
-
Method Detail
-
createEventDispatcher
protected EventDispatcher createEventDispatcher()
Creates the event dispatcher which is responsible for dispatching events to the widgets. By default, apointer event dispatcheris created.- Returns:
- the event dispatcher.
- See Also:
PointerEventDispatcher
-
getEventDispatcher
@Nullable public EventDispatcher getEventDispatcher()
Gets the event dispatcher of this desktop.- Returns:
- the event dispatcher of this desktop.
-
createRenderPolicy
protected RenderPolicy createRenderPolicy()
Creates the render policy which is responsible for rendering the widgets. By default, adefault render policyis created.- Returns:
- the render policy.
- See Also:
DefaultRenderPolicy
-
setWidget
public void setWidget(@Nullable Widget widget)Attaches a widget to this desktop.If there is already a widget on this desktop, the former is detached from the latter.
If the specified widget is
null, the desktop does not hold a widget anymore.Should be called in the display thread to avoid concurrency issues.
- Parameters:
widget- the widget.- Throws:
java.lang.IllegalArgumentException- if the specified widget is already attached.
-
getWidget
@Nullable public Widget getWidget()
Gets the widget attached to this desktop.- Returns:
- the widget attached with this desktop or
null.
-
requestLayOut
public void requestLayOut()
Requests a lay out of all the hierarchy of this desktop.The layout is done asynchronously, therefore this method returns immediately. To execute some code just after the layout is done, this code could be wrapped in a
Runnableand executed asynchronously withMicroUI.callSerially(Runnable).Nothing is done if the desktop is not shown.
Notifies its child widget that it is shown.
-
requestRender
public void requestRender()
- Overrides:
requestRenderin classej.microui.display.Displayable
-
isShown
public boolean isShown()
Checks whether the desktop is visible on the display.Calling this method is equivalent to calling
Display.getDisplay().isShown(desktop);.- Returns:
trueif the desktop is currently visible,falseotherwise.
-
requestShow
public void requestShow()
Shows the desktop on the display.Calling this method is equivalent to calling
Display.getDisplay().requestShow(desktop);.This method returns immediately and the desktop is shown asynchronously in the MicroUI thread. To execute some code just after the show is done, this code could be wrapped in a
Runnableand executed asynchronously withMicroUI.callSerially(Runnable).- Throws:
java.lang.SecurityException- if a security manager exists and does not allow the caller to get the display.
-
requestHide
public void requestHide()
Hides the desktop from the display.Calling this method is equivalent to calling
Display.getDisplay().requestHide(desktop);.This method returns immediately and the desktop is hidden asynchronously in the MicroUI thread. To execute some code just after the hide is done, this code could be wrapped in a
Runnableand executed asynchronously withMicroUI.callSerially(Runnable).
-
onShown
protected void onShown()
This method is called by the system as soon as the desktop is shown on the display.- The event dispatcher is created,
- the desktop is attached (along with its children),
- its children are shown.
- Overrides:
onShownin classej.microui.display.Displayable- See Also:
setAttached()
-
onHidden
protected void onHidden()
This method is called by the system as soon as the desktop is hidden from the display.- The event dispatcher is disposed,
- the desktop is detached (along with its widget hierarchy).
- Overrides:
onHiddenin classej.microui.display.Displayable- See Also:
setDetached()
-
setAttached
public void setAttached()
Sets this desktop as attached.Every widget in its hierarchy is attached and a layout is performed.
- See Also:
isAttached(),Widget.onAttached()
-
setDetached
public void setDetached()
Sets this desktop as detached.Every widget in its hierarchy is detached.
- See Also:
isAttached(),Widget.onDetached()
-
isAttached
public boolean isAttached()
Gets whether this desktop is attached or not.When the desktop is attached, that means that it is ready to be displayed (shown on a display or drawn in an image).
- Returns:
trueif this desktop is attached,falseotherwise.
-
handleEvent
public boolean handleEvent(int event)
Handles an event by delegating it to the event dispatcher.- Parameters:
event- the event to handle.- Returns:
trueif the event is consumed,falseotherwise.
-
renderWidget
public void renderWidget(ej.microui.display.GraphicsContext g, Widget widget)Renders a widget.Beware that even an hidden child can be rendered by calling this method.
An assertion checks that the given widget is actually a child of this desktop.
- Parameters:
g- the graphics context to use to draw the widget.widget- the widget to render.
-
render
protected void render(ej.microui.display.GraphicsContext g)
The desktop is rendered using the given graphics context.Renders its child widget entirely.
- Specified by:
renderin classej.microui.display.Displayable- Parameters:
g- the graphics context of the display.
-
getWidgetAt
@Nullable public Widget getWidgetAt(int x, int y)
Returns the child widget at the specified position.If this desktop does not
contains(x, y),nullis returned. The position is considered here as a relative position to the desktop.- Parameters:
x- x coordinate.y- y coordinate.- Returns:
- the widget at the position,
nullif no widget is found in this desktop hierarchy. - See Also:
Widget.getWidgetAt(int, int)
-
containsWidget
public boolean containsWidget(Widget widget)
Returns whether or not this desktop contains the given widget.- Parameters:
widget- the widget to check.- Returns:
trueif this desktop contains the given widget,falseotherwise.- See Also:
Widget.containsWidget(Widget)
-
getAnimator
public Animator getAnimator()
Gets the animator instance.- Returns:
- the animator instance.
-
setStylesheet
public void setStylesheet(Stylesheet stylesheet)
Sets the stylesheet instance.- Parameters:
stylesheet- the stylesheet instance.
-
getStylesheet
public Stylesheet getStylesheet()
Gets the stylesheet instance.- Returns:
- the stylesheet instance.
-
-