Class BufferImpl

  • All Implemented Interfaces:
    Buffer

    public class BufferImpl
    extends java.lang.Object
    implements Buffer
    A holder for a StringBuilder that also contains the current cursor position.
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] buffer  
      private int cursor  
      private int cursorCol  
      private int g0  
      private int g1  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int adjust​(int i)  
      int atChar​(int i)  
      boolean backspace()
      Issue a backspace.
      int backspace​(int num)
      Issue num backspaces.
      boolean clear()  
      BufferImpl copy()  
      void copyFrom​(Buffer buf)  
      int currChar()  
      boolean currChar​(int ch)  
      int cursor()  
      boolean cursor​(int position)
      Move the cursor position to the specified absolute index.
      boolean delete()  
      int delete​(int num)  
      boolean down()  
      private int getCursorCol()  
      int length()  
      int move​(int num)
      Move the cursor where characters.
      private void moveGapToCursor()  
      boolean moveXY​(int dx, int dy)  
      int nextChar()  
      int prevChar()  
      java.lang.String substring​(int start)  
      java.lang.String substring​(int start, int end)  
      java.lang.String toString()  
      boolean up()  
      java.lang.String upToCursor()  
      void write​(int c)
      Write the specific character into the buffer, setting the cursor position ahead one.
      private void write​(int[] ucps)  
      void write​(int c, boolean overTyping)
      Write the specific character into the buffer, setting the cursor position ahead one.
      void write​(java.lang.CharSequence str)
      Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
      void write​(java.lang.CharSequence str, boolean overTyping)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • cursor

        private int cursor
      • cursorCol

        private int cursorCol
      • buffer

        private int[] buffer
      • g0

        private int g0
      • g1

        private int g1
    • Constructor Detail

      • BufferImpl

        public BufferImpl()
      • BufferImpl

        public BufferImpl​(int size)
      • BufferImpl

        private BufferImpl​(BufferImpl buffer)
    • Method Detail

      • cursor

        public int cursor()
        Specified by:
        cursor in interface Buffer
      • length

        public int length()
        Specified by:
        length in interface Buffer
      • currChar

        public boolean currChar​(int ch)
        Specified by:
        currChar in interface Buffer
      • currChar

        public int currChar()
        Specified by:
        currChar in interface Buffer
      • prevChar

        public int prevChar()
        Specified by:
        prevChar in interface Buffer
      • nextChar

        public int nextChar()
        Specified by:
        nextChar in interface Buffer
      • atChar

        public int atChar​(int i)
        Specified by:
        atChar in interface Buffer
      • adjust

        private int adjust​(int i)
      • write

        public void write​(int c)
        Write the specific character into the buffer, setting the cursor position ahead one.
        Specified by:
        write in interface Buffer
        Parameters:
        c - the character to insert
      • write

        public void write​(int c,
                          boolean overTyping)
        Write the specific character into the buffer, setting the cursor position ahead one. The text may overwrite or insert based on the current setting of overTyping.
        Specified by:
        write in interface Buffer
        Parameters:
        c - the character to insert
      • write

        public void write​(java.lang.CharSequence str)
        Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
        Specified by:
        write in interface Buffer
      • write

        public void write​(java.lang.CharSequence str,
                          boolean overTyping)
        Specified by:
        write in interface Buffer
      • write

        private void write​(int[] ucps)
      • clear

        public boolean clear()
        Specified by:
        clear in interface Buffer
      • substring

        public java.lang.String substring​(int start)
        Specified by:
        substring in interface Buffer
      • substring

        public java.lang.String substring​(int start,
                                          int end)
        Specified by:
        substring in interface Buffer
      • upToCursor

        public java.lang.String upToCursor()
        Specified by:
        upToCursor in interface Buffer
      • cursor

        public boolean cursor​(int position)
        Move the cursor position to the specified absolute index.
        Specified by:
        cursor in interface Buffer
      • move

        public int move​(int num)
        Move the cursor where characters.
        Specified by:
        move in interface Buffer
        Parameters:
        num - If less than 0, move abs(where) to the left, otherwise move where to the right.
        Returns:
        The number of spaces we moved
      • up

        public boolean up()
        Specified by:
        up in interface Buffer
      • down

        public boolean down()
        Specified by:
        down in interface Buffer
      • moveXY

        public boolean moveXY​(int dx,
                              int dy)
        Specified by:
        moveXY in interface Buffer
      • getCursorCol

        private int getCursorCol()
      • backspace

        public int backspace​(int num)
        Issue num backspaces.
        Specified by:
        backspace in interface Buffer
        Returns:
        the number of characters backed up
      • backspace

        public boolean backspace()
        Issue a backspace.
        Specified by:
        backspace in interface Buffer
        Returns:
        true if successful
      • delete

        public int delete​(int num)
        Specified by:
        delete in interface Buffer
      • delete

        public boolean delete()
        Specified by:
        delete in interface Buffer
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface Buffer
        Overrides:
        toString in class java.lang.Object
      • moveGapToCursor

        private void moveGapToCursor()