Package org.astrogrid.samp.gui
Class SendActionManager
java.lang.Object
org.astrogrid.samp.gui.SendActionManager
- Direct Known Subclasses:
AbstractCallActionManager
,NotifyActionManager
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
FieldsModifier and TypeFieldDescriptionstatic final String
ComboBox element indicating broadcast to all clients. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SendActionManager
(GuiHubConnector connector, ListModel clientListModel) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Action
Returns a new action for broadcast associated with this object.createSendMenu
(String name) Returns a new menu which provides options to send a message to one of the registered listeners at a time.createTargetAction
(ComboBoxModel targetSelector) Returns an action suitable for sending the message represented by this manager to a target selected by a supplied ComboBoxModel.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
(JMenu menu) Releases any resources associated with a menu previously created usingcreateSendMenu(java.lang.String)
.Returns an action which will broadcast a message to all suitable registered applications.static Icon
Returns an icon suitable for depicting a general broadcast send.Returns the client list to which this manager will offer sends.Returns this manager's hub connector.protected abstract Action
getSendAction
(Client client) Returns an action which can perform a single-client send associated with this object.static Icon
Returns an icon suitable for depicting a general targetted send.void
setEnabled
(boolean enabled) Sets the enabled status of this object.void
Updates the state of actions managed by this object when the list of registered listeners has changed.
-
Field Details
-
BROADCAST_TARGET
ComboBox element indicating broadcast to all clients.- See Also:
-
-
Constructor Details
-
SendActionManager
Constructor.- Parameters:
connector
- hub connectorclientListModel
- list model containing only those clients which are suitable recipients; all elements must beClient
s
-
-
Method Details
-
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
Returns an action which can perform a single-client send associated with this object. If it implementsequals
(andhashCode
) 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
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
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
Releases any resources associated with a menu previously created usingcreateSendMenu(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
Returns the client list to which this manager will offer sends.- Returns:
- listmodel whose elements are suitably subscribed
Client
s
-
createTargetSelector
Returns a new ComboBoxModel containing selections for each suitable client and an additional selection for broadcast to all clients. Elements areClient
objects, orBROADCAST_TARGET
to indicate broadcast. The result of this is suitable for use withcreateTargetAction(javax.swing.ComboBoxModel)
.- Returns:
- new client combo box model
-
createTargetAction
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 callingcreateTargetSelector()
.- Parameters:
targetSelector
- combo box model in which the elements areClient
objects, orBROADCAST_TARGET
null to indicate broadcast
-
getConnector
Returns this manager's hub connector.- Returns:
- connector
-
getSendIcon
Returns an icon suitable for depicting a general targetted send.- Returns:
- send icon
-
getBroadcastIcon
Returns an icon suitable for depicting a general broadcast send.- Returns:
- broadcast icon
-