On Sep 4, 8:30 pm, Jonathan Smith <jonathansmith...@gmail.com> wrote:
> Hi Ralph,
>
> First off, nice post! We need more of these types of tutorials on GUI
> in clojure, they're very useful.
>
> On make-login-widget you can probably do a doto when you do this part:
>
> > (.addWidget layout (WLabel. "Login:") 0 0 )
> > (.addWidget layout login-field 0 1 )
> > (.addWidget layout (WLabel. "Password:") 1 0 )
> > (.addWidget layout password-field 1 1)
> > (.addWidget layout submit-button 2 0 1 2)
>
> Can be like (doto layout (add ) (add))
>
yes, I didn't think of that!
> I don't have any experience using Jwt, but with regard to listeners
> and such, I've been using a 'continuation passing' style when writing
> little toy applications using swing.
The first version of my code was like that (see here:
http://paste.lisp.org/display/86499), but then I decided to try using
signals.
Thanks for your feedback.
raph
>
> I guess the best way to explain it is that rather than using .trigger
> on the signal in the do-login function block, you would just apply a
> passed in (possibly anonymous) function. I can give an example:
>
> Think of this as pseudocode that may or may not run, as I only have
> Swing for ui on this computer.
>
> (defn make-login-form [logged-in-fn wrong-creds-fn]
> (let [layout (WGridLayout.)
> container (WContainerWidget.)
> password-field (doto (WLineEdit. container)
> (.setEchoMode WLineEdit$EchoMode/Password ) )
> password #(.getText password-field)
> login-field (WLineEdit. container)
> login #(.getText login-field)
> do-login (fn [evt]
> (if (authenticate (login) (password))
> (logged-in-fn)
> (wrong-creds-fn)))
> submit-button (WPushButton. "Login")]
> (-> submit-button .clicked
> (.addListener container
> ( create-listener [mouse-event]
> (do-login mouse-event))))
> (doto layout
> (.addWidget (WLabel. "Login:") 0 0 )
> (.addWidget login-field 0 1 )
> (.addWidget (WLabel. "Password:") 1 0 )
> (.addWidget password-field 1 1)
> (.addWidget submit-button 2 0 1 2))
> (.setLayout container layout)
> (.setFocus login-field)
> container))
>
> (defn make-login-app
> ([env continuation]
> (let [wapp (new WApplication env)
> root (.getRoot wapp)
> result-text (WText. "")
> user nil
> dialog (WDialog. "test")
> dialog-container (.getContents dialog)
> app-screen (make-app-screen)
> form (make-login-form
> #(do (.remove dialog)
> (.setText (-> app-screen .getLayout (.getItemAt 0)
> .getWidget)
> "Logged in!")
> (continuation))
> #(do (.setText (-> app-screen .getLayout (.getItemAt 0)
> .getWidget)
> "Wrong credentials!")))]
> (.setTitle wapp "Login Example")
> (doto dialog (.. getContents (addWidget form)) .show)
> (.addWidget root app-screen)
> wapp))
> ([env]
> (make-login-app env identity)))
>
> And so then, to get a dialog that is like a sequence of panels, you
> can go through and do like:
>
> (make-login-app env make-next-widget)
>
> Anyway, is not particularly any better than using signal passing
> technique,
> but is another approach that you might consider in your application.
>
> On Sep 4, 11:01 am, rb <raphi...@gmail.com> wrote:
>
> > Hi,
>
> > In using the Jwt library, for which I only found examples in object
> > oriented languages that structure the code in class definitions and do
> > heavy usage of instance variables, I was in a situation where I
> > wondered how I could best structure my code.
>
> > With help on the IRC channel I got to a working solution which I
> > document in a blog post
> > athttp://www.nsa.be/index.php/eng/Blog/From-OO-to-Lisp-style-structurin...
>
> > I'm interested in feedback and advices for improvements
>
> > Thanks
>
> > Raph
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---