`
annewman
  • 浏览: 30991 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

SWT custom HtmlToolTip

    博客分类:
  • SWT
阅读更多
public class HtmlTooltip extends BrowserInformationControl{
	
	public final static String APPEARANCE_JAVADOC_FONT= "org.eclipse.jdt.ui.javadocfont"; //$NON-NLS-1$
	
	private static final String fgStyleSheet= "/* Font definitions */\n" + //$NON-NLS-1$
	"body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt {font-family: sans-serif; font-size: 9pt }\n" + //$NON-NLS-1$
	"pre				{ font-family: monospace; font-size: 9pt }\n" + //$NON-NLS-1$
	"\n" + //$NON-NLS-1$
	"/* Margins */\n" + //$NON-NLS-1$
	"body	     { overflow: auto; margin-top: 0; margin-bottom: 4; margin-left: 3; margin-right: 0 }\n" + //$NON-NLS-1$
	"h1           { margin-top: 5; margin-bottom: 1 }	\n" + //$NON-NLS-1$
	"h2           { margin-top: 25; margin-bottom: 3 }\n" + //$NON-NLS-1$
	"h3           { margin-top: 20; margin-bottom: 3 }\n" + //$NON-NLS-1$
	"h4           { margin-top: 20; margin-bottom: 3 }\n" + //$NON-NLS-1$
	"h5           { margin-top: 0; margin-bottom: 0 }\n" + //$NON-NLS-1$
	"p            { margin-top: 10px; margin-bottom: 10px }\n" + //$NON-NLS-1$
	"pre	         { margin-left: 6 }\n" + //$NON-NLS-1$
	"ul	         { margin-top: 0; margin-bottom: 10 }\n" + //$NON-NLS-1$
	"li	         { margin-top: 0; margin-bottom: 0 } \n" + //$NON-NLS-1$
	"li p	     { margin-top: 0; margin-bottom: 0 } \n" + //$NON-NLS-1$
	"ol	         { margin-top: 0; margin-bottom: 10 }\n" + //$NON-NLS-1$
	"dl	         { margin-top: 0; margin-bottom: 10 }\n" + //$NON-NLS-1$
	"dt	         { margin-top: 0; margin-bottom: 0; font-weight: bold }\n" + //$NON-NLS-1$
	"dd	         { margin-top: 0; margin-bottom: 0 }\n" + //$NON-NLS-1$
	"\n" + //$NON-NLS-1$
	"/* Styles and colors */\n" + //$NON-NLS-1$
	"a:link	     { color: #0000FF }\n" + //$NON-NLS-1$
	"a:hover	     { color: #000080 }\n" + //$NON-NLS-1$
	"a:visited    { text-decoration: underline }\n" + //$NON-NLS-1$
	"h4           { font-style: italic }\n" + //$NON-NLS-1$
	"strong	     { font-weight: bold }\n" + //$NON-NLS-1$
	"em	         { font-style: italic }\n" + //$NON-NLS-1$
	"var	         { font-style: italic }\n" + //$NON-NLS-1$
	"th	         { font-weight: bold }\n" + //$NON-NLS-1$
	""; //$NON-NLS-1$

	
	public HtmlTooltip(Shell parent,boolean resizable) {
		super(parent, APPEARANCE_JAVADOC_FONT, resizable);
	}
	
	public HtmlTooltip(Shell parent, String symbolicFontName, boolean resizable) {
		super(parent, symbolicFontName, resizable);
	}
	
	protected void createContent(Composite parent) {
		super.createContent(parent);
		super.addLocationListener(new LocationListener() {
			
			public void changing(LocationEvent event) {
				String url = event.location;
				if (url.startsWith("about:")) {
					return;
				}
				event.doit = false;
				if( url.startsWith("http"))
					launchBrowser(url);
			}
			
			public void changed(LocationEvent event) {
				
			}
		});
	}
	
	protected void launchBrowser(String url) {
		// open url in external browser
		 Program.launch(url);		
	}

	public void setTooltip(String content){
		content= addCSSToHTMLFragment(content);
		super.setInformation(content);
	}

	/**
	 * Adds a HTML header and CSS info if <code>html</code> is only an HTML fragment (has no
	 * &lt;html&gt; section).
	 *
	 * @param html the html / text produced by a revision
	 * @return modified html
	 */
	private String addCSSToHTMLFragment(String html) {
		int max= Math.min(100, html.length());
		if (html.substring(0, max).indexOf("<html>") != -1) //$NON-NLS-1$
			// there is already a header
			return html;

		StringBuffer info= new StringBuffer(512 + html.length());
		HTMLPrinter.insertPageProlog(info, 0, fgStyleSheet);
		info.append(html);
		HTMLPrinter.addPageEpilog(info);
		return info.toString();
	}
}
 
0
1
分享到:
评论

相关推荐

    org.eclipse.swt.win32

    org.eclipse.swt.custom.StyledTextDropTargetEffect.class org.eclipse.swt.custom.StyledTextEvent.class org.eclipse.swt.custom.StyledTextListener.class org.eclipse.swt.custom.StyledTextPrintOptions.class...

    swt-64.rar_64位swt_64的SWT_SWT64_swt.jar 64位_swt64位

    标题“swt-64.rar_64位swt_64的SWT_SWT64_swt.jar 64位_swt64位”表明这个压缩包包含了适用于64位Windows操作系统的SWT库。描述中提到的“64位windows操作系统使用的SWT库”进一步确认了这一点。 SWT的设计目标是...

    SWT源码 swt.jar

    SWT(Standard Widget Toolkit)是Eclipse项目的一个重要组成部分,它提供了一套用于构建图形用户界面(GUI)的API,与Java Swing不同,SWT基于操作系统原生的UI组件,因此能够实现更好的性能和与操作系统的集成。...

    SWT配置 SWT配置 SWT配置 SWT配置 SWT配置

    ### SWT配置详解 #### 一、SWT简介与配置的重要性 SWT(Standard Widget Toolkit)是一种用于构建基于Java的应用程序的图形用户界面工具包。它提供了丰富的控件集,并能够生成本地外观和感觉的界面,这使得应用在...

    SWT源代码 SWT Source code

    6. `os_custom.c`:这部分代码可能包含了一些针对特定操作系统的定制功能,使得SWT能够更好地适应不同平台的特性。 7. `swt_awt.c`:SWT和Java AWT(Abstract Window Toolkit)之间的桥梁。AWT是Java的标准GUI库,...

    swt-api swt DOC

    【标题】"swt-api swt DOC" 指的是一个关于SWT(Standard Widget Toolkit)API的文档,主要用于Java GUI(图形用户界面)开发。这个文档可能是开发者们在使用SWT进行界面设计时的重要参考资料。 【描述】"java界面...

    swt教程 有关SWT怎么应用

    在本文中,我们将深入探讨SWT(Standard Widget Toolkit)的应用,以及如何在Java应用程序中使用它。SWT是由IBM公司为Eclipse集成开发环境设计的一种图形用户界面(GUI)工具包,它通过JNI(Java Native Interface)...

    java界面库swt.jar 4.911

    下载编译的SWT库,版本号4.911,包含多个版本: org.eclipse.swt.cocoa.macosx.x86_64 org.eclipse.swt.gtk.linux.aarch64 org.eclipse.swt.gtk.linux.arm org.eclipse.swt.gtk.linux.ppc64le org.eclipse.swt.gtk....

    SWT JFace 按键、事件、监听

    ### SWT JFace 按键、事件、监听 #### 概述 SWT(Standard Widget Toolkit)是Eclipse平台下的图形界面开发工具包,而JFace则是基于SWT之上的高级用户界面工具集。SWT提供了低级别的组件,用于创建跨平台的图形...

    swt工具文档 swt工具文档

    SWT(Standard Widget Toolkit)是Java编程环境中一个用于创建图形用户界面(GUI)的开源库。它是Eclipse项目的一部分,旨在提供与操作系统更紧密的集成,使得开发者可以创建原生外观的应用程序。SWT提供了丰富的...

    org.eclipse.swt 相关jar包

    org.eclipse.swt 相关jar包,JAVA调用火狐内核制作浏览器教程中所需,供各位下载,可在我的博客中查看详细用法。

    SWT Tree 完整的树例子源码

    **SWT Tree 全面解析** SWT(Standard Widget Toolkit)是Java中用于构建桌面应用程序的一个开源GUI库,它是Eclipse开发平台的基础。在SWT中,Tree组件用于展示层次结构的数据,类似于Windows资源管理器中的文件...

    swt table 实现换行

    根据提供的文件信息,可以看出本文主要讨论的是如何在 SWT (Standard Widget Toolkit) 的 Table 控件中实现文本换行的功能。SWT 是一个用于开发基于 Java 的桌面应用程序的工具包,它提供了丰富的用户界面组件来帮助...

    swt.jar swt.jar swt.jar

    swt.jar swt.jar swt.jar swt.jar swt.jar

    DJNativeSwing-SWT.jar、DJNativeSwing.jar、swt-win-x64.jar

    DJNativeSwing和SWT虽然不是专门用于这种场景,但在某些情况下,例如需要在Swing或SWT界面中显示HTML内容时,它们可能会发挥作用。 总结来说,DJNativeSwing-SWT.jar和DJNativeSwing.jar是用于在Java Swing应用中...

    swt windows平台64位的包

    SWT (Standard Widget Toolkit) 是一个开放源代码的Java库,用于在各种操作系统上创建图形用户界面(GUI)。它是Eclipse项目的一部分,提供了一种替代Java标准库AWT和Swing的方式,允许开发者构建与本机系统更加紧密...

    SWT 弹出对话框 可以选择的图标种类

    SWT(Standard Widget Toolkit)是Java编程中用于创建图形用户界面(GUI)的一种库,它为开发者提供了丰富的控件和对话框。在SWT中,`MessageBox`是一个用于显示简单的消息对话框的类,通常用来向用户显示警告、确认...

    java swt自定义控件

    Java SWT(Standard Widget Toolkit)是Java平台上用于创建桌面应用程序的一个库,它提供了丰富的用户界面元素,如按钮、文本框、列表等。SWT是Eclipse IDE的基础,它通过与操作系统直接交互来提供本地化的图形用户...

    SWT_全接触 SWT_全接触 SWT_全接触

    根据给定的信息,本文将详细介绍SWT(Standard Widget Toolkit)的相关知识点,包括其背景、特点、与AWT/Swing的对比以及如何开始使用SWT。 ### SWT简介 SWT(Standard Widget Toolkit)是一个开放源码的原生GUI...

    swt编程,不错的电子书

    SWT控件通常位于`org.eclipse.swt.widget`和`org.eclipse.swt.custom`包中。前者包含了基于操作系统控件的基础组件,后者提供了额外的定制控件,它们通常以"C"开头,如CLabel和Label。 7. 父子关系 在SWT中,除了...

Global site tag (gtag.js) - Google Analytics