home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / SMALTALK / TEXTBOOK / AP03.ST (.txt) < prev    next >
Text File  |  1997-04-22  |  3KB  |  92 lines

  1.  
  2. 'Smalltalk Textbook Appendix 03'!
  3.  
  4.  
  5.  
  6.  
  7.  
  8. Object subclass: #EngiMenuMaker
  9.     instanceVariableNames: ''
  10.     classVariableNames: ''
  11.     poolDictionaries: ''
  12.     category: 'Engi-Interface'!
  13. EngiMenuMaker comment:
  14. '
  15.  
  16. Engi 0.01 (10 January 1994)
  17. Copyright (C) 1994 by Atsushi Aoki
  18.  
  19. '!
  20.  
  21. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  22.  
  23. EngiMenuMaker class
  24.     instanceVariableNames: ''!
  25.  
  26.  
  27. !EngiMenuMaker class methodsFor: 'instance creation'!
  28.  
  29. fromCollection: assocCollection 
  30.     | labels lines values index |
  31.     labels := OrderedCollection new.
  32.     lines := OrderedCollection new.
  33.     values := OrderedCollection new.
  34.     index := 0.
  35.     assocCollection do: [:assoc | assoc isNil
  36.             ifTrue: [lines add: index]
  37.             ifFalse: 
  38.                 [labels add: assoc key.
  39.                 values add: assoc value.
  40.                 index := index + 1]].
  41.     ^PopUpMenu
  42.         labelArray: labels asArray
  43.         lines: lines asArray
  44.         values: values asArray! !
  45.  
  46. !EngiMenuMaker class methodsFor: 'examples'!
  47.  
  48. example1
  49.     "EngiMenuMaker example1."
  50.  
  51.     | collection menu result |
  52.     collection := OrderedCollection new.
  53.     collection add: 'again' -> [Transcript cr; show: 'again'].
  54.     collection add: 'undo' -> [Transcript cr; show: 'undo'].
  55.     collection add: nil.
  56.     collection add: 'copy' -> [Transcript cr; show: 'copy'].
  57.     collection add: 'cut' -> [Transcript cr; show: 'cut'].
  58.     collection add: 'paste' -> [Transcript cr; show: 'paste'].
  59.     collection add: nil.
  60.     collection add: 'do it' -> [Transcript cr; show: 'do it'].
  61.     collection add: 'print it' -> [Transcript cr; show: 'print it'].
  62.     collection add: 'inspect' -> [Transcript cr; show: 'inspect'].
  63.     menu := EngiMenuMaker fromCollection: collection.
  64.     result := menu startUp.
  65.     result value!
  66.  
  67. example2
  68.     "EngiMenuMaker example2."
  69.  
  70.     | collection menu result |
  71.     collection := OrderedCollection new.
  72.     collection add: 'editing' -> 
  73.             [| editing |
  74.             editing := OrderedCollection new.
  75.             editing add: 'again' -> [Transcript cr; show: 'again'].
  76.             editing add: 'undo' -> [Transcript cr; show: 'undo'].
  77.             editing add: nil.
  78.             editing add: 'copy' -> [Transcript cr; show: 'copy'].
  79.             editing add: 'cut' -> [Transcript cr; show: 'cut'].
  80.             editing add: 'paste' -> [Transcript cr; show: 'paste'].
  81.             EngiMenuMaker fromCollection: editing] value.
  82.     collection add: 'execution' -> 
  83.             [| execution |
  84.             execution := OrderedCollection new.
  85.             execution add: 'do it' -> [Transcript cr; show: 'do it'].
  86.             execution add: 'print it' -> [Transcript cr; show: 'print it'].
  87.             execution add: 'inspect' -> [Transcript cr; show: 'inspect'].
  88.             EngiMenuMaker fromCollection: execution] value.
  89.     menu := EngiMenuMaker fromCollection: collection.
  90.     result := menu startUp.
  91.     result value! !
  92.