hIPster icon The Official Hipster Blog

Sunday, September 24, 2006

XML Menus

The menus in the main window of the application are now stored as XML within the jar bundle. It's done using a very simple package I created a couple of years ago called "Interfaces iN Xml" (INX). Here's the menu:

<menubar>
<menu textname="file">
<item textname="new" action="newDocument" key="N">
<item textname="-">
<item textname="open" action="openDocument" key="O">
<item textname="save" action="saveDocument" key="S">
<item textname="saveAs" action="saveAsDocument">
</menu>
<menu textname="edit">
<item textname="insertChild" action="insertChild">
<item textname="insertSibling" action="insertSibling">
</menu>
<menu textname="view">
<item textname="zoomIn" action="zoomIn" key="PLUS">
<item textname="zoomOut" action="zoomOut" key="MINUS">
</menu>
<menu textname="help">
</menu>
</menubar>

The text-names refer to strings in a specified resources file (that'll help with internationalization), the action is a method in some underlying Java class and the key will be comined with whatever the platform-specific menu key is ([CTRL] on Windows [Command] on the Mac).

Here's the code in Mainframe that calls it up:

XMLMenuBar menuMgr = new XMLMenuBar(this,
"/dg/hipster/view/mainframeMenu.xml", resBundle);

If somebody clicks on the "view/zoomIn" item, the Mainframe.zoomIn() method will be called.

I hope to migrate more and more of the interface to XML. It should make it easier for non-Java people to modify the code.

0 Comments:

Post a Comment

<< Home