Class SendActionManager

  • Direct Known Subclasses:
    AbstractCallActionManager, NotifyActionManager

    public abstract class SendActionManager
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BROADCAST_TARGET
      ComboBox element indicating broadcast to all clients.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SendActionManager​(GuiHubConnector connector, javax.swing.ListModel clientListModel)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract javax.swing.Action createBroadcastAction()
      Returns a new action for broadcast associated with this object.
      javax.swing.JMenu createSendMenu​(java.lang.String name)
      Returns a new menu which provides options to send a message to one of the registered listeners at a time.
      javax.swing.Action createTargetAction​(javax.swing.ComboBoxModel targetSelector)
      Returns an action suitable for sending the message represented by this manager to a target selected by a supplied ComboBoxModel.
      javax.swing.ComboBoxModel createTargetSelector()
      Returns a new ComboBoxModel containing selections for each suitable client and an additional selection for broadcast to all clients.
      void dispose()
      Releases any resources associated with this object.
      void disposeSendMenu​(javax.swing.JMenu menu)
      Releases any resources associated with a menu previously created using createSendMenu(java.lang.String).
      javax.swing.Action getBroadcastAction()
      Returns an action which will broadcast a message to all suitable registered applications.
      static javax.swing.Icon getBroadcastIcon()
      Returns an icon suitable for depicting a general broadcast send.
      javax.swing.ListModel getClientListModel()
      Returns the client list to which this manager will offer sends.
      GuiHubConnector getConnector()
      Returns this manager's hub connector.
      protected abstract javax.swing.Action getSendAction​(Client client)
      Returns an action which can perform a single-client send associated with this object.
      static javax.swing.Icon getSendIcon()
      Returns an icon suitable for depicting a general targetted send.
      void setEnabled​(boolean enabled)
      Sets the enabled status of this object.
      void updateState()
      Updates the state of actions managed by this object when the list of registered listeners has changed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BROADCAST_TARGET

        public static final java.lang.String BROADCAST_TARGET
        ComboBox element indicating broadcast to all clients.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SendActionManager

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

      • createBroadcastAction

        protected abstract javax.swing.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 javax.swing.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 javax.swing.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 javax.swing.JMenu createSendMenu​(java.lang.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​(javax.swing.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 javax.swing.ListModel getClientListModel()
        Returns the client list to which this manager will offer sends.
        Returns:
        listmodel whose elements are suitably subscribed Clients
      • createTargetSelector

        public javax.swing.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 javax.swing.Action createTargetAction​(javax.swing.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 javax.swing.Icon getSendIcon()
        Returns an icon suitable for depicting a general targetted send.
        Returns:
        send icon
      • getBroadcastIcon

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