public class Buffer
extends java.lang.Object
Lines
.Modifier and Type | Field and Description |
---|---|
private java.awt.font.FontRenderContext |
context
The
FontRenderContext to use. |
private Fonts |
fonts
The
Fonts instance for looking up fonts. |
private java.awt.Color |
lastColor
The color of the previously added line of text.
|
private int |
lastCount
The number of repetitions of the previously added line of text.
|
private java.lang.String |
lastText
The contents of the previously added line of text.
|
private java.util.List<Line> |
lines
The lines in display order.
|
private EventListenerList2<BufferListener> |
listeners
The listeners to notify about changes.
|
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.
|
private int |
renderWidth
The width to render.
|
private java.lang.Object |
sync
Object to synchronized access to
lines and totalHeight . |
private int |
totalHeight
The total height of all
lines . |
Constructor and Description |
---|
Buffer(Fonts fonts,
java.awt.font.FontRenderContext context,
int renderWidth)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addBufferListener(BufferListener listener)
Adds a listener to notify of changes.
|
void |
addLine(Line line)
Appends a
Line to the end of the buffer. |
private int |
calculateHeight(Line line)
Determines the height of a
Line in pixels. |
void |
clear()
Clears all lines from the buffer.
|
int |
getLastCount()
Returns the number of merged lines.
|
Line |
getLine(int line)
Returns one
Line by line index. |
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.
|
java.util.Iterator<Line> |
iterator()
Returns an
Iterator for the lines in this buffer. |
java.util.Iterator<Line> |
listIterator(int line)
Returns an
Iterator for the lines in this buffer. |
boolean |
mergeLines(java.lang.String text,
java.awt.Color color)
Checks whether a new text line should be merged with a preceding line.
|
void |
prune()
Prunes excess lines.
|
void |
removeBufferListener(BufferListener listener)
Removes a listener to be notified of changes.
|
void |
replaceLine(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.
|
@NotNull private final java.awt.font.FontRenderContext context
FontRenderContext
to use.@Nullable private java.awt.Color lastColor
private int lastCount
@NotNull private java.lang.String lastText
@NotNull private final java.util.List<Line> lines
@NotNull private final EventListenerList2<BufferListener> listeners
public static final int MAX_LINES
public static final int MIN_LINE_HEIGHT
private int renderWidth
@NotNull private final java.lang.Object sync
lines
and totalHeight
.private int totalHeight
lines
.public Buffer(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context, int renderWidth)
fonts
- the Fonts
instance for looking up fontscontext
- the FontRenderContext
to userenderWidth
- the width to renderpublic void addBufferListener(@NotNull BufferListener listener)
listener
- the listenerpublic void addLine(@NotNull Line line)
Line
to the end of the buffer.line
- the line to appendprivate int calculateHeight(@NotNull Line line)
Line
in pixels.line
- the line to processpublic void clear()
public int getLastCount()
mergeLines(String, Color)
did return true
.@NotNull public Line getLine(int line)
Line
by line index. The first line has the index
0
.line
- the line index@NotNull public java.lang.Object getSyncObject()
iterator()
or
listIterator(int)
.public int getTotalHeight()
@NotNull public java.util.Iterator<Line> iterator()
Iterator
for the lines in this buffer. The caller must
hold sync
's lock.@NotNull public java.util.Iterator<Line> listIterator(int line)
Iterator
for the lines in this buffer.line
- the initial line index of the list iteratorpublic boolean mergeLines(@NotNull java.lang.String text, @Nullable java.awt.Color color)
text
- the text line contentscolor
- the text line colorpublic void prune()
public void removeBufferListener(@NotNull BufferListener listener)
listener
- the listenerpublic void replaceLine(@NotNull Line line)
Line
of this buffer.line
- the replacing linepublic void setRenderWidth(int renderWidth)
renderWidth
- the width to renderpublic int size()