You are hereBlogs / luano's blog / SwingLabs contribution

SwingLabs contribution


By luano - Posted on 05 June 2008

I've just contributed some text components to the SwingLabs project. These components allow text to be laid out in a manner akin to the way desktop publishing packages (DTP) can flow text around shapes, graphics and through columns.

Indeed the components were inspired by Aldus PageMaker many years ago and started out as C++ components on the Win32 platform. About 10 years ago I ported them to Java when Java 2D first came out and they were bundled with the both Genny and XUI frameworks and now that both of those platforms are defunct they have become part of the Aria framework. Donating the components to the SwingLabs project should give the components a wider audience.

Of course the components fall far short of what a DTP package can do as they do not yet support kerning and other advanced manipulation of the text, but there is no reason why that cannot be added, along with various transforms and composition effects.

The components are pretty easy to use - just instantiate and add some content. The content can include basic HTML markup like <b>, <i>, <u>, <sub>, <super>, <swap>, <justify>, <strike>. The demo project in the jdnc-incubator sets some "Lorem" text and flows it within an irregular polygon. The flow area can be divided into columns and can have various knockouts, the example includes an image nested within an ellipse as a sample knockout.

The demo application

There are some features not yet shown in the demo, but these can be seen in the Aria Components demo. One such feature is the ability to rotate and shear text. The rotation of text is just one possible effect and it hopefully it will not be a major step to extend the components to lay out text along an arbitrary path. Such effects are included in some other Aria demos, but they are not yet integrated with the flowed text components.





Aria's rotated text demo

The knockouts are created by the JXFlowedText component as it iterates over its siblings searching for those components that implement the JXShapeGenerator interface. The interface just returns the shape of the knockout

The demo application in debug mode showing the text flow area

Originally the components included an animation capability, but with the advent of the TimingFramework and now the SceneGraph library this no longer makes sense. Indeed how some of this layout stuff stacks up against SceneGraph is something I haven't had a chance to investigate but perhaps some clever readers can comment on the interaction.

For now the code is in the incubator and it probably needs some revision to make it more sympathetic to other SwingLabs components and to properly handle look and feel issues - again comments are welcome.