The Source for Java Technology Collaboration
User: Password:



Romain Guy

Romain Guy's Blog

Synth Studio

Posted by gfx on September 01, 2005 at 02:47 AM | Comments (14)

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.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • I have not seen any Synth look and feel to download. Where can I found something?

    Posted by: lokimad on September 01, 2005 at 07:22 AM

  • >I have not seen any Synth look and feel to download. Where can
    >I found something?


    See http://www.javasoft.de/jsf/public/products/synthetica/screenshots

    Posted by: marcohu on September 01, 2005 at 08:23 AM

  • >> I have not seen any Synth look and feel to download. Where can I found something?

    Synth is part of Java 1.5+

    http://www.developertutorials.com/tutorials/java/advanced-synth-050416/page1.html

    Posted by: bloid on September 01, 2005 at 08:45 AM

  • Doh! Forgot this was HTML based...
    Synth is part of Java 1.5+
    http://www.developertutorials.com/tutorials/java/advanced-synth-050416/page1.html

    Posted by: bloid on September 01, 2005 at 08:46 AM

  • Romain,
    A couple of us here in WI have already started developing a tool that can read and write Synth Files. We are incorporating a ui as well. I'd like to start a java.net project and move the code if that's possible. The ultimate goal is what you state in your post: to create an application that would allow the creation of Synth LNF files without the developer having to write XML. Please let me know if you are interested.

    Tim

    Posted by: lordkilgour on September 01, 2005 at 10:51 AM

  • real cool Romain. Is that my PropertySheet you are using or what?

    and BTW you forced me to release a small Flash demo of my SynthBuilder.... http://synth.l2fprod.com/synthbuilder.htm

    Let's see things move around this topic...

    -fred

    Posted by: l2fprod on September 01, 2005 at 12:12 PM

  • Yes, this is your property sheet :) Your builder seems really cool but you'll have to support the new features ^^

    Posted by: gfx on September 01, 2005 at 01:46 PM

  • lordkilgour and fred, could we get in contact to talk about a Synth editor?

    Posted by: gfx on September 01, 2005 at 11:06 PM

  • Looks nice, didn't tried it yet.
    Maybe you could use the pluginengine I am working on with two other develper, so other could extend the tool.
    You can get it from here
    .

    For more info you can look at our website,
    you can find a tutorial here (site is not yet completed), for question you can send an e-mail to our mailing list on the sourceforge website.
    The pluginengine is licensed under the BSD licence.

    Posted by: carmello on September 05, 2005 at 12:46 AM

  • Hi Romain,
    I am trying to run ./VisualGrinder on Linux RH9 with java version "1.5.0_01". Here's what I have:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.sun.swing.synth.studio.ui.LookAndFeelGrinderFrame$LookAndFeelListCellRenderer.getListCellRendererComponent(LookAndFeelGrinderFrame.java:530)
    at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1148)
    at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1098)


    ...


    Since you didn't post the source code, could you please take a look at that. I would like to experiment with synth.

    Thanks
    -zak_d

    Posted by: zak_d on November 22, 2005 at 11:49 AM

  • if you want to make things easier ,you can try ro use Zoom Studio, enjoy yourself!

    Posted by: orange2006 on April 05, 2006 at 07:53 PM

  • Hello Romain, I can not download the file "http://www.progx.org/users/Gfx/synthstudio-ea1.tgz", it seems that the host is closed?
    Can you provide another download url?
    Or maybe you can send it to me by email?
    My email is gdxuanyun@hotmail.com, thank you:-)

    Posted by: xuanyun on February 06, 2007 at 05:20 PM

  • xuanyun: The host is up and the file is here but I know that my host provider is blocked or difficult to access from certain countries.

    Posted by: gfx on February 06, 2007 at 11:46 PM

  • Hi Romain, I can not access the host, is there any mirror?
    By the way, are you still working on the Synth Studio? Is there any progress? I'm very interest in this.

    Posted by: xuanyun on March 12, 2007 at 02:04 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds