Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6ba7cb17e4a4de0c62296416e0e67488bec6b67b (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
 * Copyright (c) 2002, 2015 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.views;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.internal.cheatsheets.CheatSheetStopWatch;

public abstract class Page {
	protected final static int HORZ_SCROLL_INCREMENT = 20;

	protected final static int VERT_SCROLL_INCREMENT = 20;

	// Colors
	protected Color backgroundColor;

	protected FormToolkit toolkit;

	protected ScrolledForm form;

	public Page() {
	}

	public Control getControl() {
		return form;
	}

	public void createPart(Composite parent) {
		init(parent.getDisplay());
		CheatSheetStopWatch.startStopWatch("Page.createInfoArea()"); //$NON-NLS-1$
		CheatSheetStopWatch
				.printLapTime(
						"Page.createInfoArea()", "Time in Page.createInfoArea() after new FormToolkit(): "); //$NON-NLS-1$ //$NON-NLS-2$
		form = toolkit.createScrolledForm(parent);
		form.setData("novarrows", Boolean.TRUE); //$NON-NLS-1$
		form.setText(ViewUtilities.escapeForLabel(getTitle()));
		form.setDelayedReflow(true);
		CheatSheetStopWatch
				.printLapTime(
						"Page.createInfoArea()", "Time in Page.createInfoArea() after createScrolledForm(): "); //$NON-NLS-1$ //$NON-NLS-2$
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.widthHint = 10;
		form.setLayoutData(gd);
		CheatSheetStopWatch
				.printLapTime(
						"Page.createInfoArea()", "Time in Page.createInfoArea() after setLayoutData(): "); //$NON-NLS-1$ //$NON-NLS-2$
		TableWrapLayout layout = new TableWrapLayout();
		CheatSheetStopWatch
				.printLapTime(
						"Page.createInfoArea()", "Time in Page.createInfoArea() after new FormTableWrapLayout(): "); //$NON-NLS-1$ //$NON-NLS-2$
		layout.numColumns = 2;
		// DG - added changes to make the check icon use less space
		// and to compensate for the fix in section layout
		// computation that makes it shorter for 3 pixels.
		layout.leftMargin = 0;
		layout.horizontalSpacing = 0;
		layout.verticalSpacing = 3;
		form.getBody().setLayout(layout);

		CheatSheetStopWatch
				.printLapTime(
						"Page.createInfoArea()", "Time in Page.createInfoArea() end of method: "); //$NON-NLS-1$ //$NON-NLS-2$
	}

	public void dispose() {
		if (form != null) {
			form.dispose();
		}

		if (toolkit != null) {
			toolkit.dispose();
		}
		form = null;
		toolkit = null;
	}

	protected void init(Display display) {
		toolkit = new FormToolkit(display);
		backgroundColor = toolkit.getColors().getBackground();
	}

	protected abstract String getTitle();

	public abstract void initialized();

}

Back to the top