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:
JLabeland create a definition that tells Fuse to inject
text. Definitions can be declared with XML, regulare classes or maps.
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"); AutoInjection.enable(f); // 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 ResourceInjector.addDefinition("error-foreground", 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."); label.setName("error-label"); 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.