|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
org.gwtwidgets.client.ui.canvas.Canvas
public abstract class Canvas
Abstract base class for canvas widgets. A canvas is a rectangular area which
can display vector graphics - scalable shapes such as lines, polygons and
images. There exist currently two implementations: the FFCanvasImpl
which runs on browsers which support the canvas widget and the
IECanvasImpl widget which emulates a canvas in Internet Explorer
through VML.
Canvas implementations have no public constructor, instead they are derived
from a CanvasFactory. The GWT compiler makes sure that
CanvasFactory returns the correct canvas implementation for each
browser.
Canvas instances are stateful, similar to a java Graphics
object. A stroke, filling, rotation etc. applied affects all subsequent
operations. Similar to a stream, a canvas must be flushed for the graphics
operations to become visible - the opposite does not hold; there is no
guarantee that graphics operations will not be visible without flushing.
The typical lifecycle of a canvas widget looks like:
Canvas canvas = Canvas.create(640,480); panel.add(canvas); ... canvas.clear(); ... canvas.setStroke(255,0,0,1); canvas.drawLine(0,0,100,100); ... canvas.flush();
Note that in order for the canvas to function in Internet Explorer, a special
namespace must be used on the HTML page and a special CSS style must be
included. For details please consult IECanvasImpl.
Some implementations may not allow you to draw shapes starting at greater coordinates
towards lower coordinates, i.e. drawRectangle(100,100,10,10) may fail on
certain browsers.
IECanvasImpl, FFCanvasImpl| Field Summary | |
|---|---|
protected double |
rotation
Rotation in radians. |
| Constructor Summary | |
|---|---|
Canvas()
|
|
| Method Summary | |
|---|---|
void |
addClickListener(com.google.gwt.user.client.ui.ClickListener listener)
|
void |
addFocusListener(com.google.gwt.user.client.ui.FocusListener listener)
|
void |
addKeyboardListener(com.google.gwt.user.client.ui.KeyboardListener listener)
|
void |
addMouseListener(com.google.gwt.user.client.ui.MouseListener listener)
|
void |
addMouseWheelListener(com.google.gwt.user.client.ui.MouseWheelListener listener)
|
abstract void |
clear()
Clears the canvas area and resets fill, stroke, strokeWeight, font and offset. |
static Canvas |
create(int width,
int height)
Return a suitable canvas for the browser the application is running in. |
static Font |
createBitmapFont(java.lang.String bitmapPath,
java.lang.String descriptionPath,
FontLoadListener listener)
Creates a Font object from a bitmap representation. |
abstract void |
drawArc(double centerLeft,
double centerTop,
double width,
double height,
double fromAngle,
double toAngle)
Draws an arc with the stroke as border and fills it with the current fill. |
abstract void |
drawImage(com.google.gwt.user.client.Element image,
double sx,
double sy,
double swidth,
double sheight,
double dx,
double dy,
double dwidth,
double dheight)
Draws an image. |
abstract void |
drawLine(double fromLeft,
double fromTop,
double toLeft,
double toTop)
Draws a line. |
abstract void |
drawPolygon(double[] x,
double[] y)
Draws a closed polygon with the current stroke as border and fills it with the current fill. |
abstract void |
drawPolyLine(double[] x,
double[] y)
Draws a consecutive line with the current stroke as border. |
abstract void |
drawRectangle(double left,
double top,
double width,
double height)
Draws a rectangle with the stroke as border and fills it with the current fill. |
abstract void |
drawText(java.lang.String text,
double x,
double y)
Draw Text. |
abstract void |
flush()
Makes all changes performed since the last flush visible. |
double |
getRotation()
Gets the currently set rotation |
void |
onBrowserEvent(com.google.gwt.user.client.Event event)
|
abstract com.google.gwt.user.client.Element |
prepareImage(com.google.gwt.user.client.Element image)
On some platforms, it is faster to use prepared images rather than the source image directly. |
void |
removeClickListener(com.google.gwt.user.client.ui.ClickListener listener)
|
void |
removeFocusListener(com.google.gwt.user.client.ui.FocusListener listener)
|
void |
removeKeyboardListener(com.google.gwt.user.client.ui.KeyboardListener listener)
|
void |
removeMouseListener(com.google.gwt.user.client.ui.MouseListener listener)
|
void |
removeMouseWheelListener(com.google.gwt.user.client.ui.MouseWheelListener listener)
|
abstract void |
setFill(int red,
int green,
int blue,
double alpha)
Applies a filling (interior) to surfaces. |
abstract void |
setFont(Font font)
Apply font to all following text drawings. |
abstract void |
setOffset(double left,
double top)
Apply offset to all following drawings. |
void |
setRotation(double angle)
Applies a rotation to all following drawing operations. |
abstract void |
setStroke(int red,
int green,
int blue,
double alpha)
Applies a stroke (outline) to all drawings. |
abstract void |
setStrokeWeight(double weight)
Applies stroke width to strokes (outlines). |
| Methods inherited from class com.google.gwt.user.client.ui.Widget |
|---|
doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onDetach, onLoad, onUnload, removeFromParent, setElement |
| Methods inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected double rotation
| Constructor Detail |
|---|
public Canvas()
| Method Detail |
|---|
public void onBrowserEvent(com.google.gwt.user.client.Event event)
onBrowserEvent in interface com.google.gwt.user.client.EventListeneronBrowserEvent in class com.google.gwt.user.client.ui.Widgetpublic void setRotation(double angle)
angle - Angle in radianspublic double getRotation()
public abstract void setStroke(int red,
int green,
int blue,
double alpha)
red - Red component from 0 ( =none ) to 255 (full),green - Green component from 0 ( =none ) to 255 (full),blue - Blue component from 0 ( =none ) to 255 (full),alpha - Alpha (opacity) component from 0 (=transparent) to 1 (=opaque)
public abstract void setFill(int red,
int green,
int blue,
double alpha)
#drawImage(Element, double, double, double, double, double, double),
drawPolygon(double[], double[]), and
drawText(String, double, double).
red - Red component from 0 ( =none ) to 255 (full),green - Green component from 0 ( =none ) to 255 (full),blue - Blue component from 0 ( =none ) to 255 (full),alpha - Alpha (opacity) component from 0 (=transparent) to 1 (=opaque)public abstract void setStrokeWeight(double weight)
weight -
public abstract void setOffset(double left,
double top)
left - offset to be added to the X ordinatetop - offset to be added to the Y ordinate
public abstract void drawRectangle(double left,
double top,
double width,
double height)
left - top - width - height -
public abstract void drawLine(double fromLeft,
double fromTop,
double toLeft,
double toTop)
fromLeft - fromTop - toLeft - toTop -
public abstract void drawArc(double centerLeft,
double centerTop,
double width,
double height,
double fromAngle,
double toAngle)
centerLeft - centerTop - width - height - fromAngle - Angle in radians.toAngle - Angle in radians.
public abstract void drawPolyLine(double[] x,
double[] y)
x - X ordinates of each line nodey - Y ordinates of each line node.
public abstract void drawPolygon(double[] x,
double[] y)
x - X ordinates of each line nodey - Y ordinates of each line node.public abstract void clear()
public abstract void flush()
public abstract void drawImage(com.google.gwt.user.client.Element image,
double sx,
double sy,
double swidth,
double sheight,
double dx,
double dy,
double dwidth,
double dheight)
image - Image element. Please note that this must be a genuine
<img> tag element, using a clipped GWT
image will not work. Images are rotated around their center and not
around the center of the coordinate system.sx - Offset from the left in the image from which to start drawingsy - Offset from the top in the image from which to start drawingswidth - Width of the part in the image which to drawsheight - Height of the part in the image which to drawdx - X position in the canvas to draw the selected image area tody - Y position in the canvas to draw the selected image area todwidth - Width of the destination area. Can be used for scaling.dheight - Height of the destination area.
public abstract void drawText(java.lang.String text,
double x,
double y)
#setFont(BitmapFontImpl) must be called prior to
drawing the first text.
text - x - X ordinate of the canvas location to draw text to.y - Y ordinate of the canvas location to draw text to.public abstract void setFont(Font font)
font -
public static Canvas create(int width,
int height)
width - Width in pixelsheight - Height in pixels
public static Font createBitmapFont(java.lang.String bitmapPath,
java.lang.String descriptionPath,
FontLoadListener listener)
Font object from a bitmap representation.
bitmapPath - URL to bitmap as created by the BitmapFontCreatordescriptionPath - URL to the font description path as created by the
BitmapFontCreatorlistener - Optional listener to notify when a font is loaded or an error
occurred.
public void addClickListener(com.google.gwt.user.client.ui.ClickListener listener)
addClickListener in interface com.google.gwt.user.client.ui.SourcesClickEventspublic void removeClickListener(com.google.gwt.user.client.ui.ClickListener listener)
removeClickListener in interface com.google.gwt.user.client.ui.SourcesClickEventspublic void addFocusListener(com.google.gwt.user.client.ui.FocusListener listener)
addFocusListener in interface com.google.gwt.user.client.ui.SourcesFocusEventspublic void removeFocusListener(com.google.gwt.user.client.ui.FocusListener listener)
removeFocusListener in interface com.google.gwt.user.client.ui.SourcesFocusEventspublic void addKeyboardListener(com.google.gwt.user.client.ui.KeyboardListener listener)
addKeyboardListener in interface com.google.gwt.user.client.ui.SourcesKeyboardEventspublic void removeKeyboardListener(com.google.gwt.user.client.ui.KeyboardListener listener)
removeKeyboardListener in interface com.google.gwt.user.client.ui.SourcesKeyboardEventspublic void addMouseListener(com.google.gwt.user.client.ui.MouseListener listener)
addMouseListener in interface com.google.gwt.user.client.ui.SourcesMouseEventspublic void removeMouseListener(com.google.gwt.user.client.ui.MouseListener listener)
removeMouseListener in interface com.google.gwt.user.client.ui.SourcesMouseEventspublic void addMouseWheelListener(com.google.gwt.user.client.ui.MouseWheelListener listener)
addMouseWheelListener in interface com.google.gwt.user.client.ui.SourcesMouseWheelEventspublic void removeMouseWheelListener(com.google.gwt.user.client.ui.MouseWheelListener listener)
removeMouseWheelListener in interface com.google.gwt.user.client.ui.SourcesMouseWheelEventspublic abstract com.google.gwt.user.client.Element prepareImage(com.google.gwt.user.client.Element image)
Element image = DOM.createImage();
DOM.setImgSrc(image,"test.png");
Element preparedImage = canvas.prepareImage(image);
canvas.drawImage(preparedImage,0,0,100,100,0,0,100,100);
image -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||