public class Desktop extends Displayable
Display
.
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.
Display
Constructor and Description |
---|
Desktop()
Creates a new desktop.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsWidget(Widget widget)
Returns whether or not this desktop contains the given widget.
|
protected EventDispatcher |
createEventDispatcher()
Creates the event dispatcher which is responsible for dispatching events to the widgets.
|
protected RenderPolicy |
createRenderPolicy()
Creates the render policy which is responsible for rendering the widgets.
|
Animator |
getAnimator()
Gets the animator instance.
|
EventDispatcher |
getEventDispatcher()
Gets the event dispatcher of this desktop.
|
Stylesheet |
getStylesheet()
Gets the stylesheet instance.
|
Widget |
getWidget()
Gets the widget attached to this desktop.
|
Widget |
getWidgetAt(int x,
int y)
Returns the child widget at the specified position.
|
boolean |
handleEvent(int event)
Handles an event by delegating it to the event dispatcher.
|
boolean |
isAttached()
Gets whether this desktop is attached or not.
|
boolean |
isShown()
Checks whether the desktop is visible on the display.
|
protected void |
onHidden()
This method is called by the system as soon as the desktop is hidden from the display.
|
protected void |
onShown()
This method is called by the system as soon as the desktop is shown on the display.
|
protected void |
render(GraphicsContext g)
The desktop is rendered using the given graphics context.
|
void |
renderWidget(GraphicsContext g,
Widget widget)
Renders a widget.
|
void |
requestHide()
Hides the desktop from the display.
|
void |
requestLayOut()
Requests a lay out of all the hierarchy of this desktop.
|
void |
requestRender()
Requests a rendering for the entire displayable.
|
void |
requestShow()
Shows the desktop on the display.
|
void |
setAttached()
Sets this desktop as attached.
|
void |
setDetached()
Sets this desktop as detached.
|
void |
setStylesheet(Stylesheet stylesheet)
Sets the stylesheet instance.
|
void |
setWidget(Widget widget)
Attaches a widget to this desktop.
|
public boolean containsWidget(Widget widget)
widget
- the widget to check.true
if this desktop contains the given widget, false
otherwise.Widget.containsWidget(Widget)
protected EventDispatcher createEventDispatcher()
pointer event dispatcher
is created.PointerEventDispatcher
protected RenderPolicy createRenderPolicy()
default render policy
is created.DefaultRenderPolicy
public Animator getAnimator()
@Nullable public EventDispatcher getEventDispatcher()
public Stylesheet getStylesheet()
@Nullable public Widget getWidget()
null
.@Nullable public Widget getWidgetAt(int x, int y)
If this desktop does not contains(x, y)
, null
is returned. The position is considered
here as a relative position to the desktop.
x
- x coordinate.y
- y coordinate.null
if no widget is found in this desktop hierarchy.Widget.getWidgetAt(int, int)
public boolean handleEvent(int event)
event
- the event to handle.true
if the event is consumed, false
otherwise.Event
public boolean isAttached()
When the desktop is attached, that means that it is ready to be displayed (shown on a display or drawn in an image).
true
if this desktop is attached, false
otherwise.public boolean isShown()
Calling this method is equivalent to calling Display.getDisplay().isShown(desktop);
.
true
if the desktop is currently visible, false
otherwise.protected void onHidden()
onHidden
in class Displayable
setDetached()
protected void onShown()
onShown
in class Displayable
setAttached()
protected void render(GraphicsContext g)
Renders its child widget entirely.
render
in class Displayable
g
- the graphics context of the display.public void renderWidget(GraphicsContext g, Widget 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.
g
- the graphics context to use to draw the widget.widget
- the widget to render.public void requestHide()
Calling this method is equivalent to calling Display.getDisplay().requestHide(desktop);
.
public void requestLayOut()
The lay out is done asynchronously, therefore this method returns immediately.
Nothing is done if the desktop is not shown.
Notifies its child widget that it is shown.
public void requestRender()
Displayable
Displayable.render(GraphicsContext)
on the displayable.
The call to Displayable.render(GraphicsContext)
occurs asynchronously to this call. That is, this method will not
block waiting for Displayable.render(GraphicsContext)
to finish. After render action (after call to
Displayable.render(GraphicsContext)
), a call to Display.flush()
is synchronously performed.
This call may have no effect under certain conditions:
Display.isShown(Displayable)
): the request is
refused.Display.requestShow(Displayable)
has been performed with another displayable): the request is abandoned
(this displayable is no longer the current displayable).requestRender
in class Displayable
public void requestShow()
Calling this method is equivalent to calling Display.getDisplay().requestShow(desktop);
.
SecurityException
- if a security manager exists and does not allow the caller to get the display.public void setAttached()
Every widget in its hierarchy is attached and a layout is performed.
isAttached()
,
Widget.onAttached()
public void setDetached()
Every widget in its hierarchy is detached.
isAttached()
,
Widget.onDetached()
public void setStylesheet(Stylesheet stylesheet)
stylesheet
- the stylesheet instance.public void setWidget(@Nullable Widget widget)
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.
widget
- the widget.IllegalArgumentException
- if the specified widget is already attached.