/*--------------------------------------------------------------------------*/
static void setMainWindowState(windowState_enum windowState)
{
    JNIEnv *env = getScilabJNIEnv();
    jobject  ScilabObj = getScilabObject();

    if (env)
    {
        jclass class_Mine = (*env)->GetObjectClass(env, ScilabObj);
        if (class_Mine)
        {
            jfieldID id_Window =  (*env)->GetFieldID(env, class_Mine, "mainView","Lorg/scilab/modules/gui/bridge/window/SwingScilabWindow;");
            if (id_Window)
            {
                jobject jMainView = (*env)->GetObjectField(env, ScilabObj, id_Window);
                if (jMainView)
                {
                    jclass cls = (*env)->GetObjectClass(env, jMainView);
                    if (cls)
                    {
                        jmethodID mid = 0;
                        switch (windowState)
                        {
                        case DEICONIFY_MAINWINDOW:
                            mid = (*env)->GetMethodID(env, cls, "windowDeiconified", "()V");
                            break;
                        case ICONIFY_MAINWINDOW :
                            mid = (*env)->GetMethodID(env, cls, "windowIconified", "()V");
                            break;
                        case MAXIMIZE_MAINWINDOW:
                            mid = (*env)->GetMethodID(env, cls, "windowMaximized", "()V");
                            break;
                        case NORMAL_MAINWINDOW:
                        default:
                            mid = (*env)->GetMethodID(env, cls, "windowNormal", "()V");
                            break;
                        }

                        if (mid)
                        {
                            (*env)->CallVoidMethod(env, jMainView, mid);
                        }
                    }
                }
            }
        }
    }
}
/*--------------------------------------------------------------------------*/
char * getMainWindowTitle(void)
{
    char *title = NULL;

    JNIEnv *env = getScilabJNIEnv();
    jobject  ScilabObj = getScilabObject();

    if (env)
    {
        jclass class_Mine = (*env)->GetObjectClass(env, ScilabObj);
        if (class_Mine)
        {
            jfieldID id_Window =  (*env)->GetFieldID(env, class_Mine, "mainView", "Lorg/scilab/modules/gui/window/Window;");

            if (id_Window)
            {
                jobject jMainView = (*env)->GetObjectField(env, ScilabObj, id_Window);
                if (jMainView)
                {
                    jclass cls = (*env)->GetObjectClass(env, jMainView);
                    if (cls)
                    {
                        jmethodID mid = (*env)->GetMethodID(env, cls, "getTitle", "()Ljava/lang/String;");
                        if (mid)
                        {
                            jstring jstr;
                            jstr = (*env)->CallObjectMethod(env, jMainView, mid);
                            if (jstr)
                            {
                                const char *strValue = NULL;
                                strValue = (*env)->GetStringUTFChars(env, jstr, 0);
                                if (strValue)
                                {
                                    title = strdup(strValue);
                                }
                                (*env)->ReleaseStringUTFChars(env, jstr , strValue);
                            }
                        }
                    }
                }
            }
        }
    }

    return title;
}
/*--------------------------------------------------------------------------*/
BOOL setMainWindowTitle(char* newtitle)
{
    BOOL bOK = FALSE;
    if (newtitle)
    {
        JNIEnv *env = getScilabJNIEnv();
        jobject  ScilabObj = getScilabObject();

        if (env)
        {
            jclass class_Mine = (*env)->GetObjectClass(env, ScilabObj);
            if (class_Mine)
            {
                jfieldID id_Window =  (*env)->GetFieldID(env, class_Mine, "mainView", "Lorg/scilab/modules/gui/bridge/window/SwingScilabWindow;");

                if (id_Window)
                {
                    jobject jMainView = (*env)->GetObjectField(env, ScilabObj, id_Window);
                    if (jMainView)
                    {
                        jclass cls = (*env)->GetObjectClass(env, jMainView);
                        if (cls)
                        {
                            jmethodID mid = (*env)->GetMethodID(env, cls, "setTitle", "(Ljava/lang/String;)V");
                            if (mid)
                            {
                                jstring jstr;
                                jstr = (*env )->NewStringUTF(env , newtitle);
                                (*env)->CallVoidMethod(env, jMainView, mid, jstr);
                                bOK = TRUE;
                            }
                        }
                    }
                }
            }
        }
    }
    return bOK;
}