KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > parts > FormBrowser


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.parts;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.DisposeEvent;
16 import org.eclipse.swt.events.DisposeListener;
17 import org.eclipse.swt.layout.FillLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.ui.forms.widgets.FormText;
21 import org.eclipse.ui.forms.widgets.FormToolkit;
22 import org.eclipse.ui.forms.widgets.ScrolledFormText;
23
24 public class FormBrowser {
25     FormToolkit toolkit;
26     Composite container;
27     ScrolledFormText formText;
28     String JavaDoc text;
29     int style;
30     
31     public FormBrowser(int style) {
32         this.style = style;
33     }
34
35     public void createControl(Composite parent) {
36         toolkit = new FormToolkit(parent.getDisplay());
37         int borderStyle = toolkit.getBorderStyle()==SWT.BORDER?SWT.NULL:SWT.BORDER;
38         container = new Composite(parent, borderStyle);
39         FillLayout flayout = new FillLayout();
40         flayout.marginWidth = 1;
41         flayout.marginHeight = 1;
42         container.setLayout(flayout);
43         formText = new ScrolledFormText(container, SWT.V_SCROLL | SWT.H_SCROLL, false);
44         if (borderStyle==SWT.NULL) {
45             formText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
46             toolkit.paintBordersFor(container);
47         }
48         FormText ftext = toolkit.createFormText(formText, false);
49         formText.setFormText(ftext);
50         formText.setExpandHorizontal(true);
51         formText.setExpandVertical(true);
52         formText.setBackground(toolkit.getColors().getBackground());
53         formText.setForeground(toolkit.getColors().getForeground());
54         ftext.marginWidth =2;
55         ftext.marginHeight =2;
56         ftext.setHyperlinkSettings(toolkit.getHyperlinkGroup());
57         formText.addDisposeListener(new DisposeListener() {
58             public void widgetDisposed(DisposeEvent e) {
59                 if (toolkit!=null) {
60                     toolkit.dispose();
61                     toolkit = null;
62                 }
63             }
64         });
65         if (text!=null)
66             formText.setText(text);
67     }
68
69     public Control getControl() {
70         return container;
71     }
72     
73     public void setText(String JavaDoc text) {
74         this.text = text;
75         if (formText!=null) formText.setText(text);
76     }
77 }
78
Popular Tags