summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c2d9740)
raw | patch | inline | side by side (parent: c2d9740)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 21 Mar 2008 19:34:33 +0000 (19:34 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 21 Mar 2008 19:34:33 +0000 (19:34 +0000) |
14 files changed:
diff --git a/src/bind/dobinding.cpp b/src/bind/dobinding.cpp
index 639e27062844729b714734e49e60fff338124f8d..6f90105339461a32830f27063480912ce6ca9531 100644 (file)
--- a/src/bind/dobinding.cpp
+++ b/src/bind/dobinding.cpp
//# BASE OBJECT
//########################################################################
+static jmethodID _getPointer_id = NULL;
+
static jlong getPointer(JNIEnv *env, jobject obj)
{
- jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J");
- if (!id)
+ if (!_getPointer_id)
{
- err("getPointer: %s", EXCEPTION);
- return 0;
- }
- jlong val = env->GetLongField(obj, id);
+ _getPointer_id = env->GetMethodID(env->GetObjectClass(obj), "getPointer", "()J");
+ if (!_getPointer_id)
+ {
+ err("getPointer(): %s", EXCEPTION);
+ return 0;
+ }
+ }
+ jlong val = env->CallLongMethod(obj, _getPointer_id);
return val;
}
+
+static jmethodID _setPointer_id = NULL;
+
static void setPointer(JNIEnv *env, jobject obj, jlong val)
{
- jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J");
- if (!id)
+ if (!_setPointer_id)
{
- err("setPointer: %s", EXCEPTION);
- return;
+ _setPointer_id = env->GetMethodID(env->GetObjectClass(obj), "setPointer", "(J)V");
+ if (!_setPointer_id)
+ {
+ err("setPointer(): %s", EXCEPTION);
+ return;
+ }
}
- env->SetLongField(obj, id, val);
+ env->CallVoidMethod(obj, _setPointer_id, val);
}
+
static void JNICALL BaseObject_construct
(JNIEnv *env, jobject obj)
{
static void JNICALL BaseObject_destruct
(JNIEnv *env, jobject obj)
{
- NodePtr *ptr = (NodePtr *)getPointer(env, obj);
+ BaseObject *ptr = (BaseObject *)getPointer(env, obj);
if (ptr)
{
delete ptr;
diff --git a/src/bind/java/org/inkscape/cmn/BaseInterface.java b/src/bind/java/org/inkscape/cmn/BaseInterface.java
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * This is a simple mechanism to bind Inkscape to Java, and thence
+ * to all of the nice things that can be layered upon that.
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2007-2008 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.inkscape.cmn;
+
+/**
+ * A BaseInterface is not an object of its down, but is owned
+ * by a parent BaseObject. It has no mapping to a C++ object of
+ * its own, but is merely the delegate that a BaseObject calls.
+ * This is how we provide some semblance of multiple inheritance,
+ * and keep the native method count down.
+ */
+public class BaseInterface extends BaseObject
+{
+BaseObject parent;
+
+
+public void setParent(BaseObject par)
+{
+ parent = par;
+}
+
+/**
+ * Overloaded. getPointer() means that -any- java instance rooted on
+ * either BaseObject or BaseInterface can call getPointer() to get the
+ * handle to the associated C++ object pointer. The difference is that
+ * BaseObject holds the actual pointer, while BaseInterface refers to
+ * its owner BaseObject.
+ */
+protected long getPointer()
+{
+ if (parent == null)
+ return 0L;
+ else
+ return parent.getPointer();
+}
+
+/**
+ * Since this is an interface, construct()
+ * means nothing. Nothing must happen
+ */
+protected void construct()
+{
+}
+
+/**
+ * Since this is an interface, destruct()
+ * means nothing. Nothing must happen
+ */
+protected void destruct()
+{
+}
+
+
+/**
+ * Instances of this "interface" can only exist parasitically attached
+ * to a BaseObject
+ */
+public BaseInterface()
+{
+ setParent(null);
+}
+
+}
diff --git a/src/bind/java/org/inkscape/cmn/BaseObject.java b/src/bind/java/org/inkscape/cmn/BaseObject.java
index 5e496b67da3d4547e3482e7c3835d701b251f06c..b2c7aac8ff041340f2f7fc89ffc4f693459c0a44 100644 (file)
package org.inkscape.cmn;
+/**
+ * This is the base of all classes which map to a corresponding
+ * C++ object. The _pointer value is storage for the C++ object's
+ * pointer. Construct() and destruct() are called for when things
+ * need to be setup or cleaned up on the C++ side during creation or
+ * destruction of this object.
+ *
+ * @see BaseInterface for how we add multiple inheritance to classes
+ * which are rooted on this class.
+ */
public class BaseObject
{
private long _pointer;
+/**
+ * getPointer() means that -any- java instance rooted on
+ * either BaseObject or BaseInterface can call getPointer() to get the
+ * handle to the associated C++ object pointer. The difference is that
+ * BaseObject holds the actual pointer, while BaseInterface refers to
+ * its owner BaseObject.
+ */
+protected long getPointer()
+{
+ return _pointer;
+}
+
+/**
+ * sets the pointer to the associated C++ object to a new value
+ */
+protected void setPointer(long val)
+{
+ _pointer = val;
+}
+
protected native void construct();
protected native void destruct();
+protected BaseInterface imbue(BaseInterface intf)
+{
+ intf.setParent(this);
+ return intf;
+}
+
+
+/**
+ * Simple constructor
+ */
public BaseObject()
{
construct();
diff --git a/src/bind/java/org/inkscape/dom/DOMBase.java b/src/bind/java/org/inkscape/dom/DOMBase.java
index 88a3e7de114bc329b267b383162dc37772ef190d..4ab1409f01cf1b764157f396b4aeaace8c509e71 100644 (file)
* all of the DOM classes are rooted
*/
public class DOMBase
+ extends org.inkscape.cmn.BaseObject
{
-protected long _pointer;
-
/**
- * @see dobinding.cpp: DOMBase_construct()
+ * @see dobinding.cpp: DOMBase_construct().
+ *
+ * Overloaded from BaseObject so that we can do 'special' construction
*/
protected native void construct();
/**
* @see dobinding.cpp: DOMBase_destruct()
+ *
+ * Overloaded from BaseObject so that we can do 'special' destruction
*/
protected native void destruct();
public DOMBase()
{
construct();
- _pointer = 0;
}
}
diff --git a/src/bind/java/org/inkscape/dom/NodeImpl.java b/src/bind/java/org/inkscape/dom/NodeImpl.java
index a2cea09b3e000b8947b1615de031af653a09ac2f..e6071df4288c16ccf4a753f79fc4a0e0ce2dd50f 100644 (file)
public class NodeImpl
+ extends DOMBase
implements org.w3c.dom.Node
{
diff --git a/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java b/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java
index e1996f4ee4a1393bc01289bb6acb1417d30ed7ff..34778f03bcba4745d699c5abf8e099ac3d08bbfb 100644 (file)
public class EventTargetImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.events.EventTarget
{
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java
index 120683570924f0298cdd5ad586f462ed664b21c2..59c02120d88a177c6d2f4e5dd4503914b9146684 100644 (file)
implements org.w3c.dom.svg.SVGAElement
{
//from SVGURIReference
-public native SVGAnimatedString getHref( );
+private SVGURIReferenceImpl _SVGURIReference;
+public SVGAnimatedString getHref( )
+{
+ return _SVGURIReference.getHref( );
+}
//end SVGURIReference
//from SVGTests
-public native SVGStringList getRequiredFeatures( );
-public native SVGStringList getRequiredExtensions( );
-public native SVGStringList getSystemLanguage( );
-public native boolean hasExtension ( String extension );
+private SVGTestsImpl _SVGTests;
+public SVGStringList getRequiredFeatures()
+ { return _SVGTests.getRequiredFeatures(); }
+public SVGStringList getRequiredExtensions()
+ { return _SVGTests.getRequiredExtensions(); }
+public SVGStringList getSystemLanguage()
+ { return _SVGTests.getSystemLanguage(); }
+public boolean hasExtension (String extension)
+ { return _SVGTests.hasExtension(extension); }
//end SVGTests
//from SVGLangSpace
-public native String getXMLlang( );
-public native void setXMLlang( String xmllang )
- throws DOMException;
-public native String getXMLspace( );
-public native void setXMLspace( String xmlspace )
- throws DOMException;
+private SVGLangSpaceImpl _SVGLangSpace;
+public String getXMLlang()
+ { return _SVGLangSpace.getXMLlang(); }
+public void setXMLlang(String xmllang)
+ throws DOMException
+ { _SVGLangSpace.setXMLlang(xmllang); }
+public String getXMLspace()
+ { return _SVGLangSpace.getXMLspace(); }
+public void setXMLspace(String xmlspace)
+ throws DOMException
+ { _SVGLangSpace.setXMLspace(xmlspace); }
//end SVGLangSpace
//from SVGExternalResourcesRequired
-public native SVGAnimatedBoolean getExternalResourcesRequired( );
+private SVGExternalResourcesRequiredImpl _SVGExternalResourcesRequired;
+public SVGAnimatedBoolean getExternalResourcesRequired()
+ { return _SVGExternalResourcesRequired.getExternalResourcesRequired(); }
//end SVGExternalResourcesRequired
//from SVGStylable
-public native SVGAnimatedString getClassName( );
-public native CSSStyleDeclaration getStyle( );
-public native CSSValue getPresentationAttribute ( String name );
+private SVGStylableImpl _SVGStylable;
+public SVGAnimatedString getClassName()
+ { return _SVGStylable.getClassName(); }
+public CSSStyleDeclaration getStyle()
+ { return _SVGStylable.getStyle(); }
+public CSSValue getPresentationAttribute(String name)
+ { return _SVGStylable.getPresentationAttribute(name); }
//end SVGStylable
//from SVGTransformable
-public native SVGAnimatedTransformList getTransform( );
+private SVGTransformableImpl _SVGTransformable;
+public SVGAnimatedTransformList getTransform()
+ { return _SVGTransformable.getTransform(); }
//end SVGTransformable
//from SVGLocatable (from SVGTransformable)
-public native SVGElement getNearestViewportElement( );
-public native SVGElement getFarthestViewportElement( );
-
-public native SVGRect getBBox ( );
-public native SVGMatrix getCTM ( );
-public native SVGMatrix getScreenCTM ( );
-public native SVGMatrix getTransformToElement ( SVGElement element )
- throws SVGException;
+public SVGElement getNearestViewportElement()
+ { return _SVGTransformable.getNearestViewportElement(); }
+public SVGElement getFarthestViewportElement()
+ { return _SVGTransformable.getFarthestViewportElement(); }
+public SVGRect getBBox()
+ { return _SVGTransformable.getBBox(); }
+public SVGMatrix getCTM()
+ { return _SVGTransformable.getCTM(); }
+public SVGMatrix getScreenCTM()
+ { return _SVGTransformable.getScreenCTM(); }
+public SVGMatrix getTransformToElement (SVGElement element)
+ throws SVGException
+ { return _SVGTransformable.getTransformToElement(element); }
//end SVGLocatable
//from EventTarget
-public native void addEventListener(String type,
+private org.inkscape.dom.events.EventTargetImpl _EventTarget;
+public void addEventListener(String type,
EventListener listener,
- boolean useCapture);
-public native void removeEventListener(String type,
+ boolean useCapture)
+ { _EventTarget.addEventListener(type, listener, useCapture); }
+public void removeEventListener(String type,
EventListener listener,
- boolean useCapture);
-public native boolean dispatchEvent(Event evt)
- throws EventException;
-public native void addEventListenerNS(String namespaceURI,
+ boolean useCapture)
+ { _EventTarget.removeEventListener(type, listener, useCapture); }
+public boolean dispatchEvent(Event evt)
+ throws EventException
+ { return _EventTarget.dispatchEvent(evt); }
+public void addEventListenerNS(String namespaceURI,
String type,
EventListener listener,
boolean useCapture,
- Object evtGroup);
-public native void removeEventListenerNS(String namespaceURI,
+ Object evtGroup)
+ { _EventTarget.addEventListenerNS(namespaceURI, type, listener, useCapture, evtGroup); }
+public void removeEventListenerNS(String namespaceURI,
String type,
EventListener listener,
- boolean useCapture);
-public native boolean willTriggerNS(String namespaceURI,
- String type);
-public native boolean hasEventListenerNS(String namespaceURI,
- String type);
+ boolean useCapture)
+ { _EventTarget.removeEventListenerNS(namespaceURI, type, listener, useCapture); }
+public boolean willTriggerNS(String namespaceURI,
+ String type)
+ { return _EventTarget.willTriggerNS(namespaceURI, type); }
+public boolean hasEventListenerNS(String namespaceURI,
+ String type)
+ { return _EventTarget.hasEventListenerNS(namespaceURI, type); }
//end EventTarget
public native SVGAnimatedString getTarget( );
+
+public SVGAElementImpl()
+{
+ imbue(_SVGURIReference = new SVGURIReferenceImpl());
+ imbue(_SVGTests = new SVGTestsImpl());
+ imbue(_SVGLangSpace = new SVGLangSpaceImpl());
+ imbue(_SVGExternalResourcesRequired = new SVGExternalResourcesRequiredImpl());
+ imbue(_SVGStylable = new SVGStylableImpl());
+ imbue(_SVGTransformable = new SVGTransformableImpl());
+ imbue(_EventTarget = new org.inkscape.dom.events.EventTargetImpl());
+}
+
}
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java
index b4830d9a06f5dd1b642e743bd6ece804c155e9bc..08fac83125d13f03cdf52d34c01fa4c3a0c364b2 100644 (file)
public class SVGExternalResourcesRequiredImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGExternalResourcesRequired
{
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java
index 4a35f0539a8ae66ffa722e079bc9ffc0cdb8fe91..5caed03305eebd8f8e456bfb914e7205ef0578ad 100644 (file)
public class SVGLangSpaceImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGLangSpace
{
public native String getXMLlang( );
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java
index f7045fb04fe5d014de8241a59741e471e0085883..df9a0d59bdb63449337b379c89d98b5454640bf2 100644 (file)
public class SVGLocatableImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGLocatable
{
public native SVGElement getNearestViewportElement( );
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java
index 54df62696d4fb20b83ebc2343e4a63835d8e8b08..7523d456d3b24d10eba1889567c75779b8f2892a 100644 (file)
import org.w3c.dom.svg.SVGAnimatedString;
public class SVGStylableImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGStylable
{
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java
index c31291fc430e6b3a230a8582eee0d88d89b07d40..5f0a8c727900799e84f2e9e9013e423d2b981d99 100644 (file)
public class SVGTestsImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGTests
{
public native SVGStringList getRequiredFeatures( );
diff --git a/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java
index c2e53d11a7f1cd4835b10b8a3b3defdbb99ed42f..2e3bb0bd442f32b29512d615dc70aad101f1bf53 100644 (file)
public class SVGURIReferenceImpl
+ extends
+ org.inkscape.cmn.BaseInterface
implements org.w3c.dom.svg.SVGURIReference
{
public native SVGAnimatedString getHref( );
diff --git a/src/bind/javabind.h b/src/bind/javabind.h
index c73afa58194dc5d35575648d9845e207a940da5a..144e633e70c5b1061dc0f6f2428b2e13cf37f927 100644 (file)
--- a/src/bind/javabind.h
+++ b/src/bind/javabind.h
typedef Glib::ustring String;
+/**
+ * This is the base class of all things which will be C++ object
+ * instances
+ */
+class BaseObject
+{
+public:
+
+ /**
+ * Simple constructor
+ */
+ BaseObject()
+ {}
+
+ /**
+ * Destructor
+ */
+ virtual ~BaseObject()
+ {}
+
+};
+
/**
*