Java Examples for org.vectomatic.dom.svg.OMSVGDocument

The following java examples will help you to understand the usage of org.vectomatic.dom.svg.OMSVGDocument. These source code samples are taken from different open source projects.

Example 1
Project: svgreal-master  File: SVGModel.java View source code
private void createViewBox(OMSVGRect viewBoxRect) {
    OMSVGDocument document = (OMSVGDocument) svg.getOwnerDocument();
    OMSVGRectElement rect = document.createSVGRectElement(viewBoxRect);
    rect.getStyle().setSVGProperty(SVGConstants.CSS_FILL_PROPERTY, SVGConstants.CSS_NONE_VALUE);
    rect.getStyle().setSVGProperty(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_BLACK_VALUE);
    rect.getStyle().setSVGProperty(SVGConstants.CSS_STROKE_DASHARRAY_PROPERTY, "4, 2");
    rect.setAttribute(ATTR_KIND, ATTR_KIND_VIEWBOX);
    SVGRectElement element = rect.getElement().cast();
    SVGRectElement twin = element.cloneNode(true).cast();
    viewBox = new SVGViewBoxElementModel(this, element, twin);
    adopt(viewBox);
    insertBefore(modelGroup, viewBox, (SVGElementModel) modelGroup.getChild(0));
}
Example 2
Project: lib-gwt-svg-samples-master  File: EventSample.java View source code
@Override
public TabLayoutPanel getPanel() {
    if (tabPanel == null) {
        tabPanel = binder.createAndBindUi(this);
        tabPanel.setTabText(0, "Events");
        createCodeTabs("EventSample");
        // Cast the document into a SVG document
        Element div = svgContainer.getElement();
        OMSVGDocument doc = OMSVGParser.currentDocument();
        // Create the root svg element
        svg = doc.createSVGSVGElement();
        svg.setViewBox(0f, 0f, 400f, 200f);
        svg.getWidth().getBaseVal().newValueSpecifiedUnits(Unit.PCT, 100);
        svg.getHeight().getBaseVal().newValueSpecifiedUnits(Unit.PCT, 100);
        // Create a circle
        final OMSVGCircleElement circle = doc.createSVGCircleElement(80f, 80f, 40f);
        circle.getStyle().setSVGProperty(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_BLACK_VALUE);
        setCircleColor(circle, SVGConstants.CSS_RED_VALUE);
        svg.appendChild(circle);
        // Set a mousedown event handler
        circle.addMouseDownHandler(new MouseDownHandler() {

            final String[] colors = new String[] { SVGConstants.CSS_RED_VALUE, SVGConstants.CSS_BLUE_VALUE, SVGConstants.CSS_GREEN_VALUE, SVGConstants.CSS_YELLOW_VALUE, SVGConstants.CSS_PINK_VALUE };

            @Override
            public void onMouseDown(MouseDownEvent event) {
                String color = getCircleColor(circle);
                while (color.equals(getCircleColor(circle))) {
                    setCircleColor(circle, colors[Random.nextInt(colors.length)]);
                }
                event.stopPropagation();
                event.preventDefault();
            }
        });
        // Create a square
        square = doc.createSVGRectElement(140f, 40f, 80f, 80f, 0f, 0f);
        square.getStyle().setSVGProperty(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_BLACK_VALUE);
        square.getStyle().setSVGProperty(SVGConstants.CSS_FILL_PROPERTY, SVGConstants.CSS_GREEN_VALUE);
        square.addMouseDownHandler(this);
        square.addMouseUpHandler(this);
        square.addMouseMoveHandler(this);
        svg.appendChild(square);
        // Insert the SVG root element into the HTML UI
        div.appendChild(svg.getElement());
    }
    return tabPanel;
}