<?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>Ben Galbraith&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/" />
<modified>2008-01-27T05:59:44Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/javaben/112</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, javaben</copyright>
<entry>
<title>Of Fonts and Java2D</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2008/01/of_fonts_and_ja.html" />
<modified>2008-01-27T05:59:44Z</modified>
<issued>2008-01-25T16:08:38Z</issued>
<id>tag:weblogs.java.net,2008:/blog/javaben/112.9067</id>
<created>2008-01-25T16:08:38Z</created>
<summary type="text/plain">A poorly-rendered typeface can really ruin my day. This entry describes my past and recent efforts to get beautiful type in my Java Swing applications.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[		<p>
			<i>The other day I googled for information on nice-looking fonts
				for Java2D and found nothing; this entry is largely to help future
				googlers.</i>
		</p>
		<p>
			A poorly-rendered typeface can really ruin my day. I'm passionate
			about creating beautiful software. Well, for the sake of those who've
			seen my code, I should clarify: beautiful user interfaces.
		</p>
		<p>
			Generally, I'm satisfied that when my attempts fall short of my ideals,
			I'm the weak link in the process. After all, I control every pixel
			on the screen, so whether they look purty or not is <i>my</i> problem.
		</p>
		<p>
			Except for the fonts. Ah, the fonts. Translating typefaces into pixels
			is a complex problem I'm all too happy to leave to others
			to solve. But of course, that's the double-edged sword; I'm stuck with
			other people's solutions, be they good, bad, or somewhere
			in-between.
		</p>
		<p>
			I often find myself building user interfaces in Java Swing. Interestingly,
			Swing typically renders its own fonts--it doesn't rely on the underlying
			operating system. (Apple's JRE lets developers choose between having the OS
			or Java2D do the font rendering, but in the future, it appears this choice
			will go away in favor of Java2D). This could be a really good thing, if
			Java2D rendered better than the OS. Unfortunately, when compared to Windows
			 and OS X, it doesn't. (It might render better than Linux, but I've never cared about 
			that OS.)
		</p>
		<p>
			This characteristic of Java GUIs is still arguably a good thing, because Java 
			applications render consistently across differently platforms; consistently 
			subpar rendering to many is better than inconsistent rendering behavior, 
			which could lead to all kinds of problems when the bounds of strings are different
			on different operating systems.
		</p>
		<p>
			<b>The Problems with Java2D Fonts</b>
		</p>
		<p>
			I've been blabbing about how Java2D font rendering is worse than that of
			Windows and OS X. In what way is it worse? Back in 2004, <a href="http://www.galbraiths.org/fonts/fontReport.pdf">I identified and documented what I
				judged to be the four most serious problems</a>. 
				I'll summarize these issues here:
		</p>
		<ol>
			<li>Swing makes it difficult to use anti-aliasing. Back then, you had
				to either create your own UI delegates or subclass components.
				Nowadays, Swing either does the right thing and/or lets you configure
				global anti-aliasing with system properties.
			</li>
			<li>Java2D mis-renders many glyphs. At the time, I listed these examples:
				<ul>
					<li>Arial 13pt (compare to Windows' 10pt rendering): x, S, X</li>
					<li>Microsoft Sans Serif 11pt (Windows' 8pt): x, C, M, Q, 8, 9, ) </li>
					<li>Times New Roman 16pt (Windows' 12pt): 8</li>
					<li>Tahoma 12pt (Windows' 9 pt): D</li>
					<li>Tahoma 13pt (Windows' 10 pt): q</li>
					<li>Tahoma 16pt (Windows' 12 pt): a, 0</li>
				</ul>
				Here's one screenshot from the document that illustrates the problem:
				<p>
				<img src="http://www.galbraiths.org/fonts/font1.png"/><br/>
				</p>
				Today, I glanced at the same font in the image with Java 6
				running on Windows XP today:
				<p>
					<img src="http://www.galbraiths.org/fonts/font2.png" alt="Java2D Arial 13pt rendering on Java 6 / WinXP"/>
				</p>
				We've come a ways: the 'S' looks great, but the 'x' and 'X' are probematic.
				That doesn't bother me too much, however, because of the next point.
			</li>
			<li>Java2D lacks sub-pixel anti-aliasing. Well, not anymore. As Chet explained at
				length some time ago, Java2D now uses sub-pixel anti-aliasing when rendering
				fonts. The Arial 13pt example above now looks like this:
				<p>
					<img src="http://www.galbraiths.org/fonts/font3.png" alt="Java2D Arial 13pt on Java 6 / WinXP w/ sub-pixel AA turned on">
				</p>
				How do you like them apples? In my experience, Java2D glyphs look really nice
				with the new sub-pixel anti-aliasing, and it makes Swing look really
				competitive with Windows XP font rendering with ClearType, as you can see:
				<p>
					<img src="http://www.galbraiths.org/fonts/font4.png" alt="Windows versus Java2D"/>
				</p>
				In the image above, Windows is on the top and Java2D is on the bottom. I
				prefer the weightier Windows rendering, but the Java2D rendering is nice.
			</li>
			<li>Java2D needs higher-quality font rendering techniques, such as
				better glyph layout. Admittedly, this is a bit of a catch-all, but features
				like ligatures and properly spaced characters make a big difference in
				the quality of type. Unfortunately, I can't see that this has gotten much better.
			</li>
		</ol>
		<p>
			<b>A Problem of Spacing</b>
		</p>
		<p>
			To get a feel for the problem of spacing, check out how both OS X and Java2D
			(Java 1.6, Windows XP) rendering the same text with Lucida Grande Bold (11 points,
			Java2D text attributes set to PLAIN):
		</p>
		<p>
			<img src="http://www.galbraiths.org/fonts/font5sp.png" alt="Java2D versus OS X with Lucida Grande Bold at 11pts"/>
		</p>
		<p>
			It's pretty amazing how gorgeous OS X's rendering of the text is; it's as though
			a magazine climbed into my LCD. The Java rendering looks pretty rough, due to both
			the glyph quality and their spacing. 
			Check out the difference in character spacing in the word "quick"
			versus the word "brown" or how the "ps" in "jumps" is floating a bit too far to
			the right; also, note how Java renders the 'e', 'q', and 'w' compared to the Mac.
			It's pretty hard to argue that one could prefer the Java rendering, though the
			increased intensity of the pure white hue is a potential benefit. 
		</p>
		<p>
			<b>Am I Crazy?</b>
		</p>
		<p>
			I know there are a large swath of folks who are just happy if they can get their
			app to <i>do</i> something and view my rambling on about fonts as silliness. I have
			no problem with such.
		</p>
		<p>
			My point here is that when you want to create <i>gorgeous</i> applications, these
			things really do matter, and they matter quite a bit. If you disagree with this
			assertion, well, we'll just have to disagree. (I'm reminded of a recent Wall
			Street Journal column by Lee Gomes in which he said audiophiles are divided into
			two camps: the crazy and the totally insane.)
		</p>
		<p>
			<b>What To Do?</b>
		</p>
		<p>
			I've had the opportunity to meet Phil Race, the font guru on the Java2D team,
			and I'm satisfied that he's smarter than I'll ever be, that he knows about these
			problems, and that he'd fix them if Sun's priorities and resources 
			permitted such to happen. And who knows but that such fixes are already in the
			pipeline? (Well, I guess Phil knows.)
		</p>
		<p>
			That doesn't relate to my problem: I've got an app that I need to make gorgeous
			<i>today</i>. So, what do I do? I don't have time to render fonts myself. That's
			Hard Stuff. But, I could lay out the individual glyphs myself and do a better job
			than the Sun folks. But, having met Phil, I assume if that problem were non-trivial,
			he'd have improved it himself by now. However, by only caring how fonts look in 			
			<i>my</i>
			applications, as opposed to the entire world's set of Swing apps, perhaps I can
			get some results in this area.
		</p>
		<p>
			<b>Finding the Best Fonts for Java2D</b>
		<p>
			In a past life, I did lay out glyphs myself, but that code no longer belongs to
			me, and I'm not in the mood to write it again. So the easiest solution is simply
			to check how Java2D renders fonts at different
			sizes and see which ones look best. I created a simple program and rendered some
			test output for Java2D using sub-pixel anti-aliasing (HRGB) with all of the fonts
			available to the JRE in a default Windows XP installation (along with Lucida Grande
			Bold), split into <a href="http://www.galbraiths.org/fonts/fontssp1.png">three</a> 
			<a href="http://www.galbraiths.org/fonts/fontssp2.png"/>large</a> 
			<a href="http://www.galbraiths.org/fonts/fontssp3.png">images</a>.
		</p>
		<p>
			My favorites are:
		</p>
		<ul>
			<li>Arial 11pt Plain (12 and 13 ain't bad either):
				<p>
					<img src="http://www.galbraiths.org/fonts/arial.png"/>
				</p>
			</li>
			<li>Franklin Gothic Medium 9pt Plain--what an attractive small typeface! 10 and 11
				are pretty good as well:
				<p>
					<img src="http://www.galbraiths.org/fonts/franklin.png"/>
				</p>
			</li>
			<li>Georgia 9pt Plain, a seriffed answer to Franklin Gothic's clarity (10-13 are
				also really nice):
				<p>
					<img src="http://www.galbraiths.org/fonts/georgia.png"/>
				</p>
			</li>
			<li>Lucida Sans Regular 12pt Plain (11 is also nice):
				<p>
					<img src="http://www.galbraiths.org/fonts/lucida.png"/>
				</p>
			</li>
			<li>Microsoft Sans Serif 12pt Plain
				<p>
					<img src="http://www.galbraiths.org/fonts/microsoft.png"/>
				</p>
			</li>
			<li>Segoe UI 11pt Plain
				<p>
					<img src="http://www.galbraiths.org/fonts/segoe.png"/>
				</p>
			</li>
			<li>Verdana 9pt and 11pt Plain
				<p>
					<img src="http://www.galbraiths.org/fonts/verdana.png"/>
				</p>
			</li>
		</ul>
		<p>
			<b>Your Favorites?</b>
		</p>
		<p>
			I was surprised at just how good some of these fonts look. Thanks Phil!
			Did I miss some other good ones? Are there other fonts that you've used with good 
			results	in Java2D? What are your "go to" fonts for beautiful type at large sizes?
		</p>
<p>
<b>Update:</b> Whoops. I put together this blog entry in a bit of a hurry whilst flying from Point A to Point B and I included some faulty images (due to a bug I introduced in the program I wrote to display the fonts; the last 2/3 of the fonts weren't sub-pixel AA'd):
</p>
<ol>
<li>The comparison between Lucida Grande Bold Java2D vs. OS X originally showed the Java2D rendering <a href="http://www.galbraiths.org/fonts/font5.png">without sub-pixel AA</a>; this was a mistake. I updated it with a sub-pixel AA version, as shown above. Note that the observations about subpar glyph formations and layout still remain valid (as I originally noticed them with properly sub-pixel anti-aliases imagery).</li>
<li>Two of the three large images I linked to were not sub-pixel anti-aliases as claimed. This has been fixed.</li>
<li>Six of the seven fonts displayed at the end of the blog entry were not sub-pixel anti-aliased; this has been fixed.</li>
</ol>
<p>
The observations that drove me to write this blog entry were with properly sub-pixel anti-aliased type; so the content stands. Sorry for the goof-up.
</p>]]>

</content>
</entry>
<entry>
<title>Java on Leopard: The New Rendering Pipeline</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/10/java_on_leopard.html" />
<modified>2007-11-05T14:18:05Z</modified>
<issued>2007-10-31T17:44:46Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.8533</id>
<created>2007-10-31T17:44:46Z</created>
<summary type="text/plain">Why you should accept that the new pipeline is a Good Thing and move on.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>
In my <a href="http://weblogs.java.net/blog/javaben/archive/2007/10/the_java_on_os.html">recent</a> <a href="http://weblogs.java.net/blog/javaben/archive/2007/10/more_on_leopard.html">duo</a> of "Whiners! No whining!" blog posts, I made a statement with which some commenters have taken issue:
</p>
<blockquote>
the already-mentioned transition to Sun's rendering pipeline (a tough but correct decision reflecting a commitment to cross-platform fidelity)
</blockquote>
<p>
Specifically, Michael Urban wrote in to say:
</p>
<blockquote>
I really don't see how this has anything to do with cross-platform fidelity. After all, Sun JVMs don't even use the Sun pipeline by default anymore. They use the OpenGL pipeline where / when it is available. I think all Apple really did by switching to the Sun pipeline is make Java2D performance unusably slow, and create tons of support headaches for developers who now have to field all the complaints from their customers about why their application no long works correctly on Leopard, and either explain to the customer who to enable the Quartz pipeline, or ship a patch for their application to re-enable the Quartz pipeline.
</blockquote>
<p>
Michael, as you'll see below, Sun's OpenGL renderer is indeed part of the pipeline Apple is now using. And unless I'm really out of date, I think the traditional GDI platform is still used on the majority of Windows JRE installs.
</p>
<p>
And "opinali" opined:
</p>
<blockquote>
but what you said about the transition to the Sun rendering pipeline being an improvement, that was pure spin that I'd only parse as radical Mac zealotry. There is NO justification for this (except Apple having no resources / time / priority to update the accelerated pipeline for the new OS). It's the opposite direction that everybody else is moving; see for example Java 6 UpdateN, which will move to the new D3D-accelerated pipeline by default on Windows. The Java platform must keep up with the LAF improvements of the latest OSs, like Vista and OSX, which are severely raising the bar in sfx (remarkably with WPF, Quartz, Beryl etc) so the Java toolkits (AWT/Swing/J2D) can't reasonably compete without full acceleration. And also, Java must support the development of "filthy rich" clients, not that I like this trend, but many users do so developers should be able to crank out sophisticated J2D effects that don't bring Java's performance to its knees. These requirements are MUCH more important than "pixel-by-pixel portability" (and for this, there's always the option of the portable Java LAF).
</blockquote>
<p>
Well, look. Dissent on this topic is perfectly reasonable; there are trade-offs at work. But, I'm confident that in the final analysis, most folks will agree this was the right decision.
</p>
<p>
Let's start with precedent. Initially, Sun relied on the underlying platforms to perform font rendering, but in Java 1.2 a new Java2D-based pipeline was introduced. This pipeline has represented a substantial engineering investment, especially as Adobe font support and subpixel anti-aliasing have come into the picture. Why not just use the underlying platform's font renderer?
</p>
<p>
The answer, of course, is that it would be nearly impossible to write cross-platform applications that do any detailed layout or typography work without Java itself handling the rendering. Sun abandoned the technically superior rendering approach in most situations in the name of compatibility.
</p>
<p>
Now, with Quartz, we see shades of the same issue. Quartz is great, Quartz makes certain drawing operations wicked fast in Java, but Quartz is much different than Sun's pipeline. The canonical example of just how different is the fact that aliased lines require Apple's adapter to draw an anti-aliased line (the *only* kind of line in Quartz) and then mask out the aliased pixels. Try some benchmarks to see just how slow this is.
</p>
<p>
Anyone who has written a rendering-heavy app has run into the pain that these differences cause. Any time the cross platform abstraction breaks and you need to adapt for the underlying platform, Java loses (or, phrased less dramatically, the value proposition of Java leaks in direct proportion to how often its abstractions leak).
</p>
<p>
Now that Sun has produced an OpenGL pipeline and is committed to making it work, why wouldn't Apple drop their own Java bridge to a Cocoa bridge to OpenGL in favor of Sun's OpenGL pipeline? Sun now pays the tax to make OpenGL behave the same as their traditional GDI (and Linux and Solaris equivalent) pipelines.
</p>
<p>
Thus, the Apple team no longer duplicates work that Sun is doing and they can spend more time on other features (like porting the new applet architecture to OS X, for example).
</p>
<p>
There are really only two sets of potential losers here: those who use Java to develop for OS X and don't care about other platforms, and those who need a fully tested and optimized Sun rendering pipeline today.</p>
<p>
For the former, I'm convinced it's not a big deal. If you really want to take advantage of OS X goodies, learn Ruby and use the Ruby/Cocoa bridge. If you're content to just look like a native OS X app and don't need really fancy effects, the new Aqua look-and-feel is quite nice and I'm hopeful it will evolve favorably over time.
</p>
<p>
For the latter group--that need it today--I think you're confusing needs and wants. Use Quartz today and switch to the Sun pipeline when you're ready. In my own testing, it works quite well for most needs.
</p>
<p>
Am I wrong? Was this move a blunder? I'm curious to hear other points of view.
</p>
<p>
UPDATE: amasson pointed out that the Quartz stack includes a non-retained mode drawing API. I excised the relevant paragraph. See comments below for details. Thanks amasson!
</p>]]>

