From eae62907a30288c1c7b6b8ebb2c848c7394c9067 Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Tue, 13 Dec 2011 18:16:27 -0800 Subject: logcat: Improve auto scroll lock behavior Setting up scroll lock automatically is broken due to the highly platform dependent nature of the scroll bar events. This patch improves the current situation significantly, but may not be the last word on this subject. This patch does the following: 1. Sets up auto scroll lock on Windows and Linux. 2. Removes auto scroll locking on Mac. Users have to manually press the Pause Logcat button. 3. Renames the "Scroll to latest" button to "Pause Logcat" to more accurately reflect what is happening. Change-Id: I1ce03371d7ac7aeaea218aa3c5c426c69c56a527 --- .../com/android/ddmuilib/logcat/LogCatPanel.java | 125 +++++++++++++-------- ddms/libs/ddmuilib/src/images/pause_logcat.png | Bin 0 -> 180 bytes ddms/libs/ddmuilib/src/images/scroll_latest.png | Bin 291 -> 0 bytes 3 files changed, 79 insertions(+), 46 deletions(-) create mode 100644 ddms/libs/ddmuilib/src/images/pause_logcat.png delete mode 100644 ddms/libs/ddmuilib/src/images/scroll_latest.png (limited to 'ddms') 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 608086d..f910c14 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -66,6 +66,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; @@ -120,7 +121,7 @@ public final class LogCatPanel extends SelectionDependentPanel private static final String IMAGE_SAVE_LOG_TO_FILE = "save.png"; //$NON-NLS-1$ private static final String IMAGE_CLEAR_LOG = "clear.png"; //$NON-NLS-1$ private static final String IMAGE_DISPLAY_FILTERS = "displayfilters.png"; //$NON-NLS-1$ - private static final String IMAGE_SCROLL_TO_LATEST = "scroll_latest.png"; //$NON-NLS-1$ + private static final String IMAGE_PAUSE_LOGCAT = "pause_logcat.png"; //$NON-NLS-1$ private static final int[] WEIGHTS_SHOW_FILTERS = new int[] {15, 85}; private static final int[] WEIGHTS_LOGCAT_ONLY = new int[] {0, 100}; @@ -142,7 +143,8 @@ public final class LogCatPanel extends SelectionDependentPanel private TableViewer mViewer; private boolean mShouldScrollToLatestLog = true; - private ToolItem mScrollToLastCheckBox; + private ToolItem mPauseLogcatCheckBox; + private boolean mLastItemPainted = false; private String mLogFileExportFolder; private LogCatMessageLabelProvider mLogCatMessageLabelProvider; @@ -570,17 +572,17 @@ public final class LogCatPanel extends SelectionDependentPanel } }); - mScrollToLastCheckBox = new ToolItem(toolBar, SWT.CHECK); - mScrollToLastCheckBox.setImage( - ImageLoader.getDdmUiLibLoader().loadImage(IMAGE_SCROLL_TO_LATEST, + mPauseLogcatCheckBox = new ToolItem(toolBar, SWT.CHECK); + mPauseLogcatCheckBox.setImage( + ImageLoader.getDdmUiLibLoader().loadImage(IMAGE_PAUSE_LOGCAT, toolBar.getDisplay())); - mScrollToLastCheckBox.setSelection(true); - mScrollToLastCheckBox.setToolTipText("Scroll to display the latest logcat message."); - mScrollToLastCheckBox.addSelectionListener(new SelectionAdapter() { + mPauseLogcatCheckBox.setSelection(false); + mPauseLogcatCheckBox.setToolTipText("Pause receiving new logcat messages."); + mPauseLogcatCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - boolean shouldScroll = mScrollToLastCheckBox.getSelection(); - setScrollToLatestLog(shouldScroll, false); + boolean pauseLogcat = mPauseLogcatCheckBox.getSelection(); + setScrollToLatestLog(!pauseLogcat, false); } }); } @@ -792,55 +794,86 @@ public final class LogCatPanel extends SelectionDependentPanel } }); - setupScrollBehavior(); + setupAutoScrollLockBehavior(); 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: - *