Sun Java Solaris Communities My SDN Account Join SDN

Meet the Engineer

Meet Josh Marinacci of the Swing Toolkit Team at Sun Microsystems

 
 
By Janice J. Heiss, August 2006  
Josh Marinacci Bio: I've been a Java platform programmer since 1995, when my favorite TA (teaching assistant) in college suggested I try it. I've spent the last 10 years writing Java technology-based user interfaces (UIs) for wireless, web, and desktop platforms. After tiring of web programming at a home improvement retail center, a wireless carrier, and a document-management company, I joined the Swing toolkit team at Sun to return to high-quality UIs. I recently co-authored O'Reilly's Swing Hacks: Tips and Tools for Killer GUIs with Chris Adamson. In addition, I work on the Flying Saucer open-source project and participate on many projects in SwingLabs. I received a B.S. in computer science from Georgia Tech in 1997 and moved to San Jose, California, about a year ago.
 

java.sun.com (JSC): What are some of your favorite tricks and "wow" effects with Swing?

Marinacci: My favorite hacks for Swing usually involve the Glass Pane component that sits on top of your application component. We liken it to a sheet of glass stretched across the top of your JFrames -- it's my favorite tool to build cool hacks. A great many of the hacks in my book were built using it.

Because the glass pane sits on top of the app, you can easily draw on top of your components without modifying any of the other code. For example, I recently built a magnifying glass that captures the pixels below it and then magnifies them, adding crosshairs and a movable handle.

Glass Pane Magnifying Glass
Glass Pane Magnifying Glass

The core of this hack is the paintComponent() method of the component I installed as the glass pane with frame.setGlassPane(myMagComponent). Here, let me show you:

 protected void paintComponent(Graphics gs) { Graphics2D g = 
(Graphics2D)gs; g = (Graphics2D)g.create(); 
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.BLACK);
        
        genGlass();
        g.setColor(Color.red);
        g.drawImage(lensImage,mx-70,my-70,null);
        
        // Regen the mag buffer.
        if(glass.intersects(g.getClipBounds())) {
            JFrame frame = (JFrame)this.getParent().getParent();
            Container content = frame.getContentPane();
            Graphics2D gfx = buff.createGraphics();
            gfx.translate(-mx-lrad-21, -my-lrad-21);
            content.paint(gfx);
            gfx.dispose();
        }
        
        drawBigGlass(g);
        drawSmallGlass(g);
    }
 

In that code, you'll see that I create a copy of the graphics2d, configure it appropriately, then call genGlass(), which builds the lens image -- the actual magnifying glass handle.

After drawing the lens to the screen, I generate the magnification of the underlying window by getting the contentPane of the frame, drawing the content components into a buffered image, then drawing the buffered image to the screen at two different resolutions using drawBigGlass() and drawSmallGlass(). I essentially trick the lower components into drawing into a buffer instead of to the screen. Once I have that buffer, I can manipulate it in any way I want, for instance, rotating or scaling the components, adding dropshadows, performing color changes, or even sending the image over the network to someone else.

When you can virtualize your components, you can combine them with the power of Java 2D to do pretty much anything.

JSC: Do you have a favorite Swing hack?

Marinacci: One of my favorites is one of the simplest. It's called "Put a NASA Photo Into the Background of a Text Area." It's not so much the visual effect that I like, since it's difficult to see what you are typing when it floats over an image. I like it because it combines two completely different entities, Swing text areas and a NASA web page, into something new and surprising. It's a "mashup" for the Swing world that leverages the strengths of Java technology: the hackable toolkit and good networking support. I think the future of desktop Java technology will be with programs like this -- programs that combine multiple libraries and services into new and unique applications.

Developers seem to enjoy reading zany graphical hacks, but they tend to use more practical hacks like antialiasing, customizing JLists, or more attractive blocking progress bars.

The Future of Desktop Java Technology

JSC: Tell us more about the future of desktop Java technology.

Marinacci: Some people want the future of desktop Java to lie in rebuilding existing Java apps. This was the vision in the late '90s. Today some think Java apps have failed on the desktop because they don't see lots of Java technology-based word processors, spreadsheets, or graphics apps. It was shortsighted of us to think that developers would rewrite all of their old apps to run in the Java programming language. Existing apps aren't written in Java software or Perl or Ruby or .NET or anything else new simply because they haven't been rewritten at all. Existing apps are still in C++ and always will be.

