home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / tooldocs / javadoc / source / standard / AbstractTreeWriter.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  5.8 KB  |  172 lines

  1. /*
  2.  * @(#)AbstractTreeWriter.java    1.8 98/02/24
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package com.sun.tools.doclets.standard;
  16.  
  17. import com.sun.tools.doclets.*;
  18. import com.sun.javadoc.*;
  19. import java.io.*;
  20. import java.lang.*;
  21. import java.util.*;
  22.  
  23. /**
  24.  * Abstract class to print the class hierarchy page for all the Classes. This
  25.  * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
  26.  * generate the Package Tree and global Tree(for all the classes and packages)
  27.  * pages. 
  28.  *
  29.  * @author Atul M Dambalkar
  30.  */
  31. public abstract class AbstractTreeWriter extends HtmlStandardWriter {
  32.  
  33.     /**
  34.      * The class and interface tree built by using {@link ClassTree}
  35.      */
  36.     protected final ClassTree classtree;
  37.  
  38.     /**
  39.      * Constructor initilises classtree variable. This constructor will be used
  40.      * while generating global tree file "overview-tree.html".
  41.      * 
  42.      * @param filename   File to be generated.
  43.      * @param classtree  Tree built by {@link com.sun.tools.doclets.ClassTree}
  44.      */
  45.     protected AbstractTreeWriter(String filename, ClassTree classtree) 
  46.                                  throws IOException, DocletAbortException {
  47.         super(filename);
  48.         this.classtree = classtree;
  49.     }
  50.     
  51.     /**
  52.      * Create appropriate directory for the package and also initilise the 
  53.      * relative path from this generated file to the current or
  54.      * the destination directory. This constructor will be used while 
  55.      * generating "package tree" file.
  56.      *
  57.      * @param path Directories in this path will be created if they are not 
  58.      * already there.
  59.      * @param filename Name of the package tree file to be generated.
  60.      * @classtree The tree built using {@link com.sun.tools.doclets.ClassTree}
  61.      * for the package pkg.
  62.      * @param pkg PackageDoc for which tree file will be generated.
  63.      */
  64.     protected AbstractTreeWriter(String path, String filename, 
  65.                                  ClassTree classtree, PackageDoc pkg) 
  66.                                  throws IOException, DocletAbortException {
  67.         super(path, filename, DirectoryManager.getRelativePath(pkg.name()));
  68.         this.classtree = classtree;
  69.     }
  70.  
  71.     /**
  72.      * Generate each level of the class tree. For each sub-class or 
  73.      * sub-interface indents the next level information.
  74.      * Recurses itself to generate subclasses info.
  75.      * To iterate is human, to recurse is divine - L. Peter Deutsch.
  76.      *
  77.      * @param parent the superclass or superinterface of the list.
  78.      * @param list list of the sub-classes at this level.
  79.      */
  80.     protected void generateLevelInfo(ClassDoc parent, List list) {
  81.         if (list.size() > 0) {
  82.             ul();
  83.             for (int i = 0; i < list.size(); i++) {
  84.                 ClassDoc local = (ClassDoc)list.get(i);
  85.                 printPartialInfo(local);
  86.                 printExtendsImplements(parent, local);
  87.                 generateLevelInfo(local, classtree.subs(local));   // Recurse 
  88.             }
  89.             ulEnd();
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * Generate the heading for the tree depending upon tree type if it's a 
  95.      * Class Tree or Interface tree and also print the tree.
  96.      *
  97.      * @param list List of classes which are at the most base level, all the 
  98.      * other classes in this run will derive from these classes.
  99.      * @param heading Heading for the tree.
  100.      */
  101.     protected void generateTree(List list, String heading) {
  102.         if (list.size() > 0) {
  103.             ClassDoc cd = (ClassDoc)list.get(0);   
  104.             printTreeHeading(heading);
  105.             generateLevelInfo(cd.isClass()? (ClassDoc)list.get(0): null, list);
  106.         }
  107.     }
  108.  
  109.     /**
  110.      * Print the information regarding the classes which this class extends or
  111.      * implements. 
  112.      *
  113.      * @param cd The classdoc under consideration.
  114.      */
  115.     protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) {
  116.         ClassDoc[] interfaces = cd.interfaces();
  117.         if (interfaces.length > (cd.isInterface()? 1 : 0)) {
  118.             Arrays.sort(interfaces);
  119.             if (cd.isInterface()) {
  120.                 print("(" + getText("doclet.also") + " extends ");
  121.             } else {
  122.                 print(" (implements ");
  123.             }
  124.             boolean printcomma = false;
  125.             for (int i = 0; i < interfaces.length; i++) {
  126.                 if (parent != interfaces[i]) {
  127.                     if (printcomma) {
  128.                         print(", ");
  129.                     }
  130.                     printPreQualifiedClassLink(interfaces[i]);
  131.                     printcomma = true;
  132.                 }
  133.             }
  134.             println(")");
  135.         }
  136.     }
  137.  
  138.     /**
  139.      * Print information about the class kind, if it's a "class" or "interface".
  140.      *
  141.      * @param cd classdoc.
  142.      */
  143.     protected void printPartialInfo(ClassDoc cd) {
  144.         boolean isInterface = cd.isInterface();
  145.         li("circle");
  146.         print(isInterface? "interface " : "class ");
  147.         printPreQualifiedBoldClassLink(cd);
  148.     } 
  149.  
  150.     /**
  151.      * Print the heading for the tree.
  152.      * 
  153.      * @param heading Heading for the tree.
  154.      */
  155.     protected void printTreeHeading(String heading) {
  156.         h2();
  157.         println(getText(heading));
  158.         h2End();
  159.     }
  160.  
  161.     /**
  162.      * Highlight "Tree" word in the navigation bar, since this is the tree page.
  163.      */
  164.     protected void navLinkTree() {
  165.         navCellRevStart();
  166.         fontStyle("NavBarFont1Rev");
  167.         boldText("doclet.Tree");
  168.         fontEnd();
  169.         navCellEnd();
  170.     }              
  171. }
  172.