<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Todd Costella &#187; groovy</title>
	<atom:link href="http://blog.toddcostella.com/category/java/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.toddcostella.com</link>
	<description>Crafting code.  bits at a time</description>
	<lastBuildDate>Wed, 16 Sep 2009 18:52:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>GriffonCast</title>
		<link>http://blog.toddcostella.com/2009/09/griffoncast/</link>
		<comments>http://blog.toddcostella.com/2009/09/griffoncast/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 18:52:23 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[griffon]]></category>

		<guid isPermaLink="false">http://blog.toddcostella.com/?p=117</guid>
		<description><![CDATA[My new GriffonCast project has been launched.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started a new project with the purpose of promoting the <a href="http://griffon.codehaus.org/">Griffon framework</a> and helping build the community around the project. The <a href="http://www.griffoncast.com">GriffonCast</a> is a screencast that I hope to produce at least once a month. </p>
<p>Griffon is a framework for building rich desktop applications. It leverages the Groovy programming language and a number of the key features of Groovy including builders. It&#8217;s a fantastic effort and while it&#8217;s still fairly early days, the team is making great headway with the <a href="http://griffon.codehaus.org/Road+Map">roadmap</a>. The <a href="http://www.griffoncast.com/episode-1/">first episode</a> of the GriffonCast is available for viewing and/or downloading. If you have any comments or would like to see specific topics covered drop me a note or post your thoughts on the Griffon <a href="mailto:user@griffon.codehaus.org">mailing list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.toddcostella.com/2009/09/griffoncast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java One 2009 &#8211; Day 2</title>
		<link>http://blog.toddcostella.com/2009/06/java-one-2009-day-2/</link>
		<comments>http://blog.toddcostella.com/2009/06/java-one-2009-day-2/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 03:44:15 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://blog.toddcostella.com/?p=100</guid>
		<description><![CDATA[Java One 2009 - Day 2. Extreme GUI Makeover (Hybrid Swing and JavaFX™ Technology), Move Your Users: Animation Principles for Great User Experiences,The Magic of the JXLayer Component,JavaFX™ Programming Language + Groovy = Beauty + Productivity,Hudson Community Meet-Up and Griffon in Depth]]></description>
			<content:encoded><![CDATA[<h3>Extreme GUI Makeover (Hybrid Swing and JavaFX™ Technology)</h3>
<p>In this session, Amy Fowler, Jasper Potts, Paru Somasheka and David Grieve all from Sun took the Swing application that was written  for <a href="http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-1548&amp;yr=2006&amp;track=desktop">last year&#8217;s installment</a> of the GUI Makeover and added a bit of Java/FX. The idea is that there is a bit of a migration path for existing swing applications to Java/FX.</p>
<p>javafx.ext.swing.SwingComponent is the Java/FX component that can be used to wrap any existing swing component. The resultant object is a Node object that can be added to the FX scene graph. This is a decent approach but the biggest drawback is that none of the core elements for Java/FX (like transitions) can be applied to the contents of these kinds of nodes. They showed the CSS skinning approach that can be taken with Java/FX applications. It&#8217;s a good idea to separate the style (colour, font, size etc) from the actual components. Lastly Jasper showed an illustration of a an annimation on the Scene Graph. </p>
<p>It was pretty impressive all in all.</p>
<h3>Move Your Users: Animation Principles for Great User Experiences</h3>
<p>This session was presented by Chet Haas and Romain Guy. They introduced 12 animation principals that are documented in the book. The principals are related to traditional animation (cartoons) but they are very applicable to computer animation as well. They followed up a description of each of the principals with it&#8217;s application in building rich user interfaces on desktop applications. They did a great job. The content is something folks should consider when they&#8217;re implementing any sort of animation in their applications even things as simple as a fade transition or a scale. It&#8217;s really easy to get this stuff wrong and learning from the masters of animation who have been thinking about this stuff for almost a century could make a huge difference in your application.</p>
<p>The 12 principals are:</p>
<ul>
<li>Squash and Stretch</li>
<li>Anticipation</li>
<li>Staging (poses, camera angle, focus)</li>
<li>Straight ahead vs. pose to pose (related to transitions)</li>
<li>Follow through and overlapping action (objects should obey physical reality)</li>
<li>Slow in and out (non linear timing)</li>
<li>Arcs (things generally don&#8217;t move in a perfectly straight line)</li>
<li>Secondary Action (an additional action that gives context to the main action)</li>
<li>Timing </li>
<li>Exaggeration</li>
<li>Solid Drawing</li>
<li>Appeal</li>
</ul>
<p>One of the sources for their presentation was <a href="http://www.amazon.com/Illusion-Life-Disney-Animation/dp/0786860707/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1244404789&amp;sr=8-1">The Illusion of Life: Disney Animation</a></p>
<h3>The Magic of the JXLayer Component</h3>
<p>This session introduced the JXLayer component which is currently a <a href="https://jxlayer.dev.java.net/">java.net project</a>. JXLayer is a wrapper or more precisely implements the decorator pattern for Swing Components. It has a bunch of different uses including a very lightweight way of disabling compound components, implementing mouse wheel scrolling as well a many other uses. We use this component in our framework quite a bit mostly in and around our UI security implementation. It&#8217;s great and if you write any Swing code and don&#8217;t know about this component go have a look. It was also announced in this session that this component is being promoted into  JDK 7.</p>
<h3>JavaFX™ Programming Language + Groovy = Beauty + Productivity</h3>
<p>Dierk König author of Groovy in Action (still the best book on Groovy written to date in my opinion), presented a couple of different approaches to integrate groovy with Java/FX. One strategy is to use Java/FX for client code and then use a REST layer to have the Java/FX client talk to a back end written in Groovy (or Grails for that matter). This approach is pretty clean but you don&#8217;t get to take advantage of any Groovy code on the client.</p>
<p>Both Java/FX and Groovy are JVM languages and ultimately emit bytecode from their respective compilers. It is possible to reference Java/FX components from within Groovy but it&#8217;s messy. Andres Almiray has a JavaFX builder in the Griffon Project that begins to make this integration easier but it&#8217;s still early days.</p>
<p>The short answer is that true integration at this point in time is hard and will get better as Java/FX matures.</p>
<h3>Hudson Community Meet-Up</h3>
<p>I&#8217;ve been looking into <a href="http://hudson.dev.java.net">Hudson</a> for a few months now and it just keeps getting better and better. The project lead (Kohsuke Kawaguchi) gave a bit of background and some of the current trends of Hudson. The growth of the product and the community surrounding it since last Java One is very impressive. Plugins for Hudson are one of the distinguishing features. Tom Huybrechts from AGFA Healthcare demoed a new plugin he wrote that implements the JBoss Rules Engine (drools) within Hudson. Layered on top of it is a graphical builder for building workflow steps, gathering input at various points in the workflow and a ton of other cool stuff. It was very impressive and something I want to take a closer look at.</p>
<p>Netbeans project integration was also demoed (actually talked about as there was a technical glitch with the netbeans machine/projector combo). It would be interesting to monitor builds from within Netbeans, kick them off etc. but given that we&#8217;re an IntelliJ shop it&#8217;s not that relevant. There may be some form of plugin for IntelliJ but the web interface is great so I&#8217;m not sure we would even look at it.</p>
<h3>Griffon in Depth</h3>
<p> Danno Ferrin and James Williams gave an introduction to <a href="http://griffon.codehaus.org/">Griffon</a> which is a <a href="http://grails.codehaus.org/">Grails</a> inspired framework for building Swing applications in Groovy. It&#8217;s still very early days with the project however the project team has leveraged all of the great work from the Grails project in bootstrapping the Griffon project. This is one technology that I&#8217;m quite excited about. Writing swing apps in Groovy is possible (see <a href="http://blog.toddcostella.com/2009/03/groovyswingyqlgoogle-maps-lightning-talk/">this post</a> for an example) however writing a big Swing app would be quite a lot of work. The idea behind Griffon is to put a framework in place to support building Swing applications with the same sort of velocity the web guys are seeing with frameworks like Grails and Ruby on Rails. The fellows demoed a few applications written in Griffon the most impressive one was Greet which is a Twitter client written in Griffon. I wish the fellows much luck with this project and I&#8217;m trying to figure out a way I can help in some small way. Swing and Groovy in the same stack makes me very happy <img src='http://blog.toddcostella.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.toddcostella.com/2009/06/java-one-2009-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java One 2009 &#8211; What I&#8217;m Looking Forward to</title>
		<link>http://blog.toddcostella.com/2009/04/java-one-2009-what-im-looking-forward-to/</link>
		<comments>http://blog.toddcostella.com/2009/04/java-one-2009-what-im-looking-forward-to/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 15:02:07 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://blog.toddcostella.com/?p=75</guid>
		<description><![CDATA[I&#8217;ll be heading to San Francisco in the first week of June for the 2009 edition of Java One. I&#8217;ve been fortunate to attend something like eight or nine years and find it interesting to see the trends and how things like the economy affect attendance and the type of folks that come. Java FX [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be heading to San Francisco in the first week of June for the 2009 edition of <a href="http://java.sun.com/javaone/">Java One</a>. I&#8217;ve been fortunate to attend something like eight or nine years and find it interesting to see the trends and how things like the economy affect attendance and the type of folks that come.</p>
<h3>Java FX</h3>
<p>I&#8217;m sure this year will be all about the Desktop (again) with <a href="http://www.sun.com/software/javafx/">Java FX</a>. I&#8217;m mildly interested to see what all the hype is about. I&#8217;ve been a Swing guy for most of my Java life and while I am excited about seeing some of the new shiny tools and techniques (Scene Graph being very high up there), part of me is sad to see so much engineering time and resources being focused on this. Amy Fowler is doing a session entitled <a href="http://www28.cplan.com/cc230/session_details.jsp?isid=305575&#038;ilocation_id=230-1&#038;ilanguage=english">Extreme GUI Makeover (Hybrid Swing and JavaFX™ Technology)</a> which promises to be a Pimp my Swing App with Java/FX. </p>
<h3>Groovy</h3>
<p>I first learned about Groovy at Java One in 2004 where James Strachan gave an introduction and overview of the language. This was the first time I had considered using anything else except for Java on the JVM and I remember having one of those &#8216;light bulb&#8217; moments in the session. It&#8217;s totally changed the way I think about the JVM and languages in general. We&#8217;re a pretty heavy user of groovy in our application and I&#8217;m quite excited to see a number of Groovy sessions at Java One this year.</p>
<p>Some of the sessions that have caught my eye are:<br />
<a href="http://www28.cplan.com/cc230/session_details.jsp?isid=304215&#038;ilocation_id=230-1&#038;ilanguage=english">What&#8217;s New in Groovy 1.6?</a> with Guillaume Laforge<br />
<a href="http://www28.cplan.com/cc230/session_details.jsp?isid=305189&#038;ilocation_id=230-1&#038;ilanguage=english">Griffon in Depth</a> with Danno Ferrin and James Williams<br />
<a href="http://www28.cplan.com/cc230/session_details.jsp?isid=304961&#038;ilocation_id=230-1&#038;ilanguage=english">&#8220;Design Patterns&#8221; for Dynamic Languages on the JVM™ Machine</a> with Neal Ford<br />
<a href="http://www28.cplan.com/cc230/session_details.jsp?isid=303979&#038;ilocation_id=230-1&#038;ilanguage=english">The Groovy and Grails BOF: With Live Grails Podcast Recording!</a> with Sven Haiges and Glen Smith of <a href="http://grailspodcast.com/">The Grails Podcast</a></p>
<h3>Java EE</h3>
<p>Not nearly as sexy as Java/FX, the Java EE space will probably see some new announcements and updates on some of the key JSRs. I haven&#8217;t really been following the progress of the JCP that closely and can usually get all I need to satisfy my curiosity at Java One.</p>
<h3>Summary</h3>
<p>I&#8217;m really looking forward to it. San Francisco is one of my favorite cities and having been there a few times I&#8217;m starting to have a few favorite haunts including a <a href="http://en.wikipedia.org/wiki/Tadich_Grill">new one</a> I found last year. If you&#8217;re going to Java One this year, drop me a note on <a href="http://twitter.com/ToddCostella">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.toddcostella.com/2009/04/java-one-2009-what-im-looking-forward-to/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Groovy/Swing/YQL/Google Maps Lightning Talk</title>
		<link>http://blog.toddcostella.com/2009/03/groovyswingyqlgoogle-maps-lightning-talk/</link>
		<comments>http://blog.toddcostella.com/2009/03/groovyswingyqlgoogle-maps-lightning-talk/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 04:34:31 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://blog.toddcostella.com/?p=41</guid>
		<description><![CDATA[I decided to write a little Groovy app that displayed a few participants from the roundup and their origin airports on a Google map.  I wanted to illustrate a few common Groovy idioms and illustrate how easy it is to create a pretty functional app in just a few lines of code. ]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Lightning_Talk">Lightning talks</a> are another very cool aspect to the Java Posse Roundup. The lightning talks we do are five minutes long and they cover a wide range of topics. All the lightning talks are posted on the Java Posse <a href="http://www.youtube.com/javaposse">YouTube Chanel</a>.  The recording for this lightning talk (of which the rest of this post describes) is here.</p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/CgEbyZc68Qw&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CgEbyZc68Qw&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object><br />
</br></br><br />
If you would rather not hear me blather on describing this code, you can see a quick 20 second demo of the running application here.<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/vXZqSXVDxaw&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vXZqSXVDxaw&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>I decided to write a little groovy app that displayed a few participants from the roundup and their origin airports on a Google map.  I wanted to illustrate a few common Groovy idioms and illustrate how easy it is to create a pretty functional app in just a few lines of code.<br />
</br></p>
<p>The first thing of note in the script is a small class that represents an Attendee. Notice there is no constructor, no getters or setters. The only method in the class is the toString method. This method isn&#8217;t actually called in the script but I wanted to illustrate what a simple Groovy String (GString) looks like. The method has an implicit return (as the string is the last statement in the method). The String has references to the properties in the class. These properties are enclosed by ${}.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Attendee <span style="color: #66cc66;">&#123;</span>
  <span style="color: #aaaadd; font-weight: bold;">String</span> name
  <span style="color: #aaaadd; font-weight: bold;">String</span> lastName
  <span style="color: #aaaadd; font-weight: bold;">String</span> email
  <span style="color: #aaaadd; font-weight: bold;">String</span> origin
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">String</span> toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;Name:${name} Last name:${lastName} eMail:${email} origin:${origin}&quot;</span><span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The next few lines of code construct new instances of our Attendee class, one for each attendee. Normally these would come from some sort of datasource like a database or something but to keep this example simple, they are just hardcoded here. There are a few things of interest in this code. The first thing to note is that the attendees variable is dynamically typed. It is constructed using an ArrayList that is typed. This is really just to illustrate that Groovy does support Java generics. A typical declaration of a list in groovy would be <strong>def attendees = []</strong> the [] are shorthand for new empty ArrayList().<br />
</br></br><br />
The next interesting feature is the &lt;&lt; construct. This is the equivalent of attendees.add().<br />
</br></br><br />
The last thing to note in this example is the way we&#8217;re constructing the Attendee class. We have a comma separated list of values that are prefixed by property names. Notice that in our class definition we don&#8217;t have a constructor. This is one of the nice features of Groovy, named parameters.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> attendees <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #66cc66;">&lt;</span>Attendee<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Peter&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Pilgrim&quot;</span>, email: <span style="color: #ff0000;">&quot;pp@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;IAD&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Joel&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Neely&quot;</span>, email: <span style="color: #ff0000;">&quot;jn@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;MEM&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Dianne&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Marsh&quot;</span>, email: <span style="color: #ff0000;">&quot;dm@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;DTW&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Carl&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Quinn&quot;</span>, email: <span style="color: #ff0000;">&quot;cq@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;SJC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Dick&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Wall&quot;</span>, email: <span style="color: #ff0000;">&quot;dw@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;SJC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Joe&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Nuxoll&quot;</span>, email: <span style="color: #ff0000;">&quot;jn@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;SJC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Bill&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Pugh&quot;</span>, email: <span style="color: #ff0000;">&quot;pp@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;SJC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Dave&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Briccetti&quot;</span>, email: <span style="color: #ff0000;">&quot;db@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;SFO&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Todd&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Costella&quot;</span>, email: <span style="color: #ff0000;">&quot;tc@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;YYC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Ståle&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Undheim&quot;</span>, email: <span style="color: #ff0000;">&quot;su@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;FRA&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Eirik&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Bjørsnøs&quot;</span>, email: <span style="color: #ff0000;">&quot;eb@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;MUC&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Andrew&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Harmel-Law&quot;</span>, email: <span style="color: #ff0000;">&quot;al@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;EDI&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Oliver&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Gierke&quot;</span>, email: <span style="color: #ff0000;">&quot;og@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;ORD&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Joe&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Sondow&quot;</span>, email: <span style="color: #ff0000;">&quot;js@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;LGA&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Fred&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Simon&quot;</span>, email: <span style="color: #ff0000;">&quot;fs@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;ORD&quot;</span><span style="color: #66cc66;">&#41;</span>
attendees <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Attendee<span style="color: #66cc66;">&#40;</span>name: <span style="color: #ff0000;">&quot;Daniel&quot;</span>, lastName: <span style="color: #ff0000;">&quot;Watson&quot;</span>, email: <span style="color: #ff0000;">&quot;dw@example.com&quot;</span>, origin: <span style="color: #ff0000;">&quot;ATL&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>The next section is an implementation of a SwingBuilder. Builders are a pretty common idiom in Groovy. There are MarkupBuilders, AntBuilders and others including a SwingBuilder. The SwingBuilder abstracts a lot of the nasty complex requirements for building a rich user interface in Java. Swing is the desktop UI library. It&#8217;s very powerful but can also be very complex to use. The SwingBuilder provides a very elegant abstraction on what turns out to be a complex model. One of the great things about the SwingBuilder (and all Builders for that matter) is that in just reading the code, it&#8217;s quite apparent what the user interface is going to look like. We start with a Frame. Within the Frame we have a panel and within the panel we have a button and a label. We have a second panel that contains a table and thrid panel that contains the Google Map wiget. The equivalent swing code to implement this would be many more lines of code probably two or three times the amount of code I would guess. The other thing is that it would be harder to visualize the layout of the application with standard swing code. With the builder implementation, we can see how the components are nested within each other.<br />
</br></br><br />
I&#8217;ll talk about the {&#8230;} code behind the Refresh Button and the table in a second. Before we leave this code I wanted to talk a bit about the Map component. The Google Map component is based on some fine work by Josh Marinacci that can be found at java.net <a href="http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing-app-with-jxmapviewer.html">JXMapViewer</a>.The interesting thing with respect to this example is that any Swing component can be wrapped by a widget call in the builder. This provides a very nice mechanism for reusing existing swing classes within the builder pattern.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> swing <span style="color: #66cc66;">=</span> SwingBuilder.<span style="color: #006600;">build</span> <span style="color: #66cc66;">&#123;</span>
  frame<span style="color: #66cc66;">&#40;</span>title: <span style="color: #ff0000;">&quot;Java Posse Roundup 2009&quot;</span>, pack: <span style="color: #000000; font-weight: bold;">true</span>, show: <span style="color: #000000; font-weight: bold;">true</span>, defaultCloseOperation: EXIT_ON_CLOSE, id: <span style="color: #ff0000;">&quot;frame&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    borderLayout<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    panel<span style="color: #66cc66;">&#40;</span>constraints: NORTH<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      boxLayout<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      button<span style="color: #66cc66;">&#40;</span>text: <span style="color: #ff0000;">&quot;Refresh&quot;</span>, actionPerformed: <span style="color: #66cc66;">&#123;</span>
        doOutside <span style="color: #66cc66;">&#123;</span>...<span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
      label<span style="color: #66cc66;">&#40;</span>id:<span style="color: #ff0000;">&quot;status&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
    panel<span style="color: #66cc66;">&#40;</span>constraints: CENTER<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      borderLayout<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      table<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>...<span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    panel<span style="color: #66cc66;">&#40;</span>constraints: SOUTH<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      borderLayout<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      scrollPane<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        widget<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> JXMapKit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, defaultProvider: JXMapKit.<span style="color: #006600;">DefaultProviders</span>.<span style="color: #006600;">OpenStreetMaps</span>, dataProviderCreditShown: <span style="color: #000000; font-weight: bold;">true</span>, id: <span style="color: #ff0000;">&quot;map&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p></br></br><br />
Aside from the structure of our application, the most interesting code in the builder can be found in the actionPerformed closure. This closure will be called when the Refresh button is clicked. There is quite a bit going on in a very few lines of code. The first thing of note is the doOutside method that takes a closure. Quite simply the code in the closure will get executed in a separate thread. How cool is that? Within the closure we iterate over the attendees collection. For each entry in the collection we make a call to the <a href="http://developer.yahoo.com/yql/console/">Yahoo Geo Service</a>. Many thanks to my friend <a href="http://idojava.blogspot.com/">Ido Green</a> for introducing me to YQL via his <a href="http://www.youtube.com/watch?v=nnks7HovnUo">lightning talk</a>. The XmlSlurper class is a handy means for parsing XML content. The query we&#8217;re composing takes the origin airport {it.origin} and returns an xml document that contains a bunch of geographical information for the airport. In our case, we&#8217;re only interested in the latitude and logitude. We pull those values out of the resulting document and then construct a WayPoint. The WayPoint object is present in the JXMapViewer package and is relly the only thing we need to construct a pin point on the map.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">      button<span style="color: #66cc66;">&#40;</span>text: <span style="color: #ff0000;">&quot;Refresh&quot;</span>, actionPerformed: <span style="color: #66cc66;">&#123;</span>
        doOutside <span style="color: #66cc66;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">def</span> waypoints <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #66cc66;">&lt;</span>Waypoint<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
          attendees.<span style="color: #663399;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">def</span> url <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22${it.origin}%22&amp;format=xml&quot;</span>
            status.<span style="color: #006600;">text</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Looking up Airport: ${it.origin}&quot;</span>
            <span style="color: #000000; font-weight: bold;">def</span> doc <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlSlurper<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>doc.<span style="color: #006600;">results</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
              <span style="color: #000000; font-weight: bold;">def</span> latitude <span style="color: #66cc66;">=</span> doc.<span style="color: #006600;">results</span>.<span style="color: #006600;">place</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">centroid</span>.<span style="color: #006600;">latitude</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #000000; font-weight: bold;">def</span> longitude <span style="color: #66cc66;">=</span> doc.<span style="color: #006600;">results</span>.<span style="color: #006600;">place</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">centroid</span>.<span style="color: #006600;">longitude</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
              waypoints <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #000000; font-weight: bold;">new</span> Waypoint<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Double</span>.<span style="color: #006600;">valueOf</span><span style="color: #66cc66;">&#40;</span>latitude<span style="color: #66cc66;">&#41;</span>, <span style="color: #aaaadd; font-weight: bold;">Double</span>.<span style="color: #006600;">valueOf</span><span style="color: #66cc66;">&#40;</span>longitude<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#125;</span>
          <span style="color: #66cc66;">&#125;</span>
          WaypointPainter painter <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WaypointPainter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
          painter.<span style="color: #006600;">setWaypoints</span><span style="color: #66cc66;">&#40;</span>waypoints<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
          map.<span style="color: #006600;">getMainMap</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setOverlayPainter</span><span style="color: #66cc66;">&#40;</span>painter<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
          status.<span style="color: #006600;">text</span> <span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>The last thing of note is the table entry. The table has a tablemodel which is constructed using the list of attendees. The model itself is very simple and consists of a propertyColumn that has a constructor that takes the column title and the name of the property to display. If you&#8217;ve attempted to implement a tablemodel in java (even a read only one like this one), I&#8217;m sure you can appreciate the brevity and cleanliness of this implementation.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">      table<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          tableModel<span style="color: #66cc66;">&#40;</span>list: attendees<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            propertyColumn<span style="color: #66cc66;">&#40;</span>header: <span style="color: #ff0000;">'Name'</span>, propertyName: <span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#41;</span>
            propertyColumn<span style="color: #66cc66;">&#40;</span>header: <span style="color: #ff0000;">'Last Name'</span>, propertyName: <span style="color: #ff0000;">'lastName'</span><span style="color: #66cc66;">&#41;</span>
            propertyColumn<span style="color: #66cc66;">&#40;</span>header: <span style="color: #ff0000;">'EMail'</span>, propertyName: <span style="color: #ff0000;">'email'</span><span style="color: #66cc66;">&#41;</span>
            propertyColumn<span style="color: #66cc66;">&#40;</span>header: <span style="color: #ff0000;">'Origin'</span>, propertyName: <span style="color: #ff0000;">'origin'</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it. 87 lines of Groovy goodness that renders a Google Map in a swing app, utilizes YQL to resolve geo location information for airports.</p>
<p>The source and external libraries that are required to run this application are available here. You&#8217;ll need <a href="http://groovy.codehaus.org">Groovy</a> installed. This archive has idea project files included. If you use eclipse or netbeans you&#8217;ll have to add the three external libraries to your project manually.</p>
<p><a href="/jpr09/jpr09.zip">jpr09.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.toddcostella.com/2009/03/groovyswingyqlgoogle-maps-lightning-talk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
