KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > swing > GoToLineThread


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25  
26
27 package org.aspectj.ajde.ui.swing;
28
29 import javax.swing.SwingUtilities JavaDoc;
30 import org.aspectj.ajde.*;
31
32 /**
33  * Used to ensure that a source line has been seeked to. Will repeatedly attempt
34  * to seek to the line until this has succeeded.
35  *
36  * @author Mik Kersten
37  */

38 public class GoToLineThread extends Thread JavaDoc {
39     private EditorAdapter editorAdapter = null;
40     
41     private int lineNumber = 0;
42     private String JavaDoc fileToSeekTo = "";
43     private boolean finished = false;
44
45     public boolean isFinished() {
46         return finished;
47     }
48
49     public boolean needsRetry() {
50         return !this.isAlive() && !finished;
51     }
52
53     public GoToLineThread(String JavaDoc fileToSeekTo, int lineNumber, EditorAdapter editorAdapter) {
54         this.lineNumber = lineNumber;
55         this.fileToSeekTo = fileToSeekTo;
56         this.editorAdapter = editorAdapter;
57     }
58
59     public void run() {
60
61         while(true) {
62             String JavaDoc file = editorAdapter.getCurrFile();
63             if (file != null) {
64                 if (file.equals(this.fileToSeekTo)) {
65                     try {
66                     SwingUtilities.invokeAndWait( new Runnable JavaDoc() {
67                         public void run() {
68                             editorAdapter.showSourceLine(lineNumber, true);
69                         }
70                     });
71                     } catch (Exception JavaDoc e) {
72                         Ajde.getDefault().getErrorHandler().handleError("Could not seek to line.", e);
73                     }
74                     finished = true;
75                     break;
76                 }
77                 shortPause();
78             }
79         }
80     }
81
82     private void shortPause() {
83         try {
84             this.sleep(100);
85         } catch (InterruptedException JavaDoc e) {
86             throw new RuntimeException JavaDoc(e.getMessage());
87         }
88     }
89 }
Popular Tags