2
0

Moka-Examples.st 4.1 KB

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