Class Chatter

All Implemented Interfaces:
DropTargetListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Buildable, CommandEncoder
Direct Known Subclasses:
PrivateChatter

public class Chatter extends JPanel implements CommandEncoder, Buildable, DropTargetListener
The chat window component. Displays text messages and accepts input. Also acts as a CommandEncoder, encoding/decoding commands that display message in the text area
See Also:
  • Field Details

  • Constructor Details

    • Chatter

      public Chatter()
  • Method Details

    • getAnonymousUserName

      public static String getAnonymousUserName()
    • setChatterVisible

      protected void setChatterVisible(boolean vis)
      Because our Chatters make themselves visible in their constructor, providing a way for an overriding class to "turn this chatter off" is friendlier than What Went Before.
      Parameters:
      vis - - whether this chatter should be visible
    • formatChat

      protected String formatChat(String text)
    • getInputField

      public JTextField getInputField()
    • getChatStyle

      protected String getChatStyle(String s)
      Styles a chat message based on the player who sent it. Presently just distinguishes a chat message "from me" from a chat message "from anyone else".

      To make the player colors easy to override in a custom class (my modules have logic to assign individual player colors -- beyond the scope of the present effort but a perhaps a fun future addition)

      Parameters:
      s - - chat message from a player
      Returns:
      - an entry in our CSS style sheet to use for this chat message
    • consoleHook

      public boolean consoleHook(String s, String style, boolean html_allowed)
      A hook for inserting a console class that accepts commands
      Parameters:
      s - - chat message
      style - - current style name (contains information that might be useful)
      html_allowed - - flag if html_processing is enabled for this message (allows console to apply security considerations)
      Returns:
      true - if was accepted as a console command
    • show

      public void show(String s)
      Display a message in the text area. Ensures we execute in the EDT
    • addStyle

      protected void addStyle(String s, Font f, Color c, String font_weight, int size)
      Adds or updates a CSS stylesheet entry. Styles in the color, font type, and font size.
      Parameters:
      s - Style name
      f - Font to use
      c - Color for text
      font_weight - Bold? Italic?
      size - Font size
    • makeStyleSheet

      protected void makeStyleSheet(Font f)
      Build ourselves a CSS stylesheet from our preference font/color settings.
      Parameters:
      f - - Font to use for this stylesheet
    • setFont

      public void setFont(Font f)
      Set the Font used by the text area
      Overrides:
      setFont in class JComponent
    • build

      public void build(Element e)
      Description copied from interface: Buildable
      Build the object from the XML representation of the Buildable
      Specified by:
      build in interface Buildable
      Parameters:
      e - the XML element containing the object data
    • getBuildElement

      public Element getBuildElement(Document doc)
      Specified by:
      getBuildElement in interface Buildable
      Parameters:
      doc - XML file
      Returns:
      an XML element from which this component can be built
    • addTo

      public void addTo(Buildable b)
      Expects to be added to a GameModule. Adds itself to the controls window and registers itself as a CommandEncoder
      Specified by:
      addTo in interface Buildable
      Parameters:
      b - parent Buildable to add this component to as a subcomponent.
    • add

      public void add(Buildable b)
      Description copied from interface: Buildable
      Adds a child component. Both this method and Buildable.addTo(VASSAL.build.Buildable) are invoked when adding a child to a parent
      Specified by:
      add in interface Buildable
      Parameters:
      b - Child to attach to this buildable as a subcomponent
    • decode

      public Command decode(String s)
      Description copied from interface: CommandEncoder
      Translate a String into a Command
      Specified by:
      decode in interface CommandEncoder
    • encode

      public String encode(Command c)
      Description copied from interface: CommandEncoder
      Translate a Command into a String
      Specified by:
      encode in interface CommandEncoder
    • send

      public void send(String msg)
      Displays the message, Also logs and sends to the server a Command that displays this message.
    • send

      public void send(String msg, String console)
      Checks first for an intercepted console command; otherwise displays the message
      Parameters:
      msg - message to display if not a console command
      console - potential console command (without any chat livery added to it)
    • warning

      public static void warning(String msg)
      Warning message method -- same as send, but accepts messages from static methods. For reporting soft-fail problems in modules.
    • keyCommand

      public void keyCommand(KeyStroke e)
      Classes other than the Chatter itself may forward KeyEvents to the Chatter by using this method
    • main

      public static void main(String[] args)
    • getHandle

      @Deprecated(since="2020-08-06", forRemoval=true) public String getHandle()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • dragEnter

      public void dragEnter(DropTargetDragEvent event)
      Specified by:
      dragEnter in interface DropTargetListener
    • dragExit

      public void dragExit(DropTargetEvent event)
      Specified by:
      dragExit in interface DropTargetListener
    • dragOver

      public void dragOver(DropTargetDragEvent event)
      Specified by:
      dragOver in interface DropTargetListener
    • dropActionChanged

      public void dropActionChanged(DropTargetDragEvent event)
      Specified by:
      dropActionChanged in interface DropTargetListener
    • drop

      public void drop(DropTargetDropEvent dtde)
      We put the "drop" in drag-n-drop!
      Specified by:
      drop in interface DropTargetListener
      Parameters:
      dtde - DropTargetDragEvent
    • isMandatory

      public boolean isMandatory()
      Description copied from interface: Buildable
      Is this component a reqired component within its parent?
      Specified by:
      isMandatory in interface Buildable
      Returns:
      true if component is mandatory
    • isUnique

      public boolean isUnique()
      Description copied from interface: Buildable
      Does this component need to be unique within it's parent?
      Specified by:
      isUnique in interface Buildable
      Returns: