changeset 3168:9c7c5ecea41a

6960655: GTKFileDialogPeer shouldn't be a singletone Reviewed-by: art, dcherepanov
author anthony
date Mon, 08 Nov 2010 18:02:15 +0300
parents f6f2989e547f
children 65bd45308475
files make/sun/xawt/mapfile-vers src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.h
diffstat 4 files changed, 49 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/xawt/mapfile-vers	Mon Nov 08 17:51:35 2010 +0300
+++ b/make/sun/xawt/mapfile-vers	Mon Nov 08 18:02:15 2010 +0300
@@ -429,6 +429,7 @@
         Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetClassValue;
         Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetPangoFontName;
 
+        Java_sun_awt_X11_GtkFileDialogPeer_initIDs;
         Java_sun_awt_X11_GtkFileDialogPeer_run;
         Java_sun_awt_X11_GtkFileDialogPeer_quit;
 
--- a/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java	Mon Nov 08 17:51:35 2010 +0300
+++ b/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java	Mon Nov 08 18:02:15 2010 +0300
@@ -42,11 +42,19 @@
 
     private FileDialog fd;
 
+    // A pointer to the native GTK FileChooser widget
+    private volatile long widget = 0L;
+
     public GtkFileDialogPeer(FileDialog fd) {
         super((Dialog) fd);
         this.fd = fd;
     }
 
+    private static native void initIDs();
+    static {
+        initIDs();
+    }
+
     private native void run(String title, int mode, String dir, String file,
             FilenameFilter filter, boolean isMultipleMode);
 
--- a/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Mon Nov 08 17:51:35 2010 +0300
+++ b/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Mon Nov 08 18:02:15 2010 +0300
@@ -4,13 +4,29 @@
 #include <string.h>
 #include "gtk2_interface.h"
 #include "sun_awt_X11_GtkFileDialogPeer.h"
+#include "debug_assert.h"
 
 static JavaVM *jvm;
-static GtkWidget *dialog = NULL;
 
 /* To cache some method IDs */
 static jmethodID filenameFilterCallbackMethodID = NULL;
 static jmethodID setFileInternalMethodID = NULL;
+static jfieldID  widgetFieldID = NULL;
+
+JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs
+(JNIEnv *env, jclass cx)
+{
+    filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
+            "filenameFilterCallback", "(Ljava/lang/String;)Z");
+    DASSERT(filenameFilterCallbackMethodID != NULL);
+
+    setFileInternalMethodID = (*env)->GetMethodID(env, cx,
+            "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
+    DASSERT(setFileInternalMethodID != NULL);
+
+    widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J");
+    DASSERT(widgetFieldID != NULL);
+}
 
 static gboolean filenameFilterCallback(const GtkFileFilterInfo * filter_info, gpointer obj)
 {
@@ -20,30 +36,17 @@
 
     env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
-    if (filenameFilterCallbackMethodID == NULL) {
-        cx = (*env)->GetObjectClass(env, (jobject) obj);
-        if (cx == NULL) {
-            JNU_ThrowInternalError(env, "Could not get file filter class");
-            return 0;
-        }
-
-        filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
-                "filenameFilterCallback", "(Ljava/lang/String;)Z");
-        if (filenameFilterCallbackMethodID == NULL) {
-            JNU_ThrowInternalError(env,
-                    "Could not get filenameFilterCallback method id");
-            return 0;
-        }
-    }
-
     filename = (*env)->NewStringUTF(env, filter_info->filename);
 
     return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID,
             filename);
 }
 
-static void quit(gboolean isSignalHandler)
+static void quit(JNIEnv * env, jobject jpeer, gboolean isSignalHandler)
 {
+    GtkWidget * dialog = (GtkWidget*)jlong_to_ptr(
+            (*env)->GetLongField(env, jpeer, widgetFieldID));
+
     if (dialog != NULL)
     {
         // Callbacks from GTK signals are made within the GTK lock
@@ -57,7 +60,8 @@
         fp_gtk_widget_destroy (dialog);
 
         fp_gtk_main_quit ();
-        dialog = NULL;
+
+        (*env)->SetLongField(env, jpeer, widgetFieldID, 0);
 
         if (!isSignalHandler) {
             fp_gdk_threads_leave();
@@ -73,7 +77,7 @@
 JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_quit
 (JNIEnv * env, jobject jpeer)
 {
-    quit(FALSE);
+    quit(env, jpeer, FALSE);
 }
 
 /**
@@ -132,24 +136,8 @@
 
     if (responseId == GTK_RESPONSE_ACCEPT) {
         current_folder = fp_gtk_file_chooser_get_current_folder(
-                GTK_FILE_CHOOSER(dialog));
-        filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-    }
-
-    if (setFileInternalMethodID == NULL) {
-        cx = (*env)->GetObjectClass(env, (jobject) obj);
-        if (cx == NULL) {
-            JNU_ThrowInternalError(env, "Could not get GTK peer class");
-            return;
-        }
-
-        setFileInternalMethodID = (*env)->GetMethodID(env, cx,
-                "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
-        if (setFileInternalMethodID == NULL) {
-            JNU_ThrowInternalError(env,
-                    "Could not get setFileInternalMethodID method id");
-            return;
-        }
+                GTK_FILE_CHOOSER(aDialog));
+        filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog));
     }
 
     jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
@@ -159,7 +147,7 @@
             jfilenames);
     fp_g_free(current_folder);
 
-    quit(TRUE);
+    quit(env, (jobject)obj, TRUE);
 }
 
 /*
@@ -172,6 +160,7 @@
         jstring jtitle, jint mode, jstring jdir, jstring jfile,
         jobject jfilter, jboolean multiple)
 {
+    GtkWidget *dialog = NULL;
     GtkFileFilter *filter;
 
     if (jvm == NULL) {
@@ -233,8 +222,12 @@
 
     fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
             handle_response), jpeer);
+
+    (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog));
+
     fp_gtk_widget_show(dialog);
 
     fp_gtk_main();
     fp_gdk_threads_leave();
 }
+
--- a/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.h	Mon Nov 08 17:51:35 2010 +0300
+++ b/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.h	Mon Nov 08 18:02:15 2010 +0300
@@ -11,6 +11,14 @@
 
 /*
  * Class:     sun_awt_X11_GtkFileDialogPeer
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs
+(JNIEnv *, jclass);
+
+/*
+ * Class:     sun_awt_X11_GtkFileDialogPeer
  * Method:    run
  * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;Z;)V
  */