public class Panel extends java.lang.Object implements Renderable
Constructor and Description |
---|
Panel()
Creates a new panel.
|
Modifier and Type | Method and Description |
---|---|
void |
becameActive()
Notifies the panel that it is now the active panel of its desktop.
|
void |
becameInactive()
Notifies the panel that it is no longer the active panel of its desktop.
|
boolean |
contains(int x,
int y)
Gets whether or not a location (x,y) is in the panel's bounds.
|
Desktop |
getDesktop()
Gets the desktop on which the panel is shown.
|
EventHandler |
getEventHandler()
Gets the event handler.
|
Widget |
getFocus()
Gets the widget that is the focus owner of this panel.
|
int |
getHeight()
Gets the height of this renderable.
|
int |
getPreferredHeight()
Returns the preferred height of the panel.
|
int |
getPreferredWidth()
Returns the preferred width of the panel.
|
Widget |
getWidget()
Gets the widget attached to this panel.
|
Widget |
getWidgetAt(int x,
int y)
Returns the child widget at the specified location.
|
int |
getWidth()
Gets the width of this renderable.
|
int |
getX()
Gets the x coordinate of this renderable, relative to its parent.
|
int |
getY()
Gets the y coordinate of this renderable, relative to its parent.
|
boolean |
handleEvent(int event)
Called by the system if this is the active panel and if no widget in the hierarchy of the focused widget has
consumed the event.
|
void |
hide()
Requests the panel be hidden.
|
void |
hideNotify()
This method is called as soon as the renderable is hidden.
|
void |
invalidate()
Declares that this panel needs to be laid out.
|
boolean |
isActive()
Gets whether or not the panel is the active one on its desktop.
|
boolean |
isAdjustedToChild()
Gets whether this panel is adjusted to its child or not.
|
boolean |
isPacked()
Deprecated.
|
boolean |
isShown()
Gets whether or not the panel is shown on a shown desktop.
|
boolean |
isTransparent()
Gets whether this panel is transparent or not.
|
boolean |
isValid()
Gets whether this panel is valid.
|
void |
render(GraphicsContext g)
Renders the renderable on the given graphics context.
|
void |
repaint()
Requests a repaint of this entire panel.
|
void |
repaint(int x,
int y,
int width,
int height)
Requests a repaint of a zone of this panel.
|
void |
revalidate()
Lays out all the hierarchy of this panel.
|
void |
setBounds(int x,
int y,
int width,
int height)
Sets the bounds of this panel.
|
void |
setEventHandler(EventHandler eventHandler)
Sets the event handler.
|
void |
setFocus(Widget widget)
Sets the specified widget as the current focus owner of this panel.
|
void |
setLocation(int x,
int y)
Sets the location of this panel.
|
void |
setPacked(boolean packed)
Deprecated.
|
void |
setPreferredSize(int preferredWidth,
int preferredHeight)
Sets the preferred size of the panel.
|
void |
setSize(int width,
int height)
Sets the size of this panel.
|
void |
setWidget(Widget widget)
Attach the specified widget to this panel.
|
void |
show(Desktop desktop)
Deprecated.
Use
showAdjustingToChild(Desktop) instead. |
void |
show(Desktop desktop,
boolean fill)
Deprecated.
Use
showAdjustingToChild(Desktop) or showFullScreen(Desktop) instead. |
void |
showAdjustingToChild(Desktop desktop)
Requests the panel to be shown on the specified desktop.
|
void |
showFullScreen(Desktop desktop)
Requests the panel to be shown on the specified desktop.
|
protected void |
showInternal(Desktop desktop)
Adds the panel to the desktop and validate it asynchronously.
|
void |
showNotify()
This method is called as soon as the renderable is visible.
|
void |
showUsingBounds(Desktop desktop)
Requests the panel to be shown on the specified desktop.
|
void |
validate()
Lays out all the hierarchy of this panel.
|
void |
validate(int widthHint,
int heightHint)
Lays out all the hierarchy of this panel.
|
public Panel()
By default:
0
,public void setWidget(@Nullable Widget widget) throws java.lang.IllegalArgumentException
If there is already a widget on this panel, the former is detached from the latter.
If the specified widget is null
, the panel does not hold a widget anymore.
The panel is also ask to be revalidated if shown.
widget
- the widget to set.java.lang.IllegalArgumentException
- if the specified widget is already in a hierarchy (already contained in a composite or panel).revalidate()
,
Composite.add(Widget)
@Nullable public Widget getWidget()
null
.public void setLocation(int x, int y)
x
- the x coordinate to set.y
- the y coordinate to set.public void setSize(int width, int height)
width
- the width to set.height
- the height to set.public void setBounds(int x, int y, int width, int height)
x
- the x coordinate to set.y
- the y coordinate to set.width
- the width to set.height
- the height to set.public int getPreferredWidth()
isValid()
is
true
or if setPreferredSize(int, int)
has been called explicitly.public int getPreferredHeight()
isValid()
is
true
or if setPreferredSize(int, int)
has been called explicitly.public void setPreferredSize(int preferredWidth, int preferredHeight)
preferredWidth
- the width to set.preferredHeight
- the height to set.public int getX()
Renderable
getX
in interface Renderable
public int getY()
Renderable
getY
in interface Renderable
public int getWidth()
Renderable
getWidth
in interface Renderable
public int getHeight()
Renderable
getHeight
in interface Renderable
@Deprecated public void show(Desktop desktop) throws java.lang.NullPointerException
showAdjustingToChild(Desktop)
instead.
Identical to calling show(Desktop, boolean)
without filling the desktop.
desktop
- the desktopjava.lang.NullPointerException
- if desktop
is null
.show(Desktop, boolean)
,
hide()
,
isShown()
,
revalidate()
@Deprecated public void show(Desktop desktop, boolean fill) throws java.lang.NullPointerException
showAdjustingToChild(Desktop)
or showFullScreen(Desktop)
instead.
If fill
is true
, it is fitted to desktop size and it will be declared as not be packed.
If fill
is false
and no size has been set, it will be declared as packed.
If the desktop is shown, the panel is automatically validated.
The panel is added to the list of panels known by the desktop.
Special cases:
desktop
- the desktop.fill
- true
to fit the panel to the desktop size, false
otherwise.java.lang.NullPointerException
- if desktop
is null
.hide()
,
isShown()
,
revalidate()
public void showFullScreen(@NonNull Desktop desktop) throws java.lang.NullPointerException
The panel is fitted to desktop size.
If the desktop is shown, the panel is automatically validated.
The panel is added to the list of panels known by the desktop.
If the panel is already shown on another desktop, it is hidden on this desktop before being shown on the new
desktop
- the desktopjava.lang.NullPointerException
- if the given desktop is null
.hide()
,
isShown()
,
revalidate()
public void showAdjustingToChild(@NonNull Desktop desktop) throws java.lang.NullPointerException
The panel is fitted to its child widget size. If a location has been set, it is kept.
If the desktop is shown, the panel is automatically validated.
The panel is added to the list of panels known by the desktop.
If the panel is already shown on another desktop, it is hidden on this desktop before being shown on the new
desktop
- the desktopjava.lang.NullPointerException
- if the given desktop is null
.setLocation(int, int)
,
hide()
,
isShown()
,
revalidate()
public void showUsingBounds(@NonNull Desktop desktop) throws java.lang.NullPointerException
The bounds of the panel remains unchanged and must be set with setBounds(int, int, int, int)
before.
If the desktop is shown, the panel is automatically validated.
The panel is added to the list of panels known by the desktop.
If the panel is already shown on another desktop, it is hidden on this desktop before being shown on the new
desktop
- the desktopjava.lang.NullPointerException
- if the given desktop is null
.setBounds(int, int, int, int)
,
hide()
,
isShown()
,
revalidate()
protected void showInternal(@NonNull Desktop desktop)
desktop
- the desktop to show the panel on.public void showNotify()
Notifies its child widget that it is shown.
showNotify
in interface Renderable
public void hideNotify()
Notifies its child widget that it is hidden.
hideNotify
in interface Renderable
public void hide()
The panel is invalidated.
The panel is removed from the list of panels known by the desktop.
public boolean isShown()
isShown
in interface Renderable
true
if the panel is shown, false
otherwise.getDesktop()
,
Renderable.isShown()
public boolean isActive()
false
.true
if the panel is the active one, false
otherwise.isShown()
public void becameActive()
public void becameInactive()
@Nullable public Desktop getDesktop()
null
if the panel is not shown.null
.isShown()
public void repaint()
If the panel is not shown, nothing is done.
repaint
in interface Renderable
public void repaint(int x, int y, int width, int height)
If the panel is not shown, nothing is done.
repaint
in interface Renderable
x
- the relative x coordinate of the area to repaint.y
- the relative y coordinate of the area to repaint.width
- the width of the area to repaint.height
- the height of the area to repaint.public void render(GraphicsContext g)
Renderable
render
in interface Renderable
g
- the graphics context to be used to draw the renderable.public boolean isTransparent()
By default, a panel is transparent.
A transparent panel means that it will not repaint ALL the rectangular zone defined by its bounds. Then each time it needs to be repainted, its parent (recursively if also transparent) will be repainted within the bounds of the panel.
Each time a non-transparent panel needs to be repainted, it is the only one to be repainted.
true
if this panel is transparent, false
otherwise.contains(int, int)
public boolean contains(int x, int y)
The given location is considered here as a relative location to the desktop.
x
- x coordinate.y
- y coordinate.true
if the (x,y) location is in the panel bounds, false
otherwise.isTransparent()
@Nullable public Widget getWidgetAt(int x, int y)
If this panel does not contains(x, y)
, null
is returned. The location is considered
here as a relative location to the desktop.
x
- x coordinate.y
- y coordinate.null
if no widget is found in this panel hierarchy.Widget.getWidgetAt(int, int)
public void setFocus(@Nullable Widget widget) throws java.lang.IllegalArgumentException
If the widget is not enabled, nothing is done.
If the widget already own the focus, nothing is done.
Throws an IllegalArgumentException
if the specified widget is not in the panel.
widget
- the widget to focus.java.lang.IllegalArgumentException
- if the specified widget is not in the panel.public Widget getFocus()
null
.@Deprecated public void setPacked(boolean packed)
This property is used when the panel is validated: if it is packed (specified boolean is true
), the
panel is resized to the preferred size of its widgets, otherwise its widgets fill its size.
packed
- true
to pack the panel, false
otherwise.revalidate()
,
setSize(int, int)
@Deprecated public boolean isPacked()
true
if this panel is packed, false
otherwise.public boolean isAdjustedToChild()
true
if this panel is adjusted to its child, false
otherwise.showAdjustingToChild(Desktop)
public void invalidate()
revalidate()
,
validate()
public boolean isValid()
A panel is valid if its contents are correctly laid out.
true
if this panel is valid, false
otherwise.invalidate()
,
validate()
public void revalidate()
It performs the method validate()
asynchronously. Therefore this method does not block until the
validation of the hierarchy is done.
Nothing is done if the panel is already valid.
The panel is not validated if it is not shown or if its desktop is not shown.
invalidate()
public void validate()
Nothing is done if the panel is already valid.
The panel is repainted if it is shown on a desktop.
If the panel is declared as packed, it is resized to the preferred size of its widgets, otherwise its widgets fill its size.
isPacked()
,
isValid()
public void validate(int widthHint, int heightHint)
After this call the preferred size will have been established. The parameters defines the maximum size available
for this panel, or MWT.NONE
if there is no constraint.
public void setEventHandler(@Nullable EventHandler eventHandler)
Renderable
setEventHandler
in interface Renderable
eventHandler
- the event handler to set.Renderable.handleEvent(int)
@Nullable public EventHandler getEventHandler()
Renderable
getEventHandler
in interface Renderable
Renderable.handleEvent(int)
public boolean handleEvent(int event)
Command#UP
, Command#DOWN
, Command#LEFT
, and
Command#RIGHT
commands to manage navigation.handleEvent
in interface Renderable
event
- the event to handle.true
if the panel has consumed the event, false
otherwise.