<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Scott Violet&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/" />
<modified>2007-02-02T19:22:10Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/zixle/234</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2007, zixle</copyright>
<entry>
<title>Update on Beans Binding (JSR 295)</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2007/02/update_on_beans.html" />
<modified>2007-02-02T19:22:10Z</modified>
<issued>2007-02-02T19:22:04Z</issued>
<id>tag:weblogs.java.net,2007:/blog/zixle/234.6468</id>
<created>2007-02-02T19:22:04Z</created>
<summary type="text/plain">Get the skinny on where beans binding (JSR 295) is headed.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[Way back in May (YOW!) of last year I <a href="http://weblogs.java.net/blog/zixle/archive/2006/05/index.html">blogged</a> on <a href="http://jcp.org/en/jsr/detail?id=295">beans binding (JSR 295)</a>. While not much progress has been made externally, a ton of progress has been made before the expert group and internally. For the anxious folks, here's a small demo showing off various features of beans binding (I got lazy, the demo requires 1.6; for the folks still on 1.5, sorry):

<p align="center"><img src="http://weblogs.java.net/blog/zixle/archive/2007.02.02/screenShot.png" width="361" height="340" />

<p align="center"><a href="http://www.java.net/download/javadesktop/blogs/zixle/2007.02.02/bindingExample.jnlp"><img src="http://weblogs.java.net/blog/zixle/archive/2006.12.18/launch-button.png"></a>
<p>
Try selecting multiple elements in the table, notice the label beneath the table updates to reflect how many elements are selected. Similarly notice that when multiple rows are selected changing one of the detail values (such as the slider) updates all. But I'm getting ahead of myself.
<p>
<b>WARNING</b>: beans binding is in no way done and will most likely change from what I'm going to detail here.
<p>
Quick refresher: beans binding is all about binding two properties of two objects together. Properties in this sense refers to the beans notions of properties, the "foo" property is identified because you have setFoo/getFoo. If the two objects are observable (support PropertyChangeListeners), then beans binding can track changes and keep the two sides in sync. Don't get hung on using "bean" here, nearly any Object is a bean and if you're following common design patterns, you're in good shape.
<p>

Before getting into how the UI is configured, let me describe the model for this app. The model consists of a List&lt;Bug>, where Bug is a trivial bean with properties for id, priority, synopsis ... And of course Bug is observable, meaning it notifies listeners of changes by way of PropertyChangeListener. 
<p>

For this example I'm going to use BindingContext. BindingContext isn't strictly necessary; it's useful for managing a set of bindings. I envision a BindingContext per form:

<pre>
context = new BindingContext();
</pre>

We want to display the List&lt;Bug> in the table, where each row corresponds to a Bug, and each column corresponds to a property of the Bug. Here's how this is done with beans binding:
<pre>
List&lt;Bug> bugs = ...;
Binding tableBinding = context.addBinding(
    bugs,      // Source for the binding, the List of bugs in this case.
    null,      // Expression, relative to the source, used in obtaining the property.
               // For this example it's null, meaning use bugs as is.
    bugTable,  // Target of the binding, a JTable in this case.
    "elements"); // The property of the target to bind to.
</pre>
By itself, this binding specifies the rows of the table. The astute reader will wonder just what "elements" is? JTable has no "elements" property, right? Turns out when you're binding using an object based binding approach there are a number of properties you would really like to have, but just aren't there. Beans binding provides a standard way to extend objects, adding properties for the sake of binding. "elements" is such a property, and equates to the rows of the table (as Objects). Under the covers this is building a private TableModel implementation, backed by the elements in the List. For the demo, the List is a plain old ArrayList. If the List were observable (I'm not going to get into details of what an ObservableList is here), then JTable would track changes made to the underlying list.
<p>
While this example isn't showing it, you can also specify a converter, validator and a handful of other properties per binding.
<p>

The next step is to specify how the values for each column are obtained:
<pre>
tableBinding.addBinding(
    "${ID}",    // Expression evaluated relative to each Bug.
                // In this case, it's treated as bug.getID().
    null,       // Target value (I'm not going to get into this parameter now)
    TableColumnParameter, 0); // Specifies the binding applies to the first column
</pre>
This specifies the expression ${ID} should be used to to obtain the value for the entries in the first column. This expression is evaluated relative to the element of each row (a Bug in this example). The expression ${ID} maps to invoking bug.getID() for each row. Of course the appropriate listeners are installed to keep everything in sync, meaning that if someone invokes aBug.setID(xxx), the private TableModel implementation built underneath will fire the appropriate notification and JTable will update the display. Similarly, if you edit the table, binding will end up invoking aBug.setID(xxx). Nice!
<p>
The expression language for the source is nearly the same one used by JSF/JSP. The only changes are to support a handful of things needed for binding, none-the-less it's nearly the same. Do a search for JSF expression language if you're interested in the specifics. The language for the target is just a dot separated property syntax. I'm not going to get into why these are different now.
<p>
The second and third columns are similarly bound:
<pre>
tableBinding.addBinding("${priority}", null, TableColumnParameter, 1);
tableBinding.addBinding("${synopsis}", null, TableColumnParameter, 2);
</pre>
Similar to the "elements" property, JTable also exposes two properties that correspond to the selection: "selectedElement" and "selectedElements". The "selectedElement" property corresponds to selected object from the List bound to the "elements" property. The "selectedElements" contains the List of selected elements, again from the List bound to the "elements" property.
<p>
Each of the detail components (text fields, slider, combobox) are driven from the selection of the table. As such, they are bound to a property of the "selectedElements" property from the table. This means that any time the selection of the table changes, the text field is updated appropriately. The following shows the code for the first text field:
<pre>
Binding textFieldBinding = context.addBinding(
    bugTable,                 // Source of the binding, the JTable in this case.
    "${selectedElements.ID}", // Expression relative to the source. Evaluates to the
                              // the id property of each of the selected elements
    idTF,                     // Target of the binding, a JTextField here.
    "text",                   // The target property to bind to.
    // The next line specifies the 'text' property should change as you type.
    // The default is to change the property on enter/focus leaving.
    TextChangeStrategyParameter, TextChangeStrategy.CHANGE_ON_TYPE);
</pre>
Notice the text field is bound to the "selectedElements.ID" property. But "selectedElements" is a List and has no "ID" property! How can this be? In the modified version of EL being used any properties relative to a List are expanded in place, and the result of the evaluation is a List of values. For example, if there are two selected elements, the modifier version of EL evaluates this expression to the "ID" for each of the elements. Beans Binding then passes the List of values through a ListCondenser that returns one value to pass to the target of the binding. For this example I wanted to show all the selected values wrapped in quotes and separated by commas. Here's the code that does this:
<pre>
textFieldBinding.setListCondenser(ListCondenser.concatenatingCondenser(
    "\"",   // The string placed before each element
    "\"",   // The string paced after each element
    ", ")); // The string that separates each element.
</pre>
The binding I want to mention is the summary label. Notice the summary label shows a count for the selection. This can be handled with a function in EL. Here's the code:
<pre>
context.addBinding(
  bugTable,  // The source of the binding, the table in this case.
  // The expression evaluated relative to the source. Notice this makes use
  // of the function "listSize", that returns an size of the list supplied to it.
  "${bb:listSize(selectedElements)} of ${bb:listSize(elements)} are selected",
  summaryLabel, // The target of the binding, a JLabel here.
  "text");      // The target property to bind to
</pre>
This shows how to use static methods as part of the EL expression. The expression "${bb:listSize(selectedElements)}" evaluates to the size of the list. As the "selectedElements" property of the table updates every time the selection changes, the summary label is kept in sync appropriately.
<p>
The last step is to realize the bindings, or install all the necessary listeners so that everything remains in sync:
<pre>
context.bind();
</pre>
And that's it.
<p>
There's a lot that I haven't gotten into, but this should give you a feel for where beans binding is headed.
<p>
Next question I know is going to be asked: where's the source? I'm working on it!
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>On Look and Feels</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2007/01/on_look_and_fee.html" />
<modified>2007-01-25T23:05:23Z</modified>
<issued>2007-01-25T23:05:19Z</issued>
<id>tag:weblogs.java.net,2007:/blog/zixle/234.6414</id>
<created>2007-01-25T23:05:19Z</created>
<summary type="text/plain">Scott questions whether the system look and feels are really as important as we&apos;ve been lead to believe.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[For the past couple of releases we've been focusing significantly on the system look and feels (Windows XP/Vista and GTK). Sure, we updated the Java look and feel in 1.5, but that was more of redocorating the bathroom rather then remodeling the house. Our focus on system look and feels was in response to the cries of customers and the community screaming that the system look and feel matters, and is in fact is critical! After all, who wants an app that doesn't fit in with the desktop?
<p>
Yes, who does? Well, I suspect many folks actually don't care! That's right, I'm questioning whether the system look and feels matter as much as we've been lead to believe. But I'm getting ahead of myself.
<p>

Here's the set of apps I run day in and day out on my Windows box:
      Firefox, Thunderbird, NetBeans, Gaim, <a href="http://www.ghisler.com">Total Commander</a>, Yahoo! Widgets and Light Room. What's interesting about this set of apps is that I suspect Total Commander is the only one that directly uses the system toolkit. That's just a suspicion though, I don't confidently know what Total Commander is running, all I can say about Total Commander is that it doesn't look very much like an XP app. Total Commander is a better fit for DOS;) I use Total Commander as it extremely customizable and you can do everything from the keyboard; a power users dream for file management. That it isn't the prettiest app doesn't bother me (well, ok, if given the choice between two functionally equivalent versions of the app, I'll choose the prettier).

<p>
Adobe's Light Room is a wonderful app, but it looks nothing like the rest of the desktop. Does that bother me? No! I use Light Room for a particular task, and that it doesn't look much like the desktop in no way bothers me.

<p>
We also have a Mac at home. Surely the Mac must be a paragon of
      consistency, right? Well, take a look at any of Apple's
      pro-apps, such as Aperture or Final Cut Pro. These apps
      definitely have an Apple'ish look to them, but they don't have
      the exact same look as the rest of the apps on the desktop.

<p>
And lets not forget the web apps that are out there. Gmail is great for occasional email, but it too doesn't look anything like a desktop app. The same is true of most AJAX and Flash apps.

<p>
So, what gives? Does the system look and feel matter? Could it be that the cries we were hearing were primarily the result of our dated Java look and feel? And the knee jerk reaction from the community was to demand the system look and feel? I have to wonder that if we had kept the Java look and feel modern and fresh (not Ocean), would we have heard such a demand for the system look and feel?

<p>
I suppose you could take my argument one step further, that the look of the app doesn't really matter that much to the end user. What does matter is whether they are able to complete the task they need to get done with it in a timely manner. Anything on top of that is just icing.

<p>
While I'm not sold on apps needing to look consistent on the desktop, having a consistent feel, in terms of keyboard accessibility, is critical to me. Can you imagine not being able to use control-c (on windows) for copy? Or what about something other than alt-F4 for closing windows. That would drive me batty in a heart beat.

<p>
Now for the controversial (yes, it gets better). Is it time we take some of the energy we've been putting in the system look and feels and channel it into a stellar cross platform look and feel? Even if it came at the expense of fixing more off by one pixel problems in the system look and feels for a release?

<p>
Please don't take this train of thought as an indication that we're
    decommitting from the system look and feels. That couldn't be
    further from the truth; the same number of folks continue to fix
    bugs for both XP and GTK as has for the last release (well, except
    for occasional help from an <a href="http://weblogs.java.net/blog/campbell/">unlikely source</a>)! I'm posting this
    blog to stir up a discussion on the merits of the system look and
    feels as compared to cross platform look and feels.

<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott]]>

</content>
</entry>
<entry>
<title>Extreme List View</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/12/extreme_list_vi.html" />
<modified>2006-12-18T16:39:55Z</modified>
<issued>2006-12-18T16:39:50Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.6190</id>
<created>2006-12-18T16:39:50Z</created>
<summary type="text/plain">In my last blog we finally released the source for
this years Extreme GUI Makeover talk; hooray! There are a number of
aspects of the app that are worth exploring. For this blog, I want to
explore how the extreme list view was done.
</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[In my <a href="http://weblogs.java.net/blog/zixle/archive/2006/11/extreme_gui_mak.html">last blog</a> we finally released the source for
this years Extreme GUI Makeover talk; hooray! There are a number of
aspects of the app that are worth exploring. For this blog, I want to
explore how the extreme list view was done. What I'm calling the
extreme list view can be seen in the following screen shot:

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.12.18/elv.small.png">

<p align="center">
<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.12.18/elv.jnlp"><img src="http://weblogs.java.net/blog/zixle/archive/2006.12.18/launch-button.png"></a>
<p>
As you may be able to surmise from the screen shot, and the name, the
extreme list view is nothing more than a JList with a custom
ListCellRenderer. The ListCellRenderer is implemented as a JPanel,
that uses GroupLayout to achieve the desired effect.
<p>
If you look at the layout of each cell, you'll notice the layout is
nearly a grid, but not quite. The first row has two columns, the
second row one column, and the third row two columns. The reason this
doesn't fit well with a grid is that the second columns of the first
and last row shouldn't have the same size. Most grid based layout
managers enforce all columns to have the same size. I've no doubt
there is some grid based layout managers that does this, but not
GridBagLayout. Of course you could always implement this as nested
panels, but that should be avoided when possible!
<p>
GroupLayout does not enforce the components be in a grid, although
grid based layouts are certainly possible with GroupLayout. As such,
GroupLayout is particularly well suited for this layout, and it gave
me another chance to play with GroupLayout. Here's how this layout is
implemented in terms of GroupLayout. For those wishing to learn more
about GroupLayout before getting into the nitty gritty, we've just
updated the Swing Tutorial to include coverage of GroupLayout, which
can be found <a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/group.html">here</a>.
<p>
GroupLayout treats each axis independently. Looking at the horizontal
axis, visually you can see space needs to be provided for the image,
followed by three rows of text. This translates to:

<pre>
(IP + rows)
</pre>

Which equates to a sequential group with the image component, followed
by the rows. As the rows are positioned in the same
space, horizontally, the components in each row need to be placed in a
parallel group:

<pre>
(I + [R1 R2 R2])
</pre>

I'm using parens to denote sequential groups, and brackets to denote
parallel groups. The first and third row consist of two components
each for the differing labels. As the labels in each are placed one
after another, a sequential group is used:

<pre>
(I + [(S + C0) C1 (C2 + F)])
</pre>

The key for this layout is that all extra space should go to the
subject and content text. This is achieved by explicitly specifing the
subject and context text have a minimum and preferred size of 1, and a
maximum size of Integer.MAX_VALUE:

<pre>
  addComponent(component, 1, 1, Integer.MAX_VALUE);
</pre>

All other components are forced to use their preferred size for the
min/pref/max. As JLabels already do this, you can use the single
argument addComponent, or explicitly request this behavior with the
following code:

<pre>
  addComponent(component, PREFERRED_SIZE, PREFERRED_SIZE, PREFERRED_SIZE);
</pre>

Viewed graphically, this looks like:

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.12.18/blog.png">
<p>
Here's the complete code for creating the horizontal grouping:

<pre>
  GroupLayout.SequentialGroup hg = layout.createSequentialGroup();
  layout.setHorizontalGroup(hg);
  // Add the image panel with a fixed size
  hg.addComponent(imagePanel, IS, IS, IS).
    // Create parallel group that will contain the rows
    addGroup(layout.createParallelGroup().
      // First row contains the subject, and date labels
      // Notice the subject is infinitely resizable
      addGroup(layout.createSequentialGroup().
        addComponent(subjectLabel, 1, 1, Integer.MAX_VALUE).
        addComponent(dateLabel)).
      // Second row is a single label that is infinitely resizable.
      addComponent(labels[0], 1, 1, Integer.MAX_VALUE).
      // Third row contains two labels: text and from. The label
      // is infinitely resizable, where as the from label is fixed
      // at its preferred size.
      addGroup(layout.createSequentialGroup().
        addComponent(labels[1], 1, 1, Integer.MAX_VALUE).
        addComponent(fromLabel)));
</pre>

The only other trick to mention when using a JList like this is be
absolutely sure to set the prototype cell value. If you don't, JList is
going to query the renderer for the preferred size for each and every
value in the list. As you can imagine, a layout like this is NOT
cheap! Additionally each cell should have the same size, so specifying
the protoype value is the way to go!
<p>
I'm not going to go through the code for the vertical axis, hopefully
it's not that hard to grok given the walk through of the horizontal
axis.
<p>
Here's the complete <a href="http://weblogs.java.net/blog/zixle/archive/2006.12.18/ELV-1.0-src.zip">source</a> for the app.
<p>
Enjoy!
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>Extreme GUI Makeover: 2006</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/11/extreme_gui_mak.html" />
<modified>2006-11-21T15:42:35Z</modified>
<issued>2006-11-21T15:42:26Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.6010</id>
<created>2006-11-21T15:42:26Z</created>
<summary type="text/plain">After much legal maneuvering the source code from this years Extreme GUI Makeover session at JavaOne is finally available! Download the source and try the demo out.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[During one of many brainstorming sessions for the 2005 JavaOne
conference the Swing team latched on to the idea of doing a makeover
talk. Borrowing the idea from the popular TV show, the idea was to
makeover an ugly ducking of a Swing app, turning it into a beautiful
swan. <a href="http://weblogs.java.net/blog/shan_man/">Shannon</a>, <a
href="http://jroller.com/page/gfx">Romain</a> and myself had a great
time putting the app together and doing the session; as a bonus, the
session was one of the most popular talks. WOW! Because we had so much
fun, and because of the popularity, we decided to do a similar session
for 2006.
<p>
For the 2006 session we decided to make over a mail client. A good
chunk of my day goes into reading email, so I had a plethora of ideas
in this area. This was true of Romain and Shannon as well. We didn't
have the time to craft a real mail client, or the time to come up to
speed on one of the many open source mail clients out there. As such,
we put together a shell of a mail app. It has just the amount of
functionality we needed for the demo, that's it. We tuned for demos,
with just the windows look and feel. Romain says it works on OS X,
which is surprising. There is plenty of stuff that doesn't work, and
you can get stuck in areas where you can't get out. It's most
defintely a DEMO! Let me say that one more time, THIS IS A DEMO! 
None-the-less we've gotten a slew of email requests for the code, some
friendly, some not so friendly. So, in all it's glory, here's the <a
href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/mailman-1.0-src.zip">code</a>.
<p>
Here's a screen shot of the before:
<p align=center><a href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/plain1.png"><img src="http://weblogs.java.net/blog/zixle/archive/2006.10.21/plain1-small.png"></a>
<p>
And the after, with a traditional table:
<p align=center><a href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/extreme1.png"><img src="http://weblogs.java.net/blog/zixle/archive/2006.10.21/extreme1-small.png"></a>
<p>
A screen shot with a rich list:
<p align=center><a href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/extreme2.png"><img src="http://weblogs.java.net/blog/zixle/archive/2006.10.21/extreme2-small.png"></a>
<p>
The screen shots don't do the transformation justice; they can't show
transitions, animation, custom drag and drop effects... For that, you
need to run the app. You can run the app by downloanding <a
href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/mailman-1.0.zip">this</a>
zip file, extracting it, and invoking <code>java -jar
mailman.jar</code> on the jar file.
<p>
All 103 slides from the session can be found <a href="http://weblogs.java.net/blog/zixle/archive/2006.10.21/session.pdf">here</a>.
<p>
A big part of the presentation was showing the ugly, then
transitioning to the improved. To provide a similar experience for
those trying the app now, I scripted the whole app with Robot. If you
don't move the mouse, the demo will drive itself. It'll take you
through each of the stages showing the before and after. I'll go over
how this was done in more detail later. For those that want to know
now, look in the appscripter package.
<p>
Wouldn't it be cool if I did voice overs? Or music? Or provided links
to the code while running it? Or fixed some bugs in the message
handling? Or added comments? Yes, yes and YES! The list of things I
would like to do to this app could keep me employed for years. But, I
know folks want the source, so we're cutting the cord. Have at it! I
do promise Shannon, Romain and myself will go over aspects of the
session in more detail over time.
<p>
Enjoy!
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Scott
<p>
PS For those thinking a webstart link would be ideal. I agree. For
JavaOne I threw a 5MB mailbox at the original parsing code, and it
took minutes. I rewrote it using NIO, which means it won't work from
WebStart. <a href="http://weblogs.java.net/blog/hansmuller/">Hans</a> pointed this out months ago. Not having time myself, I
dropped the gauntlet and challenged Hans to give me the code that
would suck down the mailboxes so that it would work from
WebStart. Months later that code isn't in my mail box. Perhaps the
public humiliation will be enough to get Hans to give me the code and
I'll update the app later on;)
]]>

</content>
</entry>
<entry>
<title>Cut, Copy and Paste</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/08/cut_copy_and_pa.html" />
<modified>2006-08-08T05:27:12Z</modified>
<issued>2006-08-08T05:27:07Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.5312</id>
<created>2006-08-08T05:27:07Z</created>
<summary type="text/plain">After a long hiatus I&apos;m returning to a series of blogs on architecting
applications. This time around I&apos;m covering a simple way to provide
rich cut, copy and paste behavior in an application.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[After a long hiatus I'm returning to a series of blogs on architecting
applications. This time around I'm covering a simple way to provide
rich cut, copy and paste behavior in an application.
<p>
As usual, for those wishing to cut to the chase, here's the app:
<p align="center">
   <img src="http://weblogs.java.net/blog/zixle/archive/2006.01.18/passwordStore.png"/>
<p align="center">
<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.08.02/PasswordStore.jnlp">
	  <img src="http://weblogs.java.net/blog/hansmuller/archive/jws-launch-button.png" 
	    width="88" 
	    height="23""/>
</a>
<p>
Many Swing components provide cut, copy and paste support. For
example, JTextField supports cut, copy and paste out the box. This is
hardly revolutionary; todays developers expect such behavior out of
the box.
<p>
Swing's cut, copy and paste support is provided by
javax.swing.TransferHandler. TransferHandler provides Actions for cut,
copy and paste. Unfortunately the enabled state of the actions is not
updated based on context, and the actions target the source of the
event. In other words, the actions provided by TransferHandler are not
appropriate for use on menus or toolbars.
<p>
While the Actions provided by TransferHandler have limited usage, the
remaining portions of TransferHandler are imminently more useful (even
more so in 1.6). Rather than reinvent the wheel, I'll provide new
Actions that target TransferHandler.
<p>
Here's the list of requirements for cut, copy and paste actions:
<ul>
<li>The actions should track the permanent focus owner. For example, you
would not want the copy action to target a menu when it has focus.
<li>The paste action should only be enabled if the clipboard has a data
flavor supported by the component.
<li>The cut and copy actions need to update based on the selection of
the component. For example, if a text field has focus, the cut and
copy actions should only be enabled if the selection is not empty. <a href="#selection">*</a>
</ul>
Ideally it would be easy to enable this support in an existing
application with minimal fuss. To that end a helper class,
CutCopyPasteHelper, with all static methods is used. The static
methods operate on any JComponent and do not look for specific
interface in determining cut, copy and paste support. 
<p>
Targetting the focused component is easily done with the
KeyboardFocusManager. The KeyboardFocusManager maintains a bound
property for the permanent focus owner. To listen for changes one need
only install a PropertyChangeListener. The following code illustrates
this:
<pre>
  PropertyChangeListener focusListener = new PropertyChangeListener {
    public void propertyChange(PropertyChangeEvent e) {
      if (e.getPropertyName() == "permanentFocusOwner") {
        // The permanent focus owner has changed.
        newPermanentFocusOwner((Component)e.getNewValue());
      }
    }
  };
  KeyboardFocusManager.getCurrentKeyboardFocusManager().
      addPropertyChangeListener(focusListener);
</pre>
The paste action is the trickiest. The paste action is enabled if the
paste action is enabled on the focus component, and a data flavor on
the clipboard matches the one supplied for the focused
component. Tracking the set of data flavors on the clipboard is easily
done using a FlavorListener. The following code illustrates this:
<pre>
  FlavorListener flavorListener = new FlavorListener {
    public void flavorsChanged(FlavorEvent e) {
      flavorsChanged();
    }
  };
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  clipboard.addFlavorListener(flavorListener);
</pre>

The set of data flavors a component supports for paste must be
provided by the developer. This is done with the following method:

<pre>
  CutCopyPasteHelper.registerDataFlavors(component,  DataFlavor...dataFlavors);
</pre>

In addition to setting the set of flavors, you must explicitly enable
the ability for a component to paste. This is done with the
<code>setPasteEnabled</code> method. Seperating the set of flavors
from the enable state makes it easier to operate on each
independently. For example, once you've registered the flavors, if you
subsequently need to change the paste enabled state you need only
invoke <code>setPasteEnabled</code>.
<p>
Once you've enabled paste on the component and registered the set of
flavors, CutCopyPasteHelper has all the information needed to update
the paste action appropriately for you.
<p>
The cut and copy actions are simpler. These are updated based on the
focused component, and whether or not you've enabled cut and copy. For
example, a text field with an empty selection would disable the cut
and copy actions. On the other hand, a text field with a non-empty
selection would enable the cut and copy actions. CutCopyPasteHelper
provides the setCutEnabled and setCopyEnabled methods for this.
<p>
Many Swing components provide keyboard bindings that target the
actions provided by TransferHandler. CutCopyPasteHelper provides
replacements for these actions. For a component to use
CutCopyPasteHelper actions you must change the bindings registered on
each component to target CutCopyPasteHelper. This is done using the
ActionMap and InputMap. CutCopyPasteHelper provides the
registerCutCopyPasteBindings that takes care of this.
<p>
Here's a cheat sheet for using these actions with a component:

<ol>
<li>Provide a TransferHandler for the component.
<li>Replace the bindings provided by Swing using the
registerCutCopyPasteBindings method.
<li>Register the set of data flavors supported during paste by way of
the registerDataFlavors method.
<li>Install a listener on the component that updates the cut and copy
state based on the component's selection. The cut and copy state is
changed using the setCutEnabled and setCopyEnabled methods.
</ol>

Here's the relevant portions of the code for the password store app
that enable cut, copy and paste on entryList (a JList):

<pre>
  // Step 1
  // Install the TransferHandler.
  entryList.setTransferHandler(new ListTransferHandler());

  // Step 2
  // Register key bindings that target the cut, copy, and paste actions
  // provided by CutCopyPasteHelper.
  CutCopyPasteHelper.registerCutCopyPasteBindings(entryList, true);

  // Step 3
  // Register the data flavors on the list:
  CutCopyPasteHelper.registerDataFlavors(entryList,
                PASSWORD_ENTRY_DATA_FLAVOR);
  // Enable paste
  CutCopyPasteHelper.setPasteEnabled(entryList, true);

  // Step 4
  // Install listener to update cut/copy state based on selection
  ListSelectionListener selectionListener = new ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
      if (!e.getValueIsAdjusting()) {
        boolean hasSelection = (entryList.getMinSelectionIndex() != -1);
        CutCopyPasteHelper.setCopyEnabled(entryList, hasSelection);
        CutCopyPasteHelper.setCutEnabled(entryList, hasSelection);
      }
    }
  };
  entryList.addListSelectionListener(new ListSelectionHandler());
