Class WVirtualImage


public class WVirtualImage extends WCompositeWidget
An abstract widget that shows a viewport to a virtually large image.

WVirtualImage is an abstract class which renders a large image in small pieces. The large image is broken down, and rendered as a grid of smaller square images parts.

The WVirtualImage may provide interactive navigation using the mouse, by reacting to dragging of the mouse on the image.

The WVirtualImage renders pieces in and bordering the current viewport. In this way, provided the individual pieces load sufficiently fast, the user has effectively the impression of scrolling through a single large image, without glitches. Whenever the image is navigated, if necessary, new images are rendered to maintain the border. Images that are too far from the current viewport are pruned away, so that browser memory remains bounded.

To use this class, you must reimplement one of two virtual methods to specify the contents of each grid piece. Either you provide a suitable WImage for every grid piece, or you provide a WResource which renders the contents for a WImage for every grid piece.

The total image dimensions are (0, 0) to (imageWidth, imageHeight) for a finite image, and become unbounded (including negative numbers) for each dimension which is Infinite.

CSS

Styling through CSS is not applicable.

  • Field Details

    • Infinite

      public static final long Infinite
      Special value for imageWidth or imageHeight.
      See Also:
  • Constructor Details

    • WVirtualImage

      public WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight, int gridImageSize, WContainerWidget parentContainer)
      Creates a viewport for a virtual image.

      You must specify the size of the viewport, and the size of the virtual image. The latter dimensions may be the special value Infinite, indicating that in one or more dimensions, the image size is infinite (in practice limited by the maximum integer value).

      In addition, you must specify the size of each square grid item. The default is 256 by 256.

    • WVirtualImage

      public WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight)
    • WVirtualImage

      public WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight, int gridImageSize)
  • Method Details

    • remove

      public void remove()
      Destructor.
      Overrides:
      remove in class WCompositeWidget
      See Also:
    • redrawAll

      public void redrawAll()
      Regenerates and redraws the image pieces.

      This method invalidates all current grid images, and recreates them.

    • enableDragging

      public void enableDragging()
      Enables mouse dragging to scroll around the image.

      The cursor is changed to a 'move' symbol to indicate the interactivity.

    • scroll

      public void scroll(long dx, long dy)
      Scrolls the viewport of the image over a distance.

      See Also:
    • scrollTo

      public void scrollTo(long newX, long newY)
      Scrolls the viewport of the image to a specific coordinate.

      Scroll the viewport so that its top left coordinate becomes (x, y).

      See Also:
    • getImageWidth

      public long getImageWidth()
      Returns the virtual image width.

      See Also:
    • getImageHeight

      public long getImageHeight()
      Returns the virtual image height.

      See Also:
    • resizeImage

      public void resizeImage(long w, long h)
      Resizes the virtual image.

      This sets a new virtual size for the image. The viewport size sets the visible portion of the image.

      See Also:
    • getViewPortWidth

      public int getViewPortWidth()
      Returns the viewport width.

      See Also:
    • getViewPortHeight

      public int getViewPortHeight()
      Returns the viewport height.

      See Also:
    • getGridImageSize

      public int getGridImageSize()
      Returns the size of a single piece.

      This is the size of a side of the square pieces that is used to render the visible part of the image.

    • getCurrentTopLeftX

      public long getCurrentTopLeftX()
      Returns the current top left X coordinate.

      See Also:
    • getCurrentTopLeftY

      public long getCurrentTopLeftY()
      Returns the current top left Y coordinate.

      See Also:
    • getCurrentBottomRightX

      public long getCurrentBottomRightX()
      Returns the current bottom right X coordinate.

      See Also:
    • getCurrentBottomRightY

      public long getCurrentBottomRightY()
      Returns the current bottom right Y coordinate.

      See Also:
    • viewPortChanged

      public Signal2<Long,Long> viewPortChanged()
      Signal emitted whenever the viewport changes.

      The viewport can be changed by the user dragging the image or through the API methods scrollTo() and scroll().

    • createImage

      protected WImage createImage(long x, long y, int width, int height)
      Creates a grid image for the given rectangle.

      Create the image which spans image coordinates with left upper corner (x, y) and given width and height.

      Width and height will not necesarilly equal getGridImageSize(), if the the image is not infinite sized.

      The default implementation calls render() and creates an image for the resource returned.

      You should override this method if you wish to serve for example static image content.

    • render

      protected WResource render(long x, long y, int width, int height)
      Render a grid image for the given rectangle.

      Returns a resource that streams an image which renders the rectangle which spans image coordinates with left upper corner (x, y) and given width and height.

      Width and height will not necesarilly equal to getGridImageSize(), if the the image is not infinite sized.

      The default implementation throws an Exception. You must reimplement this method unless you reimplement createImage().

      See Also: