![]() | ![]() |
The configuration filesA The following is a simple example configuration file for a menu bar containing a file menu with a single 'exit' action:
<!DOCTYPE configuration
PUBLIC "-//SWIRL//MenuBuilder configuration 1.0//EN" "configuration.dtd"
>
<configuration>
<root id="main.menu">
<menu i18n="menu.file.text">
<action id="exit">
<caption i18n="exit.text"/>
</action>
</menu>
</root>
</configuration>
(In the examples that follow we shall leave out the DOCTYPE declaration. You should however always include it in your
configuration files, as it
allows the menu builder - and your IDE - to check whether it has the correct format.)
The resource bundle that goes with this configuration will contain entries like the following:
menu.file.text = File
exit.text = Exit program
(and others like them for the different languages that are supported by your application).
Let us use this example to give you a preliminary overview of the various XML elements you may encounter in a typical configuration file.
<caption> and the <menu>
have an i18n-attribute that refers to a key in the resource bundle. In our example the English version of the application
will therefore have a menu called File which contains a menu item called Exit program.
The Java sideThe configuration file alone is not sufficient for the menu builder to be able to do its work. To create the actual menu bar we need a few lines of code:
MenuBuilder menuBuilder = new MenuBuilder ();
menuBuilder.load ("/myapplication/resources/menus.xml",
"myapplication.resources.menus");
menuBuilder.registerAction ("exit", new ExitAction());
JMenuBar menuBar = menuBuilder.createJMenuBar ("main.menu");
Some remarks:
|
|