Class SendActionManager

java.lang.Object
org.astrogrid.samp.gui.SendActionManager
Direct Known Subclasses:
AbstractCallActionManager, NotifyActionManager

public abstract class SendActionManager extends Object
Manages actions to send SAMP messages to one or all recipients. The main useful trick that this class can do is to maintain one or more menus for sending messages to suitable recipients. The contents of these menus are updated automatically depending on the subscriptions of all the currently registered SAMP clients.

Note: concrete subclasses must call updateState() before use (in the constructor).

Since:
2 Sep 2008
Author:
Mark Taylor
  • Field Details

    • BROADCAST_TARGET

      public static final String BROADCAST_TARGET
      ComboBox element indicating broadcast to all clients.
      See Also:
  • Constructor Details

    • SendActionManager

      protected SendActionManager(GuiHubConnector connector, ListModel clientListModel)
      Constructor.
      Parameters:
      connector - hub connector
      clientListModel - list model containing only those clients which are suitable recipients; all elements must be Clients
  • Method Details

    • createBroadcastAction

      protected abstract Action createBroadcastAction()
      Returns a new action for broadcast associated with this object. The enabled status of the action will be managed by this object.
      Returns:
      broadcast action; may be null if broadcast is not required
    • getSendAction

      protected abstract Action getSendAction(Client client)
      Returns an action which can perform a single-client send associated with this object. If it implements equals (and hashCode) intelligently there will be efficiency advantages. The enabled status of such actions will be managed by this object.
      Parameters:
      client - recipient client
      Returns:
      action which sends to the given client
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets the enabled status of this object. This acts as a restriction (AND) on the enabled status of the menus and actions controlled by this object. If there are no suitable recipient applications registered they will be disabled anyway.
      Parameters:
      enabled - false to ensure that the actions are disabled, true means they may be enabled
    • getBroadcastAction

      public Action getBroadcastAction()
      Returns an action which will broadcast a message to all suitable registered applications.

      This action is currently not disabled when there are no suitable listeners, mainly for debugging purposes (so you can see if a message is getting sent and what it looks like even in absence of suitable listeners).

      Returns:
      broadcast action
    • createSendMenu

      public JMenu createSendMenu(String name)
      Returns a new menu which provides options to send a message to one of the registered listeners at a time. This menu will be disabled when no suitable listeners are registered.
      Parameters:
      name - menu title
      Returns:
      new message send menu
    • disposeSendMenu

      public void disposeSendMenu(JMenu menu)
      Releases any resources associated with a menu previously created using createSendMenu(java.lang.String). Don't use the menu again.
      Parameters:
      menu - previously created send menu
    • dispose

      public void dispose()
      Releases any resources associated with this object.
    • updateState

      public void updateState()
      Updates the state of actions managed by this object when the list of registered listeners has changed.
    • getClientListModel

      public ListModel getClientListModel()
      Returns the client list to which this manager will offer sends.
      Returns:
      listmodel whose elements are suitably subscribed Clients
    • createTargetSelector

      public ComboBoxModel createTargetSelector()
      Returns a new ComboBoxModel containing selections for each suitable client and an additional selection for broadcast to all clients. Elements are Client objects, or BROADCAST_TARGET to indicate broadcast. The result of this is suitable for use with createTargetAction(javax.swing.ComboBoxModel).
      Returns:
      new client combo box model
    • createTargetAction

      public Action createTargetAction(ComboBoxModel targetSelector)
      Returns an action suitable for sending the message represented by this manager to a target selected by a supplied ComboBoxModel. This model is typically the result of calling createTargetSelector().
      Parameters:
      targetSelector - combo box model in which the elements are Client objects, or BROADCAST_TARGET null to indicate broadcast
    • getConnector

      public GuiHubConnector getConnector()
      Returns this manager's hub connector.
      Returns:
      connector
    • getSendIcon

      public static Icon getSendIcon()
      Returns an icon suitable for depicting a general targetted send.
      Returns:
      send icon
    • getBroadcastIcon

      public static Icon getBroadcastIcon()
      Returns an icon suitable for depicting a general broadcast send.
      Returns:
      broadcast icon