22 package com.realtime.crossfire.jxclient.gui.log;
24 import java.util.Collection;
25 import org.jetbrains.annotations.NotNull;
40 private final Object
sync =
new Object();
88 final int bufferHeight = buffer.getTotalHeight();
90 final int oldHeight =
height;
92 if (bufferHeight <= height) {
97 canScrollDown =
false;
98 }
else if (topOffset < 0 || scrollPos > bufferHeight-height || scrollPos == bufferHeight-oldHeight) {
109 synchronized (
sync) {
112 }
else if (!canScrollDown) {
126 synchronized (
sync) {
127 if (topOffset < 0 || !canScrollDown) {
140 final int bufferHeight = buffer.getTotalHeight();
141 synchronized (
sync) {
142 if (bufferHeight <= height) {
147 canScrollDown =
false;
150 for (
final Line line : lines) {
151 scrollPos -= line.getHeight();
153 topIndex -= lines.size();
161 assert topIndex >= 0;
174 synchronized (
sync) {
184 synchronized (
sync) {
194 synchronized (
sync) {
204 synchronized (
sync) {
214 synchronized (
sync) {
227 synchronized (
sync) {
240 final int bufferHeight = buffer.getTotalHeight();
241 synchronized (
sync) {
242 if (bufferHeight > height) {
243 scrollPos = Math.max(Math.min(y, bufferHeight-height), 0);
247 final int lineHeight = buffer.getLine(topIndex).getHeight();
248 if (yPos < lineHeight) {
257 canScrollUp = topIndex > 0 || topOffset > 0;
258 canScrollDown = y+height < bufferHeight;
270 final int bufferHeight = buffer.getTotalHeight();
271 synchronized (
sync) {
272 if (bufferHeight <= height) {
277 canScrollDown =
false;
279 scrollPos = Math.max(bufferHeight-height, 0);
280 topIndex = buffer.size();
284 assert topIndex >= 0;
285 y -= buffer.getLine(topIndex).getHeight();
288 canScrollUp = topIndex > 0 || topOffset > 0;
289 canScrollDown =
false;
Manages the contents of one text line.
int height
The height of the viewable area.
boolean canScrollDown()
Returns whether scrolling down is possible.
int getTopIndex()
Returns the index of the first line to display.
void scrollToBottom(@NotNull final Buffer buffer)
Sets the view area to the bottom-most value.
void linesReplaced(@NotNull final Buffer buffer)
Some lines have been replaced at the end of the buffer.
int topIndex
The first line to display in the viewable area.
boolean canScrollUp
Whether scrolling up is possible.
void linesAdded(@NotNull final Buffer buffer)
Some lines have been added to the buffer.
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.
int topOffset
The number of pixels to shift the first displayed line (topIndex.
boolean canScrollDown
Whether scrolling down is possible.
final Object sync
Synchronization object for accesses to all fields.
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.
boolean mustRepaint()
Returns whether the view should be repainted even if no other values have changed.
boolean canScrollUp()
Returns whether scrolling up is possible.
int scrollPos
The location of the view area relative to the buffer's total height.
Manages the contents of the contents of a log window.
Encapsulates the state for a scroll bar.
void scrollTo(@NotNull final Buffer buffer, final int y)
Scrolls to the given pixel location.