Home Segments Index Top Previous Next

875: Mainline

THE VIEW MANAGER

The marked line is needed only when you wish to separate the application from the development environment, as explained in Segment••missing reference••.

CalorieViewManager class definition
ViewManager subclass: #CalorieViewManager
  instanceVariableNames: 'food foodList'
  classVariableNames: ''
  poolDictionaries: ''
CalorieViewManager method definition • instance
initializeMeter: theMeter
  theMeter setMin: 0; setMax: 100;
           setTitle: 'Calorie Meter';
           event: #display.
CalorieViewManager method definition • instance
initializeListBox: theListBox
  foodList :=
   (Food collectFrom: 'c:\test\vtbls.dta').
  theListBox contents: (foodList collect: [:p | p name]).
CalorieViewManager method definition • instance
itemSelected: theListBox
  food := foodList at: theListBox selection.
  (self paneNamed: 'CalorieMeter')
    setValue: food tCalories;
    event: #display.
CalorieViewManager method definition • instance
callDrawMeter: thePane
  thePane drawMeter.
CalorieViewManager method definition • instance
resetListBox
  | theFileDialog file |
  (theFileDialog := FileDialog new)
    fileSpec: '*.dta';
    open.
  (file := theFileDialog file) notNil
    ifTrue: [foodList := (Food collectFrom: file).
              (self paneNamed: 'ListBox')
                contents: (foodList collect: [:p | p name]).
              (self paneNamed: 'CalorieMeter')
                 setValue: nil; event: #display].
CalorieViewManager method definition • instance
createViews
  | theTopPane theListBox theMeterPane theMenuWindow |
  "Set up all panes"
  self addView: (theTopPane := TopPane new).
  theListBox := ListBox new.
  theMeterPane := MeterGraphPane new.
  "Set up the top pane"
  theTopPane owner: self;
    labelWithoutPrefix: 'Demonstration Window';
    noSmalltalkMenuBar;
    addSubpane: theListBox;
    addSubpane: theMeterPane;
    menuWindow: (theMenuWindow := MenuWindow new);
    when: #close perform: #close:;                              
    framingRatio: (1/4 @ (1/3) rightBottom: 3/4 @ (2/3)).  
  "Set up the menu window" 
  theMenuWindow addMenu:                                                 
    (Menu new                                                            
       title: '~Options';                                                
       owner: self;                                                      
       appendItem: '~Food type' selector: #resetListBox;                 
       appendSubMenu: (Menu new                                          
                         title: '~Mode';                                 
                         owner: self;                                    
                         appendItem: '~Fat calories' selector: nil;      
                         appendItem: '~Total calories' selector: nil)).  
  "Set up the list-box pane" 
  theListBox owner: self; 
    paneName: 'ListBox';                                                 
    when: #getContents perform: #initializeListBox:;  
    when: #select perform: #itemSelected:;               
    framingRatio: (2/3 @ 0 rightBottom: 1 @ 1).                  
  "Set up the meter pane" 
  theMeterPane owner: self; 
    paneName: 'CalorieMeter';                                            
    noScrollBars;  
    when: #getContents perform: #initializeMeter:;  
    when: #display perform: #callDrawMeter:;  
    framingRatio: (0 @ 0 rightBottom: 2/3 @ 1).