1
2
3
4
5
6
7
8
9
10 package edu.uci.ics.jung.visualization.util;
11
12 import edu.uci.ics.jung.algorithms.util.IterativeContext;
13
14
15
16
17
18
19
20 public class Animator implements Runnable {
21
22 protected IterativeContext process;
23 protected boolean stop;
24 protected Thread thread;
25
26
27
28
29 protected long sleepTime = 10L;
30
31
32 public Animator(IterativeContext process) {
33 this(process, 10L);
34 }
35
36 public Animator(IterativeContext process, long sleepTime) {
37 this.process = process;
38 this.sleepTime = sleepTime;
39 }
40
41
42
43
44 public long getSleepTime() {
45 return sleepTime;
46 }
47
48
49
50
51 public void setSleepTime(long sleepTime) {
52 this.sleepTime = sleepTime;
53 }
54
55 public void start() {
56
57 stop();
58 stop = false;
59 thread = new Thread(this);
60 thread.setPriority(Thread.MIN_PRIORITY);
61 thread.start();
62 }
63
64 public synchronized void stop() {
65 stop = true;
66 }
67
68 public void run() {
69 while (!process.done() && !stop) {
70
71 process.step();
72
73 if (stop)
74 return;
75
76 try {
77 Thread.sleep(sleepTime);
78 } catch (InterruptedException ie) {
79 }
80 }
81 }
82 }