Moka-Examples.st 4.2 KB

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