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 / TreeWriter.java < prev   
Encoding:
Java Source  |  1999-09-19  |  4.2 KB  |  149 lines

  1. /*
  2.  * @(#)TreeWriter.java    1.23 98/08/18
  3.  *
  4.  * Copyright 1997, 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.  * Generate Class Hierarchy page for all the Classes in this run.  Use
  25.  * {@link com.sun.tools.doclets.ClassTree} for building the Tree. The name of 
  26.  * the generated file is "overview-tree.html" and it is generated in the 
  27.  * current or the destination directory. 
  28.  *
  29.  * @author Atul M Dambalkar
  30.  */
  31. public class TreeWriter extends AbstractTreeWriter {
  32.  
  33.     /**
  34.      * Packages in this run.
  35.      */
  36.     private PackageDoc[] packages;
  37.  
  38.     /**
  39.      * True if there are no packages specified on the command line, 
  40.      * False otherwise.
  41.      */
  42.     private boolean classesonly;
  43.  
  44.     /**
  45.      * Constructor to construct TreeWriter object.
  46.      *
  47.      * @param file String filename
  48.      * @param classtree Tree built using
  49.      * {@link com.sun.tools.doclets.ClassTree}.
  50.      */
  51.     public TreeWriter(String filename, ClassTree classtree)  
  52.                                  throws IOException, DocletAbortException {
  53.         super(filename, classtree);
  54.         packages = Standard.configuration().packages;
  55.     classesonly = packages.length == 0;
  56.     }
  57.  
  58.     /** 
  59.      * Create a TreeWriter object and use it to generate the
  60.      * "overview-tree.html" file.
  61.      *
  62.      * @param classtree 
  63.      * {@link com.sun.tools.doclets.ClassTree}.
  64.      */ 
  65.     public static void generate(ClassTree classtree) 
  66.                                 throws DocletAbortException {
  67.         TreeWriter treegen;
  68.         String filename = "overview-tree.html";
  69.         try {
  70.             treegen = new TreeWriter(filename, classtree); 
  71.             treegen.generateTreeFile();
  72.             treegen.close();
  73.         } catch (IOException exc) {
  74.             Standard.configuration().standardmessage.
  75.                 error("doclet.exception_encountered", exc.toString(), filename);
  76.             throw new DocletAbortException();
  77.         }
  78.     }
  79.  
  80.     /**
  81.      * Print the interface hierarchy and class hierarchy in the file.
  82.      */
  83.     public void generateTreeFile() throws IOException {
  84.         printHeader(getText("doclet.Window_Class_Hierarchy",
  85.                             Standard.configuration().windowtitle));
  86.         printTreeHeader();
  87.  
  88.         printPageHeading();
  89.     
  90.         printPackageTreeLinks();
  91.  
  92.         generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy"); 
  93.         generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy"); 
  94.  
  95.         printTreeFooter();
  96.     }
  97.  
  98.     /**
  99.      * Generate the links to all the package tree files.
  100.      */
  101.     protected void printPackageTreeLinks() {
  102.         if (!classesonly) {
  103.             dl();
  104.             dt();
  105.             boldText("doclet.Package_Hierarchies");
  106.             dd();
  107.             for (int i = 0; i < packages.length; i++) {
  108.                 String filename = pathString(packages[i], "package-tree.html");
  109.                 printHyperLink(filename, "", packages[i].name());
  110.                 if (i < packages.length - 1) {
  111.                     print(", ");
  112.                 }
  113.             }
  114.             dlEnd();
  115.             hr();
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * Print the navigation bar links at the top.
  121.      */
  122.     protected void printTreeHeader() {
  123.         navLinks(true);
  124.         hr();
  125.     } 
  126.  
  127.     /**
  128.      * Print the navigation bar links at the bottom.
  129.      */
  130.     protected void printTreeFooter() {
  131.         hr(); 
  132.         navLinks(false);
  133.         printBottom();
  134.         printBodyHtmlEnd();
  135.     } 
  136.  
  137.     /**
  138.      * Print the page title "Hierarchy For All Packages" at the top of the tree
  139.      * page.
  140.      */
  141.     protected void printPageHeading() {
  142.         center();
  143.         h2();
  144.         printText("doclet.Hierarchy_For_All_Packages");
  145.         h2End();
  146.         centerEnd();
  147.     }
  148. }
  149.