</content>
</entry>
<entry>
<title>More on Leopard&apos;s Java 1.5: The Release Notes Michael Urban Should Have Read</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/10/more_on_leopard.html" />
<modified>2007-10-31T17:52:03Z</modified>
<issued>2007-10-31T12:24:34Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.8528</id>
<created>2007-10-31T12:24:34Z</created>
<summary type="text/plain">A journey through OS X 10.5 Leopard&apos;s release notes shows some pretty interesting tidbits.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>I <a href="http://weblogs.java.net/blog/javaben/archive/2007/10/the_java_on_os.html">recently blogged about the recent Mac whining</a> from the Java community. Subsequently, I browsed through <a href="http://developer.apple.com/releasenotes/Java/JavaLeopardRN/index.html">OS X 10.5 Leopard's Java release notes</a>. Wow!</p>

<p>I think most people have by now realized that <a href="http://www.javalobby.org/java/forums/t102936.html">Michael Urban's straw-that-broke-the-camel's-back example</a> of how Apple has regressed Java 5 is actually a step forward (i.e., the Aqua look-and-feel uses the *right* icon in message boxes now), but it gets much better.</p>

<p>Some of my favorites include:</p>

<ul>
<li>"It is now possible to create a circular indeterminate progress indicator from a JProgressBar in Swing. Setting the "JProgressBar.style" client property to "circular" will create a small round indicator when the progress bar has been setIndeterminate(true). Please see tech note TN2196 "New Control Styles available within J2SE 5.0 on Mac OS X 10.5" for more information."</li>

