Conversion of one java example to clojure?

2011-06-23 Thread Antonio Recio
I have tried to translate an example of vaadin in java to clojure. But I get 
errors.

This is the java code:
Panel panel = new Panel("Split Panels Inside This Panel");
HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
panel.setContent(hsplit);
Tree tree = new Tree("Menu", TreeExample.createTreeContent());
hsplit.setFirstComponent(tree);
VerticalSplitPanel vsplit = new VerticalSplitPanel();
hsplit.setSecondComponent(vsplit);
vsplit.addComponent(new Label("Here's the upper panel"));
vsplit.addComponent(new Buton("Here's the lower panel"));

And this the clojure code. Where I am doing wrong?
(defn -init [this]
  (let [app this]
(.setMainWindow this
  (doto (Window. "Test application")
(add
  (panel (doto (Panel. "Split panels inside this panel")
   (.setContent hsplit)))
  (hsplit (doto (HorizontalSplitPanel.)
(.setFirstComponent tree)
(.setSecondComponent vsplit)))
  (tree Tree. "Menu")
  (vsplit VerticalSplitPanel.
  (add (Label. "upper panel") (Button. "lower panel"

-- 
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

Re: Conversion of one java example to clojure?

2011-06-23 Thread Ambrose Bonnaire-Sergeant
What is the Java source for setting up the Window object?

Ambrose

On Fri, Jun 24, 2011 at 1:24 AM, Antonio Recio  wrote:

> I have tried to translate an example of vaadin in java to clojure. But I
> get errors.
>
> This is the java code:
> Panel panel = new Panel("Split Panels Inside This Panel");
> HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
> panel.setContent(hsplit);
> Tree tree = new Tree("Menu", TreeExample.createTreeContent());
> hsplit.setFirstComponent(tree);
> VerticalSplitPanel vsplit = new VerticalSplitPanel();
> hsplit.setSecondComponent(vsplit);
> vsplit.addComponent(new Label("Here's the upper panel"));
> vsplit.addComponent(new Buton("Here's the lower panel"));
>
> And this the clojure code. Where I am doing wrong?
> (defn -init [this]
>   (let [app this]
> (.setMainWindow this
>   (doto (Window. "Test application")
> (add
>   (panel (doto (Panel. "Split panels inside this panel")
>(.setContent hsplit)))
>   (hsplit (doto (HorizontalSplitPanel.)
> (.setFirstComponent tree)
> (.setSecondComponent vsplit)))
>   (tree Tree. "Menu")
>   (vsplit VerticalSplitPanel.
>   (add (Label. "upper panel") (Button. "lower
> panel"
>
> --
> 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

-- 
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

Re: Conversion of one java example to clojure?

2011-06-23 Thread Ambrose Bonnaire-Sergeant
Does Window's add() method take multiple arguments? It looks like
you're passing 4 arguments to it.

Also   (tree Tree. "Menu")
should be (tree (Tree. "Menu"))

Same with (vsplit VerticalSplitPanel.
  (add (Label. "upper panel") (Button. "lower panel"

Could you post the full source? Looks like you're using some helper
functions like "tree"
and "vsplit" and "panel".

Ambrose

On Fri, Jun 24, 2011 at 2:19 AM, Antonio Recio  wrote:

> There are not window in the java code, anyway I have added it in the
> clojure code (could be deleted).
>
> The window java code could be something like this:
> setMainWindow(new Window("Test application"));
>
> --
> 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
>

-- 
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

Re: Conversion of one java example to clojure?

2011-06-23 Thread Antonio Recio
There are not window in the java code, anyway I have added it in the clojure 
code (could be deleted).

The window java code could be something like this:
setMainWindow(new Window("Test application"));

-- 
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

Re: Conversion of one java example to clojure?

2011-06-23 Thread Mark Rathwell
It looks like you may also be thinking that you are creating local bindings
in the 'add' call, but you actually need to create those bindings in a let.
 Also,'app' is bound to 'this' but never used.

I think something like this may be closer to what you are trying to do:

(defn -init [this]
  (let [tree (Tree. "Menu")
vsplit (doto (VerticalSplitPanel.)
 (.add (Label. "upper panel"))
 (.add (Button. "lower panel")))
hsplit (doto (HorizontalSplitPanel.)
 (.setFirstComponent tree)
 (.setSecondComponent vsplit))
panel (doto (Panel. "Split panels inside this panel")
(.setContent hsplit))
window (Window. "Test application")]
(do
  (.add window panel)
  (.setMainWindow this window



On Thu, Jun 23, 2011 at 2:27 PM, Ambrose Bonnaire-Sergeant <
abonnaireserge...@gmail.com> wrote:

> Does Window's add() method take multiple arguments? It looks like
> you're passing 4 arguments to it.
>
> Also   (tree Tree. "Menu")
> should be (tree (Tree. "Menu"))
>
> Same with (vsplit VerticalSplitPanel.
>
>   (add (Label. "upper panel") (Button. "lower
> panel"
>
> Could you post the full source? Looks like you're using some helper
> functions like "tree"
> and "vsplit" and "panel".
>
> Ambrose
>
> On Fri, Jun 24, 2011 at 2:19 AM, Antonio Recio  wrote:
>
>> There are not window in the java code, anyway I have added it in the
>> clojure code (could be deleted).
>>
>> The window java code could be something like this:
>> setMainWindow(new Window("Test application"));
>>
>> --
>> 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
>>
>
>  --
> 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
>

-- 
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

Re: Conversion of one java example to clojure?

2011-06-23 Thread Antonio Recio
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 toggleL

Re: Conversion of one java example to clojure?

2011-06-23 Thread .Bill Smith
Why is brownFox a function instead of a string constant?  

-- 
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

Re: Conversion of one java example to clojure?

2011-06-24 Thread Antonio Recio
I am newbie. Could be better like this? 

(def brownFox "The quick brown fox jumps over the lazy dog.")

-- 
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

Re: Conversion of one java example to clojure?

2011-06-24 Thread .Bill Smith
Sure could.  And you don't want to do this if brownFox is a function:

(Label. brownFox)

If you really want it to be a function, you could do the following, but I 
 think it would complicate things unnecessarily:

(Label. (brownFox))


-- 
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

Re: Conversion of one java example to clojure?

2011-06-25 Thread Ken Wesson
On Fri, Jun 24, 2011 at 11:57 AM, .Bill Smith  wrote:
> Sure could.  And you don't want to do this if brownFox is a function:
>
> (Label. brownFox)
>
> If you really want it to be a function, you could do the following, but I
>  think it would complicate things unnecessarily:
>
> (Label. (brownFox))

I can think of at least one good reason for this: i18n. The initial
implementation of brownFox may be

(defn brownFox [] "The quick brown fox...")

but the idea might be to eventually change that to

(def bundle (atom nil))

(defn get-in-bundle [^String key]
  (swap! bundle
#(if %
%
(with-open [in (reader-on blah blah blah)]
  (PropertiesResourceBundle. in
  (.handleGetObject ^PropertiesResourceBundle @bundle key))

(defn brownFox []
  (get-in-bundle "fox.brown"))

or something similar.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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