javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GSVGElement.java
changeset 87 1627c337e51e
parent 56 abc41079b313
equal deleted inserted replaced
80:d6dafc5d983f 87:1627c337e51e
     1 /*
     1 /*
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 package com.nokia.microedition.m2g;
    19 package com.nokia.microedition.m2g;
    20 
    20 
    21 import org.w3c.dom.*;
    21 import org.w3c.dom.*;
    22 import org.w3c.dom.svg.*;
    22 import org.w3c.dom.svg.*;
    23 import org.w3c.dom.events.*;
    23 import org.w3c.dom.events.*;
    24 //import com.nokia.mj.impl.rt.legacy.ToolkitInvoker;
       
    25 import java.io.IOException;
    24 import java.io.IOException;
    26 import org.eclipse.swt.widgets.*;
    25 import org.eclipse.swt.widgets.*;
    27 //import org.eclipse.swt.widgets.Display;
       
    28 import com.nokia.mj.impl.utils.Logger;
    26 import com.nokia.mj.impl.utils.Logger;
    29 
    27 
    30 public class M2GSVGElement extends M2GObject implements SVGElement
    28 public class M2GSVGElement extends M2GObject implements SVGElement
    31 {
    29 {
    32     //--------------------------------------------------
    30     //--------------------------------------------------
    37         "The type is null.";
    35         "The type is null.";
    38     static final String LISTENER_IS_NULL_ESTR =
    36     static final String LISTENER_IS_NULL_ESTR =
    39         "The listener is null.";
    37         "The listener is null.";
    40     static final String CAPTURE_NOT_SUPPORTED_ESTR =
    38     static final String CAPTURE_NOT_SUPPORTED_ESTR =
    41         "The capture phase is not supported in SVG Tiny.";
    39         "The capture phase is not supported in SVG Tiny.";
    42     //static final String ESWT_PACKAGE =
       
    43        // "org.eclipse.swt.widgets.Display" ;
       
    44 
       
    45     /* Optimization: static finals changed to local variables
       
    46     static final String TRAIT_IS_NULL_ESTR =
       
    47       "The trait is null.";
       
    48     static final String TRAIT_NOT_SUPPORTED_ON_ELEM_ESTR =
       
    49       "The trait is not supported on this element.";
       
    50     static final String TRAIT_NOT_SUPPORTED_IN_NS_ESTR =
       
    51       "The trait is not supported in this namespace.";
       
    52     static final String GET_FLOAT_MISMATCH_ESTR =
       
    53       "Trait's computed value cannot be converted to a float.";
       
    54     static final String SET_FLOAT_MISMATCH_ESTR =
       
    55       "Trait's value cannot be specified as a float.";
       
    56     static final String GET_MATRIX_MISMATCH_ESTR =
       
    57       "Trait's computed value cannot be converted to a SVGMatrix.";
       
    58     static final String SET_MATRIX_MISMATCH_ESTR =
       
    59       "Trait's value cannot be specified as a SVGMatrix.";
       
    60     static final String GET_PATH_MISMATCH_ESTR =
       
    61       "Trait's computed value cannot be converted to a SVGPath.";
       
    62     static final String SET_PATH_MISMATCH_ESTR =
       
    63       "Trait's value cannot be specified as a SVGPath.";
       
    64     static final String GET_RECT_MISMATCH_ESTR =
       
    65       "Trait's computed value cannot be converted to a SVGRect.";
       
    66     static final String SET_RECT_MISMATCH_ESTR =
       
    67       "Trait's value cannot be specified as a SVGRect.";
       
    68     static final String GET_RGB_MISMATCH_ESTR =
       
    69       "Trait's computed value cannot be converted to a SVGRGBColor.";
       
    70     static final String SET_RGB_MISMATCH_ESTR =
       
    71       "Trait's value cannot be specified as a SVGRGBColor.";
       
    72     static final String NS_NOT_SUPPORTED_ESTR =
       
    73       "The namespace is not supported.";
       
    74     static final String GET_TRAIT_NS_STRING_MISMATCH_ESTR =
       
    75       "Trait's computed value cannot be converted to a String.";
       
    76     static final String SET_TRAIT_NS_STRING_MISMATCH_ESTR =
       
    77       "Trait's value cannot be specified as a String.";
       
    78     static final String ID_IS_NULL_ESTR =
       
    79       "The id is null.";
       
    80     static final String EXISTING_ELEM_ID_CHANGE_ESTR =
       
    81       "Existing element id cannot be changed.";
       
    82     static final String ELEM_ID_EXIST_IN_DOCUMENT_ESTR =
       
    83       "Element id already exists in the document.";
       
    84     static final String INVALID_INPUT_VALUE_ESTR =
       
    85       "The input value is an invalid value for the given trait.";
       
    86     static final String VALUE_IS_NULL_ESTR =
       
    87       "Value cannot be set to null.";
       
    88     static final String SET_READONLY_MISMATCH_ESTR =
       
    89       "Attempt to change readonly trait.";
       
    90     static final String INVALID_VALUE_ESTR =
       
    91       "The value is invalid.";
       
    92     static final String INVALID_USE_ELEMENT_ESTR =
       
    93       "The <use> element is hooked into the document tree and the the value of xlink:href is set invalid.";
       
    94     static final String CANNOT_REMOVE_NODE_ESTR =
       
    95       "Cannot remove this type of node.";
       
    96     static final String CANNOT_REMOVE_NOT_CHILD_ESTR =
       
    97       "Not a child of this node.";
       
    98     static final String CANNOT_REMOVE_NON_NULL_ID_ESTR =
       
    99       "The element being removed or one of its decendants have non-null id.";
       
   100     static final String INSERT_NODE_OF_THAT_TYPE_ESTR =
       
   101       "Cannot insert node of that type.";
       
   102     static final String APPEND_DOCUMENT_ESTR =
       
   103       "Cannot append Document elements.";
       
   104     static final String DOCUMENT_HIERARCHY_ESTR =
       
   105       "Hierarchy request error in Document.";
       
   106     static final String CHILD_IS_WRONG_TYPE_ESTR =
       
   107       "Child is wrong type (Document).";
       
   108     static final String CHILD_BELONG_TO_DIFFERENT_DOCUMENT_ESTR =
       
   109       "Child belongs to different document.";
       
   110     static final String CHILD_NOT_FOUND_ESTR =
       
   111       "The child to insert before doesn't exist in this current node.";
       
   112     static final String INVALID_ELEMENT_ID_VALUE =
       
   113       "Invalid element id value.";
       
   114     */
       
   115 
    40 
   116     //--------------------------------------------------
    41     //--------------------------------------------------
   117     // VARIABLES
    42     // VARIABLES
   118     //--------------------------------------------------
    43     //--------------------------------------------------
   119     protected M2GDocument iDocument;
    44     protected M2GDocument iDocument;
   260      */
   185      */
   261     public Element getFirstElementChild() throws DOMException
   186     public Element getFirstElementChild() throws DOMException
   262     {
   187     {
   263         // Get child element's handle
   188         // Get child element's handle
   264         int childHandle = _getFirstElementChild(
   189         int childHandle = _getFirstElementChild(
   265                                getNativeSVGProxyHandle(), getHandle());
   190                               getNativeSVGProxyHandle(), getHandle());
   266         if (M2GObject.checkHandle(childHandle))
   191         if (M2GObject.checkHandle(childHandle))
   267         {
   192         {
   268             return (Element)M2GSVGElement.buildElement(childHandle, iDocument);
   193             return (Element)M2GSVGElement.buildElement(childHandle, iDocument);
   269         }
   194         }
   270         return null;
   195         return null;
   371      * @see org.w3c.dom.svg.SVGElement#getNextElementSibling()
   296      * @see org.w3c.dom.svg.SVGElement#getNextElementSibling()
   372      */
   297      */
   373     public Element getNextElementSibling()
   298     public Element getNextElementSibling()
   374     {
   299     {
   375         int elementHandle = _getNextElementSibling(
   300         int elementHandle = _getNextElementSibling(
   376                                  getNativeSVGProxyHandle(), getHandle());
   301                                 getNativeSVGProxyHandle(), getHandle());
   377         if (M2GObject.checkHandle(elementHandle))
   302         if (M2GObject.checkHandle(elementHandle))
   378         {
   303         {
   379             return M2GSVGElement.buildElement(elementHandle, iDocument);
   304             return M2GSVGElement.buildElement(elementHandle, iDocument);
   380         }
   305         }
   381         return null;
   306         return null;
   392             Logger.ELOG(Logger.EJavaUI,
   317             Logger.ELOG(Logger.EJavaUI,
   393                         "getParentNode() - access rights failure");
   318                         "getParentNode() - access rights failure");
   394             throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
   319             throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
   395         }
   320         }
   396         int parentHandle = _getParent(
   321         int parentHandle = _getParent(
   397                                 getNativeSVGProxyHandle(), getHandle());
   322                                getNativeSVGProxyHandle(), getHandle());
   398         if (M2GObject.checkHandle(parentHandle))
   323         if (M2GObject.checkHandle(parentHandle))
   399         {
   324         {
   400             return M2GSVGElement.buildElement(parentHandle, iDocument);
   325             return M2GSVGElement.buildElement(parentHandle, iDocument);
   401         }
   326         }
   402         return null;
   327         return null;
   765         }
   690         }
   766         String href = _getStringTrait(
   691         String href = _getStringTrait(
   767                           getNativeSVGProxyHandle(),
   692                           getNativeSVGProxyHandle(),
   768                           ((M2GSVGElement)newChild).getHandle(),
   693                           ((M2GSVGElement)newChild).getHandle(),
   769                           M2GSVGConstants.AT_XLINKHREF);
   694                           M2GSVGConstants.AT_XLINKHREF);
   770         // Need to call resource handler if element is elementindom, image,
   695         // call resource handler call if element is elementindom, image,
   771         // and if it has an href attribute
   696         // and if it has an href attribute
   772         if ((href != null) &&
   697         if ((href != null) &&
   773                 (((M2GSVGElement)newChild).iElementTypeId == M2GSVGConstants.EL_IMAGE) &&
   698                 (((M2GSVGElement)newChild).iElementTypeId == M2GSVGConstants.EL_IMAGE) &&
   774                 iDocument.isElementInDOM(((M2GSVGElement)newChild).getHandle()))
   699                 iDocument.isElementInDOM(((M2GSVGElement)newChild).getHandle()))
   775         {
   700         {
   958             throw new DOMException(
   883             throw new DOMException(
   959                 DOMException.INVALID_ACCESS_ERR,
   884                 DOMException.INVALID_ACCESS_ERR,
   960                 /*SF*/"The input value is an invalid value for the given trait."/*SF*/);
   885                 /*SF*/"The input value is an invalid value for the given trait."/*SF*/);
   961         }
   886         }
   962 
   887 
   963         _setPathTrait( getNativeSVGProxyHandle(),
   888         _setPathTrait(getNativeSVGProxyHandle(),
   964                       getHandle(), id, ((M2GSVGPath)path).getHandle());
   889                       getHandle(), id, ((M2GSVGPath)path).getHandle());
   965 
   890 
   966         // inform observer about changes in DOM only if element is in DOM
   891         // inform observer about changes in DOM only if element is in DOM
   967         iDocument.notifyDOMChangeObserver(iNativeHandle);
   892         iDocument.notifyDOMChangeObserver(iNativeHandle);
   968     }
   893     }
  1280         {
  1205         {
  1281 
  1206 
  1282             String id = M2GSVGElement._getStringTrait(
  1207             String id = M2GSVGElement._getStringTrait(
  1283                             M2GManager.getInstance().getSVGProxyHandle(),
  1208                             M2GManager.getInstance().getSVGProxyHandle(),
  1284                             aElementHandle,
  1209                             aElementHandle,
  1285                             M2GSVGConstants.AT_ID );
  1210                             M2GSVGConstants.AT_ID);
  1286             if ((id != null) && id.equals("text_use_svg_default_font"))
  1211             if ((id != null) && id.equals("text_use_svg_default_font"))
  1287             {
  1212             {
  1288                 return buildElement(
  1213                 return buildElement(
  1289                            M2GSVGElement._getNextElementSibling(
  1214                            M2GSVGElement._getNextElementSibling(
  1290                                aDocument.getNativeSVGProxyHandle(), aElementHandle),
  1215                                aDocument.getNativeSVGProxyHandle(), aElementHandle),