BaseKeyboardOperation implements KeyboardOperation { protected boolean scrollSelectedCellIntoView(final GridWidget gridWidget) { if (!isSelectionOriginSet(gridWidget) && !isHeaderSelectionOriginSet(gridWidget)) { return false; } boolean isHeaderCellSelected = false; if (!isSelectionOriginSet(gridWidget) && isHeaderSelectionOriginSet(gridWidget)) { isHeaderCellSelected = true; } if (!isGridColumnCandidateForScroll(gridWidget, isHeaderCellSelected)) { return false; } final double dx = getCellScrollDeltaX(gridWidget, isHeaderCellSelected); final double dy = getCellScrollDeltaY(gridWidget, isHeaderCellSelected); if (dx != 0 || dy != 0) { adjustViewportTransform(gridLayer.getViewport(), new Point2D(dx, dy)); } return true; } BaseKeyboardOperation(final GridLayer gridLayer); @Override TriStateBoolean isShiftKeyDown(); @Override TriStateBoolean isControlKeyDown(); @Override boolean isExecutable(final GridWidget gridWidget);  }
@Test public void scrollSelectedCellIntoView_NoSelection() { assertFalse(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); }
@Test public void scrollSelectedCellIntoView_NoRenderedInformation() { List<GridData.SelectedCell> selectedCells = Arrays.asList(new GridData.SelectedCell(0, 0)); when(gridData.getSelectedHeaderCells()).thenReturn(selectedCells); when(baseGridRendererHelperMock.getRenderingInformation()).thenReturn(null); assertFalse(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); }
@Test public void scrollSelectedCellIntoView_HeaderSelected() { when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 0))); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, never()).getViewport(); verify(viewport, never()).getTransform(); }
@Test public void scrollSelectedCellIntoView_CellSelected() { when(gridData.getSelectedCellsOrigin()).thenReturn(new GridData.SelectedCell(0, 0)); when(gridData.getRow(0)).thenReturn(gridRow); when(gridRow.getHeight()).thenReturn(30d); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, never()).getViewport(); verify(viewport, never()).getTransform(); }
@Test public void scrollSelectedCellIntoView_HeaderSelected_WithDeltaXScroll() { when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 0))); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(600, 0, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(600, 0); }
@Test public void scrollSelectedCellIntoView_CellSelected_WithDeltaXScroll() { when(gridData.getSelectedCellsOrigin()).thenReturn(new GridData.SelectedCell(0, 0)); when(gridData.getRow(0)).thenReturn(gridRow); when(gridRow.getHeight()).thenReturn(30d); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(500, 0, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(500d, 0); }
@Test public void scrollSelectedCellIntoView_HeaderSelected_WithDeltaYScroll() { when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 0))); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(0, 250, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(0, 250); }
@Test public void scrollSelectedCellIntoView_CellSelected_WithDeltaYScroll() { when(gridData.getSelectedCellsOrigin()).thenReturn(new GridData.SelectedCell(0, 0)); when(gridData.getRow(0)).thenReturn(gridRow); when(gridRow.getHeight()).thenReturn(30d); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(0, 400, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(0, 400); }
@Test public void scrollSelectedCellIntoView_HeaderSelected_WithDeltaXYScroll() { when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 0))); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(50, 75, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(50, 75); }
@Test public void scrollSelectedCellIntoView_CellSelected_WithDeltaXYScroll() { when(gridData.getSelectedCellsOrigin()).thenReturn(new GridData.SelectedCell(0, 0)); when(gridData.getRow(0)).thenReturn(gridRow); when(gridRow.getHeight()).thenReturn(30d); when(layer.getVisibleBounds()).thenReturn(new BaseBounds(75, 100, BOUNDS_WIDTH, BOUNDS_HEIGHT)); assertTrue(baseKeyboardOperationSpy.scrollSelectedCellIntoView(gridWidget)); verify(layer, times(1)).getViewport(); verify(viewport, times(1)).getTransform(); verify(transform, times(1)).scale(1, 1); verify(transform, times(1)).translate(75, 100); }