Class Buffer
java.lang.Object
com.realtime.crossfire.jxclient.gui.log.Buffer
- Direct Known Subclasses:
DefaultBuffer
Manages the contents of the contents of a log window. It consists of a list
of
Lines
.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Buffer
(int maxLines, int renderWidth) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBufferListener
(@NotNull BufferListener listener) Adds a listener to notify of changes.void
Appends aLine
to the end of the buffer.void
addTextSegment
(@NotNull Line line, @NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull FontID fontID, @NotNull Color color, @NotNull Color selectionColor) Appends aTextSegment
to the end of a line.void
clear()
Clears all lines from the buffer.int
coordinateToPosition
(int x, int y) Returns the text position for a coordinate.int
Returns the number of merged lines.@NotNull Line
getLine
(int line) Returns oneLine
by line index.protected abstract int
getSegmentWidth
(@NotNull TextSegment segment, int characters) Returns the width of a prefix of aTextSegment
.@NotNull Object
Returns the object to synchronize on when callinglines(int)
.@NotNull String
getText
(int beginSelection, int endSelection) Returns the selected text.int
Returns the total height of all lines.lines
(int line) Returns anIterator
for the lines in this buffer.boolean
mergeLines
(@NotNull String text, int type, int subtype, @Nullable Color color) Checks whether a new text line should be merged with a preceding line.protected abstract @NotNull TextSegment
newTextSegment
(@NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull FontID fontID, @NotNull Color color, @NotNull Color selectionColor) Creates a new segment.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 lastLine
of this buffer.void
setRenderWidth
(int renderWidth) Updates the width to render.void
setShowSentCommands
(boolean showSentCommands) Sets whether commands sent to the server are shown.void
setShowTimestamps
(boolean showTimestamps) Sets whether timestamps are shown.int
size()
Returns the number 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 holdrenderWidth
- 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
Appends aLine
to the end of the buffer.- Parameters:
line
- the line to append
-
replaceLine
Replaces the lastLine
of this buffer.- Parameters:
line
- the replacing line
-
prune
public void prune()Prunes excess lines. -
getLine
Returns oneLine
by line index. The first line has the index0
.- Parameters:
line
- the line index- Returns:
- the line
-
getTotalHeight
public int getTotalHeight()Returns the total height of all lines.- Returns:
- the total height
-
lines
Returns anIterator
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
Adds a listener to notify of changes.- Parameters:
listener
- the listener
-
removeBufferListener
Removes a listener to be notified of changes.- Parameters:
listener
- the listener
-
getSyncObject
Returns the object to synchronize on when callinglines(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 contentstype
- the message typesubtype
- the message subtypecolor
- 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 aftermergeLines(String, int, int, Color)
did returntrue
.- 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 aTextSegment
to the end of a line.- Parameters:
line
- the linetext
- the text to displaybold
- whether bold face is enableditalic
- whether italic face is enabledunderline
- whether underlining is enabledfontID
- the font to usecolor
- the color to useselectionColor
- 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 displaybold
- whether bold face is enableditalic
- whether italic face is enabledunderline
- whether underlining is enabledfontID
- the font to usecolor
- the color to useselectionColor
- 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 coordinatey
- the y coordinate- Returns:
- the text position
-
getSegmentWidth
Returns the width of a prefix of aTextSegment
.- Parameters:
segment
- the text segmentcharacters
- the number of characters in the prefix- Returns:
- the width in pixels
-
getText
Returns the selected text.- Parameters:
beginSelection
- the first selected characterendSelection
- the first character after the selection- Returns:
- the selected text
-