</pre>

To use the actions provided by CutCopyPasteHelper in a menu is no
different than any other action, invoke setAction or use a constructor
that takes an Action. Please note that the name, accelerator,
mnemonic, and icon are not provided. It is expected you'll set these
directly on the menu or button using the action.

<h3><a name="selection">*</a> Selection</h3>

You'll notice these actions target the focused component. Targetting
the focused component is problematic if you need another component to
get focus while firing the action. For example, if a button wired to
the cut action gets focus, the cut action targets the button; this is
not what you want. This is trivially fixed by invoking
setFocusable(false) on the button, but that's a stop-gap. The larger
issue is how to determine the target of these actions. In nearly all
cases targetting the permanent focus owner is what you want, but there
are exceptions. This is a larger issue, to which many folks have
proposed big solutions. It's something that needs more study, and has
been bothering both <a
href="http://weblogs.java.net/blog/hansmuller">Hans</a> and myself...

<h3>The Sandbox</h3>

For security reasons a sandboxed app can't get at the system
clipboard. This is most definitely a major pain! I've primarily
concerned myself with apps that have full access to the clipboard. I
suspect there are some things that could be done to make support of
these actions better when in the sandbox. That's for another day though.
<p>
Early on I mentioned I wanted it to be trivial to wire these actions
up to existing components. I've done the work for the text
components. As this blog is now gargantuan in size, I'll save that for
a later blog. In the mean time, here's the latest <a
href="http://weblogs.java.net/blog/zixle/archive/2006.08.02/passwordstore.zip">source</a> for the password store app, and <a
href="http://weblogs.java.net/blog/zixle/archive/2006.08.02/fabric.zip">source</a> for fabric. For those that look at the source,
you'll see a bunch of stuff I haven't gotten to. That's for a later
day as well... Oh, and yes, CutCopyPasteHelper will eventually makes it's way
into Swing in some form or another.
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>BeanShell + 2D = Instant Graphics</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/07/beanshell_2d_in.html" />
<modified>2006-07-11T23:48:31Z</modified>
<issued>2006-07-11T23:45:08Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.5175</id>
<created>2006-07-11T23:45:08Z</created>
<summary type="text/plain">Over the years I&apos;ve worked on a number of projects that involved
various 2D rendering operations. The usual cycle for such work is to
tweak rendering code, compile, run, examine the results using a
magnifier, and repeat until I&apos;m happy with it. This certainly works,
but takes a bit longer than is ideal. When I needed to do a lot of
graphics tweaking for this years &apos;Extreme GUI Makeover&apos; talk, I
figured it was time to see if I could streamline this process. This
blog shows what I&apos;ve concocted.
</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[Over the years I've worked on a number of projects that involved
various 2D rendering operations. The usual cycle for such work is to
tweak rendering code, compile, run, examine the results using a
magnifier, and repeat until I'm happy with it. This certainly works,
but takes a bit longer than is ideal. When I needed to do a lot of
graphics tweaking for this years 'Extreme GUI Makeover' talk, I
figured it was time to see if I could streamline this process. This
blog shows what I've concocted.
<p>
I was looking for something that would allow me to get rid of the usual
compile and run cycle; I want instant feedback! More often than not I
need to zoom in on the results. As such, a magnifier would have to be
included. In the end I want Java code, so alternative scripting
languages aren't an option.
<p>
Thankfully I stumbled upon <a href="http://www.beanshell.org">Bean
Shell</a>. BeanShell fit my needs perfectly! With BeanShell you can
evaluate blocks of Java code; just what I was looking for. Evaluating
raw Java code, for my purposes, is hardly interesting with out the
ability to supply state to the interpeter. BeanShell allows you to
supply state to the java code it executes. In this way I can pass a
graphics object to the interpeter that is available to the java code
that is executed. Putting all the pieces together enables me to
execute arbitrary Java code, rendering the results to an Image and
showing that Image using Swing components. Just what I wanted.
<p>
Here's the resulting application. For reasons I did not investigate
BeanShell won't run in the sandbox. As such, the application is signed
and needs to live outside the sandbox. Also note the application
stores the script in the file ~/.igeScript.

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.07.10/ige.png" width="618" height="537"/>
<p align="center">
<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.07.10/ige.jnlp">
  <img src="http://weblogs.java.net/blog/hansmuller/archive/jws-launch-button.png">
</a>

<h3>How does it work?</h3>

As you type in the text area a timer is started. When the timer fires
(~1 second) the script is evaluated in a background thread using
BeanShell. The intepreter is passed three variables: the width of the
image, the height of the image, and a graphics obtained from an image
of the specified size. If the interpeter successfully evaluates the
script, the image is rendered in two places. One shows the results at
actual size, the other scaled.
<p>
One of the first things you'll notice is the text area does no
completion for you. This is most definitely annoying! Ideally the
editor would behave just like that of NetBeans. As such, a better fit
would be to turn this into a NetBeans module. That way NetBeans would
provide all the completion, syntax highlighting, and error reporting
for free. Nice! If I have time, I'll do this; but don't hold your
breath;)
<p>
In my first take at the app I evaluated the script nearly immediately,
and on the EDT. This worked perfectly, until I typed in something
like:
<pre>
  while (x < y) {
  }
