// Path: toybox/src/main/java/com/threerings/toybox/data/ToyBoxCodes.java
// public class ToyBoxCodes implements InvocationCodes
// {
//     /** Defines our invocation services group. */
//     public static final String TOYBOX_GROUP = "toybox";
// 
//     /** Defines the general ToyBox translation message bundle.*/
//     public static final String TOYBOX_MSGS = "toybox";
// 
//     /** An error constant returned by the {@link ToyBoxService}. */
//     public static final String ERR_NO_SUCH_GAME =
//         MessageUtil.qualify(TOYBOX_MSGS, "e.no_such_game");
// 
//     /** An error constant indicating a malformed game definition. */
//     public static final String ERR_MALFORMED_GAMEDEF =
//         MessageUtil.qualify(TOYBOX_MSGS, "e.malformed_gamedef");
// }
// 
// Path: toybox/src/main/java/com/threerings/toybox/util/ToyBoxContext.java
// public abstract class ToyBoxContext implements ParlorContext
// {
//     /**
//      * Returns a reference to the message manager used by the client to
//      * generate localized messages.
//      */
//     public abstract MessageManager getMessageManager ();
// 
//     /**
//      * Returns a reference to our ToyBox director.
//      */
//     public abstract ToyBoxDirector getToyBoxDirector ();
// 
//     /**
//      * Returns a reference to our frame manager (used for media services).
//      */
//     public abstract FrameManager getFrameManager ();
// 
//     /**
//      * Returns a reference to our key dispatcher.
//      */
//     public abstract KeyDispatcher getKeyDispatcher ();
// 
//     /**
//      * Returns the resource manager which is used to load media resources.
//      */
//     public ResourceManager getResourceManager ()
//     {
//         return getToyBoxDirector().getResourceManager();
//     }
// 
//     /**
//      * Translates the specified message using the specified message bundle.
//      */
//     public String xlate (String bundle, String message)
//     {
//         MessageBundle mb = getMessageManager().getBundle(bundle);
//         return (mb == null) ? message : mb.xlate(message);
//     }
// 
//     /**
//      * Convenience method to get the username of the currently logged on
//      * user. Returns null when we're not logged on.
//      */
//     public Name getUsername ()
//     {
//         BodyObject bobj = (BodyObject)getClient().getClientObject();
//         return (bobj == null) ? null : bobj.getVisibleName();
//     }
// 
//     /**
//      * Convenience method to load an image from our resource bundles.
//      */
//     public BufferedImage loadImage (String rsrcPath)
//     {
//         try {
//             return getResourceManager().getImageResource(rsrcPath);
//         } catch (IOException ioe) {
//             log.warning("Unable to load image resource [path=" + rsrcPath + "].", ioe);
//             // cope; return an error image of abitrary size
//             return ImageUtil.createErrorImage(50, 50);
//         }
//     }
// }
// 
// Path: toybox/src/main/java/com/threerings/toybox/Log.java
// public static Logger log = Logger.getLogger("com.threerings.toybox");


