Class KHtmlEdit

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class KHtmlEdit extends JComponent
A HTML implementation of a KTextEdit component. TODO: Many of the general HTML functions can be moved to a common utility class. TODO: Move the message formatting (and setup) code to a common class so that the in-game text bubbles can use the same code for rendering.
See Also:
Serialized Form
  • Field Details

    • HEADER_COLOR

      protected static final Color HEADER_COLOR
      Color of the time stamp written before the lines.
  • Method Details

    • activateLink

      protected void activateLink(HyperlinkEvent ev)
      Handle hypertext link activation.
      Parameters:
      ev - The link event data.
    • appendString

      protected void appendString(String text)
      Append HTML text to the end of the content. Note: Currently elements must be complete to be added correctly.
      Parameters:
      text - The HTML text to add.
    • appendHTML

      protected void appendHTML(StringBuilder sbuf, char ch)
      Append a character to a buffer, escaping HTML meta-characters when needed.
      Parameters:
      sbuf -
      ch -
    • appendHTML

      protected void appendHTML(StringBuilder sbuf, String text)
      Escape text as HTML, escaping meta-characters.
      Parameters:
      sbuf -
      text - Raw text.
    • translateToHTML

      protected String translateToHTML(String text)
      Translate a standard Stendhal encoded to HTML encoded.
      Parameters:
      text - The text to encode.
      Returns:
      HTML encoded text.
    • extractLink

      protected String extractLink(CharacterIterator ci)
      Extract link content from a character iterator. It is assumed that the '#' has already been eaten. It leaves the character iterator at the first character after the link text.
      Parameters:
      ci - The character iterator.
      Returns:
      Link text (or an empty string).
    • isWordDelim

      protected boolean isWordDelim(char ch)
      Determine is a character is a word delimiter when followed by a space or end-of-line. Care should be taken to avoid matching characters that are typically at the end of valid URL's.
      Parameters:
      ch - A character;
      Returns:
      true if a word delimiter.
    • buildLink

      protected void buildLink(StringBuilder sbuf, String text)
      Convert a text "link" to an HTML link. For well-known URL's, the link is taken literally, otherwise a say: URL will be generated.
      Parameters:
      sbuf - The string buffer to append to.
      text - The text to convert.
    • colorToRGB

      protected String colorToRGB(Color color)
      Convert a color to a CSS color attribute value.
      Parameters:
      color - An AWT color.
      Returns:
      A color: CSS attribute value.
    • initStylesForTextPane

      protected void initStylesForTextPane(JTextPane textPane, int mainTextSize)
      Initializes the basic styles.
      Parameters:
      textPane - the active text component
      mainTextSize - size of regular text
    • insertHeader

      protected void insertHeader(String text)
      Insert a header.
      Parameters:
      text - header string
    • insertNewline

      protected void insertNewline()
      Start a new line.
    • insertText

      protected void insertText(String text, NotificationType type)
      Insert the text portion of the line using a specified notification type for style.
      Parameters:
      text - The text to insert.
      type - The notification type.
    • insertTimestamp

      protected void insertTimestamp(String text)
      Insert time stamp.
      Parameters:
      text - time stamp
    • setFont

      public void setFont(Font font)
      Overrides:
      setFont in class JComponent