Best Lead In to Explain NetBeans FilterNode
By Geertjan-Oracle on May 22, 2010
"There may be situations where you are not really satisfied by an existing node hierarchy. You may want to construct a new node hierarchy, based on the original nodes, but with different behavior. For example, you may want to provide different icons or filter out child nodes, while wanting to keep the rest of the behavior of the original node.
Initially, you might attempt to expand the existing node, or the node's children, overriding the relevant methods to obtain the required behavior. In the first place, this approach would be cumbersome and inflexible, given that a flexible alternative exists. Secondly, however, this approach might not be possible in all cases. Think, for example, of nodes that are defined in modules over which you have no control.
The decorator pattern, familiar from other areas of Java, provides a useful approach, letting you create a filter for a node that does not quite meet your requirements. In dealing with Java streams, for example, you have a BufferedInputStream, which is an InputStream that owns another InputStream, the first InputStream delegating the actual reading to the second InputStream. The first InputStream implements additional behavior, namely the buffering of the data, reducing the number of real read activities. Thus, the additional behavior is added to the decorated InputStream at runtime, dynamically. Its behavior is changed, without requiring a subclass. In the same way, you can decorate existing nodes and children to change their behavior."
The whole book is full of helpful explanations such as the above. Pretty cool, isn't it!