public class ImageWidget extends Widget
The widget holds a path to the image. The actual image is allocated only when the widget is attached. It is also closed when the widget is detached.
NO_CONSTRAINT
Constructor and Description |
---|
ImageWidget(String imagePath)
Creates an image widget with the resource path of the image to display.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeContentOptimalSize(Size size)
Computes the optimal size of the widget.
|
protected void |
onAttached()
This method is called as soon as:
the widget is attached to a desktop that is attached,
the desktop of the widget is attached.
|
protected void |
onDetached()
This method is called as soon as:
the widget is detached from a desktop that is attached,
the desktop of the widget is detached.
|
protected void |
renderContent(GraphicsContext g,
int contentWidth,
int contentHeight)
Renders the content of the widget without the border, margin and padding specified in the style.
|
void |
setImagePath(String imagePath)
Sets the image path.
|
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getContentBounds, getDesktop, getHeight, getParent, getStyle, getWidgetAt, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle, updateStyle
public ImageWidget(String imagePath)
imagePath
- the resource path of the image to display.IllegalArgumentException
- if the image cannot be loaded.ResourceImage.canLoadImage(String)
protected void computeContentOptimalSize(Size size)
Widget
This method does not consider the border, margin, padding and dimension specified in the style.
The given size is the available size for this widget in its parent. A width or a height equal to
Widget#NO_CONSTRAINT
means that there is no constraint on this dimension.
The given size is modified to set the optimal size.
computeContentOptimalSize
in class Widget
size
- the size available for the content.protected void onAttached()
Widget
After this call, the widget is ready to be rendered.
For example, the widget can allocate some resources useful to render it.
onAttached
in class Widget
Desktop.setAttached()
protected void onDetached()
Widget
After this call, the resources allocated to render the widget must be disposed.
onDetached
in class Widget
Desktop.setDetached()
protected void renderContent(GraphicsContext g, int contentWidth, int contentHeight)
Widget
The given graphics context is translated and clipped according to the given bounds (the border, margin and padding are applied on this graphics context before).
renderContent
in class Widget
g
- the graphics context where to render the content of the widget.contentWidth
- the width of the content area.contentHeight
- the height of the content area.public void setImagePath(String imagePath)
imagePath
- the resource path of the image to display.IllegalArgumentException
- if the image cannot be loaded.ResourceImage.canLoadImage(String)