Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2016-08-05 10:28:45 +0000
committerLakshmi Shanmugam2016-08-09 12:08:11 +0000
commit2214fda883b89bb4f8ad39483d2e3f9ae1a89294 (patch)
treebdb51eef6ad8a7229b63da07e6cc1783dc8edce6 /bundles/org.eclipse.swt/Eclipse SWT AWT
parent210d28c8c907f291b17bbdbea06eac3d62e6eeab (diff)
downloadeclipse.platform.swt-2214fda883b89bb4f8ad39483d2e3f9ae1a89294.tar.gz
eclipse.platform.swt-2214fda883b89bb4f8ad39483d2e3f9ae1a89294.tar.xz
eclipse.platform.swt-2214fda883b89bb4f8ad39483d2e3f9ae1a89294.zip
Bug 482318 - [Java9] Illegal Access Exception with SWT_AWT on
JDK9+Jigsaw Moved the methods inaccessible in Java 9 to native code. They'll be called using reflection.
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT AWT')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java88
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/library/swt_awt.c53
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java69
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/win32/library/swt_awt.c29
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java52
6 files changed, 196 insertions, 135 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
index 29a9899008..faf5420143 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -60,3 +60,41 @@ JNIEXPORT jintLong JNICALL SWT_AWT_NATIVE(getAWTHandle)
return result;
}
#endif
+
+#ifndef NO_initFrame
+JNIEXPORT jobject JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_initFrame
+ (JNIEnv *env, jclass that, jintLong handle, const char *className)
+{
+ jobject object;
+ jmethodID constructor;
+
+ jclass cls = (*env)->FindClass(env, "sun/lwawt/macosx/CViewEmbeddedFrame");
+ if (NULL == cls) return NULL;
+ constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
+ object = (*env)->NewObject(env, cls, constructor, handle);
+ return object;
+}
+#endif
+
+#ifndef NO_validateWithBounds
+JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_validateWithBounds
+(JNIEnv *env, jclass that, jobject frame, jint x,jint y,jint w,jint h)
+{
+ jclass cls = (*env)->FindClass(env, "sun/lwawt/macosx/CViewEmbeddedFrame");
+ if (NULL == cls) return;
+ jmethodID midInit = (*env)->GetMethodID(env, cls, "validateWithBounds", "(IIII)V");
+ (*env)->CallVoidMethod(env, frame, midInit, x,y,w,h);
+}
+#endif
+
+#ifndef NO_synthesizeWindowActivation
+JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_synthesizeWindowActivation
+(JNIEnv *env, jclass that, jobject frame, jboolean doActivate)
+{
+ jclass cls = (*env)->FindClass(env, "sun/lwawt/macosx/CViewEmbeddedFrame");
+ if (NULL == cls) return;
+ jmethodID midInit = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
+ (*env)->CallVoidMethod(env, frame, midInit, doActivate);
+}
+#endif
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
index ae3257927f..7a75d107ba 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
@@ -51,16 +51,14 @@ public class SWT_AWT {
*/
static final String RUN_AWT_INVOKE_LATER_KEY = "org.eclipse.swt.internal.runAWTInvokeLater"; //$NON-NLS-1$
- static {
- System.setProperty("apple.awt.usingSWT", "true");
- }
-
- static final String JDK16_FRAME = "apple.awt.CEmbeddedFrame";
static final String JDK17_FRAME = "sun.lwawt.macosx.CViewEmbeddedFrame";
static boolean loaded, swingInitialized;
static native final long /*int*/ getAWTHandle (Canvas canvas);
+ static native final Object initFrame (long /*int*/ handle, String className);
+ static native final void validateWithBounds (Frame frame, int x, int y, int w, int h);
+ static native final void synthesizeWindowActivation (Frame frame, boolean doActivate);
static synchronized void loadLibrary () {
if (loaded) return;
@@ -136,23 +134,15 @@ public static Frame new_Frame(final Composite parent) {
if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
-
final long /*int*/ handle = parent.view.id;
-
- final Class<?> [] clazz = new Class [1];
+ final String className = embeddedFrameClass != null ? embeddedFrameClass : JDK17_FRAME;
try {
- String className = embeddedFrameClass != null ? embeddedFrameClass : JDK16_FRAME;
- if (embeddedFrameClass == null) {
- clazz[0] = Class.forName(className, true, ClassLoader.getSystemClassLoader());
- } else {
- clazz[0] = Class.forName(className);
+ if (embeddedFrameClass != null) {
+ Class.forName(className);
}
+ loadLibrary();
} catch (ClassNotFoundException cne) {
- try {
- clazz[0] = Class.forName(JDK17_FRAME);
- } catch (ClassNotFoundException cne1) {
- SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne1);
- }
+ SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne);
} catch (Throwable e) {
SWT.error (SWT.ERROR_UNSPECIFIED , e, " [Error while starting AWT]");
}
@@ -168,14 +158,14 @@ public static Frame new_Frame(final Composite parent) {
public void run() {
if (run) return;
run = true;
- Constructor<?> constructor = null;
- try {
- constructor = clazz[0].getConstructor (long.class);
- result [0] = (Frame) (constructor.newInstance (new Long(handle)));
- result [0].addNotify();
- } catch (Throwable e) {
- exception[0] = e;
- }
+ Object obj = initFrame(handle, className);
+ if (obj == null || !(obj instanceof Frame)) {
+ exception [0] = new Throwable("[Error while creating AWT embedded frame]");
+ SWT.error (SWT.ERROR_UNSPECIFIED, exception[0]);
+ return;
+ }
+ result[0] = (Frame) obj;
+ result[0].addNotify();
}
};
if (EventQueue.isDispatchThread() || parent.getDisplay().getSyncThread() != null) {
@@ -196,7 +186,6 @@ public static Frame new_Frame(final Composite parent) {
SWT.error (SWT.ERROR_NOT_IMPLEMENTED, exception[0]);
}
final Frame frame = result[0];
- final boolean isJDK17 = JDK17_FRAME.equals(frame.getClass().getName());
/* NOTE: addNotify() should not be called in the UI thread or we could hang */
//frame.addNotify();
@@ -250,10 +239,8 @@ public static Frame new_Frame(final Composite parent) {
Shell shell = parent.getShell ();
shell.removeListener (SWT.Deiconify, shellListener);
shell.removeListener (SWT.Iconify, shellListener);
- if (isJDK17) {
- shell.removeListener (SWT.Activate, this);
- shell.removeListener (SWT.Deactivate, this);
- }
+ shell.removeListener (SWT.Activate, this);
+ shell.removeListener (SWT.Deactivate, this);
parent.setVisible(false);
EventQueue.invokeLater(() -> {
try {
@@ -267,9 +254,7 @@ public static Frame new_Frame(final Composite parent) {
EventQueue.invokeLater(() -> {
if (frame.isActive()) return;
try {
- Class<?> clazz1 = frame.getClass();
- Method method = clazz1.getMethod("synthesizeWindowActivation", boolean.class);
- if (method != null) method.invoke(frame, Boolean.TRUE);
+ synthesizeWindowActivation (frame, Boolean.TRUE);
} catch (Throwable e1) {e1.printStackTrace();}
});
break;
@@ -278,9 +263,7 @@ public static Frame new_Frame(final Composite parent) {
EventQueue.invokeLater(() -> {
if (!frame.isActive()) return;
try {
- Class<?> clazz1 = frame.getClass();
- Method method = clazz1.getMethod("synthesizeWindowActivation", boolean.class);
- if (method != null) method.invoke(frame, Boolean.FALSE);
+ synthesizeWindowActivation (frame, Boolean.FALSE);
} catch (Throwable e1) {e1.printStackTrace();}
});
break;
@@ -289,35 +272,18 @@ public static Frame new_Frame(final Composite parent) {
};
parent.addListener (SWT.FocusIn, listener);
- if (isJDK17) {
- parent.addListener(SWT.FocusOut, listener);
- //To allow cross-app activation/deactivation
- shell.addListener (SWT.Activate, listener);
- shell.addListener (SWT.Deactivate, listener);
- } else {
- parent.addListener (SWT.Deactivate, listener);
- }
+ parent.addListener(SWT.FocusOut, listener);
+ //To allow cross-app activation/deactivation
+ shell.addListener (SWT.Activate, listener);
+ shell.addListener (SWT.Deactivate, listener);
parent.addListener (SWT.Dispose, listener);
display.asyncExec(() -> {
if (parent.isDisposed()) return;
final Rectangle clientArea = parent.getClientArea();
- if (isJDK17) {
- try {
- Method method = frame.getClass().getMethod("validateWithBounds", int.class, int.class, int.class, int.class);
- if (method != null) method.invoke(frame, Integer.valueOf(clientArea.x), Integer.valueOf(clientArea.y), Integer.valueOf(clientArea.width), Integer.valueOf(clientArea.height));
- } catch (Throwable e) {e.printStackTrace();}
- } else {
- EventQueue.invokeLater(() -> {
- frame.setSize(clientArea.width, clientArea.height);
- frame.validate();
-
- // Bug in Cocoa AWT? For some reason the frame isn't showing up on first draw.
- // Toggling visibility seems to be the only thing that works.
- frame.setVisible(false);
- frame.setVisible(true);
- });
- }
+ try {
+ validateWithBounds(frame, Integer.valueOf(clientArea.x), Integer.valueOf(clientArea.y), Integer.valueOf(clientArea.width), Integer.valueOf(clientArea.height));
+ } catch (Throwable e) {e.printStackTrace();}
});
return frame;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/library/swt_awt.c b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/library/swt_awt.c
index c43fdc56a3..72d5590774 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/library/swt_awt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/library/swt_awt.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -71,3 +71,54 @@ JNIEXPORT void JNICALL SWT_AWT_NATIVE(setDebug)
}
}
#endif
+
+#ifndef NO_initFrame
+JNIEXPORT jobject JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_initFrame
+ (JNIEnv *env, jclass that, jintLong handle)
+{
+ jobject object;
+ jmethodID constructor;
+
+ jclass cls = (*env)->FindClass(env, "sun/awt/X11/XEmbeddedFrame");
+ if (NULL == cls) return NULL;
+ constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
+ object = (*env)->NewObject(env, cls, constructor, handle);
+ return object;
+}
+#endif
+
+#ifndef NO_validateWithBounds
+JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_validateWithBounds
+(JNIEnv *env, jclass that, jobject frame, jint x,jint y,jint w,jint h)
+{
+ jclass cls = (*env)->FindClass(env, "sun/awt/X11/XEmbeddedFrame");
+ if (NULL == cls) return;
+ jmethodID midInit = (*env)->GetMethodID(env, cls, "validateWithBounds", "(IIII)V");
+ (*env)->CallVoidMethod(env, frame, midInit, x,y,w,h);
+}
+#endif
+
+#ifndef NO_synthesizeWindowActivation
+JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_synthesizeWindowActivation
+(JNIEnv *env, jclass that, jobject frame, jboolean doActivate)
+{
+ jclass cls = (*env)->FindClass(env, "sun/awt/X11/XEmbeddedFrame");
+ if (NULL == cls) return;
+ jmethodID midInit = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
+ (*env)->CallVoidMethod(env, frame, midInit, doActivate);
+}
+#endif
+
+#ifndef NO_registerListeners
+JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_registerListeners
+(JNIEnv *env, jclass that, jobject frame)
+{
+ jclass cls = (*env)->FindClass(env, "sun/awt/X11/XEmbeddedFrame");
+ if (NULL == cls) return;
+ jmethodID midInit = (*env)->GetMethodID(env, cls, "registerListeners", "()V");
+ (*env)->CallVoidMethod(env, frame, midInit);
+}
+#endif
+
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java
index abd0347f01..7a949e7de0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java
@@ -54,6 +54,10 @@ static boolean loaded, swingInitialized;
static native final long /*int*/ getAWTHandle (Object canvas);
static native final void setDebug (Frame canvas, boolean debug);
+static native final Object initFrame (long /*int*/ handle, String className);
+static native final void validateWithBounds (Frame frame, int x, int y, int w, int h);
+static native final void synthesizeWindowActivation (Frame frame, boolean doActivate);
+static native final void registerListeners (Frame frame);
static synchronized void loadLibrary () {
if (loaded) return;
@@ -144,46 +148,38 @@ public static Frame new_Frame (final Composite parent) {
* and other JREs take a long. To handle this binary incompatibility, use
* reflection to create the embedded frame.
*/
- Class<?> clazz = null;
+ String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.X11.XEmbeddedFrame";
try {
- String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.X11.XEmbeddedFrame";
- clazz = Class.forName(className);
+ if (embeddedFrameClass != null) {
+ Class.forName(className);
+ }
+ loadLibrary();
+ } catch (ClassNotFoundException cne) {
+ SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne);
} catch (Throwable e) {
- SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e, " [need JDK 1.5 or greater]");
+ SWT.error (SWT.ERROR_UNSPECIFIED , e, " [Error while starting AWT]");
}
initializeSwing ();
- Object value = null;
- Constructor<?> constructor = null;
- try {
- constructor = clazz.getConstructor (int.class, boolean.class);
- value = constructor.newInstance (new Integer ((int)/*64*/handle), Boolean.TRUE);
- } catch (Throwable e1) {
- try {
- constructor = clazz.getConstructor (long.class, boolean.class);
- value = constructor.newInstance (new Long (handle), Boolean.TRUE);
- } catch (Throwable e2) {
- SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e2);
- }
+ final Frame [] frame = new Frame [1];
+ Object object = initFrame(handle, className);
+ if (object == null || !(object instanceof Frame)) {
+ SWT.error (SWT.ERROR_UNSPECIFIED , new Throwable(), " [Error while starting AWT]");
}
- final Frame frame = (Frame) value;
- parent.setData(EMBEDDED_FRAME_KEY, frame);
+ frame[0] = (Frame) object;
+ parent.setData(EMBEDDED_FRAME_KEY, frame[0]);
if (Device.DEBUG) {
- loadLibrary();
- setDebug(frame, true);
+ setDebug(frame[0], true);
}
- try {
- /* Call registerListeners() to make XEmbed focus traversal work */
- Method method = clazz.getMethod("registerListeners");
- if (method != null) method.invoke(value);
- } catch (Throwable e) {}
+ /* Call registerListeners() to make XEmbed focus traversal work */
+ registerListeners(frame[0]);
+
final AWTEventListener awtListener = event -> {
if (event.getID() == WindowEvent.WINDOW_OPENED) {
final Window window = (Window) event.getSource();
- if (window.getParent() == frame) {
+ if (window.getParent() == frame[0]) {
parent.getDisplay().asyncExec(() -> {
if (parent.isDisposed()) return;
Shell shell = parent.getShell();
- loadLibrary();
long /*int*/ awtHandle = getAWTHandle(window);
if (awtHandle == 0) return;
long /*int*/ xWindow;
@@ -197,14 +193,15 @@ public static Frame new_Frame (final Composite parent) {
}
}
};
- frame.getToolkit().addAWTEventListener(awtListener, AWTEvent.WINDOW_EVENT_MASK);
+
+ frame[0].getToolkit().addAWTEventListener(awtListener, AWTEvent.WINDOW_EVENT_MASK);
final Listener shellListener = e -> {
switch (e.type) {
case SWT.Deiconify:
- EventQueue.invokeLater(() -> frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEICONIFIED)));
+ EventQueue.invokeLater(() -> frame[0].dispatchEvent (new WindowEvent (frame[0], WindowEvent.WINDOW_DEICONIFIED)));
break;
case SWT.Iconify:
- EventQueue.invokeLater(() -> frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ICONIFIED)));
+ EventQueue.invokeLater(() -> frame[0].dispatchEvent (new WindowEvent (frame[0], WindowEvent.WINDOW_ICONIFIED)));
break;
}
};
@@ -220,13 +217,13 @@ public static Frame new_Frame (final Composite parent) {
shell1.removeListener (SWT.Iconify, shellListener);
parent.setVisible(false);
EventQueue.invokeLater(() -> {
- frame.getToolkit().removeAWTEventListener(awtListener);
- frame.dispose ();
+ frame[0].getToolkit().removeAWTEventListener(awtListener);
+ frame[0].dispose ();
});
break;
case SWT.Resize:
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
- EventQueue.invokeLater(() -> frame.setSize (clientArea.width, clientArea.height));
+ EventQueue.invokeLater(() -> frame[0].setSize (clientArea.width, clientArea.height));
break;
}
};
@@ -237,11 +234,11 @@ public static Frame new_Frame (final Composite parent) {
if (parent.isDisposed()) return;
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
EventQueue.invokeLater(() -> {
- frame.setSize (clientArea.width, clientArea.height);
- frame.validate ();
+ frame[0].setSize (clientArea.width, clientArea.height);
+ frame[0].validate ();
});
});
- return frame;
+ return frame[0];
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/library/swt_awt.c b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/library/swt_awt.c
index 0df8e82fb7..47b87ba559 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/library/swt_awt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/library/swt_awt.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -43,3 +43,30 @@ JNIEXPORT jintLong JNICALL SWT_AWT_NATIVE(getAWTHandle)
return result;
}
#endif
+
+#ifndef NO_initFrame
+JNIEXPORT jobject JNICALL SWT_AWT_NATIVE(initFrame)
+ (JNIEnv *env, jclass that, jintLong handle, jstring className)
+{
+ jobject object;
+ jmethodID constructor;
+
+ jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
+ if (NULL == cls) return NULL;
+ constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
+ object = (*env)->NewObject(env, cls, constructor, handle);
+ return object;
+}
+#endif
+
+#ifndef NO_synthesizeWindowActivation
+JNIEXPORT void JNICALL SWT_AWT_NATIVE(synthesizeWindowActivation)
+(JNIEnv *env, jclass that, jobject frame, jboolean doActivate)
+{
+ jmethodID midInit;
+ jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
+ if (NULL == cls) return;
+ midInit = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
+ (*env)->CallVoidMethod(env, frame, midInit, doActivate);
+}
+#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java
index bb50999c3c..c626164515 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java
@@ -51,6 +51,8 @@ public class SWT_AWT {
static boolean loaded, swingInitialized;
static native final long /*int*/ getAWTHandle (Canvas canvas);
+static native final Object initFrame (long /*int*/ handle, String className);
+static native final void synthesizeWindowActivation (Frame frame, boolean doActivate);
static synchronized void loadLibrary () {
if (loaded) return;
@@ -136,46 +138,26 @@ public static Frame new_Frame (final Composite parent) {
* and other JREs take a long. To handle this binary incompatibility, use
* reflection to create the embedded frame.
*/
- Class<?> clazz = null;
+ String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.windows.WEmbeddedFrame";
try {
- String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.windows.WEmbeddedFrame";
- clazz = Class.forName(className);
- } catch (Throwable e3) {
- exception[0] = e3;
+ if (embeddedFrameClass != null) {
+ Class.forName(className);
+ }
+ loadLibrary();
+ } catch (ClassNotFoundException cne) {
+ SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne);
+ } catch (Throwable e) {
+ exception[0] = e;
return;
}
initializeSwing ();
- Object value = null;
- Constructor<?> constructor = null;
- try {
- constructor = clazz.getConstructor (int.class);
- value = constructor.newInstance (new Integer ((int)/*64*/handle));
- } catch (Throwable e1) {
- try {
- constructor = clazz.getConstructor (long.class);
- value = constructor.newInstance (new Long (handle));
- } catch (Throwable e2) {
- exception[0] = e2;
- return;
- }
+ Object value = initFrame(handle, className);
+ if (value == null || !(value instanceof Frame)) {
+ exception [0] = new Throwable("[Error while creating AWT embedded frame]");
+ SWT.error (SWT.ERROR_UNSPECIFIED, exception[0]);
+ return;
}
- final Frame frame = (Frame) value;
-
- /*
- * 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.
- */
- try {
- clazz = Class.forName("sun.awt.windows.WComponentPeer");
- Field field = clazz.getDeclaredField("winGraphicsConfig");
- field.setAccessible(true);
- field.set(frame.getPeer(), frame.getGraphicsConfiguration());
- } catch (Throwable e4) {}
-
- result[0] = frame;
+ result[0] = (Frame) value;
} finally {
synchronized(result) {
result.notify();

Back to the top