<p><li>"Horizontal scroll events are now delivered to JScrollPanes as Shift+ScrollWheel events, since there is no horizontal scrolling API in Java. Horizontal scrolling mouse events will now move the content view horizontally, along with Shift key modifier events."</li></p>

<p><li>"There has been no way to specify smaller versions of the default Mac OS X Aqua controls. Many JComponents now change their default size, appearance, and font when the "JComponent.sizeVariant" client property is set to "small" or "mini". Please see the tech note "New Control Styles available within J2SE 5.0 on Mac OS X 10.5" for more information."</li></p>

<p><li>"JTextFields can now be converted into search files using the "TextField.variant" client property set to "search". Please see the tech note "New Control Styles available within J2SE 5.0 on Mac OS X 10.5" for more information and additional options to configure JTextField based search fields."</li></p>

<p><li>Apple introduced a 64-bit JVM with Leopard along-side the 32-bit JVM.</li></p>

</ul>

<p>And, as anyone who has spent any time playing with the JRE will have noticed, the release notes omit many smaller features related to polish in their ground-up rewrite of the Aqua look-and-feel.</p>

<p>There will always be the whiners about Java 1.next; Apple is Apple. As the snake says in the <a href="http://www.indigenouspeople.net/snake.htm">proverbial parable</a>, "you knew what [Apple] was when you [bought your MacBook Pro]." Whine about this to someone who cares.</p>

