eu.webtoolkit.jwt
Class WRasterPaintDevice

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WResource
          extended by eu.webtoolkit.jwt.WRasterPaintDevice
All Implemented Interfaces:
WPaintDevice

public class WRasterPaintDevice
extends WResource
implements WPaintDevice


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WResource
WResource.DispositionType
 
Nested classes/interfaces inherited from interface eu.webtoolkit.jwt.WPaintDevice
WPaintDevice.ChangeFlag, WPaintDevice.FeatureFlag
 
Constructor Summary
WRasterPaintDevice(java.lang.String format, WLength width, WLength height)
           
 
Method Summary
 void clear()
          Clears the image (resets the background to solid white).
static java.awt.Color createColor(WColor color)
          Converts a jwt.WColor to an awt.Color
static java.awt.Shape createShape(WPainterPath path)
          Converts a jwt.WPainterPath to an awt.Shape
static java.awt.Stroke createStroke(WPainter painter, WPen pen)
          converts a jwt.WPen to an awt.Stroke
 void done()
          Finishes painting on the device.
 void drawArc(WRectF rect, double startAngle, double spanAngle)
          Draws an arc.
 void drawImage(WRectF rect, java.lang.String imageUri, int imgWidth, int imgHeight, WRectF sourceRect)
          Draws an image.
 void drawLine(double x1, double y1, double x2, double y2)
          Draws a line.
 void drawPath(WPainterPath path)
          Draws a path.
 void drawText(WRectF rect, java.util.EnumSet<AlignmentFlag> flags, TextFlag textFlag, java.lang.CharSequence text)
          Draws text.
 java.util.EnumSet<WPaintDevice.FeatureFlag> getFeatures()
          Returns device features.
 WFontMetrics getFontMetrics()
          Returns font metrics.
 WLength getHeight()
          Returns the device height.
 WPainter getPainter()
          Returns the painter that is currently painting on the device.
 WLength getWidth()
          Returns the device width.
protected  void handleRequest(WebRequest request, WebResponse response)
          Handles a request.
 void init()
          Initializes the device for painting.
 boolean isPaintActive()
          Returns whether painting is active.
 WTextItem measureText(java.lang.CharSequence text)
          Measures rendered text size.
 WTextItem measureText(java.lang.CharSequence text, double maxWidth)
          Measures rendered text size.
 WTextItem measureText(java.lang.CharSequence text, double maxWidth, boolean wordWrap)
          Measures rendered text size.
 void setChanged(java.util.EnumSet<WPaintDevice.ChangeFlag> flags)
          Indicates changes in painter state.
 void setChanged(WPaintDevice.ChangeFlag flag, WPaintDevice.ChangeFlag... flags)
          Indicates changes in painter state.
 void setPainter(WPainter painter)
          Sets the painter.
 
Methods inherited from class eu.webtoolkit.jwt.WResource
dataChanged, dataReceived, generateUrl, getDispositionType, getInternalPath, getSuggestedFileName, getUrl, setChanged, setDispositionType, setInternalPath, setUploadProgress, suggestFileName, suggestFileName, write, write
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WRasterPaintDevice

public WRasterPaintDevice(java.lang.String format,
                          WLength width,
                          WLength height)
Method Detail

handleRequest

protected void handleRequest(WebRequest request,
                             WebResponse response)
                      throws java.io.IOException
Description copied from class: WResource
Handles a request.

Reimplement this method so that a proper response is generated for the given request. From the request object you can access request parameters and whether the request is a continuation request. In the response object, you should set the mime type and stream the output data.

Specified by:
handleRequest in class WResource
Parameters:
request - The request information
response - The response object
Throws:
java.io.IOException

done

public void done()
Description copied from interface: WPaintDevice
Finishes painting on the device.

This method is called when a WPainter stopped painting.

Specified by:
done in interface WPaintDevice
See Also:
WPainter.end()

drawArc

public void drawArc(WRectF rect,
                    double startAngle,
                    double spanAngle)
Description copied from interface: WPaintDevice
Draws an arc.

The arc is defined as in WPainter#drawArc()

The arc must be stroked, filled, and transformed using the current painter settings.

Specified by:
drawArc in interface WPaintDevice

drawImage

public void drawImage(WRectF rect,
                      java.lang.String imageUri,
                      int imgWidth,
                      int imgHeight,
                      WRectF sourceRect)
Description copied from interface: WPaintDevice
Draws an image.

Draws sourceRect from the image with URL imageUri and original dimensions imgWidth and imgHeight to the location, into the rectangle defined by rect.

The image is transformed using the current painter settings.

Specified by:
drawImage in interface WPaintDevice

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Description copied from interface: WPaintDevice
Draws a line.

The line must be stroked and transformed using the current painter settings.

Specified by:
drawLine in interface WPaintDevice

drawPath

