Class WImage


  • public class WImage
    extends WInteractWidget
    A widget that displays an image.

    The image may be specified either as a URL, or may be dynamically generated by a WResource.

    You may listen to events by attaching event listeners to signals such as WInteractWidget.clicked(). Since mouse events pass the coordinates through a WMouseEvent object, it is possible to react to clicks in specific parts of the image. An alternative is to define interactive areas on the image using addArea(), which in addition allows to have customized tool tips for certain image areas (using WAbstractArea#setToolTip()).

    WImage is an inline widget.

    CSS

    The widget corresponds to the HTML <img> tag and does not provide styling. It can be styled using inline or external CSS as appropriate.

    See Also:
    WResource, WPaintedWidget
    • Constructor Detail

      • WImage

        public WImage​(WContainerWidget parentContainer)
        Creates an empty image widget.
      • WImage

        public WImage​(WLink link,
                      WContainerWidget parentContainer)
        Creates an image widget with a given image link.

        The imageLink may link to a URL or resource.

      • WImage

        public WImage​(WLink link,
                      java.lang.CharSequence altText,
                      WContainerWidget parentContainer)
        Creates an image widget with a given image link and alternate text.

        The imageLink may link to a URL or resource.

    • Method Detail

      • setAlternateText

        public void setAlternateText​(java.lang.CharSequence text)
        Sets an alternate text.

        The alternate text should provide a fallback for browsers that do not display an image. If no sensible fallback text can be provided, an empty text is preferred over nonsense.

        This should not be confused with WWebWidget.getToolTip() text, which provides additional information that is displayed when the mouse hovers over the image.

        The default alternate text is an empty text ("").

        See Also:
        getAlternateText()
      • setImageLink

        public void setImageLink​(WLink link)
        Sets the image link.

        The image may be specified as a URL or as a resource. A resource specifies application-dependent content, which may be used to generate an image on demand.

      • getImageLink

        public WLink getImageLink()
        Returns the image link.
      • setAlternativeBotUrl

        public void setAlternativeBotUrl​(java.lang.String url)
        Sets an alternative URL, given to bots, for this image.

        If url is not empty, this URL will be used instead of the regular URL when the request comes from a bot (e.g., a web crawler).

        By default, this is empty.

      • getAlternativeBotUrl

        public java.lang.String getAlternativeBotUrl()
        Returns the alternative URL, given to bots, for this image.

        See Also:
        setAlternativeBotUrl(String url)
      • addArea

        public void addArea​(WAbstractArea area)
        Adds an interactive area.

        Adds the area which listens to events in a specific region of the image. Areas are organized in an indexed list, to which the given area is appended. When areas overlap, the area with the lowest index receives the event.

        Ownership of the area is transferred to the image.

        Note: Currently it is not possible to add a first area after the image has been rendered. If you want to use interactive areas you need to add one immediately.

      • removeArea

        public WAbstractArea removeArea​(WAbstractArea area)
        Removes an interactive area.

        Removes the area from this widget.

      • getArea

        public WAbstractArea getArea​(int index)
        Returns the interactive area at the given index.

        Returns null if index was invalid.

      • imageLoaded

        public EventSignal imageLoaded()
        Event emitted when the image was loaded.
      • setTargetJS

        public void setTargetJS​(java.lang.String targetJS)
      • getUpdateAreasJS

        public java.lang.String getUpdateAreasJS()
      • getSetAreaCoordsJS

        public java.lang.String getSetAreaCoordsJS()
      • getDomChanges

        protected void getDomChanges​(java.util.List<DomElement> result,
                                     WApplication app)
        Description copied from class: WWebWidget
        Get DOM changes for this widget.

        This is an internal function, and should not be called directly, or be overridden!

        Overrides:
        getDomChanges in class WWebWidget
      • defineJavaScript

        protected void defineJavaScript()
      • render

        protected void render​(java.util.EnumSet<RenderFlag> flags)
        Description copied from class: WWidget
        Renders the widget.

        This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

        The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

        Overrides:
        render in class WInteractWidget
      • getUpdateAreaCoordsJSON

        protected java.lang.String getUpdateAreaCoordsJSON()