Class ImageWidget
- java.lang.Object
-
- ej.mwt.Widget
-
- ej.widget.basic.ImageWidget
-
- Direct Known Subclasses:
ImageButton
public class ImageWidget extends Widget
A widget that displays a resource image.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ej.mwt.Widget
Widget.WidgetListener
-
-
Field Summary
-
Fields inherited from class ej.mwt.Widget
DEBUG_WIDGET_ENABLED_CONSTANT, DEBUG_WIDGET_MONITOR_CONSTANT, NO_CONSTRAINT
-
-
Constructor Summary
Constructors Modifier Constructor Description ImageWidget(String imagePath)Creates an image widget with the resource path of the image to display.protectedImageWidget(String imagePath, boolean enabled)Creates an image widget with the resource path of the image to display and its enabled state.ImageWidget(String imagePath, ResourceImage.OutputFormat outputFormat)Creates an image widget with the resource path of the image to display.protectedImageWidget(String imagePath, ResourceImage.OutputFormat outputFormat, boolean enabled)Creates an image widget with the resource path of the image to display and its enabled state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomputeContentOptimalSize(Size size)Computes the optimal size of the widget.protected voidonAttached()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 voidonDetached()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 voidrenderContent(GraphicsContext g, int contentWidth, int contentHeight)Renders the content of the widget without the border, margin and padding specified in the style.voidsetImagePath(String imagePath)Sets the image path.-
Methods inherited from class ej.mwt.Widget
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, setX, setY, updateStyle
-
-
-
-
Constructor Detail
-
ImageWidget
public ImageWidget(String imagePath)
Creates an image widget with the resource path of the image to display.- Parameters:
imagePath- the resource path of the image to display.- Throws:
IllegalArgumentException- if the image cannot be loaded.- See Also:
ResourceImage.canLoadImage(String)
-
ImageWidget
public ImageWidget(String imagePath, ResourceImage.OutputFormat outputFormat)
Creates an image widget with the resource path of the image to display.- Parameters:
imagePath- the resource path of the image to display.outputFormat- the output format of the image to display.- Throws:
IllegalArgumentException- if the image cannot be loaded.- See Also:
ResourceImage.canLoadImage(String)
-
ImageWidget
protected ImageWidget(String imagePath, boolean enabled)
Creates an image widget with the resource path of the image to display and its enabled state.- Parameters:
imagePath- the resource path of the image to display.enabled-trueif this image widget is to be enabled,falseotherwise.- Throws:
IllegalArgumentException- if the image cannot be loaded.- See Also:
ResourceImage.canLoadImage(String)
-
ImageWidget
protected ImageWidget(String imagePath, ResourceImage.OutputFormat outputFormat, boolean enabled)
Creates an image widget with the resource path of the image to display and its enabled state.- Parameters:
imagePath- the resource path of the image to display.outputFormat- the output format of the image to display.enabled-trueif this image widget is to be enabled,falseotherwise.- Throws:
IllegalArgumentException- if the image cannot be loaded.- See Also:
ResourceImage.canLoadImage(String)
-
-
Method Detail
-
onAttached
protected void onAttached()
Description copied from class:WidgetThis method is called as soon as:- the widget is attached to a desktop that is attached,
- the desktop of the widget is attached.
After this call, the widget is ready to be rendered.
For example, the widget can allocate some resources useful to render it.
- Overrides:
onAttachedin classWidget- See Also:
Desktop.setAttached()
-
onDetached
protected void onDetached()
Description copied from class:WidgetThis method is called as soon as:- the widget is detached from a desktop that is attached,
- the desktop of the widget is detached.
After this call, the resources allocated to render the widget must be disposed.
- Overrides:
onDetachedin classWidget- See Also:
Desktop.setDetached()
-
setImagePath
public void setImagePath(String imagePath)
Sets the image path.- Parameters:
imagePath- the resource path of the image to display.- Throws:
IllegalArgumentException- if the image cannot be loaded.- See Also:
ResourceImage.canLoadImage(String)
-
renderContent
protected void renderContent(GraphicsContext g, int contentWidth, int contentHeight)
Description copied from class:WidgetRenders the content of the widget without the border, margin and padding specified in the style.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).
- Specified by:
renderContentin classWidget- Parameters:
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.
-
computeContentOptimalSize
protected void computeContentOptimalSize(Size size)
Description copied from class:WidgetComputes the optimal size of the 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_CONSTRAINTmeans that there is no constraint on this dimension.The given size is modified to set the optimal size.
- Specified by:
computeContentOptimalSizein classWidget- Parameters:
size- the size available for the content.
-
-