User's Guide

Implementing the remaining ten methods

Now that you have implemented open, you can implement the remaining ten methods of class Chooser. The first seven methods define different parts of the user interface. The remaining three methods add items to a list box and perform functions when a push button is pressed or when the window closes.

Method createWindow

Method createWindow defines the window for DevelopChooser. To implement the method, do the following:

  1. From the Applications Browser opened on DevelopChooser, select public underneath the list of methods so the method settings change to private and instance.
  2. Add a new category: Window Creation.
  3. From the Methods menu, select New Method Template.
  4. Revise the displayed template so it reads as follows:

    Method createWindow

    createWindow
       "Private - Creates a window."
       shell := CwTopLevelShell
          createApplicationShell: 'shell'
          argBlock: [:w | w
             width: 220;
             height: 175].
       shell
          title: 'Applications';
          addCallback: XmNdestroyCallback
          receiver: self
          selector: #destroyCallback:clientData:callData:  "Call if window closes"
          clientData: nil.
    
  5. Save the method. If you typed in the text shown above, createWindow is displayed in the list of methods.

Follow the above steps to create the following six more methods for the Window Creation category.

Method createForm

createForm
   "Private - Creates a form to hold other user interface elements."
   widgetManager := shell
      createForm: 'widgetManager'    "Positions the label, list box, and button"
      argBlock: nil.
   widgetManager manageChild.

Method createLabel

createLabel
   "Private - Creates a label."
   instructions := widgetManager
      createLabel: 'Select an application: '
      argBlock: [:w | w
         marginHeight: 10;
         leftAttachment: XmATTACHFORM;
         topAttachment: XmATTACHFORM ;
         rightAttachment: XmATTACHFORM].
   instructions manageChild.

Method createList

createList
   "Private - Creates a list box to hold application names."
   listBox := widgetManager "Define a list box."
      createScrolledList: 'listBox'
      argBlock: [:w | w
         items: self addApplicationsToList;         "Add list of applications"
         visibleItemCount: 5;
         selectionPolicy: XmEXTENDEDSELECT].
   listBox parent
      topAttachment: XmATTACHWIDGET;
      topWidget: instructions;
      leftAttachment: XmATTACHFORM;
      rightAttachment: XmATTACHFORM.
   listBox
      addCallback: XmNdefaultActionCallback
      receiver: self
      selector: #executeCallback:clientData:callData:  "Call if button pressed"
      clientData: nil.
   listBox manageChild.

Method createButton

createButton
   "Private - Define a push button."
   openButton := widgetManager
      createPushButton: 'Open'
      argBlock: [:w | w
         leftAttachment: XmATTACHFORM;
         topAttachment: XmATTACHWIDGET;
         topWidget: listBox;
         rightAttachment: XmATTACHFORM;
         bottomAttachment: XmATTACHFORM].
      openButton
         alignment: XmALIGNMENTCENTER;
         addCallback: XmNactivateCallback
         receiver: self
         selector: #executeCallback:clientData:callData:
         clientData: nil;
   manageChild.

Method displayWindow

displayWindow
   "Private - Show the window."
   shell realizeWidget.

Method setCursorBusy

setCursorBusy
   "Private - Create a cursor."
   busyCursor := shell display createFontCursor: XCWatch.

Method addApplicationsToList

Method addApplicationsToList defines what application names are shown in the list box. To implement it, do the following:

  1. From the Applications Browser opened on DevelopChooser, select public underneath the list of methods so the method settings change to private and instance.
  2. Add the category List Operations.
  3. From the Methods menu, select New Method Template.
  4. Revise the displayed template so it reads as follows:
    addApplicationsToList
      "Private - Answer a list of application classes to go into the list box."
      ^#(
        Stopwatch
        TextEditor
        TimeLogger) select: [:className |
          (Smalltalk classAt: className asSymbol) notNil]
    
  5. Save the method.

Stopwatch, TextEditor, and TimeLogger are the names of main classes in other applications that you can create by completing the examples in this book.

Method destroyCallback:clientData:callData:

The method destroyCallback:clientData:callData: enables you to close the window for DevelopChooser when you are finished using it. To implement the method, do the following:

  1. Ensure that the method settings refer to private instance methods and add the category Event Handlers.
  2. From the Methods menu, select New Method Template.
  3. Type the following into the source pane:
    destroyCallback: aWidget clientData: clientData callData: callData
      "Private - The receiver has been destroyed, free all resources."
      busyCursor freeCursor
    
  4. Save the method.

Method executeCallback:clientData:callData:

The method executeCallback:clientData:callData: enables you to open one of the applications named in the list box. To implement the method, do the following:

  1. Ensure that the method settings refer to private, instance methods in the category Event Handlers.
  2. From the Methods menu, select New Method Template, Or, you can simply delete the current text.
  3. Type the following into the description pane:
    executeCallback: aWidget clientData: aString callData: callData
      "Private - Open the selected application."
      listBox selectedItems do: [:className |
        (Smalltalk classAt: className asSymbol) new open].
    
  4. Save the method.

Note the words new open in this method. The classes Chooser, Stopwatch, TextEditor, and TimeLogger, when completed, each open an instance when their class name followed by new open is evaluated in a Transcript or Workspace window.

Tips
If you are using views created with the Composition Editor, you can generally open the views by replacing new open with newPart openWidget.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]