BeeSoft®
Since 1992
 

Content

 Welcome
 Products
       Abeona
       Gaia
             News
             Documentation
                   Introduction
                   Swing support
                         Components
                         Building from XML
                               Step by step
                               XML elements
                               Data binding
                               Internationalization
                         Client / server
                   Server application
                   Validation
                   XML
                   Logging
                   Utilities
                   Launcher
             License
             Download
       Hephaistos
       JavaGantt
 Services
       Promote your software
 Contact Us
 Links
      
  GaiaI®
© 2012 BeeSoft ®
 

Step by step

Of course, the first step is to create a XML file with Swing form description. Currently there is no tool to support this work, so you must to do it manually.

You can read about all supported elements and attributes in the next chapter. Please, note, there are supported all important Swing components and layouts, and you can enhance this support with your own classes.

When you have your XML file completed, you need to process it to the Swing form. The basic pattern is here:

	// prepare path to form XML 
	String formId = "mypackage/myform.form";

	// prepare resource bundle name
	// this is not necessary, you must not always use the resource bundles
	String messagesBundleId = "mypackage.myform";

	// create new builder factory
	SwingBuilderFactory factory = new SwingBuilderFactory ();
	factory.setResourceBundle (messagesBundleId);

	// build component (form, menu, application, ...)
	InputStream is = Streams.getInputStream (formId);
	ComponentBuilder<?> builder = (ComponentBuilder<?>) factory.build (is);

	// obtain a root component
	JComponent component = (JComponent) builder.getObject();

	// use this component 
	...

You can see, the SwingBuilderFactory class is playing the key role in our code. This class registers which element tag is processed by which builder class. Each buider instance is responsible for creation one component. And most of our builders are derived from eu.beesoft.gaia.swing.builder.SwingBuilder class.

You can also write your own builder if Gaia built-in support does not meet your requirements, or if you are using the component we don't support. Then you can register it to the factory in the pair with processed element tag with this code:

	SwingBuilderFactory factory = new SwingBuilderFactory ();
	factory.registerBuilderClass ("mytag", MyBuilder.class);

A SwingBuilderFactory instance keeps a list of all builders it produced. So you can access to any component in the built form via its id:

	String id = "label_m01";
	LabelBuilder builder = (LabelBuilder) factory.getBuilder (id);
	JLabel label = builder.getObject ();

A special attention is focused on the Swing actions and a ListModels. There are implemented methods to obtain:

	// returns the action builders as children of the given builder
	List<ActionBuilder> actionBuilders = factory.getActionBuilder (rootBuilder);

	// returns the actions produced by children of the given builder
	List<Action> actions = factory.getActions (rootBuilder);

	// returns a collection of all list model builders
	List<ListModelBuilder> listModelBuilders = factory.getListModelBuilders ();

	// returns a collection of list model builders as children of the given builder
	List<ListModelBuilder> listModelBuilders = factory.getListModelBuilders (rootBuilder) ;

These method are needed to obtain actions supported by the built form and also to initialize list models with data.