@Override public void gvtRenderingStarted(final GVTTreeRendererEvent e) { super.gvtRenderingStarted(e); final SVGDocument document = getSVGDocument(); final SVGSVGElement rootElement = document.getRootElement(); final SVGLength width = rootElement.getWidth().getBaseVal(); final SVGLength height = rootElement.getHeight().getBaseVal(); float defaultWidth = (float) Math.ceil(width.getValue()); float defaultHeigth = (float) Math.ceil(height.getValue()); if (defaultWidth == 1f && defaultHeigth == 1f) { defaultWidth = ResourceController.getResourceController().getIntProperty( "default_external_component_width", 200); defaultHeigth = ResourceController.getResourceController().getIntProperty( "default_external_component_height", 200); } originalSize = new Dimension((int) defaultWidth, (int) defaultHeigth); if ("".equals(rootElement.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE))) { rootElement.setAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + defaultWidth + " " + defaultHeigth); } removeGVTTreeRendererListener(this); }
public void run() { getSVGRootElement().setCurrentTime(m_currentTime); } });
if (svgElement.getAttributeNode("width") != null && svgElement.getAttribute("height") != null) { new BridgeContext(userAgent), svgElement); float width = svgLengthInPixels(svgElement.getWidth().getBaseVal(), context); float height = svgLengthInPixels(svgElement.getHeight().getBaseVal(), context); float x = 0; float y = 0; if (svgElement.getX() != null && svgElement.getX().getBaseVal() != null) { x = svgLengthInPixels(svgElement.getX().getBaseVal(), context); if (svgElement.getY() != null && svgElement.getY().getBaseVal() != null) { y = svgLengthInPixels(svgElement.getY().getBaseVal(), context);
protected Rectangle2D getViewBoxRect() { SVGDocument doc = canvas.getSVGDocument(); if (doc == null) return null; SVGSVGElement el = doc.getRootElement(); if (el == null) return null; String viewBoxStr = el.getAttributeNS (null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (viewBoxStr.length() != 0) { float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr, null); return new Rectangle2D.Float(rect[0], rect[1], rect[2], rect[3]); } GraphicsNode gn = canvas.getGraphicsNode(); if (gn == null) return null; Rectangle2D bounds = gn.getBounds(); if (bounds == null) return null; return (Rectangle2D) bounds.clone(); }
/** * Returns the default Interpreter for this document. */ public Interpreter getInterpreter() { if (interpreter != null) return interpreter; SVGSVGElement root = (SVGSVGElement)document.getDocumentElement(); String lang = root.getContentScriptType(); return getInterpreter(lang); }
/** * Convert the coordinates of an DOM Event from screen into element * coordinates. * * @param doc Document context * @param tag Element containing the coordinate system * @param evt Event to interpret * @return coordinates */ public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) { try { DOMMouseEvent gnme = (DOMMouseEvent) evt; SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM(); SVGMatrix imat = mat.inverse(); SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint(); cPt.setX(gnme.getClientX()); cPt.setY(gnme.getClientY()); return cPt.matrixTransform(imat); } catch(Exception e) { LoggingUtil.warning("Error getting coordinates from SVG event.", e); return null; } }
public void handleEvent(Event evt) { if (!(evt.getTarget() instanceof SVGSVGElement)) return; // assert(evt.getType() == // SVGConstants.SVG_SVGZOOM_EVENT_TYPE); SVGSVGElement svg = (SVGSVGElement) evt.getTarget(); scaleChange(svg.getCurrentScale()); } // handleEvent() }, false, null);
void initialize() { m_svgImage = m_sceneMgr.getSVGImage(); m_svgDoc = (DocumentNode) m_svgImage.getDocument(); m_animator = (SVGAnimatorImpl) SVGAnimator.createAnimator( m_svgImage, "javax.swing.JComponent"); //NOI18N m_animationState = containsAnimation(m_svgDoc) ? ANIMATION_NOT_RUNNING : ANIMATION_NOT_AVAILABLE; SVGSVGElement svg = getSVGRootElement(); SVGRect rect = svg.getRectTrait(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (rect != null) { m_viewBoxMarker = (SVGLocatableElement) m_svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_RECT_TAG); m_viewBoxMarker.setId(ID_VIEWBOX_MARKER); m_viewBoxMarker.setTrait(SVGConstants.SVG_FILL_ATTRIBUTE, "none"); //NOI18N m_viewBoxMarker.setTrait(SVGConstants.SVG_STROKE_ATTRIBUTE, "none"); //NOI18N m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_X_ATTRIBUTE, rect.getX()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_Y_ATTRIBUTE, rect.getY()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_WIDTH_ATTRIBUTE, rect.getWidth()); m_viewBoxMarker.setFloatTrait(SVGConstants.SVG_HEIGHT_ATTRIBUTE, rect.getHeight()); svg.appendChild(m_viewBoxMarker); } else { m_viewBoxMarker = null; } // we need to get the animator into the 'paused' state so that // all changes are immediately visible m_animator.play(); m_animator.pause(); SceneManager.log(Level.INFO, toString() + " initialized."); //NOI18N }
private void outputMessage(final String message) { SVGSVGElement svgElement = getSVGDocument().getRootElement(); String[] parts = message.split("\n"); int initialPosition = 200; for (int i = 0; i < parts.length; i++) { Text errorsText = createText(parts[i]); SVGOMTextElement error = (SVGOMTextElement) createElement(SVGConstants.SVG_TEXT_TAG); error.setAttribute(SVGConstants.SVG_Y_ATTRIBUTE, Integer.toString(initialPosition + i * 60)); error.setAttribute(SVGConstants.SVG_FONT_SIZE_ATTRIBUTE, "20"); error.setAttribute(SVGConstants.SVG_FONT_FAMILY_ATTRIBUTE, "sans-serif"); error.setAttribute(SVGConstants.SVG_FILL_ATTRIBUTE, "red"); error.appendChild(errorsText); svgElement.appendChild(error); } bounds = new Rectangle(300, parts.length * 60 + 200); svgCanvas.setDocument(getSVGDocument()); }
svgDocument.getRootElement().getAttribute("viewBox"), bridgeContext);
protected Rectangle2D getViewBoxRect() { SVGDocument doc = canvas.getSVGDocument(); if (doc == null) return null; SVGSVGElement el = doc.getRootElement(); if (el == null) return null; String viewBoxStr = el.getAttributeNS (null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (viewBoxStr.length() != 0) { float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr, null); return new Rectangle2D.Float(rect[0], rect[1], rect[2], rect[3]); } GraphicsNode gn = canvas.getGraphicsNode(); if (gn == null) return null; Rectangle2D bounds = gn.getBounds(); if (bounds == null) return null; return (Rectangle2D) bounds.clone(); }
/** * Returns the default Interpreter for this document. */ public Interpreter getInterpreter() { if (interpreter != null) return interpreter; SVGSVGElement root = (SVGSVGElement)document.getDocumentElement(); String lang = root.getContentScriptType(); return getInterpreter(lang); }
/** * Convert the coordinates of an DOM Event from screen into element * coordinates. * * @param doc Document context * @param tag Element containing the coordinate system * @param evt Event to interpret * @return coordinates */ public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) { try { DOMMouseEvent gnme = (DOMMouseEvent) evt; SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM(); SVGMatrix imat = mat.inverse(); SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint(); cPt.setX(gnme.getClientX()); cPt.setY(gnme.getClientY()); return cPt.matrixTransform(imat); } catch(Exception e) { LoggingUtil.warning("Error getting coordinates from SVG event.", e); return null; } }
public void handleEvent(Event evt) { if (!(evt.getTarget() instanceof SVGSVGElement)) return; // assert(evt.getType() == // SVGConstants.SVG_SVGZOOM_EVENT_TYPE); SVGSVGElement svg = (SVGSVGElement) evt.getTarget(); scaleChange(svg.getCurrentScale()); } // handleEvent() }, false, null);
private void layoutSVGDocument(Rectangle bounds) { animateBounds = SVGUtil.createAnimationElement(this, SVGConstants.SVG_ANIMATE_TAG, SVGConstants.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; }
protected Rectangle2D getViewBoxRect() { SVGDocument doc = canvas.getSVGDocument(); if (doc == null) return null; SVGSVGElement el = doc.getRootElement(); if (el == null) return null; String viewBoxStr = el.getAttributeNS (null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (viewBoxStr.length() != 0) { float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr, null); return new Rectangle2D.Float(rect[0], rect[1], rect[2], rect[3]); } GraphicsNode gn = canvas.getGraphicsNode(); if (gn == null) return null; Rectangle2D bounds = gn.getBounds(); if (bounds == null) return null; return (Rectangle2D) bounds.clone(); }
if (svgElement.getAttributeNode("width") != null && svgElement.getAttribute("height") != null) { new BridgeContext(userAgent), svgElement); float width = svgLengthInPixels(svgElement.getWidth().getBaseVal(), context); float height = svgLengthInPixels(svgElement.getHeight().getBaseVal(), context); float x = 0; float y = 0; if (svgElement.getX() != null && svgElement.getX().getBaseVal() != null) { x = svgLengthInPixels(svgElement.getX().getBaseVal(), context); if (svgElement.getY() != null && svgElement.getY().getBaseVal() != null) { y = svgLengthInPixels(svgElement.getY().getBaseVal(), context);
/** * Returns the default Interpreter for this document. */ public Interpreter getInterpreter() { if (interpreter != null) return interpreter; SVGSVGElement root = (SVGSVGElement)document.getDocumentElement(); String lang = root.getContentScriptType(); return getInterpreter(lang); }
/** * 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; }