1 11 package org.eclipse.ui.texteditor; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.widgets.Shell; 15 16 import org.eclipse.jface.internal.text.html.BrowserInformationControl; 17 import org.eclipse.jface.internal.text.html.HTMLPrinter; 18 import org.eclipse.jface.internal.text.html.HTMLTextPresenter; 19 20 import org.eclipse.jface.text.AbstractReusableInformationControlCreator; 21 import org.eclipse.jface.text.DefaultInformationControl; 22 import org.eclipse.jface.text.IInformationControl; 23 import org.eclipse.jface.text.IInformationControlExtension4; 24 25 import org.eclipse.ui.editors.text.EditorsUI; 26 27 28 34 class RevisionHoverInformationControlCreator extends AbstractReusableInformationControlCreator { 35 36 private static final String fgStyleSheet= "/* Font definitions */\n" + "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" + "pre { font-family: monospace; font-size: 9pt }\n" + "\n" + "/* Margins */\n" + "body { overflow: auto; margin-top: 0; margin-bottom: 4; margin-left: 3; margin-right: 0 }\n" + "h1 { margin-top: 5; margin-bottom: 1 } \n" + "h2 { margin-top: 25; margin-bottom: 3 }\n" + "h3 { margin-top: 20; margin-bottom: 3 }\n" + "h4 { margin-top: 20; margin-bottom: 3 }\n" + "h5 { margin-top: 0; margin-bottom: 0 }\n" + "p { margin-top: 10px; margin-bottom: 10px }\n" + "pre { margin-left: 6 }\n" + "ul { margin-top: 0; margin-bottom: 10 }\n" + "li { margin-top: 0; margin-bottom: 0 } \n" + "li p { margin-top: 0; margin-bottom: 0 } \n" + "ol { margin-top: 0; margin-bottom: 10 }\n" + "dl { margin-top: 0; margin-bottom: 10 }\n" + "dt { margin-top: 0; margin-bottom: 0; font-weight: bold }\n" + "dd { margin-top: 0; margin-bottom: 0 }\n" + "\n" + "/* Styles and colors */\n" + "a:link { color: #0000FF }\n" + "a:hover { color: #000080 }\n" + "a:visited { text-decoration: underline }\n" + "h4 { font-style: italic }\n" + "strong { font-weight: bold }\n" + "em { font-style: italic }\n" + "var { font-style: italic }\n" + "th { font-weight: bold }\n" + ""; 68 private boolean fIsFocusable; 69 70 71 public RevisionHoverInformationControlCreator(boolean isFocusable) { 72 fIsFocusable= isFocusable; 73 } 74 75 78 public boolean canReuse(IInformationControl control) { 79 if (!super.canReuse(control)) 80 return false; 81 82 if (control instanceof IInformationControlExtension4) 83 ((IInformationControlExtension4)control).setStatusText(EditorsUI.getTooltipAffordanceString()); 84 85 return true; 86 } 87 88 91 protected IInformationControl doCreateInformationControl(Shell parent) { 92 int style= fIsFocusable ? SWT.V_SCROLL | SWT.H_SCROLL : SWT.NONE; 93 94 if (BrowserInformationControl.isAvailable(parent)) { 95 final int shellStyle= SWT.TOOL | (fIsFocusable ? SWT.RESIZE : SWT.NO_TRIM); 96 return new BrowserInformationControl(parent, shellStyle, style, EditorsUI.getTooltipAffordanceString()) { 97 98 101 public void setInformation(String content) { 102 content= addCSSToHTMLFragment(content); 103 super.setInformation(content); 104 } 105 106 113 private String addCSSToHTMLFragment(String html) { 114 int max= Math.min(100, html.length()); 115 if (html.substring(0, max).indexOf("<html>") != -1) return html; 118 119 StringBuffer info= new StringBuffer (512 + html.length()); 120 HTMLPrinter.insertPageProlog(info, 0, fgStyleSheet); 121 info.append(html); 122 HTMLPrinter.addPageEpilog(info); 123 return info.toString(); 124 } 125 }; 126 } 127 return new DefaultInformationControl(parent, style, new HTMLTextPresenter(), EditorsUI.getTooltipAffordanceString()); 128 } 129 } | Popular Tags |