|
// ore.cpp: Implementierung der Klasse Core.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "stdafx.h"
#include "ore.h"
#include <assert.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
namespace JBridge
{
jclass ClassCache::jframe = 0;
jclass ClassCache::jembeddedframe;
jmethodID MethodCache::jframe_getContentPane = 0;
jmethodID MethodCache::jframe_constr = 0;
jmethodID MethodCache::jframe_show = 0;
jmethodID MethodCache::jframe_setBounds = 0;
jmethodID MethodCache::jframe_setVisible = 0;
jmethodID MethodCache::jframe_add = 0;
jmethodID MethodCache::jframe_dispose = 0;
AttachCurrentThread::AttachCurrentThread(bool autodetach) : detach(autodetach)
{
jint res = JVMLoader::getInstance()->getJVM()->AttachCurrentThread((void**)&env, NULL);
assert(res >= 0);
}
AttachCurrentThread::~AttachCurrentThread()
{
if (detach)
JVMLoader::getInstance()->getJVM()->DetachCurrentThread();
}
GetStringUTFChars::GetStringUTFChars(jstring str, JNIEnv *e) : jStr(str), env(e)
{
assert(env != NULL);
if (str != NULL)
cStr = env->GetStringUTFChars(jStr, NULL);
else
cStr = NULL;
}
GetStringUTFChars::~GetStringUTFChars()
{
env->ReleaseStringUTFChars(jStr, cStr);
}
JFrame::JFrame(const char *title) : NewObject(true)
{
AttachCurrentThread thread;
object = thread.getJNIEnv()->NewObject(ClassCache::jframe, MethodCache::jframe_constr, thread.getJNIEnv()->NewStringUTF(title));
}
JFrame::JFrame(jobject jframe) : NewObject(false)
{
object = jframe;
}
jobject JFrame::getContentPane()
{
AttachCurrentThread thread;
return thread.getJNIEnv()->CallObjectMethod(object, MethodCache::jframe_getContentPane);
}
void JFrame::show()
{
AttachCurrentThread thread;
thread.getJNIEnv()->CallVoidMethod(object, MethodCache::jframe_show);
}
void JFrame::dispose()
{
AttachCurrentThread thread;
thread.getJNIEnv()->CallVoidMethod(object, MethodCache::jframe_dispose);
}
void JFrame::setBounds(int x, int y, int width, int height)
{
AttachCurrentThread thread;
thread.getJNIEnv()->CallVoidMethod(object, MethodCache::jframe_setBounds, x, y, width, height);
}
void JFrame::setVisible(jboolean visible)
{
AttachCurrentThread thread;
thread.getJNIEnv()->CallVoidMethod(object, MethodCache::jframe_setVisible, visible);
}
jobject JFrame::add(jobject component)
{
AttachCurrentThread thread;
return thread.getJNIEnv()->CallObjectMethod(getContentPane(), MethodCache::jframe_add, component);
}
jobject JFrame::operator*()
{
if (NewObject)
{
AttachCurrentThread thread;
return thread.getJNIEnv()->NewLocalRef(object);
}
else
{
return object;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.