Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Common/vtkJavaAwt.h

Go to the documentation of this file.
00001 // only do this when JAWT is to be used
00002 #include "jawt_md.h"
00003 
00004 extern "C" JNIEXPORT void  JNICALL 
00005     Java_vtkPanel_RenderCreate(JNIEnv *env, jobject canvas, jobject id0)
00006 {
00007   JAWT awt;
00008   JAWT_DrawingSurface* ds;
00009   JAWT_DrawingSurfaceInfo* dsi;
00010   jint lock;
00011 
00012   // get the render window pointer
00013   vtkRenderWindow *temp0;
00014   temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,id0,(char *) "vtkRenderWindow"));
00015   
00016   /* Get the AWT */
00017   awt.version = JAWT_VERSION_1_3;
00018   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) 
00019     {
00020     printf("AWT Not found\n");
00021     return;
00022     }
00023   
00024   /* Get the drawing surface */
00025   ds = awt.GetDrawingSurface(env, canvas);
00026   if (ds == NULL) 
00027     {
00028     printf("NULL drawing surface\n");
00029     return;
00030     }
00031   
00032   /* Lock the drawing surface */
00033   lock = ds->Lock(ds);
00034   if((lock & JAWT_LOCK_ERROR) != 0) 
00035     {
00036     printf("Error locking surface\n");
00037     awt.FreeDrawingSurface(ds);
00038     return;
00039     }
00040 
00041   /* Get the drawing surface info */
00042   dsi = ds->GetDrawingSurfaceInfo(ds);
00043   if (dsi == NULL) 
00044     {
00045     printf("Error getting surface info\n");
00046     ds->Unlock(ds);
00047     awt.FreeDrawingSurface(ds);
00048     return;
00049     }
00050   
00051 // Here is the win32 drawing code
00052 #if defined(_WIN32) || defined(WIN32)
00053   JAWT_Win32DrawingSurfaceInfo* dsi_win;
00054   dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
00055   temp0->SetWindowId((void *)dsi_win->hwnd);
00056   
00057 // otherwise use X11 code
00058 #else
00059   JAWT_X11DrawingSurfaceInfo* dsi_x11;
00060   dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
00061   temp0->SetDisplayId((void *)dsi_x11->display);
00062   temp0->SetWindowId((void *)dsi_x11->drawable);
00063 #endif
00064 
00065   temp0->Render();
00066   
00067   /* Free the drawing surface info */
00068   ds->FreeDrawingSurfaceInfo(dsi);
00069   
00070   /* Unlock the drawing surface */
00071   ds->Unlock(ds);
00072   
00073   /* Free the drawing surface */
00074   awt.FreeDrawingSurface(ds);
00075 }
00076 
00077 extern "C" JNIEXPORT void  JNICALL 
00078     Java_vtkPanel_RenderInternal(JNIEnv *env, jobject canvas, jobject id0)
00079 {
00080   JAWT awt;
00081   JAWT_DrawingSurface* ds;
00082   jint lock;
00083 
00084   // get the render window pointer
00085   vtkRenderWindow *temp0;
00086   temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,id0,(char *) "vtkRenderWindow"));
00087   
00088   /* Get the AWT */
00089   awt.version = JAWT_VERSION_1_3;
00090   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) 
00091     {
00092     printf("AWT Not found\n");
00093     return;
00094     }
00095   
00096   /* Get the drawing surface */
00097   ds = awt.GetDrawingSurface(env, canvas);
00098   if (ds == NULL) 
00099     {
00100     printf("NULL drawing surface\n");
00101     return;
00102     }
00103   
00104   /* Lock the drawing surface */
00105   lock = ds->Lock(ds);
00106   if((lock & JAWT_LOCK_ERROR) != 0) 
00107     {
00108     printf("Error locking surface\n");
00109     awt.FreeDrawingSurface(ds);
00110     return;
00111     }
00112 
00113   temp0->Render();
00114   
00115   /* Unlock the drawing surface */
00116   ds->Unlock(ds);
00117   
00118   /* Free the drawing surface */
00119   awt.FreeDrawingSurface(ds);
00120 }
00121 
00122 extern "C" JNIEXPORT void  JNICALL 
00123     Java_vtkPanel_SetSizeInternal(JNIEnv *env, 
00124                                   jobject canvas,
00125                                   jobject id0, jint id1,jint id2)
00126 {
00127   JAWT awt;
00128   JAWT_DrawingSurface* ds;
00129   jint lock;
00130 
00131   // get the render window pointer
00132   vtkRenderWindow *temp0;
00133   temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,id0,(char *) "vtkRenderWindow"));
00134   
00135   /* Get the AWT */
00136   awt.version = JAWT_VERSION_1_3;
00137   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) 
00138       {
00139           printf("AWT Not found\n");
00140           return;
00141       }
00142   
00143   /* Get the drawing surface */
00144   ds = awt.GetDrawingSurface(env, canvas);
00145   if (ds == NULL) 
00146       {
00147           printf("NULL drawing surface\n");
00148           return;
00149       }
00150   
00151   /* Lock the drawing surface */
00152   lock = ds->Lock(ds);
00153   if((lock & JAWT_LOCK_ERROR) != 0) 
00154     {
00155     printf("Error locking surface\n");
00156     awt.FreeDrawingSurface(ds);
00157     return;
00158     }
00159 
00160   int      temp1;
00161   int      temp2;
00162   temp1 = id1;
00163   temp2 = id2;
00164 
00165   temp0->SetSize(temp1,temp2);
00166   
00167   /* Unlock the drawing surface */
00168   ds->Unlock(ds);
00169   
00170   /* Free the drawing surface */
00171   awt.FreeDrawingSurface(ds);
00172 }
00173 
00174 
00175 // This function is provided to lock the render window and execute the
00176 // method represented by methodString of the object represented by anObject.
00177 // This is necessary to wrap any vtk filter which might call Render in
00178 // its Execute method (for example vtkRenderLargeImage).  The method passed
00179 // in must be void and zero-argument (this could be extended later to handle
00180 // more generic methods).
00181 extern "C" JNIEXPORT void  JNICALL 
00182     Java_vtkPanel_LockAndExecuteVoidMethod(JNIEnv *env, 
00183                                            jobject canvas,
00184                                            jobject renderWindow, 
00185                                            jobject anObject,
00186                                            jstring methodString)
00187 {
00188   JAWT awt;
00189   JAWT_DrawingSurface* ds;
00190   jint lock;
00191 
00192   jclass clazz;
00193   jmethodID mid;
00194   jboolean isCopy;
00195 
00196   // get the render window pointer
00197   vtkRenderWindow *temp0;
00198   temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,renderWindow,(char *) "vtkRenderWindow"));
00199 
00200 
00201   // convert jstring to const char*
00202   const char* utf_string = env->GetStringUTFChars(methodString, &isCopy);
00203 
00204   /* Get the AWT */
00205   awt.version = JAWT_VERSION_1_3;
00206   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) 
00207       {
00208           printf("AWT Not found\n");
00209           return;
00210       }
00211   
00212   /* Get the drawing surface */
00213   ds = awt.GetDrawingSurface(env, canvas);
00214   if (ds == NULL) 
00215       {
00216           printf("NULL drawing surface\n");
00217           return;
00218       }
00219   
00220   /* Lock the drawing surface */
00221   lock = ds->Lock(ds);
00222   if((lock & JAWT_LOCK_ERROR) != 0) 
00223     {
00224     printf("Error locking surface\n");
00225     awt.FreeDrawingSurface(ds);
00226     return;
00227     }
00228 
00229   // get object class containing method
00230   clazz = env->GetObjectClass(anObject);
00231 
00232   // get void method id 
00233   mid = env->GetMethodID(clazz, utf_string, "()V");
00234   if (mid == 0)
00235     {
00236       printf("Can't get void methodID %s for object\n", utf_string);
00237       ds->Unlock(ds);
00238       awt.FreeDrawingSurface(ds);
00239       return;
00240     }
00241 
00242   env->CallVoidMethod(anObject, mid);
00243 
00244   temp0->Render();
00245   
00246   /* Unlock the drawing surface */
00247   ds->Unlock(ds);
00248   
00249   /* Free the drawing surface */
00250   awt.FreeDrawingSurface(ds);
00251 }
00252 
00253 

Generated on Thu Mar 28 14:19:15 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001