Class WPaintedWidget
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WWebWidget
-
- eu.webtoolkit.jwt.WInteractWidget
-
- eu.webtoolkit.jwt.WPaintedWidget
-
- Direct Known Subclasses:
WAbstractChart,WAxisSliderWidget,WQrCode
public abstract class WPaintedWidget extends WInteractWidget
A widget that is painted using vector graphics.A painted widget is rendered from basic drawing primitives. Rendering is done not on the server but on the browser, using different rendering methods:
Browser Methods Default method Firefox 1.5+ HtmlCanvas, InlineSVG, PngImage HtmlCanvas Internet Explorer 6.0+ InlineVML, PngImage InlineVML Internet Explorer 9+ HtmlCanvas, InlineSVG, PngImage HtmlCanvas Safari HtmlCanvas, InlineSVG, PngImage HtmlCanvas Opera InlineSVG, HtmlCanvas*, PngImage InlineSVG other ? HtmlCanvas, PngImage * HtmlCanvas occasionally suffers from rendering artefacts in Opera.
The different rendering methods correspond to different
WPaintDeviceimplementations, from which this widget choses a suitable one depending on the browser capabilities and configuration.If no JavaScript is available, the JavaScript-based HtmlCanvas will not be used, and InlineSVG will be used instead. The method used may be changed by using
setPreferredMethod().In some browsers, InlineSVG requires that the document is rendered as XHTML. This must be enabled in the configuration file using the
<send-xhtml-mime-type>option. By default, this option is off. Firefox 4 and Chrome do support svg in normal html mode.The PngImage is the most portable rendering method, and may be the fastest if the painting is of high complexity and/or the image is fairly small.
To use a WPaintedWidget, you must derive from it and reimplement
paintEvent(). To paint on aWPaintDevice, you will need to use aWPainter. Repainting is triggered by calling theupdate()method.CSS
Styling through CSS is not applicable.
Note: A WPaintedWidget requires that it is given a size using
resize()or by a layout manager.Client side interaction and repainting
If the widget is drawn as an HTML canvas element, i.e. the
methodis HtmlCanvas, a WPaintedWidget can expose certain objects to be modified client side.- See Also:
WJavaScriptHandle,WJavaScriptExposableObject,WImage
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WPaintedWidget()Create a new painted widget.WPaintedWidget(WContainerWidget parentContainer)Create a new painted widget.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddArea(WAbstractArea area)Adds an interactive area.protected DomElementcreateDomElement(WApplication app)Create DOM element for widget.protected WJavaScriptHandle<WBrush>createJSBrush()Create aWBrushthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPainterPath>createJSPainterPath()Create aWPainterPaththat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPen>createJSPen()Create aWPenthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPointF>createJSPoint()Create aWPointFthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WRectF>createJSRect()Create aWRectFthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WTransform>createJSTransform()Create aWTransformthat is accessible from JavaScript, associated with this WPaintedWidget.protected voidenableAjax()Progresses to an Ajax-enabled widget.WAbstractAreagetArea(int index)Returns the interactive area at the given index.java.util.List<WAbstractArea>getAreas()Returns the interactive areas set for this widget.java.lang.StringgetBotResourceId()Returns the potential bot resource ID.protected WPaintDevicegetCreatePaintDevice()Creates a paint device.protected voidgetDomChanges(java.util.List<DomElement> result, WApplication app)Get DOM changes for this widget.protected RenderMethodgetMethod()Returns the actual method used for rendering.protected java.lang.StringgetObjJsRef()Returns a JavaScript reference to the client side representation of theWPaintedWidget.RenderMethodgetPreferredMethod()Returns the preferred rendering method.JSlotgetRepaintSlot()A JavaScript slot that repaints the widget when triggered.voidinsertArea(int index, WAbstractArea area)Inserts an interactive area.protected voidlayoutSizeChanged(int width, int height)Virtual method that indicates a size change.protected abstract voidpaintEvent(WPaintDevice paintDevice)Paints the widget.voidrefresh()Refresh the widget.voidremove()Destructor.WAbstractArearemoveArea(WAbstractArea area)Removes an interactive area.protected voidrender(java.util.EnumSet<RenderFlag> flags)Renders the widget.voidresize(WLength width, WLength height)Resizes the widget.voidsetBotResourceId(java.lang.String id)Sets the potential bot resource ID.protected voidsetFormData(WObject.FormData formData)voidsetPreferredMethod(RenderMethod method)Sets the preferred rendering method.voidupdate()Lets the widget repaint itself.voidupdate(PaintFlag flag, PaintFlag... flags)Lets the widget repaint itself.voidupdate(java.util.EnumSet<PaintFlag> flags)Lets the widget repaint itself.-
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
-
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, 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
getObjectName
-
-
-
-
Constructor Detail
-
WPaintedWidget
public WPaintedWidget(WContainerWidget parentContainer)
Create a new painted widget.
-
WPaintedWidget
public WPaintedWidget()
Create a new painted widget.
-
-
Method Detail
-
remove
public void remove()
Destructor.- Overrides:
removein classWInteractWidget- See Also:
WWidget.removeWidget(WWidget widget)
-
setPreferredMethod
public void setPreferredMethod(RenderMethod method)
Sets the preferred rendering method.When
methodis supported by the browser, then it is chosen for rendering.
-
getPreferredMethod
public RenderMethod getPreferredMethod()
Returns the preferred rendering method.
-
update
public void update(java.util.EnumSet<PaintFlag> flags)
Lets the widget repaint itself.Repainting is not immediate, but happens after when the event loop is exited.
Unless a
PaintFlag.Updatepaint flag is set, the widget is first cleared.
-
update
public final void update(PaintFlag flag, PaintFlag... flags)
Lets the widget repaint itself.
-
update
public final void update()
Lets the widget repaint itself.
-
refresh
public void refresh()
Description copied from class:WWidgetRefresh the widget.The refresh method is invoked when the locale is changed using
WApplication#setLocale()or when the user hit the refresh button.The widget must actualize its contents in response.
Note: This does not rerender the widget! Calling
refresh()usually does not have any effect (unless you've reimplementedrefresh()to attach to it an effect).- Overrides:
refreshin classWWebWidget
-
resize
public void resize(WLength width, WLength height)
Description copied from class:WWidgetResizes the widget.Specifies a fixed size for this widget, setting CSS
widthandheightproperties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether the widget is a block or inline widget:
- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).
When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using
setLayoutSizeAware(). If you have defined a"wtResize()"JavaScript method for the widget, then this method will also be called.The default width and height of a widget is
WLength.Auto.- Overrides:
resizein classWWebWidget- See Also:
WWidget.getWidth(),WWidget.getHeight()
-
addArea
public void addArea(WAbstractArea area)
Adds an interactive area.Adds the
areawhich listens to events in a specific region of the widget. Areas are organized in a list, to which the givenareais appended. When areas overlap, the area with the lowest index receives the event.Note: When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a
WRectAreathat corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
-
insertArea
public void insertArea(int index, WAbstractArea area)Inserts an interactive area.Inserts the
areawhich listens to events in the coresponding area of the widget. Areas are organized in a list, and the area is inserted at indexindex. When areas overlap, the area with the lowest index receives the event.Note: When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a
WRectAreathat corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
-
removeArea
public WAbstractArea removeArea(WAbstractArea area)
Removes an interactive area.Removes the
areafrom this widget.
-
getArea
public WAbstractArea getArea(int index)
Returns the interactive area at the given index.Returns
nullifindexwas invalid.
-
getAreas
public java.util.List<WAbstractArea> getAreas()
Returns the interactive areas set for this widget.- See Also:
addArea(WAbstractArea area)
-
setBotResourceId
public void setBotResourceId(java.lang.String id)
Sets the potential bot resource ID.In case the
WPaintDeviceof thisWPaintedWidgetpaints aWResource, this allows to set the bot resource ID thatWResource.- See Also:
WResource.getBotResourceId()
-
getBotResourceId
public java.lang.String getBotResourceId()
Returns the potential bot resource ID.- See Also:
setBotResourceId(String id)
-
getRepaintSlot
public JSlot getRepaintSlot()
A JavaScript slot that repaints the widget when triggered.This is useful for client-side initiated repaints. You may want to use this if you want to add interaction or animation to your
WPaintedWidget.Note: This feature is currently only supported if the
methodis HtmlCanvas. This will not cause a server roundtrip. Instead, the resulting JavaScript ofpaintEvent()will be re-executed on the client side.- See Also:
getObjJsRef()
-
createJSTransform
protected WJavaScriptHandle<WTransform> createJSTransform()
Create aWTransformthat is accessible from JavaScript, associated with this WPaintedWidget.
-
createJSBrush
protected WJavaScriptHandle<WBrush> createJSBrush()
Create aWBrushthat is accessible from JavaScript, associated with this WPaintedWidget.
-
createJSPen
protected WJavaScriptHandle<WPen> createJSPen()
Create aWPenthat is accessible from JavaScript, associated with this WPaintedWidget.
-
createJSPainterPath
protected WJavaScriptHandle<WPainterPath> createJSPainterPath()
Create aWPainterPaththat is accessible from JavaScript, associated with this WPaintedWidget.
-
createJSRect
protected WJavaScriptHandle<WRectF> createJSRect()
Create aWRectFthat is accessible from JavaScript, associated with this WPaintedWidget.
-
createJSPoint
protected WJavaScriptHandle<WPointF> createJSPoint()
Create aWPointFthat is accessible from JavaScript, associated with this WPaintedWidget.
-
layoutSizeChanged
protected void layoutSizeChanged(int width, int height)Description copied from class:WWidgetVirtual method that indicates a size change.This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called.
- Overrides:
layoutSizeChangedin classWWidget- See Also:
WWidget.setLayoutSizeAware(boolean aware)
-
getMethod
protected RenderMethod getMethod()
Returns the actual method used for rendering.The default method considers browser capabilites and the preferred method to make an actual choice for the implementation.
You may want to reimplement this method to override this choice.
-
paintEvent
protected abstract void paintEvent(WPaintDevice paintDevice)
Paints the widget.You should reimplement this method to paint the contents of the widget, using the given paintDevice.
-
getCreatePaintDevice
protected WPaintDevice getCreatePaintDevice()
Creates a paint device.Although it's usually not necessary to call this function, you may want to reimplement this function to customize or specialize the device used for painting the widget.
-
createDomElement
protected DomElement createDomElement(WApplication app)
Description copied from class:WWebWidgetCreate DOM element for widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
createDomElementin classWWebWidget
-
getDomChanges
protected void getDomChanges(java.util.List<DomElement> result, WApplication app)
Description copied from class:WWebWidgetGet DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChangesin classWWebWidget
-
enableAjax
protected void enableAjax()
Description copied from class:WWidgetProgresses to an Ajax-enabled widget.This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
- Overrides:
enableAjaxin classWWebWidget- See Also:
WApplication.enableAjax()
-
render
protected void render(java.util.EnumSet<RenderFlag> flags)
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
renderin classWInteractWidget
-
setFormData
protected void setFormData(WObject.FormData formData)
- Overrides:
setFormDatain classWObject
-
getObjJsRef
protected java.lang.String getObjJsRef()
Returns a JavaScript reference to the client side representation of theWPaintedWidget.The client side representation exposes the following interface:
{ canvas: exposes the underlying HTML canvas element repaint: a function that, when called, will repaint the widget without a server roundtrip }Note: The
methodshould be HtmlCanvas and there has to be at least oneWJavaScriptHandleassociated with thisWPaintedWidgetin order for this reference to be valid.
-
-