Package org.astrogrid.samp.gui
Class GuiHubConnector
- java.lang.Object
-
- org.astrogrid.samp.client.HubConnector
-
- org.astrogrid.samp.gui.GuiHubConnector
-
- Direct Known Subclasses:
MessageTrackerHubConnector
public class GuiHubConnector extends HubConnector
Extends HubConnector to provide additional graphical functionality. In particular SwingAction
s are provided for hub connection/disconnection and the client list is made available as aListModel
. See thesuperclass
documentation for details of how to use this class. A number of utility methods build on these features to provide Swing components and Actions which can be used directly to populate application menus etc.- Since:
- 25 Nov 2008
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description GuiHubConnector(ClientProfile profile)
Constructs a hub connector based on a given profile instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConnectionListener(javax.swing.event.ChangeListener listener)
Adds a listener which will be notified when this connector registers or unregisters with a hub.protected void
connectionChanged(boolean isConnected)
Method which is called every time this connector changes its connection status (from disconnected to connected, or vice versa).javax.swing.JComponent
createClientBox(boolean vertical, int iconSize)
Creates a component which shows an icon for each registered client.javax.swing.ListCellRenderer
createClientListCellRenderer()
Returns a list cell renderer suitable for use with the client list model returned bygetClientListModel()
.javax.swing.JComponent
createConnectionIndicator()
Creates a component which indicates whether this connector is currently connected or not, using default icons.javax.swing.JComponent
createConnectionIndicator(javax.swing.Icon onIcon, javax.swing.Icon offIcon)
Creates a component which indicates whether this connector is currently connected or not, using supplied icons.javax.swing.Action
createHubAction(boolean external, HubServiceMode hubMode)
Returns an action which will start up a SAMP hub.javax.swing.JComponent
createMonitorPanel()
Returns a new component which displays status for this connector.javax.swing.Action
createRegisterAction()
Returns an action which attempts to register with the hub.javax.swing.Action
createRegisterOrHubAction(java.awt.Component parent, javax.swing.Action[] hubStartActions)
Returns a new action which will register with a hub if one is running, and if not, will offer to start a hub.javax.swing.Action
createShowMonitorAction()
Returns an action which will display a SAMP hub monitor window.javax.swing.Action
createToggleRegisterAction()
Returns an action which toggles hub registration.javax.swing.Action
createUnregisterAction()
Returns an action which attempts to unregister from the hub.javax.swing.ListModel
getClientListModel()
Returns a ListModel containing the registered clients.void
removeConnectionListener(javax.swing.event.ChangeListener listener)
Removes a listener previously added byaddConnectionListener
.-
Methods inherited from class org.astrogrid.samp.client.HubConnector
addMessageHandler, addResponseHandler, call, callAll, callAndWait, computeSubscriptions, configureConnection, createConnection, createTag, declareMetadata, declareSubscriptions, disconnect, getClientMap, getClientSet, getConnection, getMetadata, getSubscriptions, isActive, isConnected, removeMessageHandler, removeResponseHandler, setActive, setAutoconnect
-
-
-
-
Constructor Detail
-
GuiHubConnector
public GuiHubConnector(ClientProfile profile)
Constructs a hub connector based on a given profile instance.- Parameters:
profile
- profile implementation
-
-
Method Detail
-
connectionChanged
protected void connectionChanged(boolean isConnected)
Description copied from class:HubConnector
Method which is called every time this connector changes its connection status (from disconnected to connected, or vice versa). The default implementation does nothing, but it may be overridden by subclasses wishing to be informed of these events.- Overrides:
connectionChanged
in classHubConnector
- Parameters:
isConnected
- true if we've just registered; false if we've just unregistered
-
addConnectionListener
public void addConnectionListener(javax.swing.event.ChangeListener listener)
Adds a listener which will be notified when this connector registers or unregisters with a hub.- Parameters:
listener
- listener to add
-
removeConnectionListener
public void removeConnectionListener(javax.swing.event.ChangeListener listener)
Removes a listener previously added byaddConnectionListener
.- Parameters:
listener
- listener to remove
-
getClientListModel
public javax.swing.ListModel getClientListModel()
Returns a ListModel containing the registered clients. Listeners to this model are correctly notified whenever any change in its contents takes place.- Returns:
- list model containing
Client
objects
-
createClientListCellRenderer
public javax.swing.ListCellRenderer createClientListCellRenderer()
Returns a list cell renderer suitable for use with the client list model returned bygetClientListModel()
.- Returns:
- list cell renderer for Client objects
-
createRegisterAction
public javax.swing.Action createRegisterAction()
Returns an action which attempts to register with the hub. Disabled when already registered.- Returns:
- registration action
-
createUnregisterAction
public javax.swing.Action createUnregisterAction()
Returns an action which attempts to unregister from the hub. Disabled when already unregistered.- Returns:
- unregistration action
-
createToggleRegisterAction
public javax.swing.Action createToggleRegisterAction()
Returns an action which toggles hub registration.- Returns:
- registration toggler action
-
createRegisterOrHubAction
public javax.swing.Action createRegisterOrHubAction(java.awt.Component parent, javax.swing.Action[] hubStartActions)
Returns a new action which will register with a hub if one is running, and if not, will offer to start a hub. The exact options for starting a hub are given by thehubStartActions
parameter - the elements of this array will normally be generated by calling thecreateHubAction
method.- Parameters:
parent
- parent component, used for placing dialoguehubStartActions
- actions which start a hub, or null for a default list
-
createShowMonitorAction
public javax.swing.Action createShowMonitorAction()
Returns an action which will display a SAMP hub monitor window.- Returns:
- monitor window action
-
createHubAction
public javax.swing.Action createHubAction(boolean external, HubServiceMode hubMode)
Returns an action which will start up a SAMP hub. You can specify whether it runs in the current JVM or a newly created one; in the former case, it will shut down when the current application does.- Parameters:
external
- false to run in the current JVM, true to run in a new onehubMode
- hub mode
-
createConnectionIndicator
public javax.swing.JComponent createConnectionIndicator(javax.swing.Icon onIcon, javax.swing.Icon offIcon)
Creates a component which indicates whether this connector is currently connected or not, using supplied icons.- Parameters:
onIcon
- icon indicating connectionoffIcon
- icon indicating no connection- Returns:
- connection indicator
-
createConnectionIndicator
public javax.swing.JComponent createConnectionIndicator()
Creates a component which indicates whether this connector is currently connected or not, using default icons.- Returns:
- connection indicator
-
createClientBox
public javax.swing.JComponent createClientBox(boolean vertical, int iconSize)
Creates a component which shows an icon for each registered client.- Parameters:
vertical
- true for vertical box, false for horizontaliconSize
- dimension in pixel of each icon (square)
-
createMonitorPanel
public javax.swing.JComponent createMonitorPanel()
Returns a new component which displays status for this connector.- Returns:
- new hub connection monitor component
-
-