</pre>

As I was evaluating the script almost immediately, on the EDT, this
caused an infinite loop and I was screwed. This very rarely comes in
every day coding as you don't compile and run while typing. Not the
case here.
<p>
I was hoping BeanShell would allow me to stop the intepreter, but it
doesn't. To solve this problem I moved evaluating the script to a
separate thread. If the evaluation takes more than than 3 seconds, an
option pane is shown asking if the background thread should be
killed. To kill the background thread I use Thread.stop. This is
obviously bad, and can cause problems, but is better than causing the
app to be wedged...

<h3>Running the app</h3>

Try changing a couple of the variables at the top of the file to see
the results. For example, try changing <code>TEXT_COLOR</code> to
<code>Color.RED</code> and notice the effects render
immediately. Trying changing the <code>KERNEL_SIZE</code> and
<code>BLUR_FACTOR</code> to see the results on the drop shadow.
<p>
You can of course delete all the code and start a new.

<h3>Random other things</h3>

The app uses  <a
href="http://weblogs.java.net/blog/hansmuller">Hans's</a> <a
href="http://weblogs.java.net/blog/hansmuller/archive/2006/03/multisplitpane.html">MultiSplitPane</a>
to house the components. This makes it easy to resize the app to fit
your needs.
<p>
I'm also using an early prototype of <a
href="http://weblogs.java.net/blog/zixle/archive/2006/05/ease_of_swing_d.html">beans
binding</a> to keep the model in sync with the width, height, scale
and text area. I'm still working on the legal issues of releasing this
code. I'll do a blog once it's all straightened out.
<p>
I'm using a variant of the application framework I had been developing
in my blog series on <a
href="http://weblogs.java.net/blog/zixle/archive/2006/03/architecting_ap_2.html">architecting
applications</a>. I will return to the application framework series,
but will stop development of the pieces that overlap with Hans's <a
href="http://weblogs.java.net/blog/hansmuller/archive/2006/06/jsr_296_bows_sw.html">JSR
296: Swing appliction framework</a>.
<p>
Full source can be found <a href="http://weblogs.java.net/blog/zixle/archive/2006.07.10/src.zip">here</a>.
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>Modern Heap View</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/06/modern_heap_vie.html" />
<modified>2006-06-19T14:25:53Z</modified>
<issued>2006-06-19T14:25:41Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.5048</id>
<created>2006-06-19T14:25:41Z</created>
<summary type="text/plain">See a modern heap view, and in the process learn about some of the more obscure parts of 2D. Pictures, demo, source and a NetBeans module are all included!</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[As part of brain storming on future ideas one of the visual designers
did a mockup of NetBeans that included a more modern looking heap
view. I was rather taken by it and decided to do an implementation,
hence this blog. I had to cut a few corners, and features, to avoid the view consuming too much memory. As usual, for those that don't have the stomach to wade through a blog the following shows the heap view in action.

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/heapViewTest.png" width="147" height="190">
<p align="center">
<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.06.17/HeapViewTest.jnlp">
  <img src="http://weblogs.java.net/blog/hansmuller/archive/jws-launch-button.png">
</a>

<p>

Source can be found <a
href="http://weblogs.java.net/blog/zixle/archive/2006.06.17/HeapView.java">here</a>.

<p>

For those using NetBeans 5.0 I've created a module with this heap view
in it. The module is <a
href="http://weblogs.java.net/blog/zixle/archive/2006.06.17/modernheapviewmodule.nbm">here</a>.
To install this in NetBeans click on Tools -> Module Manager, then
click on the 'Update' button, choose the 'Install Manually Downloaded
Modules' and follow the instructions. Here's the <a href="http://weblogs.java.net/blog/zixle/archive/2006.06.17/modernHeapViewModule.zip">source</a> for the module.

<h3>Dissecting the View</h3>

The view consists of the following:

<table>
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/1.png" width="95" height="34">
  <td>Small Border
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/2.png" width="95" height="34">
  <td>A background gradient.
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/3.png" width="95" height="34">
  <td>A grid with each cell having a slight gradient.
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/4.png" width="95" height="34">
  <td>Vertical lines representing the amount of the heap being used at a
particular time. The ticks are also drawn with a gradient.
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/5.png" width="95" height="34">
  <td>A grid on top of the ticks.
<tr>
  <td><img src="http://weblogs.java.net/blog/zixle/archive/2006.06.17/6.png" width="95" height="34">
  <td>Textual description showing amount of heap being used, with a
drop shadow.
</table>

Yes, gradients galore;)