The future of desktop Java technology -- and the future of other new languages and runtimes -- is in new kinds of applications, often talking to web-based services. I'm thinking of something like iTunes, where a web service, the music store, is as much a part of the application as the local app itself.

In the future, all applications will be network-based. They just may not be browser-based. That is where new Java technologies like Java Web Start (JWS) software come in. With JWS, an application that is installed and updated from the network like a browser app can offer the richness of a local program.

So where do I see the future of desktop Java apps? The same place I see the future of desktop apps in general: creatively interacting with network-based resources and local devices. No longer will software be restricted to your personal computer. In the future, almost everything you do on your PC will involve participating with other people and services.

First Encounter With Java Platform Programming

JSC: Tell us about your first encounter with Java platform programming.

Marinacci: Wow. That's a long story. I had just finished my first two years of college in the summer of 1995 and was scheduled to take my first practical OO class in C++. I had taken Smalltalk the year before but couldn't build much with it. I asked my favorite teaching assistant, Ian Smith, who had taught me Lisp in an earlier course, if I should focus on C++ or C. He recommended that I learn the new Java language that he had heard about from friends at Sun.

I began playing around with it, enjoying the cleanness of the syntax and the incredibly rich standard libraries. It's hard to picture it now, but 11 years ago, C++ and many other popular languages didn't have standard Vector and String support, and always dropped down to low-level C APIs for things like File and Socket access. The Java language was such a breath of fresh air.

I took my first Java language class -- the first in the school -- in the spring of '96, and my first big program was a raytracer that ran as an applet -- the first of its kind, as I recall. I did my research project under a professor who was designing a constraint-based GUI toolkit for Java technology called subArctic. It was an amazing toolkit that let you virtualize everything.

Looking back, I now realize that subArctic was the inspiration for many of my later Swing hacks. After graduation, my subArctic knowledge got me an internship at Xerox PARC for nine months writing demos and test applications for the researchers. I was able to work on cool projects like threaded video conversations and scalable UIs. After leaving PARC, I switched to Swing and was on my way.

Beautiful Software

JSC: You wrote in your blog: "We are here to make software that works, that is easy to use, that is beautiful, and, most importantly, that makes life better for other people." What do you mean by software that is "beautiful"?

Marinacci: Beautiful software is software that perfectly fits its purpose. It's partly about its visual aesthetic, but it's more about the underlying design. A beautiful automobile is a car that has high performance, perfect airflow, good fuel efficiency, and a seat that fits its driver perfectly, as well as looking good on a billboard. iTunes is a beautiful piece of software because it lets users perform what used to be complex tasks with minimal effort. The UI is responsive and presents clear and unambiguous feedback. iTunes is probably less beautiful than it used to be because they've added extraneous features to it, but it's still a great example of beautiful software.

Ultimately, our job as software developers is to build software for people who aren't experts in computers. Just as it's the responsibility of an architect to design beautiful and reliable bridges for me to use, it's my responsibility to build beautiful and reliable software for other people to use.

Too often, we software developers sit in our box and write software that makes sense to us but to no one else. Usability and design should be high priorities in our software-development process -- as high as technical features, if not higher. After all, if a feature is too hard to use or understand, then why build it at all?

JSC: You moved 2500 miles to work at Sun, which you described as your "dream job." Why is working on Java platform applications a dream job?

Marinacci: As I've said to others: I don't love Java software because I work at Sun. I work at Sun because I love Java software.

Sun is the intellectual core of Java development, as well as one of the best places for any engineer to work. I love the Java language, so I came to the place where I could do the most good. Sun gives me great freedom to innovate and work with the greater Java community. It's also nice to have the clout that working at Sun brings. For better or worse, more people will listen to me when I talk about Java applications because of my job.

JSC: Can you describe the process of writing code?

Marinacci: For me, writing code is a lot like sculpting or painting. I begin with a sketch of what I want to make. Sometimes this is a feature list and sometimes a real physical sketch with paper and pencil. After laying out my ideas, I build a first version using rapid-development tools like Matisse in the NetBeans IDE, often stubbing in features like persistence or talking to the network.

Once I have the basic concept down, I methodically implement features and fix bugs, constantly going over the interface looking for flaws. After a while, I show it to someone to get feedback and then dive back into the code.

