Decoration

What a Decoratable component paints through, and how far it paints past its layout bounds: the steps its modifier declares and the paint outsets its parent gives it. The library creates each value for one component and writes it to Decoratable.decoration; a value never changes, and a change is a new value.

Each step is a Decorator, the first outermost: it paints at the layout bounds, or, when a layout modifier is declared after it, at the box of the first such modifier. The layout bounds are the box measurement, placement, alignment, onPlaced, onSizeChanged and hit testing see. The component's bounds, Swing's rectangle, are the layout bounds plus the paint outsets, how far the component paints past them on each side. A Foundation container gives a component all its paint outsets: the steps' outsets, the box of a layout modifier a step paints at, what a rotating or scaling placement layer adds and, for a Foundation container, what its children paint past it. Any other parent gives only the part of the steps' outsets the component's PaintOutsets value leaves in layout.

The layout box is the box a Foundation container sizes and aligns. A layout modifier node reads it with layoutBoxInParent.

Types

Link copied to clipboard
object Companion

Holds None.

Properties

Link copied to clipboard

Whether the component's modifier declares any decoration step.

Functions

Link copied to clipboard
fun contains(decoratable: Decoratable, x: Int, y: Int): Boolean

Whether (x, y), in decoratable's coordinates, hits it: inside the layout bounds, as its placement layers rotate, scale and clip them, or, inside its bounds, where a visible child's own contains takes the point, as for a child placed or painting past the layout bounds. A step that cuts its children to its box, such as a clip or a fade, cuts the point too. Other paint outsets, such as a shadow's, are not hit.

Link copied to clipboard
fun getGraphics(decoratable: Decoratable, graphics: Graphics?): Graphics?

Returns graphics, the superclass getGraphics() result of decoratable, unchanged. Makes the steps' image layers record on their next draw, as the caller can draw on it outside paint, with the exception that DecorationModifierNode.invalidateLayerProperties names. Requests no repaint. Call this from getGraphics() of a Decoratable, on the event dispatch thread.

Link copied to clipboard
fun insets(base: Insets): Insets

base plus the paint outsets: base itself where there are none, otherwise a new Insets.

fun insets(base: Insets, into: Insets): Insets

Writes base plus the paint outsets into into and returns it: what getInsets(Insets) answers without allocating. base may be into; a border's own Insets passed as base is left unchanged.

Link copied to clipboard
fun isOpaque(decoratable: Decoratable): Boolean

Whether decoratable, painted through this decoration, still covers every pixel of its bounds: false where it has paint outsets, or where a step paints translucently, cuts the content (Decorator.isOpaque) or paints at a box smaller than the layout bounds. The steps' own opacity is the one the library last gathered; the boxes are read at each call.

Link copied to clipboard

decoratable's layout bounds in its own coordinates: its bounds less the paint outsets; a new Rectangle. Named as SwingUtilities.getLocalBounds is.

Link copied to clipboard
fun paint(decoratable: Decoratable, graphics: Graphics, content: (Graphics) -> Unit)

Paints content, the component itself in its own coordinates, through the decoration. The steps paint at the layout bounds, or at the box of the layout modifier declared after them. Without a clip on graphics, as in a capture or a print, the whole component is painted.

Link copied to clipboard
fun paintImmediately(decoratable: Decoratable, x: Int, y: Int, width: Int, height: Int, paint: (x: Int, y: Int, width: Int, height: Int) -> Unit)

Hands paint, super.paintImmediately, the area at (x, y) of width by height, in decoratable's coordinates, grown as repaint grows it. In a Foundation container, the area grows first by what each visible child it touches spreads its part of the area into, if the child has a transform, steps with outsets or a step that does not repaint within its outsets, or holds such a child: by the steps' reach, held inside the child's bounds, or to the whole child if its steps move content or a step does not repaint within its outsets. Until the paint that DecorationModifierNode.invalidateLayerProperties asked for runs, the area is the whole bounds, so no paint shows the component at two values of what that paint changes. Decoration steps show content changes in this paint. Call this from paintImmediately(int, int, int, int) of a Decoratable.

Link copied to clipboard

How far the component paints past its layout bounds on each side; a new Insets the caller owns. Under a parent that is not a Foundation container, the part of its decoration its paintOutsets value leaves in layout, none by default.

Link copied to clipboard
fun repaint(decoratable: Decoratable, tm: Long, x: Int, y: Int, width: Int, height: Int, repaint: (Long, Int, Int, Int, Int) -> Unit)

Hands repaint, the superclass repaint, tm and the area at (x, y) of width by height, in decoratable's coordinates, grown to all a change in it repaints: by how far the steps spread a change, such as a blur's or a shadow's reach, held inside the bounds, or to the whole bounds while the steps move what decoratable paints, as a rotating layer does. On the event dispatch thread, the area is the whole bounds until the paint that DecorationModifierNode.invalidateLayerProperties asked for runs. Content changes must request a repaint for decoration steps to show them on the next paint. Call this from repaint(long, int, int, int, int) of a Decoratable.