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

Quick Search    Search Deep

Source code: javax/ide/extension/IconVisitor.java


1   package javax.ide.extension;
2   import java.util.logging.Level;
3   import javax.ide.extension.spi.ExtensionVisitor;
4   import javax.ide.util.IconDescription;
5   
6   /**
7    * Use IconVisitor for processing an XML element in the manifest that provides
8    * an icon.
9    */
10  public abstract class IconVisitor extends ElementVisitor
11  {
12    private I18NStringVisitor _delegate = new I18NStringVisitor()
13    {
14      protected final void string( ElementContext context, String string )
15      {
16        // NO-OP
17      }
18    };
19    
20    public void start( ElementStartContext context )
21    {
22      _delegate.start( context );
23    }
24    
25    public void end( ElementEndContext context )
26    {
27      String rskey = (String) context.getScopeData().get( 
28        I18NStringVisitor.KEY_RSKEY );
29  
30      if ( rskey == null || rskey.trim().length() == 0 )
31      {
32        String text = context.getText();
33        if ( text == null || ( text = text.trim()).length() == 0 )
34        {
35          log( context, Level.WARNING, 
36            "Must provide an icon path or resource key."
37          );
38        }
39        IconDescription id = IconDescription.createPathInstance(
40          (ClassLoader) context.getScopeData().get( ExtensionVisitor.KEY_CLASSLOADER ),
41          text
42        );
43        icon( context, id );
44      }
45      else
46      {
47        IconDescription id = IconDescription.createResourceInstance(
48          (ClassLoader) context.getScopeData().get( ExtensionVisitor.KEY_CLASSLOADER ),
49          (String) context.getScopeData().get( ExtensionHook.KEY_RSBUNDLE_CLASS ),
50          rskey
51        );
52        icon( context, id );
53      }
54    }
55  
56    /**
57     * Called when an icon is encountered. 
58     * 
59     * @param context the processing context.
60     * @param icon the icon.
61     */
62    protected abstract void icon( ElementContext context, IconDescription icon );
63  
64  }