summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 587dd41)
raw | patch | inline | side by side (parent: 587dd41)
author | ishmal <ishmal@users.sourceforge.net> | |
Wed, 2 Apr 2008 20:39:29 +0000 (20:39 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Wed, 2 Apr 2008 20:39:29 +0000 (20:39 +0000) |
src/bind/java/org/inkscape/cmn/Gateway.java | patch | blob | history | |
src/bind/javabind.cpp | patch | blob | history |
diff --git a/src/bind/java/org/inkscape/cmn/Gateway.java b/src/bind/java/org/inkscape/cmn/Gateway.java
index 00e720e3223a1c6889cfe0d1ce88ecba84a76d87..bba9cdf0b2d1f7b7df3242a054a91c524154f59e 100644 (file)
import java.io.IOException;
import javax.swing.JOptionPane;
+//for xml
+import org.w3c.dom.Document;
+import java.io.ByteArrayInputStream;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.inkscape.script.ScriptConsole;
+//########################################################################
+//# R E P R (inkscape's xml tree)
+//########################################################################
+
+private native String documentGet(long backPtr);
+
+public String documentGet()
+{
+ return documentGet(backPtr);
+}
+
+public Document documentGetXml()
+{
+ String xmlStr = documentGet();
+ if (xmlStr == null || xmlStr.length()==0)
+ return null;
+ Document doc = null;
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ doc = parser.parse(new ByteArrayInputStream(xmlStr.getBytes()));
+ }
+ catch (java.io.IOException e)
+ {
+ err("getReprXml:" + e);
+ }
+ catch (javax.xml.parsers.ParserConfigurationException e)
+ {
+ err("getReprXml:" + e);
+ }
+ catch (org.xml.sax.SAXException e)
+ {
+ err("getReprXml:" + e);
+ }
+ return doc;
+}
+
+private native boolean documentSet(long backPtr, String xmlStr);
+
+public boolean documentSet(String xmlStr)
+{
+ return documentSet(backPtr, xmlStr);
+}
+
//########################################################################
//# LOGGING STREAM
//########################################################################
private static Gateway _instance = null;
-public static Gateway getInstance(long backPtr)
+public static Gateway getInstance()
{
- if (_instance == null)
- {
- _instance = new Gateway(backPtr);
- }
return _instance;
}
diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp
index 0262aee54c5cc570756d7d94a1ef663cadfef620..6bffe0cd71fce728752a207c2286026468da2df2 100644 (file)
--- a/src/bind/javabind.cpp
+++ b/src/bind/javabind.cpp
#include <prefix.h>
#include <glib/gmessages.h>
+//For repr and document
+#include <document.h>
+#include <inkscape.h>
+#include <xml/repr.h>
/**
* Note: We must limit Java or JVM-specific code to this file
return buf;
}
-jint getInt(JNIEnv *env, jobject obj, const char *name)
+jint getObjInt(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "I");
return env->GetIntField(obj, fid);
}
-void setInt(JNIEnv *env, jobject obj, const char *name, jint val)
+void setObjInt(JNIEnv *env, jobject obj, const char *name, jint val)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "I");
env->SetIntField(obj, fid, val);
}
-jlong getLong(JNIEnv *env, jobject obj, const char *name)
+jlong getObjLong(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "J");
return env->GetLongField(obj, fid);
}
-void setLong(JNIEnv *env, jobject obj, const char *name, jlong val)
+void setObjLong(JNIEnv *env, jobject obj, const char *name, jlong val)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "J");
env->SetLongField(obj, fid, val);
}
-jfloat getFloat(JNIEnv *env, jobject obj, const char *name)
+jfloat getObjFloat(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "F");
return env->GetFloatField(obj, fid);
}
-void setFloat(JNIEnv *env, jobject obj, const char *name, jfloat val)
+void setObjFloat(JNIEnv *env, jobject obj, const char *name, jfloat val)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "F");
env->SetFloatField(obj, fid, val);
}
-jdouble getDouble(JNIEnv *env, jobject obj, const char *name)
+jdouble getObjDouble(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "D");
return env->GetDoubleField(obj, fid);
}
-void setDouble(JNIEnv *env, jobject obj, const char *name, jdouble val)
+void setObjDouble(JNIEnv *env, jobject obj, const char *name, jdouble val)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "D");
env->SetDoubleField(obj, fid, val);
}
-String getString(JNIEnv *env, jobject obj, const char *name)
+String getString(JNIEnv *env, jstring jstr)
{
- jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;");
- jstring jstr = (jstring)env->GetObjectField(obj, fid);
const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE);
String str = chars;
env->ReleaseStringUTFChars(jstr, chars);
return str;
}
-void setString(JNIEnv *env, jobject obj, const char *name, const String &val)
+String getObjString(JNIEnv *env, jobject obj, const char *name)
+{
+ jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;");
+ jstring jstr = (jstring)env->GetObjectField(obj, fid);
+ return getString(env, jstr);
+}
+
+void setObjString(JNIEnv *env, jobject obj, const char *name, const String &val)
{
jstring jstr = env->NewStringUTF(val.c_str());
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;");
//========================================================================
// Gateway
//========================================================================
+/**
+ * This is provided to scripts can grab the current copy or the
+ * repr tree. If anyone has a smarter way of doing this, please implement.
+ */
+jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong ptr)
+{
+ JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ String buf = sp_repr_save_buf((SP_ACTIVE_DOCUMENT)->rdoc);
+ jstring jstr = env->NewStringUTF(buf.c_str());
+ return jstr;
+}
+
+/**
+ * This is provided to scripts can load an XML tree into Inkscape.
+ * If anyone has a smarter way of doing this, please implement.
+ */
+jboolean JNICALL documentSet(JNIEnv *env, jobject /*obj*/, jlong ptr, jstring jstr)
+{
+ JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ String s = getString(env, jstr);
+ SPDocument *doc = sp_document_new_from_mem(s.c_str(), s.size(), true);
+}
+
/**
* This method is used to allow the gateway class to
* redirect its logging stream here.
static JNINativeMethod gatewayMethods[] =
{
-{ (char *)"logWrite", (char *)"(JI)V", (void *)logWrite },
+{ (char *)"documentGet", (char *)"(J)Ljava/lang/String;", (void *)documentGet },
+{ (char *)"documentSet", (char *)"(JLjava/lang/String;)Z", (void *)documentSet },
+{ (char *)"logWrite", (char *)"(JI)V", (void *)logWrite },
{ NULL, NULL, NULL }
};