Advanced Synth
By Michael Abernethy2005-04-16
Examining Synth Performance, Reliability, and Efficiency
Now that you've seen how to create an XML file for Synth and how to create a custom look by changing fonts, changing colors, and adding images, you probably have questions about Synth. If you've dealt with Swing for a while now, I'm sure you first thought about performance issues. I've devised some performance tests that show that Synth won't slow your UI to a crawl. I've also checked out the Java Bug Parade (see Resources) for Synth issues to investigate problem areas you might see (and to discuss issues I've come across in working with it). Finally, I'll answer your most important question -- will Synth really save you time?
Does loading so many images make Synth slower?I've created two tests to answer this question and give you a better feel for how Synth stacks up against the other look and feels in terms of performance. The first test times the load-up for the example login-screen application. This test loads six images in Synth and compares the load-up time to that of an average screen that a developer might create. The second test is a stress test on load-up times -- a frame with over 100
Both tests time the Ocean and Motif look and feels for comparison. To make a fair evaluation, I ran both tests on three machines -- a Windows XP laptop, a SuSE Linux box, and a Red Hat Linux box. The results appear in Tables 1 and 2.
Table 1. Average load time of login screen
| Machine settings | Ocean | Motif | Synth |
| Windows XP - 1.7GHz - 2GB RAM | .32 seconds | .29 seconds | .57 seconds |
| SuSE Linux 9.0 - 3.3GHz - 2GB RAM | .23 seconds | .20 seconds | .45 seconds |
| Red Hat Linux 3.0 - 1.4GHz - 512MB RAM | .37 seconds | .32 seconds | .61 seconds |
Table 2. Average load time of 100-component screen
| Machine settings | Ocean | Motif | Synth |
| Windows XP - 1.7GHz - 2GB RAM | .33 seconds | .32 seconds | .34 seconds |
| SuSE Linux 9.0 - 3.3GHz - 2GB RAM | .23 seconds | .23 seconds | .30 seconds |
| Red Hat Linux 3.0 - 1.4GHz - 512MB RAM | .40 seconds | .40 seconds | .43 seconds |
As you can see, the Synth look and feel loads up only minimally more slowly than Ocean and Motif. Note, though, that the login screen loads up more slowly than the stress test. This seems odd at first glance, but closer examination revealed the culprit. The stress test doesn't load the images used in the checkbox, whereas the login screen does. This leads to the conclusion that every additional image used in the Synth look adds to load up time. A hundred components using the same image will load faster than an application that has two components using two images. Reducing the number of images used will improve performance in Synth load-up times.
Is Synth as buggy as Swing was when it was first released?
To judge by the Bug Parade on Sun's Java developer Web site, Synth seems to be a clean and bug-free product. However, no software is perfect. At one point there were 125 bugs against Synth, a disproportionate share of which related to how Synth deals with the JTabbedPane. So if you experience some issues there, don't be surprised. In Sun's defense, though, these defects are all in the "Closed" state. But it's often the case that if there have been problems before, problems will probably occur in the future.
Despite the relatively clean image that the bug database gives Synth, I had some other issues when working with the login screen. My first attempt at changing the background color of the JPanel failed. I had created a style specific for JPanels and bound it to all JPanels, but it just didn't work. Things did work when I decided to use my own custom painter instead.
A bigger issue is the repainting of the widgets when states change. In working with the buttons and their states, I found that the text on the button wouldn't change colors properly. The default color of white would not appear correctly when initialized and wouldn't show up until a state change had been triggered and then was set back to default. Poring through the documentation on Synth turns up this little tidbit: "While you can supply a different font per state, in general widgets will NOT revalidate when the state changes, so that you may run into sizing problems if you try to use a font with a significantly different size for different states." Sounds like they ran into problems trying to make Synth work with the old legacy Swing code. So, beware when trying to change fonts when states change.
Synth does appear to be relatively bug free. But I wouldn't be surprised if little things crop up here and there where the code should work but doesn't. Workarounds shouldn't be hard to find, though. I could find one for every issue that popped up in my work.
Can a complete professional look and feel be created from Synth?
The answer is yes. The GTK+ and Windows XP look and feels released in Java 1.4 were created solely by using Synth. (It wasn't a published API back then.) So it definitely can be done.
How much faster can you create a complete look with Synth versus writing one in Java code?This should be easy to compute. Two steps are involved in each approach:
1. Creating the look, which is work usually done by graphic artists
2. Converting the graphical work into code
In both the Java-coding and Synth approaches, the graphic-design work takes the same amount of time. Based on my experience in creating custom looks, I estimate that graphic artists take about two people two weeks to create a complete look for an application. That's four person-weeks for graphical work.
Again, based on my experience, it takes three Java coders about two months to translate graphical drawings to a complete, ready-for-prime-time look and feel through subclassing. That's six person-months of Java coding. Adding on the graphical work, it takes seven person-months to create a complete custom look and feel in Swing by overriding the UI classes. Numbers like these help you see why there are so few available for download on the Internet.
Synth enables huge time savings by translating the graphical work to an XML file. The six person-months it takes to create a look by Java coding becomes only two weeks for one developer to translate the graphical work into a Synth XML file. That takes the total down to only six person-weeks to create a complete look and feel in Synth -- more than five months of time savings by using Synth. With a team of two graphical designers and two programmers, a complete Synth look could be produced in just three weeks.
Tutorial Pages:
» Custom UIs are a Breeze with the Newest Swing Look and Feel
» Beauty's Only Skin Deep
» Synth Basics
» Demo Application
» Changing a Color and Font
» Using Images
» Handling Different States
» Working with Custom Painters
» More-Advanced Settings
» Examining Synth Performance, Reliability, and Efficiency
» Conclusion
» Resources
First published by IBM DeveloperWorks
