You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

In an earlier part of the tutorial we showed how to add a menu item to the help menu using the addMenu() method, and a "magic" number. In practice this method is only useful for trivial plugins. Real plugins are more likely to use an XML file to define new menu items, as described below.

First lets look at where the "magic" number 900100 in the earlier example came from. To do this we need to look at the XML file which JAS3 uses to define its own basic menus.

jas3.menus
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MenuSystem SYSTEM "http://java.freehep.org/schemas/menus/1.0/menus.dtd">
<MenuSystem>
   <MenuBar id="mainMenu">
		
      <Menu name="File" mnemonic="F" location="100">
         <Component type="default" name="Exit" mnemonic="E" command="exit" location="990"/>
      </Menu>
		
      <Menu name="View" mnemonic="V" location="300">
         <Component type="checkbox" name="Tool Bar" mnemonic="T" 
	     description="Show the application tool bar" command="showToolBar" location="100"/>
         <Component type="checkbox" name="Status Bar" mnemonic="S" 
	     description="Show the application status bar" command="showStatusBar" location="110"/>
         <Menu name="Look and Feel" mnemonic="L" class="org.freehep.application.LookAndFeelMenu" location="700"/>
         <Menu name="Window Style" mnemonic="W" class="org.freehep.application.studio.PageManagerMenu" location="750"/>
      </Menu>
		
      <Menu name="Window" mnemonic="W" location="800" class="org.freehep.application.mdi.WindowMenu">
         <Component type="default" name="Close" mnemonic="C" command="closePage"/>
         <Component type="default" name="Close All" mnemonic="A" command="closeAllPages"/>
         <Separator/>
         <Component type="default" name="Cascade" mnemonic="s" command="cascade"/>
         <Component type="default" name="Tile Horizontally" mnemonic="h" command="tileHorizontally"/>
         <Component type="default" name="Tile Vertically" mnemonic="v" command="tileVertically"/>
      </Menu>
		
      <Menu name="Help" mnemonic="H" location="900">
         <Component type="default" name="Examples" mnemonic="E" command="examples" location="500"/>
         <Component type="default" name="About" mnemonic="A" icon="/toolbarButtonGraphics/general/About16.gif" 
	     command="about" location="900">
            <Accelerator shift="false" meta="false" key="VK_F1" ctrl="false" alt="false"/>
         </Component>
      </Menu>

   </MenuBar>
</MenuSystem>
  • No labels