home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / JTreeVue / Src / JTreeNodeInfo.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  2.7 KB  |  98 lines

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. import java.io.StreamTokenizer;
  5. import java.io.IOException;
  6.  
  7. public class JTreeNodeInfo implements JTreeConsts
  8.     public String name;
  9.     public int type;
  10.     public String pkg;
  11.  
  12.     private static int prevtype;
  13.  
  14.     public JTreeNodeInfo(String name)
  15.     {
  16.         this.name = name;
  17.     }
  18.  
  19.     //
  20.     // line from html will have following format:
  21.     //    <li> class thepkg.subpkg.<a href="thepkg.subpkg.theclass#tag">TheClass</a>
  22.     //
  23.     //    will also be called for extends/implements
  24.     //
  25.     public JTreeNodeInfo(StreamTokenizer tokstrm)
  26.     {
  27.         // On entry tokstrm.nextToken is token after closing bracket of <li>
  28.         try {
  29.             if ( tokstrm.nextToken() == StreamTokenizer.TT_WORD ) {
  30.                 if ( tokstrm.sval.equalsIgnoreCase("class") )
  31.                     type = HTI_CLS;
  32.                 else if ( tokstrm.sval.equalsIgnoreCase("interface") )
  33.                     type = HTI_IFACE;
  34.                 else if ( tokstrm.sval.equalsIgnoreCase("extends") ||
  35.                           tokstrm.sval.equalsIgnoreCase("implements") )
  36.                 {
  37.                     if ( tokstrm.sval.equalsIgnoreCase("implements") )
  38.                         // if it implements it must be a class
  39.                         type = HTI_CLS;
  40.                     else 
  41.                         // if it extends it must be an interface (which b.t.w.
  42.                         //  can extend more than one interface).
  43.                         type = HTI_IFACE;
  44.  
  45.                     prevtype = type;
  46.  
  47.                     // Skip over pkg
  48.                     if ( tokstrm.nextToken() != StreamTokenizer.TT_WORD )
  49.                         return; // Let's get out of here
  50.  
  51.                     fillInfo(tokstrm);
  52.                     return; // Normal return
  53.                 }
  54.                 else 
  55.                     return; // Let's get out of here
  56.  
  57.                 if ( tokstrm.nextToken() == StreamTokenizer.TT_WORD )
  58.                     pkg = tokstrm.sval;
  59.                     // FALL OUT OF IF out to fillInfo()    call
  60.                 else 
  61.                     return; // Let's get out of here
  62.             }
  63.             else if ( tokstrm.ttype == ',' ) {
  64.                 if ( tokstrm.nextToken() == StreamTokenizer.TT_WORD ) {
  65.                     // found pkg
  66.                     type = prevtype;
  67.                     fillInfo(tokstrm);
  68.                     return; // Normal return;
  69.                 }
  70.                 else {
  71.                     tokstrm.pushBack();
  72.                     return; // Let's get out of here
  73.                 }
  74.             }
  75.             else return; // Let's get out of here
  76.  
  77.             fillInfo(tokstrm);
  78.         } catch (Exception e) {}
  79.     }
  80.  
  81.     private void fillInfo(StreamTokenizer tokstrm)
  82.     {
  83.         try {
  84.             // tokstrm.nextToken() will be beginning of anchor ("<a")upon entry; 
  85.             //  look for closing brace '>', name will be right after
  86.             while ( tokstrm.nextToken() != '>' ) 
  87.                 ;
  88.             // Extract name - This is the text part of the anchor that is underlined
  89.             if ( tokstrm.nextToken() == StreamTokenizer.TT_WORD )
  90.                 name = tokstrm.sval;
  91.  
  92.             // Skip over '</a>'
  93.             tokstrm.nextToken(); tokstrm.nextToken(); tokstrm.nextToken();
  94.         } catch ( IOException e ) { e.printStackTrace(); }
  95.     }
  96. }
  97.