Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 67c6ffc0f34deb5e7b33ccb61bf5f69407926ed1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
 * Copyright (c) 2009 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Alexander Kurtakov - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.man.views;

import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.linuxtools.man.parser.ManDocument;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.widgets.Composite;

/**
 * Text viewer for a man page.
 * 
 */
public class ManTextViewer extends SourceViewer {

	/**
	 * Creates a resizable text viewer.
	 * 
	 * @param parent
	 */
	public ManTextViewer(Composite parent) {
		super(parent, null, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		// setEditable(false);
	}

	/**
	 * Sets the document to display.
	 * 
	 * @param document
	 *            The document to display.
	 */
	public void setDocument(ManDocument document) {
		super.setDocument(document);
		TextPresentation style = new TextPresentation();
		for (int underlineSymbol : document.getUnderlinedSymbols()) {
			StyleRange styleRange = new StyleRange(underlineSymbol, 1, null,
					null, SWT.NORMAL);
			styleRange.underline = true;
			style.addStyleRange(styleRange);
		}
		for (int boldSymbol : document.getBoldSymbols()) {
			style.mergeStyleRange(new StyleRange(boldSymbol, 1, null, null,
					SWT.BOLD));
		}
		getTextWidget().setBackground(
				getControl().getDisplay().getSystemColor(SWT.COLOR_GRAY));
		changeTextPresentation(style, true);
	}

}

Back to the top