com.threerings.chat
Class SubtitleChatOverlay

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

public class SubtitleChatOverlay
extends ChatOverlay
implements ChangeListener, com.threerings.crowd.chat.client.HistoryList.Observer

Implements subtitle chat.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.chat.ChatOverlay
ChatOverlay.InfoProvider
 
Field Summary
protected  int _histOffset
          The history offset (from 0) such that the history lines (0, _histOffset - 1) will all fit onscreen if the lowest scrollbar position is _histOffset.
protected  boolean _histOffsetFinal
          If the history offset we've figured is all figured out or needs to be refigured.
protected  com.threerings.crowd.chat.client.HistoryList _history
          List of existing messages from our chat director.
protected  int _historyExtent
          A guess of how many history lines fit onscreen at a time.
protected  BoundedRangeModel _historyModel
          If we're in history mode, this will be non-null and will notify us of our historical positioning.
protected  boolean _laidout
          Tracks whether or not we've been laid out.
protected  long _lastExpire
          The unbounded expire time of the last chat glyph displayed.
protected  boolean _overrideHistory
          If set, show history no matter what the client prefs say.
protected  JScrollBar _scrollbar
          Our history scrollbar.
protected  List<ChatGlyph> _showingHistory
          The currently displayed subtitles O' history.
protected  int _subtitleHeight
          The amount of vertical space to use for subtitles.
protected  List<ChatGlyph> _subtitles
          The currently displayed subtitle areas.
protected  boolean _subtitlesFill
          If true, subtitles should fill all available height.
protected  int _subtitleXSpacing
          The amount of space we want around the subtitles.
protected  int _subtitleYSpacing
           
protected static int ICON_PADDING
          The amount of space to insert between the icon and the text.
protected static int PAD
          The padding in each direction around the text to the edges of a chat 'bubble'.
protected static int SUBTITLE_HEIGHT_GUESS
          A guess as to the height of a subtitle (plus spacing).
 
Fields inherited from class com.threerings.chat.ChatOverlay
_ctx, _dimmed, _logic, _provider, _target
 
Constructor Summary
  SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar bar)
          Construct a comic chat overlay using all the available space for subtitling.
  SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar bar, boolean full)
           
  SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar bar, boolean full, boolean overrideHistory)
           
  SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar bar, int subtitleHeight)
          Construct a subtitle chat overlay.
protected SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx, ChatLogic logic, JScrollBar bar, int height, boolean fill, int xspace, int yspace)
          Shared chained constructor.
 
Method Summary
 void added(VirtualMediaPanel target)
          Indicates that the target component was added to the widget hier.
protected  void addSubtitle(ChatGlyph rec)
          Add a subtitle for display now.
 void clear()
           
protected  void clearGlyphs(List<ChatGlyph> glyphs)
          Clears out the supplied list of chat glyphs.
protected  ChatGlyph createHistorySubtitle(int index, Graphics2D layoutGfx)
          Creates a subtitle for display in the history panel.
protected  ChatGlyph createSubtitle(com.threerings.crowd.chat.data.ChatMessage message, int type, Graphics2D layoutGfx, boolean expires)
          Create a subtitle, but don't do anything funny with it.
protected  ChatGlyph createSubtitle(Graphics2D gfx, int type, long timestamp, Icon icon, int indent, String text, boolean expires)
          Create a subtitle- a line of text that goes on the bottom.
 boolean displayMessage(com.threerings.crowd.chat.data.ChatMessage message, boolean alreadyDisplayed)
           
protected  void displayMessage(com.threerings.crowd.chat.data.ChatMessage message, Graphics2D gfx)
          Display the specified message now, unless we are to ignore it.
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  void figureCurrentHistory()
          Figure out which ChatMessages in the history should currently appear in the showing history.
protected  void figureHistoryOffset(Graphics2D gfx)
          Figure out how many of the first history elements fit in our bounds such that we can set the bounds on the scrollbar correctly such that the scrolling to the smallest value just barely puts the first element onscreen.
protected  long getChatExpire(long timestamp, String text)
          Get the expire time for the specified chat.
protected  int getDisplayDurationOffset()
          A hack to allow subtitle chat to display longer and comic chat to display for a normal duration.
protected  ChatGlyph getHistorySubtitle(int index, Graphics2D layoutGfx)
          Get the glyph for the specified history index, creating if necessary.
protected  int getHistorySubtitleSpacing(int index)
          Determines the amount of spacing to put after a history subtitle.
