| 971072b by No'am Rosenthal at 2009-11-08 |
1 |
<?xml version="1.0" ?> |
|
2 |
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" |
| 752f94a by No'am Rosenthal at 2009-11-08 |
3 |
initial="root" profile="ecmascript" name="flow"> |
|
4 |
|
| 971072b by No'am Rosenthal at 2009-11-08 |
5 |
<parallel id="root"> |
|
6 |
<state id="ui" initial="calc"> |
|
7 |
<onentry> |
|
8 |
<script>showPopup('Press Spacebar to switch between widgets');</script> |
|
9 |
</onentry> |
|
10 |
<state id="calc"> |
|
11 |
<transition event="WIDGETS.NEXT" target="weather" /> |
|
12 |
</state> |
|
13 |
<state id="weather"> |
|
14 |
<transition event="WIDGETS.NEXT" target="shopping" /> |
|
15 |
</state> |
|
16 |
<state id="shopping"> |
|
17 |
<transition event="WIDGETS.NEXT" target="calc" /> |
|
18 |
</state> |
|
19 |
</state> |
|
20 |
<state id="popup_region" initial="popup_off"> |
|
21 |
<state id="popup_off"> |
|
22 |
<transition event="POPUP.SHOW" target="popup" /> |
|
23 |
</state> |
|
24 |
<state id="popup"> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
25 |
<onentry> |
|
26 |
<script> |
|
27 |
setTimeout(function(){raise("POPUP.HIDE");},2500); |
|
28 |
</script> |
|
29 |
</onentry> |
| 971072b by No'am Rosenthal at 2009-11-08 |
30 |
<transition event="POPUP.HIDE" target="popup_off" /> |
|
31 |
<transition event="KEY.PRESS" target="popup_off" /> |
|
32 |
</state> |
|
33 |
</state> |
|
34 |
<state initial="calc_logic"> |
|
35 |
<datamodel> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
36 |
<data id="long_expr" expr="''" /> |
|
37 |
<data id="short_expr" expr="0" /> |
|
38 |
<data id="res" expr="0" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
39 |
</datamodel> |
|
40 |
<state id="calc_logic" initial="on"> |
|
41 |
<state id="on" initial="ready"> |
|
42 |
<onentry> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
43 |
<send event="DISPLAY.UPDATE" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
44 |
</onentry> |
|
45 |
<state id="ready" initial="begin"> |
|
46 |
<state id="begin"> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
47 |
<transition event="OPER.MINUS" target="negated1" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
48 |
<onentry> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
49 |
<send event="DISPLAY.UPDATE" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
50 |
</onentry> |
|
51 |
</state> |
|
52 |
<state id="result"> |
|
53 |
</state> |
|
54 |
<transition event="OPER" target="opEntered" /> |
|
55 |
<transition event="DIGIT.0" target="zero1"> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
56 |
<assign dataid="short_expr" expr="''" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
57 |
</transition> |
|
58 |
<transition event="DIGIT" target="int1"> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
59 |
<assign dataid="short_expr" expr="''" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
60 |
</transition> |
|
61 |
<transition event="POINT" target="frac1"> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
62 |
<assign dataid="short_expr" expr="''" /> |
| 971072b by No'am Rosenthal at 2009-11-08 |
63 |
</transition> |
|
64 |
</state> |
|
65 |
<state id="negated1"> |
|
66 |
<onentry> |
|
67 |
<assign dataid="short_expr" expr="'-'" /> |
|
68 |
<send event="DISPLAY.UPDATE" /> |
|
69 |
</onentry> |
|
70 |
<transition event="DIGIT.0" target="zero1" /> |
|
71 |
<transition event="DIGIT" target="int1" /> |
|
72 |
<transition event="POINT" target="frac1" /> |
|
73 |
</state> |
|
74 |
<state id="operand1"> |
|
75 |
<state id="zero1"> |
|
76 |
<transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int1" /> |
|
77 |
<transition event="POINT" target="frac1" /> |
|
78 |
</state> |
|
79 |
<state id="int1"> |
|
80 |
<transition event="POINT" target="frac1" /> |
|
81 |
<transition event="DIGIT"> |
|
82 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
83 |
<send event="DISPLAY.UPDATE" /> |
|
84 |
</transition> |
|
85 |
<onentry> |
|
86 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
87 |
<send event="DISPLAY.UPDATE" /> |
|
88 |
</onentry> |
|
89 |
</state> |
|
90 |
<state id="frac1"> |
|
91 |
<onentry> |
|
92 |
<assign dataid="short_expr" expr="_data.short_expr+'.'" /> |
|
93 |
<send event="DISPLAY.UPDATE" /> |
|
94 |
</onentry> |
|
95 |
<transition event="DIGIT"> |
|
96 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
97 |
<send event="DISPLAY.UPDATE" /> |
|
98 |
</transition> |
|
99 |
</state> |
|
100 |
<transition event="OPER" target="opEntered" /> |
|
101 |
</state> |
|
102 |
<state id="opEntered"> |
|
103 |
<transition event="OPER.MINUS" target="negated2" /> |
|
104 |
<transition event="POINT" target="frac2" /> |
|
105 |
<transition event="DIGIT.0" target="zero2" /> |
|
106 |
<transition event="DIGIT" target="int2" /> |
|
107 |
<onentry> |
|
108 |
<raise event="CALC.SUB" /> |
|
109 |
<send event="OP.INSERT"> |
|
110 |
<param name="operator" expr="_event.name" /> |
|
111 |
</send> |
|
112 |
</onentry> |
|
113 |
</state> |
|
114 |
<state id="negated2"> |
|
115 |
<onentry> |
|
116 |
<assign dataid="short_expr" expr="'-'" /> |
|
117 |
<send event="DISPLAY.UPDATE" /> |
|
118 |
</onentry> |
|
119 |
<transition event="DIGIT.0" target="zero2" /> |
|
120 |
<transition event="DIGIT" target="int2" /> |
|
121 |
<transition event="POINT" target="frac2" /> |
|
122 |
</state> |
|
123 |
<state id="operand2"> |
|
124 |
<state id="zero2"> |
|
125 |
<transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int2" /> |
|
126 |
<transition event="POINT" target="frac2" /> |
|
127 |
</state> |
|
128 |
<state id="int2"> |
|
129 |
<transition event="DIGIT"> |
|
130 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
131 |
<send event="DISPLAY.UPDATE" /> |
|
132 |
</transition> |
|
133 |
<onentry> |
|
134 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
135 |
<send event="DISPLAY.UPDATE" /> |
|
136 |
</onentry> |
|
137 |
<transition event="POINT" target="frac2" /> |
|
138 |
</state> |
|
139 |
<state id="frac2"> |
|
140 |
<onentry> |
|
141 |
<assign dataid="short_expr" expr="_data.short_expr+'.'" /> |
|
142 |
<send event="DISPLAY.UPDATE" /> |
|
143 |
</onentry> |
|
144 |
<transition event="DIGIT"> |
|
145 |
<assign dataid="short_expr" expr="_data.short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> |
|
146 |
<send event="DISPLAY.UPDATE" /> |
|
147 |
</transition> |
|
148 |
</state> |
|
149 |
<transition event="OPER" target="opEntered"> |
|
150 |
<raise event="CALC.SUB" /> |
|
151 |
<raise event="OP.INSERT" /> |
|
152 |
</transition> |
|
153 |
<transition event="EQUALS" target="result"> |
|
154 |
<raise event="CALC.SUB" /> |
|
155 |
<raise event="CALC.DO" /> |
|
156 |
</transition> |
|
157 |
</state> |
|
158 |
<transition event="C" target="on"> |
|
159 |
<assign dataid="long_expr" expr="''" /> |
|
160 |
<assign dataid="short_expr" expr="0" /> |
|
161 |
<assign dataid="res" expr="0" /> |
|
162 |
</transition> |
|
163 |
</state> |
|
164 |
<transition event="CALC.DO"> |
|
165 |
<assign dataid="short_expr" expr="''+_data.res" /> |
|
166 |
<assign dataid="long_expr" expr="''" /> |
|
167 |
<assign dataid="res" expr="0" /> |
|
168 |
</transition> |
|
169 |
<transition event="CALC.SUB"> |
|
170 |
<if cond="_data.short_expr!=''"> |
|
171 |
<assign dataid="long_expr" expr="_data.long_expr+'('+_data.short_expr+')'" /> |
|
172 |
</if> |
|
173 |
<assign dataid="res" expr="eval(_data.long_expr)" /> |
|
174 |
<assign dataid="short_expr" expr="''" /> |
|
175 |
<send event="DISPLAY.UPDATE" /> |
|
176 |
</transition> |
|
177 |
<transition event="DISPLAY.UPDATE"> |
|
178 |
<if cond="_data.short_expr == ''"> |
|
179 |
<script>outputText(_data.res);</script> |
|
180 |
<else /> |
|
181 |
<script>outputText(_data.short_expr);</script> |
|
182 |
</if> |
|
183 |
</transition> |
|
184 |
<transition event="OP.INSERT"> |
|
185 |
<if cond="_event.data.operator == 'OPER.PLUS'"> |
|
186 |
<assign dataid="long_expr" expr="_data.long_expr+'+'" /> |
|
187 |
<elseif cond="_event.data.operator=='OPER.MINUS'" /> |
|
188 |
<assign dataid="long_expr" expr="_data.long_expr+'-'" /> |
|
189 |
<elseif cond="_event.data.operator =='OPER.STAR'" /> |
|
190 |
<assign dataid="long_expr" expr="_data.long_expr+'*'" /> |
|
191 |
<elseif cond="_event.data.operator =='OPER.DIV'" /> |
|
192 |
<assign dataid="long_expr" expr="_data.long_expr+'/'" /> |
|
193 |
</if> |
|
194 |
</transition> |
|
195 |
</state> |
|
196 |
</state> |
|
197 |
</parallel> |
| 752f94a by No'am Rosenthal at 2009-11-08 |
198 |
</scxml> |