@@ -686,6 +686,7 @@ public void execute() {
686
686
updateRowGrouping ();
687
687
688
688
resetCellContents ();
689
+ relayoutSheet (false );
689
690
loaded = true ;
690
691
}
691
692
});
@@ -762,31 +763,29 @@ public void relayoutSheet(boolean triggerRequest) {
762
763
final int rightBound = leftFrozenPanelWidth + scrollLeft
763
764
+ scrollViewWidth + actionHandler .getColumnBufferSize ();
764
765
765
- int leftEdgeChange = newFirstColumnPosition - firstColumnPosition ;
766
766
int rightEdgeChange = newLastColumnPosition - lastColumnPosition ;
767
767
firstColumnPosition = newFirstColumnPosition ;
768
768
lastColumnPosition = newLastColumnPosition ;
769
769
770
770
// always call handle scroll left, otherwise
771
771
// expanding groups with layouts does not work
772
- handleHorizontalScrollLeft (scrollLeft );
772
+ handleHorizontalScroll (scrollLeft , hScrollDiff );
773
773
updateCells (0 , -1 );
774
774
775
775
if (rightEdgeChange < 0 || hScrollDiff > 0
776
776
|| (lastColumnIndex < actionHandler .getMaxColumns ()
777
777
&& lastColumnPosition < rightBound )) {
778
- handleHorizontalScrollRight (scrollLeft );
779
778
updateCells (0 , 1 );
780
779
}
781
780
781
+ handleVerticalScroll (scrollTop , vScrollDiff );
782
+
782
783
if (topEdgeChange > 0 || vScrollDiff < 0 ) {
783
- handleVerticalScrollUp (scrollTop );
784
784
updateCells (-1 , 0 );
785
785
}
786
786
if (bottomEdgeChange != 0 || vScrollDiff > 0
787
787
|| (lastRowIndex < actionHandler .getMaxRows ()
788
788
&& lastRowPosition < bottomBound )) {
789
- handleVerticalScrollDown (scrollTop );
790
789
updateCells (1 , 0 );
791
790
}
792
791
resetRowAndColumnStyles ();
@@ -2311,15 +2310,15 @@ private void createOverlayStyles(StyleElement stylesheet,
2311
2310
2312
2311
private int calculateLeftValueOfScrolledColumns () {
2313
2312
int left = 0 ;
2314
- for (int i = 1 ; i < ( firstColumnIndex - horizontalSplitPosition ) ; i ++) {
2313
+ for (int i = horizontalSplitPosition + 1 ; i < firstColumnIndex ; i ++) {
2315
2314
left += actionHandler .getColWidth (i );
2316
2315
}
2317
2316
return left ;
2318
2317
}
2319
2318
2320
2319
private int calculateTopValueOfScrolledRows () {
2321
2320
int top = 0 ;
2322
- for (int i = 1 ; i < ( firstRowIndex - verticalSplitPosition ) ; i ++) {
2321
+ for (int i = verticalSplitPosition + 1 ; i < firstRowIndex ; i ++) {
2323
2322
top += definedRowHeights [i - 1 ];
2324
2323
}
2325
2324
return top ;
@@ -2992,7 +2991,7 @@ private void clearListOfCells(ArrayList<Cell> row) {
2992
2991
* handler (if needed).
2993
2992
*/
2994
2993
private void onSheetScroll () {
2995
- int scrollTop = topFrozenPanelHeight + sheet .getScrollTop ();
2994
+ int scrollTop = sheet .getScrollTop ();
2996
2995
int scrollLeft = sheet .getScrollLeft ();
2997
2996
int vScrollDiff = scrollTop - previousScrollTop ;
2998
2997
int hScrollDiff = scrollLeft - previousScrollLeft ;
@@ -3007,21 +3006,13 @@ private void onSheetScroll() {
3007
3006
if (Math .abs (
3008
3007
hScrollDiff ) > (actionHandler .getColumnBufferSize () / 2 )) {
3009
3008
previousScrollLeft = scrollLeft ;
3010
- if (hScrollDiff > 0 ) {
3011
- handleHorizontalScrollRight (scrollLeft );
3012
- } else if (hScrollDiff < 0 ) {
3013
- handleHorizontalScrollLeft (scrollLeft );
3014
- }
3009
+ handleHorizontalScroll (scrollLeft , hScrollDiff );
3015
3010
}
3016
3011
3017
3012
if (Math .abs (
3018
3013
vScrollDiff ) > (actionHandler .getRowBufferSize () / 2 )) {
3019
3014
previousScrollTop = scrollTop ;
3020
- if (vScrollDiff > 0 ) {
3021
- handleVerticalScrollDown (scrollTop );
3022
- } else if (vScrollDiff < 0 ) {
3023
- handleVerticalScrollUp (scrollTop );
3024
- }
3015
+ handleVerticalScroll (scrollTop , vScrollDiff );
3025
3016
}
3026
3017
requester .trigger ();
3027
3018
} catch (Throwable t ) {
@@ -3310,15 +3301,49 @@ private void updateCells(int vScrollDiff, int hScrollDiff) {
3310
3301
}
3311
3302
}
3312
3303
3313
- private void handleHorizontalScrollLeft (int scrollLeft ) {
3304
+ /**
3305
+ * Handles horizontal scrolling in the spreadsheet. It calculates the
3306
+ * visible columns and updates the column headers accordingly.
3307
+ *
3308
+ * The method takes the current scroll position and the difference since the
3309
+ * last update to determine how many columns to display.
3310
+ *
3311
+ * @param scrollLeft
3312
+ * the current scroll position from the left
3313
+ * @param scrollDiff
3314
+ * the difference in scroll position since the last update
3315
+ */
3316
+ private void handleHorizontalScroll (int scrollLeft , int scrollDiff ) {
3317
+ if (scrollDiff == 0 ) {
3318
+ return ; // no scroll
3319
+ }
3320
+
3314
3321
int columnBufferSize = actionHandler .getColumnBufferSize ();
3315
3322
int leftBound = scrollLeft - columnBufferSize ;
3316
- int rightBound = scrollLeft + scrollViewWidth + columnBufferSize ;
3323
+ int rightBound = leftFrozenPanelWidth + scrollLeft + scrollViewWidth
3324
+ + columnBufferSize ;
3317
3325
3318
3326
if (leftBound < 0 ) {
3319
3327
leftBound = 0 ;
3320
3328
}
3321
3329
3330
+ if (scrollDiff > 0 ) {
3331
+ handleHorizontalScrollRight (leftBound , rightBound );
3332
+ } else {
3333
+ handleHorizontalScrollLeft (leftBound , rightBound );
3334
+ }
3335
+
3336
+ }
3337
+
3338
+ /**
3339
+ * Handles horizontal scrolling to the left in the sheet.
3340
+ *
3341
+ * @param leftBound
3342
+ * the left bound of the visible area
3343
+ * @param rightBound
3344
+ * the right bound of the visible area
3345
+ */
3346
+ private void handleHorizontalScrollLeft (int leftBound , int rightBound ) {
3322
3347
int maxFirstColumn = horizontalSplitPosition + 1 ; // hSP is 0 when no
3323
3348
while (firstColumnPosition > leftBound
3324
3349
&& firstColumnIndex > maxFirstColumn ) {
@@ -3355,15 +3380,7 @@ private void handleHorizontalScrollLeft(int scrollLeft) {
3355
3380
*
3356
3381
* @param scrollLeft
3357
3382
*/
3358
- private void handleHorizontalScrollRight (int scrollLeft ) {
3359
- int columnBufferSize = actionHandler .getColumnBufferSize ();
3360
- int leftBound = scrollLeft - columnBufferSize ;
3361
- int rightBound = scrollLeft + scrollViewWidth + columnBufferSize ;
3362
-
3363
- if (leftBound < 0 ) {
3364
- leftBound = 0 ;
3365
- }
3366
-
3383
+ private void handleHorizontalScrollRight (int leftBound , int rightBound ) {
3367
3384
final int maximumCols = actionHandler .getMaxColumns ();
3368
3385
while (lastColumnPosition < rightBound
3369
3386
&& lastColumnIndex < maximumCols ) {
@@ -3389,15 +3406,50 @@ private void handleHorizontalScrollRight(int scrollLeft) {
3389
3406
resetColHeaders ();
3390
3407
}
3391
3408
3392
- private void handleVerticalScrollDown (int scrollTop ) {
3409
+ /**
3410
+ * Handles vertical scrolling in the spreadsheet. It calculates the visible
3411
+ * rows and updates the row headers accordingly.
3412
+ *
3413
+ * The method takes the current scroll position and the difference since the
3414
+ * last update to determine how many rows to display.
3415
+ *
3416
+ * @param scrollTop
3417
+ * the current scroll position from the top
3418
+ * @param scrollDiff
3419
+ * the difference in scroll position since the last update
3420
+ */
3421
+ private void handleVerticalScroll (int scrollTop , int scrollDiff ) {
3422
+ if (scrollDiff == 0 ) {
3423
+ return ; // no scroll
3424
+ }
3425
+
3393
3426
int rowBufferSize = actionHandler .getRowBufferSize ();
3394
3427
int topBound = scrollTop - rowBufferSize ;
3395
- int bottomBound = scrollTop + scrollViewHeight + rowBufferSize ;
3428
+ int bottomBound = topFrozenPanelHeight + scrollTop + scrollViewHeight
3429
+ + rowBufferSize ;
3396
3430
3397
3431
if (topBound < 0 ) {
3398
3432
topBound = 0 ;
3399
3433
}
3400
3434
3435
+ if (scrollDiff > 0 ) {
3436
+ handleVerticalScrollDown (topBound , bottomBound );
3437
+ } else {
3438
+ handleVerticalScrollUp (topBound , bottomBound );
3439
+ }
3440
+
3441
+ }
3442
+
3443
+ /**
3444
+ * Calculates viewed cells after a scroll down. Runs the escalator for row
3445
+ * headers.
3446
+ *
3447
+ * @param topBound
3448
+ * the top bound of the visible area
3449
+ * @param bottomBound
3450
+ * the bottom bound of the visible area
3451
+ */
3452
+ private void handleVerticalScrollDown (int topBound , int bottomBound ) {
3401
3453
final int maximumRows = actionHandler .getMaxRows ();
3402
3454
while (lastRowPosition < bottomBound && lastRowIndex < maximumRows ) {
3403
3455
if ((firstRowPosition + getRowHeight (firstRowIndex )) < topBound ) {
@@ -3417,15 +3469,16 @@ private void handleVerticalScrollDown(int scrollTop) {
3417
3469
resetRowHeaders ();
3418
3470
}
3419
3471
3420
- private void handleVerticalScrollUp (int scrollTop ) {
3421
- int rowBufferSize = actionHandler .getRowBufferSize ();
3422
- int topBound = scrollTop - rowBufferSize ;
3423
- int bottomBound = scrollTop + scrollViewHeight + rowBufferSize ;
3424
-
3425
- if (topBound < 0 ) {
3426
- topBound = 0 ;
3427
- }
3428
-
3472
+ /**
3473
+ * Calculates viewed cells after a scroll up. Runs the escalator for row
3474
+ * headers.
3475
+ *
3476
+ * @param topBound
3477
+ * the top bound of the visible area
3478
+ * @param bottomBound
3479
+ * the bottom bound of the visible area
3480
+ */
3481
+ private void handleVerticalScrollUp (int topBound , int bottomBound ) {
3429
3482
int maxTopRow = verticalSplitPosition + 1 ; // vSP is 0 when no split
3430
3483
while (firstRowPosition > topBound && firstRowIndex > maxTopRow ) {
3431
3484
if ((lastRowPosition - getRowHeight (lastRowIndex )) > bottomBound ) {
0 commit comments