/** * Returns the content of the 'desc' child of the given element. */ public static String getDescription(SVGElement elt) { String result = ""; boolean preserve = false; Node n = elt.getFirstChild(); if (n != null && n.getNodeType() == Node.ELEMENT_NODE) { String name = (n.getPrefix() == null) ? n.getNodeName() : n.getLocalName(); if (name.equals(SVG_DESC_TAG)) { preserve = ((SVGLangSpace)n).getXMLspace().equals (SVG_PRESERVE_VALUE); for (n = n.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.TEXT_NODE) { result += n.getNodeValue(); } } } } return (preserve) ? XMLSupport.preserveXMLSpace(result) : XMLSupport.defaultXMLSpace(result); }
/** * Get the relative coordinates of a point within the coordinate system of a * particular SVG Element. * * @param evt Event, needs to be a DOMMouseEvent * @param reference SVG Element the coordinate system is used of * @return Array containing the X and Y values */ public static double[] getRelativeCoordinates(Event evt, Element reference) { if(evt instanceof DOMMouseEvent && reference instanceof SVGLocatable && reference instanceof SVGElement) { // Get the screen (pixel!) coordinates DOMMouseEvent gnme = (DOMMouseEvent) evt; SVGMatrix mat = ((SVGLocatable) reference).getScreenCTM(); SVGMatrix imat = mat.inverse(); SVGPoint cPt = ((SVGElement) reference).getOwnerSVGElement().createSVGPoint(); cPt.setX(gnme.getClientX()); cPt.setY(gnme.getClientY()); // Have Batik transform the screen (pixel!) coordinates into SVG element // coordinates cPt = cPt.matrixTransform(imat); return new double[] { cPt.getX(), cPt.getY() }; } return null; }
private void layoutSVGDocument(Rectangle bounds) { animateBounds = createAnimationElement(this, SVG_ANIMATE_TAG, SVG_VIEW_BOX_ATTRIBUTE, null); updateManager = null; datalinkMap.clear(); Graph graph = getGraph(); if (graph instanceof SVGGraph) { SVGGraph svgGraph = (SVGGraph) graph; SVGSVGElement svgElement = getSVGDocument().getRootElement(); SVGElement graphElement = svgGraph.getSVGElement(); svgElement.appendChild(graphElement); setBounds(layoutGraph(graph, bounds)); edgeLine = EdgeLine.createAndAdd(getSVGDocument(), this); } drawingDiagram = true; }
@Override public void setGraph(Graph graph) { super.setGraph(graph); if (graph instanceof SVGGraph) { SVGGraph svgGraph = (SVGGraph) graph; final SVGElement graphElement = svgGraph.getSVGElement(); if (isExpanded()) graphController.updateSVGDocument(new Runnable() { @Override public void run() { mainGroup.replaceChild(expandedElement, graphElement); } }); expandedElement = graphElement; } }
public Rectangle2D.Float getBorderScreenPosition() { Rectangle2D.Float rect = getBorder(); SVGElement eleBorder = getElement(SvgElementType.Border); SVGMatrix matrix = ((SVGLocatable) eleBorder).getScreenCTM(); SVGPoint leftTopCoordinatePoint = new SVGOMPoint(rect.x, rect.y); SVGPoint leftTopScreenPoint = leftTopCoordinatePoint .matrixTransform(matrix); SVGPoint rightBottomCoordinatePoint = new SVGOMPoint(rect.x + rect.width, rect.y + rect.height); SVGPoint rightBottomScreenPoint = rightBottomCoordinatePoint .matrixTransform(matrix); Rectangle2D.Float result = new Rectangle2D.Float( leftTopScreenPoint.getX(), leftTopScreenPoint.getY(), rightBottomScreenPoint.getX() - leftTopScreenPoint.getX(), rightBottomScreenPoint.getY() - leftTopScreenPoint.getY()); return result; }
public void invokeScriptEvent(String eventName) { SVGElement eventElement = getElement(SvgElementType.Event); if (eventElement != null) { eventElement.setTextContent(eventName); DocumentEvent de = (DocumentEvent) doc; MutationEvent ev = (MutationEvent) de.createEvent("MutationEvents"); ev.initMutationEvent("DOMCharacterDataModified", true, // canBubbleArg false, // cancelableArg null, // relatedNodeArg null, // prevValueArg null, // newValueArg null, // attrNameArg ev.ADDITION); EventTarget t = (EventTarget) eventElement; t.dispatchEvent(ev); } }
/** * Adds a new fill color to all given elements. * * @param color The replacement color * @param document The document in which to replace the color * @param elementName The name of an XML element for which to replace the color */ private static void changeColorOfElement (final Color color, final SVGDocument document, final String elementName) { final NodeList nodes = document.getElementsByTagName (elementName); for (int i = 0; i < nodes.getLength (); i++) { if (nodes.item (i) instanceof SVGElement) { final SVGElement element = (SVGElement) nodes.item (i); element.setAttribute ("fill", toText (color)); } } }
/** * <b>DOM</b>: Implements {@link * SVGSVGElement#getIntersectionList(SVGRect,SVGElement)}. */ public NodeList getIntersectionList(SVGRect rect, SVGElement referenceElement) { SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); List list = ctx.getIntersectionList(rect, referenceElement); return new ListNodeList(list); }
/** * <b>DOM</b>: Implements {@link * SVGSVGElement#getEnclosureList(SVGRect,SVGElement)}. */ public NodeList getEnclosureList(SVGRect rect, SVGElement referenceElement) { SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); List list = ctx.getEnclosureList(rect, referenceElement); return new ListNodeList(list); }
/** * To implement {@link * org.w3c.dom.svg.SVGLocatable#getNearestViewportElement()}. */ public static SVGElement getNearestViewportElement(Element e) { Element elt = e; while (elt != null) { elt = SVGCSSEngine.getParentCSSStylableElement(elt); if (elt instanceof SVGFitToViewBox) { break; } } return (SVGElement)elt; }
/** * To implement {@link * org.w3c.dom.svg.SVGLocatable#getFarthestViewportElement()}. */ public static SVGElement getFarthestViewportElement(Element elt) { Element rootSVG = elt.getOwnerDocument().getDocumentElement(); if (elt == rootSVG) { return null; } return (SVGElement) rootSVG; }
/** * To implement {@link * org.w3c.dom.svg.SVGLocatable#getTransformToElement(SVGElement)}. */ public static SVGMatrix getTransformToElement(Element elt, SVGElement element) throws SVGException { final SVGOMElement currentElt = (SVGOMElement)elt; final SVGOMElement targetElt = (SVGOMElement)element; return new AbstractSVGMatrix() { protected AffineTransform getAffineTransform() { AffineTransform cat = currentElt.getSVGContext().getGlobalTransform(); if (cat == null) { cat = new AffineTransform(); } AffineTransform tat = targetElt.getSVGContext().getGlobalTransform(); if (tat == null) { tat = new AffineTransform(); } AffineTransform at = new AffineTransform(cat); try { at.preConcatenate(tat.createInverse()); return at; } catch (NoninvertibleTransformException ex) { throw currentElt.createSVGException (SVGException.SVG_MATRIX_NOT_INVERTABLE, "noninvertiblematrix", null); } } }; }
/** * <b>DOM</b>: Implements {@link SVGElement#getViewportElement()}. */ public SVGElement getViewportElement() { for (Element e = CSSEngine.getParentCSSStylableElement(this); e != null; e = CSSEngine.getParentCSSStylableElement(e)) { if (e instanceof SVGFitToViewBox) { return (SVGElement)e; } } return null; }
/** {@inheritDoc} */ public void handleXML(RendererContext context, org.w3c.dom.Document doc, String ns) throws Exception { if (getNamespace().equals(ns)) { if (!(doc instanceof SVGDocument)) { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); doc = DOMUtilities.deepCloneDocument(doc, impl); } SVGSVGElement svg = ((SVGDocument) doc).getRootElement(); SVGDocument targetDoc = (SVGDocument)context.getProperty(SVG_DOCUMENT); SVGElement currentPageG = (SVGElement)context.getProperty(SVG_PAGE_G); Element view = targetDoc.createElementNS(getNamespace(), "svg"); Node newsvg = targetDoc.importNode(svg, true); //view.setAttributeNS(null, "viewBox", "0 0 "); int xpos = ((Integer)context.getProperty(XPOS)).intValue(); int ypos = ((Integer)context.getProperty(YPOS)).intValue(); view.setAttributeNS(null, "x", "" + xpos / 1000f); view.setAttributeNS(null, "y", "" + ypos / 1000f); // this fixes a problem where the xmlns is repeated sometimes Element ele = (Element) newsvg; ele.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns", getNamespace()); if (ele.hasAttributeNS(null, "xmlns")) { ele.removeAttributeNS(null, "xmlns"); } view.appendChild(newsvg); currentPageG.appendChild(view); } }
public SvgTransformBox(Document doc, SVGOMGElement objectElement) { this.doc = doc; this.objectElement = objectElement; borderElement = (SVGOMRectElement) doc .getElementById("transform-border"); leftTopArrow = (SVGElement) doc .getElementById("transform-lefttoparrow"); topArrow = (SVGElement) doc.getElementById("transform-toparrow"); rightTopArrow = (SVGElement) doc .getElementById("transform-righttoparrow"); rightArrow = (SVGElement) doc.getElementById("transform-rightarrow"); rightBottomArrow = (SVGElement) doc .getElementById("transform-rightbottomarrow"); bottomArrow = (SVGElement) doc.getElementById("transform-bottomarrow"); leftBottomArrow = (SVGElement) doc .getElementById("transform-leftbottomarrow"); leftArrow = (SVGElement) doc.getElementById("transform-leftarrow"); rightBottomArrowSelected = false; visible = false; addMouseListener((EventTarget) rightBottomArrow); }
/** * <b>DOM</b>: Implements {@link * org.w3c.dom.svg.SVGLocatable#getTransformToElement(SVGElement)}. */ public SVGMatrix getTransformToElement(SVGElement element) throws SVGException { return SVGLocatableSupport.getTransformToElement(this, element); }
/** * <b>DOM</b>: Implements {@link * SVGSVGElement#checkIntersection(SVGElement,SVGRect)}. */ public boolean checkIntersection(SVGElement element, SVGRect rect) { SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); return ctx.checkIntersection(element, rect); }
/** * <b>DOM</b>: Implements {@link * SVGSVGElement#checkEnclosure(SVGElement,SVGRect)}. */ public boolean checkEnclosure(SVGElement element, SVGRect rect) { SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); return ctx.checkEnclosure(element, rect); }
/** * <b>DOM</b>: Implements {@link SVGAnimationElement#getTargetElement()}. */ public SVGElement getTargetElement() { return ((SVGAnimationContext) getSVGContext()).getTargetElement(); }