diff options
author | Siva Velusamy <vsiva@google.com> | 2012-10-01 17:08:05 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2012-10-01 17:46:45 -0700 |
commit | 5b8be6e373ecd71d5743f07ed781cd7141928db4 (patch) | |
tree | 7ed8f70d20c70c3e24598efe26af1dac17b2c2ec /ddms/libs/ddmuilib/src | |
parent | 4caaf5a119a92faa7a9ef91c3e53c67491686140 (diff) | |
download | sdk-5b8be6e373ecd71d5743f07ed781cd7141928db4.zip sdk-5b8be6e373ecd71d5743f07ed781cd7141928db4.tar.gz sdk-5b8be6e373ecd71d5743f07ed781cd7141928db4.tar.bz2 |
logcat: Only listen to user generated scroll events
Scrolling behavior should not be altered when the scroll bar
location changes due to the addition of new messages.
Change-Id: Id38deb9f17d6d58bea6f25b33fed23c887c5cc5d
Diffstat (limited to 'ddms/libs/ddmuilib/src')
-rw-r--r-- | ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java | 58 |
1 files changed, 52 insertions, 6 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 9f38b29..4f27f02 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -51,6 +51,7 @@ import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; @@ -177,6 +178,11 @@ public final class LogCatPanel extends SelectionDependentPanel private ToolItem mScrollLockCheckBox; private boolean mAutoScrollLock; + // Lock under which the vertical scroll bar listener should be added + private final Object mScrollBarSelectionListenerLock = new Object(); + private SelectionListener mScrollBarSelectionListener; + private boolean mScrollBarListenerSet = false; + private String mLogFileExportFolder; private Font mFont; @@ -916,18 +922,28 @@ public final class LogCatPanel extends SelectionDependentPanel }); final ScrollBar vbar = mTable.getVerticalBar(); - vbar.addSelectionListener(new SelectionAdapter() { + mScrollBarSelectionListener = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!mAutoScrollLock) { return; } - boolean isAtBottom = (vbar.getThumb() + vbar.getSelection()) == vbar.getMaximum(); - setScrollToLatestLog(isAtBottom); - mScrollLockCheckBox.setSelection(isAtBottom); + // thumb + selection < max => bar is not at the bottom. + // We subtract an arbitrary amount (thumbSize/2) from this difference to allow + // for cases like half a line being displayed at the end from affecting this + // calculation. The thumbSize/2 number seems to work experimentally across + // Linux/Mac & Windows, but might possibly need tweaking. + int diff = vbar.getThumb() + vbar.getSelection() - vbar.getMaximum(); + boolean isAtBottom = Math.abs(diff) < vbar.getThumb() / 2; + + if (isAtBottom != mShouldScrollToLatestLog) { + setScrollToLatestLog(isAtBottom); + mScrollLockCheckBox.setSelection(isAtBottom); + } } - }); + }; + startScrollBarMonitor(vbar); // Explicitly set the values to use for the scroll bar. In particular, we want these values // to have a high enough accuracy that even small movements of the scroll bar have an @@ -943,6 +959,24 @@ public final class LogCatPanel extends SelectionDependentPanel THUMB); // page increment } + private void startScrollBarMonitor(ScrollBar vbar) { + synchronized (mScrollBarSelectionListenerLock) { + if (!mScrollBarListenerSet) { + mScrollBarListenerSet = true; + vbar.addSelectionListener(mScrollBarSelectionListener); + } + } + } + + private void stopScrollBarMonitor(ScrollBar vbar) { + synchronized (mScrollBarSelectionListenerLock) { + if (mScrollBarListenerSet) { + mScrollBarListenerSet = false; + vbar.removeSelectionListener(mScrollBarSelectionListener); + } + } + } + /** Setup menu to be displayed when right clicking a log message. */ private void addRightClickMenu(final Table table) { // This action will pop up a create filter dialog pre-populated with current selection @@ -1013,7 +1047,6 @@ public final class LogCatPanel extends SelectionDependentPanel private void setScrollToLatestLog(boolean scroll) { mShouldScrollToLatestLog = scroll; - if (scroll) { scrollToLatestLog(); } @@ -1209,6 +1242,10 @@ public final class LogCatPanel extends SelectionDependentPanel mTable.setRedraw(false); + // the scroll bar should only listen to user generated scroll events, not the + // scroll events that happen due to the addition of logs + stopScrollBarMonitor(mTable.getVerticalBar()); + // Obtain the list of new messages, and the number of deleted messages. List<LogCatMessage> newMessages; int deletedMessageCount; @@ -1285,6 +1322,15 @@ public final class LogCatPanel extends SelectionDependentPanel } mTable.setRedraw(true); + + // re-enable listening to scroll bar events, but do so in a separate thread to make + // sure that the current task (LogCatRefresherTask) has completed first + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + startScrollBarMonitor(mTable.getVerticalBar()); + } + }); } /** |