com.threerings.chat
Class ComicChatOverlay

java.lang.Object
  extended by com.threerings.chat.ChatOverlay
      extended by com.threerings.chat.SubtitleChatOverlay
          extended by com.threerings.chat.ComicChatOverlay
All Implemented Interfaces:
com.threerings.crowd.chat.client.ChatDisplay, com.threerings.crowd.chat.client.HistoryList.Observer, EventListener, ChangeListener

public class ComicChatOverlay
extends SubtitleChatOverlay

Implements comic chat in the yohoho client.


Nested Class Summary
protected static class ComicChatOverlay.BubbleGlyph
          A glyph of a particlar chat bubble
 
Nested classes/interfaces inherited from class com.threerings.chat.ChatOverlay
ChatOverlay.InfoProvider
 
Field Summary
protected  List<ComicChatOverlay.BubbleGlyph> _bubbles
          The currently displayed bubble areas.
protected  int _newPlacePoint
          The place in our history at which we last entered a new place.
protected static Color[] BACKGROUNDS
          The background colors to use when drawing bubbles.
protected static int BUBBLE_SPACING
          The space we force between adjacent bubbles.
protected static double GOLDEN
          The golden ratio.
protected static int MAX_BUBBLES
          The maximum number of bubbles to show.
protected static int MAX_BUBBLES_PER_USER
          The maximum number of bubbles to show per user.
protected static int MINIMUM_SPLIT_WIDTH
          The minimum width of a bubble's label before we consider splitting lines.
protected static int SPEAKER_DISTANCE
          The distance to stay from the speaker.
protected static int TAIL_WIDTH
          The width of the end of the tail.
 
Fields inherited from class com.threerings.chat.SubtitleChatOverlay
_histOffset, _histOffsetFinal, _history, _historyExtent, _historyModel, _laidout, _lastExpire, _overrideHistory, _scrollbar, _showingHistory, _subtitleHeight, _subtitles, _subtitlesFill, _subtitleXSpacing, _subtitleYSpacing, ICON_PADDING, PAD, SUBTITLE_HEIGHT_GUESS
 
Fields inherited from class com.threerings.chat.ChatOverlay
_ctx, _dimmed, _logic, _provider, _target
 
Constructor Summary
ComicChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar historyBar, int subtitleHeight)
          Construct a comic chat overlay.
 
Method Summary
protected  Point adjustLabel(int type, Point labelpos)
          Position the label based on the type.
 void clear()
           
protected  void clearBubbles(boolean all)
          Clear chat bubbles, either all of them or just the place-oriented ones.
protected  boolean createBubble(Graphics2D gfx, int type, long timestamp, String text, Name speaker, Point speakerloc)
          Create a chat bubble with the specified type and text.
protected  void displayMessage(com.threerings.crowd.chat.data.ChatMessage message, int type, Graphics2D layoutGfx)
          Display the message after we've decided which type it is.
protected  List<ComicChatOverlay.BubbleGlyph> getAndExpireBubbles(Name speaker)
          Expire a bubble, if necessary, and return the old bubbles for the specified speaker.
protected  List<Shape> getAvoidList(Name speaker)
          Return a list of rectangular areas that we should avoid while laying out a bubble for the specified speaker.
protected  Shape getBubbleShape(int type, Rectangle r)
          Get the appropriate shape for the specified type of chat.
protected  Rectangle getBubbleSize(int type, Dimension d)
          Calculate the size of the chat bubble based on the dimensions of the label and the type of chat.
protected  int getDisplayDurationOffset()
          A hack to allow subtitle chat to display longer and comic chat to display for a normal duration.
protected  int getGoldenLabelHeight(Dimension d)
          Given the specified label dimensions, attempt to find the height that will give us the width/height ratio that is closest to the golden ratio.
protected  Rectangle getRectWithOlds(Rectangle r, List<ComicChatOverlay.BubbleGlyph> oldbubs)
          Get a rectangle based on the old bubbles, but with room for the new one.
protected  Shape getTail(int type, Rectangle r, Point speaker)
          Create a tail to the specified rectangular area from the speaker point.
protected  void glyphExpired(ChatGlyph glyph)
          Called by a chat glyph when it has determined that it is expired.
 void historyUpdated(int adjustment)
           
protected  boolean isApprovedLocalType(String localtype)
          Check to see if we want to display the specified localtype.
protected  boolean isPlaceOrientedType(int type)
          Is the type of chat place-oriented.
 void layout()
          Layout the chat overlay inside the previously configured target component.
