home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX1 / TESTVW3.CLS < prev    next >
Text File  |  1991-12-20  |  4KB  |  131 lines

  1.  
  2. ViewManager subclass: #TestView
  3.   instanceVariableNames: 
  4.     'myOdCollection myEntryField myListBox '
  5.   classVariableNames: ''
  6.   poolDictionaries: 
  7.     'PMConstants '  !
  8.  
  9.  
  10. !TestView class methods ! !
  11.  
  12.  
  13.  
  14. !TestView methods !
  15.    
  16. cancel: aPane
  17.         "Private-Clear the contents of the EntryField and reset it."
  18.   
  19.      myEntryField contents:  (myListBox lineAt: myListBox selection).!
  20.  
  21. close:topPane
  22.  
  23.    " Private-Close TopPane. Before do it, 
  24.       And clear the contents of the EntryField."
  25.  
  26.    myEntryField contents: ''.
  27.    self close!
  28.   
  29. myEntryField: aPane
  30.         "Private-Display a text on the entryfield,initially."
  31.  
  32.     aPane contents: 'This is an entryfield'.!
  33.  
  34. myMenu
  35.         "Private - Answer the File menu."
  36.     ^Menu new
  37.         appendItem: '~My Choice' selector: #myMenuMethod ;
  38.       title: '~My Menu'!
  39.   
  40. myMenuMethod
  41.          "This method is activated when 'MyChoice'
  42.           is selected in the pulldown 'My Menu'"
  43.  
  44.          MessageBox
  45.                     titled: 'Gotcha!!!!!!'
  46.                     withText: 'My menu WORKS !!!!!!'
  47.                     style: MbOk | MbIconexclamation.!
  48.   
  49. mySelect: aListBox
  50.  
  51.  
  52.          "This method is activated when a new
  53.           selection in made in listbox"
  54.  
  55.         "Private-Display a text on the entryfield"
  56.  
  57.     myEntryField contents:  (aListBox lineAt: aListBox selection).!
  58.  
  59. myTextList: aListBox
  60.       "Private- Display the contents of myOdCollection on the ListBox"
  61.  
  62.       aListBox contents: myOdCollection.!
  63.    
  64. newItem: aPane
  65.         "Private-Add a new item at myOdCollection."
  66.  
  67.     myOdCollection add:(myEntryField contents).
  68.     myListBox selection:1.!
  69.  
  70. open
  71.         "Open an window containing a ListBox and an EntryField,
  72.           two PushButtons."
  73.  
  74.    | lineHeight charWidth charHeight |
  75.  
  76.     charHeight := SysFontHeight.
  77.     charWidth := SysFontWidth. 
  78.     lineHeight := charHeight + 5. 
  79.     
  80.    "Create an instance of TestOdCollection Class and initialize it."
  81.     myOdCollection:= TestOdCollection new.
  82.     myOdCollection readList.
  83.  
  84.     self
  85.         owner: self;
  86.         label: 'A TEST';
  87.         yourself.
  88.      self when: #close perform: #close: . 
  89.  
  90.     self addSubpane:
  91.         (myListBox:=ListBox new
  92.             owner: self;
  93.             when: #getContents perform: #myTextList: ;
  94.             when: #select perform: #mySelect:;
  95.             framingBlock: [:box | box leftTop
  96.                        extentFromLeftTop:(box width @ (box height // 2))]).
  97.  
  98.     self addSubpane:
  99.         (myEntryField:= EntryField new
  100.            when: #getContents perform: #myEntryField:; 
  101.             framingBlock: [:box |
  102.                 (box leftBottom rightAndUp: (charWidth * 2) @ (lineHeight * 4))
  103.                     extentFromLeftTop: (charWidth * 40 ) @ (charHeight ) ]).
  104.  
  105.         self addSubpane:
  106.         (Button new
  107.             contents: 'NewItem';
  108.             defaultPushButton;
  109.             when: #clicked perform: #newItem:;
  110.             framingBlock: [:box |
  111.                 (box leftBottom rightAndUp: (charWidth * 15) @ (lineHeight * 2))
  112.                     extentFromLeftTop: (charWidth * 9) @ lineHeight ] ).
  113.  
  114.     self addSubpane:
  115.         (Button new
  116.             contents: 'Cancel';
  117.             owner: self;
  118.             when: #clicked perform: #cancel:;
  119.             framingBlock: [:box |
  120.                 (box leftBottom rightAndUp: (charWidth * 30) @ (lineHeight * 2))
  121.                     extentFromLeftTop: (charWidth * 9) @ lineHeight ] ).
  122.  
  123.  
  124.      self openWindow.
  125.      self menuWindow addMenu: self myMenu owner: self.
  126.  
  127.      "Default selection of the item at the first place on the ListBox."
  128.      myOdCollection size > 0
  129.            ifTrue:[    myListBox selection:1.
  130.                       ].! !
  131.