public void drawPath(WPainterPath path)
Description copied from interface: WPaintDevice
Draws a path.

The path must be stroked, filled, and transformed using the current painter settings.

Specified by:
drawPath in interface WPaintDevice

createShape

public static java.awt.Shape createShape(WPainterPath path)
Converts a jwt.WPainterPath to an awt.Shape

Parameters:
path -
Returns:
a shape that represents the path

drawText

public void drawText(WRectF rect,
                     java.util.EnumSet<AlignmentFlag> flags,
                     TextFlag textFlag,
                     java.lang.CharSequence text)
Description copied from interface: WPaintDevice
Draws text.

The text must be rendered, stroked and transformed using the current painter settings.

Specified by:
drawText in interface WPaintDevice

getHeight

public WLength getHeight()
Description copied from interface: WPaintDevice
Returns the device height.

The device height, in pixels, establishes the height of the device coordinate system.

Specified by:
getHeight in interface WPaintDevice

getPainter

public WPainter getPainter()
Description copied from interface: WPaintDevice
Returns the painter that is currently painting on the device.

Specified by:
getPainter in interface WPaintDevice
See Also:
WPaintDevice.init()

getWidth

public WLength getWidth()
Description copied from interface: WPaintDevice
Returns the device width.

The device width, in pixels, establishes the width of the device coordinate system.

Specified by:
getWidth in interface WPaintDevice

init

public void init()
Description copied from interface: WPaintDevice
Initializes the device for painting.

This method is called when a WPainter starts painting.

Specified by:
init in interface WPaintDevice
See Also:
WPainter.begin(WPaintDevice device), WPaintDevice.getPainter()

isPaintActive

public boolean isPaintActive()
Description copied from interface: WPaintDevice
Returns whether painting is active.

Specified by:
isPaintActive in interface WPaintDevice
See Also:
WPaintDevice.init(), WPaintDevice.getPainter()

setChanged

public void setChanged(java.util.EnumSet<WPaintDevice.ChangeFlag> flags)
Description copied from interface: WPaintDevice
Indicates changes in painter state.

The flags argument is the logical OR of one or more change flags.

Specified by:
setChanged in interface WPaintDevice
See Also:
WPaintDevice.ChangeFlag

setChanged

public void setChanged(WPaintDevice.ChangeFlag flag,
                       WPaintDevice.ChangeFlag... flags)
Description copied from interface: WPaintDevice
Indicates changes in painter state.

Calls setChanged(EnumSet.of(flag, flags))

Specified by:
setChanged in interface WPaintDevice

setPainter

public void setPainter(WPainter painter)
Description copied from interface: WPaintDevice
Sets the painter.

Specified by:
setPainter in interface WPaintDevice

createColor

public static java.awt.Color createColor(WColor color)
Converts a jwt.WColor to an awt.Color

Parameters:
color - the JWt color
Returns:
the corresponding AWT color

createStroke

public static java.awt.Stroke createStroke(WPainter painter,
                                           WPen pen)
converts a jwt.WPen to an awt.Stroke

Parameters:
painter - the painter used to take into account transformations for the pen width
pen - the JWt pen
Returns:
the corresponding AWT Stroke

clear

public void clear()
Clears the image (resets the background to solid white).


getFontMetrics

public WFontMetrics getFontMetrics()
Description copied from interface: WPaintDevice
Returns font metrics.

This returns font metrics for the current font.

Throws a std::logic_error if the underlying device does not provide font metrics.

Specified by:
getFontMetrics in interface WPaintDevice

measureText

public WTextItem measureText(java.lang.CharSequence text,
                             double maxWidth,
                             boolean wordWrap)
Description copied from interface: WPaintDevice
Measures rendered text size.

Returns the bounding rect of the given text when rendered using the current font.

If maxWidth != -1, then the text is truncated to fit in the width.

If wordWrap = true then text is truncated only at word boundaries. Note that in this case the whitespace at the truncated position is included in the text but not accounted for by the returned width (since usually you will not render the whitespace at the end of a line).

Throws a std::logic_error if the underlying device does not provide font metrics.

Specified by:
measureText in interface WPaintDevice

measureText

public WTextItem measureText(java.lang.CharSequence text)
Description copied from interface: WPaintDevice
Measures rendered text size.

Returns measureText(text, - 1, false)

Specified by:
measureText in interface WPaintDevice

measureText

public WTextItem measureText(java.lang.CharSequence text,
                             double maxWidth)
Description copied from interface: WPaintDevice
Measures rendered text size.

Returns measureText(text, maxWidth, false)

Specified by:
measureText in interface WPaintDevice

getFeatures

public java.util.EnumSet<WPaintDevice.FeatureFlag> getFeatures()
Description copied from interface: WPaintDevice
Returns device features.

Specified by:
getFeatures in interface WPaintDevice