Package org.w3c.dom.svg

Examples of org.w3c.dom.svg.SVGElement


     * will be added.
     * @param node the <code>GraphicsNode</code>.
     */
    public static void addDOMListener(BridgeContext ctx,
                                      Element eee) {
        SVGElement element = null;
        EventTarget target = null;
        try {
            element = (SVGElement)eee;
            // ability for scripts to be called
            target = (EventTarget)element;
        } catch (ClassCastException e) {
            // will not work on this one!
            return;
        }
        SVGSVGElement svgElement = (SVGSVGElement)element.getOwnerSVGElement();
        if (svgElement == null) {
            if (element.getLocalName().equals(SVG_SVG_TAG)) {
                svgElement = (SVGSVGElement)element;
            } else {
                // something goes wrong => disable scripting
                return;
            }
        }
        String language = svgElement.getContentScriptType();
        Interpreter interpret = null;
        String script = null;
        // <!> TODO we need to memo listeners to be able to remove
        // them later when deconnecting the bridge binding...
        if (element.getLocalName().equals(SVG_SVG_TAG)) {
            for (int i = 0; i < EVENT_ATTRIBUTES_SVG.length; i++) {
                if (!(script = element.getAttribute(EVENT_ATTRIBUTES_SVG[i])).
                    equals("")) {
                    if (interpret == null) {
                        // try to get the intepreter only if we have
                        // a reason to do it!
                        interpret = ctx.getInterpreterPool().
                            getInterpreter(element.getOwnerDocument(), language);
                        // the interpreter is not avaible => stop it now!
                        if (interpret == null) {
                            UserAgent ua = ctx.getUserAgent();
                            if (ua != null)
                                ua.displayError(new Exception("unknow language: "+language));
                            break;
                        }
                    }
                    target.
                        addEventListener(EVENT_NAMES[i+FIRST_SVG_EVENT],
                                         new ScriptCaller(ctx.getUserAgent(),
                                                          script, interpret),
                                         false);
                }
            }
            // continue
        } else
            if (element.getLocalName().equals("set") ||
                element.getLocalName().startsWith("animate")) {
                for (int i = 0; i < EVENT_ATTRIBUTES_ANIMATION.length; i++) {
                    if (!(script =
                          element.getAttribute(EVENT_ATTRIBUTES_ANIMATION[i])).
                        equals("")) {
                        if (interpret == null) {
                            // try to get the intepreter only if we have
                            // a reason to do it!
                            interpret = ctx.getInterpreterPool().
                                getInterpreter(element.getOwnerDocument(),
                                               language);
                            // the interpreter is not avaible => stop it now!
                            if (interpret == null) {
                                UserAgent ua = ctx.getUserAgent();
                                if (ua != null)
                                    ua.displayError(new Exception("unknow language: "+
                                                                  language));
                                break;
                            }
                        }
                        target.
                            addEventListener(EVENT_NAMES[i+
                                                        FIRST_ANIMATION_EVENT],
                                             new ScriptCaller(ctx.getUserAgent(),
                                                              script, interpret),
                                             false);
                    }
                }
                // not other stuff to do on this kind of events
                return;
            }
        for (int i = 0; i < EVENT_ATTRIBUTES_GRAPHICS.length; i++) {
            if (!(script = element.getAttribute(EVENT_ATTRIBUTES_GRAPHICS[i])).
                equals("")) {
                if (interpret == null) {
                    // try to get the intepreter only if we have
                    // a reason to do it!
                    interpret = ctx.getInterpreterPool().
                        getInterpreter(element.getOwnerDocument(), language);
                    // the interpreter is not avaible => stop it now!
                    if (interpret == null) {
                        UserAgent ua = ctx.getUserAgent();
                        if (ua != null)
                            ua.displayError(new Exception("unknow language: "+language));
View Full Code Here


     * will be added.
     * @param node the <code>GraphicsNode</code>.
     */
    public static void addDOMListener(BridgeContext ctx,
                                      Element eee) {
        SVGElement element = null;
        EventTarget target = null;
        try {
            element = (SVGElement)eee;
            // ability for scripts to be called
            target = (EventTarget)element;
        } catch (ClassCastException e) {
            // will not work on this one!
            return;
        }
        SVGSVGElement svgElement = (SVGSVGElement)element.getOwnerSVGElement();
        if (svgElement == null) {
            if (element.getLocalName().equals(SVG_SVG_TAG)) {
                svgElement = (SVGSVGElement)element;
            } else {
                // something goes wrong => disable scripting
                return;
            }
        }
        String language = svgElement.getContentScriptType();
        Interpreter interpret = null;
        String script = null;
        if (element.getLocalName().equals(SVG_SVG_TAG)) {
            for (int i = 0; i < EVENT_ATTRIBUTES_SVG.length; i++) {
                if (!(script = element.getAttribute(EVENT_ATTRIBUTES_SVG[i])).
                    equals("")) {
                    if (interpret == null) {
                        // try to get the intepreter only if we have
                        // a reason to do it!
                        interpret = ctx.getInterpreterPool().
                            getInterpreter(element.getOwnerDocument(), language);
                        // the interpreter is not avaible => stop it now!
                        if (interpret == null) {
                            UserAgent ua = ctx.getUserAgent();
                            if (ua != null)
                                ua.displayError(new Exception("unknow language: "+
                                                              language));
                            break;
                        }
                    }
                    addScriptCaller(target, EVENT_NAMES[i+FIRST_SVG_EVENT],
                                     new ScriptCaller(ctx.getUserAgent(),
                                                      script, interpret));
                }
            }
            // continue
        } else
            if (element.getLocalName().equals("set") ||
                element.getLocalName().startsWith("animate")) {
                for (int i = 0; i < EVENT_ATTRIBUTES_ANIMATION.length; i++) {
                    if (!(script =
                          element.getAttribute(EVENT_ATTRIBUTES_ANIMATION[i])).
                        equals("")) {
                        if (interpret == null) {
                            // try to get the intepreter only if we have
                            // a reason to do it!
                            interpret = ctx.getInterpreterPool().
                                getInterpreter(element.getOwnerDocument(),
                                               language);
                            // the interpreter is not avaible => stop it now!
                            if (interpret == null) {
                                UserAgent ua = ctx.getUserAgent();
                                if (ua != null)
                                    ua.displayError(new Exception("unknow language: "+
                                                                  language));
                                break;
                            }
                        }
                        addScriptCaller(target, EVENT_NAMES[i+
                                                            FIRST_ANIMATION_EVENT],
                                         new ScriptCaller(ctx.getUserAgent(),
                                                          script, interpret));
                    }
                }
                // not other stuff to do on this kind of events
                return;
            }
        for (int i = 0; i < EVENT_ATTRIBUTES_GRAPHICS.length; i++) {
            if (!(script = element.getAttribute(EVENT_ATTRIBUTES_GRAPHICS[i])).
                equals("")) {
                if (interpret == null) {
                    // try to get the intepreter only if we have
                    // a reason to do it!
                    interpret = ctx.getInterpreterPool().
                        getInterpreter(element.getOwnerDocument(), language);
                    // the interpreter is not avaible => stop it now!
                    if (interpret == null) {
                        UserAgent ua = ctx.getUserAgent();
                        if (ua != null)
                            ua.displayError(new Exception("unknow language: "+language));
View Full Code Here

                // Reset the last x and y coordinates.
                _lastX = -1;
                _lastY = -1;

                // Remove all children from the svg node.
                SVGElement line = (SVGElement) _svg.getFirstElementChild();
                while (line != null) {
                    _svg.removeChild(line);
                    line = (SVGElement) _svg.getFirstElementChild();
                }
View Full Code Here

     *            The ending y coordinate
     */
    private void drawLine(final String color, final int width, final int x,
            final int y) {
        // Create new element
        final SVGElement newElement =
                (SVGElement) _document.createElementNS(SVG_NAMESPACE_URI,
                        SVG_LINE);
        newElement.setFloatTrait(X1, _lastX);
        newElement.setFloatTrait(Y1, _lastY);
        newElement.setFloatTrait(X2, x);
        newElement.setFloatTrait(Y2, y);
        newElement.setFloatTrait(STROKE_WIDTH, width);
        newElement.setTrait(STROKE, color.toLowerCase());
        _svg.appendChild(newElement);
    }
View Full Code Here

        // Scale and center the display element to a portion of the device's
        // minimum display dimension.
        final float translateX = (displayWidth - newDimension) / 2;
        final float scaleWidth = newDimension / ORIGINAL_DISPLAY_SIZE;
        final float scaleHeight = newDimension / ORIGINAL_DISPLAY_SIZE;
        final SVGElement display = (SVGElement) doc.getElementById("display");
        display.setAttribute("transform", "translate(" + translateX + " "
                + DISPLAY_Y_OFFSET + ") " + "scale(" + scaleWidth + " "
                + scaleHeight + ")");

        // Scale and position the play and stop buttons
        final float newBtnSize = 0.2f * (minDimension - DISPLAY_Y_OFFSET);
        final float scaleBtn = newBtnSize / ORIGINAL_BUTTON_SIZE;
        final SVGElement playBtn = (SVGElement) doc.getElementById("play");
        playBtn.setAttribute("transform", "translate(" + newBtnSize + " "
                + (displayHeight - newBtnSize) + ") " + "scale(" + scaleBtn
                + ")");

        final SVGElement stopBtn = (SVGElement) doc.getElementById("stop");
        stopBtn.setAttribute("transform", "translate("
                + (displayWidth - newBtnSize) + " "
                + (displayHeight - newBtnSize) + ") " + "scale(" + scaleBtn
                + ")");
    }
View Full Code Here

                    public void run() {
                        _svgFormsScreen.setFocus(null);
                        String items = "Items: ";
                        String quantity = "quantity: ";
                        for (int i = 0; i < _checkBoxVector.size(); i++) {
                            final SVGElement checkBox =
                                    (SVGElement) _checkBoxVector.elementAt(i);
                            final String checkTrait =
                                    checkBox.getTrait("display");
                            if (checkTrait.equals("inline")) {
                                String itemName = "";
                                if (checkBox == _checkbox1_check) {
                                    itemName =
                                            _checkbox1_text.getTrait("#text");
                                } else if (checkBox == _checkbox2_check) {
                                    itemName =
                                            _checkbox2_text.getTrait("#text");
                                }
                                items = items + itemName + " ";
                            }
                        }
                        for (int i = 0; i < _radioButtonVector.size(); i++) {
                            final SVGElement radiobuttoncheck =
                                    (SVGElement) _radioButtonVector
                                            .elementAt(i);
                            final String radioCheckTrait =
                                    radiobuttoncheck.getTrait("display");
                            if (radioCheckTrait.equals("inline")) {
                                String quantityInKg = "";
                                if (radiobuttoncheck == _radiobutton1_check) {
                                    quantityInKg =
                                            _radiobutton1_text
                                                    .getTrait("#text");
                                } else if (radiobuttoncheck == _radiobutton2_check) {
                                    quantityInKg =
                                            _radiobutton2_text
                                                    .getTrait("#text");
                                } else if (radiobuttoncheck == _radiobutton3_check) {
                                    quantityInKg =
                                            _radiobutton3_text
                                                    .getTrait("#text");
                                }
                                quantity = quantity + quantityInKg;
                                break;
                            }
                        }

                        _dialogbox.setTrait("display", "inline");
                        _dialogbox_text1.setTrait("#text", items);
                        _dialogbox_text2.setTrait("#text", quantity);
                    }
                });
            }

            // Handle the dialog box button
            else if (_currentClickedElement == _dialogboxbutton) {
                deActivateSVGElement(_dialogboxbutton, this);
                _svgFormsScreen.dialogboxMode(this, false);
                _animator.invokeLater(new Runnable() {
                    public void run() {
                        _dialogbox.setTrait("display", "none");
                    }
                });
            }

            // Handle the checkboxes and radiobutton events
            else {
                _animator.invokeLater(new Runnable() {
                    public void run() {
                        if (_currentClickedElement == _checkbox1) {
                            final String checkBoxState =
                                    _checkbox1_check.getTrait("display");
                            if (checkBoxState.equals("none")) {
                                _checkbox1_check.setTrait("display", "inline");
                            } else if (checkBoxState.equals("inline")) {
                                _checkbox1_check.setTrait("display", "none");
                            }
                        } else if (_currentClickedElement == _checkbox2) {
                            final String checkBoxState =
                                    _checkbox2_check.getTrait("display");
                            if (checkBoxState.equals("none")) {
                                _checkbox2_check.setTrait("display", "inline");
                            } else if (checkBoxState.equals("inline")) {
                                _checkbox2_check.setTrait("display", "none");
                            }
                        } else if (_currentClickedElement == _radiobutton1) {
                            _radiobutton1_check.setTrait("display", "inline");

                            for (int i = 0; i < _radioButtonVector.size(); i++) {
                                final SVGElement radiobutton =
                                        (SVGElement) _radioButtonVector
                                                .elementAt(i);
                                if (!(radiobutton == _radiobutton1_check)) {
                                    radiobutton.setTrait("display", "none");
                                }
                            }
                        } else if (_currentClickedElement == _radiobutton2) {
                            _radiobutton2_check.setTrait("display", "inline");
                            for (int i = 0; i < _radioButtonVector.size(); i++) {
                                final SVGElement radiobutton =
                                        (SVGElement) _radioButtonVector
                                                .elementAt(i);
                                if (!(radiobutton == _radiobutton2_check)) {
                                    radiobutton.setTrait("display", "none");
                                }
                            }
                        } else if (_currentClickedElement == _radiobutton3) {
                            _radiobutton3_check.setTrait("display", "inline");
                            for (int i = 0; i < _radioButtonVector.size(); i++) {
                                final SVGElement radiobutton =
                                        (SVGElement) _radioButtonVector
                                                .elementAt(i);
                                if (!(radiobutton == _radiobutton3_check)) {
                                    radiobutton.setTrait("display", "none");
                                }
                            }
                        }
                    }
                });
View Full Code Here

     * @param elementId
     *            the id of the element being activated
     */
    private void activateElement(final String elementId) {
        final Document doc = _image.getDocument();
        final SVGElement element = (SVGElement) doc.getElementById(elementId);
        _image.focusOn(element);
        _image.activate();
    }
View Full Code Here

     * @param elementId
     *            the id of the element being displayed
     */
    private void setDisplayInline(final String elementId) {
        final Document doc = _image.getDocument();
        SVGElement animation = null;
        if (!_currentAnimation.equals("")) {
            animation = (SVGElement) doc.getElementById(_currentAnimation);
            animation.setTrait(DISPLAY_ATTR, NONE_VALUE);
        }

        animation = (SVGElement) doc.getElementById(elementId);
        _currentAnimation = elementId;
        animation.setTrait(DISPLAY_ATTR, INLINE_VALUE);
    }
View Full Code Here

        // Initialize a hashtable for our check boxes.
        _checkboxes = new Hashtable(3);
        // Populates the hashtable, associates listeners with the checkbox
        final CheckboxField roadsCheckBox = new CheckboxField("Roads  ", true);
        final SVGElement roadsGroup =
                (SVGElement) _document.getElementById("roads");
        _checkboxes.put(roadsCheckBox, roadsGroup);

        final CheckboxField railsCheckBox =
                new CheckboxField("Railways  ", true);
        final SVGElement railsGroup =
                (SVGElement) _document.getElementById("railways");
        _checkboxes.put(railsCheckBox, railsGroup);

        final CheckboxField interestsCheckBox =
                new CheckboxField("Points of interest ", true);
        final SVGElement interestsGroup =
                (SVGElement) _document.getElementById("interests");
        _checkboxes.put(interestsCheckBox, interestsGroup);

        final CheckboxField restaurantCheckBox =
                new CheckboxField("Restaurants ", true);
        final SVGElement restaurantGroup =
                (SVGElement) _document.getElementById("restaurants");
        _checkboxes.put(restaurantCheckBox, restaurantGroup);

        // Set this class as the handler of the change listeners.
        roadsCheckBox.setChangeListener(this);
View Full Code Here

    /**
     * @see FieldChangeListener#fieldChanged(Field, int)
     */
    public void fieldChanged(final Field field, final int context) {
        final CheckboxField cbf = (CheckboxField) field;
        final SVGElement svgElement = (SVGElement) _checkboxes.get(cbf);

        // If the checkbox is checked change svg display trait.
        if (cbf.getChecked() == true) {
            _animator.invokeLater(new Runnable() {
                public void run() {
                    svgElement.setTrait("display", "inline");
                }
            });
        } else {
            _animator.invokeLater(new Runnable() {
                public void run() {
                    svgElement.setTrait("display", "none");
                }
            });
        }
    }
View Full Code Here

TOP

Related Classes of org.w3c.dom.svg.SVGElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.