javauis/lcdui_akn/javalcdui/javasrc/javax/microedition/lcdui/Ticker.java
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 1999 - 2004 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 
       
    20 package javax.microedition.lcdui;
       
    21 
       
    22 import com.nokia.mj.impl.rt.legacy.NativeError;
       
    23 import com.nokia.mj.impl.rt.support.Finalizer;
       
    24 
       
    25 public class Ticker
       
    26 {
       
    27     final Toolkit iToolkit;
       
    28     private int iHandle;
       
    29     private String iText;
       
    30     private Finalizer mFinalizer;
       
    31 
       
    32     public Ticker(String aText)
       
    33     {
       
    34         if (null == aText)
       
    35         {
       
    36             throw new NullPointerException();
       
    37         }
       
    38         mFinalizer = new Finalizer()
       
    39         {
       
    40             public void finalizeImpl()
       
    41             {
       
    42                 doFinalize();
       
    43             }
       
    44         };
       
    45         Toolkit toolkit = Toolkit.getToolkit();
       
    46         synchronized (toolkit)
       
    47         {
       
    48             iToolkit = toolkit;
       
    49             iHandle  = Toolkit.checkHandle(_create(toolkit.getHandle(), aText));
       
    50             iText    = aText;
       
    51         }
       
    52     }
       
    53 
       
    54     public void setString(String aText)
       
    55     {
       
    56         if (null == aText)
       
    57         {
       
    58             throw new NullPointerException();
       
    59         }
       
    60         synchronized (iToolkit)
       
    61         {
       
    62             if (iHandle <= 0) throw new RuntimeException("bad handle");
       
    63             NativeError.check(_setText(iHandle,iToolkit.getHandle(),aText));
       
    64             iText = aText;
       
    65         }
       
    66     }
       
    67 
       
    68     public String getString()
       
    69     {
       
    70         return iText;
       
    71     }
       
    72 
       
    73     int getHandle()
       
    74     {
       
    75         if (iHandle <= 0)
       
    76         {
       
    77             throw new RuntimeException("Ticker: bad handle " + iHandle);
       
    78         }
       
    79         return iHandle;
       
    80     }
       
    81 
       
    82     private void doFinalize()
       
    83     {
       
    84         if (mFinalizer != null)
       
    85         {
       
    86             registeredFinalize();
       
    87             mFinalizer = null;
       
    88         }
       
    89     }
       
    90 
       
    91     void registeredFinalize()
       
    92     {
       
    93         synchronized (iToolkit)
       
    94         {
       
    95             iToolkit.disposeObject(iHandle);
       
    96             iHandle=0;
       
    97         }
       
    98     }
       
    99 
       
   100     private native int _create(int aToolkit,String aText);
       
   101     private native int _setText(int aHandle,int aToolkit,String aText);
       
   102 } // class Ticker