We're going to look at how to extend the menu bar.
- In the /home/idv/idv/ucar/unidata/apps/example/resources directory
copy the file defaultmenu.xml up a level to the example directory.
- Bring the defaultmenu.xml file into an editor.
- Run the ExampleIdv. Note the new menu entry. For kicks, select
. This shows all of the resources
loaded into the ExampleIdv.
- Let's add in a Hello World menu item.
- Note that we now have code embedded in our menubar xml file. This might not be good practice.
We'll use the "actions"resource to define an action.
- Copy the file resources/actions.xml to the example directory.
- This defines an action called "example.helloworld":
<action
id="example.helloworld"
image="/ucar/unidata/apps/example/resources/HelloWorld.gif"
description="Call hello world"
action="jython:idv.helloWorld();"/>
- Add the following into the defaultmenu.xml. Note the "action:" prefix.
<menuitem
action="action:example.helloworld"
label="Hello World from action"/>
<separator/>
- Run ExampleIdv.
- The example.helloworld action is now also available in the toolbar.
Bring up the User Preferences
- So, this added our own menu into the menu bar. How do we not use any of the system menus?
- Bring up the idv.rbi and change
<resources name="idv.resource.menubar">
</resources>
To:
<resources name="idv.resource.menubar" loadmore="false">
<resource
location="/ucar/unidata/apps/example/defaultmenu.xml"/>
</resources>
The loadmore tells the IDV not to use the system resources.
- Run the ExampleIdv.
- Remove the above entries from the example idv.rbi file.
- Now, lets look at the default system menubar in /home/idv/idv/ucar/unidata/idv/resources/defaultmenu.xml
- Note the "id=" attributes. The IDV uses these ids to know where to dynamically
add in different menus, e.g., available windows, display lists, data, etc.
Unidata IDV Workshop for version 3.0u2 > Java Developer Topics > IDV User Interfaces