<p>But those who complain that Apple has lessened their support for Java at a time when Apple has done more to make Java a first-class peer of Cocoa and other dev environments--you could not be more misinformed.</p>

<p>UPDATE: I posted follow-up comments on the new rendering pipeline in a <a href="http://weblogs.java.net/blog/javaben/archive/2007/10/java_on_leopard.html">new blog entry</a>.</p>]]>

</content>
</entry>
<entry>
<title>The (Java on OS X) Sky is Falling!</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/10/the_java_on_os.html" />
<modified>2007-10-31T12:27:33Z</modified>
<issued>2007-10-31T01:32:21Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.8526</id>
<created>2007-10-31T01:32:21Z</created>
<summary type="text/plain">With a tip of the hat to Casablanca, I&apos;m shocked--SHOCKED--to read the really rather embarrassing blog entries from folks in the community about the state of Java in Apple&apos;s latest OS release.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>With a tip of the hat to Casablanca, I'm shocked--SHOCKED--to read the really rather embarrassing blog entries from folks in the community about the state of Java in Apple's latest OS release (see <a href="http://weblogs.java.net/blog/robogeek/archive/2007/10/the_ifs_and_whe.html">David Herron</a>'s blog for a round up of some).</p>

<p>Please.</p>

<p>It turns out that Swing in Leopard represents a <em>huge leap forward</em> in Apple's commitment to desktop Java. Among the new goodies I've stumbled across are animated triangles in JTrees, the already-mentioned transition to Sun's rendering pipeline (a tough but correct decision reflecting a commitment to cross-platform fidelity), a revised UI for JTabbedPane, improved button rendering behavior, and more.</p>

<p>I suspect as time passes, more improvements will come out and folks will understand just how busy the Apple Java team has been.</p>

<p>So, what, there are some bugs in OS X 10.5.0? They didn't have 1.6 ready out-of-the-chutes? Big deal. Give it time, just like we have with every release of Java since OS X first shipped with Java 1.3. Only now, thanks to Parallels/Fusion, we actually have a great alternative for the impatient.</p>

<p>Kudos, Apple, for a fine release and for all your hard work.</p>

<p>UPDATE: I've <a href="http://weblogs.java.net/blog/javaben/archive/2007/10/more_on_leopard.html">elaborated a bit</a> after reading the release notes.</p>]]>

</content>
</entry>
<entry>
<title>Desktop Matters Blogging</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/03/desktop_matters_2.html" />
<modified>2007-03-09T19:55:53Z</modified>
<issued>2007-03-09T19:55:45Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.6776</id>
<created>2007-03-09T19:55:45Z</created>
<summary type="text/plain">Catch some of the news from Desktop Matters</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>I'm blogging about <a href="http://www.desktopmatters.com">Desktop Matters</a> over at my <a href="http://www.galbraiths.org/blog/">personal blog</a>. Some of the interesting news so far is that JIDE is open-sourcing 1/3 of their code, <a href="http://galbraiths.org/blog/?p=77">a new cross-platform look-and-feel designed by Sun called Nimbus</a>, and more...</p>]]>

</content>
</entry>
<entry>
<title>Open Party During Desktop Matters</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/03/open_party_duri.html" />
<modified>2007-03-08T04:48:01Z</modified>
<issued>2007-03-07T20:58:49Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.6761</id>
<created>2007-03-07T20:58:49Z</created>
<summary type="text/plain">If you can&apos;t make it to the Desktop Matters conference this week, consider joining us for the party.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>Hard to believe that <a href="http://www.desktopmatters.com">Desktop Matters</a> is finally upon us. I'm very much looking forward to hearing <a href="http://www.desktopmatters.com/agenda.html">all the talks</a> and being with some folks from the Java Desktop community at the show.</p>

<p>Recognizing that not everyone who might wish to attend the conference is able to come, we've decided to open up the party Thursday night to everyone who wants to come. We also <a href="http://ajaxian.com/archives/ajaxian-party-this-thursday-in-san-jose">posted an invite on Ajaxian.com</a>, so perhaps quite a crowd of folks will come (then again, perhaps not).</p>

<p>So if you're in the neighborhood, why not drop in and say hello? There will be food and drinks, but not sure how long they'll last.</p>

<p>Party starts at 8:00 pm, located at the <a href="http://www.wyndham.com/hotels/SJCAP/main.wnt">Wyndham San Jose</a> (map <a href="http://maps.google.com/?q=1350+N+1st+St,+San+Jose,+CA+95112&sll=37.0625,-95.677068&sspn=48.688845,75.761719&ie=UTF8&z=16&om=1&iwloc=addr">here</a>). The room is Salon H (at the mezzanine level).</p>]]>

