java.lang.Object
com.realtime.crossfire.jxclient.gui.log.Buffer
Direct Known Subclasses:
DefaultBuffer

public abstract class Buffer extends Object
Manages the contents of the contents of a log window. It consists of a list of Lines.
  • Constructor Details

    • Buffer

      protected Buffer(int maxLines, int renderWidth)
      Creates a new instance.
      Parameters:
      maxLines - the maximum number of lines the buffer can hold
      renderWidth - the width to render
  • Method Details

    • setRenderWidth

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

      public void setShowSentCommands(boolean showSentCommands)
      Sets whether commands sent to the server are shown.
      Parameters:
      showSentCommands - whether commands sent to the server are shown
    • setShowTimestamps

      public void setShowTimestamps(boolean showTimestamps)
      Sets whether timestamps are shown.
      Parameters:
      showTimestamps - whether timestamps are shown
    • 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
    • lines

      @NotNull public @NotNull Iterable<Line> lines(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 Object getSyncObject()
      Returns the object to synchronize on when calling lines(int).
      Returns:
      the object
    • mergeLines

      public boolean mergeLines(@NotNull @NotNull String text, int type, int subtype, @Nullable @Nullable Color color)
      Checks whether a new text line should be merged with a preceding line.
      Parameters:
      text - the text line contents
      type - the message type
      subtype - the message subtype
      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, int, int, Color) did return true.
      Returns:
      the number of merged lines
    • addTextSegment

      public void addTextSegment(@NotNull @NotNull Line line, @NotNull @NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull @NotNull FontID fontID, @NotNull @NotNull Color color, @NotNull @NotNull Color selectionColor)
      Appends a TextSegment to the end of a line.
      Parameters:
      line - the line
      text - the text to display
      bold - whether bold face is enabled
      italic - whether italic face is enabled
      underline - whether underlining is enabled
      fontID - the font to use
      color - the color to use
      selectionColor - the selection color to use
    • newTextSegment

      @NotNull protected abstract @NotNull TextSegment newTextSegment(@NotNull @NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull @NotNull FontID fontID, @NotNull @NotNull Color color, @NotNull @NotNull Color selectionColor)
      Creates a new segment.
      Parameters:
      text - the text to display
      bold - whether bold face is enabled
      italic - whether italic face is enabled
      underline - whether underlining is enabled
      fontID - the font to use
      color - the color to use
      selectionColor - the selection color to use
      Returns:
      the new segment
    • coordinateToPosition

      public int coordinateToPosition(int x, int y)
      Returns the text position for a coordinate.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the text position
    • getSegmentWidth

      protected abstract int getSegmentWidth(@NotNull @NotNull TextSegment segment, int characters)
      Returns the width of a prefix of a TextSegment.
      Parameters:
      segment - the text segment
      characters - the number of characters in the prefix
      Returns:
      the width in pixels
    • getText

      @NotNull public @NotNull String getText(int beginSelection, int endSelection)
      Returns the selected text.
      Parameters:
      beginSelection - the first selected character
      endSelection - the first character after the selection
      Returns:
      the selected text