Class WPaintedWidget
- Direct Known Subclasses:
WAbstractChart
,WAxisSliderWidget
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.
-
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_
-
Constructor Summary
ConstructorDescriptionCreate a new painted widget.WPaintedWidget
(WContainerWidget parentContainer) Create a new painted widget. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArea
(WAbstractArea area) Adds an interactive area.protected DomElement
Create DOM element for widget.protected WJavaScriptHandle<WBrush>
Create aWBrush
that is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPainterPath>
Create aWPainterPath
that is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPen>
Create aWPen
that is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WPointF>
Create aWPointF
that is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WRectF>
Create aWRectF
that is accessible from JavaScript, associated with this WPaintedWidget.protected WJavaScriptHandle<WTransform>
Create aWTransform
that is accessible from JavaScript, associated with this WPaintedWidget.protected void
Progresses 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.protected WPaintDevice
Creates a paint device.protected void
getDomChanges
(List<DomElement> result, WApplication app) Get DOM changes for this widget.protected RenderMethod
Returns the actual method used for rendering.protected String
Returns a JavaScript reference to the client side representation of theWPaintedWidget
.Returns the preferred rendering method.A JavaScript slot that repaints the widget when triggered.void
insertArea
(int index, WAbstractArea area) Inserts an interactive area.protected void
layoutSizeChanged
(int width, int height) Virtual method that indicates a size change.protected abstract void
paintEvent
(WPaintDevice paintDevice) Paints the widget.void
remove()
Destructor.removeArea
(WAbstractArea area) Removes an interactive area.protected void
render
(EnumSet<RenderFlag> flags) Renders the widget.void
Resizes the widget.protected void
setFormData
(WObject.FormData formData) void
setPreferredMethod
(RenderMethod method) Sets the preferred rendering method.final void
update()
Lets the widget repaint itself.final void
Lets the widget repaint itself.void
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, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, refresh, 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, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, 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 Details
-
WPaintedWidget
Create a new painted widget. -
WPaintedWidget
public WPaintedWidget()Create a new painted widget.
-
-
Method Details
-
remove
public void remove()Destructor.- Overrides:
remove
in classWInteractWidget
- See Also:
-
setPreferredMethod
Sets the preferred rendering method.When
method
is 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.Update
paint flag is set, the widget is first cleared. -
update
Lets the widget repaint itself. -
update
public final void update()Lets the widget repaint itself. -
resize
Description copied from class:WWidget
Resizes the widget.Specifies a fixed size for this widget, setting CSS
width
andheight
properties. 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 they 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:
resize
in classWWebWidget
- See Also:
-
addArea
Adds an interactive area.Adds the
area
which listens to events in a specific region of the widget. Areas are organized in a list, to which the givenarea
is 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
WRectArea
that 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
area
which 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
WRectArea
that 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
area
from this widget. -
getArea
Returns the interactive area at the given index.Returns
null
ifindex
was invalid. -
getAreas
Returns the interactive areas set for this widget.- 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
method
is 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 aWTransform
that is accessible from JavaScript, associated with this WPaintedWidget. -
createJSBrush
Create aWBrush
that is accessible from JavaScript, associated with this WPaintedWidget. -
createJSPen
Create aWPen
that is accessible from JavaScript, associated with this WPaintedWidget. -
createJSPainterPath
Create aWPainterPath
that is accessible from JavaScript, associated with this WPaintedWidget. -
createJSRect
Create aWRectF
that is accessible from JavaScript, associated with this WPaintedWidget. -
createJSPoint
Create aWPointF
that is accessible from JavaScript, associated with this WPaintedWidget. -
layoutSizeChanged
protected void layoutSizeChanged(int width, int height) Description copied from class:WWidget
Virtual 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:
layoutSizeChanged
in 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:WWebWidget
Create DOM element for widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
createDomElement
in classWWebWidget
-
getDomChanges
Description copied from class:WWebWidget
Get DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChanges
in classWWebWidget
-
enableAjax
protected void enableAjax()Description copied from class:WWidget
Progresses 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:
enableAjax
in classWWebWidget
- See Also:
-
render
Description copied from class:WWidget
Renders 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:
render
in classWWebWidget
-
setFormData
- Overrides:
setFormData
in 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
method
should be HtmlCanvas and there has to be at least oneWJavaScriptHandle
associated with thisWPaintedWidget
in order for this reference to be valid.
-