Iterative development is the key. Even when I'm fixing bugs in Java SE 6, where I'm not creating new software, I will iteratively arrive at a bug fix by first reproducing the bug, then coming up with a quick fix, and finally refining the fix to address backward- or forward-compatibility concerns.

Scripting Support in Java SE 6

JSC: What excites you about the scripting support in Java SE 6?

Marinacci: I'm really excited because it will let us use the Java Runtime Environment -- the JVM* and the libraries -- with non-Java languages. The Java language is great but not the perfect language for every solution. I'd like to be able to write components of my code in the Java language and then tie them together, when appropriate, with a scripting language such as JavaScript, Perl, or Ruby. I've heard that Java SE 7 will contain even more cool features for scripting support, possibly including a new JVM bytecode to make dynamic language execution even faster.

Flying Saucer

JSC: What do you contribute to the Flying Saucer open-source project?

Marinacci: Flying Saucer (FS) is an XHTML renderer for Java technology. You can think of it as the part of a web browser that actually parses and draws web pages to the screen. It only handles well-formed markup that strictly adheres to the specs -- XHTML 1.0 and CSS 2.1 -- so it will never be good for rendering general web pages, but it's terrific in cases where a developer controls both the client and the server.

Not coincidentally, I think rich clients talking to web services is the future of Java technology, so FS perfectly fits into that vision. I started and continue to contribute to FS because I believe in that vision. If you were going to make iTunes in Java apps, FS would be the perfect way to build the music store.

FS is great to use in producing reports and forms for PDFs and printing because CSS and HTML are a lot easier to work with than Java 2D or native PDF APIs. Plus, your graphic designers can build great CSS templates using their powerful design tools instead of having to write drawing code by hand. HTML and CSS are 21st-century tools that we need to use with Java technology.

JSC: Tell us about Aerith, the road-trip slide-show application you helped build that was demo'd at the 2006 JavaOne Conference.

Marinacci: Aerith is a trip-report builder that enables the user to build graphical slideshows of their photos. It combines Flickr, Google Maps, and Yahoo web services. Aerith represents the next generation of desktop Java applications. It's fast, has a good interface, and you can create unique Internet services with it.

Although there are web apps that allow you to link photos to maps, there is nothing like Aerith's 3D graphics and interactivity. I'm most excited that we were able to open source the code for Aerith under the BSD license so that other developers can learn from it.

What to Do When Stumped

JSC: What do you do when you feel stumped?

Marinacci: I do something else. My brain will continue working on the problem even if I'm not actively thinking about it, so I switch tasks and do some email, read some blogs, or take a 15-minute walk. Sometimes, I can resolve the problem in minutes; other times, it takes days. If I'm completely stumped, I ask one of my colleagues. Chances are, one of them will know the answer.

JSC: What would you say to a student or an engineer new to Java software?

Marinacci: When it comes to graphical user interfaces (GUIs), don't use a layout manager! Start by building all of your screens in Matisse, the new GUI builder in NetBeans IDE 5.0. It will reduce your GUI-building time by a factor of five and lower your learning curve dramatically. The days of hand-coding GUIs are over!

A Dollar From James Gosling

JSC: Do you have a favorite Java software story?

Marinacci: When we demo'd the Aerith application for James Gosling to include in his JavaOne conference keynote, he was very impressed. He said to give serious props (proper respect) to whoever built the mapping component, which is the part of Aerith I had focused on. I nervously said it was me. James said, "That's worth a dollar" and actually took a dollar out of his wallet and handed it to me!

To have James Gosling, one of the inventors of the Java language, give me a dollar is worth more to me than any accolades from the press. We now have that dollar, signed and framed, hanging on the wall of the Swing team's common room.

See Also

Josh Marinacci's blog
Swing Hacks: Tips and Tools for Killer GUIs
Flying Saucer: The 100% Java XHTML Renderer
Meet Kohsuke Kawaguchi, Staff Engineer and XML Schema Developer at Sun Microsystems
Migrating to Tiger: James Gosling and Mark Reinhold on Java 2 Platform, Standard Edition 5.0
Java SE 6 platform
Swing toolkit tutorial
Java 2D API
NetBeans IDE
Matisse
Aerith
2006 JavaOne Conference home page

The terms "Java Virtual Machine" and "JVM" mean a Virtual Machine for the Java platform.

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.