> From: bob therriault
> 
> My questions.
> 
> 1. Any comments on my approach and style are welcome. I seek guidance.

Here is a slightly different take on your script. The biggest differences: 

* the display verb takes a right argument
* It uses the Unicode box drawing chars if specified by the user's session.
   wd 'set tdisp *', ,LF,~"1 u...@ucpboxdraw_jijs_"1 ":STYLE <'ZZZ'
* It simplifies the event handlers for the radiobuttons by reading which one is 
selected in the update verb.

coclass 'rgtVisual'
NB. ---------------------------------------------------------
NB. This script creates a form that takes tacit sentences
NB. entered by the user in a text box and displays the
NB. selected format in a listbox.
NB. ---------------------------------------------------------

style=: 5!:   NB. adverb

DISPLAY=: 0 : 0
pc display dialog;
xywh 291 167 44 12;cc cancel button leftmove topmove rightmove bottommove;cn 
"Close";
xywh 9 156 216 22;cc box edit topmove rightmove bottommove;
xywh 248 24 60 11;cc rbFormatBox radiobutton leftmove rightmove;cn "Box Format";
xywh 248 40 60 11;cc rbFormatLinear radiobutton leftmove rightmove group;cn 
"Linear Format";
xywh 248 55 60 11;cc rbFormatTree radiobutton leftmove rightmove group;cn "Tree 
Format";
xywh 248 72 60 11;cc rbFormatParen radiobutton leftmove rightmove group;cn 
"Paren Format";
xywh 240 11 95 80;cc format groupbox leftmove rightmove;cn "Display Style";
xywh 0 0 225 150;cc tdisp listbox ws_hscroll ws_vscroll lbs_multiplesel 
rightmove bottommove;
pas 6 6;pcenter;
rem form end;
)

NB. ---------------------------------------------------------
NB. form creation
NB. ---------------------------------------------------------

NB. box=: 'NB. Function here'

display_run=: 3 : 0
wd DISPLAY
wd 'set box "',y,'";'
wd 'setfont box ',FIXFONT,';setfocus box;' NB. FIXFONT is specified in user 
session
wd 'setfont tdisp ',FIXFONT,'; setenable tdisp 1;'
wd 'set rbFormatBox 1;'
RBFORMAT=: 'rbFormat'&,&.> ;:'Box Tree Linear Paren'
update y
wd 'pshow;'
)

display_close=: 3 : 0
  wd'pclose'
)

NB. ---------------------------------------------------------
NB.  repaint if the form already exists, otherwise create it
NB. ---------------------------------------------------------

display=: 3 : 0
try.
   wd 'psel display;'
   if. 0=#y do. y=. box end.
   wd 'set box "',y,'";'
   update y
catch.
   display_run y          NB. create form
end.
)

NB. ---------------------------------------------------------
NB. repaint tdisp according to STYLE of box contents
NB. ---------------------------------------------------------

update=: 3 : 0
try.
  sidx=. {. 2 4 5 6 2 {~ I. 99".> RBFORMAT wdget wdq 
  ".'ZZZ=. ' , y NB. ZZZ is a global dummy that holds the tacit entry
  wd 'set tdisp *', ,LF,~"1 u...@ucpboxdraw_jijs_"1 ": sidx style <'ZZZ'
  catch.
  wd 'set tdisp *',13!:12 ''
end.
)

NB. ---------------------------------------------------------
NB. event controls for objects on the text form
NB. ---------------------------------------------------------


display_cancel_button=: display_close

display_box_button=: display
display_rbFormatLinear_button=: display
display_rbFormatBox_button=: display
display_rbFormatTree_button=: display
display_rbFormatParen_button=: display

display_z_=: display_rgtVisual_

NB. display ''


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to