Package limn.scene

Interface Change

All Known Implementing Classes:
Change.State, Change.TextEdit

public sealed interface Change permits Change.State, Change.TextEdit
What changed on a widget, and what moved it.

Every value but a text edit is interned, so a notification allocates nothing; a text edit allocates one record per edit, and not one per watcher.

This is the payload of the watcher channel (Widget.observeChanges), which hears every change to a widget whatever moved it. The other channel is the handler — the fluent onX slot — which is the application's one response to the user operating the widget, and which runs only for Change.Origin.USER. The whole rule is on Change.Origin.

A change carries no payload beyond the aspect and the origin: it says what changed, and the widget says what it is now. That keeps one type instead of one per widget, keeps every aspect free of boxing, and makes the accessor the single source of truth — at the price of one obligation, which is that no widget announces a state aspect that no public accessor answers.

See Also:
  • Method Details

    • aspect

      Change.Aspect aspect()
      Returns:
      what about the widget changed
    • origin

      Change.Origin origin()
      Returns:
      what moved it
    • fromUser

      default boolean fromUser()
      Returns:
      whether the user operated the widget, which is the only origin a handler runs for
    • of

      static Change of(Change.Aspect aspect, Change.Origin origin)
      The interned value for this pair. Never allocates.
      Parameters:
      aspect - what changed; never Change.Aspect.TEXT
      origin - what moved it
      Returns:
      the one instance for the pair
      Throws:
      IllegalArgumentException - for Change.Aspect.TEXT, which only edit(limn.scene.Change.Origin, int, int, int) can make: TEXT is the one aspect a watcher may narrow on, so it must never arrive as a Change.State and give that watcher a ClassCastException at its own site, with no diagnostic anywhere near the component that announced it
    • edit

      static Change.TextEdit edit(Change.Origin origin, int offset, int removed, int inserted)
      A text edit, with the offsets a platform text-changed event wants. Allocates one record per edit, and not one per watcher.
      Parameters:
      origin - what moved it
      offset - where the damaged range begins, in chars
      removed - how many chars it replaced
      inserted - how many chars it inserted
      Returns:
      the edit