On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson <kwess...@gmail.com> wrote:
> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund <jonas.enl...@gmail.com> wrote:
>> Hi.
>> I'm trying to create a java.io.Writer proxy (which writes to a
>> JTextArea) but I can't get it to work.
>> Here is my clojure code so far:
>>
>> (def text-area (javax.swing.JTextArea.))
>>
>> (def frame
>>      (let [f (javax.swing.JFrame.)]
>>        (.. f getContentPane (add text-area))
>>        (.setMinimumSize f (java.awt.Dimension. 200 200))
>>        (.setVisible f true)
>>        f))
>>
>> (def text-area-writer
>>      (proxy [java.io.Writer] []
>>        (close [])
>>        (flush [])
>>        (write [^chars chrs ^int offs ^int len]
>>          (.append text-area (String. chrs offs len)))))
>>
>> When I load the code above I get an "IllegalArgumentException: Unable
>> to resolve classname: int" so I think I'm not type hinting correctly.
>
> Indeed. You can't (in 1.2 at least) type hint "int" though you can
> "ints" (array of int). Note that int is a primitive type while array
> of int is a reference type.
>
> Type hinting as Integer shouldn't throw exceptions, but you can
> probably omit all but the chars hint and have the correct String
> constructor overload selected.

I tried with 1.3.0-alpha5. With type hints I get "CompilerException
java.lang.IllegalArgumentException: Only long and double primitives
are supported". If I only keep the ^chars hint I get an ArityException
when I do (.write text-area-writer "hello").

Is this problem unsolvable with proxy? Should I look into gen-class
and AOT compilation instead?

>
> Also note that while text area .append is safe to call from off the
> EDT, other Swing methods mostly aren't, and it's something to watch
> for if you do anything similar to this with other Swing components,
> and wherever you construct your text area and its surrounds.
>
> --
> 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

Reply via email to