Class Buffer
- java.lang.Object
-
- com.realtime.crossfire.jxclient.gui.log.Buffer
-
public class Buffer extends java.lang.ObjectManages the contents of the contents of a log window. It consists of a list ofLines.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_LINESThe maximum number of lines the buffer can hold.static intMIN_LINE_HEIGHTThe minimal height of a line in pixels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBufferListener(@NotNull BufferListener listener)Adds a listener to notify of changes.voidaddLine(@NotNull Line line)Appends aLineto the end of the buffer.voidclear()Clears all lines from the buffer.intgetLastCount()Returns the number of merged lines.@NotNull LinegetLine(int line)Returns oneLineby line index.@NotNull java.lang.ObjectgetSyncObject()Returns the object to synchronize on when callingiterator()orlistIterator(int).intgetTotalHeight()Returns the total height of all lines.@NotNull java.util.Iterator<Line>iterator()Returns anIteratorfor the lines in this buffer.@NotNull java.util.Iterator<Line>listIterator(int line)Returns anIteratorfor the lines in this buffer.booleanmergeLines(@NotNull java.lang.String text, @Nullable java.awt.Color color)Checks whether a new text line should be merged with a preceding line.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.intsize()Returns the number of lines.
-
-
-
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- theFontsinstance for looking up fontscontext- theFontRenderContextto userenderWidth- 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 aLineto the end of the buffer.- Parameters:
line- the line to append
-
replaceLine
public void replaceLine(@NotNull @NotNull Line line)Replaces the lastLineof this buffer.- Parameters:
line- the replacing line
-
prune
public void prune()
Prunes excess lines.
-
getLine
@NotNull public @NotNull Line getLine(int line)
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
-
iterator
@NotNull public @NotNull java.util.Iterator<Line> iterator()
Returns anIteratorfor the lines in this buffer. The caller must holdsync's lock.- Returns:
- the iterator
-
listIterator
@NotNull public @NotNull java.util.Iterator<Line> listIterator(int line)
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
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 callingiterator()orlistIterator(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 contentscolor- 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, Color)did returntrue.- Returns:
- the number of merged lines
-
-