source: osm/applications/editors/josm/plugins/calculator/src/calc/CalcPlugin.java@ 23163

Last change on this file since 23163 was 23163, checked in by postfix, 14 years ago
File size: 1.1 KB
Line 
1package calc;
2
3import toms.plug.ifc.Pluggable;
4import toms.plug.ifc.PluginManager;
5
6public class CalcPlugin implements Pluggable {
7
8 private Calculator calc;
9 private PluginManager manager;
10 private boolean running = false;
11
12 public CalcPlugin() {
13 this.calc = new Calculator();
14 }
15
16 @Override
17 public boolean start() {
18 this.running = true;
19 new Thread(new Runnable() {
20
21 @Override
22 public void run() {
23 int one = 0;
24 int two = 0;
25 int res = 0;
26
27 while(CalcPlugin.this.running) {
28 one = (int)(Math.random() * 1000);
29 two = (int)(Math.random() * 1000);
30
31 res = CalcPlugin.this.calc.add(one, two);
32
33 CalcPlugin.this.manager.showVisualMessage(one + " + " + two + " = " + res);
34
35 // sleep a little bit
36 try {
37 Thread.sleep(res);
38 } catch (InterruptedException e) {
39 e.printStackTrace();
40 }
41 }
42 }
43
44
45 }).start();
46
47 return true;
48 }
49
50 @Override
51 public boolean stop() {
52 this.manager.showVisualMessage("Calculation stopped");
53 this.running = false;
54
55 return true;
56 }
57
58 @Override
59 public void setPluginManager(PluginManager manager) {
60 this.manager = manager;
61 }
62
63}
Note: See TracBrowser for help on using the repository browser.