The To-Do List Application

The best way to learn about visual programming is to do it. The following sections guide you through using VisualAge to develop a simple or advanced To-Do List application. The simple application allows you to add items to or remove items from the list. The advanced application allows you to save the list for use now or later.

Creating a New Visual Part for the To-Do List Application

Create a To-Do project and a To-Do List visual part through the IDE SmartGuides:

  1. In the Project name field of the Project SmartGuide, enter ToDoList.icc.
  2. On the Target Type panel, select the Add Target button and the Target Smart Guide appears.
  3. In the Target name field enter ToDoList.exe.
  4. In the Program Type list box select IOC application and select Next.
  5. On the Part Type panel, select the Create part button and the Parts SmartGuide appears.
  6. In the Visual part name field, enter ToDoList and select Next twice.
  7. On the Client Area panel, select ICanvas and then OK and the new part appears in the Current parts list of the Part Type panel.
  8. Select OK and the Target Type panel appears. Select Finish and open the project in the IDE.

In the IDE Project panel, select the Parts button. If no parts appear in the left panel, right click in that panel and select refresh view. When the part appears, select it and select Edit part from the right panel and the Composition Editor opens with the new visual part.

Change the window name to To-Do List by holding the Alt key and clicking the pointer over the title bar. Delete the existing text and enter the new text. To save the change, hold shift and press enter. This is called direct edit.

Placing Parts in the To-Do List Application Window

After creating your new visual part, you can place parts in the application window.

Placing a Static Text Part in the To-List Application Window:

  1. Select the Data entry category, from the left column of the parts palette.
  2. Select the IStaticText* icon, from the right column of the parts palette. As you move the mouse pointer over the free-form surface it changes to crosshairs, indicating that the mouse pointer is loaded with the IStaticText* part.
  3. Place the crosshairs in the upper-left corner of the To-Do List application window and click mouse button 1. A static text part appears in the window.
  4. As you did the window name above, direct edit the text of the static text part to To-Do Item:.

Placing an Entry Field in the To-Do List Application Window:

  1. From the Data Entry category, select the IEntryField* icon, from the right column of the parts palette.
  2. Place the crosshairs beneath the first static text part and click mouse button 1. The entry field part appears beneath the static text part.

Placing Another Static Text Part in the To-Do List Application Window:

  1. As you did with the first static text part, place the second static text part in the To-Do List application window.
  2. Change the text of the static text part to To-Do List:

Placing a List Box in the To-Do List Application Window:

Because the to-do list consists of a list of text strings, you will store that list in an IListBox* part. To place a list box part in the To-Do List application window:

  1. Select the Lists category from the left column of the parts palette.
  2. Select the IListBox* icon from the right column of the parts palette.
  3. Place the crosshairs below the second static text part and click mouse button 1. The list box part appears beneath the second static text part.

Placing the Push Buttons in the To-Do List Application Window:

  1. Select the Buttons category, from the left column of the parts palette.
  2. Select the IPushButton* icon, from the right column of the parts palette.
  3. Select Sticky from the bottom left side of the parts palette area to pick up more than one part.
  4. Place the crosshairs below the lower-left corner of the list box and click mouse button 1. The first push button part appears in the window.
  5. Place the crosshairs to the right of the first push button and click mouse button 1. The second push button appears in the window.
  6. Deselect Sticky to unload the pointer.
  7. Change the text of the first push button to Add. You may also use the direct edit technique on push buttons.
  8. Change the text of the second push button to Remove.

Resizing and Aligning the Parts in the To-Do List Application

Once you have placed all the parts that you need in the application window, you should resize and align them.

Resizing the To-Do List Application Window:

  1. Select the application window by clicking mouse button 1 on the title bar.
  2. Move the mouse pointer over the selection handle on the lower-right corner of the application window.
  3. Press and hold mouse button 1.
  4. Resize the application window by dragging the mouse pointer towards the left until it is the size you want.

You can resize the window any time during the creation process. To size the window in only one direction, either horizontally or vertically, hold down the Shift key while dragging the mouse pointer.

Matching the Widths of Parts in the To-Do List Application :

  1. Select the list box and drag the right bottom selection handle to the width you want the box.
  2. Select the entry field.
  3. To select the anchor part, which is the part used to determine placement or size, do the following:

    Solid selection handles, like those on the list box, means that the part is the anchor part. Therefore, any sizing actions performed cause the entry field to match the size of its anchor part, the list box.

  4. From the tool bar or the Tools drop-down, select Match Width. The width of the entry field changes to match that of the list box.

Repeat these steps with the Add and Remove push buttons to match their widths.

Dragging and Dropping Parts in the To-Do List Application Window:

Note: The following instructions are for moving multiple parts simultaneously. If you want to move one part at a time, skip the first step.
  1. Select all of the parts you want to drag using the multiple parts selection technique for OS/2 or Windows (see Selecting Parts to review).
  2. Move the mouse pointer over one of the parts that you selected to drag.
  3. Press and hold mouse button 2 in OS/2 or mouse button 1 in Windows and move the mouse cursor. The Composition Editor displays an outline of the parts that you are dragging.
  4. Move the outline to the place where you want to drop the parts and release the mouse button. The parts appear in their new location.

Centering the Entry Field and List Box Within the To-Do List Application Window:

  1. Select the entry field.
  2. Select the Distribute Horizontally tool, from the row of icons on the tool bar. The Composition Editor centers the entry field between the left and right borders of the application window.
  3. Select the list box and then the entry field, making the entry field the anchor part. Use the multiple part selection technique you learned previously.
  4. Select the Align Center tool, from the row of icons on the tool bar. The list box is centered beneath the entry field.

Aligning the Left Edges of the Parts in the To-Do List Application :

  1. Select both static text parts, the list box, and then select the entry field, making the entry field the anchor part.
  2. Select the Align Left tool, from the row of icons on the tool bar. The first static text part is aligned even with the left edge of the entry field.

Aligning the Top Edges of the Push Buttons in the To-Do List Application:

  1. Select Add and then select Remove.
  2. Select the Align Top tool. The Composition Editor aligns the Add push button even with the top of the Remove push button.

Centering the Push Buttons in the To-Do List Application :

  1. Select both push buttons. You can make either push button the anchor part.
  2. Press and hold mouse button 2 in OS/2 or mouse button 1 in Windows and position the push buttons midway between the bottom edge of the list box and the bottom window border.
  3. When the push buttons are in place, release the mouse button.

Spacing the Push Buttons in the To-Do List Application:

  1. Select both push buttons. You can make either push button the anchor part.
  2. Select the Distribute Horizontally tool. The Composition Editor spaces both push buttons evenly across the application window.

Connecting the Parts in the To-Do List Application

You can now connect the parts so that your application can add and remove items from the to-do list. You need to connect the push buttons to the list box and entry field. The following steps show you how to do this.

Connecting the Add Push Button to the To-Do List Application List Box:

  1. With the mouse pointer over the Add push button, click mouse button 2. A pop-up menu appears.
  2. Select Connect. A cascaded menu, called the connection menu, of the Add push button is displayed.
  3. Select the buttonClickEvent feature. Selecting the buttonClickEvent feature means that you want something to happen whenever a user selects this push button. The mouse pointer changes to look like a spider, indicating that you may select another feature.
  4. Move the mouse pointer to the list box and click mouse button 1. A pop-up menu appears showing the connection menu of the list box.
  5. Select the addAsLast action. Selecting the addAsLast action means that you want new items to be added to the end of the to-do list whenever a user selects Add.
  6. Move the mouse pointer to the dashed connection line between Add and the list box. A dashed line means that the connection is incomplete. The connection is supposed to add something to the list box when you select Add, but you have not yet supplied what needs to be added.
  7. Open the connections menu by holding down the Alt key, clicking mouse button 2, and releasing the Alt key immediately afterward. The pop-up menu for the connection appears.
  8. Select the text parameter. Connecting the text parameter to the entry field provides a value for the connection line and changes its appearance from dashed to solid.
  9. Move the mouse pointer over the entry field, and click mouse button 1. The Composition Editor displays the connection menu for the list box.
  10. Select the text attribute. Selecting the text attribute here means that you want to pass the text entered in the entry field to the text parameter of the addAsLast action. When the addAsLast action is called, whenever you select Add, the text string is added to the end of the to-do list.

Connecting the Remove Push Button to the To-Do List Application List Box:

  1. With the mouse pointer over the Remove push button, hold down the Alt key and click mouse button 2. The Composition Editor displays the connection menu for the Remove push button.

  2. Select the buttonClickEvent feature.

  3. Move the mouse pointer to the list box and click mouse button 1. The Composition Editor displays the connection menu for the list box.

  4. Select the remove action. Selecting the remove action means that you want your application to remove the selected item in the to-do list whenever a user selects Remove. Once again, the connection is incomplete.

  5. Move the mouse pointer to the connection between the Remove push button and the list box.

  6. Hold down the Alt key and click mouse button 2. The Composition Editor displays the connection menu for the connection.

  7. Select the index parameter. Connecting the index parameter to the list box provides a value for the connection line and changes its appearance from dashed to solid.

  8. Move the mouse pointer over the list box and click mouse button 1. The Composition Editor displays the connection menu for the list box.

  9. Select the selection attribute. Selecting the selection attribute means that you want to pass the index of the selected item in the list box to the index parameter of the remove action. The remove action uses this index to determine which item to remove when you select Remove.

Now that you have made all of the connections, the next step is Building and Executing Your To-Do List Application.