Fuse 0.2 and Fuse 0.3

Yesterday, Daniel Spiewak released Fuse 0.2. Fuse is a resource injection library mostly designed to be used with GUI toolkits like Swing and SWT. I did not work much on this release so there are no new supported types for Swing. That said there is some good stuff in there:

  • Hives: A hive can inject resources into objects but it also keeps track of them. If you reload the resources, the hive will automatically inject the new values into your objects. In the case of Swing and SWT it will also refresh them. You can take a look at an example of the Swing Hive.
  • Definitions: Fuse works great when you have the source code of your components so that you can annotate their fields. However, if you don't the only solution is to create a custom TypeLoader which can be very tedious. Fuse 0.2 brings definitions which describe the fields to be injected. For instance, you can take a JLabel and create a definition that tells Fuse to inject foreground and text. Definitions can be declared with XML, regulare classes or maps.
  • New types: Fuse 0.2 supports 8 new SWT types and 5 new Java core types. (Like Date.)
  • Resource loaders: Prior to Fuse 0.2 you could only define your resources in a properies file. Fuse 0.2 now supports abstract resource loaders. Default resource loaders include XML, properties and maps. You can easily create your own to pull the resources out of a database for instance.
  • Demos: Fuse 0.2 ships with many demos. Included demos show you how to you use the basic features, but also how to use definitions, new resource loaders and the hives.

The are a few other new features you can discover in the release notes. You can download Fuse 0.2 or visit the project page to get a comprehensive introduction and documentation.

We have already begun working on Fuse 0.3 and if you grab the source code from the CVS you will be able to play with a very cool incoming feature: auto injection. Here is a short example:

JFrame f = new JFrame("Swing Auto Injection");
// or enable("name", f) to choose a specific resource injector

Once auto injection is enabled on a container, (JPanel, JFrame, whatever…) resources will be injected in every component you add to this container or one of its children. That's right, you won't have anything else to do. Auto injection also introduces the notion of binding. When using Swing's auto injection provider you can bind a component name to a definition. For instance, here is how you can make all your error labels be red:

// load a definition
    XMLDefinition.load(SwingAutoInjection.class, "error-label.xml"));

// bind the name error-label to the definition called error-foreground
AutoInjection.bind("error-label", "error-foreground");

// create the label and give it a name
JLabel label = new JLabel("Howdy I am red.");
f.add(label, BorderLayout.SOUTH); 

Once bound to a definition you can easily change the properties file to change the appearance of all your error labels. We are also thinking about the way we could mix auto injection and hives to let you reload and refresh the UI very easily.


2 Responses to “Fuse 0.2 and Fuse 0.3”

  1. I agree! Just marvellous! Your writing manner is pleasing and the way you treated the subject with grace is commendable. I am intrigued, I presume you are an master on this subject. I am signing up for your upcoming updates from now on.