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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import gl4java.swing.*;
import gl4java.*;
public class InternalGLFrameDemo1 extends JFrame {
JDesktopPane desktop = null;
public InternalGLFrameDemo1() {
super("InternalGLFrameDemo1");
//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width/2 - inset*2,
screenSize.height/2*3-inset*2);
//Quit this app when the big window closes.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(); //Create first window
setContentPane(desktop);
setJMenuBar(createMenuBar());
//Make dragging faster:
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
}
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createFrame();
}
});
menu.add(menuItem);
menuBar.add(menu);
return menuBar;
}
protected void createFrame() {
InternalGLFrame frame = new InternalGLFrame("CrossColorJPanel");
frame.setVisible(true); //necessary as of kestrel
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
public static void main(String[] args) {
GLContext.gljNativeDebug = true;
GLContext.gljClassDebug = true;
InternalGLFrameDemo1 frame = new InternalGLFrameDemo1();
frame.setVisible(true);
}
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
static InternalGLFrame activeIF = null;
public class InternalGLFrame extends JInternalFrame
implements ItemListener, InternalFrameListener
{
String[] data = {"CrossColorJPanel",
"GearsJPanel",
"DrawColoredPrimitivesJPanel",
"TessJPanel"};
String[] dataSize = {"offscreen-size: component",
"offscreen-size: 10x10",
"offscreen-size: 50x50",
"offscreen-size: 100x100",
"offscreen-size: 500x500",
"offscreen-size: 1000x1000"};
Dimension[] dimSize = { null,
new Dimension(10,10),
new Dimension(50,50),
new Dimension(100,100),
new Dimension(500,500),
new Dimension(1000,1000)};
GLJPanel canvas = null;
JComboBox glChoice = null;
JComboBox glOffScrnSize = null;
JComponent master = null;
public InternalGLFrame(String clazzName)
{
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the window...
master = (JComponent) getContentPane();
master.setLayout(new BorderLayout());
switchGLJPanel(clazzName);
JPanel np = new JPanel();
master.add("North", np);
glChoice = new JComboBox(data);
glChoice.addItemListener(this);
np.add(glChoice);
glOffScrnSize = new JComboBox(dataSize);
glOffScrnSize.addItemListener(this);
np.add(glOffScrnSize);
setJMenuBar(createIFMenuBar());
//...Then set the window size or call pack...
setSize(300,300);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
addInternalFrameListener(this);
}
public void switchGLJPanel(String clazzName)
{
try {
Object obj =
Class.forName(clazzName).newInstance();
if(obj instanceof GLJPanel)
{
if(canvas!=null)
{
master.remove(canvas);
canvas.cvsDispose();
}
canvas = (GLJPanel)obj;
canvas.setVisible(true);
master.add("Center", canvas);
master.invalidate();
master.validate();
master.repaint();
glOffScrnSize.setSelectedIndex(0);
}
if(obj instanceof GLAnimJPanel)
{
((GLAnimJPanel)obj).start();
}
} catch (Exception ex) {
System.out.println("Exception during loading: "+
clazzName);
System.out.println(ex);
}
}
protected JMenuBar createIFMenuBar()
{
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createIFFrame();
}
});
menu.add(menuItem);
menuBar.add(menu);
return menuBar;
}
protected void createIFFrame() {
if(activeIF==null)
return;
InternalGLFrame frame = new InternalGLFrame("CrossColorJPanel");
frame.setVisible(true); //necessary as of kestrel
activeIF.canvas.add(frame);
try {
activeIF.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
public void itemStateChanged(ItemEvent e)
{
Object source = e.getItemSelectable();
Object item = e.getItem();
System.out.println("item changed: "+source);
if(glChoice!=null &&
glChoice.equals(e.getItemSelectable()) &&
e.getStateChange()==ItemEvent.SELECTED &&
(item instanceof String)==true
)
{
switchGLJPanel((String)item);
} else
if(glOffScrnSize!=null && canvas!=null &&
glOffScrnSize.equals(e.getItemSelectable()) &&
e.getStateChange()==ItemEvent.SELECTED &&
(item instanceof String)==true
)
{
int idx = glOffScrnSize.getSelectedIndex();
canvas.setOffScreenSize(dimSize[idx]);
}
}
public void internalFrameClosing(InternalFrameEvent e) {
}
public void internalFrameClosed(InternalFrameEvent e) {
}
public void internalFrameOpened(InternalFrameEvent e) {
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
public void internalFrameActivated(InternalFrameEvent e) {
activeIF = (InternalGLFrame)e.getSource();
}
public void internalFrameDeactivated(InternalFrameEvent e) {
}
}
}
|