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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.opengl.examples;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class OpenGLExample {
private TabFolder tabFolder;
private OpenGLTab[] tabs;
private int sleep;
/**
* Renders the scene of the current tab.
*/
void display() {
int index = tabFolder.getSelectionIndex();
tabs[index].render();
tabs[index].swap();
}
/**
* Disposes of all contained tabs.
*/
void dispose() {
tabFolder = null;
for (int i = 0; i < tabs.length; i++) {
tabs[i].dispose();
}
}
/**
* Runs the OpenGL example
*/
void run() {
final Display display = new Display();
final Shell shell =
new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND);
shell.setLayout(new FillLayout());
tabFolder = new TabFolder(shell, SWT.NONE);
tabs =
new OpenGLTab[] {
new AntialiasingTab(),
new AreaTab(),
new BezierTab(),
new BitmapTextTab(),
new FogTab(),
new GradientTab(),
new LightTab(),
new NurbTab(),
new ObjectsTab(),
// outline tab is windows specific
new OutlineTextTab (),
new ReflectionTab(),
new StencilTab(),
new TextureTab(),
new TransparencyTab()};
for (int i = 0; i < tabs.length; i++) {
TabItem item = new TabItem(tabFolder, SWT.NONE);
item.setText(tabs[i].getTabText());
item.setControl(tabs[i].createTabFolderPage(tabFolder));
}
tabFolder.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
OpenGLTab tab = tabs[tabFolder.getSelectionIndex()];
tab.setCurrent();
sleep = tab.getSleepLength();
}
});
if (tabs.length > 0) {
tabs[0].setCurrent();
sleep = tabs[0].getSleepLength();
}
shell.setText("OpenGL Example");
Runnable timer = new Runnable() {
public void run() {
if (shell.isDisposed()) return;
display();
display.timerExec(sleep, this);
}
};
timer.run();
shell.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event e) {
dispose();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Invokes as a standalone program.
*/
public static void main(String[] args) {
new OpenGLExample().run();
}
}
|