1 18 package org.apache.batik.bridge; 19 20 import java.awt.Cursor ; 21 22 import org.apache.batik.dom.events.AbstractEvent; 23 import org.apache.batik.dom.util.XLinkSupport; 24 import org.apache.batik.gvt.GraphicsNode; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.events.Event ; 27 import org.w3c.dom.events.EventListener ; 28 import org.w3c.dom.events.EventTarget ; 29 import org.w3c.dom.events.UIEvent ; 30 import org.w3c.dom.svg.SVGAElement; 31 32 38 public class SVGAElementBridge extends SVGGElementBridge { 39 40 43 public SVGAElementBridge() {} 44 45 48 public String getLocalName() { 49 return SVG_A_TAG; 50 } 51 52 55 public Bridge getInstance() { 56 return new SVGAElementBridge(); 57 } 58 59 67 public void buildGraphicsNode(BridgeContext ctx, 68 Element e, 69 GraphicsNode node) { 70 71 super.buildGraphicsNode(ctx, e, node); 72 73 if (ctx.isInteractive()) { 74 EventTarget target = (EventTarget )e; 75 EventListener l = new AnchorListener(ctx.getUserAgent()); 76 target.addEventListener(SVG_EVENT_CLICK, l, false); 77 ctx.storeEventListener(target, SVG_EVENT_CLICK, l, false); 78 79 l = new CursorMouseOverListener(ctx.getUserAgent()); 80 target.addEventListener(SVG_EVENT_MOUSEOVER, l, false); 81 ctx.storeEventListener(target, SVG_EVENT_MOUSEOVER, l, false); 82 83 l = new CursorMouseOutListener(ctx.getUserAgent()); 84 target.addEventListener(SVG_EVENT_MOUSEOUT, l, false); 85 ctx.storeEventListener(target, SVG_EVENT_MOUSEOUT, l, false); 86 } 87 } 88 89 92 public boolean isComposite() { 93 return true; 94 } 95 96 99 public static class AnchorListener implements EventListener { 100 101 protected UserAgent userAgent; 102 103 public AnchorListener(UserAgent ua) { 104 userAgent = ua; 105 } 106 107 public void handleEvent(Event evt) { 108 if (AbstractEvent.getEventPreventDefault(evt)) 109 return; 110 SVGAElement elt = (SVGAElement)evt.getCurrentTarget(); 111 Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); 112 userAgent.setSVGCursor(cursor); 113 userAgent.openLink(elt); 114 evt.stopPropagation(); 115 } 116 } 117 118 121 public static class CursorMouseOverListener implements EventListener { 122 123 protected UserAgent userAgent; 124 125 public CursorMouseOverListener(UserAgent ua) { 126 userAgent = ua; 127 } 128 129 public void handleEvent(Event evt) { 130 if (AbstractEvent.getEventPreventDefault(evt)) 131 return; 132 Element target = (Element )evt.getTarget(); 151 152 if (CSSUtilities.isAutoCursor(target)) { 153 userAgent.setSVGCursor(CursorManager.ANCHOR_CURSOR); 155 } 156 157 161 SVGAElement elt = (SVGAElement)evt.getCurrentTarget(); 162 if (elt != null) { 163 String href = XLinkSupport.getXLinkHref(elt); 164 userAgent.displayMessage(href); 165 } 166 } 167 } 168 169 172 public static class CursorMouseOutListener implements EventListener { 173 174 protected UserAgent userAgent; 175 176 public CursorMouseOutListener(UserAgent ua) { 177 userAgent = ua; 178 } 179 180 public void handleEvent(Event evt) { 181 if (AbstractEvent.getEventPreventDefault(evt)) 182 return; 183 186 SVGAElement elt = (SVGAElement)evt.getCurrentTarget(); 188 if (elt != null) { 189 userAgent.displayMessage(""); 190 } 191 } 192 } 193 } 194 | Popular Tags |