JXLayer 3.0 demonstration by Piet Blok

Note: the code on this page is targeted at the older JXLayer 3.0. For a version of this page targeted at the new JXLayer 4.0 please go to JXLayer 4.0 demonstration by Piet Blok

This page supersedes two previous blogs about the same subject, JXLayer, a first impression and JXLayer and a generic ZoomUI . Basically, the same demonstrations are shown, but the source code has been restructured considerably.

Binary code: PBTransform.jar

Source code: Transform_src.zip

API documentation: API doc

Note: the API doc is generated with the source code flag on, so one can view the source directly via the API doc.

License

The code is licensed under the new BSD license. .


Updates

2009 - 04 - 22 The RepaintManager blues continued: for Java versions starting with Java 6u10, an attempt is made to use the undocumented JavaFX RepaintManager delegate facility for TransformUI (thank you Alex, for the hint some time ago. Finally found the time to pursue that trail).

During class initialization, the method SwingUtilities3.setDelegateRepaintManager(JComponent, RepaintManager) is obtained via reflection. If this is successful, a flag is set that the mechanism is available and can be used. If not, the existing mechanism RepaintManager.setCurrentManager(RepaintManager) will be used.

As a result, the hack experiments concerning RepaintManagers don't make much sense anymore when running Java 6u10 or higher. (But I didn't remove them)

