Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/menu/spi/MenuVisitor.java


1   package javax.ide.menu.spi;
2   
3   
4   import javax.ide.extension.ElementContext;
5   import javax.ide.extension.ElementName;
6   import javax.ide.extension.ElementStartContext;
7   import javax.ide.extension.ElementVisitor;
8   import javax.ide.extension.ExtensionHook;
9   import javax.ide.extension.I18NCharVisitor;
10  import javax.ide.extension.I18NStringVisitor;
11  import javax.ide.extension.IconVisitor;
12  import javax.ide.util.IconDescription;
13  
14  /**
15   * Handler for menu in a menu bar.
16   */
17  class MenuVisitor extends PositionableVisitor
18  {
19    static final ElementName MENU = new ElementName( 
20      ExtensionHook.MANIFEST_XMLNS, "menu" );
21  
22    private final static ElementName LABEL = new ElementName(
23      ExtensionHook.MANIFEST_XMLNS, "label" );
24    private final static ElementName MNEMONIC = new ElementName(
25      ExtensionHook.MANIFEST_XMLNS, "mnemonic" );
26    private final static ElementName TOOLTIP = new ElementName(
27      ExtensionHook.MANIFEST_XMLNS, "tooltip" );    
28    private final static ElementName ICONPATH = new ElementName(
29      ExtensionHook.MANIFEST_XMLNS, "iconpath" );  
30  
31    private ElementVisitor _sectionVisitor; // = new SectionVisitor();
32  
33  
34    protected void positionable(ElementStartContext context, String id,
35      String before, String after)
36    {
37      MenuBar menuBar = 
38        (MenuBar) context.getScopeData().get( MenusVisitor.KEY_MENU_BAR );
39      Menu menu = menuBar.getMenu( id );
40  
41      if ( menu == null )
42      {
43        menu = new Menu( id );
44        menuBar.addMenu( menu );
45      }
46          
47      processMenu( context, menu, before, after );
48    }
49    
50    protected final void processMenu( ElementStartContext context, final Menu menu, 
51      String before, String after )
52    {
53      if ( before != null ) menu.setBefore( before );
54      else if ( after != null ) menu.setAfter( after );
55  
56      if ( _sectionVisitor == null )
57      {
58        _sectionVisitor = new SectionVisitor();
59      }
60  
61      context.getScopeData().put( MenuHook.KEY_SECTION_CONTAINER, menu );
62      context.registerChildVisitor( SectionVisitor.SECTION, _sectionVisitor );
63      
64      context.registerChildVisitor( LABEL, new I18NStringVisitor() 
65      {
66        protected void string( ElementContext context, String string )
67        {
68          menu.setLabel( string );
69        }
70      });
71      
72      context.registerChildVisitor( MNEMONIC, new I18NCharVisitor() 
73      {
74        protected void characterValue( ElementContext context, char c )
75        {
76          menu.setMnemonic( c );
77        }
78      });      
79      
80      context.registerChildVisitor( TOOLTIP, new I18NStringVisitor() 
81      {
82        protected void string( ElementContext context, String string )
83        {
84          menu.setTooltip( string );
85        }
86      });      
87      
88      context.registerChildVisitor( ICONPATH, new IconVisitor() 
89      {
90        protected void icon( ElementContext context, IconDescription icon )
91        {
92          menu.setIcon( icon );
93        }
94      });      
95      
96    }
97  
98  }