Class 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.

    • Constructor Detail

      • 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 - true if this image widget is to be enabled, false otherwise.
        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 - true if this image widget is to be enabled, false otherwise.
        Throws:
        IllegalArgumentException - if the image cannot be loaded.
        See Also:
        ResourceImage.canLoadImage(String)
    • Method Detail

      • onAttached

        protected void onAttached()
        Description copied from class: Widget
        This 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:
        onAttached in class Widget
        See Also:
        Desktop.setAttached()
      • onDetached

        protected void onDetached()
        Description copied from class: Widget
        This 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:
        onDetached in class Widget
        See Also:
        Desktop.setDetached()
      • renderContent

        protected void renderContent​(GraphicsContext g,
                                     int contentWidth,
                                     int contentHeight)
        Description copied from class: Widget
        Renders 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:
        renderContent in class Widget
        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: Widget
        Computes 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_CONSTRAINT means that there is no constraint on this dimension.

        The given size is modified to set the optimal size.

        Specified by:
        computeContentOptimalSize in class Widget
        Parameters:
        size - the size available for the content.