Skip to main content

Synth Studio

Posted by gfx on September 1, 2005 at 2:47 AM PDT

Synth Studio EA1

Synth Studio Early Access 1 is a package of three very simple tools I wrote to help me port existing look and feels to Synth. The downloadable archive contains everything you need to run them but I haven't included the source code yet, for I need to figure out which license to use. I might even start a new java.net project if some of you are interested into helping creating a suite of tools to easy Synth look and feels creation. But let's take a look at what Synth Studio already offers.

Visual Look and Feel Grinder

For my first experiences with Synth I tried to port existing look and feels. Doing such a thing can be really painful if you take the time to capture screenshots of every component, in each possible state. It's even harder because you usually have to extract the component from its background. In the case of non rectangular components, like Alloy or Windows XP buttons, things can get pretty nasty. Visual Look and Feel Grinder helps a lot:

In this window, you can selected the look and feel of your choice in the bottom combo box. Look and feels are seeked within the classpath used when you run the application. If you use one of the startup scripts included in the archive, you can just set the CLASSPATH environment variable so that it includes the look and feel you want to "grind". Once you've selected the look and feel of your choice, you can pick a Swing component in the left palette and see it in the central area. Next, you can use the properties sheet on the right to change properties until the component is in the appropriate state. You can finally click either of the two buttons on the lower right to export the component as a PNG file with a transparent background. The result is incredibly easy to use in any good picture editing software and it can serve as excellent basis for a brand new look and feel of your own.

Look and Feel Grinder

While useful, Visual Look and Feel Grinder is quite tedious to use when you want to extract pictures for every Swing component. Look and Feel Grinder works in a very similar fashion but solely with a command line interface. By default, it will use the default platform look and feel (Metal or Ocean on Windows and Linux, Aqua on MacOS X) but you can choose your own by specifying its class name as a parameter:

$ ./LookAndFeelGrinder com.sun.java.swing.plaf.motif.MotifLookAndFeel

The tool will then create a new directory named after the look and feel and put all the generated pictures in it.

Some components will have several pictures, one per state. For instance, a JProgressBar will generate two pictures, JProgressBar_default.png and JProgressBar_disabled.png. You can see them both here:

To achieve its work, Look and Feel Grinder relies on a resource called

com/sun/swing/synth/studio/resources/beans.xml

which contains a definition of the components and their states we want to generate:



<beans>
  <bean name="JButton">
    <state type="disabled" />
    <state type="empty" />
    <state type="pressed" />
  </bean>
  <!-- ... -->
</beans>


Each couple bean/state is mapped to a method of com.sun.swing.synth.studio.components.ComponentFactory

. Here are the methods available for a JButton:

public abstract JComponent createJButtonDefault(ComponentContext context);
public abstract JComponent createJButtonDisabled(ComponentContext context);
public abstract JComponent createJButtonEmpty(ComponentContext context);
public abstract JComponent createJButtonPressed(ComponentContext context);

The ComponentContext is actually unused but has a future purpose. Its goal is to encapsulate all the required states to avoir declaring one method per component and state. Each method simply creates the appropriate components and sets it up so that it can be "grinded" and provide a good result. Take a look at the creation of a progress bar:

public JComponent createJScrollBarDefault(ComponentContext context) {
  JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
  scrollBar.setValue(50);
  scrollBar.setPreferredSize(new Dimension(300,
    scrollBar.getPreferredSize().height));
  return scrollBar;
}

Finally, the grinder calls a renderer on each component. It is, by default, a PictureComponentRenderer which, as you can guess, creates a PNG file from the component. I also started implementing a SynthComponentRenderer to generate a skeleton of the Synth look and feel in which you'll only have to modify the insets.

In the end, both grinders are really useful when used with the third tool, Insets Worker.

Insets Worker

The most annoying part of creating a Synth look and feel (apart from understanding how Synth works :) is to define the insets of each picture used for each state of each component. It is a tedious job we can't really automate and for which picture editing tool aren't really meant for. Insets Worker is a very simple application which helps you define them by loading a picture of a component and dragging guidelines:

You can load a picture by using PNG files and the load button, but you can also drag them directly from Visual Look and Feel Grinder (initiate the drag gesture on the checkboard panel beneath the component). Just drag the four guidelines until they match what you want, read the insets at the bottom and write them down in your Synth XML file. Defining the insets often require single-pixel precision and you can hardly do that with components shown at 100% of their size. Just roll your mouse wheel to zoom in and out:

Is it really a Synth Studio? Not yet...

Even though they proved to be really useful in my work, those three tools are still very crude and should be somehow integrated together. They should also be extended so that you can visually design a Synth look and feel without ever writing XML code. Such a graphical tool could even help masking a lot of Synth subtelties and make this skinning technology much easier to use. If you are interested in contributing to such a project, say so and we'll start a new java.net project.

Related Topics >>