22 package com.realtime.crossfire.jxclient.gui.log;
25 import java.awt.FontFormatException;
26 import java.awt.Graphics2D;
27 import java.awt.GraphicsConfiguration;
28 import java.awt.GraphicsDevice;
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Transparency;
31 import java.awt.image.BufferedImage;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.util.List;
35 import org.jetbrains.annotations.NotNull;
36 import org.junit.Assert;
37 import org.junit.Test;
49 private static final int HEIGHT = 104;
56 if (GraphicsEnvironment.isHeadless()) {
63 for (
int i = 0; i < HEIGHT+10; i++) {
94 if (GraphicsEnvironment.isHeadless()) {
169 private static class Rec {
187 final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
188 final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
189 final GraphicsConfiguration graphicsConfiguration = graphicsDevice.getDefaultConfiguration();
190 final BufferedImage image = graphicsConfiguration.createCompatibleImage(1, 1, Transparency.TRANSLUCENT);
191 final Graphics2D g = image.createGraphics();
194 try (
final InputStream fis = getClass().getClassLoader().getResourceAsStream(
"com/realtime/crossfire/jxclient/skins/ragnorok/fonts/regular.ttf")) {
196 font = Font.createFont(Font.TRUETYPE_FONT, fis);
197 }
catch (
final FontFormatException ex) {
199 throw new AssertionError(ex);
202 }
catch (
final IOException ex) {
204 throw new AssertionError(ex);
206 buffer =
new Buffer(
new Fonts(font, font, font, font), g.getFontRenderContext(), 100);
209 assert buffer != null;
215 public void lineAdded() {
217 assert buffer != null;
222 public void lineReplaced() {
224 assert buffer != null;
229 public void linesRemoved(@NotNull
final List<Line> lines) {
231 assert buffer != null;
236 assert buffer != null;
254 public void checkState(
final int expectedTopIndex,
final int expectedTopOffset) {
259 Assert.assertEquals(
formatState(expectedTopIndex, expectedTopOffset, expectedScrollPos),
formatState(topIndex, topOffset, scrollPos));
270 public String
formatState(
final int topIndex,
final int topOffset,
final int scrollPos) {
271 return "top="+topIndex+
"/"+topOffset+
" pos="+scrollPos+
"/"+buffer.
getTotalHeight();
static final int MAX_LINES
The maximum number of lines the buffer can hold.
Regression tests for RenderState.
String formatState(final int topIndex, final int topOffset, final int scrollPos)
Returns a text representation of the state.
int getTotalHeight()
Returns the total height of all lines.
void scrollTo(final int y)
Calls RenderState#scrollTo(Buffer, int).
void checkState(final int expectedTopIndex, final int expectedTopOffset)
Checks that the RenderState instance contains expected values.
int getTopIndex()
Returns the index of the first line to display.
static final int HEIGHT
Assumed height of log window.
Parser for parsing drawextinfo messages received from a Crossfire server to update a Buffer instance...
void linesReplaced(@NotNull final Buffer buffer)
Some lines have been replaced at the end of the buffer.
void test1()
General checks.
void linesAdded(@NotNull final Buffer buffer)
Some lines have been added to the buffer.
void test2()
Checks that overflowing the buffer works as expected.
int getScrollPos()
Returns the location of the view area in pixels.
void linesRemoved(@NotNull final Buffer buffer, @NotNull final Collection< Line > lines)
Some lines have been removed from the buffer.
void addBufferListener(@NotNull final BufferListener listener)
Adds a listener to notify of changes.
static final int MIN_LINE_HEIGHT
The minimal height of a line in pixels.
void setHeight(@NotNull final Buffer buffer, final int h)
Sets the the viewable height in pixel.
int getTopOffset()
Returns the number of pixels to shift the first displayed line.
final Buffer buffer
The tested Buffer instance.
Rec()
Creates a new instance.
Manages the contents of the contents of a log window.
void parse(@NotNull final CharSequence text, @Nullable final Color defaultColor, @NotNull final Buffer buffer)
Parses a text message.
Interface for listeners for changes of Buffer contents.
Encapsulates the state for a scroll bar.
final RenderState rs
The tested RenderState instance.
void scrollTo(@NotNull final Buffer buffer, final int y)
Scrolls to the given pixel location.