protected  Label layoutText(Graphics2D gfx, Font font, String text)
          Get a label formatted as close to the golden ratio as possible for the specified text and given the standard padding we use on all bubbles.
 void newPlaceEntered(ChatOverlay.InfoProvider provider)
          Callback from the target that the place has changed and we are to now talk to the new info provider.
protected  void positionRectIdeally(Rectangle r, int type, Point speaker)
          Position the rectangle in its ideal location given the type and speaker positon (which may be null).
 void removed()
          Indicates that the target component was removed from the widget hier.
 void setDimmed(boolean dimmed)
          Set the dimmed mode of the currently displaying glyphs.
protected  boolean shouldShowFromHistory(com.threerings.crowd.chat.data.ChatMessage msg, int index)
          We're looking through history to figure out what messages we should be showing, should we show the following?
 void speakerDeparted(Name speaker)
          Should be called when a speaker departs the chat area to allow the overlay to clean up.
protected  String splitNear(String text, int pos)
          Split the text at the space nearest the specified location.
 void viewDidScroll(int dx, int dy)
          Called if our containing media panel scrolled its view.
 
Methods inherited from class com.threerings.chat.SubtitleChatOverlay
added, addSubtitle, clearGlyphs, createHistorySubtitle, createSubtitle, createSubtitle, displayMessage, displayMessage, figureCurrentHistory, figureHistoryOffset, getChatExpire, getHistorySubtitle, getHistorySubtitleSpacing, getTargetGraphics, getType, isHistoryMode, isLaidOut, resetHistoryOffset, scrollUpSubtitles, setHistoryEnabled, stateChanged, updateDimmed, updateHistBar, viewDidScroll
 
Methods inherited from class com.threerings.chat.ChatOverlay
getTarget, isShowing, placeExited, setVisible, xlate, xlate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_newPlacePoint

protected int _newPlacePoint
The place in our history at which we last entered a new place.


_bubbles

protected List<ComicChatOverlay.BubbleGlyph> _bubbles
The currently displayed bubble areas.


MINIMUM_SPLIT_WIDTH

protected static final int MINIMUM_SPLIT_WIDTH
The minimum width of a bubble's label before we consider splitting lines.

See Also:
Constant Field Values

GOLDEN

protected static final double GOLDEN
The golden ratio.


BUBBLE_SPACING

protected static final int BUBBLE_SPACING
The space we force between adjacent bubbles.

See Also:
Constant Field Values

SPEAKER_DISTANCE

protected static final int SPEAKER_DISTANCE
The distance to stay from the speaker.

See Also:
Constant Field Values

TAIL_WIDTH

protected static final int TAIL_WIDTH
The width of the end of the tail.

See Also:
Constant Field Values

MAX_BUBBLES

protected static final int MAX_BUBBLES
The maximum number of bubbles to show.

See Also:
Constant Field Values

MAX_BUBBLES_PER_USER

protected static final int MAX_BUBBLES_PER_USER
The maximum number of bubbles to show per user.

See Also:
Constant Field Values

BACKGROUNDS

protected static final Color[] BACKGROUNDS
The background colors to use when drawing bubbles.

Constructor Detail

ComicChatOverlay

public ComicChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                        ChatLogic logic,
                        JScrollBar historyBar,
                        int subtitleHeight)
Construct a comic chat overlay.

Parameters:
subtitleHeight - the amount of vertical space to use for subtitles.
Method Detail

newPlaceEntered

public void newPlaceEntered(ChatOverlay.InfoProvider provider)
Description copied from class: ChatOverlay
Callback from the target that the place has changed and we are to now talk to the new info provider.

Overrides:
newPlaceEntered in class ChatOverlay

layout

public void layout()
Description copied from class: ChatOverlay
Layout the chat overlay inside the previously configured target component. Should be called if our component changes size.

Overrides:
layout in class SubtitleChatOverlay

removed

public void removed()
Description copied from class: ChatOverlay
Indicates that the target component was removed from the widget hier. Should be called when we no longer wish to paint chat.

Overrides:
removed in class SubtitleChatOverlay

clear

public void clear()
Specified by:
clear in interface com.threerings.crowd.chat.client.ChatDisplay
Overrides:
clear in class SubtitleChatOverlay

viewDidScroll

public void viewDidScroll(int dx,
                          int dy)
Description copied from class: ChatOverlay
Called if our containing media panel scrolled its view.

Overrides:
viewDidScroll in class SubtitleChatOverlay

setDimmed

public void setDimmed(boolean dimmed)
Description copied from class: ChatOverlay
Set the dimmed mode of the currently displaying glyphs.