</content>
</entry>
<entry>
<title>Dramatically Faster JavaScript in Firefox</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/02/dramatically_fa.html" />
<modified>2007-02-07T18:56:56Z</modified>
<issued>2007-02-07T18:56:48Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.6501</id>
<created>2007-02-07T18:56:48Z</created>
<summary type="text/plain">I just posted a podcast exploring when Firefox will see dramatically increased JavaScript speeds thanks to the Tamarin project.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>When Adobe donated their JIT-compiling JavaScript VM to the Mozilla Foundation in Nov. '06, it had some pretty huge implications. The VM boosted Flash's own JavaScript execution speed by 10x -- seeing those kinds of improvements in Firefox could enable a whole new class of "thicker" web applications. So, when will we see it? And, why did Adobe donate the code?</p>
<p>Over at <a href="http://www.ajaxian.com">Ajaxian</a>, I just posted a <a href="http://ajaxian.com/archives/audible-ajax-episode-20-project-tamarin">~30 minute podcast</a> exploring this issue, featuring interviews with Brendan Eich (CTO, Mozilla), Kevin Lynch (Chief Software Architect, Adobe), Alex Russell (Dojo Lead), and many others. I had a lot of fun recording the interviews and editing this together, but I probably spent a little too much time doing it. ;-)</p>
<p>I'm interested in knowing if folks enjoy this kind of "feature" podcasts that involve more of a narrative than traditional monologue or interview podcasts. They take a lot of time to produce, but I kind of like having the information dense and relevant to a particular subject...</p>

<p>(cross-posted on <a href="http://www.galbraiths.org/blog">Married... with Children</a>)</p>]]>

</content>
</entry>
<entry>
<title>I Love Intelligent Tools...</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2007/01/i_love_intellig.html" />
<modified>2007-01-18T07:54:06Z</modified>
<issued>2007-01-18T07:54:01Z</issued>
<id>tag:weblogs.java.net,2007:/blog/javaben/112.6351</id>
<created>2007-01-18T07:54:01Z</created>
<summary type="text/plain">After years of use, IntelliJ IDEA still makes me smile.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>I’m writing some Java2D code, and I notice that IDEA (my code editor) highlighted parts of my code:</p>

<p><img src="http://galbraiths.org/blog/wp-content/uploads/2007/01/idea.png" alt="IDEA highlighting my awful code" /></p>

<p>Check out the caption at the bottom of the window. It turns out (as any good Java2D programmer knows) I’m reversing the width and height arguments — but how did IDEA know? Whether its lexical analysis or a special case built into the tool, wow! This kind of stuff is infinitely useful.</p>

<p>(cross-posted on <a href="http://www.galbraiths.org/blog">Married... with Children</a>, my personal blog)</p>]]>

</content>
</entry>
<entry>
<title>Desktop Matters Agenda Updated</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/12/desktop_matters_1.html" />
<modified>2006-12-18T19:18:01Z</modified>
<issued>2006-12-18T19:17:53Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.6176</id>
<created>2006-12-18T19:17:53Z</created>
<summary type="text/plain">Check out desktopmatters.com; we&apos;ve updated the agenda.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>Continuing my series of updates on <a href="http://www.desktopmatters.com">Desktop Matters</a>, I'm happy to say we've given <a href="http://www.desktopmatters.com/agenda.html">the agenda</a> much more shape since my last posting. The show continues to be one track, but we've expanded out a touch to one and a half days.</p>

<p>Check it out and let me know what you think!</p>]]>

</content>
</entry>
<entry>
<title>Desktop Matters Open for Registration</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/12/desktop_matters.html" />
<modified>2006-12-01T21:33:23Z</modified>
<issued>2006-12-01T21:32:38Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.6072</id>
<created>2006-12-01T21:32:38Z</created>
<summary type="text/plain">Desktop Matters is March 8-9 in San Jose, California; check out www.desktopmatters.com</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>We've got the final dates locked in for Desktop Matters: March 8-9 in at the <a href="http://maps.google.com/maps?f=q&hl=en&q=1350+N+1st+St,+San+Jose,+CA+95112&ie=UTF8&z=13&ll=37.36088,-121.92009&spn=0.088414,0.180073&om=1">Wyndham in San Jose, California</a>. The <a href="http://www.desktopmatters.com">conference website is live</a>, as is the registration link.</p>

<p>A big "Thank You" to all of you who offered to present at the show; we'll be finalizing the agenda in the coming weeks and getting in touch with you.</p>

<p>Desktop Matters is still technically a one-day show, but we're also putting on a "pre-show" event in the hotel where, among other things, you can bring your Swing questions and apps in person and discuss your ideas / problems / etc. with some of the speakers and Swing experts at the show.</p>

<p>We're also really struggling with a possible decision to go to two tracks; we've got a lot of content and one day isn't a very long time... anyone with opinions on the issue, please comment here.</p>

<p>Thanks!</p>]]>

</content>
</entry>
<entry>
<title>The Desktop Matters</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/11/the_desktop_mat.html" />
<modified>2006-11-06T17:46:22Z</modified>
<issued>2006-11-06T17:07:37Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.5877</id>
<created>2006-11-06T17:07:37Z</created>
<summary type="text/plain">I&apos;m happy to announce Desktop Matters, a desktop-focused conference to take place in February 2007 in the Bay Area, California</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>With the advent of Ajax, it's been fun to watch the Web in a renaissance as technologies we dismissed years ago have come into vogue. There's such buzz in that space that some are beginning to predict that web applications will replace  desktop apps entirely and that perhaps even a "Web OS" concept will take root.</p>

