|
AjaxSwing provides a universal renderer and updater that can be used to support any component.
It works by taking a snapshot image and inserting it into the HTML page. If the component is
enabled SnapshotRenderer will add a mouse listener to the image that will capture and emulate
mouse clicks to the component. If mouse clicks are emulated, it is necessary to register
SnapshotUpdater as well. While SnapshotRenderer will work for any component, it is recommended
to use it as a last resort or for components that use custom drawing. Every time a page is
rendered an image will be generated in the temporary directory so there is a certain performance
overhead. By default SnapshotRenderer will be used for all unsupported components, but it can
be turned off using html.snapshotRenderer.enable property.
The quality of the generated JPEG image is controlled by snapshotRenderer.quality property in the
application properties file. Possible values are between 0.0 (the worst quality but smallest size)
and 1.0 (the best quality but no compression). The default is 1.0. The example below sets a quality
of 75% to all snapshots rendered in the application:
window.*.snapshotRenderer.quality=0.75
Example
Suppose a Network Management System uses a custom component com.acme.NetworkMap to display a
graphics map of nodes and connections between them. NetworkMap is derived from JPanel and overrides
paint() method to draw itself. When the application is run in AjaxSwing the component will be rendered
blank because it has no children. To see the maps in HTML we are going to register a SnapshotRenderer
as a custom renderer in the application properties file for NetworkMap
as shown below
render.com.acme.NetworkMap=com.creamtec.ajaxswing.rendering.html.SnapshotRenderer
Now, suppose that the user can click on a node to select it and see its properties. In order to have
the same functionality in HTML we need to make sure that the table is enabled and that we have registered
SnapshotUpdater to emulate the action
update.com.acme.NetworkMap=com.creamtec.ajaxswing.gui.SnapshotUpdater
|