<p>

You can toggle a couple of options by right clicking.

<h3>Gradients</h3>

The code for rendering a gradient is pretty simple, pick the end
points, colors, invoke setPaint, and fill in the region:

<pre>
  Paint gradient = new GradientPaint(0, 0, color1, width, height, color2);
  g2.setPaint(gradient);
  g2.fillRect(0, 0, width, height);
</pre>

It's worth mentioning a couple of new gradients have recently been
added to 1.6. I wanted this code to work with 1.4.2, so I restricted
myself to GradientPaint. For details on the new gradient classes look
to <a href="http://weblogs.java.net/blog/campbell/">Chris's</a> <a href="http://weblogs.java.net/blog/campbell/archive/2006/04/five_easy_piece.html">blog</a>.

<h3>The vitues of caching</h3>

A good heap view shouldn't accumulate much garbage on any given paint,
otherwise when the heap view is running you'll be able to watch the
amount of garbage continually grow and shrink even when you're not
doing anything. Believe me, my first implementations did this and it
wasn't pretty;) To avoid the garbage I ended up creating a bunch of
images and doing image copies from the images. Turns out this
generates very little garbage and is much faster; all around goodness.

<p>

If you look at the source you'll see a number of images. There is one
for the border, background gradient and tiles, another for the tick
gradient, and two for the text (I'll get to that in second).

<h3>The drop shadow</h3>

If you look closely at the text you can see a slight drop shadow. To
create a drop shadow requires a bit of the more obscure 2D
operations. The general algorithm is:

<ol>
<li>Render what ever it is you want to create the drop shadow of to an
image.
<li>Render that image to another image using a BufferedImageOp.
<li>Rerender step 1 to the second image.
</ol>

Here's what this looks like in terms of creating a drop shadow for text.

<pre>
  BufferedImage textImage = ... ;
  BufferedImage dropShadowImage = ...;

  // Step 1:
  Graphics2D textImageG = textImage.createGraphics();
  textImageG.drawString(...);
  textImageG.dispose();

  // Step 2:
  Graphics2D dropShadowG = dropShadowImage.createGraphics();
  dropShadowG.drawImage(textImage, bufferedImageOp, shiftX, shiftY);

  // Step 3:
  drawShadowG.drawString(...);
  drawShadowG.dispose();
</pre>

So, what is bufferedImageOp? For a drop shadow effect it's a
ConvolveOp. Here's the code:

<pre>
  int kw = KERNEL_SIZE, kh = KERNEL_SIZE;
  float blurFactor = BLUR_FACTOR;
  float[] kernelData = new float[kw * kh];
  for (int i = 0; i < kernelData.length; i++) {
    kernelData[i] = blurFactor;
  }
  bufferedImageOp = new ConvolveOp(new Kernel(kw, kh, kernelData));
</pre>

As I said, a bit obscure. You can play with the KERNEL_SIZE and
BLUR_FACTORY to get different effects, I've used 3 and .1
respectively.

<p>

As part of this years Extreme GUI talk I wrote an app that lets you
interactively experiment with these values and see the effects. I'll
blog on that later. I know, I know, what about the architecture
series? I will return to it! And yes, this years extreme GUI code will
be released. And yes, I've been a bad BAD boy! Bad Scott, bad Scott!

<p>

Sorry, back to this blog.

<h3>Variations</h3>

I experimented with a handful of variations until I arrived at this
one. You can try a couple of them by right clicking on the heap view
and choosing one of the options. And just as with the heap view in
NetBeans, a single click triggers a GC (I didn't add the flashing
effect, sorry).

<p>

I suspect I could have spent weeks fine tuning (I'm aware of at least one
other optimization I could have done), adding more features,
refining the look, more effects (yes, there is one effect buried in
the implementation and I played with more) ... But, I figured it best
to push out what's there and move on to the next thing.

<p>

So, that's it. What do you think?

<p>

&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>Ease of Swing Development - Beans Binding</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/05/ease_of_swing_d.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-05-23T23:25:43Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.4886</id>
<created>2006-05-23T23:25:43Z</created>
<summary type="text/plain">Beans binding (JSR 295) aims to make it easy to bind your application model to Swing components. Get the skinny on beans binding, a demo, and how you can help!</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[With few exceptions (<a href="http://jcp.org/en/jsr/detail?id=56">Web
Start</a> and <a href="http://jcp.org/en/jsr/detail?id=57">Beans
Persistence</a>) there have been very few desktop related JSRs. Well,
we're going to change that. <a
href="http://jcp.org/en/jsr/detail?id=295">Beans Binding</a>, or JSR
295, has just passed inception ballot and the expert group is now
forming. Wahoo!

<h3>Beans Binding</h3>

A big part of what we, desktop developers, have to write every day is
component wiring code, or glue code. Glue code is the code that
connects components to your application model. For example, connecting
a slider's value propety to a property of the selected object in a
table requires glue code. Here's an example.

<pre>
  slider.addValueListener(new ChangeListener() {
    public void stateChanged(ChangeEvent e) {
      selectedObject.setFoo(slider.getValue());
    }
  });

  selectedObject.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChanged(PropertyChangeEvent e) {
      if (e.getPropertyName() == null || "foo".equals(e.getPropertyName())) {
        slider.setValue(selectedObject.getFoo());
      }
    }
  });
</pre>

Anyone that's written this code, and we all have, knows it's painful,
tedious and error prone. YUCK!

<p>

Beans Binding aims to make it easy to bind two properties of
two objects together. Taking the slider example, you might be
able to bind the two together with the following code.

<pre>
  bind(slider, "value", selectedObject, "foo");
</pre>

This would bind the slider's value property to the selectedObject's
foo property, such that changes to the slider are reflected in the
selectedObject, and vice versa. Take this as just an example, the JSR
was just filed, so no API has been decided upon.

<p>

Of course this is a simplified view of things, beans binding will
likely accomodate converters, and possibly validators. To be
successful it will also need to accomodate renderers.

At this years JavaOne conference Hans and myself did a presentation on
beans binding with a handful of demos. You can view the presentation
<a
href="http://weblogs.java.net/blog/zixle/archive/2006.05.23/JavaOne.2006.binding.pdf">here</a>.
The source for the first demo can be found <a
href="http://weblogs.java.net/blog/zixle/archive/2006.05.23/crazyFaces.src.zip">here</a>.
Notice the source contains two variants, one implemented in terms of
binding (<a
href="http://weblogs.java.net/blog/zixle/archive/2006.05.23/BindingCaricatureController.java">BindingCaricatureController</a>),
the other with typical listeners (<a
href="http://weblogs.java.net/blog/zixle/archive/2006.05.23/NoBindingCaricatureController.java">NoBindingCaricatureController</a>).
You can run the demo by clicking on the launch button below.

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.05.23/crazyFaces.png">

<p align="center">
<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.05.23/CrazyFaces.jnlp">
  <img src="http://weblogs.java.net/blog/hansmuller/archive/jws-launch-button.png">
</a>

<p>

We also demoed how beans binding addresses more traditional database
apps at JavaOne, but being a database app, it requires a bit
more setup so I'm holding off on publishing it now. I'll return to it
later on.

<h3>Data Binding</h3>

How does this relate to data binding, and specifically <a
href="http://jcp.org/en/jsr/detail?id=227">JSR 227: A Standard Data Binding &
Data Access Facility for J2EE</a>?

