;; This pops up a removable menu that allows the user to select and run various demo programs (jlib.JLIB.load) (define (makeDemorunner title this buttons) (define components (map (lambda (x) (button(first x) (color 250 0 250) (action (lambda (e) (rundemo (first x) (second x)))))) buttons)) (define detachbutton (button "DETACH" (color 255 255 255) (action (lambda (e) (.add newwin buttonpanel) (.show attachbutton) (.hide detachbutton) (.hide this) (.pack newwin) (.show newwin))))) (define attachbutton (button "ATTACH" (action (lambda (e) (.add this buttonpanel) (.hide attachbutton) (.show detachbutton) (.hide newwin) (.show this))))) (define buttonpanel (apply grid `( 0 1 ,(color 150 200 200) ,attachbutton ,detachbutton ,@ components))) (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 tag (maketagger)) (define (rundemo name code) (define mywin (window name (color 200 200 255) (border (west (col 'none 'north (grid 4 1 (button "Evaluate" EvalAction) (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 mywin))))))) (south (tag "statusbar" (label ""))) (center (grid 2 1 (tag "prog" (textarea 4 10)) (tag "result" (textarea 4 10))))))) (let ((f (CourierBold 18))) (.setFont (tag "prog") f) (.setFont (tag "result") f)) (.setText (tag "prog") code) (.resize mywin 600 600) (.show mywin) ) (define newwin (window "Demos")) (.resize newwin 300 300) (.hide attachbutton) (set! newwin (window title (java.awt.Dimension. 300 300))) (.setBackground this white) (.setBackground newwin (color 150 200 200)) (.add this buttonpanel) (if (.isInstance java.awt.Window.class this) (.pack this)) (.validate this) (.show this) )