Class Buffer


  • public class Buffer
    extends java.lang.Object
    Manages the contents of the contents of a log window. It consists of a list of Lines.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAX_LINES
      The maximum number of lines the buffer can hold.
      static int MIN_LINE_HEIGHT
      The minimal height of a line in pixels.
    • Constructor Summary

      Constructors 
      Constructor Description
      Buffer​(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context, int renderWidth)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBufferListener​(@NotNull BufferListener listener)
      Adds a listener to notify of changes.
      void addLine​(@NotNull Line line)
      Appends a Line to the end of the buffer.
      void clear()
      Clears all lines from the buffer.
      int getLastCount()
      Returns the number of merged lines.
      @NotNull Line getLine​(int line)
      Returns one Line by line index.
      @NotNull java.lang.Object getSyncObject()
      Returns the object to synchronize on when calling iterator() or listIterator(int).
      int getTotalHeight()
      Returns the total height of all lines.
      @NotNull java.util.Iterator<Line> iterator()
      Returns an Iterator for the lines in this buffer.
      @NotNull java.util.Iterator<Line> listIterator​(int line)
      Returns an Iterator for the lines in this buffer.
      boolean mergeLines​(@NotNull java.lang.String text, @Nullable java.awt.Color color)
      Checks whether a new text line should be merged with a preceding line.
      void prune()
      Prunes excess lines.
      void removeBufferListener​(@NotNull BufferListener listener)
      Removes a listener to be notified of changes.
      void replaceLine​(@NotNull Line line)
      Replaces the last Line of this buffer.
      void setRenderWidth​(int renderWidth)
      Updates the width to render.
      int size()
      Returns the number of lines.
      • Methods inherited from class java.lang.Object

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

      • MAX_LINES

        public static final int MAX_LINES
        The maximum number of lines the buffer can hold.
        See Also:
        Constant Field Values
      • MIN_LINE_HEIGHT

        public static final int MIN_LINE_HEIGHT
        The minimal height of a line in pixels. Normally applies to empty lines.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Buffer

        public Buffer​(@NotNull
                      @NotNull Fonts fonts,
                      @NotNull
                      @NotNull java.awt.font.FontRenderContext context,
                      int renderWidth)
        Creates a new instance.
        Parameters:
        fonts - the Fonts instance for looking up fonts
        context - the FontRenderContext to use
        renderWidth - the width to render
    • Method Detail

      • setRenderWidth

        public void setRenderWidth​(int renderWidth)
        Updates the width to render.
        Parameters:
        renderWidth - the width to render
      • clear

        public void clear()
        Clears all lines from the buffer.
      • addLine

        public void addLine​(@NotNull
                            @NotNull Line line)
        Appends a Line to the end of the buffer.
        Parameters:
        line - the line to append
      • replaceLine

        public void replaceLine​(@NotNull
                                @NotNull Line line)
        Replaces the last Line of this buffer.
        Parameters:
        line - the replacing line
      • prune

        public void prune()
        Prunes excess lines.
      • getLine

        @NotNull
        public @NotNull Line getLine​(int line)
        Returns one Line by line index. The first line has the index 0.
        Parameters:
        line - the line index
        Returns:
        the line
      • getTotalHeight

        public int getTotalHeight()
        Returns the total height of all lines.
        Returns:
        the total height
      • iterator

        @NotNull
        public @NotNull java.util.Iterator<Line> iterator()
        Returns an Iterator for the lines in this buffer. The caller must hold sync's lock.
        Returns:
        the iterator
      • listIterator

        @NotNull
        public @NotNull java.util.Iterator<Line> listIterator​(int line)
        Returns an Iterator for the lines in this buffer.
        Parameters:
        line - the initial line index of the list iterator
        Returns:
        the list iterator
      • size

        public int size()
        Returns the number of lines.
        Returns:
        the number of lines
      • addBufferListener

        public void addBufferListener​(@NotNull
                                      @NotNull BufferListener listener)
        Adds a listener to notify of changes.
        Parameters:
        listener - the listener
      • removeBufferListener

        public void removeBufferListener​(@NotNull
                                         @NotNull BufferListener listener)
        Removes a listener to be notified of changes.
        Parameters:
        listener - the listener
      • getSyncObject

        @NotNull
        public @NotNull java.lang.Object getSyncObject()
        Returns the object to synchronize on when calling iterator() or listIterator(int).
        Returns:
        the object
      • mergeLines

        public boolean mergeLines​(@NotNull
                                  @NotNull java.lang.String text,
                                  @Nullable
                                  @Nullable java.awt.Color color)
        Checks whether a new text line should be merged with a preceding line.
        Parameters:
        text - the text line contents
        color - the text line color
        Returns:
        whether the line should be merged
      • getLastCount

        public int getLastCount()
        Returns the number of merged lines. Should not be called unless directly after mergeLines(String, Color) did return true.
        Returns:
        the number of merged lines