javauis/m3g_qt/javasrc/javax/microedition/m3g/Node.java
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package javax.microedition.m3g;
       
    20 
       
    21 public abstract class Node extends Transformable
       
    22 {
       
    23     //------------------------------------------------------------------
       
    24     // Static data
       
    25     //------------------------------------------------------------------
       
    26 
       
    27     public static final int NONE = 144;
       
    28     public static final int ORIGIN = 145;
       
    29     public static final int X_AXIS = 146;
       
    30     public static final int Y_AXIS = 147;
       
    31     public static final int Z_AXIS = 148;
       
    32 
       
    33     //------------------------------------------------------------------
       
    34     // Instance data
       
    35     //------------------------------------------------------------------
       
    36 
       
    37     // The node references are kept on the Java side to avoid having
       
    38     // to replicate garbage collection in the native implementation.
       
    39     // Instead, we let Java manage Node reachability detection and
       
    40     // deletion.
       
    41 
       
    42     private Node parent;
       
    43     private Node zRef, yRef;
       
    44 
       
    45     //------------------------------------------------------------------
       
    46     // Constructor(s)
       
    47     //------------------------------------------------------------------
       
    48 
       
    49     /**
       
    50      * There is only a package private constructor. Applications can not extend
       
    51      * this class directly.</p>
       
    52      */
       
    53     Node(int handle)
       
    54     {
       
    55         super(handle);
       
    56         parent = (Node) getInstance(_getParent(handle));
       
    57         zRef = (Node) getInstance(_getZRef(handle));
       
    58         yRef = (Node) getInstance(_getYRef(handle));
       
    59     }
       
    60 
       
    61     //------------------------------------------------------------------
       
    62     // Public methods
       
    63     //------------------------------------------------------------------
       
    64 
       
    65     public Node getParent()
       
    66     {
       
    67         return parent;
       
    68     }
       
    69 
       
    70     public boolean getTransformTo(Node target, Transform transform)
       
    71     {
       
    72         return _getTransformTo(handle,
       
    73                                target.handle,
       
    74                                transform != null ? transform.matrix : null);
       
    75     }
       
    76 
       
    77     public void setAlignment(Node zReference, int zTarget,
       
    78                              Node yReference, int yTarget)
       
    79     {
       
    80         _setAlignment(handle,
       
    81                       zReference != null ? zReference.handle : 0, zTarget,
       
    82                       yReference != null ? yReference.handle : 0, yTarget);
       
    83         zRef = zReference;
       
    84         yRef = yReference;
       
    85     }
       
    86 
       
    87     public void setAlphaFactor(float alphaFactor)
       
    88     {
       
    89         _setAlphaFactor(handle, alphaFactor);
       
    90     }
       
    91 
       
    92     public float getAlphaFactor()
       
    93     {
       
    94         return _getAlphaFactor(handle);
       
    95     }
       
    96 
       
    97     public void setRenderingEnable(boolean enable)
       
    98     {
       
    99         _enable(handle, Defs.SETGET_RENDERING, enable);
       
   100     }
       
   101 
       
   102     public boolean isRenderingEnabled()
       
   103     {
       
   104         return _isEnabled(handle, Defs.SETGET_RENDERING);
       
   105     }
       
   106 
       
   107     public void setPickingEnable(boolean enable)
       
   108     {
       
   109         _enable(handle, Defs.SETGET_PICKING, enable);
       
   110     }
       
   111 
       
   112     public boolean isPickingEnabled()
       
   113     {
       
   114         return _isEnabled(handle, Defs.SETGET_PICKING);
       
   115     }
       
   116 
       
   117     public void setScope(int id)
       
   118     {
       
   119         _setScope(handle, id);
       
   120     }
       
   121 
       
   122     public int getScope()
       
   123     {
       
   124         return _getScope(handle);
       
   125     }
       
   126 
       
   127     public final void align(Node reference)
       
   128     {
       
   129         _align(handle, reference != null ? reference.handle : 0);
       
   130     }
       
   131 
       
   132     // M3G 1.1 Maintenance release getters
       
   133 
       
   134     public Node getAlignmentReference(int axis)
       
   135     {
       
   136         switch (axis)
       
   137         {
       
   138         case Y_AXIS:
       
   139             return yRef;
       
   140         case Z_AXIS:
       
   141             return zRef;
       
   142         default:
       
   143             throw new IllegalArgumentException();
       
   144         }
       
   145     }
       
   146 
       
   147     public int getAlignmentTarget(int axis)
       
   148     {
       
   149         return _getAlignmentTarget(handle, axis);
       
   150     }
       
   151 
       
   152 
       
   153     //------------------------------------------------------------------
       
   154     // Private methods
       
   155     //------------------------------------------------------------------
       
   156 
       
   157     void setParent(Node parent)
       
   158     {
       
   159         this.parent = parent;
       
   160     }
       
   161 
       
   162     // Native methods
       
   163     private static native boolean _getTransformTo(int handle,
       
   164             int hTarget,
       
   165             byte[] transform);
       
   166 
       
   167     private static native void _align(int handle, int refHandle);
       
   168     private static native void _setAlignment(int handle,
       
   169             int hZReference, int zTarget,
       
   170             int hYReference, int yTarget);
       
   171 
       
   172     private static native void _setAlphaFactor(int handle, float alphaFactor);
       
   173     private static native float _getAlphaFactor(int handle);
       
   174 
       
   175     private static native void _enable(int handle, int which, boolean enable);
       
   176     private static native boolean _isEnabled(int handle, int which);
       
   177 
       
   178     private static native void _setScope(int handle, int id);
       
   179     private static native int _getScope(int handle);
       
   180 
       
   181     private static native int _getParent(int handle);
       
   182     private static native int _getZRef(int handle);
       
   183     private static native int _getYRef(int handle);
       
   184     static native int _getSubtreeSize(int handle);
       
   185 
       
   186     // M3G 1.1 Maintenance release getters
       
   187     private static native int _getAlignmentTarget(int handle, int axis);
       
   188 }