66
|
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 |
private static final int MAX_TICKER_SIZE = 8000; // less than 8KB
|
|
32 |
|
|
33 |
public Ticker(String aText)
|
|
34 |
{
|
|
35 |
if (null == aText)
|
|
36 |
{
|
|
37 |
throw new NullPointerException();
|
|
38 |
}
|
|
39 |
else if (aText.length() > MAX_TICKER_SIZE)
|
|
40 |
{
|
|
41 |
aText = aText.substring(0, MAX_TICKER_SIZE - 1);
|
|
42 |
}
|
|
43 |
|
|
44 |
mFinalizer = new Finalizer()
|
|
45 |
{
|
|
46 |
public void finalizeImpl()
|
|
47 |
{
|
|
48 |
doFinalize();
|
|
49 |
}
|
|
50 |
};
|
|
51 |
Toolkit toolkit = Toolkit.getToolkit();
|
|
52 |
synchronized (toolkit)
|
|
53 |
{
|
|
54 |
iToolkit = toolkit;
|
|
55 |
iHandle = Toolkit.checkHandle(_create(toolkit.getHandle(), aText));
|
|
56 |
iText = aText;
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
public void setString(String aText)
|
|
61 |
{
|
|
62 |
if (null == aText)
|
|
63 |
{
|
|
64 |
throw new NullPointerException();
|
|
65 |
}
|
|
66 |
else if (aText.length() > MAX_TICKER_SIZE)
|
|
67 |
{
|
|
68 |
aText = aText.substring(0, MAX_TICKER_SIZE - 1);
|
|
69 |
}
|
|
70 |
|
|
71 |
synchronized (iToolkit)
|
|
72 |
{
|
|
73 |
if (iHandle <= 0) throw new RuntimeException("bad handle");
|
|
74 |
NativeError.check(_setText(iHandle,iToolkit.getHandle(),aText));
|
|
75 |
iText = aText;
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
public String getString()
|
|
80 |
{
|
|
81 |
return iText;
|
|
82 |
}
|
|
83 |
|
|
84 |
int getHandle()
|
|
85 |
{
|
|
86 |
if (iHandle <= 0)
|
|
87 |
{
|
|
88 |
throw new RuntimeException("Ticker: bad handle " + iHandle);
|
|
89 |
}
|
|
90 |
return iHandle;
|
|
91 |
}
|
|
92 |
|
|
93 |
private void doFinalize()
|
|
94 |
{
|
|
95 |
if (mFinalizer != null)
|
|
96 |
{
|
|
97 |
registeredFinalize();
|
|
98 |
mFinalizer = null;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
void registeredFinalize()
|
|
103 |
{
|
|
104 |
synchronized (iToolkit)
|
|
105 |
{
|
|
106 |
iToolkit.disposeObject(iHandle);
|
|
107 |
iHandle=0;
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
private native int _create(int aToolkit,String aText);
|
|
112 |
private native int _setText(int aHandle,int aToolkit,String aText);
|
|
113 |
} // class Ticker
|