ymsg.support
Class SwingModelFactory

Object
  extended bySessionAdapter
      extended bySwingModelFactory
All Implemented Interfaces:
SessionListener

public class SwingModelFactory
extends SessionAdapter

A handy class for creating self-updating models for use with Swing's MVC scheme.

This class is rather clever. It will register itself with the session provided, and enacts any events from said session on the model objects it creates automatically. Eg, having created a ListModel for a chat room, this class will automatically update the ListModel's status, based upon messages received from Yahoo (or rather, the session events they generate).

The result is that users coming and going, or changing their status, will be automatically reflected by the model, and any Swing component 'listening' will be told to update its display. (For best results, take advantage of Swing's 'cell renderer' scheme to include status icons etc, based upon data provided by these models.)

Note: you should not create duplicate models for the same data, as subsequent calls will create models which superceed previous models. Each source of data, be it the user's groups, or a chat room, should have only one model created for it, which should then be passed to all Swing components which need to use that model. (This is how MVC is supposed to work anyway - with single models for each distinct data source.)

Technical note: this class uses weak references to map the objects it creates. The models are automatically freed for garbage collection once there are no strong references left outside the factory instance.

This is an experimental class, with only basic testing applied. Please report all bugs via the usual channels.

Since:
1.0

Constructor Summary
SwingModelFactory(Session ss)
          Create a model factory.
 
Method Summary
 javax.swing.ListModel createListModel(YahooChatLobby ycl, boolean sort)
          Create a Swing ListModel, based upon the activities of the users in a given chatroom lobby.
 javax.swing.ListModel createListModel(YahooConference yc, boolean sort)
          Create a Swing ListModel, based upon the activities of the users in a given conference.
 javax.swing.tree.TreeModel createTreeModel(boolean sort)
          Create a Swing TreeModel, based upon the activities of the users in the session's friends groups.
static javax.swing.ListModel getEmptyListModel()
          Convenience method to create an empty list model.
 
Methods inherited from class SessionAdapter
buzzReceived, chatConnectionClosed, chatLogoffReceived, chatLogonReceived, chatMessageReceived, chatUserUpdateReceived, conferenceInviteDeclinedReceived, conferenceInviteReceived, conferenceLogoffReceived, conferenceLogonReceived, conferenceMessageReceived, connectionClosed, contactRejectionReceived, contactRequestReceived, errorPacketReceived, fileTransferReceived, friendAddedReceived, friendRemovedReceived, friendsUpdateReceived, inputExceptionThrown, listReceived, messageReceived, newMailReceived, notifyReceived, offlineMessageReceived
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface SessionListener
errorMessageReceived
 

Constructor Detail

SwingModelFactory

public SwingModelFactory(Session ss)
Create a model factory. All models will be based upon the session object provided.

Note: this method will attempt to register listeners with the given session.

Parameters:
ss - session
Since:
1.0
Method Detail

createListModel

public javax.swing.ListModel createListModel(YahooChatLobby ycl,
                                             boolean sort)
Create a Swing ListModel, based upon the activities of the users in a given chatroom lobby.

Note: please only create one model per lobby. Future implementations of this method may refuse to work a second time for a given lobby..

Parameters:
ycl - the lobby to model
sort - true if the list is to be kept sorted
Returns:
Swing ListModel
Since:
1.0

createListModel

public javax.swing.ListModel createListModel(YahooConference yc,
                                             boolean sort)
Create a Swing ListModel, based upon the activities of the users in a given conference.

Note: please only create one model per conference. Future implementations of this method may refuse to work a second time for a given conference..

Note: this model is, as yet, not fully implemented/tested.

Parameters:
yc - the conference to model
sort - true if the list is to be kept sorted
Returns:
Swing ListModel
Since:
1.0

createTreeModel

public javax.swing.tree.TreeModel createTreeModel(boolean sort)
Create a Swing TreeModel, based upon the activities of the users in the session's friends groups.

Note: please only create model per session. Future implementations of this method may refuse to work a second time..

Parameters:
sort - true if the list is to be kept sorted
Returns:
Swing TreeModel
Since:
1.0

getEmptyListModel

public static javax.swing.ListModel getEmptyListModel()
Convenience method to create an empty list model. Useful for blanking a Swing JList in between leaving one chatroom and joining another. (Swing doesn't seem to provide a way to 'unset' a model once one has been set, to get the JList to return to a default empty list!)

Returns:
Swing ListModel
Since:
1.0