DrawModifierNode

A SwingModifier.ComponentNode that draws into its component.

It is a DecorationModifierNode whose paint runs draw: the component must be Decoratable, and draw nodes and decorations run in the order the modifier declares them. The element declaring a draw node is additive, and a child declares it through decoration.

Snapshot state read in draw is observed: a change to it repaints the component, without laying it out again.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard
val coroutineScope: CoroutineScope
Link copied to clipboard
Link copied to clipboard
override val isOpaque: Boolean

A draw node may leave part of its area unpainted.

Link copied to clipboard
override val outsets: Insets

A draw node paints nothing past its box.

Link copied to clipboard

Draw nodes have fixed decoration metadata and request their own repaint when their drawing changes.

Functions

Link copied to clipboard
abstract fun ContentDrawScope.draw()

Draws this node on the event dispatch thread. ContentDrawScope.size is the size of this node's decorated box.

Link copied to clipboard

Gathers the component's decoration again, after this step's outsets or isOpaque changed between modifier passes, and repaints it. An element's update needs no call. Does nothing while the node is not attached.

Link copied to clipboard

Repaints this node's component, so DrawModifierNode.draw runs again. Does nothing while it is not attached.

Link copied to clipboard
open fun needsPaintBounds(width: Int, height: Int): Boolean

Whether this decorator needs the component's paint bounds worked out, through paintBounds, while no visible child has an edge past the layout bounds and no decorator has outsets; true by default. A child with an edge past the layout bounds, or a decorator with outsets, has them worked out whatever this answers. Return false only when this decorator, in a box of width by height, cannot enlarge a box-sized content's paint bounds beyond its outsets.

Link copied to clipboard
override fun onAttach()

Refuses an element that is not additive. An element naming Decoratable as its target type is refused before this node is created; otherwise this node is refused if the component is not a Decoratable.

Link copied to clipboard
override fun onDetach()

Runs onRemovedFromDecoration. The component is handed the decoration without this step once the modifier pass ends.

Link copied to clipboard

Called before the next draw once the size this node draws in has changed, and before the first one.

Link copied to clipboard
open fun onReset()
Link copied to clipboard
override fun paint(graphics: Graphics2D, width: Int, height: Int, content: (Graphics2D, Int, Int) -> Unit)
Link copied to clipboard
open fun paintBounds(content: Shape, width: Int, height: Int): Shape

The area this decorator and its content can paint, in a box of width by height. The default includes the box and the content's bounds, grown by outsets. Override this when painting, clipping, or transforming content changes that area. The returned shape reserves paint space, not a clip. It also decides hit testing past the layout bounds: a press there reaches a child only where the paint bounds of a one-pixel content at the point cover the point.

Link copied to clipboard