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.

Saturday, September 23, 2006

Universal binaries

I am just starting to create a help system on the Mac. Been doing a lot on the Mac version this werek, mostly as a result of using the excellent jar-bundler Ant task (thanks Greg and Will).

To get the help system called up on the Mac, you need to create a JNIlib, but the problem is that the example code in jar-bundler only builds the code for the current platform. So as soon as I transferred the binary from my Intel MacBook to my PowerPC iMac, the thing broke.

The trick is to pass a couple of -arch calls to cc:

<exec executable="cc">
<arg line="-c">
<arg line="-I/System/Library/Frameworks/JavaVM.framework/Headers">
<arg line="-o build/HelpBookJNI.o">
<arg value="platforms/macosx/obj-c/HelpBookJNI.m">
</exec>

<exec executable="cc">
<arg line="-dynamiclib">
<arg line="-framework JavaVM">
<arg line="-framework Cocoa">
<arg line="-o build/libHelpBookJNI.jnilib">
<arg value="build/HelpBookJNI.o">
</exec>

becomes:

<exec executable="cc">
<arg line="-arch ppc">
<arg line="-arch i386">
<arg line="-c">
<arg line="-I/System/Library/Frameworks/JavaVM.framework/Headers">
<arg line="-o build/HelpBookJNI.o">
<arg value="platforms/macosx/obj-c/HelpBookJNI.m">
</exec>

<exec executable="cc">
<arg line="-arch i386">
<arg line="-arch ppc">
<arg line="-dynamiclib">
<arg line="-framework JavaVM">
<arg line="-framework Cocoa">
<arg line="-o build/libHelpBookJNI.jnilib">
<arg value="build/HelpBookJNI.o">
</exec>

Sunday, September 17, 2006

Binary versions available

It's starting to take shape now. Basic mind maps can be created (although only simple tree structures - no cross-links between ideas yet) and they can be opened and saved to OPML files.

Over the weekend I started to create platform-specific builds for the Mac and Windows (Linux coming next). The binaries for these and the pure Java version are available via the project page.

I've also started to create the look of the application. For the moment this means pictures of Frank Zappa plastered everywhere. Looks a little rough. I really need to spend an evening with Photoshop and the The Gimp (did you know that Gimp can export Windows .ico files? Very useful).

The code needs tidying up next. There are hardly any unit tests and the separation between model, view and controller is a little arbitrary. I'd like to formalise things a lot more and probably bring in a library called INX ("Interfaces iN XML") that I started a while back. It will let me lay out frames using HTML-style syntax in XML and then bind Java beans to the views.

Good Heavens. My longest post yet...