Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2002-11-28 22:09:29 +0000
committerDarin Wright2002-11-28 22:09:29 +0000
commit82401c0a0cdb8515c7a2b0baea7f237c1524740a (patch)
treec2f8381f9d32dc60ed7c87e321a4491c5c3a900b /org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java
parente43e0342f97439a15a02d5f33185c730a120e258 (diff)
downloadeclipse.platform.debug-82401c0a0cdb8515c7a2b0baea7f237c1524740a.tar.gz
eclipse.platform.debug-82401c0a0cdb8515c7a2b0baea7f237c1524740a.tar.xz
eclipse.platform.debug-82401c0a0cdb8515c7a2b0baea7f237c1524740a.zip
bug 26830
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java
new file mode 100644
index 000000000..99a547c9d
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleLineNotifier.java
@@ -0,0 +1,112 @@
+package org.eclipse.debug.internal.ui.views.console;
+
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
+This file is made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+**********************************************************************/
+
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.ui.console.IConsole;
+import org.eclipse.debug.ui.console.IConsoleLineTracker;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.util.ListenerList;
+
+/**
+ * Tracks text appended to the console and notifies listeners in terms of whole
+ * lines.
+ */
+public class ConsoleLineNotifier {
+
+ /**
+ * Number of lines processed in the console
+ */
+ private int fLinesProcessed = 0;
+
+ /**
+ * Console listeners
+ */
+ private ListenerList fListeners = new ListenerList(2);
+
+ /**
+ * The console this notifier is tracking
+ */
+ private IConsole fConsole = null;
+
+ /**
+ * Connects this notifier to the given console.
+ *
+ * @param console
+ */
+ public void connect(IConsole console) {
+ fConsole = console;
+ Object[] listeners = fListeners.getListeners();
+ for (int i = 0; i < listeners.length; i++) {
+ IConsoleLineTracker listener = (IConsoleLineTracker)listeners[i];
+ listener.init(console);
+ }
+ }
+
+ /**
+ * Disposes this notifier
+ */
+ public void disconnect() {
+ Object[] listeners = fListeners.getListeners();
+ for (int i = 0; i < listeners.length; i++) {
+ IConsoleLineTracker listener = (IConsoleLineTracker)listeners[i];
+ listener.dispose();
+ }
+ fListeners = null;
+ fConsole = null;
+ }
+
+ /**
+ * Notification the console has changed based on the given event
+ */
+ public void consoleChanged(DocumentEvent event) {
+ IDocument document = event.getDocument();
+ int lines = document.getNumberOfLines();
+ Object[] listeners = fListeners.getListeners();
+ for (int line = fLinesProcessed; line < lines; line++) {
+ String delimiter = null;
+ try {
+ delimiter = document.getLineDelimiter(line);
+ } catch (BadLocationException e) {
+ DebugUIPlugin.log(e);
+ return;
+ }
+ if (delimiter == null) {
+ // line not complete yet
+ return;
+ }
+ fLinesProcessed++;
+ IRegion lineRegion = null;
+ try {
+ lineRegion = document.getLineInformation(line);
+ } catch (BadLocationException e) {
+ DebugUIPlugin.log(e);
+ return;
+ }
+ for (int i = 0; i < listeners.length; i++) {
+ IConsoleLineTracker listener = (IConsoleLineTracker)listeners[i];
+ listener.lineAppended(lineRegion);
+ }
+ }
+ // TODO: what about the last line?
+ }
+
+ /**
+ * Adds the given listener to the list of listeners notified when a line of
+ * text is appended to the console.
+ *
+ * @param listener
+ */
+ public void addConsoleListener(IConsoleLineTracker listener) {
+ fListeners.add(listener);
+ }
+
+}

Back to the top