eu.webtoolkit.jwt
Class WVirtualImage

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WWidget
          extended by eu.webtoolkit.jwt.WCompositeWidget
              extended by eu.webtoolkit.jwt.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 Summary
static long Infinite
          Special value for imageWidth or imageHeight.
 
Constructor Summary
WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight)
          Creates a viewport for a virtual image.
WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight, int gridImageSize)
          Creates a viewport for a virtual image.
WVirtualImage(int viewPortWidth, int viewPortHeight, long imageWidth, long imageHeight, int gridImageSize, WContainerWidget parent)
          Creates a viewport for a virtual image.
 
Method Summary
protected  WImage createImage(long x, long y, int width, int height)
          Creates a grid image for the given rectangle.
 void enableDragging()
          Enables mouse dragging to scroll around the image.
 long getCurrentBottomRightX()
          Returns the current bottom right X coordinate.
 long getCurrentBottomRightY()
          Returns the current bottom right Y coordinate.
 long getCurrentTopLeftX()
          Returns the current top left X coordinate.
 long getCurrentTopLeftY()
          Returns the current top left Y coordinate.
 int getGridImageSize()
          Returns the size of a single piece.
 long getImageHeight()
          Returns the virtual image height.
 long getImageWidth()
          Returns the virtual image width.
 int getViewPortHeight()
          Returns the viewport height.
 int getViewPortWidth()
          Returns the viewport width.
 void redrawAll()
          Regenerates and redraws the image pieces.
 void remove()
          Destructor.
protected  WResource render(long x, long y, int width, int height)
          Render a grid image for the given rectangle.
 void resizeImage(long w, long h)
          Resizes the virtual image.
 void scroll(long dx, long dy)
          Scrolls the viewport of the image over a distance.
 void scrollTo(long newX, long newY)
          Scrolls the viewport of the image to a specific coordinate.
 Signal2<java.lang.Long,java.lang.Long> viewPortChanged()
          Signal emitted whenever the viewport changes.
 
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, getAttributeValue, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isVisible, load, propagateSetEnabled, refresh, removeStyleClass, resize, setAttributeValue, setClearSides, setDecorationStyle, setDisabled, setFloatSide, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPopup, setPositionScheme, setSelectable, setStyleClass, setTabIndex, setToolTip, setVerticalAlignment
 
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, isRendered, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName, setObjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Infinite

public static final long Infinite
Special value for imageWidth or imageHeight.

See Also:
Constant Field Values
Constructor Detail

WVirtualImage

public WVirtualImage(int viewPortWidth,
                     int viewPortHeight,
                     long imageWidth,
                     long imageHeight,
                     int gridImageSize,
                     WContainerWidget parent)
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)
Creates a viewport for a virtual image.

Calls this(viewPortWidth, viewPortHeight, imageWidth, imageHeight, 256, (WContainerWidget)null)


WVirtualImage

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

Calls this(viewPortWidth, viewPortHeight, imageWidth, imageHeight, gridImageSize, (WContainerWidget)null)

Method Detail

remove

public void remove()
Destructor.

Overrides:
remove in class WCompositeWidget
See Also:
WContainerWidget.removeWidget(WWidget widget)

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(long newX, long newY)

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:
scroll(long dx, long dy)

getImageWidth

public long getImageWidth()
Returns the virtual image width.

See Also:
getImageHeight(), resizeImage(long w, long h)

getImageHeight

public long getImageHeight()
Returns the virtual image height.

See Also:
getImageWidth(), resizeImage(long w, long h)

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:
getImageWidth(), getImageHeight()

getViewPortWidth

public int getViewPortWidth()
Returns the viewport width.

See Also:
getViewPortHeight()

getViewPortHeight

public int getViewPortHeight()
Returns the viewport height.

See Also:
getViewPortWidth()

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()

getCurrentTopLeftY

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

See Also:
getCurrentTopLeftX()

getCurrentBottomRightX

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

See Also:
getCurrentBottomRightY()

getCurrentBottomRightY

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

See Also:
getCurrentBottomRightX()

viewPortChanged

public Signal2<java.lang.Long,java.lang.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.

See Also:
render(long x, long y, int width, int height)

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:
createImage(long x, long y, int width, int height)