1 package com.tapina.robe.swi;
2
3 import com.tapina.robe.runtime.Condition;
4 import com.tapina.robe.runtime.Environment;
5 import com.tapina.robe.runtime.Instruction;
6 import com.tapina.robe.runtime.UnknownSWIException;
7 import com.tapina.robe.runtime.instruction.SWI;
8
9 import javax.swing.*;
10 import java.lang.reflect.Method;
11 import java.util.logging.Logger;
12
13 /***
14 * Created by IntelliJ IDEA.
15 * User: gareth
16 * Date: Aug 27, 2003
17 * Time: 7:51:39 AM
18 */
19 public final class Hourglass extends SWIHandler {
20 private static Hourglass instance = null;
21 private Hourglass() {
22 }
23
24 public static SWIHandler getInstance() {
25 if (instance == null) {
26 instance = new Hourglass();
27 }
28 return instance;
29 }
30
31 public static int getBase() {
32 return 0x406c0;
33 }
34
35 private static final String[] methodNames = new String[]{
36 "On", "Off", "Smash", "Start", "Percentage", "LEDs", "Colours", "",
37 "", "", "", "", "", "", "", "",
38 "", "", "", "", "", "", "", "",
39 "", "", "", "", "", "", "", "",
40 "", "", "", "", "", "", "", "",
41 "", "", "", "", "", "", "", "",
42 "", "", "", "", "", "", "", "",
43 "", "", "", "", "", "", "", ""
44 };
45
46 public static Method getMethod(Integer offset) throws NoSuchMethodException {
47 return getMethod(methodNames[offset.intValue()]);
48 }
49
50 private static Method getMethod(final String methodName) throws NoSuchMethodException {
51 return Hourglass.class.getMethod(methodName, METHOD_PARAMETERS);
52 }
53
54 public final void On(Environment env) {
55 on();
56 }
57
58 ProgressMonitor progressMonitor = null;
59 int usageCount = 0;
60
61 public final void on() {
62 if (progressMonitor == null) {
63 progressMonitor = new ProgressMonitor(null, "Please wait", null, 0, 100);
64 progressMonitor.setMillisToDecideToPopup(333);
65 progressMonitor.setMillisToPopup(333);
66 }
67 usageCount++;
68 }
69
70 public final void Off(Environment env) {
71 off();
72 }
73
74 public final void off() {
75 if (usageCount > 0) {
76 usageCount--;
77 if (usageCount == 0) {
78 hideHourglass();
79 }
80 }
81 }
82
83 private void hideHourglass() {
84 if (progressMonitor != null) {
85 progressMonitor.setProgress(100);
86 }
87 progressMonitor = null;
88 }
89
90 public final void Smash(Environment env) {
91 smash();
92 }
93
94 public final void smash() {
95 usageCount = 0;
96 hideHourglass();
97 }
98
99 public static void main(String[] args) throws InterruptedException, UnknownSWIException {
100 Environment environment = new Environment(0x8000, new byte[0]);
101 Instruction swiCall;
102 Logger log = Logger.getLogger(Hourglass.class.getName());
103
104 log.info("SWI Hourglass_On");
105 swiCall = new SWI(Condition.AL, 0x406c0);
106 swiCall.checkAndExecute(environment);
107
108 log.info("Sleep for 1s");
109 Thread.sleep(1000);
110
111 log.info("SWI Hourglass_Off");
112 swiCall = new SWI(Condition.AL, 0x406c1);
113 swiCall.checkAndExecute(environment);
114
115 log.info("Sleep for 500ms");
116 Thread.sleep(500);
117 }
118
119 }