vhardy 01/08/03 09:33:43
Modified: sources/org/apache/batik/apps/svgbrowser
JSVGViewerFrame.java
sources/org/apache/batik/bridge
AbstractGraphicsNodeBridge.java
SVGAElementBridge.java SVGBridgeExtension.java
SVGTextElementBridge.java SVGUtilities.java
UserAgent.java UserAgentAdapter.java
sources/org/apache/batik/swing JSVGCanvas.java
sources/org/apache/batik/swing/svg JSVGComponent.java
SVGUserAgent.java
sources/org/apache/batik/transcoder/image
ImageTranscoder.java
sources/org/apache/batik/transcoder/print
PrintTranscoder.java
sources/org/apache/batik/util SVGConstants.java
Added: sources/org/apache/batik/bridge GenericBridge.java
SVGDescElementBridge.java
SVGTitleElementBridge.java
sources/org/apache/batik/swing Messages.java
resources/org/apache/batik/swing/resources
Messages.properties
Log:
Added initial support for <title> and <desc> on all graphical elements.
Now, when the mouse lingers on an element with a <title> or a <desc>,
the content of <title> or <desc> (or both) is shown to the user in
a tooltip. The behavior is in JSVGCanvas.
The samples/tests/toolTips.svg test case illustrates the feature.
Note that this work uncovered an issue with event propagation on
image as illustrated in toolTips.svg and anchor.svg. I am entering
a bug against that problem.
Revision Changes Path
1.46 +6 -1
xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
Index: JSVGViewerFrame.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- JSVGViewerFrame.java 2001/07/18 22:04:53 1.45
+++ JSVGViewerFrame.java 2001/08/03 16:33:42 1.46
@@ -126,6 +126,8 @@
import org.apache.batik.xml.XMLUtilities;
+import org.w3c.dom.Element;
+
import org.w3c.dom.css.ViewCSS;
import org.w3c.dom.svg.SVGDocument;
@@ -134,7 +136,7 @@
* This class represents a SVG viewer swing frame.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: JSVGViewerFrame.java,v 1.45 2001/07/18 22:04:53 deweese Exp $
+ * @version $Id: JSVGViewerFrame.java,v 1.46 2001/08/03 16:33:42 vhardy Exp $
*/
public class JSVGViewerFrame
extends JFrame
@@ -1684,6 +1686,9 @@
*/
public boolean supportExtension(String s) {
return false;
+ }
+
+ public void handleElement(Element elt, Object data){
}
}
}
1.4 +3 -1
xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
Index: AbstractGraphicsNodeBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractGraphicsNodeBridge.java 2001/05/02 14:33:31 1.3
+++ AbstractGraphicsNodeBridge.java 2001/08/03 16:33:42 1.4
@@ -35,7 +35,7 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: AbstractGraphicsNodeBridge.java,v 1.3 2001/05/02 14:33:31 tkormann
Exp $
+ * @version $Id: AbstractGraphicsNodeBridge.java,v 1.4 2001/08/03 16:33:42 vhardy
Exp $
*/
public abstract class AbstractGraphicsNodeBridge extends AbstractSVGBridge
implements GraphicsNodeBridge, ErrorConstants {
@@ -96,6 +96,8 @@
ctx.bind(e, node);
BridgeEventSupport.addDOMListener(ctx, e);
}
+
+ SVGUtilities.bridgeChildren(ctx, e);
}
/**
1.9 +6 -5 xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java
Index: SVGAElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SVGAElementBridge.java 2001/05/02 14:33:34 1.8
+++ SVGAElementBridge.java 2001/08/03 16:33:42 1.9
@@ -24,7 +24,7 @@
* Bridge class for the <a> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGAElementBridge.java,v 1.8 2001/05/02 14:33:34 tkormann Exp $
+ * @version $Id: SVGAElementBridge.java,v 1.9 2001/08/03 16:33:42 vhardy Exp $
*/
public class SVGAElementBridge extends AbstractGraphicsNodeBridge {
@@ -63,17 +63,18 @@
EventTarget target = (EventTarget)e;
- target.addEventListener("click",
+ target.addEventListener(SVG_EVENT_CLICK,
new AnchorListener(ctx.getUserAgent()),
false);
- target.addEventListener("mouseover",
+ target.addEventListener(SVG_EVENT_MOUSEOVER,
new CursorMouseOverListener(ctx.getUserAgent()),
false);
- target.addEventListener("mouseout",
+ target.addEventListener(SVG_EVENT_MOUSEOUT,
new CursorMouseOutListener(ctx.getUserAgent()),
- false); }
+ false);
+ }
/**
* Returns true as the <a> element is a container.
1.5 +2 -0
xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java
Index: SVGBridgeExtension.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGBridgeExtension.java 2001/07/05 06:56:07 1.4
+++ SVGBridgeExtension.java 2001/08/03 16:33:42 1.5
@@ -83,6 +83,7 @@
ctx.putBridge(new SVGCircleElementBridge());
ctx.putBridge(new SVGClipPathElementBridge());
ctx.putBridge(new SVGColorProfileElementBridge());
+ ctx.putBridge(new SVGDescElementBridge());
ctx.putBridge(new SVGEllipseElementBridge());
ctx.putBridge(new SVGFeBlendElementBridge());
ctx.putBridge(new SVGFeColorMatrixElementBridge());
@@ -131,6 +132,7 @@
ctx.putBridge(new SVGSwitchElementBridge());
ctx.putBridge(new SVGTextElementBridge());
ctx.putBridge(new SVGTextPathElementBridge());
+ ctx.putBridge(new SVGTitleElementBridge());
ctx.putBridge(new SVGUseElementBridge());
ctx.putBridge(new SVGVKernElementBridge());
1.34 +4 -1
xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java
Index: SVGTextElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- SVGTextElementBridge.java 2001/08/02 13:01:31 1.33
+++ SVGTextElementBridge.java 2001/08/03 16:33:42 1.34
@@ -57,7 +57,7 @@
* Bridge class for the <text> element.
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: SVGTextElementBridge.java,v 1.33 2001/08/02 13:01:31 tkormann Exp $
+ * @version $Id: SVGTextElementBridge.java,v 1.34 2001/08/03 16:33:42 vhardy Exp $
*/
public class SVGTextElementBridge extends AbstractSVGBridge
implements GraphicsNodeBridge, ErrorConstants {
@@ -172,6 +172,9 @@
if (ctx.isDynamic()) {
ctx.bind(e, node);
}
+
+ // Handle children elements such as <title>
+ SVGUtilities.bridgeChildren(ctx, e);
}
/**
1.14 +28 -1 xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java
Index: SVGUtilities.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SVGUtilities.java 2001/05/16 11:47:15 1.13
+++ SVGUtilities.java 2001/08/03 16:33:42 1.14
@@ -51,7 +51,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGUtilities.java,v 1.13 2001/05/16 11:47:15 hillion Exp $
+ * @version $Id: SVGUtilities.java,v 1.14 2001/08/03 16:33:42 vhardy Exp $
*/
public abstract class SVGUtilities implements SVGConstants, ErrorConstants {
@@ -875,6 +875,33 @@
r.getHeight() * bounds.getHeight());
} else {
return new Rectangle2D.Double();
+ }
+ }
+
+ /**
+ * Scans the children of the input <tt>e</tt> element and
+ * invokes any registered bridge found for the children.
+ *
+ * @param ctx active BridgeContext
+ * @param e element to be scanned
+ */
+ public static void bridgeChildren(BridgeContext ctx,
+ Element elt){
+ for (Node n = elt.getFirstChild();
+ n != null;
+ n = n.getNextSibling()) {
+
+ if ((n.getNodeType() != Node.ELEMENT_NODE)) {
+ continue;
+ }
+
+ Element e = (Element)n;
+ Bridge bridge = ctx.getBridge(e);
+ if (bridge == null || !(bridge instanceof GenericBridge)) {
+ continue;
+ }
+
+ ((GenericBridge)bridge).handleElement(ctx, e);
}
}
}
1.16 +10 -1 xml-batik/sources/org/apache/batik/bridge/UserAgent.java
Index: UserAgent.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UserAgent.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- UserAgent.java 2001/07/30 12:30:28 1.15
+++ UserAgent.java 2001/08/03 16:33:42 1.16
@@ -24,7 +24,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: UserAgent.java,v 1.15 2001/07/30 12:30:28 tkormann Exp $
+ * @version $Id: UserAgent.java,v 1.16 2001/08/03 16:33:42 vhardy Exp $
*/
public interface UserAgent {
@@ -111,4 +111,13 @@
* extension is supported by the bridge.
*/
public void registerExtension(BridgeExtension ext);
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ public void handleElement(Element elt, Object data);
}
1.3 +23 -7 xml-batik/sources/org/apache/batik/bridge/UserAgentAdapter.java
Index: UserAgentAdapter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UserAgentAdapter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UserAgentAdapter.java 2001/05/31 21:10:24 1.2
+++ UserAgentAdapter.java 2001/08/03 16:33:42 1.3
@@ -22,11 +22,16 @@
import org.apache.batik.util.SVGConstants;
import org.apache.batik.util.XMLResourceDescriptor;
+import org.w3c.dom.Element;
+
import org.w3c.dom.svg.SVGAElement;
/**
* An abstract user agent adaptor implementation. It exists to simply
* the creation of UserAgent instances.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a>
+ * @version $Id: UserAgentAdapter.java,v 1.3 2001/08/03 16:33:42 vhardy Exp $
*/
public class UserAgentAdapter implements UserAgent {
protected Set FEATURES = new HashSet();
@@ -142,22 +147,33 @@
protected Set extensions = new HashSet();
- /**
- * Tells whether the given extension is supported by this
- * user agent.
- */
+ /**
+ * Tells whether the given extension is supported by this
+ * user agent.
+ */
public boolean supportExtension(String s) {
return extensions.contains(s);
}
/**
- * Lets the bridge tell the user agent that the following
- * ex tension is supported by the bridge.
- */
+ * Lets the bridge tell the user agent that the following
+ * ex tension is supported by the bridge.
+ */
public void registerExtension(BridgeExtension ext) {
Iterator i = ext.getImplementedExtensions();
while (i.hasNext())
extensions.add(i.next());
+ }
+
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ public void handleElement(Element elt, Object data){
}
}
1.1 xml-batik/sources/org/apache/batik/bridge/GenericBridge.java
Index: GenericBridge.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.bridge;
import org.w3c.dom.Element;
/**
* A tagging interface that bridges for elements child of <tt>GraphicsNodeBridge</tt>
* should implement.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
* @version $Id: GenericBridge.java,v 1.1 2001/08/03 16:33:42 vhardy Exp $
*/
public interface GenericBridge extends Bridge {
/**
* Invoked to handle an <tt>Element</tt> for a given <tt>BridgeContext</tt>.
* For example, see the <tt>SVGTitleElementBridge</tt>.
*
* @param ctx the bridge context to use
* @param e the element that describes the graphics node to build
*/
void handleElement(BridgeContext ctx, Element e);
}
1.1
xml-batik/sources/org/apache/batik/bridge/SVGDescElementBridge.java
Index: SVGDescElementBridge.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.bridge;
import org.w3c.dom.Element;
/**
* Bridge class for the <desc> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
* @version $Id: SVGDescElementBridge.java,v 1.1 2001/08/03 16:33:42 vhardy Exp $
*/
public class SVGDescElementBridge extends AbstractSVGBridge implements GenericBridge
{
/**
* Constructs a new bridge for the <desc> element.
*/
public SVGDescElementBridge() {}
/**
* Returns 'desc'.
*/
public String getLocalName() {
return SVG_DESC_TAG;
}
/**
* Invoked to handle an <tt>Element</tt> for a given <tt>BridgeContext</tt>.
* For example, see the <tt>SVGDescElementBridge</tt>.
*
* @param ctx the bridge context to use
* @param e the element that describes the graphics node to build
*/
public void handleElement(BridgeContext ctx, Element e){
UserAgent ua = ctx.getUserAgent();
ua.handleElement(e, null);
}
}
1.1
xml-batik/sources/org/apache/batik/bridge/SVGTitleElementBridge.java
Index: SVGTitleElementBridge.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.bridge;
import org.w3c.dom.Element;
/**
* Bridge class for the <title> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
* @version $Id: SVGTitleElementBridge.java,v 1.1 2001/08/03 16:33:42 vhardy Exp $
*/
public class SVGTitleElementBridge extends AbstractSVGBridge implements
GenericBridge {
/**
* Constructs a new bridge for the <title> element.
*/
public SVGTitleElementBridge() {}
/**
* Returns 'title'.
*/
public String getLocalName() {
return SVG_TITLE_TAG;
}
/**
* Invoked to handle an <tt>Element</tt> for a given <tt>BridgeContext</tt>.
* For example, see the <tt>SVGTitleElementBridge</tt>.
*
* @param ctx the bridge context to use
* @param e the element that describes the graphics node to build
*/
public void handleElement(BridgeContext ctx, Element e){
UserAgent ua = ctx.getUserAgent();
ua.handleElement(e, null);
}
}
1.24 +267 -1 xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java
Index: JSVGCanvas.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- JSVGCanvas.java 2001/07/25 15:15:51 1.23
+++ JSVGCanvas.java 2001/08/03 16:33:42 1.24
@@ -12,6 +12,7 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -19,6 +20,10 @@
import java.util.List;
+import javax.swing.ToolTipManager;
+
+import org.apache.batik.bridge.UserAgent;
+
import org.apache.batik.swing.gvt.Interactor;
import org.apache.batik.swing.gvt.AbstractImageZoomInteractor;
import org.apache.batik.swing.gvt.AbstractPanInteractor;
@@ -28,6 +33,16 @@
import org.apache.batik.swing.svg.JSVGComponent;
import org.apache.batik.swing.svg.SVGUserAgent;
+import org.apache.batik.util.SVGConstants;
+import org.apache.batik.util.XMLConstants;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventListener;
+import org.w3c.dom.events.EventTarget;
+
/**
* This class represents a general-purpose swing SVG component. The
* <tt>JSVGCanvas</tt> does not provided additional functionalities compared to
@@ -38,7 +53,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: JSVGCanvas.java,v 1.23 2001/07/25 15:15:51 tkormann Exp $
+ * @version $Id: JSVGCanvas.java,v 1.24 2001/08/03 16:33:42 vhardy Exp $
*/
public class JSVGCanvas extends JSVGComponent {
@@ -359,4 +374,255 @@
loadSVGDocument(uri);
pcs.firePropertyChange("URI", oldValue, uri);
}
+
+ /**
+ * Creates a UserAgent.
+ */
+ protected UserAgent createUserAgent() {
+ return new CanvasUserAgent();
+ }
+
+ /**
+ * Helper class. Simply keeps track of the last known mouse
+ * position over the canvas.
+ */
+ protected class LocationListener extends MouseMotionAdapter {
+ protected int lastX, lastY;
+ public void mouseMoved(MouseEvent evt){
+ lastX = evt.getX();
+ lastY = evt.getY();
+ }
+
+ public int getLastX(){ return lastX; }
+ public int getLastY(){ return lastY; }
+ }
+
+ /**
+ * Keeps track of the last known mouse position over the canvas.
+ * This is used for displaying tooltips at the right location.
+ */
+ protected LocationListener locationListener = null;
+
+ /**
+ * The <tt>CanvasUserAgent</tt> only adds tooltips to the behavior
+ * of the default <tt>BridgeUserAgent</tt>.<br />
+ * A tooltip will be displayed wheneven the mouse lingers over
+ * an element which has a <title> or a <desc> child
+ * element.
+ */
+ protected class CanvasUserAgent extends BridgeUserAgent implements XMLConstants{
+ final String TOOLTIP_TITLE_ONLY =
"JSVGCanvas.CanvasUserAgent.ToolTip.titleOnly";
+ final String TOOLTIP_DESC_ONLY =
"JSVGCanvas.CanvasUserAgent.ToolTip.titleOnly";
+ final String TOOLTIP_TITLE_AND_TEXT =
"JSVGCanvas.CanvasUserAgent.ToolTip.titleAndDesc";
+
+ /**
+ * The handleElement method builds a tool tip from the
+ * content of a <title> element, a <desc>
+ * element or both. <br/>
+ * Because these elements can appear in any order, here
+ * is the algorithm used to build the tool tip:<br />
+ * <ul>
+ * <li>If a <title> is passed to <tt>handleElement</tt>
+ * the method checks if there is a >desc> peer. If there
+ * is one, nothing is done. If there in none, the tool tip
+ * is set to the value of the <title> element content.</li>
+ * <li>If a <desc> is passed to <tt>handleElement</tt>
+ * the method checks if there is a <title> peer. If there
+ * is one, the content of that peer is pre-pended to the
+ * content of the <desc> element.</li>
+ * </ul>
+ */
+ public void handleElement(Element elt, Object data){
+ super.handleElement(elt, data);
+
+ if (elt.getNamespaceURI().equals(SVGConstants.SVG_NAMESPACE_URI)) {
+ if (elt.getLocalName().equals(SVGConstants.SVG_TITLE_TAG)) {
+ //
+ // If there is a <desc> peer, do nothing as the tooltip
+ // will be handled when handleElement is invoked for
+ // the <desc> peer.
+ //
+ if (hasPeerWithTag(elt,
+ SVGConstants.SVG_NAMESPACE_URI,
+ SVGConstants.SVG_DESC_TAG)){
+ return;
+ }
+
+ elt.normalize();
+ String toolTip = elt.getFirstChild().getNodeValue();
+ toolTip = Messages.formatMessage(TOOLTIP_TITLE_ONLY,
+ new
Object[]{toFormattedHTML(toolTip)});
+
+ setToolTip((Element)(elt.getParentNode()), toolTip);
+ }
+ else if (elt.getLocalName().equals(SVGConstants.SVG_DESC_TAG)) {
+ //
+ // If there is a <title> peer, prepend its content to
+ // the content of the <desc> element.
+ //
+ elt.normalize();
+ String toolTip = elt.getFirstChild().getNodeValue();
+
+ Element titlePeer = getPeerWithTag(elt,
+
SVGConstants.SVG_NAMESPACE_URI,
+ SVGConstants.SVG_TITLE_TAG);
+
+ if (titlePeer != null) {
+ titlePeer.normalize();
+ toolTip = Messages.formatMessage
+ (TOOLTIP_TITLE_AND_TEXT,
+ new
Object[]{toFormattedHTML(titlePeer.getFirstChild().getNodeValue()),
+ toFormattedHTML(toolTip)});
+ }
+ else{
+ toolTip = Messages.formatMessage(TOOLTIP_DESC_ONLY,
+ new
Object[]{toFormattedHTML(toolTip)});
+ }
+
+ setToolTip((Element)(elt.getParentNode()), toolTip);
+ }
+ }
+ }
+
+ /**
+ * Converts line breaks to HTML breaks and encodes
+ * special entities.
+ * Poor way of replacing '<', '>', '"', '&' and '''
+ * in attribute values.
+ */
+ public String toFormattedHTML(String str){
+ StringBuffer sb = new StringBuffer(str);
+ replace(sb, XML_CHAR_AMP, XML_ENTITY_AMP);
+ replace(sb, XML_CHAR_LT, XML_ENTITY_LT);
+ replace(sb, XML_CHAR_GT, XML_ENTITY_GT);
+ replace(sb, XML_CHAR_QUOT, XML_ENTITY_QUOT);
+ replace(sb, XML_CHAR_APOS, XML_ENTITY_APOS);
+ replace(sb, '\n', "<br>");
+ return sb.toString();
+ }
+
+ protected void replace(StringBuffer s,
+ char c,
+ String r){
+ String v = s.toString() + 1;
+ int i = v.length();
+
+ while( (i=v.lastIndexOf(c, --i)) != -1 ){
+ s.deleteCharAt(i);
+ s.insert(i, r);
+ }
+ }
+
+ /**
+ * Checks if there is a peer element of a given type.
+ * This returns the first occurence of the given type
+ * or null if none is found.
+ */
+ public Element getPeerWithTag(Element elt,
+ String nameSpaceURI,
+ String localName){
+ Element p = (Element)elt.getParentNode();
+ if (p == null) {
+ return null;
+ }
+
+ for (Node n=p.getFirstChild(); n!=null; n=n.getNextSibling()){
+ if (!nameSpaceURI.equals(n.getNamespaceURI())){
+ continue;
+ }
+
+ if (!localName.equals(n.getLocalName())){
+ continue;
+ }
+
+ if (n.getNodeType() == n.ELEMENT_NODE) {
+ return (Element)n;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a boolean defining whether or not there is a
+ * peer of <tt>elt</tt> with the given qualified tag.
+ */
+ public boolean hasPeerWithTag(Element elt,
+ String nameSpaceURI,
+ String localName){
+ if (getPeerWithTag(elt, nameSpaceURI, localName) == null){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+
+ /**
+ * Sets the tool tip on the input element.
+ */
+ public void setToolTip(Element elt, String toolTip){
+ EventTarget target = (EventTarget)elt;
+
+ elt.normalize();
+
+ // On mouseover, set the tooltip to the title value
+ target.addEventListener(SVGConstants.SVG_EVENT_MOUSEOVER,
+ new ToolTipModifier(toolTip),
+ false);
+
+ // On mouseout, remove the tooltip
+ target.addEventListener(SVGConstants.SVG_EVENT_MOUSEOUT,
+ new ToolTipModifier(null),
+ false);
+
+ if (locationListener == null){
+ locationListener = new LocationListener();
+ addMouseMotionListener(locationListener);
+ }
+ }
+ }
+
+ /**
+ * Sets a specific tooltip on the JSVGCanvas when a given event
+ * occurs. This listener is used in the handleElement method
+ * to set, remove or modify the JSVGCanvas tooltip on mouseover
+ * and on mouseout.<br/>
+ * Because we are on a single <tt>JComponent</tt> we trigger an
+ * artificial <tt>MouseEvent</tt> when the toolTip is set to
+ * a non-null value, so as to make sure it will show after the
+ * <tt>ToolTipManager</tt>'s default delay.
+ *
+ */
+ protected class ToolTipModifier implements EventListener {
+ /**
+ * Value of the toolTip
+ */
+ protected String toolTip;
+
+ /**
+ * @param toolTip value to which the JSVGCanvas should be
+ * set when the event occurs.
+ */
+ public ToolTipModifier(String toolTip){
+ this.toolTip = toolTip;
+ }
+
+ public void handleEvent(Event evt){
+ setToolTipText(toolTip);
+
+ if(toolTip != null){
+ MouseEvent e = new MouseEvent(JSVGCanvas.this,
+ MouseEvent.MOUSE_ENTERED,
+ System.currentTimeMillis(),
+ 0,
+ locationListener.getLastX(),
+ locationListener.getLastY(),
+ 0,
+ false);
+ ToolTipManager.sharedInstance().mouseEntered(e);
+ }
+ }
+ }
+
}
1.1 xml-batik/sources/org/apache/batik/swing/Messages.java
Index: Messages.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.swing;
import java.util.Locale;
import java.util.MissingResourceException;
import org.apache.batik.i18n.Localizable;
import org.apache.batik.i18n.LocalizableSupport;
/**
* This class manages the message for the test.svg module.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
* @version $Id: Messages.java,v 1.1 2001/08/03 16:33:42 vhardy Exp $
*/
public class Messages {
/**
* This class does not need to be instantiated.
*/
protected Messages() { }
/**
* The error messages bundle class name.
*/
protected final static String RESOURCES =
"org.apache.batik.swing.resources.Messages";
/**
* The localizable support for the error messages.
*/
protected static LocalizableSupport localizableSupport =
new LocalizableSupport(RESOURCES);
/**
* Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.
*/
public static void setLocale(Locale l) {
localizableSupport.setLocale(l);
}
/**
* Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.
*/
public static Locale getLocale() {
return localizableSupport.getLocale();
}
/**
* Implements {@link
* org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.
*/
public static String formatMessage(String key, Object[] args)
throws MissingResourceException {
return localizableSupport.formatMessage(key, args);
}
}
1.24 +15 -1 xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java
Index: JSVGComponent.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- JSVGComponent.java 2001/07/31 14:52:18 1.23
+++ JSVGComponent.java 2001/08/03 16:33:42 1.24
@@ -152,7 +152,7 @@
* building/rendering a document (invalid XML file, missing attributes...).</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: JSVGComponent.java,v 1.23 2001/07/31 14:52:18 hillion Exp $
+ * @version $Id: JSVGComponent.java,v 1.24 2001/08/03 16:33:42 vhardy Exp $
*/
public class JSVGComponent extends JGVTComponent {
@@ -960,6 +960,20 @@
Iterator i = ext.getImplementedExtensions();
while (i.hasNext())
extensions.put(i.next(), ext);
+ }
+
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ public void handleElement(Element elt, Object data) {
+ if (svgUserAgent != null) {
+ svgUserAgent.handleElement(elt, data);
+ }
}
}
1.4 +12 -1 xml-batik/sources/org/apache/batik/swing/svg/SVGUserAgent.java
Index: SVGUserAgent.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/SVGUserAgent.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SVGUserAgent.java 2001/05/18 08:09:55 1.3
+++ SVGUserAgent.java 2001/08/03 16:33:43 1.4
@@ -8,12 +8,14 @@
package org.apache.batik.swing.svg;
+import org.w3c.dom.Element;
+
/**
* This interface must be implemented to provide client services to
* a JSVGComponent.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGUserAgent.java,v 1.3 2001/05/18 08:09:55 hillion Exp $
+ * @version $Id: SVGUserAgent.java,v 1.4 2001/08/03 16:33:43 vhardy Exp $
*/
public interface SVGUserAgent {
@@ -66,4 +68,13 @@
* user agent.
*/
boolean supportExtension(String s);
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ void handleElement(Element elt, Object data);
}
1.27 +12 -1
xml-batik/sources/org/apache/batik/transcoder/image/ImageTranscoder.java
Index: ImageTranscoder.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/transcoder/image/ImageTranscoder.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ImageTranscoder.java 2001/07/30 12:30:28 1.26
+++ ImageTranscoder.java 2001/08/03 16:33:43 1.27
@@ -70,6 +70,7 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGAElement;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;
@@ -102,7 +103,7 @@
* millimeter conversion factor.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: ImageTranscoder.java,v 1.26 2001/07/30 12:30:28 tkormann Exp $
+ * @version $Id: ImageTranscoder.java,v 1.27 2001/08/03 16:33:43 vhardy Exp $
*/
public abstract class ImageTranscoder extends XMLAbstractTranscoder {
@@ -453,6 +454,16 @@
extensions.add(i.next());
}
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ public void handleElement(Element elt, Object data){
+ }
}
protected final static Set FEATURES = new HashSet();
1.13 +12 -1
xml-batik/sources/org/apache/batik/transcoder/print/PrintTranscoder.java
Index: PrintTranscoder.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/transcoder/print/PrintTranscoder.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- PrintTranscoder.java 2001/05/17 12:55:57 1.12
+++ PrintTranscoder.java 2001/08/03 16:33:43 1.13
@@ -84,6 +84,7 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGAElement;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;
@@ -114,7 +115,7 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: PrintTranscoder.java,v 1.12 2001/05/17 12:55:57 tkormann Exp $
+ * @version $Id: PrintTranscoder.java,v 1.13 2001/08/03 16:33:43 vhardy Exp $
*/
public class PrintTranscoder extends XMLAbstractTranscoder
implements Printable {
@@ -914,6 +915,16 @@
Iterator i = ext.getImplementedExtensions();
while (i.hasNext())
extensions.add(i.next());
+ }
+
+ /**
+ * Notifies the UserAgent that the input element
+ * has been found in the document. This is sometimes
+ * called, for example, to handle <a> or
+ * <title> elements in a UserAgent-dependant
+ * way.
+ */
+ public void handleElement(Element elt, Object data){
}
}
1.56 +10 -1 xml-batik/sources/org/apache/batik/util/SVGConstants.java
Index: SVGConstants.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/SVGConstants.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- SVGConstants.java 2001/07/31 06:16:55 1.55
+++ SVGConstants.java 2001/08/03 16:33:43 1.56
@@ -14,7 +14,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
* @author <a href="[EMAIL PROTECTED]">Vincent Hardy</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGConstants.java,v 1.55 2001/07/31 06:16:55 bella Exp $
+ * @version $Id: SVGConstants.java,v 1.56 2001/08/03 16:33:43 vhardy Exp $
*/
public interface SVGConstants extends CSSConstants {
@@ -538,4 +538,13 @@
String PATH_HORIZONTAL_LINE_TO = "H";
String PATH_QUAD_TO = "Q";
String PATH_SMOOTH_QUAD_TO = "T";
+
+ ///////////////////////////////////////////////////////////////////
+ // event constants
+ ///////////////////////////////////////////////////////////////////
+
+ String SVG_EVENT_CLICK = "click";
+ String SVG_EVENT_MOUSEOVER = "mouseover";
+ String SVG_EVENT_MOUSEOUT = "mouseout";
+
}
1.1
xml-batik/resources/org/apache/batik/swing/resources/Messages.properties
Index: Messages.properties
===================================================================
#############################################################################
# Copyright (C) The Apache Software Foundation. All rights reserved. #
#############################################################################
# This software is published under the terms of the Apache Software License #
# version 1.1, a copy of which has been included with this distribution in #
# the LICENSE file. #
#############################################################################
#
# ToolTip formatting
#
JSVGCanvas.CanvasUserAgent.ToolTip.titleOnly = \
<html><body>{0}</body></html>
JSVGCanvas.CanvasUserAgent.ToolTip.descOnly = \
<html><body>{0}</tt></body></html>
JSVGCanvas.CanvasUserAgent.ToolTip.titleAndDesc = \
<html><body><b><i>{0}</b></i><br>{1}</body></html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]