1 19 package org.netbeans.modules.ruby.rubyproject.execution; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 24 import javax.swing.SwingUtilities ; 25 import javax.swing.text.Document ; 26 27 import org.openide.ErrorManager; 28 import org.openide.cookies.EditorCookie; 29 import org.openide.cookies.LineCookie; 30 import org.openide.cookies.OpenCookie; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.loaders.DataObject; 34 import org.openide.text.Line; 35 import org.openide.windows.OutputEvent; 36 import org.openide.windows.OutputListener; 37 38 47 class OutputProcessor implements OutputListener { 48 private final String file; 49 private final int lineno; 50 private final FileLocator fileLocator; 51 52 OutputProcessor(String file, int lineno, FileLocator fileLocator) { 53 if (lineno < 0) { 54 lineno = 0; 55 } 56 57 this.file = file; 59 this.lineno = lineno; 60 this.fileLocator = fileLocator; 61 } 62 63 public void outputLineSelected(OutputEvent ev) { 64 } 66 67 public void outputLineAction(OutputEvent ev) { 68 FileObject fo = findFile(file); 70 71 if (fo != null) { 72 open(fo, lineno); 73 } 74 } 75 76 private FileObject findFile(String file) { 77 if (fileLocator != null) { 78 FileObject fo = fileLocator.find(file); 79 80 if (fo != null) { 81 return fo; 82 } 83 } 84 85 return FileUtil.toFileObject(new File (file)); 88 } 89 90 public void outputLineCleared(OutputEvent ev) { 91 } 92 93 public static boolean open(final FileObject fo, final int lineno) { 94 if (!SwingUtilities.isEventDispatchThread()) { 95 SwingUtilities.invokeLater(new Runnable () { 96 public void run() { 97 open(fo, lineno); 98 } 99 }); 100 101 return true; } 103 104 try { 105 DataObject od = DataObject.find(fo); 106 EditorCookie ec = (EditorCookie)od.getCookie(EditorCookie.class); 107 LineCookie lc = (LineCookie)od.getCookie(LineCookie.class); 108 109 if ((ec != null) && (lc != null)) { 110 Document doc = ec.openDocument(); 111 112 if (doc != null) { 113 int line = lineno; 114 115 if (line < 1) { 116 line = 1; 117 } 118 119 Line l = lc.getLineSet().getCurrent(line - 1); 120 121 if (l != null) { 122 l.show(Line.SHOW_GOTO); 123 124 return true; 125 } 126 } 127 } 128 129 OpenCookie oc = (OpenCookie)od.getCookie(OpenCookie.class); 130 131 if (oc != null) { 132 oc.open(); 133 134 return true; 135 } 136 } catch (IOException e) { 137 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 138 } 139 140 return false; 141 } 142 } 143 | Popular Tags |