<p>

WARNING: I am not on the expert group for 227, and do not speak for
Mike De Groot, the spec lead for 227. Mike was gracious enough to meet
with me on various occasions to help me understand where he believes
227 is going. The following is based on those conversations, but as
227 is not finalized, it may change.

<p>

JSR 227 aims to make it easy to bind to any data, be it a ResultSet an
XML service, you name it. 227 will not care about the type of your
data, there will be an intermediary class used to access the data that
knows the specific of your data. In this manner, assuming you have the
intermediary layer, 227 will work with any data. Beans Binding is much
narrower than that, it assumes you have your data in a well known
type, a bean and possibly a Map. A big part of 227 includes
declaratively describing the bindings and data, Beans Binding will not
include a delcarative XML file describing the bindings and data.

<p>

So, why care about beans binding? If you're a good OO citizen you've
already created some mapping layer from your database (or other
backend) to real objects. Hibernate, Mustang's DataSet, and
EJB 3 all do this; they provide a way for you to get real object
graphs. Once you've done that, it'll just work with beans binding and
the world will be a happier place. Ok, perhaps that's a bit grand, but
at the least beans binding will simplify wiring your application
objects to components.

<h3>What can you do?</h3>

As I mentioned, beans binding will be done as a JSR. If you are
interested in helping shape the API, and have time to be on an expert
group, head over to the <a
href="http://jcp.org/en/jsr/detail?id=295">home page for beans
binding</a> and click on the <a
href="http://jcp.org/en/jsr/egnom?id=295">I would like to join this
JSR</a> link. For those that are interested, but can't commit the
time, watch the <a href="http://jcp.org/en/jsr/detail?id=295">home
page for 295</a> for updates. Within the next month or so we'll settle
on a java.net project for the prototype including public forums and
what not.

<p>

&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>Architecting Applications 3: the Controller</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/03/architecting_ap_2.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-03-07T00:24:32Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.4258</id>
<created>2006-03-07T00:24:32Z</created>
<summary type="text/plain">This is the third blog in a series on architecting applications. In
the first blog I discussed the application I&apos;m going to develop,
how it would be architected, and briefly went over the model. In the
second article I motivated the need for an Application class that is
suitable for typical Swing based Apps, as well as the functionality it
should provide. In this third installment I&apos;ll go over the role of the
controller as used in the MVC architecture. As promised, this blog has
a runnable demo.
</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[This is the third blog in a series on architecting applications. In
the <a href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap.html">first blog</a> I discussed the application I'm going to develop,
how it would be architected, and briefly went over the model. In the
<a href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap_1.html">second blog</a> I motivated the need for an Application class that is
suitable for typical Swing based Apps, as well as the functionality it
should provide. In this third installment I'll go over the role of the
controller as used in the MVC architecture. As promised, this blog has
a runnable demo.
<p>
I was strongly tempted to redo the model a bit for this installment of
the application architecture series, but I had to hold back lest there
be no demo for this article. So, without further ado, here's the
demo.
<table  align="center">
    <tr>
      <td>
	<a href="http://www.java.net/download/javadesktop/blogs/zixle/2006.03.02/PasswordStore.jnlp">
	  <img src="http://weblogs.java.net/blog/hansmuller/archive/jws-launch-button.png" 
	    width="88" 
	    height="23"
	    style="border-style:none; margin-right:44px"/>
	</a>
      </td>
      <td>
	<img src="http://weblogs.java.net/blog/zixle/archive/2006.01.18/passwordStore.png"
	  style="border: none; "/>
	<br />

	<font size="-1"><i>Password Store Demo Screenshot</i></font>
      </td>
    </tr>
</table> 
<p>
The demo is far from complete. In particular most of the menus are not
wired up and are disabled. The only menu items that work is creating
a new account (control-n). I'll flesh out the implementation of the
remaining menu items in future articles. Complete source code is
available at the end of the article.
<p>
To keep the app from being signed, but be able to store information
between sessions I'm using the persistence service provided by
webstart. The persistence service allows an app to save state in a
secure way, similar to cookies. If you run the app from the command
line it'll save the file into your home directory.

<h3>Controller</h3>

As early explained this app is built using the model-view-controller
pattern. As the name implies the pattern dictates you design three
distinct areas: the model, for modelling your data; the view, for the
graphical view the user will interact with; lastly, the controller
which orchestrates the two, keeping them in sync.

For the purposes of this demo the Controller will perform the
following operations:

<ol>
  <li>Create and assemble the view.
  <li>Wire the view to the model or controller as appropriate.
  <li>Keep the view and model in sync.
</ol>

A Controller need not create and assemble the view. Undoubtedly the
view is intimately tied to the controller, and in may apps, such as
this one, making the controller create the UI fits naturally. Ideally
the view would be loaded from a GUI builder and the controller could
extract the components it's interested in, but that's for a separate
blog.

<h3>Creating the UI</h3>

Creating and assembling the view is pretty much route Swing
programming. As earlier mentioned I'm not going to have any external
dependencies, so I wrote this code by hand using GridBagLayout. I
honestly don't recommend hand coding UI creation or layout, it's
painful, error prone, and a maintenance burden. Use a builder. Of
course I recommend Matisse and once done will will publish a followup
blog that's written in terms of Matisse.

<h4>JList Wiring</h4>

The model consists of a List of PasswordEntrys. This will be
rendered as a JList. JList itself requires a model which implements
the ListModel interface. To display the List of PasswordEntrys a
custom ListModel implementation will be used that talks to the List of
PasswordEntrys from the model. Here's the code.

<pre>
  private PasswordModel model;
  private class PasswordListModel extends AbstractListModel {
    public int getSize() {
      return model.getPasswordEntries().size();
    }
    public Object getElementAt(int index) {
      return model.getPasswordEntries().get(index);
    }
  }
</pre>

Notice the ListModel returns a PasswordEntry for each of the
elements. JList's default cell renderer will use toString on this,
which isn't all that helpful here. As such we'll need a custom
ListCellRenderer. I'm not going to go over the code for the
CellRenderer, it's pretty simple, if you're curious look to the
source.

<h3>Synchronization</h3>

Keeping the model and view in sync is one of the more tedious aspects
of an application of this sort. To reinforce that, consider what
happens when the user types in a text field. As the user types in a
text field the model must be updated. As I wanted the model to be
updated immediately I'm using a DocumentListener. DocumentListeners
are notified immediately of any changes to a text component. Here's
the code.

<pre>
  // Install a DocumentListener on the host text field
  hostTF.addDocumentListener(new DocumentHandler());

  private class DocumentHandler implements DocumentListener {
    public void insertUpdate(DocumentEvent e) {
      edited(e);
    }

    public void removeUpdate(DocumentEvent e) {
      edited(e);
    }

    public void changedUpdate(DocumentEvent e) {
      // TextFields can ignore this one.
    }

    private void edited(DocumentEvent e) {
      // The host text field was edited, update the model
      hostChanged();
    }
  }

  // A valid edit has occured, update the model.
  private void hostChanged() {
    getSelectedEntry().setHost(hostTF.getText());
  }
</pre>

The real source code is slightly different in so far as I've coalesced
all the listeners into a single class, which leads to a switch like
statement in the edited method. None-the-less the core idea is the
same. As the document is edited the model is immediately updated.
<p>
The Controller must also track changes made to the model by other
parts of the app. For example, an Action might directly update the model. To
track changes to the model the Controller installs a
PropertyChangeListener on each PasswordEntry. Here's the code.

<pre>
  // Install a listener on each entry
  entry.addPropertyChangeListener(new PropertyChangeHandler());

  private class PropertyChangeHandler implements PropertyChangeListener {
    public void propertyChange(PropertyChangeEvent e) {
      entryChanged((PasswordEntry)e.getSource(), e.getPropertyName());
    }
  }

  private void entryChanged(PasswordEntry passwordEntry,
          String propertyChanged) {
    // Notify the list of the change
    listModel.fireContentsChanged(model.getPasswordEntries().
              indexOf(passwordEntry));

    // If the selected entry was changed, update the appropriate text field
    if (getSelectedEntry() == passwordEntry) {
      if (propertyChanged == "host") {
        hostTF.setText(passwordEntry.getHost());
      } else ...
    }
  }
</pre>

A PropertyChangeListener is attached to
every entry in the model. When an entry is changed, ListModel notification
is dispatched (listModel.fireContentsChanged), which triggers the JList to
update itself. Similarly if the contents of the selected entry have
changed the appropriate text field is updated.
<p>
The following graphically depicts changes originating from the text field.

<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.03.02/textToEntry.png"/>
<p>
The following depicts changes originating from the model.
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.03.02/entryToText.png"/>
<p>
What's wrong with the previous code? Turns out there is a subtle
bug. When the text field changes, we update the model, which sends
notification, which triggers a reset of the text field. JTextField
(actually javax.swing.text.Document) does not allow a listener to
modify the contents, so that this code triggers Swing to thrown an
exception. Here's a graphical depiction of this.
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.03.02/loop.png"/>
<p>
Notice the textfield on both sides.
<p>
This is happening because the Controller doesn't realize that it initiated
the change to the model and doesn't need to update the display. There
are a couple of schemes for dealing with this. You can disable and
reenable listeners, check the contents of the text fields, or keep a
property around. I've settled for keeping a property around that
tracks if the Controller initiated a change to the model.
<p>
Here's the revised code for the edited method that is invoked when the
text is edited.

<pre>
  private void hostChanged() {
    if (!changingHost) {
      changingHost = true;
      getSelectedEntry().setHost(hostTF.getText());
      changingHost = false;
    }
  }
</pre>
Now the hostChanged method knows who originated the code. If
changingHost is true it indicates the change was initiated by the
Controller and the Controller need not do anything.
<p>
The entryChanged method is similarly updated.
<pre>
  private void entryChanged(PasswordEntry passwordEntry,
          String propertyChanged) {
    // Notify the list of the change
    listModel.entryChanged(model.getPasswordEntries().
              indexOf(passwordEntry));

    if (getSelectedEntry() == passwordEntry) {
      if (propertyChanged == "host" && changingHost) {
        changingHost = true;
        hostTF.setText(passwordEntry.getHost());
        changingHost = false;
      } else ...
    }
  }
</pre>

This is most definitely one of the more tedious aspects of GUI
programming. One forgotten !changingXXX or changingXXX=true, and
you'll either get an exception, or you'll stop updating the
model or UI. Ugh!
<p>
The last thing worth mentioning is that as List has no notification
the Controller can not listen to it. Instead all mutations to the list
itself are done in Controller which will update the ListModel
appropriately. I will revist this later on.

<h3>Source</h3>

I've broken the source into
two chunks: <a href="http://weblogs.java.net/blog/zixle/archive/2006.03.02/fabric.zip">fabric.zip</a> contains the generally useful stuff, and
<a href="http://weblogs.java.net/blog/zixle/archive/2006.03.02/passwordStore.zip">passwordStore.zip</a> contains the source specific to PasswordStore.

<h3>Summary</h3>

So, where are we? I've gone through the model, I've touched on the
Application class, and went through the bulk of the
controller. At this point the app is usable, but by no means a complete
app. Next time around I'll either go over undo, or
cut/copy/paste. Which would you prefer?
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott
]]>

