KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > views > Page


1 /*******************************************************************************
2  * Copyright (c) 2002, 2007 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 package org.eclipse.ui.internal.cheatsheets.views;
12
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Display;
18 import org.eclipse.ui.forms.widgets.FormToolkit;
19 import org.eclipse.ui.forms.widgets.ScrolledForm;
20 import org.eclipse.ui.forms.widgets.TableWrapLayout;
21 import org.eclipse.ui.internal.cheatsheets.CheatSheetStopWatch;
22
23 public abstract class Page {
24     protected final static int HORZ_SCROLL_INCREMENT = 20;
25
26     protected final static int VERT_SCROLL_INCREMENT = 20;
27
28     // Colors
29
protected Color backgroundColor;
30
31     protected FormToolkit toolkit;
32
33     protected ScrolledForm form;
34
35     public Page() {
36     }
37
38     public Control getControl() {
39         return form;
40     }
41
42     public void createPart(Composite parent) {
43         init(parent.getDisplay());
44         CheatSheetStopWatch.startStopWatch("Page.createInfoArea()"); //$NON-NLS-1$
45
CheatSheetStopWatch
46                 .printLapTime(
47                         "Page.createInfoArea()", "Time in Page.createInfoArea() after new FormToolkit(): "); //$NON-NLS-1$ //$NON-NLS-2$
48
form = toolkit.createScrolledForm(parent);
49         form.setData("novarrows", Boolean.TRUE); //$NON-NLS-1$
50
form.setText(ViewUtilities.escapeForLabel(getTitle()));
51         form.setDelayedReflow(true);
52         CheatSheetStopWatch
53                 .printLapTime(
54                         "Page.createInfoArea()", "Time in Page.createInfoArea() after createScrolledForm(): "); //$NON-NLS-1$ //$NON-NLS-2$
55
GridData gd = new GridData(GridData.FILL_BOTH);
56         gd.widthHint = 10;
57         form.setLayoutData(gd);
58         CheatSheetStopWatch
59                 .printLapTime(
60                         "Page.createInfoArea()", "Time in Page.createInfoArea() after setLayoutData(): "); //$NON-NLS-1$ //$NON-NLS-2$
61
TableWrapLayout layout = new TableWrapLayout();
62         CheatSheetStopWatch
63                 .printLapTime(
64                         "Page.createInfoArea()", "Time in Page.createInfoArea() after new FormTableWrapLayout(): "); //$NON-NLS-1$ //$NON-NLS-2$
65
layout.numColumns = 2;
66         // DG - added changes to make the check icon use less space
67
// and to compensate for the fix in section layout
68
// computation that makes it shorter for 3 pixels.
69
layout.leftMargin = 0;
70         layout.horizontalSpacing = 0;
71         layout.verticalSpacing = 3;
72         form.getBody().setLayout(layout);
73
74         CheatSheetStopWatch
75                 .printLapTime(
76                         "Page.createInfoArea()", "Time in Page.createInfoArea() end of method: "); //$NON-NLS-1$ //$NON-NLS-2$
77
}
78
79     public void dispose() {
80         if (form != null) {
81             form.dispose();
82         }
83
84         if (toolkit != null) {
85             toolkit.dispose();
86         }
87         form = null;
88         toolkit = null;
89     }
90
91     protected void init(Display display) {
92         toolkit = new FormToolkit(display);
93         backgroundColor = toolkit.getColors().getBackground();
94     }
95
96     protected abstract String JavaDoc getTitle();
97
98     public abstract void initialized();
99     
100 }
101
Popular Tags