public class DrawComponent extends Component implements SpriteHandler.HasSpriteHandlers, SpriteOutEvent.HasSpriteOutHandlers, SpriteOverEvent.HasSpriteOverHandlers, SpriteSelectionEvent.HasSpriteSelectionHandlers, SpriteUpEvent.HasSpriteUpHandlers
The Draw Component is a surface in which Sprite
s 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.setHeading("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 Color |
background |
protected boolean |
deferred |
protected HandlerManager |
handlerManager |
protected Sprite |
lastSprite |
protected Surface |
surface |
protected boolean |
viewBox |
adjustSize, allowTextSelection, cacheSizes, contextMenu, contextMenuGestureRecognizer, dataMap, deferHeight, disableContextMenu, disabled, disabledStyle, disableEvents, ensureVisibilityOnSizing, focusManagerSupport, gestureRecognizers, height, hidden, hideMode, itemId, lastSize, layer, left, mask, maskMessage, monitorWindowResize, overElements, pageX, pageY, resizeHandler, shadow, shadowPosition, shim, stateful, stateId, 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 void |
createSurface(int width,
int height)
Creates a surface using the given width and height.
|
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 |
onTap(TouchData touchData) |
void |
redrawSurface()
Calls the
Surface to render. |
void |
redrawSurfaceForced()
Redraws the surface immediately.
|
void |
remove(Sprite sprite)
|
protected void |
render() |
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.
|
protected void |
setSurfaceSize(int width,
int height) |
void |
setViewBox(boolean viewBox)
Sets whether the
Surface has a view box. |
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addGestureRecognizer, 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, getGestureRecognizer, getGestureRecognizerCount, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAdjustSize, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, makeVisible, mask, mask, notifyHide, notifyShow, onAfterFirstAttach, onBlur, onDetach, onDisable, onEnable, onFocus, onHide, onHideContextMenu, onLoad, onPosition, onRightClick, onShow, onShowContextMenu, onTouch, onUnload, onWindowResize, removeStyleDependentName, removeStyleOnOver, removeToolTip, restoreVisible, setAdjustSize, 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, unmask
protected Surface surface
protected boolean viewBox
protected Color background
protected boolean deferred
protected HandlerManager handlerManager
protected Sprite lastSprite
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.HasSpriteHandlers
SpriteHandler
handler for SpriteSelectionEvent
,
SpriteOutEvent
, SpriteOverEvent
and SpriteUpEvent
events.addSpriteHandler
in interface SpriteHandler.HasSpriteHandlers
handler
- the handlerpublic HandlerRegistration addSpriteOutHandler(SpriteOutEvent.SpriteOutHandler handler)
SpriteOutEvent.HasSpriteOutHandlers
SpriteOutEvent.SpriteOutHandler
handler for SpriteOutEvent
events.addSpriteOutHandler
in interface SpriteOutEvent.HasSpriteOutHandlers
handler
- the handlerpublic HandlerRegistration addSpriteOverHandler(SpriteOverEvent.SpriteOverHandler handler)
SpriteOverEvent.HasSpriteOverHandlers
SpriteOverEvent.SpriteOverHandler
handler for SpriteOverEvent
events.addSpriteOverHandler
in interface SpriteOverEvent.HasSpriteOverHandlers
handler
- the handlerpublic HandlerRegistration addSpriteSelectionHandler(SpriteSelectionEvent.SpriteSelectionHandler handler)
SpriteSelectionEvent.HasSpriteSelectionHandlers
SpriteSelectionEvent.SpriteSelectionHandler
handler for
SpriteSelectionEvent
events.addSpriteSelectionHandler
in interface SpriteSelectionEvent.HasSpriteSelectionHandlers
handler
- the handlerpublic HandlerRegistration addSpriteUpHandler(SpriteUpEvent.SpriteUpHandler handler)
SpriteUpEvent.HasSpriteUpHandlers
SpriteUpEvent.SpriteUpHandler
handler for SpriteUpEvent
events.addSpriteUpHandler
in interface SpriteUpEvent.HasSpriteUpHandlers
handler
- the handlerpublic void clearSurface()
public Color getBackground()
public boolean isViewBox()
public void onBrowserEvent(Event event)
onBrowserEvent
in class Component
public 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 onTap(TouchData touchData)
public 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)
Component
setPixelSize
in class Component
width
- 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 Sprite
s 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)
Component
protected void createSurface(int width, int height)
width
- the width of the surfaceheight
- the height of the surfaceprotected void render()
protected void setSurfaceSize(int width, int height)
Copyright © 2018. All rights reserved.