
Rebuilding the Demo Host Software
A-16
A.4.5
Reacting to Button Clicks
The setEventListeners() function assigns a function to every widget the
user can click. The first such assignment—remembering that "w" is an
alias for the "myWidgets" hash table—is as follows:
w["btnDiscover"].addListener( SWT.Selection, eventFxnBtnDiscover );
That means, when the user clicks the "Discover" button, our
eventFxnBtnDiscover() function is to be called. If you look at the body of
that function further below, you'll see the expected—it calls the
rpc.discover() function, which returns zero or more IP addresses of
targets running the demo (determined by their response to a specific
broadcast message, see Rpc.js for details), and then fills in the
w["cmbDiscover"] drop-down list with those addresses and copies the
first in the list into the "IP address" input fields.
However, setEventListeners() defines shorter functions for events with
simpler actions right on the spot. Take this one for example:
w["btnInVideoBrowse"].addListener( SWT.Selection, function( event ) {
var dialog = new widgets.FileDialog( shell );
var fileName = dialog.open();
if (fileName != null) {
w["cmbInVideo"].add( fileName, 0 );
w["cmbInVideo"].select( 0 );
w["txtInVideoSizeKB"].setText( Math.floor( new java.io.File(
fileName ).length() / 1024 ) );
}
} );
This is a function for the "Browse for Input Video file" button. It opens a
new file dialog, and, if the user has selected a file, it adds the file to the
top of the "input video file" drop-down list and makes it the first choice.
Then, it reads the file's size and shows it in the "txtInVideoSizeKB" read-
only textbox. (The function call java.io.File(fileName).length() returns the
file size in bytes or 0 if the file doesn't exist.) Such versatile Java library
functions make the scripts short.
A.4.6
Exceptions
(C++ and OOP developers can skip this section, since they will be
familiar with the type of exception handling used by JavaScript.)
The APIs provided by the Rpc.js, Fileio.js, and Ipc.js scripts have
functions that do not return success or failure. Instead, if en error occurs,
an "exception" is thrown, either by a system module that the function
Summary of Contents for TMS320DM6437
Page 1: ...TMS320DM6437 DVDP Getting Started Guide Literature Number SPRUEV6 July 2007 ...
Page 20: ...2 8 ...
Page 34: ...3 14 ...
Page 40: ...4 6 ...
Page 63: ......