Class Commander

java.lang.Object
xal.extension.application.Commander
Direct Known Subclasses:
AcceleratorCommander

public class Commander extends Object
The Commander manages the commands (actions and menu handlers) that are used in toolbars, menu items and menus. It creates and returns a menubar and a toolbar based on the menu definition for the application. A default menu definition provides the starting point. A custom menu definition can make changes as needed. This class may optionally be overriden to provide custom commands. Alternatively hooks in ApplicationAdaptor, XalDocument and XalWindow allow custom commands to be specified. The XalWindow creates a commander for its document. The commander builds the menu and toolbar and creates the associated actions. The commander is then disposed.
Author:
tap
  • Field Details

  • Constructor Details

    • Commander

      protected Commander(Commander appCommander, xal.extension.application.XalAbstractDocument document)
      Primary Constructor for generating a document commander.
    • Commander

      protected Commander(Commander appCommander, XalDocument document)
      Constructor for generating a document commander.
    • Commander

      protected Commander(Commander appCommander, XalInternalDocument document)
      Constructor for generating a document commander.
    • Commander

      protected Commander(XalInternalDocument document)
      Constructor for generating a document commander.
    • Commander

      protected Commander(Application application)
      Constructor for generating an application commander.
    • Commander

      protected Commander(DesktopApplication application)
      Constructor for generating a desktop application commander.
  • Method Details

    • loadDefaultBundle

      protected void loadDefaultBundle()
      Load the default bundle.
    • loadCustomBundle

      protected void loadCustomBundle(Application application)
      Load a custom bundle if one exists. If a custom bundle exists, it will override and extend the properties found in the default bundle. You can use it to customize your toolbar, menubar and menus.
      Parameters:
      application - the application for which to load the custom bundle.
    • loadCustomBundle

      protected void loadCustomBundle(Application application, String resourceName)
      Load a custom bundle if one exists. If a custom bundle exists, it will override and extend the properties found in the default bundle. You can use it to customize your toolbar, menubar and menus.
      Parameters:
      application - the application for which to load the custom bundle.
      resourceName - name of the properties resource to load.
    • loadCustomBundle

      protected void loadCustomBundle(xal.extension.application.XalAbstractDocument document)
      Load a custom bundle for the document if one exists. If a custom document bundle exists, it will override and extend the properties found in the application bundle. You can use it to customize your toolbar, menubar and menus.
      Parameters:
      document - the document for which to load the custom bundle.
    • loadCustomDocumentBundle

      protected void loadCustomDocumentBundle(XalInternalDocument document)
      Load a custom bundle for the document if one exists. If a custom document bundle exists, it will override and extend the properties found in the application bundle. You can use it to customize your toolbar, menubar and menus.
      Parameters:
      document - the document for which to load the custom bundle.
    • loadBundle

      protected void loadBundle(URL resourceURL)
      Load a bundle at the specified URL.
      Parameters:
      resourceURL - URL to the resource bundle to load
    • getMenubar

      public JMenuBar getMenubar()
      Make and return a new menubar based on the menu definition file.
      Returns:
      The new menubar
    • getToolbar

      public JToolBar getToolbar()
      Make and return a new toolbar based on the menu definition file.
      Returns:
      The new toolbar
    • getModel

      public ButtonModel getModel(String actionKey)
      Get the button model corresponding to the specified action key.
      Parameters:
      actionKey - the key for which to get the button model.
      Returns:
      the button model.
    • getActionKey

      public String getActionKey(String menuItemKey)
      Get the action key for the specified menu or menu item by its ID.
      Parameters:
      menuItemKey - the ID of the menu item for which to get the label
      Returns:
      the action key for the menu item
    • getLabel

      public String getLabel(String itemID)
      Get the label for the specified item by its ID. Look for a control entry with the item ID followed by ".label". If the label identifier cannot be found then default to the item ID itself as the label.
      Parameters:
      itemID - the ID of the menu item for which to get the label
      Returns:
      the label for the menu item
    • getItemsBefore

      public String[] getItemsBefore(String itemID)
      Get the array of items preceding the specified item
    • getItemsAfter

      public String[] getItemsAfter(String itemID)
      Get the array of items following the specified item
    • getIcon

      public Icon getIcon(String itemID)
      Get the icon for the specified item.
      Parameters:
      itemID - the ID of the menu item for which to get the label
      Returns:
      the icon for the menu or toolbar item
    • getState

      public xal.extension.application.ItemState getState(String itemID)
      Get the state of the item.
    • registerCommands

      protected void registerCommands()
      Register all application commands (default and custom). Some of these commands may be associated with documents.
    • registerDesktopCommands

      protected void registerDesktopCommands()
      Register all application commands (default and custom). Some of these commands may be associated with documents.
    • registerCommands

      protected void registerCommands(XalDocument document)
      Register all document commands (default and custom). Some of these commands may be associated with documents.
      Parameters:
      document - The document for which some commands may need to be associated
    • registerCommands

      protected void registerCommands(XalInternalDocument document)
      Register all document commands (default and custom). Some of these commands may be associated with documents.
      Parameters:
      document - The document for which some commands may need to be associated
    • registerCustomCommands

      protected void registerCustomCommands()
      Subclasses may override this method to provide custom application commands. Alternatively custom commands may be specified in subclasses of XalDocument, XalWindow and ApplicationAdaptor for convenience.
      See Also:
    • registerCustomCommands

      protected void registerCustomCommands(XalDocument document)
      Subclasses may override this method to provide custom document commands. Alternatively custom commands may be specified in subclasses of XalDocument, XalWindow and ApplicationAdaptor for convenience.
      Parameters:
      document - The document for which some commands may need to be associated
      See Also:
    • registerCustomCommands

      protected void registerCustomCommands(XalInternalDocument document)
      Subclasses may override this method to provide custom document commands. Alternatively custom commands may be specified in subclasses of XalInternalDocument, XalInternalWindow and ApplicationAdaptor for convenience.
      Parameters:
      document - The document for which some commands may need to be associated
      See Also:
    • getAction

      public Action getAction(String actionName)
      Get the action with the given name.
      Parameters:
      actionName - The name of the action to get.
      Returns:
      The action with the given name.
    • registerAction

      public void registerAction(Action action)
      Register the action to be used by the commander. Every action should have a unique name because the commander fetches actions by name.
      Parameters:
      action - The action to register.
    • registerAction

      public void registerAction(Action action, ButtonModel model)
      Register the action and button model to be used by the commander. Every action should have a unique name because the commander fetches actions by name.
      Parameters:
      action - The action to register.
      model - The button model to associate with the action.
    • registerModel

      public void registerModel(String name, ButtonModel model)
      Register the action to be used by the commander. Every action should have a unique name because the commander fetches actions by name.
      Parameters:
      name - The name to key the model with a button or menu item.
      model - The button model to associate with the action.
    • registerMenuHandler

      public void registerMenuHandler(MenuListener handler, String name)
      Register the menu handler to be used by the commander. Associate the specified name with the menu handler.
      Parameters:
      handler - The handler to register
      name - The unique name to associate with the handler
    • registerTextCommands

      protected void registerTextCommands()
      Register the actions associated with text components.