<p>Maybe the future is in Web browsers. But I'm pretty satisfied that for years to come, desktop applications will continue to play an important role in the software ecosystem. In short, the desktop matters.</p>

<p>In this vein, we're happy to announce <strong>Desktop Matters</strong>, a desktop-focused conference to take place in February 2007 in the Bay Area, California (probably Feb. 23 somewhere close to Santa Clara). My <a href="http://www.ajaxian.com">Ajaxian</a> partner-in-crime, <a href="http://www.almaer.com/blog/">Dion Almaer</a>, will be co-producing and co-hosting the event with me, and Jay Zimmerman of the <a href="http://www.nofluffjuststuff.com/">No Fluff Just Stuff</a> conference series will handling the heavy-lifting and lending his conference expertise to the event.</p>

<p>We had considered making an event for all desktop technologies across all platforms. That vision may eventually come to pass, but this first Desktop Matters event will be focused on Java Desktop technologies.</p>

<p>While our recent <a href="http://www.theajaxexperience.com">Ajax Experience</a> conference had sixty sessions across six tracks over three days, the Desktop Matters will be a one day / one track event. It's not that we couldn't find enough content to fill up a bunch more slots, but we felt that the Java Desktop community is a pretty tight-knit crowd and it would be more fun to throw everyone in the same room.</p>

<p>Sun's Swing team has graciously offered to participate; Scott, Hans, Chet, Richard, and former-intern-extraordinaire Romain Guy will be there presenting.</p>

<p>The attendance fee will is still being worked out, but it will obviously be far lower than the typical $1,500 range for multi-day, multi-track events. We're trying to make it as accessible as possible.</p>

<p>The agenda is still being finalized, but it will include topics such as how to be more productive with Swing, how to make Swing look amazing, and sessions on third-party Swing libraries and tools. We may even have some non-Java folks present, just to show us how things are done on other platforms -- but that part of the show isn't finalized yet and may not happen. The show will wrap up with a party / networking event, while Chet doing stand-up comedy at some point (he doesn't know this yet, but we're confident after a few drinks we'll get him on stage).</p>

<p>Speaking of the agenda, would you like to present a session at the show? What with it only being one day, presentation space is very limited, but if you have an interested in presenting or simply being a part of the show in some way, please let me know (send email to desktopmatters@galbraiths.org).</p>

<p>I'll follow up with a commitment on the date, the venue, and the price a little later this week or earlier next. In the meantime, I hope you'll clear a space on your calendar and join us!</p>]]>

</content>
</entry>
<entry>
<title>Heaps of Memory</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/10/heaps_of_memory.html" />
<modified>2006-10-21T16:59:23Z</modified>
<issued>2006-10-21T16:59:16Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.5772</id>
<created>2006-10-21T16:59:16Z</created>
<summary type="text/plain">Is there a way to determine the largest set of strongly referenced heap data a process creates at any one time?</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Performance</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>While profiling a Java EE web app, I found myself wondering how much memory a process required. I attached a low-instrusion profiler to the JVM and watched a pattern repeat itself several times: the heap grew by ~15 MB, got collected, grew again by ~15 MB, got collected, etc.</p>

<p>My first reaction was to conclude that the process required 15 MB of heap in order to complete. But of course, that's an erroneous conclusion. With different settings or constraints, perhaps the process would have added only 7 MB of garbage before the collector cleaned the heap.</p>

<p>What I really need to know is the size of the largest set of strongly referenced object data placed on the heap as a result of the process at any one time. Because I can reasonably isolate the process, I'd settle for a definite measurement of the strongly referenced objects on the heap at any one time.</p>

<p>So how do I figure this out? I've used a number of tools that show me the size of the heap over time. Some let me take a snapshot of the heap and remove all weakly-referenced data. But I have yet to find a tool that will, over a period of time, tell me what the largest amount of the uncollectable heap data is (in bytes).</p>

<p>Anyone know of tool or process to figure this out? I know I could reduce the heap size until the process throws an OutOfMemoryException. I'm looking for something a little more automated.</p>]]>

</content>
</entry>
<entry>
<title>Ajax and Desktop Conferences</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/09/ajax_and_deskto.html" />
<modified>2006-09-26T00:04:13Z</modified>
<issued>2006-09-26T00:00:50Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.5626</id>
<created>2006-09-26T00:00:50Z</created>
<summary type="text/plain">Dion Almaer and I were given the opportunity to deliver a talk on Ajax at JavaOne earlier this year. Many of you told us was that you wished we went into greater depth. I&apos;m happy to say that the Ajax firehouse is wide open: Dion and I are hosting a conference in Boston next month. Also, I&apos;m soliciting some feedback for a Desktop Developer&apos;s Conference (again).</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>JavaOne</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p><a href="http://www.theajaxexperience.com/"><img src="http://www.ajaxian.com/wp-content/images/taeboston.jpg" border="0"/></a></p>

<p><a href="http://www.almaer.com/blog/">Dion Almaer</a> and I were given the opportunity to deliver a talk on Ajax at <a href="http://java.sun.com/javaone/sf/index.jsp">JavaOne earlier this year</a>. The session went pretty well, and I found myself giving a repeat on the last day of JavaOne that also went pretty well. Many thanks to those of you that attended and especially to those of you that gave us feedback both in person after the talks or via the eval forms.</p>

<p>One of the things a lot of you told us was that you wished we went into greater depth in some area of Ajax. Indeed, in a 60 minute session, we had to leave a lot unsaid.</p>

<p>I'm happy to say that for those of you that were left a little wanting, the Ajax firehouse is wide open: Dion and I are hosting a conference in Boston next month (<a href="http://www.theajaxexperience.com/">www.theajaxexperience.com</a>) where <em>sixty</em> 90-minute sessions will be delivered over the course of three days. We've got a ton of Java-specific content, including the lead of Google's Java-based GWT framework, the lead of the excellent DWR framework, and one of the core Spring developers.</p>

