protected void figureHistoryOffset ( Graphics2D gfx ) { if ( ! isLaidOut ( ) ) { return ; } int hei = _subtitleYSpacing ; int hsize = _history . size ( ) ; for ( int ii = 0 ; ii < hsize ; ii ++ ) { ChatGlyph rec = getHistorySubtitle ( ii , gfx ) ; Rectangle r = rec . getBounds ( ) ; hei += r . height ; // oop, we passed it, it was the last one if ( hei >= _subtitleHeight ) { _histOffset = Math . max ( 0 , ii - 1 ) ; _histOffsetFinal = true ; return ; } hei += getHistorySubtitleSpacing ( ii ) ; } // basically, this means there isn't yet enough history to fill the first 'page' of the // history scrollback, so we set the offset to the max value, but we do not set // _histOffsetFinal to be true so that this will be recalculated _histOffset = hsize - 1 ; }
Figure out how many of the first history elements fit in our bounds such that we can set the bounds on the scrollbar correctly such that the scrolling to the smallest value just barely puts the first element onscreen .