import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JViewport;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import com.samskivert.swing.GroupLayout;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.VGroupLayout;
import com.samskivert.swing.event.AncestorAdapter;
import com.samskivert.util.StringUtil;
import com.threerings.util.MessageBundle;
import com.threerings.crowd.chat.client.ChatDirector;
import com.threerings.crowd.chat.client.ChatDisplay;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.chat.data.SystemMessage;
import com.threerings.crowd.chat.data.TellFeedbackMessage;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.client.OccupantObserver;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.OccupantInfo;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.toybox.data.ToyBoxCodes;
import com.threerings.toybox.util.ToyBoxContext;
import static com.threerings.toybox.Log.log;
    protected void appendAndScroll (String message, Style style)
    {
        if (_text.getDocument().getLength() > 0) {
            message = "\n" + message;
        }
        append(message, style);
        _text.scrollRectToVisible(new Rectangle(0, _text.getHeight(), _text.getWidth(), 1));
    }

    protected void appendAndScroll (String speaker, String message, Style style)
    {
        if (_text.getDocument().getLength() > 0) {
            speaker = "\n" + speaker;
        }
        append(speaker + " ", _nameStyle);
        append(message, style);

        _text.scrollRectToVisible(
            new Rectangle(0, _text.getHeight(), _text.getWidth(), 1));
    }

    /**
     * Append the specified text in the specified style.
     */
    protected void append (String text, Style style)
    {
        Document doc = _text.getDocument();
        try {
            doc.insertString(doc.getLength(), text, style);
        } catch (BadLocationException ble) {
// Path: toybox/src/main/java/com/threerings/toybox/data/ToyBoxCodes.java
// public class ToyBoxCodes implements InvocationCodes
// {
//     /** Defines our invocation services group. */
//     public static final String TOYBOX_GROUP = "toybox";
// 
//     /** Defines the general ToyBox translation message bundle.*/
//     public static final String TOYBOX_MSGS = "toybox";
// 
//     /** An error constant returned by the {@link ToyBoxService}. */
//     public static final String ERR_NO_SUCH_GAME =
//         MessageUtil.qualify(TOYBOX_MSGS, "e.no_such_game");
// 
//     /** An error constant indicating a malformed game definition. */
//     public static final String ERR_MALFORMED_GAMEDEF =
//         MessageUtil.qualify(TOYBOX_MSGS, "e.malformed_gamedef");
// }
// 
// Path: toybox/src/main/java/com/threerings/toybox/util/ToyBoxContext.java
// public abstract class ToyBoxContext implements ParlorContext
// {
//     /**
//      * Returns a reference to the message manager used by the client to
//      * generate localized messages.
//      */
//     public abstract MessageManager getMessageManager ();
// 
//     /**
//      * Returns a reference to our ToyBox director.
//      */
//     public abstract ToyBoxDirector getToyBoxDirector ();
// 
//     /**
//      * Returns a reference to our frame manager (used for media services).
//      */
//     public abstract FrameManager getFrameManager ();
// 
//     /**
//      * Returns a reference to our key dispatcher.
//      */
//     public abstract KeyDispatcher getKeyDispatcher ();
// 
//     /**
//      * Returns the resource manager which is used to load media resources.
//      */
//     public ResourceManager getResourceManager ()
//     {
//         return getToyBoxDirector().getResourceManager();
//     }
// 
//     /**
//      * Translates the specified message using the specified message bundle.
//      */
//     public String xlate (String bundle, String message)
//     {
//         MessageBundle mb = getMessageManager().getBundle(bundle);
//         return (mb == null) ? message : mb.xlate(message);
//     }
// 
//     /**
//      * Convenience method to get the username of the currently logged on
//      * user. Returns null when we're not logged on.
//      */
//     public Name getUsername ()
//     {
//         BodyObject bobj = (BodyObject)getClient().getClientObject();
//         return (bobj == null) ? null : bobj.getVisibleName();
//     }
// 
//     /**
//      * Convenience method to load an image from our resource bundles.
//      */
//     public BufferedImage loadImage (String rsrcPath)
//     {
//         try {
//             return getResourceManager().getImageResource(rsrcPath);
//         } catch (IOException ioe) {
//             log.warning("Unable to load image resource [path=" + rsrcPath + "].", ioe);
//             // cope; return an error image of abitrary size
//             return ImageUtil.createErrorImage(50, 50);
//         }
//     }
// }
// 
// Path: toybox/src/main/java/com/threerings/toybox/Log.java
// public static Logger log = Logger.getLogger("com.threerings.toybox");


// Path: toybox/src/main/java/com/threerings/toybox/client/ChatPanel.java
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JViewport;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import com.samskivert.swing.GroupLayout;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.VGroupLayout;
import com.samskivert.swing.event.AncestorAdapter;
import com.samskivert.util.StringUtil;
import com.threerings.util.MessageBundle;
import com.threerings.crowd.chat.client.ChatDirector;
import com.threerings.crowd.chat.client.ChatDisplay;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.chat.data.SystemMessage;
import com.threerings.crowd.chat.data.TellFeedbackMessage;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.client.OccupantObserver;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.OccupantInfo;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.toybox.data.ToyBoxCodes;
import com.threerings.toybox.util.ToyBoxContext;
import static com.threerings.toybox.Log.log;

    protected void appendAndScroll (String message, Style style)
    {
        if (_text.getDocument().getLength() > 0) {
            message = "\n" + message;
        }
        append(message, style);
        _text.scrollRectToVisible(new Rectangle(0, _text.getHeight(), _text.getWidth(), 1));
    }

    protected void appendAndScroll (String speaker, String message, Style style)
    {
        if (_text.getDocument().getLength() > 0) {
            speaker = "\n" + speaker;
        }
        append(speaker + " ", _nameStyle);
        append(message, style);

        _text.scrollRectToVisible(
            new Rectangle(0, _text.getHeight(), _text.getWidth(), 1));
    }

    /**
     * Append the specified text in the specified style.
     */
    protected void append (String text, Style style)
    {
        Document doc = _text.getDocument();
        try {
            doc.insertString(doc.getLength(), text, style);
        } catch (BadLocationException ble) {
            log.warning("Unable to insert text!?", "error", ble);