Class WPaintedWidget
- Direct Known Subclasses:
WAbstractChart,WAxisSliderWidget,WQrCode
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 WPaintDevice implementations,
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 a WPaintDevice, you will need to use a WPainter. Repainting is triggered by calling the
update() 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 method is HtmlCanvas, a WPaintedWidget can expose certain objects to be modified client side.
- See Also:
-
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_, noDefaultFields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new painted widget.WPaintedWidget(WContainerWidget parentContainer) Create a new painted widget. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArea(WAbstractArea area) Adds an interactive area.protected DomElementCreate DOM element for widget.protected WJavaScriptHandle<WBrush> Create aWBrushthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPainterPath> Create aWPainterPaththat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPen> Create aWPenthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPointF> Create aWPointFthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WRectF> Create aWRectFthat is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WTransform> Create aWTransformthat is accessible from JavaScript, associated with this WPaintedWidget.protected voidProgresses to an Ajax-enabled widget.getArea(int index) Returns the interactive area at the given index.getAreas()Returns the interactive areas set for this widget.Returns the potential bot resource ID.protected WPaintDeviceCreates a paint device.protected voidgetDomChanges(List<DomElement> result, WApplication app) Get DOM changes for this widget.protected RenderMethodReturns the actual method used for rendering.protected StringReturns a JavaScript reference to the client side representation of theWPaintedWidget.Returns the preferred rendering method.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.removeArea(WAbstractArea area) Removes an interactive area.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidResizes the widget.voidSets the potential bot resource ID.protected voidsetFormData(WObject.FormData formData) voidsetPreferredMethod(RenderMethod method) Sets the preferred rendering method.final voidupdate()Lets the widget repaint itself.final voidLets the widget repaint itself.voidLets 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, unsetDraggableMethods 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, widgetRemovedMethods 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, trMethods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WPaintedWidget
Create a new painted widget. -
WPaintedWidget
public WPaintedWidget()Create a new painted widget.
-
-
Method Details
-
remove
public void remove()Destructor.- Overrides:
removein classWInteractWidget- See Also:
-
setPreferredMethod
Sets the preferred rendering method.When
methodis supported by the browser, then it is chosen for rendering. -
getPreferredMethod
Returns the preferred rendering method. -
update
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
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
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:
-
addArea
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
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
Removes an interactive area.Removes the
areafrom this widget. -
getArea
Returns the interactive area at the given index.Returns
nullifindexwas invalid. -
getAreas
Returns the interactive areas set for this widget.- See Also:
-
setBotResourceId
Sets the potential bot resource ID.In case the
WPaintDeviceof thisWPaintedWidgetpaints aWResource, this allows to set the bot resource ID thatWResource.- See Also:
-
getBotResourceId
Returns the potential bot resource ID.- See Also:
-
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:
-
createJSTransform
Create aWTransformthat is accessible from JavaScript, associated with this WPaintedWidget. -
createJSBrush
Create aWBrushthat is accessible from JavaScript, associated with this WPaintedWidget. -
createJSPen
Create aWPenthat is accessible from JavaScript, associated with this WPaintedWidget. -
createJSPainterPath
Create aWPainterPaththat is accessible from JavaScript, associated with this WPaintedWidget. -
createJSRect
Create aWRectFthat is accessible from JavaScript, associated with this WPaintedWidget. -
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:
-
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
Paints the widget.You should reimplement this method to paint the contents of the widget, using the given paintDevice.
-
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
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
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:
-
render
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
- Overrides:
setFormDatain classWObject
-
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.
-