svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / libAnimation / src / com / iver / cit / gvsig / animation / timer / AnimationTimer.java @ 15396
History | View | Annotate | Download (1.35 KB)
1 |
package com.iver.cit.gvsig.animation.timer; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
// this class is only an example. it isn?t used in librarys
|
11 |
public class AnimationTimer implements Runnable { |
12 |
double milis;
|
13 |
private boolean finish; |
14 |
private List callBackList; |
15 |
private Thread thread; |
16 |
|
17 |
|
18 |
/**
|
19 |
* Lanza un timer cada segundo.
|
20 |
*/
|
21 |
public AnimationTimer()
|
22 |
{ |
23 |
|
24 |
} |
25 |
|
26 |
public void run() { |
27 |
while (true) { |
28 |
try {
|
29 |
Thread.sleep((long) milis); |
30 |
synchronized (this) { |
31 |
if (finish) {
|
32 |
break;
|
33 |
} |
34 |
} |
35 |
} catch (InterruptedException e) { |
36 |
|
37 |
e.printStackTrace(); |
38 |
} |
39 |
//Updating
|
40 |
Update(); |
41 |
} |
42 |
} |
43 |
|
44 |
public synchronized void end() { |
45 |
finish = true;
|
46 |
thread.stop(); |
47 |
} |
48 |
|
49 |
|
50 |
private void Update() { |
51 |
// TODO Auto-generated method stub
|
52 |
for (int i = 0; i < callBackList.size(); i++) { |
53 |
IUpdateCallBack element = (IUpdateCallBack) callBackList.get(i); |
54 |
element.update(); |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
public void start(double milis) { |
60 |
this.milis = milis;
|
61 |
|
62 |
// Create the thread supplying it with the runnable object
|
63 |
thread = new Thread(this); |
64 |
|
65 |
// Start the thread
|
66 |
thread.start(); |
67 |
} |
68 |
|
69 |
public void addCallBackObject(IUpdateCallBack object) { |
70 |
if (callBackList == null) |
71 |
callBackList = new ArrayList(); |
72 |
callBackList.add(object); |
73 |
} |
74 |
|
75 |
|
76 |
} |