;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GREWP.scm ;; Group Research, Education, and Work Project ;; 2/10/2003 ;; ;; This is the top level of a group homework tool ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define GREWP-version "GREWP version 2.0, 5/1/2003") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Load in all of the scheme code needed for the demo ;; These loads will read from the jar file ;; Note that we use prefixes for all loaded procedures except ;; the windowing toolkit Swing.scm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (loadlibs) (environment-import "groupscheme/util/PrintDebug.scm") (printdebug 'verbose "loading libraries") (environment-import "jlib/Swing.scm") (environment-import "groupscheme/demo/GroupHWPanel.scm" "GHP:") (environment-import "groupscheme/widget/GroupTextAreaServer.scm" "GTAS:") (environment-import "groupscheme/widget/Linda.scm" "Linda:") (printdebug 'verbose "libraries loaded") ) (loadlibs) (let () (define isExperiment? #f) ;; This is used to serialize all groupware callbacks ;; that might interact with the GUIs (define(invokeAndWait F) (javax.swing.SwingUtilities.invokeAndWait (lambda() (tryCatch (F) (lambda(e) (printdebug 'error {ERROR in invokeAndWait: [F], [e]\n}))) )) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Local Component Naming ;; This is a method for naming and access components via a hashtable ;; Putting (namer H "zzz") in the argument list of a component will add ;; that component to the hashtable H with the key "zzz" ;; One can then access the component later using (.get H "zzz") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define H (java.util.Hashtable.)) (define (namer H x) (lambda (this) (.put H x this))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Random numbers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (randN N) (.intValue (java.lang.Math.round (* N (java.lang.Math.random))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; INITIAL WINDOW for selecting server, port, username ;; and optionally starting a local server ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define GTAS #null) ; this is the most recent group text area server created by the user (define shared-doc-clients ()) ; each time the user connects to a shared document, a new logfile is created ; When the program exits, these logfiles are lifted to the server (define shutdown-list ()) ; each time a new server is created, we append a list (GTAS "name") ; to the shutdown list. When the program exits, we gracefully shutdown these servers (define (Linda-Host) (let ((x (readstring (.get H "linda-ip")))) ;; logging/printing can go here x)) (define (Linda-Port) (let ((x (tryCatch (readexpr (.get H "linda-port")) (lambda(e) 0)))) ;; logging/printing can go here x)) (define MyColor (color (+ 150 (randN 100)) (+ 150 (randN 100)) (+ 150 (randN 100)) 120)) (define MyColorChooser (javax.swing.JColorChooser. MyColor)) (define MyColorChooserWin (window "ColorChooser" (border (center MyColorChooser) (south (button "OK" (action(lambda(e) (set! MyColor (.getColor MyColorChooser)) (.hide MyColorChooserWin)))))))) (define (select-shared-document name ip port) (writeexpr (.get H "current-selection-name") name) (writeexpr (.get H "ip") ip) (writeexpr (.get H "port") port) (.setEnabled (.get H "edit-document-button") #t) ) (define msglist (jlist (lambda(x) (select-shared-document (first x) (first (second x)) (second (second x)))))) ; (writeexpr (.get H "current-selection-name") (first x)) ; (writeexpr (.get H "ip") (first (second x))) ; (writeexpr (.get H "port") (second (second x))) ; (.setEnabled (.get H "edit-document-button") #t) ; ))) (define OLDmsglist (jlist (lambda(x) (let ((hostname (first x)) (username (readstring (.get H "name"))) (logfile {log-[(readstring (.get H "name"))]-[(first x)]-[(.getTime (Date.))]}) (make-linda-socket (lambda() (java.net.Socket. (Linda-Host) (Linda-Port)))) (selection (second x))) (writestring (.get H "ip") (first selection)) (writestring (.get H "port") (second selection)) (writestring (.get H "status-line") {CONNECTING TO SERVER ......}))))) (define (connect-to-shared-document) (let*((hostname (readstring (.get H "current-selection-name"))) (ip (readstring (.get H "ip"))) (port (readexpr (.get H "port"))) (username (readstring (.get H "name"))) (logfile {log-[(readstring (.get H "name"))]-[hostname]-[(.getTime (Date.))]}) (make-linda-socket (lambda() (java.net.Socket. (Linda-Host) (Linda-Port))))) (writestring (.get H "ip") ip) (writestring (.get H "port") port) (writestring (.get H "status-line") {CONNECTING TO SERVER ......}) ; a shared-doc-client, p, is a scheme object that provides access to the gui and the logwidget, and any ; other values or operations we want to provide, the shared-doc-clients list is used at shutdown time to ; shutdown all remaining shared-doc-clients and lift their logs to the server (let ((p (GHP:create-group-hw-client ip port username hostname make-linda-socket logfile MyColor isExperiment? ))) (set! shared-doc-clients (cons p shared-doc-clients)) (.setSelectedComponent GHP:JT (p 'get 'gui))) (writestring (.get H "status-line") {CONNECTED TO SERVER: [(.toString hostname)]}) (update-linda-data) )) (define selection (textfield "" 50)) (define (get-authorization msg pw Action) (define w (window "authorization window" (border (north (label "authorization window" (HelveticaBold 24) (namer H "auth-status"))) (center (label msg)) (south (table 2 2 (label "password") (textfield "" 20 (namer H "auth-pw")) (button "OK" (action(lambda(e) (if (equal? (readstring (.get H "auth-pw")) pw) (begin (Action) (.hide w)) (writestring (.get H "auth-status") "incorrect password"))))) (button "Cancel" (action (lambda(e) (.hide w))))))))) (.pack w) (.show w)) (define hidden-registration-window (window "GTAS-params" (border (north (table 6 2 (label "document server ip") (textfield "tat.cs.brandeis.edu" 20 (namer H "linda-ip")) (label "document server port") (textfield "13313" 20 (namer H "linda-port")) (label "my local p2p server ip") (textfield "127.0.0.1" 20(namer H "ip")) (label "my local p2p port") (textfield "14425" 20 (namer H "port")) (label "select shared document server:") (choice "default" "ITR experiment" "local" (namer H "linda-choice") (action(lambda(e) (set! isExperiment? #f) (case (readstring (.get H "linda-choice")) (("default") (writestring (.get H "linda-ip") "tat.cs.brandeis.edu") (writestring (.get H "linda-port") "13313")) (("ITR experiment") (get-authorization "Enter ITR Experiment password" "tat" (lambda() (set! isExperiment? #t) (writestring (.get H "linda-ip") "tat.cs.brandeis.edu") (writestring (.get H "linda-port") "13131")))) (("local") (writestring (.get H "linda-ip") "127.0.0.1") (writestring (.get H "linda-port") "13313") (linda-start-server)) (else (get-authorization {problem with cond: |[(readstring (.getSource e))]|} "tat" (lambda() #t)))) (update-linda-data)))) (button "Clear shared document server" (action (lambda(e) (get-authorization "Remove all shared documents from server???" "tat" (lambda() (Linda:linda-send (Linda-Host) (Linda-Port) `(take GHTAS-clients)))) #t))) ))))) (define (linda-start-server) (tryCatch (begin (writestring (.get H "linda-ip") "127.0.0.1") (Linda:make-linda-server (Linda-Port) "linda-log")) (lambda(e) (printdebug 'error (list "linda error: " e)) #t) ) ) (define (linda-login) (tryCatch (let* ((myaddress (Linda:send-line (Linda-Host) (Linda-Port) "ping")) (myport (if (equal? #null GTAS) -1 (GTAS 'get 'port))) (myname (readstring (.get H "name"))) (mydocname (readstring (.get H "docname"))) (fulldocname {[myname]==[mydocname]}) ) (Linda:linda-send (Linda-Host) (Linda-Port) `(insert GHTAS-clients ,fulldocname (,myaddress ,myport ,(java.util.Date.)))) (select-shared-document fulldocname myaddress myport) (set! shutdown-list (cons (list GTAS fulldocname) shutdown-list)) (update-linda-data)) (lambda(e) (printdebug 'error (list "linda error: " e))(newline) #t)) ) (define (linda-logoff) (tryCatch (let* ( (myname (readstring (.get H "name"))) (mydocname (readstring (.get H "docname"))) (fulldocname {[myname]==[mydocname]}) ) (Linda:linda-send (Linda-Host) (Linda-Port) `(remove GHTAS-clients ,fulldocname)) (update-linda-data)) (lambda(e) (printdebug 'error (list "linda error: " e))(newline) #t)) ) (define (update-linda-data) (tryCatch (let ((client-data (Linda:linda-send (Linda-Host) (Linda-Port) '(get GHTAS-clients)))) (jlistwrite msglist (string->expr client-data)) ) (lambda(e) (printdebug 'error (list "linda error: " e))(newline) #t)) ) (define preregistration-pane (row 'none 'center black (col 'none 'center yellow (label {
GREWP: Group Research, Education, and Work Projecthttp://www.cs.brandeis.edu/~tim/GREWP