|
1 /* |
|
2 * Copyright (c) 2005 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 package com.nokia.microedition.m2g; |
|
19 |
|
20 import javax.microedition.m2g.*; |
|
21 import org.eclipse.swt.widgets.SVGAnimatorControl; |
|
22 import com.nokia.mj.impl.rt.support.Finalizer; |
|
23 import com.nokia.mj.impl.utils.Logger; |
|
24 |
|
25 public class M2GSVGeSWTAnimator extends SVGAnimator |
|
26 { |
|
27 //-------------------------------------------------- |
|
28 // STATIC CONSTANTS |
|
29 //-------------------------------------------------- |
|
30 private static final String ANIMATOR_CONTROL_BASE_CLASS = |
|
31 "org.eclipse.swt.widgets.Canvas"; |
|
32 |
|
33 // Exception text |
|
34 /* Optimization: static finals changed to local variables |
|
35 private static final String COMPONENT_BASE_CLASS_NOT_SUPPORTED_ESTR = |
|
36 "The requested componentBaseClass is not supported by the implementation."; |
|
37 private static final String ILLEGAL_TIME_INCREMENT_ESTR = |
|
38 "The timeIncrement is less than or equal to zero."; |
|
39 private static final String ANIMATOR_PLAY_ESTR = |
|
40 "The animator is not currently in the stopped or paused state."; |
|
41 private static final String ANIMATOR_PAUSE_ESTR = |
|
42 "The animator is not in the playing state."; |
|
43 private static final String ANIMATOR_STOP_ESTR = |
|
44 "The animator is not in the playing or paused state."; |
|
45 private static final String INVALID_RUNNABLE_ESTR = |
|
46 "The runnable is null."; |
|
47 private static final String ANIMATOR_IS_STOPPED_ESTR = |
|
48 "The animator is in the stopped state."; |
|
49 private static final String RUNNABLE_IS_NULL_ESTR = |
|
50 "The runnable is null."; |
|
51 private static final String ANIMATOR_INVOKE_ESTR = |
|
52 "The animator is in the stopped state."; |
|
53 */ |
|
54 |
|
55 //-------------------------------------------------- |
|
56 // VARIABLES |
|
57 //-------------------------------------------------- |
|
58 private SVGAnimatorControl iAnimatorControl; |
|
59 |
|
60 private Finalizer mFinalizer = new Finalizer() |
|
61 { |
|
62 public void finalizeImpl() |
|
63 { |
|
64 doFinalize(); |
|
65 } |
|
66 }; |
|
67 |
|
68 //-------------------------------------------------- |
|
69 // METHODS |
|
70 //-------------------------------------------------- |
|
71 /** |
|
72 * Constructor |
|
73 * @param aImage |
|
74 */ |
|
75 protected M2GSVGeSWTAnimator(SVGImage aImage) |
|
76 { |
|
77 iAnimatorControl = new SVGAnimatorControl(/*false,*/ aImage); |
|
78 } |
|
79 |
|
80 /** |
|
81 * @see javax.microedition.m2g.SVGAnimator#getTargetComponent() |
|
82 */ |
|
83 public Object getTargetComponent() |
|
84 { |
|
85 return iAnimatorControl; |
|
86 } |
|
87 |
|
88 /** |
|
89 * @see javax.microedition.m2g.SVGAnimator#getTimeIncrement() |
|
90 */ |
|
91 public float getTimeIncrement() |
|
92 { |
|
93 Logger.LOG(Logger.EJavaUI, Logger.EInfo, |
|
94 "getTimeIncrement() " + iAnimatorControl.getTimeIncrement()); |
|
95 return iAnimatorControl.getTimeIncrement(); |
|
96 } |
|
97 |
|
98 /** |
|
99 * @see javax.microedition.m2g.SVGAnimator#invokeAndWait() |
|
100 */ |
|
101 public void invokeAndWait(java.lang.Runnable runnable) |
|
102 { |
|
103 if (runnable == null) |
|
104 { |
|
105 throw new NullPointerException( |
|
106 /*SF*/"The runnable is null."/*SF*/); |
|
107 } |
|
108 if (iAnimatorControl.isStopped()) |
|
109 { |
|
110 throw new IllegalStateException( |
|
111 /*SF*/"The animator is in the stopped state."/*SF*/); |
|
112 } |
|
113 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "invokeAndWait()"); |
|
114 |
|
115 runnable.run(); |
|
116 } |
|
117 |
|
118 /** |
|
119 * @see javax.microedition.m2g.SVGAnimator#invokeLater() |
|
120 */ |
|
121 public void invokeLater(java.lang.Runnable runnable) |
|
122 { |
|
123 if (runnable == null) |
|
124 { |
|
125 throw new NullPointerException( |
|
126 /*SF*/"The runnable is null."/*SF*/); |
|
127 } |
|
128 if (iAnimatorControl.isStopped()) |
|
129 { |
|
130 throw new IllegalStateException( |
|
131 /*SF*/"The animator is in the stopped state."/*SF*/); |
|
132 } |
|
133 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "invokeLater()"); |
|
134 Thread thread = new Thread(runnable); |
|
135 thread.start(); |
|
136 } |
|
137 |
|
138 /** |
|
139 * @see javax.microedition.m2g.SVGAnimator#pause() |
|
140 */ |
|
141 public void pause() |
|
142 { |
|
143 if (!iAnimatorControl.isPlaying()) |
|
144 { |
|
145 throw new IllegalStateException( |
|
146 /*SF*/"The animator is not in the playing or paused state."/*SF*/); |
|
147 } |
|
148 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "pause()"); |
|
149 iAnimatorControl.pause(); |
|
150 } |
|
151 |
|
152 /** |
|
153 * @see javax.microedition.m2g.SVGAnimator#play() |
|
154 */ |
|
155 public void play() |
|
156 { |
|
157 if (iAnimatorControl.isPlaying()) |
|
158 { |
|
159 throw new IllegalStateException( |
|
160 /*SF*/"The animator is not currently in the stopped or paused state."/*SF*/); |
|
161 } |
|
162 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "play()"); |
|
163 iAnimatorControl.play(); |
|
164 } |
|
165 |
|
166 private void doFinalize() |
|
167 { |
|
168 if (mFinalizer != null) |
|
169 { |
|
170 registeredFinalize(); |
|
171 mFinalizer = null; |
|
172 } |
|
173 } |
|
174 |
|
175 /** |
|
176 * Finalize |
|
177 */ |
|
178 synchronized void registeredFinalize() |
|
179 { |
|
180 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "registeredFinalize()"); |
|
181 iAnimatorControl = null; |
|
182 } |
|
183 |
|
184 /** |
|
185 * @see javax.microedition.m2g.SVGAnimator#setSVGEventListener() |
|
186 */ |
|
187 public void setSVGEventListener(SVGEventListener svgEventListener) |
|
188 { |
|
189 iAnimatorControl.setEventListener(svgEventListener); |
|
190 } |
|
191 |
|
192 /** |
|
193 * @see javax.microedition.m2g.SVGAnimator#setTimeIncrement() |
|
194 */ |
|
195 public void setTimeIncrement(float timeIncrement) |
|
196 { |
|
197 if (timeIncrement <= 0) |
|
198 { |
|
199 throw new IllegalArgumentException( |
|
200 /*SF*/"The time increment is less than or equal to zero."/*SF*/); |
|
201 } |
|
202 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "setTimeIncrement() - " + timeIncrement); |
|
203 iAnimatorControl.setTimeIncrement(timeIncrement); |
|
204 } |
|
205 |
|
206 /** |
|
207 * @see javax.microedition.m2g.SVGAnimator#stop() |
|
208 */ |
|
209 public void stop() |
|
210 { |
|
211 if (iAnimatorControl.isStopped()) |
|
212 { |
|
213 throw new IllegalStateException( |
|
214 /*SF*/"The animator is not in the playing or paused state."/*SF*/); |
|
215 } |
|
216 Logger.LOG(Logger.EJavaUI, Logger.EInfo, "stop()"); |
|
217 iAnimatorControl.stop(); |
|
218 } |
|
219 |
|
220 //-------------------------------------------------- |
|
221 // STATIC METHODS |
|
222 //-------------------------------------------------- |
|
223 /** |
|
224 * Builds animator |
|
225 * @param svgImage - |
|
226 * @return SVGAnimator |
|
227 * @see javax.microedition.m2g.SVGAnimator#createAnimator() |
|
228 */ |
|
229 public static SVGAnimator buildAnimator(SVGImage svgImage) |
|
230 { |
|
231 if (svgImage == null) |
|
232 { |
|
233 throw new NullPointerException(); |
|
234 } |
|
235 return new M2GSVGeSWTAnimator(svgImage); |
|
236 } |
|
237 |
|
238 /** |
|
239 * Builds animator |
|
240 * @param svgImage - |
|
241 * @param componentBaseClass - |
|
242 * @return SVGAnimator |
|
243 * @see javax.microedition.m2g.SVGAnimator#createAnimator() |
|
244 */ |
|
245 public static SVGAnimator buildAnimator( |
|
246 SVGImage svgImage, String componentBaseClass) |
|
247 { |
|
248 if (svgImage == null) |
|
249 { |
|
250 throw new NullPointerException(); |
|
251 } |
|
252 if ((componentBaseClass != null) && |
|
253 (!componentBaseClass.equals(ANIMATOR_CONTROL_BASE_CLASS))) |
|
254 { |
|
255 throw new IllegalArgumentException( |
|
256 /*SF*/"The requested componentBaseClass is not supported by the implementation."/*SF*/); |
|
257 } |
|
258 |
|
259 return buildAnimator(svgImage); |
|
260 } |
|
261 } |