Package jexer.teditor

Class Word


  • public class Word
    extends java.lang.Object
    A Word represents text that was entered by the user. It can be either whitespace or non-whitespace. Very dumb highlighting is supported, it has no sense of parsing (not even comments). For now this only highlights some Java keywords and puctuation.
    • Constructor Detail

      • Word

        public Word​(int ch,
                    CellAttributes defaultColor,
                    Highlighter highlighter)
        Construct a word with one character.
        Parameters:
        ch - the first character of the word
        defaultColor - the color for unhighlighted text
        highlighter - the highlighter to use
      • Word

        public Word​(CellAttributes defaultColor,
                    Highlighter highlighter)
        Construct a word with an empty string.
        Parameters:
        defaultColor - the color for unhighlighted text
        highlighter - the highlighter to use
    • Method Detail

      • getColor

        public CellAttributes getColor()
        Get the color used to display this word on screen.
        Returns:
        the color
      • setColor

        public void setColor​(CellAttributes color)
        Set the color used to display this word on screen.
        Parameters:
        color - the color
      • getText

        public java.lang.String getText()
        Get the text to display.
        Returns:
        the text
      • getDisplayLength

        public int getDisplayLength()
        Get the on-screen display length.
        Returns:
        the number of cells needed to display this word
      • isWhitespace

        public boolean isWhitespace()
        See if this is a whitespace word. Note that empty string is considered whitespace.
        Returns:
        true if this word is whitespace
      • applyHighlight

        public void applyHighlight()
        Perform highlighting.
      • addChar

        public Word addChar​(int ch)
        Add a character to this word. If this is a whitespace character adding to a non-whitespace word, create a new word and return that; similarly if this a non-whitespace character adding to a whitespace word, create a new word and return that. Note package private access: this is only called by Line to figure out highlighting boundaries.
        Parameters:
        ch - the new character to add
        Returns:
        either this word (if it was added), or a new word that contains ch