Klasse FxRefresh

java.lang.Object
com.dua3.utility.fx.FxRefresh

public final class FxRefresh extends Object
A class intended for controlling possibly long-running update operations. Refreshs happen mutually exclusive, i.e. the update tasks do not have to be explicitly synchronized as long as not called directly from other code. An example is updating a JavaFX node. I.e., if redraw requests come in before the current drawing finishes, the application becomes sluggish or burns CPU cycles for drawing outdated data. The FxRefresher automatically skips intermediate frames if redraw requests come in too fast for the drawing to come up with.
  • Methodendetails

    • stop

      public void stop()
      Stop the refresher.
    • create

      public static FxRefresh create(String name, Runnable task)
      Create new instance. The initial state is active.
      Parameter:
      name - the name for the instance
      task - the task to call when refreshing
      Gibt zurück:
      new instance
    • create

      public static FxRefresh create(String name, Runnable task, boolean active)
      Create new instance.
      Parameter:
      name - the name for the instance
      task - the task to call when refreshing
      active - the initial active state
      Gibt zurück:
      new instance
    • create

      public static FxRefresh create(String name, Runnable task, Node node)
      Create a refresher instance for a JavaFX Node. The refresher will prevent updates when the node is hidden. The refresher is stopped when the node is removed from the scene graph. The initial state is active.
      Parameter:
      name - the refresher name
      task - the task to run on refresh
      node - the node associated with this refresher
      Gibt zurück:
      new instance
    • create

      public static FxRefresh create(String name, Runnable task, Node node, boolean active)
      Create a refresher instance for a JavaFX Node. The refresher will prevent updates when the node is hidden. The refresher is stopped when the node is removed from the scene graph.
      Parameter:
      name - the refresher name
      task - the task to run on refresh
      node - the node associated with this refresher
      active - the initial active state
      Gibt zurück:
      new instance
    • isRunning

      public boolean isRunning()
      Check if the refresher has been started. Note that it's possible that the refresher is running, but inactive, i.e. if the window is hidden.
      Gibt zurück:
      true, if the refresher is running
    • isActive

      public boolean isActive()
      Check active state.
      Gibt zurück:
      true if active
    • setActive

      public void setActive(boolean flag)
      Set active state.
      Parameter:
      flag - whether to activate or deactivate the refresher
    • refresh

      public void refresh()
      Request refresh. The refresh will be performed as soon as all the following are met:
      • the refresher is running
      • the refresher's state is "active"
      • no other request is running
      • no newer request was queued (in that case, the older request will be skipped)