The ChatDirector requires a MessageManager, so let's promote that to a real

CrowdContext service instead of sneaking it into the ChatDirector's
constructor. That way other CrowdContext users can make use of the
MessageManager as well.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6192 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2010-10-14 15:45:06 +00:00
parent 706844db08
commit 586b29fa09
4 changed files with 28 additions and 13 deletions
@@ -41,7 +41,6 @@ import com.samskivert.util.ResultListener;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.util.MessageBundle; import com.threerings.util.MessageBundle;
import com.threerings.util.MessageManager;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.util.TimeUtil; import com.threerings.util.TimeUtil;
@@ -136,20 +135,19 @@ public class ChatDirector extends BasicDirector
* @param msgmgr the message manager via which we do our translations. * @param msgmgr the message manager via which we do our translations.
* @param bundle the message bundle from which we obtain our chat-related translation strings. * @param bundle the message bundle from which we obtain our chat-related translation strings.
*/ */
public ChatDirector (CrowdContext ctx, MessageManager msgmgr, String bundle) public ChatDirector (CrowdContext ctx, String bundle)
{ {
super(ctx); super(ctx);
// keep the context around // keep the context around
_ctx = ctx; _ctx = ctx;
_msgmgr = msgmgr;
_bundle = bundle; _bundle = bundle;
// register ourselves as a location observer // register ourselves as a location observer
_ctx.getLocationDirector().addLocationObserver(this); _ctx.getLocationDirector().addLocationObserver(this);
// register our default chat handlers // register our default chat handlers
if (_bundle == null || _msgmgr == null) { if (_bundle == null || _ctx.getMessageManager() == null) {
log.warning("Null bundle or message manager given to ChatDirector"); log.warning("Null bundle or message manager given to ChatDirector");
return; return;
} }
@@ -161,7 +159,7 @@ public class ChatDirector extends BasicDirector
*/ */
protected void registerCommandHandlers () protected void registerCommandHandlers ()
{ {
MessageBundle msg = _msgmgr.getBundle(_bundle); MessageBundle msg = _ctx.getMessageManager().getBundle(_bundle);
registerCommandHandler(msg, "help", new HelpHandler()); registerCommandHandler(msg, "help", new HelpHandler());
registerCommandHandler(msg, "clear", new ClearHandler()); registerCommandHandler(msg, "clear", new ClearHandler());
registerCommandHandler(msg, "speak", new SpeakHandler()); registerCommandHandler(msg, "speak", new SpeakHandler());
@@ -906,7 +904,7 @@ public class ChatDirector extends BasicDirector
*/ */
protected StringBuffer translatedReplacements (String key, StringBuffer buf) protected StringBuffer translatedReplacements (String key, StringBuffer buf)
{ {
MessageBundle bundle = _msgmgr.getBundle(_bundle); MessageBundle bundle = _ctx.getMessageManager().getBundle(_bundle);
if (!bundle.exists(key)) { if (!bundle.exists(key)) {
return buf; return buf;
} }
@@ -1027,8 +1025,8 @@ public class ChatDirector extends BasicDirector
*/ */
protected String xlate (String bundle, String message) protected String xlate (String bundle, String message)
{ {
if (bundle != null && _msgmgr != null) { if (bundle != null && _ctx.getMessageManager() != null) {
MessageBundle msgb = _msgmgr.getBundle(bundle); MessageBundle msgb = _ctx.getMessageManager().getBundle(bundle);
if (msgb == null) { if (msgb == null) {
log.warning("No message bundle available to translate message", "bundle", bundle, log.warning("No message bundle available to translate message", "bundle", bundle,
"message", message); "message", message);
@@ -1405,9 +1403,6 @@ public class ChatDirector extends BasicDirector
/** Provides access to chat-related server-side services. */ /** Provides access to chat-related server-side services. */
protected ChatService _cservice; protected ChatService _cservice;
/** The message manager. */
protected MessageManager _msgmgr;
/** The bundle to use for our own internal messages. */ /** The bundle to use for our own internal messages. */
protected String _bundle; protected String _bundle;
@@ -21,6 +21,8 @@
package com.threerings.crowd.util; package com.threerings.crowd.util;
import com.threerings.util.MessageManager;
import com.threerings.presents.util.PresentsContext; import com.threerings.presents.util.PresentsContext;
import com.threerings.crowd.chat.client.ChatDirector; import com.threerings.crowd.chat.client.ChatDirector;
@@ -49,6 +51,12 @@ public interface CrowdContext extends PresentsContext
*/ */
ChatDirector getChatDirector (); ChatDirector getChatDirector ();
/**
* Returns a reference to the message manager used by the client to generate localized
* messages.
*/
MessageManager getMessageManager ();
/** /**
* When the client enters a new place, the location director creates a * When the client enters a new place, the location director creates a
* place controller which then creates a place view to visualize the * place controller which then creates a place view to visualize the
@@ -157,7 +157,7 @@ public class JabberClient
_locdir = new LocationDirector(_ctx); _locdir = new LocationDirector(_ctx);
_occdir = new OccupantDirector(_ctx); _occdir = new OccupantDirector(_ctx);
_msgmgr = new MessageManager(MESSAGE_MANAGER_PREFIX); _msgmgr = new MessageManager(MESSAGE_MANAGER_PREFIX);
_chatdir = new ChatDirector(_ctx, _msgmgr, null); _chatdir = new ChatDirector(_ctx, null);
} }
/** /**
@@ -206,6 +206,11 @@ public class JabberClient
return _chatdir; return _chatdir;
} }
public MessageManager getMessageManager ()
{
return _msgmgr;
}
public void setPlaceView (PlaceView view) public void setPlaceView (PlaceView view)
{ {
JPanel panel = (JPanel)view; JPanel panel = (JPanel)view;
@@ -49,7 +49,8 @@ public class TestClient
_client = new Client(new UsernamePasswordCreds(new Name(username), "test"), _rqueue); _client = new Client(new UsernamePasswordCreds(new Name(username), "test"), _rqueue);
_locdir = new LocationDirector(_ctx); _locdir = new LocationDirector(_ctx);
_occdir = new OccupantDirector(_ctx); _occdir = new OccupantDirector(_ctx);
_chatdir = new ChatDirector(_ctx, new MessageManager("rsrc"), "global"); _msgmgr = new MessageManager("rsrc");
_chatdir = new ChatDirector(_ctx, "global");
// we want to know about logon/logoff // we want to know about logon/logoff
_client.addClientObserver(this); _client.addClientObserver(this);
@@ -157,6 +158,11 @@ public class TestClient
return _chatdir; return _chatdir;
} }
public MessageManager getMessageManager ()
{
return _msgmgr;
}
public void setPlaceView (PlaceView view) public void setPlaceView (PlaceView view)
{ {
// nothing to do because we don't create views // nothing to do because we don't create views
@@ -173,6 +179,7 @@ public class TestClient
protected LocationDirector _locdir; protected LocationDirector _locdir;
protected OccupantDirector _occdir; protected OccupantDirector _occdir;
protected MessageManager _msgmgr;
protected ChatDirector _chatdir; protected ChatDirector _chatdir;
protected BasicRunQueue _rqueue = new BasicRunQueue(); protected BasicRunQueue _rqueue = new BasicRunQueue();