2009 - 04 - 21
  • A complete refactoring has taken place in an attempt to have the TransformUI better fit in the concept of JXLayer.
    1. The special class TransformPort has been removed. The new TransformUI works with the normal view of the JXLayer.
    2. The TransformUI sets a different LayoutManager on the JXLayer (a sub class of the DefaultLayerLayout ). This LayoutManager checks the type of LayerUI set on JXLayer. If not a TransformUI , it delegates all methods to its super class. However, if the LayerUI is of type TransformUI , it recalculates minimum size and preferred size according to a preferred AffineTransform obtained from TransformUI . The view's size is set to its preferred size and it is placed in the center of JXLayer.
    3. TransformUI inherits from MouseEventUI (that in turn directly inherits from AbstractLayerUI ). MouseEventUI 's only responsibility is re-dispatching of MouseEvents to intended components, based on the AffineTransform obtained from getTransform().
    4. TransformUI is responsible for all painting. It does not manage transformations itself. It now overrides the paint method to prepare a Graphics object from a BufferedImage and passes that object to the paintLayer method. Normally, that paintLayer method will delegate the call to its super implementation. However, there is one situation where it does something different: when the view's height or width are larger than the layer's height or width (down sizing is needed). The super implementation would have the obscured parts not painted. So, the view will be painted directly. To prevent visual artifacts outside the layer, double buffering must be disabled (this is recursively done on each child component).
    5. Transformations are now the responsibility of a TransformModel defined as an interface. A DefaultTransformModel is available that can apply a variety of transformations. A TransformUI will always have a TransformModel , either the DefaultTransformModel that is set by default, or a custom TransformModel .
    6. A RepaintManager is still needed. For testing purposes I created a hack (default disabled) to copy some properties (via reflection) from the original RepaintManager in the new RepaintManager. This hack should prevent that the "grey rectangle fix" (see RepaintManager's side effect ) is disabled. If you want to see how the hack works, click here for the source code (you will find it somewhere around line 120).

  • Since the TransformUI demonstration is the most important one (at least, that is what I think), I changed the order of the demo's. The playground exercises have been moved to the end.
  • I added a copy of the Transformation demo with the RepaintManager hack enabled.
2009 - 04 - 08 In TransformPort the paint() method is used instead of the print() method for rendering the view to an intermediate image. This is made possible by first setting double buffering enabled to false on the RepaintManager, do the paint() and finally restoring the original flag for double buffering enabled on the RepaintManager. Thank you Alex for the golden hint!
Removed the option "Paint over Print" because it's no more relevant.
2009 - 04 - 07 Upgraded to the latest jxlayer.jar (signed by me, not Alex).
Added an option (for test purposes only) that instructs TransformUI to use paint() instead of print(). In jre 6u14 b02 this should work. However, after testing I see that artifacts are still there.
Some restructuring (moved setters and getters for transformation values from the Transformer to the TransformPort).
2009 - 04 - 06 Installed SwingX release 0.9.7.
2009 - 04 - 05 Adapted to the planned SwingX release 0.9.7. (waiting for release 0.9.7 to be available, the continuous build #1732 is currently used).
Added SwingX demo.
Added a demo by s_barlow.
Added a mirror function.
Fixed some minor bugs.
2009 - 02 - 12 Added a license.
2009 - 02 - 12 The mouse event re dispatching mechanism now re dispatches to the first component upwards in the hierarchy that actually has the appropriate listener registered.
2009 - 02 - 12 Added a feature to the Transformer class that enables one to have the view always scaled to the preferred scale, regardless of its actual size. This feature is used in the new "Vertical table headers" demo.
2009 - 02 - 10 The Transformer didn't detect changes in the view's size, thus causing artifacts when adding or removing child components.
2009 - 02 - 10 Under construction: Added some "under construction" packages that contain code for possible future use. When they mature, they may be added to official packages.

A generic TransformUI Web Start Transformations

Various transformations, like scaling (zooming), rotation (in radians and / or in quadrants) and shearing are possible on a component hierarchy.

Note: on the control dialog only one tool tip is set on the glass pane over the controls.

The following LayerUI s are demonstrated:

TransformUI With its companion class DefaultTransformModel a component hierarchy can be transformed (rotation, shearing and scaling).
MouseEventUI Mouse events are dispatched to the intended child component, even when the glass pane is a target for those events.

Press the "RPM tree" button on the control dialog to see the current RepaintManager delegate sequence.


The RepaintManager hack

The TransformUI demo with the RepaintManager hack enabled: Web Start Transformations

A modified (hacked) version of Alexander Potochkin's demo that illustrates the RepaintManager problem and the hacked solution: Web Start Transformations


A zoomed out tool tip Web Start zoomed tooltip demo

Tool tips are shown via the TransformUI on text components that are deliberately rendered with a very tiny font. The tool tip uses the Document content of those components and renders it enlarged.

The following LayerUI s are demonstrated:

TransformUI This time used on a tool tip component.


Vertical table headers Web Start rotated table header demo

A JTable is shown with vertical table headers.

The following LayerUI s are demonstrated:

TransformUI Used in a TableCellRenderer. Only a quadrant rotation is used, with the new feature Transformer.setScaleToPreferredSize(true) .


A SwingX, JXLayer and TransformUI demonstration SwingX, JXLayer and TransformUI demonstration

Nested JXPanels with JXBusyLabels are shown. The main purpose of this demonstration is to show the cooperation of SwingX's RepaintManagerX with the TransformRepaintManager.

When moving the mouse over a JXBusyLabel, the alpha value of its parent JXPanel is set higher, thus forcing setting of a RepaintManager.

Press the "RPM tree" button on the control dialog to see the current RepaintManager delegate sequence.


A test by s_barlow that I liked and got permission to put on this blog Web start s_barlow demo


A wrapping demonstration Web Start Wrapped JXLayer

A structure where three LayerUI s are wrapped on one target component.

The following LayerUI s are demonstrated:

HideCursorUI After a specified interval, the mouse cursor disappears, to reappear on any mouse movement.
MouseDrawingUI Lines will be drawn over the component, triggered by mouse dragging.
MagnifierUI A magnifier glass is shown over the component.


A shared use demonstration Web Start Shared JXLayer

Basically the same as the wrapping demo, but this time the LayerUI s are shared on two structures.

The following LayerUI s are demonstrated:

HideCursorUI After a specified interval, the mouse cursor disappears, to reappear on any mouse movement.
MouseDrawingUI Lines will be drawn over the component, triggered by mouse dragging.
MagnifierUI A magnifier glass is shown over the component.


JXLayer is a tool developed by Alexander Potochkin , also known as alexp or alexfromsun .

This is the JXLayer project .

This is the JXLayer forum .


Author: Piet Blok. If you wish to contact me, please send email to email