Renderpack Pipelines
I just committed some files to the Renderpack project that let a developer define a pipeline renderer for use with Swing JTables or JLists (or anything that can use TableCellRenderers or ListCellRenderers). This pipeline consists of a number of RenderStages, each of which tweak the output of the rendered value. There are some sample RenderStages included in the package that show off the the possibilties (cell striping, rendering dates, etc.), but I believe the real power will come from creating a custom RenderStage that, for example, uses some business logic to change the text color of all unpaid invoice, for example. RenderStages are plugged into a PipelineListCellRenderer or PipelineTableCellRenderer and can be reused anywhere in an application’s JTables or JLists.
Here’s a snippet from the demo application that shows how to render a date and stripe it with Christmas colors:
RenderStage[] listRenderers = new RenderStage[]{
new DateRenderStage("yyyy"),
new StripedRenderStage(Color.RED, Color.GREEN)
};
jList.setCellRenderer(new PipelineListCellRenderer( listRenderers ) );
The main benefit comes from the fact that you can reuse the DateRenderStage elsewhere completely seperate from the StripedRenderStage on either a JTable or JList. Using stock Swing, you would have to create a subclass of TableCellRenderer that did the date rendering for JTables and a subclass of ListCellRenderer for use on JLists and then add in striping logic if you wanted that too.
The initial idea for this came from this post at ClientJava.com which links to the HighlighterPipeline API from JDesktop Network Components. That API was too heavyweight for my uses because one must use a JDNC component (JXList, JXTable, etc.) to use a HighlighterPipeline whereas with renderpack pipelines, you’re dealing with normal Swing renderers that can be put on normalnormal Swing components. The intention of JDNC Highlighters seems to be a bit different though in that they are meant to decorate existing renderers whereas renderpack pipelines are the renderer.
A jar that you can drop into your classpath and the full source are currently available from the renderpack webpage in addition to being available from CVS.