KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > console > J9ConsoleTracker


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.console;
12
13
14 import org.eclipse.debug.ui.console.IConsole;
15 import org.eclipse.debug.ui.console.IConsoleHyperlink;
16 import org.eclipse.debug.ui.console.IConsoleLineTracker;
17 import org.eclipse.jface.text.BadLocationException;
18 import org.eclipse.jface.text.IRegion;
19
20 /**
21  * Provides links for stack traces in J9 output
22  */

23 public class J9ConsoleTracker implements IConsoleLineTracker {
24     
25     /**
26      * The console associated with this line tracker
27      */

28     private IConsole fConsole;
29     
30     private StringMatcher fJ9Matcher;
31
32     /**
33      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
34      */

35     public void init(IConsole console) {
36         fConsole = console;
37         fJ9Matcher = new StringMatcher("*.*(*)*", false, false); //$NON-NLS-1$
38
}
39
40     /**
41      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
42      */

43     public void lineAppended(IRegion line) {
44         try {
45             int offset = line.getOffset();
46             int length = line.getLength();
47             String JavaDoc text = fConsole.getDocument().get(offset, length);
48             int index = -1;
49             if (fJ9Matcher.match(text)) {
50                 // find the last space in the line
51
index = text.lastIndexOf(' ');
52                 if (index >= 0) {
53                     int linkOffset = offset + index + 1;
54                     int linkLength = length - index - 1;
55                     IConsoleHyperlink link = null;
56                     link = new J9StackTraceHyperlink(fConsole);
57                     fConsole.addLink(link, linkOffset, linkLength);
58                 }
59             }
60         } catch (BadLocationException e) {
61         }
62     }
63
64     /**
65      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
66      */

67     public void dispose() {
68         fConsole = null;
69         fJ9Matcher = null;
70     }
71
72 }
73
Popular Tags