if (exception[0] != null) { SWT.error (SWT.ERROR_NOT_IMPLEMENTED, exception[0]);
initializeSwing (); Object value = null; try { value = constructor.newInstance (new Object [] {new Integer (handle)}); } catch (Throwable e) { SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e);
public static Frame new_Frame (final Composite parent) {	if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	if ((parent.getStyle () & SWT.EMBEDDED) == 0) {		SWT.error (SWT.ERROR_INVALID_ARGUMENT);	}	final int handle = parent.handle;		final Frame[] result = new Frame[1];	final Throwable[] exception = new Throwable[1];	Runnable runnable = new Runnable () {		public void run () {			try {				/*				 * Some JREs have implemented the embedded frame constructor to take an integer				 * and other JREs take a long.  To handle this binary incompatability, use				 * reflection to create the embedded frame.				 */				Class clazz = null;				try {					String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.windows.WEmbeddedFrame";					clazz = Class.forName(className);				} catch (Throwable e) {					exception[0] = e;					return;				}				Constructor constructor = null;				try {					constructor = clazz.getConstructor (new Class [] {int.class});				} catch (Throwable e1) {					try {						constructor = clazz.getConstructor (new Class [] {long.class});					} catch (Throwable e2) {						exception[0] = e2;						return;					}				}				initializeSwing ();				Object value = null;				try {					value = constructor.newInstance (new Object [] {new Integer (handle)});				} catch (Throwable e) {					exception[0] = e;					return;				}				final Frame frame = (Frame) value;				/*				 * This is necessary to make lightweight components				 * directly added to the frame receive mouse events				 * properly.				 */				frame.addNotify();				result[0] = frame;			} finally {				synchronized(result) {					result.notify();				}			}		}	};	if (EventQueue.isDispatchThread()) {		runnable.run();	} else {		EventQueue.invokeLater(runnable);		boolean interrupted = false;		MSG msg = new MSG ();		int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_SENDMESSAGE;		while (result[0] == null && exception[0] == null) {			OS.PeekMessage (msg, 0, 0, 0, flags);			try {				synchronized (result) {					result.wait(50);				}			} catch (InterruptedException e) {				interrupted = true;			}		}		if (interrupted) {			Compatibility.interrupt();		}	}	if (exception[0] != null) {		SWT.error (SWT.ERROR_NOT_IMPLEMENTED, exception[0]);		}	final Frame frame = result[0];		parent.setData(EMBEDDED_FRAME_KEY, frame);			/* Forward the iconify and deiconify events */	final Listener shellListener = new Listener () {		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 () {							frame.dispose ();						}					});					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 {								frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));								frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_GAINED_FOCUS));							}						}					});					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 {								frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_LOST_FOCUS));								frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEACTIVATED));							}						}					});					break;			}		}	};	parent.addListener (SWT.Activate, listener);	parent.addListener (SWT.Deactivate, listener);	parent.addListener (SWT.Dispose, listener);		parent.getDisplay().asyncExec(new Runnable() {		public void run () {			if (parent.isDisposed()) return;			final Rectangle clientArea = parent.getClientArea();			EventQueue.invokeLater(new Runnable () {				public void run () {					frame.setSize (clientArea.width, clientArea.height);					frame.validate ();				}			});		}	});	/*	* TEMPORARY CODE	* 	* For some reason, the graphics configuration of the embedded	* frame is not initialized properly. This causes an exception	* when the depth of the screen is changed.	*/	EventQueue.invokeLater(new Runnable () {		public void run () {			try {				Class clazz = Class.forName("sun.awt.windows.WComponentPeer");				Field field = clazz.getDeclaredField("winGraphicsConfig");				field.setAccessible(true);				field.set(frame.getPeer(), frame.getGraphicsConfiguration());			} catch (Throwable e) {}		}	});	return frame;}