</content>
</entry>
<entry>
<title>Mustang: the little things</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/02/mustang_the_lit.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-02-15T16:08:19Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.4080</id>
<created>2006-02-15T16:08:19Z</created>
<summary type="text/plain">I&apos;m taking a brief hiatus from my series of blogs on application architecture to join in the mustang blog carnival extravaganza. The bulk of the major features have already been covered, in this blog I&apos;ll explore some of the smaller bug fixs and RFEs we&apos;ve done to make mustang that much more compelling.
</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[<p>
I'm taking a brief hiatus from my series of blogs on <a
	href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap_1.html">application architecture</a> to join in the <a href="http://weblogs.java.net/blog/mreinhold/archive/2006/02/mustang_beta_bl.html">mustang blog carnival</a> extravaganza that is celebrating the <a href="http://weblogs.java.net/blog/mreinhold/archive/2006/02/mustang_beta_bl.html">beta</a> release of mustang. The bulk of the major features have already been covered. <a href="http://weblogs.java.net/blog/chet/archive/2005/04/swing_update_no_1.html">Chet</a> and <a href="http://weblogs.java.net/blog/zixle/archive/2005/04/no_more_gray_re_1.html">myself</a> have covered true double buffering, Shannon has covered the <a href="http://weblogs.java.net/blog/shan_man/archive/2006/01/location_sensit.html">dnd work</a>, <a href="http://download.java.net/jdk6/docs/api/javax/swing/SwingWorker.html">SwingWorker</a> was covered in an <a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/enhancements/index.html">article</a>, <a href="http://weblogs.java.net/blog/zixle/archive/2005/08/should_we_gener_1.html">table's sorting and filtering API</a> was discussed as well. I've even covered some of the smaller stuff, like the <a href="http://weblogs.java.net/blog/zixle/archive/2005/11/changes_to_acti.html">action improvements</a>. So, what to talk about?
</p>
<p>
After struggling with what to cover, I realized that some times it's not just the big things that make a release matter, but a culmination of both the big things and the little things. So, in this blog I'll cover the little bugs and features. The things that by themselves aren't that big, but undoubtedly make the release that much better.
</p>
<h3>ButtonGroup.clearSelection</h3>
<p>
Anyone that has seriously used ButtonGroup undoubtedly stumbled over
      the inability to clear the selection of the group. For example,
      lets say you have two toggle buttons in a button group and you
      need to clear the selection to an initial state. Previously
      there was no way to do this! Sure, there are some ugly
      workarounds, but thankfully we've addressed this problem now. In
      mustang we've added the method <a href="http://download.java.net/jdk6/docs/api/javax/swing/ButtonGroup.html#clearSelection()">clearSelection</a> to ButtonGroup. Funny enough this is the oldest bug we've fixed for Swing in mustang.
</p>
<h3>Justified Text</h3>
<p>
One of Swing's most voted on bugs is support for fully justified text
      in Swing's text components. What's doubly bad about this feature
      is that we've always had API that implies it would work, but it
      never had. Well, thankfully it now does. Here's a screen shot of
      Stylepad in mustang with fully justified text:
</p>
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.02.08/aligned.bad.png">
</p>
<p>
YIKES! I know, it turns out we justified the last line of the text which obviously doesn't look good. Thankfully this bug will be fixed before the final release of mustang. Here's a screenshot with the fix:
</p>
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.02.08/aligned.good.png">
</p>
<h3>Window.setMinimumSize</h3>
<p>
Another long time sore point is the inability to enforce a minimum size for Windows. Being a long time NeXT/Apple user I've always thought it a good idea to enforce a minimum window size. That doesn't appear to be too common on Windows boxs though. None-the-less the API now works and you can set a minimum size. Here's an internal app that can't enforce a minimum size:
</p>
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.02.08/glow.15.png">
</p>
<p>
And that same app with mustang when it could enforce a minimum size:
</p>
<p align="center">
<img src="http://weblogs.java.net/blog/zixle/archive/2006.02.08/glow.16.png">
</p>
<p>
Nice!
</p>
<h3>Painting offscreen components</h3>
<p>
Getting into the more niche arena, Swing's painting code has always
      ignored painting child components if the Component is not
      contained in a Window or an Applet. Why would you ever do this?
      Perhaps you want to render a JComponent, and it's children, to
      an image. This came up a number of times on the forum. Finally
      it's fixed! I know, a bit obscure but none-the-less
      interesting. See <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215148">6215148</a> for details.
</p>
<h3>JTextComponent printing</h3>
<p>
The last thing I'll mention is certainly not a small change. Following
      the JTable printing support we added in 1.5 we've now made it
      trivial to print text component. JTextComponent now has a <a href="http://download.java.net/jdk6/docs/api/javax/swing/text/JTextComponent.html#print()">print</a> method that allows you to specify various attributes of the print job, such as header, footer... This means it's now trivial to print a text component and have the output reformatted for the page, just like a user would expect!
</p>
<p>
So anyway, if you haven't yet tried mustang I highly recommend you
      give it a whirl. As an incentive we <a
	href="http://weblogs.java.net/blog/robogeek/archive/2006/01/announcing_the.html">announced</a> a free t-shirt for any regressions that are found as well as the chance at winning an <a href="http://www.sun.com/desktop/workstation/ultra20">Ultra 20</a>, sadly this offer isn't availble to Sun engineers;)
</p>
<p>
Next time around, more application architure.
</p>
<p>
     -Scott
</p>
]]>

</content>
</entry>
<entry>
<title>Architecting Applications 2: the Application class</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap_1.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-01-30T23:03:13Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.4031</id>
<created>2006-01-30T23:03:13Z</created>
<summary type="text/plain">This is the second blog in a series on architecting applications. In the first blog I discussed the application I&apos;m going to develop, how it would be architected, and briefly went over the model. In this second article I&apos;ll motivate the need for an Application class that is suitable for typical Swing based Apps, as well as the functionality it should provide.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[    This is the second blog in a series on architecting
    applications. In the first <a
      href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap.html">blog</a> I discussed the application 
    I'm going to develop, how it would be architected, and briefly
    went over the model. In this second article I'll motivate the need
    for an Application class that is suitable for typical Swing based
    Apps, as well as the functionality it should provide.

    <p>
      Swing is an incredibly rich toolkit, but to date we haven't
      provided much guidance on how to structure your app. How should
      I start my app? Where should I place resource bundles in my
      project? How should I use preferences? Logging? ... The list
      goes on. While I'm not going to address all of these issues I'm
      going to focus on the first issue. How should I start my app?
      The first thing to comes to mind is something along the lines
      of:
<pre>
public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame(...);
    frame.pack();
    frame.show();
  }
}
</pre>
Unfortunately this code can be problematic. Swing is not thread safe
    and unless otherwise mentioned in the javadoc all methods must be
    invoked on the event dispatch thread. As it's name implies, the
    main method is invoked on the main thread. The preceeding code
    calls into Swing widgets from this thread - the main thread. As
    such, it is entirely likely that wierd errors or exceptions can
    occur. Why you ask? Invoking various Swing/AWT methods can result
    in events getting posted to the event dispatch thread. If the
    thread scheduler happens to schedule processing of those events
    while the main thread is still invoking methods you'll have two
    threads interacting with the same Swing component at the same
    time - a definite no-no. Best case, it all works and you're fine,
    worst case you get random deadlocks!

<p>
We currently recommend an approach along the following lines:
<pre>
public class Main {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
      }
    });
  }
}
</pre>
But this gets to be a bit painful to remember every time
    through. Ideally there would be a class that isolates you from the
    various Swing threading vagaries. Furthermore, it would be great
    if this class were seamlessly integrated with builders.
<p>
Here's how I would like to write main:
<pre>
public class Main {
  public static void main(String[] args) {
    new MyApplication().start();
  }
}
</pre>
    And MyApplication would have methods intended to be overriden that
    are called on the event dispatch thread. This way I don't have to
    do the invokeLater everytime, it's handled for me.

Beyond handling proper initialization there are a number of other
    features common across Swing apps. In no particular order they
    are:

<ul>
<li>Registering as the uncaught exception handler such that if an
	uncaught exception is received the application alerts the user
	and exits.
<li>Using a ResourceBundle for localized resources. For small to mid
	size apps putting resources into a single resource bundle is
	fine, large apps will undoubtedly want finer granularity.
<li>Using a PreferencesNode for persistant information. Again, for
	small to mid size apps using the same preferences nodes is
	fine, for large apps you will undoubtedly want finer
	granularity. There are problems with using preferences in
	webstart/plugin, but that's for another day.
<li>A single point to exit the app, as well as the ability for
	listeners to cancel the exit.
<li>Ability to block exiting until background threads have finished as
	well as displaying a dialog to the user while this is
	happening.
</ul>

Is this everything? I'm sure there is more common functionality, but this is a good start.
<p>
I suspect anyone that's developed a number of Swing apps has already
      developed a similar class. You can find the version used in this
      article <a
	href="http://weblogs.java.net/blog/zixle/archive/2006.01.30/Application.java">here</a>, or peruse the doc of <a
	href="http://weblogs.java.net/blog/zixle/archive/2006.01.30/Application.html">Application</a> and <a
	href="http://weblogs.java.net/blog/zixle/archive/2006.01.30/ApplicationListener.html">ApplicationListener</a>.
<p>
Application itself is an abstract class, a typical subclass, and the one for this blog series, looks like:
<pre>
public class PasswordStoreApplication extends Application {
    public String getName() {
        return "PasswordStore";
    }

    protected void init() {
        JFrame frame = new JFrame(getName());
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                exit();
            }
        });
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new PasswordStoreApplication().start();
    }
}
</pre>

Notice main, it's now short and sweet. While not obvious, init is
    invoked on the event dispatch thread and I needn't worry about
    using invokeLater, it's all done for me! Similarly the look and
    feel is automatically set to the system look and feel for me from
    the preInit method.
<p>
Those that look at the code will notice a couple of hard code
      strings. Bad Scott, bad Scott! I did this to make it easier for
      folks to download the source and use, but this most definitely
      needs to come from a resource bundle. You've been warned.
<p>
I've tried to keep Application simple. It doesn't know about Frame or
      any other application specific components, that's up to
      subclasses. In fact it probably makes sense to have a subclass
      that knows about a single frame. Such a subclass would further
      reduce the code of PasswordStoreApplication as registering the
      window listener, packing and all that would be done for you.
<p>
One of the biggest open questions with a class like Application, is
      should it do dependency injection? That is, should Application
      contain meta information about your application that can be used
      in configuring it. For example, database style apps need to know
      what database to connect to. Does it make sense to have
      Application configure your connection settings so that there is
      a standard place for this meta information? I'm not sure, but
      I'm certainly interested in feedback from the community.
<p>
A related issue I mentioned is how this class would work with
      builders. Ideally one would be able to create a 'Swing
      Application' which in turn would configure things like the name
      of the application and perhaps a class to create on the EDT. In
      this way developers needn't subclass Application directly, the
      builders would do the wiring for you. More research is needed on
      this.
