01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.parts;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.events.DisposeEvent;
14: import org.eclipse.swt.events.DisposeListener;
15: import org.eclipse.swt.layout.FillLayout;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.swt.widgets.Control;
18: import org.eclipse.ui.forms.widgets.FormText;
19: import org.eclipse.ui.forms.widgets.FormToolkit;
20: import org.eclipse.ui.forms.widgets.ScrolledFormText;
21:
22: public class FormBrowser {
23: FormToolkit toolkit;
24: Composite container;
25: ScrolledFormText formText;
26: String text;
27: int style;
28:
29: public FormBrowser(int style) {
30: this .style = style;
31: }
32:
33: public void createControl(Composite parent) {
34: toolkit = new FormToolkit(parent.getDisplay());
35: int borderStyle = toolkit.getBorderStyle() == SWT.BORDER ? SWT.NULL
36: : SWT.BORDER;
37: container = new Composite(parent, borderStyle);
38: FillLayout flayout = new FillLayout();
39: flayout.marginWidth = 1;
40: flayout.marginHeight = 1;
41: container.setLayout(flayout);
42: formText = new ScrolledFormText(container, SWT.V_SCROLL
43: | SWT.H_SCROLL, false);
44: if (borderStyle == SWT.NULL) {
45: formText.setData(FormToolkit.KEY_DRAW_BORDER,
46: FormToolkit.TREE_BORDER);
47: toolkit.paintBordersFor(container);
48: }
49: FormText ftext = toolkit.createFormText(formText, false);
50: formText.setFormText(ftext);
51: formText.setExpandHorizontal(true);
52: formText.setExpandVertical(true);
53: formText.setBackground(toolkit.getColors().getBackground());
54: formText.setForeground(toolkit.getColors().getForeground());
55: ftext.marginWidth = 2;
56: ftext.marginHeight = 2;
57: ftext.setHyperlinkSettings(toolkit.getHyperlinkGroup());
58: formText.addDisposeListener(new DisposeListener() {
59: public void widgetDisposed(DisposeEvent e) {
60: if (toolkit != null) {
61: toolkit.dispose();
62: toolkit = null;
63: }
64: }
65: });
66: if (text != null)
67: formText.setText(text);
68: }
69:
70: public Control getControl() {
71: return container;
72: }
73:
74: public void setText(String text) {
75: this.text = text;
76: if (formText != null)
77: formText.setText(text);
78: }
79: }
|