;; This pops up a removable menu that allows the user to select and run various demo programs (jlib.JLIB.load) (define (main args) "there is no main defined yet") (define (init this) (define title (.getParameter this "title")) (define democode (.getParameter this "democode")) (define detachbutton (button "DETACH" (color 0 50 0) (lambda(this)(.setForeground this white)) (action (lambda (e) (.add newwin evaluator) (.show attachbutton) (.hide detachbutton) ; (.hide this) (.pack newwin) (.show newwin))))) (define attachbutton (button "ATTACH" (color 0 50 0) (lambda(this)(.setForeground this white)) (action (lambda (e) (.add this evaluator) (.hide attachbutton) (.show detachbutton) (.hide newwin) (.validate this) (.show this))))) (define buttonpanel (apply grid `( 1 0 ,(color 150 200 200) ,attachbutton ,detachbutton ))) (define (REPloop Ans inport) (define (loop x) (if (eof-object? x) #t (begin (.appendText Ans (string-append (silk.U.stringify x) "\n--->\n" (silk.U.stringify (eval x)) "\n\n")) (loop (read inport))))) (loop (read inport))) (define EvalAction (action (lambda(e) (.setText (tag "statusbar") "Evaluating....") (REPloop (tag "result") (silk.InputPort. (java.io.StringReader. (.getText (tag "prog"))))) (.setText (tag "statusbar") "---ready---")))) (define MainAction (action (lambda(e) (.setText (tag "statusbar") (string-append "calling (main ()) ...")) (.appendText (tag "result") (silk.U.stringify (main ()))) (.setText (tag "statusbar") (string-append "---ready---"))))) (define tag (maketagger)) (define evaluator (border (west (col 'none 'north (grid 0 1 (button "eval" EvalAction) (button "main" MainAction) (button "Clear" (action (lambda(e) (.setText (tag "prog") "") (.setText (tag "result") "")))) (choice "fontsize" "6" "12" "18" "24" (action (lambda(e) (let ((f (readexpr (.getSource e)))) (.setFont (tag "prog") (CourierBold f)) (.setFont (tag "result") (CourierBold f)))))) (button "Quit" (action(lambda(e) (.hide this))))))) (north (tag "statusbar" (label ""))) (south buttonpanel) (center (grid 2 1 (tag "prog" (textarea 8 40)) (tag "result" (textarea 4 40)))))) (define newwin (window "Demos")) (set! thisContainer this) (.setLayout newwin (java.awt.GridLayout. 1 1)) (.setLayout this (java.awt.GridLayout. 1 1)) (.resize newwin 300 300) (.hide attachbutton) (set! newwin (window title (java.awt.Dimension. 300 300))) (.setBackground this (color 150 200 200)) (.setBackground newwin (color 150 200 200)) (.add this evaluator) (let ((f (CourierBold 12))) (.setFont (tag "prog") f) (.setFont (tag "result") f)) (.setText (tag "prog") democode) (.setText (tag "prog") (.replace democode #'|' #'\n')) (.show this) )