<p>
<a href="http://weblogs.java.net/blog/hansmuller">Hans</a> suggested
      rather than using listeners you have the ability to register
      Runnables given a name, with the Runnables processed at well
      known points in the app life cycle. This would make for a more
      loosely specified init sequence, but one that allows for a bit
      more than listeners. I'll explore this in more detail later.
<p>
In the interest of keeping each blog short and sweet I'm going to wrap
      this one up here. I had hoped to have something running by this
      point, but I'll leave that to the next blog. In the next blog
      I'll create a controller class along with the UI that ties the
      model together and is started with the Application subclass. I
      promise that by the end of the next article you'll be able to
      click on a web start link to see the app running.
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott]]>

</content>
</entry>
<entry>
<title>Architecting Applications 1: the model</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2006/01/architecting_ap.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-01-19T00:33:58Z</issued>
<id>tag:weblogs.java.net,2006:/blog/zixle/234.3968</id>
<created>2006-01-19T00:33:58Z</created>
<summary type="text/plain">In the first of a series of blogs on creating a Swing app I motivate the app, the architecture the app will use, and quickly touch on the model. In addition I&apos;ll show how easy it is to use beans persistence as a way to save and restore beans.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[While in Russia (see <a href="http://weblogs.java.net/blog/shan_man/archive/2006/01/first_class_dra.html">Shannon's blog</a>) I wrote a long blog on undo, actions and various other things. At the time I felt this a bit long for a blog and so it languishes in my unposted blog queue (with many others, but that's a different story). I really liked the idea of writing a series of blogs centered around a real app though, hence this blog and hopefully more to follow.
<p>
As part of the series I'll cover architecting the app (this blog) including using beans persistence as a way to save the model, Actions, Undo, the need for an application class, data binding and various other things that come up.
<p>
In writing a series of blogs around an app I thought it important that the app be compelling enough, but not too big such that you become bogged down in all the implementation details. So, I needed something small but not too small as to be trivial. I may have erred on the side of trivial, none-the-less the concepts and points are still worth while to explore.


<p>
If you're like me you have a ton of passwords for various machines and web sites that you're expected to remember. As an added wrinkle each password should be unique and unreadable, ugh! Added together this makes it nearly impossible to remember all your passwords. For this series I'm going to stick with a simple app that manages passwords. A Java based app that stores passwords has the added bonus of being able to run from a USB memory stick on the three major platforms: Windows, OS X and Linux. I realize there are loads of commercial apps in this space that undoubtedly go way beyond what I'm going to do. None-the-less such an app is at least interesting and not too complicated (at least as far I'm going to take it).
<p>
Here's roughly where I'll end up when done with the series:
<p align="center"><img src="http://weblogs.java.net/blog/zixle/archive/2006.01.18/passwordStore.png" width="309" height="329">
<p>
A password store will need to be encrypted, I'm going to leave that out as I don't want to worry about the legal issues of such a blog.
<p>
There are various approaches to designing apps. Some of the more popular patterns are <a href="http://www.martinfowler.com/eaaDev/ModelViewPresenter.html">model-view-presenter</a> , <a href="http://www.martinfowler.com/eaaDev/PresentationModel.html">presentation model</a> and model-view-controller. I'm a fan of the latter, and especially for an app of this size. In creating any app you'll need to make the desicision as to which approach is applicable to your design space and requirements.
<p>
Model-View-Controller dictates that you have a clear model for your application. The Controller coordinates keeping the view and model in sync. The model for Password Store is going to be trivial. It'll consist of a List of PasswordEntrys. Each PasswordEntry will have the following properties: host, user and password. PasswordEntry will be a proper bean in that it'll communicate changes to listeners by way of a PropertyChangeListener notification. That means any time you change a property all PropertyChangeListeners are notified of the change. Here's the code for setting the host property:

<pre>
    public void setHost(String host) {
        String oldHost = this.host;
        this.host = host;
        if (propertySupport != null) {
            propertySupport.firePropertyChange("host", oldHost, host);
        }
    }
</pre>

The methods for setting the user and password follow the same pattern. This may seem like a lot of boilerplate code for something so trivial, and I would agree. I'll try and address that in a later blog.
<p>
The List of PasswordEntrys will be managed by a PasswordModel. PasswordModel will initially expose the List as modifiable. I suspect this is a bad long term decision, but I'm going to stick with it in hopes of keeping the API simple and not getting bogged down in details. Here's the code:

<pre>
public class PasswordModel {
    private List<PasswordEntry> passwordEntries;
    
    public PasswordModel() {
        passwordEntries = new ArrayList<PasswordEntry>(1);
    }
    public List<PasswordEntry> getPasswordEntries() {
        return passwordEntries;
    }
</pre>

The biggest downside with choosing List is that it doesn't notify listeners of changes to the contents. This is key, and something I'll touch on later.
<p>
An added bonus of making the PasswordEntrys proper beans is that I can save and restore the PasswordEntrys using beans persistence. Here's the code:

<pre>
    public void load(String file) throws IOException {
        BufferedInputStream inputStream = new BufferedInputStream(
                new FileInputStream(file));
        XMLDecoder decoder = new XMLDecoder(inputStream);
        List entries = (List)decoder.readObject();
        decoder.close();
        passwordEntries.clear();
        passwordEntries.addAll(entries);
    }
    
    public void save(String file) throws IOException {
        BufferedOutputStream outputStream = new BufferedOutputStream(
                new FileOutputStream(file));
        XMLEncoder encoder = new XMLEncoder(outputStream);
        encoder.writeObject(passwordEntries);
        encoder.close();
    }
</pre>

At this point we have the model, which by itself isn't all that interesting. Next time around by the end of the blog we should have something that you can at least run.
<p>
&nbsp;&nbsp;&nbsp;&nbsp;-Scott]]>

</content>
</entry>
<entry>
<title>JPasswordField with an empty echo character: the fix</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2005/12/jpasswordfield.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2005-12-19T23:38:30Z</issued>
<id>tag:weblogs.java.net,2005:/blog/zixle/234.3830</id>
<created>2005-12-19T23:38:30Z</created>
<summary type="text/plain">Learn why my last attempt at a password field with an empty space echo character failed and how to fix it. And of course a demo is thrown in for good measure.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[In my <a
href="http://weblogs.java.net/blog/zixle/archive/2005/12/variations_of_j.html">last</a>
blog I explained how to customize the visual feedback
provided by JPasswordField. Unfortunately the first option I detailed,
specifying a character that takes no space, had a bug in it. This blog
discusses the bug and how to fix it. If you want to
cut to the chase and run the demo it can be found <a
href="http://www.java.net/download/javadesktop/blogs/zixle/2005.12.19/variableWidthPasswords.jnlp">here</a>.
<p>
Specifying you want JPasswordField to render a character with no space
is as easy as:
<pre>
passwordField.setEchoCharacter('\u200b');
</pre>
As my last <a
href="http://www.java.net/download/javadesktop/blogs/zixle/2005.12.05/variableWidthPasswords.jnlp">demo</a>
illustrated, this will produce an ArithmeticException when you click on the password field (second one in the demo). As you
could probably guess the exception occurs because PasswordView is
dividing the width of the character without checking it,
resulting in the exception. The fix is to create a subclass of
PasswordView that overrides viewToModel without dividing by the
character width. Here's the code:
<pre>
  public int viewToModel(float fx, float fy, Shape boundsAsShape, Position.Bias[] bias) {
    boundsAsShape = adjustAllocation(boundsAsShape);
    Rectangle bounds = (boundsAsShape instanceof Rectangle) ?
                (Rectangle)boundsAsShape : boundsAsShape.getBounds();
    if (fx &lt; bounds.x) {
      return getStartOffset();
    }
    return getEndOffset();
  }
</pre>

With a character that takes up no space there's no way for the user to click 
anywhere but the beginning or end of the text. As such, 
viewToModel will return one of these.
<p>
To install this View you need to do something similar to that of the
last blog (refer to it for more details). Create a custom
JPasswordField, with a custom UI that returns the new View:
<pre>
  new JPasswordField() {
    public void updateUI() {
      setUI(new BasicPasswordFieldUI() {
        public View create(Element elem) {
          return new EmptySpacePasswordView(elem);
        }
      });
    }
  };
</pre>
And here's the <a href="http://www.java.net/download/javadesktop/blogs/zixle/2005.12.19/variableWidthPasswords.jnlp">demo</a>.
<p>
That's enough for passwordfield and text, next time around something
new.
]]>

</content>
</entry>
<entry>
<title>Variations of JPasswordField</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2005/12/variations_of_j.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2005-12-05T23:37:48Z</issued>
<id>tag:weblogs.java.net,2005:/blog/zixle/234.3740</id>
<created>2005-12-05T23:37:48Z</created>
<summary type="text/plain">Learn how to create alternate views of JPasswordField. In the proess I&apos;ll cover portions of Swing&apos;s text architecture.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[We've been gathering input from customers on various features they
would like to see us implement. At such a meeting one customer
requested a variation of JPasswordField. I figured it
would be interesting to blog on how you could modify JPasswordField to
vary the level of feedback it gives you. I'll cover various pieces of
Swing's text architecture in implementing one variation, as well as a
demo. If you want to cut to the chase, and have 1.5 installed, here's
the <a href="http://www.java.net/download/javadesktop/blogs/zixle/2005.12.05/variableWidthPasswords.jnlp">demo</a>.

<h3>Variation 1: no feedback</h3>

JPasswordField allows you to change the character it uses as the echo
character. That is, regardless of what character the user types you'll
see the echo character in it's place (<a href="#1">1</a>). A simple variation on
JPasswordField that makes it harder for folks to guess at what you're
typing is to change the echo character to a character that takes up no
space. You can use '\u200b' for this. This means that someone watching
you type at a password field won't be able to tell how many characters
are in your password. Of course they can still watch you type at the
keyboard, and the user gets very little feedback that they're actually
typing. Here's the code for this:

<pre>
  passwordField.setEchoCharacter('\u200b');
</pre>

<h3>Variation 2: variable amount of space</h3>

For those that remember NeXT's login dialog this'll be
familiar. Rather than using a single echo character a random amount
of white space will be used for each character. This has the benefit
over the previous approach in that you can't readily determine how
many characters are in the password, but you get some level of visual
feedback as you type your password. Apple's latest login dialogs don't
use this scheme, which would seem to indicate many folks didn't
like it.
<p>
All of Swing's text components, be it JPasswordField, JTextField,
JEditorPane share the same architecture. What applies to one equally
applies to the others. The text component use an instance
of View to do the rendering of text. In some ways a View can be
thought of as a lightweight Component, for example, View has methods
like getPreferredSpan, getMinimumSpan, paint... Just as Containers are
typically nested Views are usually nested as well. Views are
responsible doing the following:

<ul>
  <li>Layout of either text or child Views. This includes calculating
      a size for the View.
  <li>Painting.
  <li>Provide a mapping between model and view, or view and model. For
example, what position on screen is the character at location 5 in the
model.
  <li>Updating as the model changes.
</ul>

To implement the variable width password field we'll provide a custom
View implementation,
VariableWidthPasswordView. VariableWidthPasswordView will keep a List
of integers that correspond to the width of each characters. An
instance of Random will be used to determine the amount of white space
to use for a particular character:

<pre>
    private static final int MIN_WIDTH = 2;
    private static final int MAX_WIDTH = 15;

    private List&lt;Integer&gt; widths;
    private Random widthGenerator;

    private final int generateCharacterSize() {
        return widthGenerator.nextInt(MAX_WIDTH - MIN_WIDTH) + MIN_WIDTH;
    }
</pre>

Swing's text components use Document for modeling the text. As you
type at a text component the text is inserted into the Document. As
the Document is mutated the Views are notified (as long as the
document is associated with a JTextComponent). This allows the Views
to stay in sync with the model. VariableWidthPasswordView will
override the two View methods insertUpdate and removeUpdate, which are
invoked as text is inserted or removed. The implementation of these
two methods is roughly the same, they will update the cache of widths
and trigger a repaint. Here's the implementation of insertUpdate:

<pre>
    // Invoked when text has been inserted. Updates the width List appropriately
    public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
        for (int i = 0; i &lt; changes.getLength(); i++) {
            // Notice the autoboxing of int to Integer here.
            widths.add(i + changes.getOffset(), generateCharacterSize());
        }
        // Invoke super to update the visibility appropriately.
        super.insertUpdate(changes, a, f);
    }
