Graphical user interface for Data processing
The GUI part of the application is specified as follows:
The form should have a File button, a Close button, and a multiline edit control. The File button allows the user to select a text file. The report on the selected text file is displayed in the multiline edit control.
You need to design the form and define the event handlers.
In this example the GUI definitions will be in a different script from the DP definitions of the previous section to keep clear the distinction between the two parts. Create a new script file and save it as user\textgui.ijs. Open the script and design the form. The File button should have an id of file and the Close button should have an id of close. The large edit control is a multiline edit control that has a class of editm in the New Control dialog. The multiline edit control should have an id of editm (the default is cceditm, so you must specify editm). The form should look like the following:
You need to add event handlers for the Close and File buttons. The code for the event handlers is in the following listing. This listing should be similar to your final cfgui.ijs script.
FILEREP=: noun define pc filerep; pmove 100 200 400 100; bin v; bin h; minwh 34 25;cc file button;cn "File"; minwh 34 25;cc close button;cn "Close"; bin s; bin z; minwh 150 150;cc editm editm;set editm scroll min; bin z; ) filerep_run=: 3 : 0 wd FILEREP NB. initialize form here wd 'pshow;' ) filerep_close=: 3 : 0 wd'pclose' ) filerep_close_button=: 3 : 0 wd'pclose' ) filerep_file_button=: 3 : 0 p =. '"" "" "Text (*.txt)"' fn =. }: wd 'mb open ' , p if. 0 ~: #fn do. wd 'set editm *' , report fn end. )
The only parts that are new are the bin s;,which provides a spacer in the horizontal bin, and the use of the wd 'mbopen' command. The wd 'mbopen' command brings up the common file open dialog box that allows the user to select a file. Local p contains the parameters for the mbopen command. These parameters are critical and must be defined properly. If you want to know more about the mbopen parameters, you can check in the message box section of the Windows Driver in the J Online Documentation located in the help menu of the JQt environment. It turns out that }: must be used to strip off the trailing linefeed that mb open appends to the path.
The result of the mbopen command is the file name selected by the user. If the user pressed cancel in the open dialog the result will be an empty string and there is nothing to do. If fn is not empty then you execute report fn to generate the report and set it into the editm control.
The * in the line wd 'set editm text *' , report fn end. indicates that the rest of the string, which is the result of report fn, is the data to set into the editm multiline edit control.
Run the textdp.ijs and textgui.ijs scripts and if this is a new session load 'files' and load 'misc' then start the application.
Press the File button and select your jpath '~user\text.txt' file and press OK. Try other text files.
The application uses definitions from three scripts: textdp.ijs, textgui.ijs, andfiles.ijs. It makes sense to create a single script that will load all the scripts and then run the application.
Create a new script file, save it as jpath '~user\textapp.ijs', and add the following lines. jpath is a verb which supplies the complete path to the user folder.
NB. this application reports file character frequencies load 'files' 0!:0 < jpath '~user\textdp.ijs' 0!:0 < jpath '~user\textgui.ijs' filerep_run 0
Save the script. Close J and restart it to get a clean slate. Run the application by using Run | Load Script to run the script user\textapp.ijs.
|Primer Index Hover to reveal titles - Click to access -|