<p><b>Desktop Conference</b></p>

<p>A while back, <a href="http://weblogs.java.net/blog/javaben/archive/2006/04/a_desktop_appli.html">I solicited feedback here on the possibility of giving a Desktop Developer's Conference</a>. I'm happy to say that I'm moving forward with this concept. At first, I was going to make it a Java, .NET, and Cocoa/ObjC affair, but as I evaluated the marketplace, I decided to give it a Java focus. I've seen a few .NET conferences start and then abruptly stop, and I've seen no precedent for a Cocoa conference, so I got cold feet building out a lot of content for those technologies.</p>

<p>But, I still am planning on having Microsoft show up and talk to us about both WinForms and Windows Presentation Foundation (WPF). And, I'm still planning on having Apple show up to talk about Cocoa. Nothing like seeing how the other half (1/3?) lives.</p>

<p>I would like some more feedback on a few things:</p>

<p>1. How much (if any) SWT/Eclipse content should there be? Anyone have any strong feelings one way or the other? It's hard for me to get a good read on this -- not a lot of hard data and my own experience suggests that SWT/JFace/EclipseRCP usage is a small fraction of Swing, but I could be off-base here.</p>

<p>2. Should this be a multi-track event or a one-track event? If multi-track, should it be a large track event like The Ajax Experience with six tracks, should it be mini-track with 2-3, or mega-track like JavaOne with 10 tracks+ (like I could <em>find</em> that much desktop content)?</p>

<p>Thanks,</p>

<p>Ben</p>]]>

</content>
</entry>
<entry>
<title>Curse You, Duke!</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/08/curse_you_duke.html" />
<modified>2006-08-30T15:24:05Z</modified>
<issued>2006-08-30T14:44:28Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.5456</id>
<created>2006-08-30T14:44:28Z</created>
<summary type="text/plain">Why can&apos;t Java have a recognizable noun as a mascot? Ever since JavaOne 2006, I&apos;ve had to deal with all kinds of questions about Duke...</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>JavaOne</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p><img src='http://www.galbraiths.org/blog/wp-content/duke_shirt.png' alt='JavaOne \&#039;06 Duke Shirt' /></p>

<p>One of the things I enjoy about fatherhood is being, for however brief a period, somewhat of an authority on life. Well, thanks to Duke, the appearance of parental infallibility has come to an early end.</p>

<p>Ever since JavaOne 2006 (where I got this nice green shirt), I've had to deal with all kinds of questions from my four and two year old daughters:</p>

<p>Girls: "Daddy, what's that on your shirt?"</p>

<p>Me: "Err, that's Duke."</p>

<p>Girls: "What is he?"</p>

<p>Me: "Hmm."</p>

<p>Girls: "Is he a bird? I think he's a bird."</p>

<p>Me: "No, he's not a bird. He's, uh, a cartoon character."</p>

<p>Girls: "He looks like a bird."</p>

<p>Me: "No, he's a cartoon mascot for Java."</p>

<p>And now, every time I wear it, I have to deal with a variant of this conversation. Like this morning:</p>

<p>Girls: "Is that Duke? What is he?"</p>

<p>And so forth. I'm just waiting for one of them to say, "Well, what exactly do you know, daddy?" and to hear them whispering amongst themselves: "Don't bother asking daddy that, he doesn't even know what Duke is."</p>

<p>Why can't Java have a recognizable noun as a mascot? Like a bird? Or even a horse? Here's for Mustang shirts at next JavaOne. Actually, too bad we can't go back and have Merlin shirts made. That could have been really cool...</p>]]>

</content>
</entry>
<entry>
<title>JavaBeans, Binding, and AOP</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/javaben/archive/2006/06/javabeans_bindi.html" />
<modified>2006-06-01T18:28:16Z</modified>
<issued>2006-06-01T17:19:47Z</issued>
<id>tag:weblogs.java.net,2006:/blog/javaben/112.4944</id>
<created>2006-06-01T17:19:47Z</created>
<summary type="text/plain">My friend Richard Bair recently reminded us what JavaBeans are; I&apos;d like to pick up where his discussion left off, touching on binding and AOP on the way.</summary>
<author>
<name>javaben</name>