Overrides:
setDimmed in class SubtitleChatOverlay

speakerDeparted

public void speakerDeparted(Name speaker)
Description copied from class: ChatOverlay
Should be called when a speaker departs the chat area to allow the overlay to clean up.

Overrides:
speakerDeparted in class ChatOverlay

historyUpdated

public void historyUpdated(int adjustment)
Specified by:
historyUpdated in interface com.threerings.crowd.chat.client.HistoryList.Observer
Overrides:
historyUpdated in class SubtitleChatOverlay

clearBubbles

protected void clearBubbles(boolean all)
Clear chat bubbles, either all of them or just the place-oriented ones.


shouldShowFromHistory

protected boolean shouldShowFromHistory(com.threerings.crowd.chat.data.ChatMessage msg,
                                        int index)
Description copied from class: SubtitleChatOverlay
We're looking through history to figure out what messages we should be showing, should we show the following?

Overrides:
shouldShowFromHistory in class SubtitleChatOverlay

isApprovedLocalType

protected boolean isApprovedLocalType(String localtype)
Description copied from class: SubtitleChatOverlay
Check to see if we want to display the specified localtype.

Overrides:
isApprovedLocalType in class SubtitleChatOverlay

isPlaceOrientedType

protected boolean isPlaceOrientedType(int type)
Is the type of chat place-oriented.


displayMessage

protected void displayMessage(com.threerings.crowd.chat.data.ChatMessage message,
                              int type,
                              Graphics2D layoutGfx)
Description copied from class: SubtitleChatOverlay
Display the message after we've decided which type it is.

Overrides:
displayMessage in class SubtitleChatOverlay

splitNear

protected String splitNear(String text,
                           int pos)
Split the text at the space nearest the specified location.


createBubble

protected boolean createBubble(Graphics2D gfx,
                               int type,
                               long timestamp,
                               String text,
                               Name speaker,
                               Point speakerloc)
Create a chat bubble with the specified type and text.

Parameters:
speakerloc - if non-null, specifies that a tail should be added which points to that location.
Returns:
true if we successfully laid out the bubble

getBubbleSize

protected Rectangle getBubbleSize(int type,
                                  Dimension d)
Calculate the size of the chat bubble based on the dimensions of the label and the type of chat. It will be turned into a shape later, but we manipulate it for a while as just a rectangle (which are easier to move about and do intersection tests with, and besides the Shape interface has no way to translate).


adjustLabel

protected Point adjustLabel(int type,
                            Point labelpos)
Position the label based on the type.


positionRectIdeally

protected void positionRectIdeally(Rectangle r,
                                   int type,
                                   Point speaker)
Position the rectangle in its ideal location given the type and speaker positon (which may be null).


getRectWithOlds

protected Rectangle getRectWithOlds(Rectangle r,
                                    List<ComicChatOverlay.BubbleGlyph> oldbubs)
Get a rectangle based on the old bubbles, but with room for the new one.


getBubbleShape

protected Shape getBubbleShape(int type,
                               Rectangle r)
Get the appropriate shape for the specified type of chat.


getTail

protected Shape getTail(int type,
                        Rectangle r,
                        Point speaker)
Create a tail to the specified rectangular area from the speaker point.


getAndExpireBubbles

protected List<ComicChatOverlay.BubbleGlyph> getAndExpireBubbles(Name speaker)
Expire a bubble, if necessary, and return the old bubbles for the specified speaker.


glyphExpired

protected void glyphExpired(ChatGlyph glyph)
Description copied from class: SubtitleChatOverlay
Called by a chat glyph when it has determined that it is expired.

Overrides:
glyphExpired in class SubtitleChatOverlay

layoutText

protected Label layoutText(Graphics2D gfx,
                           Font font,
                           String text)
Get a label formatted as close to the golden ratio as possible for the specified text and given the standard padding we use on all bubbles.


getGoldenLabelHeight

protected int getGoldenLabelHeight(Dimension d)
Given the specified label dimensions, attempt to find the height that will give us the width/height ratio that is closest to the golden ratio.


getAvoidList

protected List<Shape> getAvoidList(Name speaker)
Return a list of rectangular areas that we should avoid while laying out a bubble for the specified speaker.


getDisplayDurationOffset

protected int getDisplayDurationOffset()
Description copied from class: SubtitleChatOverlay
A hack to allow subtitle chat to display longer and comic chat to display for a normal duration.

Overrides:
getDisplayDurationOffset in class SubtitleChatOverlay