root / src / org.omnetpp.ide.nativelibs / jprogressmonitor.cc @ 79bb12dc
History | View | Annotate | Download (2.36 KB)
1 |
//=========================================================================
|
---|---|
2 |
// JPROGRESSMONITOR.CC - part of
|
3 |
// OMNeT++/OMNEST
|
4 |
// Discrete System Simulation in C++
|
5 |
//
|
6 |
//=========================================================================
|
7 |
|
8 |
/*--------------------------------------------------------------*
|
9 |
Copyright (C) 1992-2005 Andras Varga
|
10 |
|
11 |
This file is distributed WITHOUT ANY WARRANTY. See the file
|
12 |
`license' for details on this and other legal matters.
|
13 |
*--------------------------------------------------------------*/
|
14 |
|
15 |
#include <jni.h> |
16 |
#include "jprogressmonitor.h" |
17 |
|
18 |
JniProgressMonitor::JniProgressMonitor(jobject jProgressMonitor, JNIEnv *env) |
19 |
: jProgressMonitor(jProgressMonitor), env(env) |
20 |
{ |
21 |
jclass clazz = env->FindClass("org/eclipse/core/runtime/IProgressMonitor");
|
22 |
if (clazz) {
|
23 |
this->beginTaskID = env->GetMethodID(clazz, "beginTask", "(Ljava/lang/String;I)V"); |
24 |
this->doneID = env->GetMethodID(clazz, "done", "()V"); |
25 |
this->isCanceledID = env->GetMethodID(clazz, "isCanceled", "()Z"); |
26 |
this->setCanceledID = env->GetMethodID(clazz, "setCanceled", "(Z)V"); |
27 |
this->subTaskID = env->GetMethodID(clazz, "subTask", "(Ljava/lang/String;)V"); |
28 |
this->workedID = env->GetMethodID(clazz, "worked", "(I)V"); |
29 |
} |
30 |
if (!beginTaskID || !doneID || !isCanceledID || ! setCanceledID || !subTaskID || !workedID)
|
31 |
env = NULL;
|
32 |
} |
33 |
|
34 |
JniProgressMonitor::~JniProgressMonitor() |
35 |
{ |
36 |
} |
37 |
|
38 |
void JniProgressMonitor::beginTask(std::string name, int totalWork) |
39 |
{ |
40 |
if (env)
|
41 |
{ |
42 |
jstring jname = env->NewStringUTF(name.c_str()); |
43 |
env->CallVoidMethod(jProgressMonitor, beginTaskID, jname, (jint)totalWork); |
44 |
} |
45 |
} |
46 |
|
47 |
void JniProgressMonitor::done()
|
48 |
{ |
49 |
if (env)
|
50 |
{ |
51 |
env->CallVoidMethod(jProgressMonitor, doneID); |
52 |
} |
53 |
} |
54 |
|
55 |
bool JniProgressMonitor::isCanceled()
|
56 |
{ |
57 |
if (env)
|
58 |
{ |
59 |
return env->CallBooleanMethod(jProgressMonitor, isCanceledID);
|
60 |
} |
61 |
return false; |
62 |
} |
63 |
|
64 |
void JniProgressMonitor::setCanceled(bool value) |
65 |
{ |
66 |
if (env)
|
67 |
{ |
68 |
env->CallVoidMethod(jProgressMonitor, setCanceledID, (jboolean)value); |
69 |
} |
70 |
} |
71 |
|
72 |
void JniProgressMonitor::subTask(std::string name) |
73 |
{ |
74 |
if (env)
|
75 |
{ |
76 |
jstring jname = env->NewStringUTF(name.c_str()); |
77 |
env->CallVoidMethod(jProgressMonitor, subTaskID, jname); |
78 |
} |
79 |
} |
80 |
|
81 |
void JniProgressMonitor::worked(int work) |
82 |
{ |
83 |
if (env)
|
84 |
{ |
85 |
env->CallVoidMethod(jProgressMonitor, workedID, (jint)work); |
86 |
} |
87 |
} |
88 |
|