Previous: Example UI Manager Next:  Data Choosers Table of contents Frames User guide
Unidata IDV Workshop for version 6.3 > Java Developer Topics > IDV User Interfaces

5.3.3 Example Menu Bar
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 Example→Show resources. This shows all of the resources loaded into the ExampleIdv.
  • Let's add in a Hello World menu item.
    • Add in the following under the "Example" menu tag.
          <menuitem
             action="jython:idv.helloWorld();"
             label="Hello World"/>
      
    • Run ExampleIdv. Select Example→Hello World
    • We get an error. We need to add the helloWorld method to ExampleIdv:
        public void helloWorld() {
            System.err.println("Hello World");
        }
      
      The method needs to be public.
    • Compile and run again.
  • 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, let's 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.

 


Previous: Example UI Manager Next:  Data Choosers Table of contents Frames User guide
Unidata IDV Workshop for version 6.3 > Java Developer Topics > IDV User Interfaces