 |
Home | Changes | Index | Search | Go
Summary of goals, mechanics and implications of SwingX highlighing.
Renderer Basics
Define responsibilities - reading core javadoc and tutorial
- return component used for displaying the cell content (treeNode, object) == rendering component
- configure renderer and/or rendering component from context as passed-in in getXXComponent
The focus is on "display requirements of the object": examples are formatting of numbers as text, mapping object properties like image, color, to appropriate rendering component properties. Another concern is about visuals (like color, font, ...): they depend on current contextual state of the Component "cell" the rendering component is going to display. In the following, I'll reference the former as the "what" and the latter as the "how".. Note that calling the getXXRendererComponent does not imply an actual paint request, it might be called for other reasons, like calculating a cell's preferredSize.
Custom Renderers
- control visual properties of rendering component (on a per-renderer basis)
- visuals might depend on content values
- current cell in relation to fixed values - f.i. number <, > a threshhold
- current cell in relation to other cells in the same row
- current cell in relation to other cells in the same column (f.i. if two values are the same both need to be highlighted)
- any combination of the above
- visuals might depend on some content independent (regular) rule, example is "striping" (alternateRowColoring)
- visuals might depend on cell-local user gesture, example is mouse (roll) over
- visuals might follow (custom) guidelines (company, LF,...)
- typical custom visuals to control: font, foreground, background, border, alignment
- visual configuration often is orthogonal to data-centric configuration
Core Swing tutorial's is focused on customization per-data-type, and advises to subclass DefaultXX and/or other Components. Out in the wild, this advise leads to exploding class hierarchies with much duplicated code: sheer endless permutations of per-data-type and per-visual-property, parallel for table, list, tree.
Highlighter Basics
SwingX highlighting strives to reduce the number of classes by separating the control of renderer visuals from the renderer content, making the visuals pluggable = Highlighters. As such, it is applicable for all components which use a "cell renderer" approach to painting: table, list, tree.
The mechanics are to post-configure the component returned by the renderer, that is the visuals are changed after the renderer has configured the renderer component.
- decouple "what" from "how" == XXRenderer vs. Highlighter
- work independent of each other and independent of renderer, should be chainable without explicit coupling
- share across component types
Implications
- limited to areas (of the components) which are painted by the renderer. This excludes f.i. striping of table/list/tree background in empty viewport space (below the last filled row). Striping of trees looks funny - the renderer only renders the part of the width (covered by the text label). Not easily seen, because default tree cell renderer is crooky...
- works best if there is a dedicated location where the renderer is prepared (JTable), problematic if there's no such place (like in JTree, JList). The latter require to install a wrapper around the customer provided renderer which first delegates to the original and then decorates the returned component with the Highlighters
- works best for visual properties which are set completedly (== reset in getXXComponent for every possible execution path, depending on context as passed in via the parameters) by the renderer: nothing documented (consequently: if we were in "strict" mode, we can't rely on it and must drop the whole idea of highlighters) - but the default implementations have "complete" setting of foreground, background, font, border. Reason is that there's no way to "unconfigure" the properties which have been set by a Highlighter
Collaborators
Overhaul
TODO: summarize the new api somewhere. For now this is just a collection of links to forum threads...
Links
Forum Discussions
Alternatives
Related Wiki Pages
|