
public class DrawComponent extends Component implements SpriteHandler.HasSpriteHandlers, SpriteOutEvent.HasSpriteOutHandlers, SpriteOverEvent.HasSpriteOverHandlers, SpriteSelectionEvent.HasSpriteSelectionHandlers, SpriteUpEvent.HasSpriteUpHandlers
Sprites can be rendered. The
Draw Component manages and holds a Surface instance: an interface
that has an SVG or VML implementation depending on the browser capabilities
and where Sprites can be appended.
Here is an example of creating a draw component:
DrawComponent component = new DrawComponent();
CircleSprite circle = new CircleSprite();
circle.setCenterX(120);
circle.setCenterY(100);
circle.setRadius(25);
circle.setFill(RGB.GREEN);
circle.setStroke(new RGB(#999));
component.add(circle);
ContentPanel panel = new ContentPanel();
panel.setHeadingText("Basic Draw");
panel.setPixelSize(320, 300);
panel.add(component);
The type of the sprite is a CircleSprite so if you run this code
you'll see a green circle with gray stroke in a ContentPanel.| Modifier and Type | Field and Description |
|---|---|
protected Surface |
surface |
adjustSize, allowTextSelection, cacheSizes, disableContextMenu, disabled, disabledStyle, ensureVisibilityOnSizing, height, hidden, lastSize, layer, left, mask, maskMessage, monitorWindowResize, pageX, pageY, resizeHandler, shim, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask| Constructor and Description |
|---|
DrawComponent()
Creates a draw widget at the default size.
|
DrawComponent(int width,
int height)
Creates a draw widget using the given width and height.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addGradient(Gradient gradient)
|
void |
addSprite(Sprite sprite)
|
HandlerRegistration |
addSpriteHandler(SpriteHandler handler)
Adds a
SpriteHandler handler for SpriteSelectionEvent,
SpriteOutEvent, SpriteOverEvent and SpriteUpEvent
events. |
HandlerRegistration |
addSpriteOutHandler(SpriteOutEvent.SpriteOutHandler handler)
Adds a
SpriteOutEvent.SpriteOutHandler handler for SpriteOutEvent
events. |
HandlerRegistration |
addSpriteOverHandler(SpriteOverEvent.SpriteOverHandler handler)
Adds a
SpriteOverEvent.SpriteOverHandler handler for SpriteOverEvent
events. |
HandlerRegistration |
addSpriteSelectionHandler(SpriteSelectionEvent.SpriteSelectionHandler handler)
Adds a
SpriteSelectionEvent.SpriteSelectionHandler handler for
SpriteSelectionEvent events. |
HandlerRegistration |
addSpriteUpHandler(SpriteUpEvent.SpriteUpHandler handler)
Adds a
SpriteUpEvent.SpriteUpHandler handler for SpriteUpEvent events. |
void |
clearSurface()
Clears all of the sprites from the draw surface.
|
protected HandlerManager |
ensureHandler() |
Color |
getBackground()
Returns the background color of the component.
|
protected PrecisePoint |
getEventXY(Event event)
Returns the point of the event adjusted for the position of the chart.
|
Surface |
getSurface()
Returns the
Surface. |
boolean |
isViewBox()
Returns true if the widget is to have a view box.
|
protected void |
onAttach() |
void |
onBrowserEvent(Event event) |
void |
onMouseDown(Event event)
Method used when the chart is clicked.
|
void |
onMouseMove(Event event)
Method used when the mouse moves over the chart.
|
void |
onMouseOut(Event event)
Method used when the mouse leaves the chart.
|
void |
onMouseUp(Event event)
Method used when the mouse is released over the chart.
|
protected void |
onResize(int width,
int height)
Called after the widget is resized, this method is empty by default but can be implemented by any subclass that
needs to perform custom logic after a resize occurs.
|
void |
redrawSurface()
Calls the
Surface to render. |
void |
redrawSurfaceForced()
Redraws the surface immediately.
|
void |
remove(Sprite sprite)
|
void |
renderSprite(Sprite sprite)
Renders the given sprite to the surface.
|
void |
setBackground(Color background)
Sets the background color of the chart.
|
void |
setPixelSize(int width,
int height)
Sets the component's size.
|
void |
setViewBox(boolean viewBox)
Sets whether the
Surface has a view box. |
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disable, disableContextMenu, disableEvents, enable, enableEvents, fireCancellableEvent, fireEvent, focus, getData, getElement, getFocusEl, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, notifyHide, notifyShow, onAfterFirstAttach, onBlur, onDetach, onDisable, onEnable, onFocus, onHide, onHideContextMenu, onLoad, onPosition, onRightClick, onShow, onShowContextMenu, onUnload, onWindowResize, removeStyleDependentName, removeStyleOnOver, removeToolTip, setAllowTextSelection, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPagePosition, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmaskprotected Surface surface
public DrawComponent()
public DrawComponent(int width,
int height)
width - the width of the draw widgetheight - the height of the draw widgetpublic void addGradient(Gradient gradient)
gradient - the gradient to be addedpublic void addSprite(Sprite sprite)
sprite - the sprite to be addedpublic HandlerRegistration addSpriteHandler(SpriteHandler handler)
SpriteHandler.HasSpriteHandlersSpriteHandler handler for SpriteSelectionEvent,
SpriteOutEvent, SpriteOverEvent and SpriteUpEvent
events.addSpriteHandler in interface SpriteHandler.HasSpriteHandlershandler - the handlerpublic HandlerRegistration addSpriteOutHandler(SpriteOutEvent.SpriteOutHandler handler)
SpriteOutEvent.HasSpriteOutHandlersSpriteOutEvent.SpriteOutHandler handler for SpriteOutEvent
events.addSpriteOutHandler in interface SpriteOutEvent.HasSpriteOutHandlershandler - the handlerpublic HandlerRegistration addSpriteOverHandler(SpriteOverEvent.SpriteOverHandler handler)
SpriteOverEvent.HasSpriteOverHandlersSpriteOverEvent.SpriteOverHandler handler for SpriteOverEvent
events.addSpriteOverHandler in interface SpriteOverEvent.HasSpriteOverHandlershandler - the handlerpublic HandlerRegistration addSpriteSelectionHandler(SpriteSelectionEvent.SpriteSelectionHandler handler)
SpriteSelectionEvent.HasSpriteSelectionHandlersSpriteSelectionEvent.SpriteSelectionHandler handler for
SpriteSelectionEvent events.addSpriteSelectionHandler in interface SpriteSelectionEvent.HasSpriteSelectionHandlershandler - the handlerpublic HandlerRegistration addSpriteUpHandler(SpriteUpEvent.SpriteUpHandler handler)
SpriteUpEvent.HasSpriteUpHandlersSpriteUpEvent.SpriteUpHandler handler for SpriteUpEvent events.addSpriteUpHandler in interface SpriteUpEvent.HasSpriteUpHandlershandler - the handlerpublic void clearSurface()
public Color getBackground()
public boolean isViewBox()
public void onBrowserEvent(Event event)
onBrowserEvent in class Componentpublic void onMouseDown(Event event)
event - the mouse eventpublic void onMouseMove(Event event)
event - the mouse eventpublic void onMouseOut(Event event)
event - the mouse eventpublic void onMouseUp(Event event)
event - the mouse eventpublic void redrawSurface()
Surface to render.public void redrawSurfaceForced()
public void remove(Sprite sprite)
sprite - the sprite to be removedpublic void renderSprite(Sprite sprite)
sprite - the sprite to be renderedpublic void setBackground(Color background)
background - the background color of the chartpublic void setPixelSize(int width,
int height)
ComponentsetPixelSize in class Componentwidth - new width, in pixelsheight - height, in pixelspublic void setViewBox(boolean viewBox)
Surface has a view box. The view box is determined
by the bounding box of all the Sprites in the surface.viewBox - true for the surface to have a view boxprotected HandlerManager ensureHandler()
protected PrecisePoint getEventXY(Event event)
event - the eventprotected void onResize(int width,
int height)
ComponentCopyright © 2018. All rights reserved.