</pre>

Invoking insertUpdate on super is done to update JPasswordFields
visibility model. It will also signal the preferred size of the View
has changed and repaint.
<p>
VariableWidthPasswordView doesn't need to paint, so it no-ops the
appropriate paint methods. The primary View method for painting is
paint. VariableWidthPasswordView is a subclass of FieldView which
implements paint to invoke drawSelectedText and
drawUnselectedText. VariableWidthPasswordView will override
drawSelectedText and drawUnselectedText to do nothing. This is done
rather than overriding paint as paint is also responsible for invoking
the appropriate methods to render the selection. By overriding
drawUnselectedText and drawSelectedText to do nothing the selection is
still rendered appropriately by FieldView.
<p>
To map from a position of text in the model to that of the view
VariableWidthPasswordView overrides modelToView. modelToView uses the
List of widths to determine the position. Here's the implementation:

<pre>
    public Shape modelToView(int pos, Shape a, Position.Bias b)
            throws BadLocationException {
        // JPasswordField and JTextField implement their own virtual
        // coordinate system. This does the necessary mapping.
        Rectangle bounds = adjustAllocation(a).getBounds();
        bounds.x += modelToView(pos);
        bounds.width = 1;
        return bounds;
    }
    // Returns the view x coordinate in the views space for the specified
    // model coordinate.
    private final int modelToView(int p1) {
        int offset = 0;
        int end = Math.min(widths.size(), p1);
        for (int i = 0; i &lt; end; i++) {
            // Notice the auto unboxing here.
            offset += widths.get(i);
        }
        return offset;
    }
</pre>

viewToModel does the inverse mapping:

<pre>
    public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
        a = adjustAllocation(a);
        Rectangle bounds = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
        int x = (int)fx - bounds.x;
        for (int i = 0; i &lt; widths.size(); i++) {
            // More auto unboxing.
            x -= widths.get(i);
            if (x &lt;= 0) {
                return i;
            }
        }
        return getEndOffset();
    }
</pre>

The last thing to mention is calculating the preferred size for the
View. That's done in terms of the widths field as well:

<pre>
    public float getPreferredSpan(int axis) {
        if (axis == View.X_AXIS) {
            int size = 0;
            for (Integer width : widths) {
                size += width;
            }
            return size;
        }
        return super.getPreferredSpan(axis);
    }
</pre>

Now that we have the View implementation we need to modify
JPasswordField to use it. Views are created by a ViewFactory, which is
obtained from the EditorKit. It's up to the TextUI implementation to
provide the EditorKit and ViewFactory. Unfortunately this means
creating a custom UI to plug-in
VariableWidthPasswordView. BasicPasswordFieldUI is itself a
ViewFactory, so that by subclassing BasicPasswordFieldUI we can
plug-in VariableWidthPasswordView. Here's the code for it:

<pre>
   // We generally discourage using UIs from one look and feel
   // with another look and feel. When using metal this will be fine,
   // that may not be true when using other look and feels.
   JPasswordField myPasswordField = new JPasswordField(10) {
        public void updateUI() {
            setUI(new BasicPasswordFieldUI() {
                public View create(Element elem) {
                    return new VariableWidthPasswordView(elem);
                }
            });
        }
    };
</pre>

The complete source for VariableWidthPasswordView can be found <a
href="http://weblogs.java.net/blog/zixle/archive/2005.12.05/VariableWidthPasswordView.java">here</a>. And the demo showing the various takes on
password field can be found <a href="http://www.java.net/download/javadesktop/blogs/zixle/2005.12.05/variableWidthPasswords.jnlp">here</a>. For more
information on Swing's text component take a look at the Swing
tutorial section on <a
href="http://java.sun.com/docs/books/tutorial/uiswing/components/text.html">Using
Text Components</a> or Tim's article on <a
href="http://java.sun.com/products/jfc/tsc/articles/text/overview/index.html">Using
the Swing Text Package</a>.
<p>
<a name="1"></a>1: As this demo shows it's possible to write a UI that ignores the
echo character. All of Sun's UIs honor the echo character, but third
party look and feels may not.
]]>

</content>
</entry>
<entry>
<title>Changes to Actions in 1.6</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/zixle/archive/2005/11/changes_to_acti.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2005-11-21T16:16:33Z</issued>
<id>tag:weblogs.java.net,2005:/blog/zixle/234.3669</id>
<created>2005-11-21T16:16:33Z</created>
<summary type="text/plain">Read up on the changes to Actions in 1.6.</summary>
<author>
<name>zixle</name>

<email>Scott.Violet@Sun.COM</email>
</author>
<dc:subject>Community: JDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/zixle/">
<![CDATA[In my last two blogs I've covered various aspects of Actions. I had
originally wanted to write about the changes to Actions in 1.6 but
felt the background would make interesting blogs. I promise this is
the last blog on Actions for a while;)
<p>
In 1.6 we've overhauled Actions adding new features and fixing a
handful of annoying bugs. For this blog I'm going to cover the new
features and when you might use them.
<p>
<h3>Action.SELECTED_KEY</h3>
<p>
The single biggest request for Actions was to add support for Actions
to represent selected state. In particular when an Action is attached
to a JRadioButton, JCheckBox, JToggleButton and the like there was no
way to change the selected state of the component from the Action and
have it reflected in the component. The new key Action.SELECTED_KEY
takes care of that. All components that visually represent a selection
will now listen for changes to the SELECTED_KEY and reflect that in
the component.
<p>
The following code creates a JRadioButton from an Action that is
initially selected:
<pre>
  Action action = new MyAction();
  // Make the action selected. 
  action.putValue(Action.SELECTED_KEY, Boolean.TRUE);
  JRadioButton selectedRadioButton = new JRadioButton(action);
</pre>
The SELECTED_KEY property is a bit different than other Action
properties. In particular the SELECTED_KEY property is both read and
set from the component; none of the other Action properties have this
characteristic. For example, if the user clicks on the radio button to
make it selected, the SELECTED_KEY property is set on the Action
from the component.
<p>
The following example shows how an Action could customize it's
behavior based on the selected state:
<pre>
  class BoldAction implements Action {
    public void actionPerformed(ActionEvent e) {
      toggleBold((Boolean)getValue(Action.SELECTED_KEY));
    }
  }
</pre>
<h3>Action.LARGE_ICON_KEY</h3>
<p>
All buttons and menu items have the ability to show an Icon. When a
button or menu item is associated with an Action the button or menu
item uses the Icon from the Action. This is problematic because
typically you want two different icons for these two components. To
address this in 1.6 we added LARGE_ICON_KEY. Menu items will only
use the Icon from the SMALL_ICON property. Buttons will first look for
the LARGE_ICON_KEY property, if it's value is non-null it will be
used, otherwise the value from SMALL_ICON is used. This enables you to
customize the Icon for the two different components.
<p>
The following example creates an Action with two different
icons. The menu item will use smallIcon and the button largeIcon:
<pre>
  Action action = new MyAction();
  action.putValue(Action.SMALL_ICON, smallIcon);
  action.putValue(Action.LARGE_ICON_KEY, largeIcon);
  // menu item will use smallIcon
  new JMenuItem(action);
  // button will use largeIcon
  new JButton(action);
</pre>
Note: the term button is a bit overloaded. AbstractButton is the
superclass of both menu items and classes such as JButton,
JToggleButton, JRadioButton ... In this context when referring to
button I mean all non JMenuItem subclasses that extend AbstractButton.
<h3>Action.DISPLAYED_MNEMONIC_INDEX_KEY</h3>
This is useful for the rare cases where you don't want the first
occurence of a character in the text to be underlined. For example, 
a menu item with the text 'Save As' typically has the second 'a'
underlined. The following code shows how to do this:
<p>
<pre>
  Action action = new MyAction();
  action.putValue(Action.NAME, "Save As");
  // Notice the autoboxing here.
  action.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
  action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, 5);
  new JMenuItem(action);
</pre>
Be careful when using DISPLAYED_MNEMONIC_INDEX_KEY. In particular if
you change the mnemonic you should be sure you change the
DISPLAYED_MNEMONIC_INDEX_KEY as well.
<h3>AbstractButton.setHideActionText</h3>
This property allows you to specify whether or not AbstractButton
should show the NAME property from the Action as the buttons
text. Consider if you have a menu item and toolbar button attached to
the same Action. To have non-empty text on the menu item the Action
will have a non-null value for it's NAME property. If you don't want
the toolbar button to show the text you would invoke
setHideActionText(true). The following code illustates this:
<pre>
  Action action = new MyAction();
  action.putValue(Action.NAME, "Save As");
  new JMenuItem(action);
  JButton toolbarButton = new JButton(action);
  // We don't want the button to mirror the text from the Action.
  toolbarButton.setHideActionText(true);
</pre>
<h3>System property swing.actions.reconfigureOnNull</h3>
The beans specification indicates that a <code>null</code> property
name can be used to indicate multiple values have changed.  By default
Swing components that take an <code>Action</code> do not handle such a
change.  To indicate that Swing should treat <code>null</code>
according to the beans specification set the system property
<code>swing.actions.reconfigureOnNull</code> to the
<code>String</code> value <code>true</code>.
<p>
This property is useful for cases where you want to do a bunch of
changes to an Action without sending individual property changes, and
then have all listeners refetch properties when done. I honestly can't
say I have ever had a need for this functionality, but it's now there.
<p>
The
javadoc for <a
href="http://download.java.net/jdk6/docs/api/javax/swing/Action.html">Action</a>
now details all this information as well as how the various components
support the different Action properties.
<p>
As usual, if you want to try out these changes (and the rest of the
goodness in 1.6) download the source and binaries from <a
href="http://mustang.dev.java.net/">mustang snapshot release</a>. 
]]>

</content>
</entry>

</feed>