UISpec4J can be extended to support new kinds of UI components, using the following steps:

  1. Implement a wrapper for your component. This wrapper class must extend the UIComponent interface and it must provide one public constructor with the custom Swing class.
  2. Run the ExtensionGenerator class to generate an enhanced UISpec4J JAR
  3. Put the generated JAR in your classpath before the UISpec4J one, so that enhanced classes are taken into account

Please refer to the ExtensionGenerator Javadoc for more information.

Modified classes

The ExtensionGenerator class modifies only the Panel class. It adds two "get" methods to this class - for instance, if you are adding a Calendar component, it will add:

  public Calendar getCalendar(String name) throws ComponentNotFoundException {
    ...
  }

  public Calendar getCalendar() throws ComponentNotFoundException {
  ...
  }

How it works

The extension mechanisms works at the bytecode level, using the ASM library. It parses the Panel class loaded from the classpath, and generates the bytecode in the proper section for the two methods.

Dependencies

For the extension mechanism to work, you will need asm-3.1.jar and asm-util-3.1.jar in your classpath.