protected  Graphics2D getTargetGraphics()
          Return the current Graphics context of our target, or null if not applicable.
protected  int getType(com.threerings.crowd.chat.data.ChatMessage message, boolean history)
          Convert the Message class/localtype/mode into our internal type code.
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 isHistoryMode()
          Are we currently in history mode?
protected  boolean isLaidOut()
           
 void layout()
          Layout the chat overlay inside the previously configured target component.
 void removed()
          Indicates that the target component was removed from the widget hier.
protected  void resetHistoryOffset()
          Reset the history offset so that it will be recalculated next time it is needed.
protected  void scrollUpSubtitles(int dy)
          Scroll all the subtitles up by the specified amount.
 void setDimmed(boolean dimmed)
          Set the dimmed mode of the currently displaying glyphs.
protected  void setHistoryEnabled(boolean historyEnabled)
          Configures us for display of chat history or not.
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 stateChanged(ChangeEvent e)
           
protected  void updateDimmed(List<? extends ChatGlyph> glyphs)
          Update the chat glyphs in the specified list to be set to the current dimmed setting.
protected  void updateHistBar(int val)
          Update the history scrollbar with the specified value.
 void viewDidScroll(int dx, int dy)
          Called if our containing media panel scrolled its view.
protected  void viewDidScroll(List<? extends ChatGlyph> glyphs, int dx, int dy)
          Helper function for informing glyphs of the scrolled view.
 
Methods inherited from class com.threerings.chat.ChatOverlay
getTarget, isShowing, newPlaceEntered, placeExited, setVisible, speakerDeparted, xlate, xlate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_history

protected com.threerings.crowd.chat.client.HistoryList _history
List of existing messages from our chat director.


_overrideHistory

protected boolean _overrideHistory
If set, show history no matter what the client prefs say.


_showingHistory

protected List<ChatGlyph> _showingHistory
The currently displayed subtitles O' history.


_scrollbar

protected JScrollBar _scrollbar
Our history scrollbar.


_laidout

protected boolean _laidout
Tracks whether or not we've been laid out.


_historyModel

protected BoundedRangeModel _historyModel
If we're in history mode, this will be non-null and will notify us of our historical positioning.


_subtitles

protected List<ChatGlyph> _subtitles
The currently displayed subtitle areas.


_subtitleHeight

protected int _subtitleHeight
The amount of vertical space to use for subtitles.


_subtitlesFill

protected boolean _subtitlesFill
If true, subtitles should fill all available height.


_subtitleXSpacing

protected int _subtitleXSpacing
The amount of space we want around the subtitles.


_subtitleYSpacing

protected int _subtitleYSpacing

_lastExpire

protected long _lastExpire
The unbounded expire time of the last chat glyph displayed.


_histOffsetFinal

protected boolean _histOffsetFinal
If the history offset we've figured is all figured out or needs to be refigured.


_histOffset

protected int _histOffset
The history offset (from 0) such that the history lines (0, _histOffset - 1) will all fit onscreen if the lowest scrollbar position is _histOffset.


_historyExtent

protected int _historyExtent
A guess of how many history lines fit onscreen at a time.


SUBTITLE_HEIGHT_GUESS

protected static final int SUBTITLE_HEIGHT_GUESS
A guess as to the height of a subtitle (plus spacing).

See Also:
Constant Field Values

ICON_PADDING

protected static final int ICON_PADDING
The amount of space to insert between the icon and the text.

See Also:
Constant Field Values

PAD

protected static final int PAD
The padding in each direction around the text to the edges of a chat 'bubble'.

See Also:
Constant Field Values
Constructor Detail

SubtitleChatOverlay

public SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                           ChatLogic logic,
                           JScrollBar bar,
                           int subtitleHeight)
Construct a subtitle chat overlay.

Parameters:
subtitleHeight - the height of the subtitle area.

SubtitleChatOverlay

public SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                           ChatLogic logic,
                           JScrollBar bar)
Construct a comic chat overlay using all the available space for subtitling.


SubtitleChatOverlay

public SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                           ChatLogic logic,
                           JScrollBar bar,
                           boolean full)

SubtitleChatOverlay

public SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                           ChatLogic logic,
                           JScrollBar bar,
                           boolean full,
                           boolean overrideHistory)

SubtitleChatOverlay

protected SubtitleChatOverlay(com.threerings.crowd.util.CrowdContext ctx,
                              ChatLogic logic,
                              JScrollBar bar,
                              int height,
                              boolean fill,
                              int xspace,
                              int yspace)
Shared chained constructor.

Method Detail

historyUpdated

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

stateChanged

public void stateChanged(ChangeEvent e)
Specified by:
stateChanged in interface ChangeListener

clear

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

displayMessage

public boolean displayMessage(com.threerings.crowd.chat.data.ChatMessage message,
                              boolean alreadyDisplayed)
Specified by:
displayMessage in interface com.threerings.crowd.chat.client.ChatDisplay

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 ChatOverlay

added

public void added(VirtualMediaPanel target)
Description copied from class: ChatOverlay
Indicates that the target component was added to the widget hier. Should be called when we wish to start displaying chat.

Overrides:
added 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.

Specified by:
layout in class ChatOverlay

setDimmed

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

Overrides:
setDimmed in class ChatOverlay

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 ChatOverlay

updateDimmed

protected void updateDimmed(List<? extends ChatGlyph> glyphs)
Update the chat glyphs in the specified list to be set to the current dimmed setting.


isHistoryMode

protected boolean isHistoryMode()
Are we currently in history mode?


getTargetGraphics

protected Graphics2D getTargetGraphics()
Return the current Graphics context of our target, or null if not applicable.


setHistoryEnabled

protected void setHistoryEnabled(boolean historyEnabled)
Configures us for display of chat history or not.


viewDidScroll

protected void viewDidScroll(List<? extends ChatGlyph> glyphs,
                             int dx,
                             int dy)
Helper function for informing glyphs of the scrolled view.


updateHistBar

protected void updateHistBar(int val)
Update the history scrollbar with the specified value.


resetHistoryOffset

protected void resetHistoryOffset()
Reset the history offset so that it will be recalculated next time it is needed.


figureHistoryOffset

protected void figureHistoryOffset(Graphics2D gfx)
Figure out how many of the first history elements fit in our bounds such that we can set the bounds on the scrollbar correctly such that the scrolling to the smallest value just barely puts the first element onscreen.


figureCurrentHistory

protected void figureCurrentHistory()
Figure out which ChatMessages in the history should currently appear in the showing history.


getHistorySubtitle

protected ChatGlyph getHistorySubtitle(int index,
                                       Graphics2D layoutGfx)
Get the glyph for the specified history index, creating if necessary.


createHistorySubtitle

protected ChatGlyph createHistorySubtitle(int index,
                                          Graphics2D layoutGfx)
Creates a subtitle for display in the history panel.

Parameters:
index - the index of the message in the history list

getHistorySubtitleSpacing

protected int getHistorySubtitleSpacing(int index)
Determines the amount of spacing to put after a history subtitle.

Parameters:
index - the index of the message in the history list

isLaidOut

protected boolean isLaidOut()

shouldShowFromHistory

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?


clearGlyphs

protected void clearGlyphs(List<ChatGlyph> glyphs)
Clears out the supplied list of chat glyphs.


displayMessage

protected void displayMessage(com.threerings.crowd.chat.data.ChatMessage message,
                              Graphics2D gfx)
Display the specified message now, unless we are to ignore it.


displayMessage

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.


addSubtitle

protected void addSubtitle(ChatGlyph rec)
Add a subtitle for display now.


createSubtitle

protected ChatGlyph createSubtitle(com.threerings.crowd.chat.data.ChatMessage message,
                                   int type,
                                   Graphics2D layoutGfx,
                                   boolean expires)
Create a subtitle, but don't do anything funny with it.


createSubtitle

protected ChatGlyph createSubtitle(Graphics2D gfx,
                                   int type,
                                   long timestamp,
                                   Icon icon,
                                   int indent,
                                   String text,
                                   boolean expires)
Create a subtitle- a line of text that goes on the bottom.


getChatExpire

protected long getChatExpire(long timestamp,
                             String text)
Get the expire time for the specified chat.


getDisplayDurationOffset

protected int getDisplayDurationOffset()
A hack to allow subtitle chat to display longer and comic chat to display for a normal duration.


glyphExpired

protected void glyphExpired(ChatGlyph glyph)
Called by a chat glyph when it has determined that it is expired.


getType

protected int getType(com.threerings.crowd.chat.data.ChatMessage message,
                      boolean history)
Convert the Message class/localtype/mode into our internal type code.


isApprovedLocalType

protected boolean isApprovedLocalType(String localtype)
Check to see if we want to display the specified localtype.


scrollUpSubtitles

protected void scrollUpSubtitles(int dy)
Scroll all the subtitles up by the specified amount.