> > From: bob therriault <bobtherria...@mac.com>
> > Sent: Monday, April 27, 2009 1:20:09 PM
> >
> > <http://www.jsoftware.com/pipermail/programming/2009-April/014508.html>
> >
> > Recently I posted the following script to the chat forum, as my
> > previous post to this forum was unsuccessful ( resubscribing seemed
> > to fix this). It is meant to allow a tacit expression to be viewed 
> > in a number of formats. It is not complex, but did allow me to 
> > stretch my abilities with the form editor (my first version 
> > displayed in an isigraph, until I realized that listboxes would 
> > automatically include trackbars for oversized displays).
> >
> > 1. Any comments on my approach and style are welcome. I seek
> >    guidance.
> 
> > From: "Sherlock, Ric" <r.g.sherl...@massey.ac.nz>
> > Sent: Tuesday, April 28, 2009 4:09:40 PM
> >
> > <http://www.jsoftware.com/pipermail/programming/2009-April/014542.html> 
> >
> > 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.
> 
> From: Oleg Kobchenko
> Sent: Saturday, 2 May 2009 21:14
> <http://www.jsoftware.com/pipermail/programming/2009-May/014604.html>
>
> Here's the script taken from Ric with "a few" changes.
> 
> There are two stages in APL/J programming: solve the problem
> and then rewrite the code until it cannot be any shorter. :)
> 
>  * no comments unless absolutely unnecessary or revise code
>  * show your intention with code and naming, see "display=: ..."
>  * use first indent instead of flower boxing
>  * /!\ different verbs for different APIs: cannot use the same
>     for user API and event handling
>  * in general, streamline call flow: trace display..update paths
>  * initialize control names in form locale when calling a handler
>    verb outside event, such as when form is created ("syschild" and
> "box")
>  * no need for "Close" button, window frame already has one
>  * "Cancel" key is for child dialogs, in main form, use Cmd+W or Alt+F4
>  * use array of control names to assign event handlers programmatically
>  * typical use exemplified, as in: display '+/ % #'
>  * employ "once and only once", see how syschild assigned and next line
>  * clear traces of globals to avoid error on first use
>  * "display" name is too generic, should be in style of "disprep" or so
>  * finally: (note to self) test ad lib changes before sending :)
> 

Thanks Oleg. Very instructive as always! 

Below I have added the idea of displaying multiple styles at once to the form. 
I had to go back to using wd 'qd' to get the status of all checkboxes though.

NB.========================================================================

coerase<'rgtVisual' NB. debug - clear traces of globals
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. ---------------------------------------------------------

styles=: (4 : 0)"0 _
  ".'zzz=. ' , y
  res=. 5!: x <'zzz'
  <LF,~ , ,&l...@ucpboxdraw_jijs_"1 ": res
)

DISPLAY=: 0 : 0
pc display dialog;
xywh 9 156 216 22;cc box edit topmove rightmove bottommove;
xywh 248 24 60 11;cc cbFormatBox checkbox leftmove rightmove;cn "Box Format";
xywh 248 40 60 11;cc cbFormatLinear checkbox leftmove rightmove group;cn 
"Linear Format";
xywh 248 55 60 11;cc cbFormatTree checkbox leftmove rightmove group;cn "Tree 
Format";
xywh 248 72 60 11;cc cbFormatParens checkbox leftmove rightmove group;cn 
"Parens Format";
xywh 240 11 95 80;cc format groupbox leftmove rightmove;cn "Display Style";
xywh 0 0 225 150;cc tdisp editm ws_hscroll ws_vscroll es_readonly rightmove 
bottommove;
pas 6 6;pcenter;
rem form end;
)

FORMATS=: ;:'Box Linear Tree Parens'
RBFORMAT=: 'cbFormat'&,each FORMATS

display_run=: 3 : 0
  wd DISPLAY
  wd 'set box *',y
  wd 'setfont box ',FIXFONT,'; setfocus box;'
  wd 'setfont tdisp ',FIXFONT,'; setenable tdisp 1;'
  syschild=: 0{::RBFORMAT
  wd 'set ',syschild,' 1;'
  box=: y
  update ''
  wd 'pshow;'
)

display_resume=: 3 : 0
  wd 'psel display'
  wd 'set box *',box=: y
  update''
)

display_close=: 3 : 0
  wd'pclose'
)

update=: 3 : 0
try.
  sidx=. 2 5 4 6 #~ 99".> RBFORMAT wdget wd 'qd'
  wd 'set tdisp *', utf8 ; sidx styles box
  catch.
  wd 'set tdisp *',13!:12 ''
end.
)

display_box_button=: update
('display_'&,each RBFORMAT,each<'_button')=: update

display=: display_run`display_res...@.((<'display') e. {."1...@wdforms)

display_z_=: display_rgtVisual_

display '+/ % #'

NB.========================================================================


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

Reply via email to