eclipse中console使用

来源:互联网 发布:足球数据分析大师app 编辑:程序博客网 时间:2024/06/04 19:21
最近对eclipse里的console使用比较感兴趣,时间又有闲,大致研究里了下如何在console里输出链接,改变字体颜色但是下面这段代码并不完善,link只能在document中使用,consoleStream就没法用MessageConsole console = new MessageConsole("Console Name", null);   ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });   MessageConsoleStream consoleStream = console.newMessageStream();   MessageConsoleStream consoleStream2 = console.newMessageStream();   ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);   String url = "http://www.baidu.com";   String url2 = "http://www.google.cn";   String time = new java.util.Date().toString();   //consoleStream.println(time);   console.getDocument().set(time+"\n");   //IDocument doc = console.getDocument();   try {    console.addHyperlink(new MyHyperLink(url), 0,3);    console.addHyperlink(new MyHyperLink(url2), 8,20);    FontData fontData = new FontData();    fontData.setStyle(SWT.BOLD);    Font font = new Font(Display.getDefault(),fontData);    console.setFont(font);       /*Color color = console.getBackground();    System.out.println("color="+color.toString());*/      } catch (BadLocationException e) {    // TODO Auto-generated catch block    e.printStackTrace();   }catch(Exception e){    e.printStackTrace();   }   consoleStream.println("red");   consoleStream.setColor(new Color(Display.getDefault(),255,0,0));   consoleStream2.println("blue");   consoleStream2.setColor(new Color(Display.getDefault(),0,0,255));/****************************   MyHyperLink   *******************************************/public class MyHyperLink implements IHyperlink {private URL url; public MyHyperLink(String urlStr){   try {    this.url = new URL(urlStr);   } catch (MalformedURLException e) {    e.printStackTrace();    this.url = null;   }}@Overridepublic void linkActivated() {   if(url!=null){    try {     PlatformUI.getWorkbench().getBrowserSupport().createBrowser(url.toString()).openURL(url);    } catch (PartInitException e) {     e.printStackTrace();    }   }}@Overridepublic void linkEntered(){System.out.println("link enter");}@Overridepublic void linkExited() {System.out.println("link exit");} }

原创粉丝点击