public class GuiHubConnector extends HubConnector
Action
s are provided for
hub connection/disconnection
and the client list is made available as a ListModel
.
See the superclass
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.Modifier and Type | Class and Description |
---|---|
(package private) static interface |
GuiHubConnector.ConnectionUpdate
Interface defining how an object is to be notified when the hub
connection status changes.
|
private class |
GuiHubConnector.HubAction
Action subclass for running a hub.
|
private static class |
GuiHubConnector.ListModelTrackedClientSet
TrackedClientSet implementation used by this class.
|
private class |
GuiHubConnector.MonitorAction
Action subclass for popping up a monitor window.
|
private class |
GuiHubConnector.RegisterAction
Action which registers and unregisters with the hub.
|
Modifier and Type | Field and Description |
---|---|
private javax.swing.ListModel |
clientListModel_ |
private java.util.List |
connectionListenerList_ |
(package private) static GuiHubConnector.ConnectionUpdate |
DISABLE_ACTION |
(package private) static GuiHubConnector.ConnectionUpdate |
ENABLE_ACTION |
(package private) static GuiHubConnector.ConnectionUpdate |
ENABLE_COMPONENT |
(package private) static GuiHubConnector.ConnectionUpdate |
REPAINT_COMPONENT |
private java.util.Map |
updateMap_ |
private boolean |
wasConnected_ |
Constructor and Description |
---|
GuiHubConnector(ClientProfile profile)
Constructs a hub connector based on a given profile instance.
|
Modifier and Type | Method and 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).
|
(package private) static javax.swing.border.Border |
createBoxBorder()
Returns a border suitable for icon boxes.
|
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 by
getClientListModel() . |
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.
|
(package private) void |
registerUpdater(java.lang.Object item,
GuiHubConnector.ConnectionUpdate updater)
Adds a given item to the list of objects which will be notified
when the hub is connected/disconnected.
|
void |
removeConnectionListener(javax.swing.event.ChangeListener listener)
Removes a listener previously added by
addConnectionListener . |
private void |
scheduleConnectionChange()
Called when the connection status (registered/unregistered) may have
changed.
|
private void |
updateConnectionState()
Called when the connection status has changed, or may have changed.
|
addMessageHandler, addResponseHandler, call, callAll, callAndWait, computeSubscriptions, configureConnection, createConnection, createTag, declareMetadata, declareSubscriptions, disconnect, getClientMap, getClientSet, getConnection, getMetadata, getSubscriptions, isConnected, removeMessageHandler, removeResponseHandler, setActive, setAutoconnect
private final javax.swing.ListModel clientListModel_
private final java.util.List connectionListenerList_
private final java.util.Map updateMap_
private boolean wasConnected_
static GuiHubConnector.ConnectionUpdate ENABLE_ACTION
static GuiHubConnector.ConnectionUpdate DISABLE_ACTION
static GuiHubConnector.ConnectionUpdate REPAINT_COMPONENT
static GuiHubConnector.ConnectionUpdate ENABLE_COMPONENT
public GuiHubConnector(ClientProfile profile)
profile
- profile implementationprotected void connectionChanged(boolean isConnected)
HubConnector
connectionChanged
in class HubConnector
isConnected
- true if we've just registered;
false if we've just unregisteredpublic void addConnectionListener(javax.swing.event.ChangeListener listener)
listener
- listener to addpublic void removeConnectionListener(javax.swing.event.ChangeListener listener)
addConnectionListener
.listener
- listener to removepublic javax.swing.ListModel getClientListModel()
Client
objectspublic javax.swing.ListCellRenderer createClientListCellRenderer()
getClientListModel()
.public javax.swing.Action createRegisterAction()
public javax.swing.Action createUnregisterAction()
public javax.swing.Action createToggleRegisterAction()
public javax.swing.Action createRegisterOrHubAction(java.awt.Component parent, javax.swing.Action[] hubStartActions)
hubStartActions
parameter - the elements of this array
will normally be generated by calling the
createHubAction
method.parent
- parent component, used for placing dialoguehubStartActions
- actions which start a hub,
or null for a default listpublic javax.swing.Action createShowMonitorAction()
public javax.swing.Action createHubAction(boolean external, HubServiceMode hubMode)
external
- false to run in the current JVM,
true to run in a new onehubMode
- hub modepublic javax.swing.JComponent createConnectionIndicator(javax.swing.Icon onIcon, javax.swing.Icon offIcon)
onIcon
- icon indicating connectionoffIcon
- icon indicating no connectionpublic javax.swing.JComponent createConnectionIndicator()
public javax.swing.JComponent createClientBox(boolean vertical, int iconSize)
vertical
- true for vertical box, false for horizontaliconSize
- dimension in pixel of each icon (square)public javax.swing.JComponent createMonitorPanel()
private void scheduleConnectionChange()
private void updateConnectionState()
static javax.swing.border.Border createBoxBorder()
void registerUpdater(java.lang.Object item, GuiHubConnector.ConnectionUpdate updater)
item
- object to be notifiedupdater
- object which performs the notification on hub
connect/disconnect