diff options
author | Siva Velusamy <vsiva@google.com> | 2011-10-12 10:28:16 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2011-10-12 10:53:56 -0700 |
commit | f19e453d85c3e44f64f55ccfa1105d3fbfbbbcbb (patch) | |
tree | 9924669ada4e70a686e332d02951591d85e0e3fa /ddms | |
parent | bd1e21fefb54f4debdca6f399c96df49d2f4bcb1 (diff) | |
download | sdk-f19e453d85c3e44f64f55ccfa1105d3fbfbbbcbb.zip sdk-f19e453d85c3e44f64f55ccfa1105d3fbfbbbcbb.tar.gz sdk-f19e453d85c3e44f64f55ccfa1105d3fbfbbbcbb.tar.bz2 |
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
Diffstat (limited to 'ddms')
-rw-r--r-- | ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java | 69 |
1 files changed, 41 insertions, 28 deletions
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: + * <ul> + * <li> Using the scrollbar: If the scrollbar is moved to the bottom, then auto scroll.</li> + * <li> Selecting an entry in the table: If the selected entry is not currently the last + * entry in the table, then do not scroll, otherwise auto scroll. + * </ul> + */ + 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: - * <ul> - * <li> Scroll if the scrollbar "thumb" is at the bottom of the scrollbar, i.e., - * the last line of the table is visible. </li> - * <li> Do not scroll otherwise. This happens if the user manually moves the thumb - * to scroll up the table. - * </ul> - * @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<ILogCatMessageSelectionListener> mMessageSelectionListeners; private void initDoubleClickListener() { |