Before I have forgotten to post the source of the function "add" (https://groups.google.com/d/topic/clojure/N1wmlOrGYj0/discussion):
(defn add [composite & components] "Avoid repetition of .addComponent Instead of (doto (Window. \"foo\") (.addComponent (Label. \"bar\")) (.addComponent (Button. \"button\"))) you can use (doto (Window. \"foo\") (add (Label. \"bar\") (Button. \"button\")))" (doseq [component components] (.addComponent composite component))) I would like to post a complete example of vaadin in java (http://demo.vaadin.com/sampler/#SplitPanelBasic) and the translation in clojure that I have done, and to know your opinion. ;; JAVA : import com.vaadin.terminal.Sizeable; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CheckBox; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalSplitPanel; @SuppressWarnings("serial") public class SplitPanelBasicExample extends VerticalLayout { public static final String brownFox = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. "; public SplitPanelBasicExample() { // First a vertical SplitPanel final VerticalSplitPanel vert = new VerticalSplitPanel(); vert.setHeight("450px"); vert.setWidth("100%"); vert.setSplitPosition(150, Sizeable.UNITS_PIXELS); addComponent(vert); // add a label to the upper area vert.addComponent(new Label(brownFox)); // Add a horizontal SplitPanel to the lower area final HorizontalSplitPanel horiz = new HorizontalSplitPanel(); horiz.setSplitPosition(50); // percent vert.addComponent(horiz); // left component: horiz.addComponent(new Label(brownFox)); // right component: horiz.addComponent(new Label(brownFox)); // Lock toggle button CheckBox toggleLocked = new CheckBox("Splits locked", new Button.ClickListener() { // inline click.listener public void buttonClick(ClickEvent event) { vert.setLocked(event.getButton().booleanValue()); horiz.setLocked(event.getButton().booleanValue()); } }); toggleLocked.setImmediate(true); addComponent(toggleLocked); } } ;; CLOJURE : (ns project.vapp (:gen-class :extends com.vaadin.Application :name example.VApp :init cjinit) (:import (com.vaadin.ui CheckBox HorizontalSplitPanel Label VerticalLayout VerticalSplitPanel) (com.vaadin.terminal Sizeable))) (defn -cjinit [] [[] (ref {})]) (defn add [composite & components] "Avoid repetition of .addComponent Instead of (doto (Window. \"foo\") (.addComponent (Label. \"bar\")) (.addComponent (Button. \"button\"))) you can use (doto (Window. \"foo\") (add (Label. \"bar\") (Button. \"button\")))" (doseq [component components] (.addComponent composite component))) (def brownFox (fn [] "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ")) (defn -init [this] (let [app this] (vert (doto (VerticalSplitPanel.) (.setHeight "450px") (.setWidht "100%") (.setSplitPosition (150 Sizeable.UNITS_PIXELS)) (add (Label. brownFox) (horiz)))) (add vert) (horiz (doto (HorizontalSplitPanel.) (.setSplitPosition 50) (add (Label. brownFox)) ; Left component (add (Label. brownFox)))) ; Right component (toggleLocked (doto (CheckBox. "Split locked") (.addListener (proxy [com.vaadin.ui.Button$ClickListener] [] (buttonClick [event] (.setLocked(-> (event.getButton) (.booleanValue)) vert) (.setLocked(-> (event.getButton) (.booleanValue)) horiz)))) (.setImmediate true))) (add toggleLocked))) -- 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