Class BoundCommand

java.lang.Object
be.imgn.swing.ui.BoundCommand
All Implemented Interfaces:
DynamicEntry, MenuEntry, ToolBarEntry

public final class BoundCommand extends Object implements MenuEntry, DynamicEntry, ToolBarEntry
A command of a view, turned into Swing objects. Each created component shares the command's Action, so text, icon, tooltip, enabled and selected state stay in sync.
  • Method Details

    • id

      public String id()
      Returns the id, also the action command of every component created for the command.
      Returns:
      the id
    • createButton

      public JButton createButton()
      Returns a new button for the command.
      Returns:
      the button
    • createMenuItem

      public JMenuItem createMenuItem()
      Returns a new menu item for the command.
      Returns:
      the menu item
    • createToggleButton

      public JToggleButton createToggleButton()
      Returns a new toggle button for a command with a selected state.
      Returns:
      the toggle button
      Throws:
      IllegalStateException - if the command has no selected state
    • createCheckBoxMenuItem

      public JCheckBoxMenuItem createCheckBoxMenuItem()
      Returns a new check box menu item for a command with a selected state.
      Returns:
      the menu item
      Throws:
      IllegalStateException - if the command has no selected state
    • asAction

      public Action asAction()
      Returns the command's Swing action, the same on each call.
      Returns:
      the action
    • execute

      public boolean execute()
      Runs the command as if activated, with a Trigger.Programmatic trigger and no modifier, if it is enabled.
      Returns:
      true if the command ran, false if it is disabled
    • execute

      public boolean execute(CommandContext context)
      Runs the command as if activated, if it is enabled: whether it is enabled is the enabled observable's current value, not the state of the Action, which follows it one posted update later.
      Parameters:
      context - how the command was activated
      Returns:
      true if the command ran, false if it is disabled
    • running

      public Observable<Boolean> running()
      Returns whether the command is running: true from the moment it starts a task until every task it started has ended, waiting ones included; false otherwise. A task has ended once its last hook has run, and the value changes on the EDT, after those hooks. A command whose handler returns void, or returns Task.none(), starts nothing, so it isn't running.
      Returns:
      whether the command is running
    • cancel

      public void cancel()
      Cancels every task the command started that hasn't ended, waiting ones included; does nothing when there is none. It may be called from any thread, and runs on the EDT, as execute() does.
    • toString

      public String toString()
      Overrides:
      toString in class Object