18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

22 A text user <strong>in</strong>terface<br />

This chapter def<strong>in</strong>es an API (Application Program Interface) for use by an application program that reads<br />

and writes textual <strong>in</strong>formation to and from w<strong>in</strong>dows on a VDU screen. The TUI (Text User <strong>in</strong>terface) uses<br />

the metaphor of non-overlapp<strong>in</strong>g w<strong>in</strong>dows. The application program is written us<strong>in</strong>g an event-driven<br />

regime. In this way, call-back functions are written to implement services requested by a user of the<br />

application.<br />

The next chapter describes <strong>in</strong> detail the implementation of the TUI.<br />

22.1 Specification<br />

A TUI (Text User Interface) provides various types of non-overlapp<strong>in</strong>g w<strong>in</strong>dows on a VDU screen. The w<strong>in</strong>dows<br />

provided are:<br />

• A text w<strong>in</strong>dow <strong>in</strong>to which characters from the <strong>Ada</strong> type Character can be written.<br />

• A dialog w<strong>in</strong>dow that provides a mechanism for a user to enter character data. Associated with a dialog<br />

w<strong>in</strong>dow is a function that is called on completion of the user’s entered data.<br />

• A menu w<strong>in</strong>dow from which a user can select a menu item from a list of available options.<br />

For example, a demonstration application that converts miles <strong>in</strong>to kilometres uses the TUI to <strong>in</strong>put and display<br />

data as follows:<br />

+----------------------------------+<br />

| |<br />

| Miles to kilometres |<br />

| |<br />

+----------------------------------+<br />

#--------------------+ +----------------------------------+<br />

|Dialog| Miles | |Distance <strong>in</strong> miles = 50.00 |<br />

|--------------------| |Distance <strong>in</strong> Kms = 80.47 |<br />

|50.0* | | |<br />

+--------------------+ +----------------------------------+<br />

Note:<br />

A # <strong>in</strong> the top left-hand corner of a w<strong>in</strong>dow signifies which w<strong>in</strong>dow has the focus for <strong>in</strong>put.<br />

The <strong>in</strong>terface for this program consists of three dist<strong>in</strong>ct w<strong>in</strong>dows:<br />

• A text w<strong>in</strong>dow which displays the title of the program<br />

“Miles to kilometres”<br />

• A dialog w<strong>in</strong>dow that solicits <strong>in</strong>put from the user. In this distance <strong>in</strong> miles to be converted <strong>in</strong>to<br />

kilometres.<br />

• A text w<strong>in</strong>dow to display of the results of the conversion.<br />

The TUI <strong>in</strong>terface for writ<strong>in</strong>g to w<strong>in</strong>dows is modelled on the procedure Put <strong>in</strong> the package <strong>Ada</strong>.Text_Io.<br />

Associated with an <strong>in</strong>stance of a Dialog w<strong>in</strong>dow is a call-back function that implements the functionality of the<br />

user <strong>in</strong>teraction. This is often referred to as an event-driven metaphor.<br />

The dialog w<strong>in</strong>dow's call-back function is executed when a user has f<strong>in</strong>ished <strong>in</strong>putt<strong>in</strong>g data <strong>in</strong>to the program.<br />

For example, <strong>in</strong> the miles to kilometres program the dialog w<strong>in</strong>dow's call-back function is executed when a user<br />

presses return complet<strong>in</strong>g the entry of the miles to be converted <strong>in</strong>to kilometres. The call-back function calculates<br />

the conversion to kilometres and displays the answer <strong>in</strong> the result’s w<strong>in</strong>dow.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!