Moka-Examples.st 4.2 KB

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