You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2005/09/13 15:31:09 UTC
svn commit: r280553 [9/9] - in /xmlgraphics/batik/trunk: ./
resources/org/apache/batik/apps/svgbrowser/resources/
sources/org/apache/batik/bridge/ sources/org/apache/batik/bridge/svg12/
sources/org/apache/batik/css/engine/ sources/org/apache/batik/dom/...
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/parser/AbstractScanner.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/parser/AbstractScanner.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/parser/AbstractScanner.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/parser/AbstractScanner.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,234 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.parser;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.batik.util.io.NormalizingReader;
+import org.apache.batik.util.io.StreamNormalizingReader;
+import org.apache.batik.util.io.StringNormalizingReader;
+
+/**
+ * An abstract scanner class to be extended.
+ *
+ * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
+ * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
+ * @version $Id$
+ */
+public abstract class AbstractScanner {
+
+ /**
+ * The reader.
+ */
+ protected NormalizingReader reader;
+
+ /**
+ * The current char.
+ */
+ protected int current;
+
+ /**
+ * The recording buffer.
+ */
+ protected char[] buffer = new char[128];
+
+ /**
+ * The current position in the buffer.
+ */
+ protected int position;
+
+ /**
+ * The type of the current lexical unit.
+ */
+ protected int type;
+
+ /**
+ * The previous lexical unit type that was scanned.
+ */
+ protected int previousType;
+
+ /**
+ * The start offset of the last lexical unit.
+ */
+ protected int start;
+
+ /**
+ * The end offset of the last lexical unit.
+ */
+ protected int end;
+
+ /**
+ * The characters to skip to create the string which represents the
+ * current token.
+ */
+ protected int blankCharacters;
+
+ /**
+ * Creates a new AbstractScanner object.
+ * @param r The reader to scan.
+ */
+ public AbstractScanner(Reader r) throws ParseException {
+ try {
+ reader = new StreamNormalizingReader(r);
+ current = nextChar();
+ } catch (IOException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ /**
+ * Creates a new AbstractScanner object.
+ * @param is The input stream to scan.
+ * @param enc The encoding to use to decode the input stream, or null.
+ */
+ public AbstractScanner(InputStream is, String enc) throws ParseException {
+ try {
+ reader = new StreamNormalizingReader(is, enc);
+ current = nextChar();
+ } catch (IOException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ /**
+ * Creates a new AbstractScanner object.
+ * @param s The string to scan.
+ */
+ public AbstractScanner(String s) throws ParseException {
+ try {
+ reader = new StringNormalizingReader(s);
+ current = nextChar();
+ } catch (IOException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ /**
+ * Returns the current line.
+ */
+ public int getLine() {
+ return reader.getLine();
+ }
+
+ /**
+ * Returns the current column.
+ */
+ public int getColumn() {
+ return reader.getColumn();
+ }
+
+ /**
+ * Returns the buffer used to store the chars.
+ */
+ public char[] getBuffer() {
+ return buffer;
+ }
+
+ /**
+ * Returns the start offset of the last lexical unit.
+ */
+ public int getStart() {
+ return start;
+ }
+
+ /**
+ * Returns the end offset of the last lexical unit.
+ */
+ public int getEnd() {
+ return end;
+ }
+
+ /**
+ * Clears the buffer.
+ */
+ public void clearBuffer() {
+ if (position <= 0) {
+ position = 0;
+ } else {
+ buffer[0] = buffer[position-1];
+ position = 1;
+ }
+ }
+
+ /**
+ * The current lexical unit type like defined in LexicalUnits.
+ */
+ public int getType() {
+ return type;
+ }
+
+ /**
+ * Returns the string representation of the current lexical unit.
+ */
+ public String getStringValue() {
+ return new String(buffer, start, end - start);
+ }
+
+ /**
+ * Returns the next token.
+ */
+ public int next() throws ParseException {
+ blankCharacters = 0;
+ start = position - 1;
+ previousType = type;
+ nextToken();
+ end = position - endGap();
+ return type;
+ }
+
+ /**
+ * Returns the end gap of the current lexical unit.
+ */
+ protected abstract int endGap();
+
+ /**
+ * Returns the next token.
+ */
+ protected abstract void nextToken() throws ParseException;
+
+ /**
+ * Compares the given int with the given character, ignoring case.
+ */
+ protected static boolean isEqualIgnoreCase(int i, char c) {
+ return (i == -1) ? false : Character.toLowerCase((char)i) == c;
+ }
+
+ /**
+ * Sets the value of the current char to the next character or -1 if the
+ * end of stream has been reached.
+ */
+ protected int nextChar() throws IOException {
+ current = reader.read();
+
+ if (current == -1) {
+ return current;
+ }
+
+ if (position == buffer.length) {
+ char[] t = new char[position * 3 / 2];
+ for (int i = 0; i < position; i++) {
+ t[i] = buffer[i];
+ }
+ buffer = t;
+ }
+
+ return buffer[position++] = (char)current;
+ }
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/parser/AbstractScanner.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/script/ScriptEventWrapper.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/script/ScriptEventWrapper.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/ScriptEventWrapper.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/ScriptEventWrapper.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,33 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.script;
+
+/**
+ * Interface for objects that act as a Java wrapper for a javascript
+ * event object.
+ *
+ * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
+ * @version $Id$
+ */
+public interface ScriptEventWrapper {
+
+ /**
+ * Returns the event object this object is wrapping.
+ */
+ Object getEventObject();
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/script/ScriptEventWrapper.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2001-2003 The Apache Software Foundation
+ Copyright 2001-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,12 +18,12 @@
package org.apache.batik.script.rhino;
import java.lang.ref.SoftReference;
-import java.lang.reflect.Method;
import java.util.Map;
-import java.util.HashMap;
import java.util.WeakHashMap;
import org.apache.batik.dom.AbstractNode;
+import org.apache.batik.dom.events.CustomEvent;
+import org.apache.batik.script.ScriptEventWrapper;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.JavaScriptException;
@@ -63,7 +63,13 @@
}
public void handleEvent(Event evt) {
try {
- interpreter.callHandler(function, evt);
+ Object event;
+ if (evt instanceof ScriptEventWrapper) {
+ event = ((ScriptEventWrapper) evt).getEventObject();
+ } else {
+ event = evt;
+ }
+ interpreter.callHandler(function, event);
} catch (JavaScriptException e) {
// the only simple solution is to forward it as a
// RuntimeException to be catched by event dispatching
@@ -87,12 +93,16 @@
}
public void handleEvent(Event evt) {
try {
- array[0] = evt;
+ if (evt instanceof ScriptEventWrapper) {
+ array[0] = ((ScriptEventWrapper) evt).getEventObject();
+ } else {
+ array[0] = evt;
+ }
interpreter.enterContext();
ScriptableObject.callMethod(scriptable, HANDLE_EVENT, array);
} catch (JavaScriptException e) {
// the only simple solution is to forward it as a
- // RuntimeException to be catched by event dispatching
+ // RuntimeException to be caught by event dispatching
// in BridgeEventSupport.java
// another solution will to give UserAgent to interpreters
throw new WrappedException(e);
@@ -102,6 +112,154 @@
}
}
+ /**
+ * A Java object wrapper for a javascript custom event object.
+ */
+ static class ObjectCustomEvent implements CustomEvent, ScriptEventWrapper {
+
+ public Scriptable scriptable;
+ public RhinoInterpreter interpreter;
+ protected Map eventMap;
+
+ public ObjectCustomEvent(Scriptable s,
+ RhinoInterpreter interpreter,
+ Map eventMap) {
+ scriptable = s;
+ this.interpreter = interpreter;
+ this.eventMap = eventMap;
+ }
+
+ public Object getEventObject() {
+ return scriptable;
+ }
+
+ protected Object call(String fn) {
+ return call(fn, null);
+ }
+
+ protected Object call(String fn, Object[] args) {
+ try {
+ interpreter.enterContext();
+ return ScriptableObject.callMethod(scriptable, fn, args);
+ } catch (JavaScriptException e) {
+ throw new WrappedException(e);
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public String getType() {
+ return (String) Context.toType(call("getType"), String.class);
+ }
+
+ public EventTarget getTarget() {
+ return (EventTarget) call("getTarget");
+ }
+
+ public void setTarget(EventTarget target) {
+ call("setTarget", new Object[] { target });
+ }
+
+ public EventTarget getCurrentTarget() {
+ return (EventTarget) call("getCurrentTarget");
+ }
+
+ public short getEventPhase() {
+ return (short) ((Integer) Context.toType(call("getEventPhase"), Integer.class)).intValue();
+ }
+
+ public boolean getBubbles() {
+ return ((Boolean) Context.toType(call("getBubbles"), Boolean.class)).booleanValue();
+ }
+
+ public boolean getCancelable() {
+ return ((Boolean) Context.toType(call("getCancelable"), Boolean.class)).booleanValue();
+ }
+
+ public long getTimeStamp() {
+ return (long) ((Double) Context.toType(call("getTimeStamp"), Double.class)).doubleValue();
+ }
+
+ public void stopPropagation() {
+ call("stopPropagation");
+ }
+
+ public void preventDefault() {
+ call("preventDefault");
+ }
+
+ public void initEvent(String t, boolean b, boolean c) {
+ call("initEvent", new Object[] { t, new Boolean(b), new Boolean(c) });
+ }
+
+ public String getNamespaceURI() {
+ return (String) Context.toType(call("getNamespaceURI"), String.class);
+ }
+
+ public boolean isCustom() {
+ return ((Boolean) Context.toType(call("isCustom"), Boolean.class)).booleanValue();
+ }
+
+ public void stopImmediatePropagation() {
+ call("stopImmediatePropagation");
+ }
+
+ public boolean isDefaultPrevented() {
+ return ((Boolean) Context.toType(call("isDefaultPrevented"), Boolean.class)).booleanValue();
+ }
+
+ public void initEventNS(String ns, String t, boolean b, boolean c) {
+ call("initEventNS", new Object[] { ns, t, new Boolean(b), new Boolean(c) });
+ }
+
+ public void setDispatchState(EventTarget t, short phase) {
+ call("setDispatchState", new Object[] { t, new Double(phase) });
+ }
+
+ public boolean isPropagationStopped() {
+ return ((Boolean) Context.toType(call("isPropagationStopped"), Boolean.class)).booleanValue();
+ }
+
+ public boolean isImmediatePropagationStopped() {
+ return ((Boolean) Context.toType(call("isImmediatePropagationStopped"), Boolean.class)).booleanValue();
+ }
+
+ public void resumePropagation() {
+ call("resumePropagation");
+ }
+
+ public CustomEvent retarget(EventTarget target) {
+ Object ret = call("retarget", new Object[] { target });
+ if (ret instanceof ScriptableObject) {
+ CustomEvent evt = new ObjectCustomEvent((NativeObject) ret,
+ interpreter,
+ eventMap);
+ eventMap.put(ret, new SoftReference(evt));
+ return evt;
+ }
+ // XXX some error here
+ return null;
+ }
+
+ public Event getOriginalEvent() {
+ Object origEvt = call("getOriginalEvent");
+ if (origEvt instanceof NativeObject) {
+ SoftReference sr = (SoftReference) eventMap.get(origEvt);
+ if (sr == null) {
+ CustomEvent evt = new ObjectCustomEvent((NativeObject) origEvt,
+ interpreter,
+ eventMap);
+ eventMap.put(origEvt, new SoftReference(evt));
+ return evt;
+ }
+ } else if (origEvt instanceof NativeJavaObject) {
+ return (Event) ((NativeJavaObject) origEvt).unwrap();
+ }
+ // XXX some error here
+ return null;
+ }
+ }
+
static abstract class FunctionProxy implements Function {
protected Function delegate;
@@ -399,6 +557,33 @@
}
}
+ static class FunctionDispatchProxy extends FunctionProxy {
+ protected Map eventMap;
+ protected RhinoInterpreter interpreter;
+ FunctionDispatchProxy(RhinoInterpreter interpreter,
+ Function delegate, Map eventMap) {
+ super(delegate);
+ this.eventMap = eventMap;
+ this.interpreter = interpreter;
+ }
+
+ public Object call(Context ctx, Scriptable scope,
+ Scriptable thisObj, Object[] args)
+ throws JavaScriptException {
+ NativeJavaObject njo = (NativeJavaObject) thisObj;
+ if (args[0] instanceof NativeObject) {
+ Event evt = new ObjectCustomEvent((NativeObject) args[0],
+ interpreter,
+ eventMap);
+ eventMap.put(args[0], new SoftReference(evt));
+ args[0] = Context.toType(args[0], Scriptable.class);
+ ((EventTarget) njo.unwrap()).dispatchEvent(evt);
+ return Undefined.instance;
+ }
+ return delegate.call(ctx, scope, thisObj, args);
+ }
+ }
+
// the keys are the underlying Java object, in order
// to remove potential memory leaks use a WeakHashMap to allow
// to collect entries as soon as the underlying Java object is
@@ -409,9 +594,7 @@
public final static String ADDNS_NAME = "addEventListenerNS";
public final static String REMOVE_NAME = "removeEventListener";
public final static String REMOVENS_NAME = "removeEventListenerNS";
- public final static Class[] ARGS_TYPE = { String.class,
- EventListener.class,
- Boolean.TYPE };
+ public final static String DISPATCH_NAME = "dispatchEvent";
protected RhinoInterpreter interpreter;
EventTargetWrapper(Scriptable scope, EventTarget object,
@@ -440,6 +623,8 @@
(Function) method, initMap());
} else if (name.equals(REMOVENS_NAME)) {
method = new FunctionRemoveNSProxy((Function) method, initMap());
+ } else if (name.equals(DISPATCH_NAME)) {
+ method = new FunctionDispatchProxy(interpreter, (Function) method, initMap());
}
return method;
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassLoader.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassLoader.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassLoader.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassLoader.java Tue Sep 13 06:29:29 2005
@@ -22,13 +22,11 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.ProtectionDomain;
-import java.security.PrivilegedAction;
import java.security.cert.Certificate;
import org.mozilla.javascript.GeneratedClassLoader;
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoInterpreter.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoInterpreter.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoInterpreter.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoInterpreter.java Tue Sep 13 06:29:29 2005
@@ -21,7 +21,7 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
-import java.lang.reflect.Method;
+import java.lang.ref.WeakReference;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
@@ -39,7 +39,6 @@
import org.mozilla.javascript.Function;
import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.NativeJavaPackage;
-import org.mozilla.javascript.PropertyException;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
@@ -129,7 +128,7 @@
* Context vector, to make sure we are not
* setting the security context too many times
*/
- protected List contexts = new LinkedList();
+ protected static List contexts = new LinkedList();
/**
* Build a <code>Interpreter</code> for ECMAScript using Rhino.
@@ -194,7 +193,19 @@
if (ctx == defaultContext)
return ctx;
- if (!contexts.contains(ctx)) {
+ boolean found = false;
+ Iterator i = contexts.iterator();
+ while (i.hasNext()) {
+ WeakReference ref = (WeakReference) i.next();
+ Object context = ref.get();
+ if (context == null) {
+ i.remove();
+ } else if (context == ctx) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
ctx.setWrapFactory(wrapFactory);
ctx.setSecurityController(securityController);
ctx.setClassShutter(new RhinoClassShutter());
@@ -202,9 +213,9 @@
// No class loader so don't try and optmize.
if (rhinoClassLoader == null) {
ctx.setOptimizationLevel(-1);
- ctx.setCachingEnabled(false);
+ Context.setCachingEnabled(false);
}
- contexts.add(ctx);
+ contexts.add(new WeakReference(ctx));
}
defaultContext = ctx;
return ctx;
@@ -394,8 +405,8 @@
window = (Window)object;
object = globalObject;
}
- Scriptable jsObject;
- jsObject = Context.toObject(object, globalObject);
+ Scriptable jsObject;
+ jsObject = Context.toObject(object, globalObject);
globalObject.put(name, globalObject, jsObject);
} finally {
Context.exit();
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGCanvas.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGCanvas.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGCanvas.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGCanvas.java Tue Sep 13 06:29:29 2005
@@ -47,6 +47,7 @@
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.css.engine.CSSEngine;
+import org.apache.batik.dom.events.NodeEventTarget;
import org.apache.batik.swing.gvt.AbstractImageZoomInteractor;
import org.apache.batik.swing.gvt.AbstractPanInteractor;
import org.apache.batik.swing.gvt.AbstractResetTransformInteractor;
@@ -189,7 +190,7 @@
*/
protected Map toolTipMap = null;
protected EventListener toolTipListener = new ToolTipModifier();
- protected EventTarget lastTarget = null;;
+ protected EventTarget lastTarget = null;
protected Set toolTipDocs = null;
/**
@@ -559,13 +560,17 @@
ttdoc = (SVGDocument)((WeakReference)i.next()).get();
if (ttdoc == null) continue;
- EventTarget root;
- root = (EventTarget)ttdoc.getRootElement();
+ NodeEventTarget root;
+ root = (NodeEventTarget)ttdoc.getRootElement();
if (root == null) continue;
- root.removeEventListener(SVGConstants.SVG_EVENT_MOUSEOVER,
- toolTipListener, false);
- root.removeEventListener(SVGConstants.SVG_EVENT_MOUSEOUT,
- toolTipListener, false);
+ root.removeEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ SVGConstants.SVG_EVENT_MOUSEOVER,
+ toolTipListener, false);
+ root.removeEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ SVGConstants.SVG_EVENT_MOUSEOUT,
+ toolTipListener, false);
}
toolTipDocs = null;
}
@@ -1013,14 +1018,18 @@
SVGDocument doc = (SVGDocument)elt.getOwnerDocument();
WeakReference wr = new WeakReference(doc);
if (toolTipDocs.add(wr)) {
- EventTarget root;
- root = (EventTarget)doc.getRootElement();
+ NodeEventTarget root;
+ root = (NodeEventTarget)doc.getRootElement();
// On mouseover, it sets the tooltip to the given value
- root.addEventListener(SVGConstants.SVG_EVENT_MOUSEOVER,
- toolTipListener, false);
+ root.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ SVGConstants.SVG_EVENT_MOUSEOVER,
+ toolTipListener,
+ false, null);
// On mouseout, it removes the tooltip
- root.addEventListener(SVGConstants.SVG_EVENT_MOUSEOUT,
- toolTipListener, false);
+ root.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ SVGConstants.SVG_EVENT_MOUSEOUT,
+ toolTipListener,
+ false, null);
}
toolTipMap.put(elt, toolTip);
@@ -1165,7 +1174,7 @@
if (o != null) {
break;
}
- e = CSSEngine.getParentElement(e);
+ e = CSSEngine.getParentCSSStylableElement(e);
}
final String theToolTip = (String)o;
if (prevLastTarget != lastTarget)
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGScrollPane.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGScrollPane.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGScrollPane.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGScrollPane.java Tue Sep 13 06:29:29 2005
@@ -44,10 +44,10 @@
import org.apache.batik.bridge.ViewBox;
import org.apache.batik.bridge.UpdateManagerListener;
import org.apache.batik.bridge.UpdateManagerEvent;
+import org.apache.batik.dom.events.NodeEventTarget;
import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.JGVTComponentListener;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
@@ -56,6 +56,7 @@
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
import org.apache.batik.util.SVGConstants;
+import org.apache.batik.util.XMLConstants;
import org.w3c.dom.svg.SVGSVGElement;
import org.w3c.dom.svg.SVGDocument;
@@ -174,9 +175,11 @@
class SVGScrollDocumentLoaderListener extends SVGDocumentLoaderAdapter {
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
- SVGSVGElement root = e.getSVGDocument().getRootElement();
- root.addEventListener
- (SVGConstants.SVG_SVGZOOM_EVENT_TYPE,
+ NodeEventTarget root
+ = (NodeEventTarget) e.getSVGDocument().getRootElement();
+ root.addEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ SVGConstants.SVG_SVGZOOM_EVENT_TYPE,
new EventListener() {
public void handleEvent(Event evt) {
if (!(evt.getTarget() instanceof SVGSVGElement))
@@ -186,7 +189,7 @@
SVGSVGElement svg = (SVGSVGElement) evt.getTarget();
scaleChange(svg.getCurrentScale());
} // handleEvent()
- }, false);
+ }, false, null);
}// documentLoadingCompleted()
};
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/swing/svg/AbstractJSVGComponent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/swing/svg/AbstractJSVGComponent.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/swing/svg/AbstractJSVGComponent.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/swing/svg/AbstractJSVGComponent.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2001-2004 The Apache Software Foundation
+ Copyright 2001-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
import java.awt.geom.Dimension2D;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -50,16 +49,16 @@
import org.apache.batik.bridge.DocumentLoader;
import org.apache.batik.bridge.ErrorConstants;
import org.apache.batik.bridge.ExternalResourceSecurity;
-import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.RelaxedExternalResourceSecurity;
import org.apache.batik.bridge.ScriptSecurity;
import org.apache.batik.bridge.UpdateManager;
-import org.apache.batik.bridge.UpdateManagerAdapter;
import org.apache.batik.bridge.UpdateManagerEvent;
import org.apache.batik.bridge.UpdateManagerListener;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.bridge.ViewBox;
+import org.apache.batik.bridge.svg12.SVG12BridgeContext;
import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.dom.util.DOMUtilities;
import org.apache.batik.dom.util.XLinkSupport;
import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
@@ -69,9 +68,7 @@
import org.apache.batik.gvt.event.EventDispatcher;
import org.apache.batik.gvt.text.Mark;
import org.apache.batik.gvt.renderer.ImageRenderer;
-import org.apache.batik.swing.gvt.GVTTreeRenderer;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
-import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.JGVTComponent;
import org.apache.batik.swing.gvt.JGVTComponentListener;
import org.apache.batik.util.ParsedURL;
@@ -679,7 +676,7 @@
return;
}
- bridgeContext = createBridgeContext();
+ bridgeContext = createBridgeContext((SVGOMDocument) doc);
switch (documentState) {
case ALWAYS_STATIC:
@@ -806,11 +803,16 @@
/**
* Creates a new bridge context.
*/
- protected BridgeContext createBridgeContext() {
+ protected BridgeContext createBridgeContext(SVGOMDocument doc) {
if (loader == null) {
loader = new DocumentLoader(userAgent);
}
- BridgeContext result = new BridgeContext(userAgent, loader);
+ BridgeContext result;
+ if (doc.isSVG12()) {
+ result = new SVG12BridgeContext(userAgent, loader);
+ } else {
+ result = new BridgeContext(userAgent, loader);
+ }
return result;
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/transcoder/print/PrintTranscoder.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/transcoder/print/PrintTranscoder.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/transcoder/print/PrintTranscoder.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/transcoder/print/PrintTranscoder.java Tue Sep 13 06:29:29 2005
@@ -36,7 +36,6 @@
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.ext.awt.RenderingHintsKeyExt;
import org.apache.batik.transcoder.SVGAbstractTranscoder;
-import org.apache.batik.transcoder.XMLAbstractTranscoder;
import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftDoublyIndexedTable.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftDoublyIndexedTable.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftDoublyIndexedTable.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/SoftDoublyIndexedTable.java Tue Sep 13 06:29:29 2005
@@ -22,7 +22,7 @@
/**
* This class represents a doubly indexed hash table, which holds
- * soft references to the contained values..
+ * soft references to the contained values.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id$
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/util/XBLConstants.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/util/XBLConstants.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/XBLConstants.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/XBLConstants.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,62 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.util;
+
+/**
+ * Define XBL constants, such as tag names, attribute names and
+ * namespace URI.
+ *
+ * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
+ * @version $Id$
+ */
+public interface XBLConstants {
+
+ /**
+ * Namespace URI for XBL elements and events.
+ */
+ String XBL_NAMESPACE_URI = "http://www.w3.org/2004/xbl";
+
+ // -- Event types --------------------------------------------------------
+
+ String XBL_PREBIND_EVENT_TYPE = "prebind";
+ String XBL_BOUND_EVENT_TYPE = "bound";
+ String XBL_UNBINDING_EVENT_TYPE = "unbinding";
+
+ // -- Event handler attributes -------------------------------------------
+
+ String XBL_ONPREBIND_ATTRIBUTE = "onprebind";
+ String XBL_ONBOUND_ATTRIBUTE = "onprebind";
+ String XBL_ONUNBINDING_ATTRIBUTE = "onprebind";
+
+ // -- XBL tags -----------------------------------------------------------
+
+ String XBL_XBL_TAG = "xbl";
+ String XBL_DEFINITION_TAG = "definition";
+ String XBL_TEMPLATE_TAG = "template";
+ String XBL_CONTENT_TAG = "content";
+ String XBL_HANDLER_GROUP_TAG = "handlerGroup";
+ String XBL_IMPORT_TAG = "import";
+ String XBL_SHADOW_TREE_TAG = "shadowTree";
+
+ // -- XBL attributes -----------------------------------------------------
+
+ String XBL_BINDINGS_ATTRIBUTE = "bindings";
+ String XBL_ELEMENT_ATTRIBUTE = "element";
+ String XBL_INCLUDES_ATTRIBUTE = "includes";
+ String XBL_REF_ATTRIBUTE = "ref";
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/util/XBLConstants.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/DOMViewer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/DOMViewer.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/DOMViewer.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/DOMViewer.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000,2002-2003 The Apache Software Foundation
+ Copyright 2000,2002-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
import java.awt.BorderLayout;
import java.awt.Component;
-import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
@@ -53,6 +52,12 @@
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
+import org.apache.batik.bridge.svg12.ContentManager;
+import org.apache.batik.bridge.svg12.DefaultXBLManager;
+import org.apache.batik.dom.AbstractDocument;
+import org.apache.batik.dom.svg12.XBLOMContentElement;
+import org.apache.batik.dom.xbl.NodeXBL;
+import org.apache.batik.dom.xbl.XBLManager;
import org.apache.batik.util.gui.resource.ActionMap;
import org.apache.batik.util.gui.resource.ButtonFactory;
import org.apache.batik.util.gui.resource.MissingListenerException;
@@ -61,6 +66,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.ViewCSS;
@@ -102,6 +108,9 @@
*/
protected Panel panel = new Panel();
+ /**
+ * Whether to show text nodes that contain only whitespace in the tree.
+ */
protected boolean showWhitespace = true;
/**
@@ -135,6 +144,10 @@
getContentPane().add("South", p);
}
+ /**
+ * Sets whether to show text nodes that contain only whitespace
+ * in the tree.
+ */
public void setShowWhitespace(boolean state) {
showWhitespace = state;
if (panel.document != null)
@@ -363,8 +376,38 @@
if (txt.trim().length() == 0)
continue;
}
- result.add(createTree(n, showWhitespace));
+ result.add(createTree(n, showWhitespace));
}
+ if (node instanceof NodeXBL) {
+ Element shadowTree = ((NodeXBL) node).getXblShadowTree();
+ if (shadowTree != null) {
+ DefaultMutableTreeNode shadowNode
+ = new DefaultMutableTreeNode
+ (new ShadowNodeInfo(shadowTree));
+ shadowNode.add(createTree(shadowTree, showWhitespace));
+ result.add(shadowNode);
+ }
+ }
+ if (node instanceof XBLOMContentElement) {
+ AbstractDocument doc
+ = (AbstractDocument) node.getOwnerDocument();
+ XBLManager xm = doc.getXBLManager();
+ if (xm instanceof DefaultXBLManager) {
+ DefaultMutableTreeNode selectedContentNode
+ = new DefaultMutableTreeNode(new ContentNodeInfo(node));
+ DefaultXBLManager dxm = (DefaultXBLManager) xm;
+ ContentManager cm = dxm.getContentManager(node);
+ if (cm != null) {
+ NodeList nl
+ = cm.getSelectedContent((XBLOMContentElement) node);
+ for (int i = 0; i < nl.getLength(); i++) {
+ selectedContentNode.add(createTree(nl.item(i),
+ showWhitespace));
+ }
+ result.add(selectedContentNode);
+ }
+ }
+ }
return result;
}
@@ -693,10 +736,49 @@
if (node instanceof Element) {
String id = ((Element)node).getAttribute("id");
if (id.length() != 0) {
- return node.getNodeName() + " \""+id+"\"";
+ return node.getNodeName() + " \"" + id + "\"";
}
}
return node.getNodeName();
+ }
+ }
+
+ /**
+ * To store the node information for a shadow tree.
+ */
+ protected static class ShadowNodeInfo extends NodeInfo {
+ /**
+ * Creates a new ShadowNodeInfo object.
+ */
+ public ShadowNodeInfo(Node n) {
+ super(n);
+ }
+
+ /**
+ * Returns a printable representation of the object.
+ */
+ public String toString() {
+ return "shadow tree";
+ }
+ }
+
+ /**
+ * To store the node information for an xbl:content node's
+ * selected content.
+ */
+ protected static class ContentNodeInfo extends NodeInfo {
+ /**
+ * Creates a new ContentNodeInfo object.
+ */
+ public ContentNodeInfo(Node n) {
+ super(n);
+ }
+
+ /**
+ * Returns a printable representation of the object.
+ */
+ public String toString() {
+ return "selected content";
}
}
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/resource/MenuFactory.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/resource/MenuFactory.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/resource/MenuFactory.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/resource/MenuFactory.java Tue Sep 13 06:29:29 2005
@@ -17,8 +17,6 @@
*/
package org.apache.batik.util.gui.resource;
-import java.awt.Event;
-import java.awt.event.KeyEvent;
import java.net.URL;
import java.util.Iterator;
import java.util.List;