Skip to main content

Gooey Beans Extract 1: Resource Map

Posted by evanx on November 3, 2006 at 2:24 AM PST

This the first part of my work-in-progress, um, online book, woohoo!

It's a preachy scifi/fantasy online book, trilogy in 42 parts, on how you could rewrite your database application using Swing. It's gonna be whatsit, creative commons, partly because it's not gonna be worth the, um, paper its not written on.

Gooey Resource Map, A part of "Gooey Beans, a trilogy in 42 parts"

public class AddressFormPanel extends JPanel {    
    AddressFormPanelResources resources =
       dependencyContainer.getResources(AddressFormPanelResources.class);
    ...
    JButton newButton = new JButton(resources.newButton);
    JButton deleteButton = new JButton(resources.deleteButton);
    JButton editButton = new JButton(resources.editButton);
    JButton saveButton = new JButton(resources.saveButton);
    JButton cancelButton = new JButton(resources.cancelButton);
    ...

where we have introduced a peer "resources" class, which is as follows.

public class AddressFormPanelResources {    
    @Resource String newButton = "New";
    @Resource String deleteButton = "Delete";
    @Resource String editButton = "Edit";
    @Resource String saveButton = "Save";
    @Resource String cancelButton = "Cancel";
    ...

When we haven't specified a properties file for our application, and/or haven't populated it properly, our injection prints the following with our defaults for us to cut and paste.

AddressFormPanelResources.newButton = New
AddressFormPanelResources.deleteButton = Delete
AddressFormPanelResources.editButton = Edit
AddressFormPanelResources.saveButton = Save

We also wish to support global values, e.g.

saveAction.keyStroke = control S
saveAction.toolTip = Save the data

where these can be customised for specific classes as follows.

AddressFormPanelResources.saveAction.toolTip = Save the address form

Resources

https://code.google.com/p/vellum/ - where i will collate these articles and their code.

Related Topics >>