public void handleEvent (Event e) {
switch (e.type) {
case SWT.Deiconify:
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEICONIFIED));
}
});
break;
case SWT.Iconify:
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ICONIFIED));
}
});
break;
}
}
};
Shell shell = parent.getShell ();
shell.addListener (SWT.Deiconify, shellListener);
shell.addListener (SWT.Iconify, shellListener);
/*
* Generate the appropriate events to activate and deactivate
* the embedded frame. This is needed in order to make keyboard
* focus work properly for lightweights.
*/
Listener listener = new Listener () {
public void handleEvent (Event e) {
switch (e.type) {
case SWT.Dispose:
Shell shell = parent.getShell ();
shell.removeListener (SWT.Deiconify, shellListener);
shell.removeListener (SWT.Iconify, shellListener);
parent.setVisible(false);
EventQueue.invokeLater(new Runnable () {
public void run () {
try {
frame.dispose ();
} catch (Throwable e) {}
}
});
break;
case SWT.Activate:
EventQueue.invokeLater(new Runnable () {
public void run () {
if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_GAINED));
} else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
frame.dispatchEvent (new WindowEvent (frame, 207 /*WindowEvent.WINDOW_GAINED_FOCUS*/));
} else {
try {
/* Initialize the default focus traversal policy */
Class clazz = frame.getClass();
Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});
if (method != null) method.invoke(frame, new Object[]{new Boolean(true)});
} catch (Throwable e) {}
}
}
});
break;
case SWT.Deactivate:
EventQueue.invokeLater(new Runnable () {
public void run () {
if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0)) {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_LOST));
} else if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 5, 0)) {
frame.dispatchEvent (new WindowEvent (frame, 208 /*WindowEvent.WINDOW_LOST_FOCUS*/));
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));
} else {
try {
/* Initialize the default focus traversal policy */
Class clazz = frame.getClass();
Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class});