Skip to content

AbstractComponentDecoration (TBC)

Patrick Moawad edited this page Feb 24, 2016 · 7 revisions

This page introduces the AbstractComponentDecoration class that can be used to decorate JComponent objects (understand paint over) without impacting the layout of the parent containers and window.

General information

It provides similar functionality to the AbstractComponentDecorator described on The Rabbit Hole blog.

However, the AbstractComponentDecoration is provided under a more permissive license.

Note that there are some differences between the two. The most notable ones are the following:

  • The AbstractComponentDecoration class allows you to define the relative location of the decoration with respect to the decorated component, using an AnchorLink;
  • The AbstractComponentDecoration class allows you to define a specific component to be used for clipping the decoration;
  • The AbstractComponentDecoration class has a different API for you to provide a concrete implementation.
  • The AbstractComponentDecoration class may not support all exotic layout constructions that the AbstractComponentDecorator supports.

Concrete implementation

Concrete implementations of the AbstractComponentDecoration class must implement the following methods:

  • getWidth(): returns the decoration width in pixels;
  • getHeight(): returns the decoration height in pixels;
  • paint(Graphics): paints the decoration on the specified Graphics context. Note that coordinates (0,0) correspond to the top left corner of the decoration, not the decorated component.

In addition to that, the followDecoratedComponent() method can be called whenever conditions have changed and the decoration needs to be realigned, resized and repainted.

Anchored location

The location of the decoration is made more dynamic by nature, using an AnchorLink passed in the constructor or setAnchorLink(AnchorLink) method.

This AnchorLink allows you to slave the location of the decoration to the location and size of the decorated component.

An anchor link is made out of two Anchors. The first Anchor represents a relative point on a master (i.e. the decorated component), and the second Anchor represents a relative point on a slave (i.e. the decoration).

For example, the concrete implementation IconComponentDecoration that uses an icon as decoration, can be slaved to a textfield by using the AnchorLink: new AnchorLink(Anchor.BOTTOM_RIGHT, Anchor.CENTER). This will slave the location of the center of the icon decoration to the bottom right corner of the decorated textfield.

Dynamic size

TBC...

Input events handling

TBC...

Clipping

TBC...