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 /*=========================================================================
    00002
    00003   Program:   Visualization Toolkit
    00004   Module:    $RCSfile: vtkJavaAwt.h,v $
    00005   Language:  C++
    00006
    00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
    00008   All rights reserved.
    00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
    00010
    00011      This software is distributed WITHOUT ANY WARRANTY; without even
    00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00013      PURPOSE.  See the above copyright notice for more information.
    00014
    00015 =========================================================================*/
    00016 // for use with JAWT
    00017 #include "jawt_md.h"
    00018
    00019 #define VTK_JAVA_DEBUG
    00020
    00021 extern "C" JNIEXPORT jint  JNICALL
    00022 Java_vtk_vtkPanel_RenderCreate(JNIEnv *env, jobject canvas, jobject id0)
    00023 {
    00024   JAWT awt;
    00025   JAWT_DrawingSurface* ds;
    00026   JAWT_DrawingSurfaceInfo* dsi;
    00027   jint lock;
    00028
    00029   // get the render window pointer
    00030   vtkRenderWindow *temp0;
    00031   temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,id0,(char *) "vtkRenderWindow"));
    00032
    00033   /* Get the AWT */
    00034   awt.version = JAWT_VERSION_1_3;
    00035   if (JAWT_GetAWT(env, &awt) == JNI_FALSE)
    00036     {
    00037 #ifndef VTK_JAVA_DEBUG
    00038     printf("AWT Not found\n");
    00039 #endif
    00040     return 1;
    00041     }
    00042
    00043   /* Get the drawing surface */
    00044   ds = awt.GetDrawingSurface(env, canvas);
    00045   if (ds == NULL)
    00046     {
    00047 #ifndef VTK_JAVA_DEBUG
    00048     printf("NULL drawing surface\n");
    00049 #endif
    00050     return 1;
    00051     }
    00052
    00053   /* Lock the drawing surface */
    00054   lock = ds->Lock(ds);
    00055   if((lock & JAWT_LOCK_ERROR) != 0)
    00056     {
    00057 #ifndef VTK_JAVA_DEBUG
    00058     printf("Error locking surface\n");
    00059 #endif
    00060     awt.FreeDrawingSurface(ds);
    00061     return 1;
    00062     }
    00063
    00064   /* Get the drawing surface info */
    00065   dsi = ds->GetDrawingSurfaceInfo(ds);
    00066   if (dsi == NULL)
    00067     {
    00068     printf("Error getting surface info\n");
    00069     ds->Unlock(ds);
    00070     awt.FreeDrawingSurface(ds);
    00071     return 1;
    00072     }
    00073
    00074 // Here is the win32 drawing code
    00075 #if defined(_WIN32) || defined(WIN32)
    00076   JAWT_Win32DrawingSurfaceInfo* dsi_win;
    00077   dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
    00078   temp0->SetWindowId((void *)dsi_win->hwnd);
    00079   temp0->SetDisplayId((void *)dsi_win->hdc);
    00080   // also set parent id to avoid border sizes being added
    00081   temp0->SetParentId((void *)dsi_win->hdc);
    00082 // use mac code
    00083 #elif defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA)
    00084   JAWT_MacDrawingSurfaceInfo* dsi_mac;
    00085   dsi_mac = (JAWT_MacDrawingSurfaceInfo*)dsi->platformInfo;
    00086   temp0->SetWindowId((void *)dsi_mac->fQDWindow);
    00087 // otherwise use X11 code
    00088 #else
    00089   JAWT_X11DrawingSurfaceInfo* dsi_x11;
    00090   dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
    00091   temp0->SetDisplayId((void *)dsi_x11->display);
    00092   temp0->SetWindowId((void *)dsi_x11->drawable);
    00093   temp0->SetParentId((void *)dsi_x11->display);
    00094 #endif
    00095
    00096   /* Free the drawing surface info */
    00097   ds->FreeDrawingSurfaceInfo(dsi);
    00098
    00099   /* Unlock the drawing surface */
    00100   ds->Unlock(ds);
    00101
    00102   /* Free the drawing surface */
    00103   awt.FreeDrawingSurface(ds);
    00104
    00105   return 0;
    00106
    00107 }
    00108
    00109
    00110 // Lock must be called prior to render or anything which might
    00111 // cause vtkRenderWindow to make an XLib call or to call Render().
    00112 // The Lock() and UnLock() functions are necessary for drawing in
    00113 // JAWT, but they also provide a form of mutex locking so that multiple
    00114 // java threads are prevented from accessing X at the same time.  The only
    00115 // requirement JAWT has is that all operations on a JAWT_DrawingSurface
    00116 // MUST be performed from the same thread as the call to GetDrawingSurface.
    00117 extern "C" JNIEXPORT jint  JNICALL
    00118 Java_vtk_vtkPanel_Lock(JNIEnv *env,
    00119                        jobject canvas)
    00120 {
    00121   JAWT awt;
    00122   JAWT_DrawingSurface* ds;
    00123   jint lock;
    00124
    00125   /* Get the AWT */
    00126   awt.version = JAWT_VERSION_1_3;
    00127   if (JAWT_GetAWT(env, &awt) == JNI_FALSE)
    00128     {
    00129 #ifndef VTK_JAVA_DEBUG
    00130     printf("AWT Not found\n");
    00131 #endif
    00132     return 1;
    00133     }
    00134
    00135   /* Get the drawing surface */
    00136   ds = awt.GetDrawingSurface(env, canvas);
    00137   if (ds == NULL)
    00138     {
    00139 #ifndef VTK_JAVA_DEBUG
    00140     printf("NULL drawing surface\n");
    00141 #endif
    00142     return 1;
    00143     }
    00144
    00145   /* Lock the drawing surface */
    00146   lock = ds->Lock(ds);
    00147   if((lock & JAWT_LOCK_ERROR) != 0)
    00148     {
    00149 #ifndef VTK_JAVA_DEBUG
    00150     printf("Error locking surface\n");
    00151 #endif
    00152     awt.FreeDrawingSurface(ds);
    00153     return 1;
    00154     }
    00155
    00156   return 0;
    00157
    00158 }
    00159
    00160 // UnLock() must be called after a Lock() and execution of a
    00161 // function which might change the drawing surface.  See Lock().
    00162 extern "C" JNIEXPORT jint  JNICALL
    00163 Java_vtk_vtkPanel_UnLock(JNIEnv *env,
    00164                          jobject canvas)
    00165 {
    00166   JAWT awt;
    00167   JAWT_DrawingSurface* ds;
    00168
    00169   /* Get the AWT */
    00170   awt.version = JAWT_VERSION_1_3;
    00171   if (JAWT_GetAWT(env, &awt) == JNI_FALSE)
    00172     {
    00173 #ifndef VTK_JAVA_DEBUG
    00174     printf("AWT Not found\n");
    00175 #endif
    00176     return 1;
    00177     }
    00178
    00179   /* Get the drawing surface */
    00180   ds = awt.GetDrawingSurface(env, canvas);
    00181   if (ds == NULL)
    00182     {
    00183 #ifndef VTK_JAVA_DEBUG
    00184     printf("NULL drawing surface\n");
    00185 #endif
    00186     return 1;
    00187     }
    00188
    00189   /* Unlock the drawing surface */
    00190   ds->Unlock(ds);
    00191
    00192   /* Free the drawing surface */
    00193   awt.FreeDrawingSurface(ds);
    00194
    00195   return 0;
    00196 }