+ /**
+ * 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
+ }
+ });
+ }
+