1
0

Moka-Examples.st 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. Smalltalk createPackage: 'Moka-Examples'!
  2. MKObservable subclass: #MKClassesListBuilder
  3. instanceVariableNames: ''
  4. package: 'Moka-Examples'!
  5. !MKClassesListBuilder methodsFor: 'as yet unclassified'!
  6. build
  7. MKPaneView new
  8. height: 150;
  9. addView: ((MKScrollDecorator decorate:
  10. (MKListView
  11. model: MKClassesModel new
  12. collectionAspect: #classes
  13. selectionAspect: #selectedClass))
  14. left: 4;
  15. top: 4;
  16. bottom: 4;
  17. right: 0.5;
  18. yourself);
  19. addView: (MKPanelView new
  20. left: 0.5;
  21. top: 4;
  22. right: 4;
  23. bottom: 4;
  24. addView: (MKSourceListView
  25. model: MKClassesModel new
  26. collectionAspect: #classes
  27. selectionAspect: #selectedClass);
  28. yourself);
  29. render
  30. ! !
  31. !MKClassesListBuilder class methodsFor: 'as yet unclassified'!
  32. initialize
  33. self new build
  34. ! !
  35. MKObservable subclass: #MKClassesModel
  36. instanceVariableNames: 'classes selectedClass'
  37. package: 'Moka-Examples'!
  38. !MKClassesModel methodsFor: 'as yet unclassified'!
  39. classes
  40. ^ Smalltalk current classes
  41. !
  42. selectedClass
  43. ^ selectedClass ifNil: [ self classes first ]
  44. !
  45. selectedClass: aClass
  46. selectedClass := aClass.
  47. self changed: #selectedClass
  48. ! !
  49. Object subclass: #MKCounterBuilder
  50. instanceVariableNames: 'counter'
  51. package: 'Moka-Examples'!
  52. !MKCounterBuilder methodsFor: 'accessing'!
  53. build
  54. | pane splitter |
  55. splitter := MKVerticalSplitView new
  56. top: 200;
  57. bottomThickness: 50;
  58. bottom: 0;
  59. yourself.
  60. pane := MKPanelView new.
  61. pane addView: ((MKHeadingView model: self counter aspect: #count)
  62. level: 3;
  63. top: 0;
  64. left: 8;
  65. height: 28;
  66. yourself).
  67. pane addView: ((MKButtonView model: self counter aspect: #increase)
  68. label: 'Increase';
  69. top: 50;
  70. left: 8;
  71. yourself).
  72. pane addView: ((MKButtonView model: self counter aspect: #decrease)
  73. label: 'Decrease';
  74. default: true;
  75. top: 50;
  76. left: 92;
  77. yourself).
  78. pane addView: ((MKDropdownView
  79. model: self counter
  80. collectionAspect: #options
  81. selectionAspect: #selectedOption)
  82. left: 176;
  83. top: 50;
  84. yourself).
  85. pane addView: ((MKInputView model: self counter aspect: #text)
  86. top: 100;
  87. left: 8;
  88. yourself).
  89. pane addView: ((MKInputView model: self counter aspect: #text)
  90. top: 150;
  91. left: 8;
  92. triggerChangeOnAnyKey;
  93. yourself).
  94. pane addView: ((MKTextAreaView model: self counter aspect: #text)
  95. top: 200;
  96. left: 8;
  97. yourself).
  98. pane addView: ((MKCheckboxView model: self counter aspect: #checked)
  99. top: 300;
  100. left: 8;
  101. yourself).
  102. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  103. top: 350;
  104. centerX: 0;
  105. yourself).
  106. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  107. top: 380;
  108. centerX: -50;
  109. yourself).
  110. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  111. top: 410;
  112. centerX: 50;
  113. yourself).
  114. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  115. right: 4;
  116. centerY: 0;
  117. yourself).
  118. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  119. right: 4;
  120. centerY: 30;
  121. yourself).
  122. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  123. right: 4;
  124. centerY: -30;
  125. yourself).
  126. pane addView: ((MKDropdownView
  127. model: self counter
  128. collectionAspect: #options
  129. selectionAspect: #selectedOption)
  130. left: 4;
  131. top: 440;
  132. yourself).
  133. splitter firstView: ((MKHorizontalSplitView
  134. firstView: (MKScrollDecorator decorate: pane)
  135. secondView: MKLayoutView new)
  136. leftThickness: 300;
  137. top: 0;
  138. bottom: 0;
  139. yourself).
  140. splitter secondView: MKLayoutView new.
  141. splitter render
  142. !
  143. counter
  144. ^ counter ifNil: [ counter := MKCounterModel new ]
  145. ! !
  146. !MKCounterBuilder class methodsFor: 'initialization'!
  147. initialize
  148. self new build
  149. ! !
  150. MKObservable subclass: #MKCounterModel
  151. instanceVariableNames: 'count text checked options selectedOption'
  152. package: 'Moka-Examples'!
  153. !MKCounterModel methodsFor: 'accessing'!
  154. options
  155. ^ #('foo' 'bar' 'baz')
  156. !
  157. selectedOption
  158. ^ selectedOption ifNil: [ selectedOption := self options last ]
  159. !
  160. selectedOption: aString
  161. selectedOption := aString.
  162. self changed: #selectedOption
  163. ! !
  164. !MKCounterModel methodsFor: 'actions'!
  165. checked
  166. ^ checked ifNil: [ false ]
  167. !
  168. checked: aBoolean
  169. checked := aBoolean.
  170. self changed: 'checked'
  171. !
  172. count
  173. ^ count asString
  174. !
  175. decrease
  176. count := count - 1.
  177. self changed: #count
  178. !
  179. increase
  180. count := count + 1.
  181. self changed: #count
  182. !
  183. text
  184. ^ text ifNil: [ '' ]
  185. !
  186. text: aString
  187. text := aString.
  188. self changed: 'text'
  189. ! !
  190. !MKCounterModel methodsFor: 'initialization'!
  191. initialize
  192. super initialize.
  193. count := 0
  194. ! !