From f19e453d85c3e44f64f55ccfa1105d3fbfbbbcbb Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Wed, 12 Oct 2011 10:28:16 -0700 Subject: Logcat autoscroll behavior update. Rather than checking the position of the thumb every time entries are added, we listen to the scroll bar being moved up or down by the user. In addition, also update the scrolling behavior whenever entries in the table are selected. Auto scrolling will stop if anything but the last entry is selected. Change-Id: I7b32e9c42bc8e2ad01171b61a5a9ef09d8d0a7b1 --- .../com/android/ddmuilib/logcat/LogCatPanel.java | 69 +++++++++++++--------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'ddms/libs') diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java index d918807..067c9c9 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -138,6 +138,7 @@ public final class LogCatPanel extends SelectionDependentPanel private Text mLiveFilterText; private TableViewer mViewer; + private boolean mShouldScrollToLatestLog = true; private String mLogFileExportFolder; private LogCatMessageLabelProvider mLogCatMessageLabelProvider; @@ -724,9 +725,48 @@ public final class LogCatPanel extends SelectionDependentPanel } }); + setupScrollBehavior(); initDoubleClickListener(); } + /** + * Update setting that controls if the table should scroll to reveal the latest logcat entry. + * Users can impact the scrolling behavior in two ways: + * + */ + private void setupScrollBehavior() { + mViewer.getTable().getVerticalBar().addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + ScrollBar sb = (ScrollBar) event.getSource(); + + // On Mac & Linux, when the scroll bar is at the bottom, + // sb.getSelection + sb.getThumb = sb.getMaximum + // But on Windows 7, the scrollbar never touches the bottom, and as a result + // sb.getSelection + sb.getThumb is slightly less than sb.getMaximum. + // So we assume that as long as the thumb is close to the bottom, we want to scroll. + mShouldScrollToLatestLog = + Math.abs(sb.getSelection() + sb.getThumb() - sb.getMaximum()) < 10; + } + }); + + mViewer.getTable().addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + Table table = (Table) event.getSource(); + int[] indices = table.getSelectionIndices(); + + mShouldScrollToLatestLog = + indices.length == 1 // only 1 item selected + && indices[0] == table.getItemCount() -1; // and it is the last entry + } + }); + } + private static class WrappingToolTipSupport extends ColumnViewerToolTipSupport { protected WrappingToolTipSupport(ColumnViewer viewer, int style, boolean manualActivation) { @@ -919,11 +959,9 @@ public final class LogCatPanel extends SelectionDependentPanel mCurrentRefresher = null; } - // find out if we need to scroll before refreshing the table - boolean shouldScroll = shouldScrollToLatestLog(); mViewer.refresh(); - if (shouldScroll) { + if (mShouldScrollToLatestLog) { scrollToLatestLog(); } } @@ -934,31 +972,6 @@ public final class LogCatPanel extends SelectionDependentPanel mViewer.getTable().setTopIndex(mViewer.getTable().getItemCount() - 1); } - /** - * Determine if the table should scroll to reveal the last entry. The scrolling - * behavior is as follows: - * - * @return true if table should be scrolled, false otherwise. - */ - private boolean shouldScrollToLatestLog() { - ScrollBar sb = mViewer.getTable().getVerticalBar(); - if (sb == null) { - return true; - } - - // On Mac & Linux, when the scroll bar is at the bottom, - // sb.getSelection + sb.getThumb = sb.getMaximum - // But on Windows 7, the scrollbar never touches the bottom, and as a result - // sb.getSelection + sb.getThumb is slightly less than sb.getMaximum. - // So we assume that as long as the thumb is close to the bottom, we want to scroll. - return Math.abs(sb.getSelection() + sb.getThumb() - sb.getMaximum()) < 10; - } - private List mMessageSelectionListeners; private void initDoubleClickListener() { -- cgit v1.1