<email>ben@galbraiths.org</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/javaben/">
<![CDATA[<p>My friend <a href="http://weblogs.java.net/blog/rbair/">Richard Bair</a> <a href="http://weblogs.java.net/blog/rbair/archive/2006/05/the_unknown_jav.html">recently told the world that the colloquial definition of JavaBeans as an object with getters and setters is incomplete</a>, and demonstrated how a handy base class can make adding <code>PropertyChangeListener</code> support easier.</p>

<p>I'd like to pick up where his discussion left off. Over the past few years, I've been pondering how to make it easier to develop Swing applications. One area of pain in Swing is binding; that is, copying values from Swing widgets to business objects and vice-versa.</p>

<p>Swing components, as Richard mentioned, are observable via <code>PropertyChangeListener</code>s and other types of listeners, so detecting when widget values are changed and copying those values to objects as a result is pretty easy (though there are a few subtleties to get right). The reverse, however, is not free. In order to detect when values in an object have changed, one needs to use some mechanism like the JavaBean spec to introduce observability into JavaBeans.</p>

<p>And for me, therein lies the rub. Firstly, I hate repeating myself, and writing <code>firePropertyChange("property", old, new)</code> over and over again seems a big pain. Second, the string literal gives me the heeby-jeebies. If I'm going to all the bother of using a strongly-typed language, I hate having the bugs of loose-typing introduced with none of the benefit. Third, what if I'm using some pre-constructed business objects that aren't observable and can't easily be made to be observable?</p>

<p>(A quick tangent: Everyone ought to know that walking stacktraces is one of the most expensive VM operations around. Yet, just for fun, I created a version of <code>firePropertyChange(...)</code> that automatically obtains the property name by walking the stacktrace. Here it is:</p>

<p><code><pre>    protected void firePropertyChange(Object oldValue, Object newValue) {<br />
        try {<br />
            throw new Exception("stacktrace");<br />
        } catch (Exception e) {<br />
            StackTraceElement[] st = e.getStackTrace();<br />
            String property = ReflectionUtils.getPropertyFromAccessor(st[1].getMethodName());<br />
            firePropertyChange(property, oldValue, newValue);<br />
        }<br />
    }</pre></code></p>

<p>Never use this code in a tight loop.)</p>

<p>For all these reasons, the binding solution I use takes a hybrid approach. To save myself a lot of explanation, let me just say that when the Swing widget's value is changed, the framework can copy the value to the business object automatically, but the framework does not copy the value back to the Swing widget until the developer specifically requests that the value be copied from the business object back to the Swing widget.</p>

<p>In practice, it looks something like this:</p>

<p><code><pre>    binder.defineBinding(businessObject, swingWidget, "fieldName");<br />
    // at some future point, call this next line to update the UI from the object<br />
    binder.updateWidgets();</pre></code></p>

<p>I've used variations on this technique for a while now, and it works very well. When combined with a container-managed form system, it actually works nearly as well as true bi-directional binding as the form lifecycle can introduce automatic calls to <code>binder.updateWidgets()</code> at various flow points (and the automatic behavior can of course be disabled).</p>

<p>But I've been aware for a long time what the real solution to this problem is: Aspect-Oriented Programming (AOP). Using AOP, you can easily add <code>PropertyChangeListener</code> support to any object, even those for which you don't have source code, and generally solve all three of the problems I have with manually adding <code>PropertyChangeListener</code> support.</p>

<p>Unfortunately, I don't use an IDE that has AOP support, so I haven't been able to explore AOP much up to now. But the latest release of my favorite AOP framework, <a href="http://eclipse.org/aspectj">AspectJ 5</a>, enables a new type of AOP syntax based on Java 5 annotations (called <a href="http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj.html">@AspectJ</a>).</p>

<p>Using @AspectJ, I can create a simple class that handles all of this property firing for me:</p>

<p><code><pre>    @Aspect<br />
    public class JavaBeanObservabilityAspect {<br />
        @Around("execution(* *.set*(..))")<br />
        public void timeElapsed(ProceedingJoinPoint jp) throws Throwable {<br />
            if (jp.getTarget() instanceof JavaBean) {   // only fire listener if a JavaBean<br />
                JavaBean o = (JavaBean) jp.getTarget();<br />
                String property = ReflectionUtils.getPropertyFromAccessor(jp.getSignature().getName());<br />
                Object oldValue = ReflectionUtils.invokeAccessor(o, property));<br />
    <br />
                // proceed with the invocation of the method<br />
                jp.proceed();<br />
    <br />
                Object newValue = jp.getArgs()[0];<br />
                o.firePropertyChange(property, oldValue, newValue);<br />
            } else {<br />
                // if not a bean, just proceed with the invocation normally<br />
                jp.proceed();<br />
            }<br />
        }<br />
    }</pre></code></p>

<p>The above is a crude beginners example of how to automatically fire the event on all JavaBeans -- a more refined example would show you how to actually add <code>PropertyChangeListener</code> support dynamically to <em>any</em> object. The example I gave is also problematic in that if the setter already fired the event, it would be fired again by the aspect. And, I coded this version here in my blog, so if it doesn't compile, don't sue me. But... you get the idea.</p>

<p>The beauty of @AspectJ is that because it just uses normal Java 5 annotations, you can use your IDE to create and compile the aspects like any other part of your code base. To actually use the aspects at run-time, you must weave the aspect into your code.</p>

<p><em>Weaving</em> is the process of augmenting Java classes with the additional instructions defined by one or more aspects (such as the one above). You do that with a special compiler that comes with Ant tasks that can be easily introduced into your build process.</p>

<p>But for the impatient, there's this cool new thing in ApsectJ 5 called <a href="http://www.eclipse.org/aspectj/doc/released/devguide/ltw.html">load-time weaving</a> ("LTW"). With LTW, you pass your JVMTI compliant (Java 1.4+) VM a property that configures an agent that can weave your classes as they are loaded:</p>

<p><code><pre>    -javaagent:aspectj/aspectjweaver.jar</pre></code></p>

<p>You then create an XML file (<code>META-INF/aop.xml</code>) that specifies with aspects to weave, and into which classes, such as:</p>

<p><code><pre>    &lt;aspectj&gt;<br />
        &lt;aspects&gt;<br />
            &lt;aspect name="org.galbraiths.beans.JavaBeanObservabilityAspect"/&gt;<br />
        &lt;/aspects&gt;<br />
    <br />
        &lt;weaver options="-verbose -showWeaveInfo"&gt;<br />
            &lt;include within="org.galbraiths.beans.JavaBean"/&gt;<br />
        &lt;/weaver&gt;<br />
    &lt;/aspectj&gt;</pre></code></p>

<p>And presto! You've got AOP in your project (along with a handy speed hit whenever the affected classes are loaded for the first time). There are all kinds of fun things to do with AOP, such as introducing ultra-low-intrusion microprofiling, verifying proper Swing threading, and so forth. Blogs for other days.</p>

<p>So -- for the purposes of binding, you may not need observability in your objects, but if you do want it, consider AOP for adding observability without repeating yourself all over your codebase -- and for adding it to code you don't control.</p>

<p>If the pretty good AspectJ project documentation doesn't do it for you, check out <a href="http://www.manning.com/laddad/">AspectJ in Action</a>, written by <a href="http://ramnivas.com/">Ramnivas Laddad</a> -- a friend and collegue whom I greatly respect. His book doesn't cover @AspectJ, but is widely considered the best AspectJ book around.</p>

<p><i>As with most of my entries, this was cross-posted on my personal blog, <a href="http://www.galbraiths.org/blog/">Married... with Children</a></i></p>]]>

</content>
</entry>

</feed>