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
ConstructorsModifierConstructorDescriptionprotectedBuffer(int maxLines, int renderWidth) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBufferListener(@NotNull BufferListener listener) Adds a listener to notify of changes.voidAppends aLineto the end of the buffer.voidaddTextSegment(@NotNull Line line, @NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull FontID fontID, @NotNull Color color, @NotNull Color selectionColor) Appends aTextSegmentto the end of a line.voidclear()Clears all lines from the buffer.intcoordinateToPosition(int x, int y) Returns the text position for a coordinate.intReturns the number of merged lines.@NotNull LinegetLine(int line) Returns oneLineby line index.protected abstract intgetSegmentWidth(@NotNull TextSegment segment, int characters) Returns the width of a prefix of aTextSegment.@NotNull ObjectReturns the object to synchronize on when callinglines(int).@NotNull StringgetText(int beginSelection, int endSelection) Returns the selected text.intReturns the total height of all lines.lines(int line) Returns anIteratorfor the lines in this buffer.booleanmergeLines(@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 TextSegmentnewTextSegment(@NotNull String text, boolean bold, boolean italic, boolean underline, @NotNull FontID fontID, @NotNull Color color, @NotNull Color selectionColor) Creates a new segment.voidprune()Prunes excess lines.voidremoveBufferListener(@NotNull BufferListener listener) Removes a listener to be notified of changes.voidreplaceLine(@NotNull Line line) Replaces the lastLineof this buffer.voidsetRenderWidth(int renderWidth) Updates the width to render.voidsetShowSentCommands(boolean showSentCommands) Sets whether commands sent to the server are shown.voidsetShowTimestamps(boolean showTimestamps) Sets whether timestamps are shown.intsize()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 aLineto the end of the buffer.- Parameters:
line- the line to append
-
replaceLine
Replaces the lastLineof this buffer.- Parameters:
line- the replacing line
-
prune
public void prune()Prunes excess lines. -
getLine
Returns oneLineby 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 anIteratorfor 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 aTextSegmentto 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
-