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 / PackageUseWriter.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  7.4 KB  |  248 lines

  1. /*
  2.  * @(#)PackageUseWriter.java    1.4 98/08/05
  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.  
  16. package com.sun.tools.doclets.standard;
  17.  
  18. import com.sun.tools.doclets.*;
  19. import com.sun.javadoc.*;
  20. import java.io.*;
  21. import java.util.*;
  22.  
  23. /**
  24.  * Generate package usage information. 
  25.  *
  26.  * @author Robert G. Field
  27.  */
  28. public class PackageUseWriter extends SubWriterHolderWriter {
  29.  
  30.     final PackageDoc pkgdoc;
  31.     final SortedMap usingPackageToUsedClasses = new TreeMap();  
  32.  
  33.     /**
  34.      * Constructor.
  35.      *
  36.      * @param filename the file to be generated. 
  37.      */
  38.     public PackageUseWriter(ClassUseMapper mapper, String filename, 
  39.             PackageDoc pkgdoc) throws IOException, DocletAbortException {
  40.         super(DirectoryManager.getDirectoryPath(pkgdoc), 
  41.               filename, 
  42.               DirectoryManager.getRelativePath(pkgdoc.name()));
  43.         this.pkgdoc = pkgdoc;
  44.  
  45.         // by examining all classes in this package, find what packages
  46.         // use these classes - produce a map between using package and
  47.         // used classes.
  48.         ClassDoc[] content = pkgdoc.allClasses();
  49.         for (int i = 0; i < content.length; ++i) {
  50.             ClassDoc usedClass = content[i];
  51.             Set usingClasses = (Set)mapper.classToClass.get(usedClass);
  52.             if (usingClasses != null) {
  53.                 for (Iterator it = usingClasses.iterator(); it.hasNext(); ) {
  54.                     ClassDoc usingClass = (ClassDoc)it.next();
  55.                     PackageDoc usingPackage = usingClass.containingPackage();
  56.                     Set usedClasses = (Set)usingPackageToUsedClasses
  57.                                                      .get(usingPackage);
  58.                     if (usedClasses == null) {
  59.                         usedClasses = new TreeSet();
  60.                         usingPackageToUsedClasses.put(usingPackage, 
  61.                                                       usedClasses);
  62.                     }
  63.                     usedClasses.add(usedClass);
  64.                 }
  65.             }
  66.         }
  67.     }
  68.  
  69.     /**
  70.      * Generate a class page.
  71.      *
  72.      * @param prev the previous class to generated, or null if no previous.
  73.      * @param classdoc the class to generate.
  74.      * @param next the next class to be generated, or null if no next.
  75.      */
  76.     public static void generate(ClassUseMapper mapper, 
  77.                 PackageDoc pkgdoc) throws DocletAbortException {
  78.             PackageUseWriter pkgusegen;
  79.             String filename = "package-use.html";
  80.             try {
  81.                 pkgusegen = new PackageUseWriter(mapper, filename, pkgdoc);
  82.                 pkgusegen.generatePackageUseFile();
  83.                 pkgusegen.close();
  84.             } catch (IOException exc) {
  85.                 Standard.configuration().standardmessage.
  86.                     error("doclet.exception_encountered",
  87.                            exc.toString(), filename);
  88.                 throw new DocletAbortException();
  89.             }
  90.     }
  91.  
  92.  
  93.     /** 
  94.      * Print the class use list.
  95.      */ 
  96.     protected void generatePackageUseFile() throws IOException {
  97.         printPackageUseHeader();
  98.  
  99.     if (usingPackageToUsedClasses.isEmpty()) {
  100.             printText("doclet.ClassUse_No.usage.of.0", pkgdoc.name());
  101.             p();
  102.         } else {
  103.             generatePackageUse();
  104.         }
  105.         
  106.         printPackageUseFooter();
  107.     }        
  108.  
  109.     /** 
  110.      * Print the class use list.
  111.      */ 
  112.     protected void generatePackageUse() throws IOException {
  113.         if (Standard.configuration().packages.length > 1) {
  114.             generatePackageList();
  115.         }
  116.         generateClassList();
  117.     }
  118.  
  119.     protected void generatePackageList() throws IOException {
  120.     tableIndexSummary();
  121.     tableHeaderStart("#CCCCFF");
  122.     printText("doclet.ClassUse_Packages.that.use.0",
  123.           getPackageLink(pkgdoc));
  124.     tableHeaderEnd();
  125.  
  126.     Iterator it = usingPackageToUsedClasses.keySet().iterator();
  127.         while (it.hasNext()) {
  128.         PackageDoc pkg = (PackageDoc)it.next();
  129.         generatePackageUse(pkg);
  130.     }
  131.     tableEnd();
  132.     space();
  133.     p();
  134.     }
  135.         
  136.     protected void generateClassList() throws IOException {
  137.     Iterator itp = usingPackageToUsedClasses.keySet().iterator();
  138.         while (itp.hasNext()) {
  139.         PackageDoc usingPackage = (PackageDoc)itp.next();
  140.         anchor(usingPackage.name());
  141.         tableIndexSummary();
  142.         tableHeaderStart("#CCCCFF");
  143.         printText("doclet.ClassUse_Classes.in.0.used.by.1",
  144.               getPackageLink(pkgdoc),
  145.                       getPackageLink(usingPackage));
  146.             Iterator itc = 
  147.                   ((Collection)usingPackageToUsedClasses.get(usingPackage))
  148.                        .iterator();
  149.             while (itc.hasNext()) {
  150.                 printClassRow((ClassDoc)itc.next(), usingPackage);
  151.             }
  152.         tableHeaderEnd();
  153.         tableEnd();
  154.             space();
  155.             p();
  156.     }
  157.     }        
  158.  
  159.     protected void printClassRow(ClassDoc usedClass, PackageDoc usingPackage) {
  160.         String path = pathString(usedClass, 
  161.                                  "class-use/" + usedClass.name() + ".html");
  162.  
  163.         trBgcolorStyle("white", "TableRowColor");
  164.         summaryRow(0);
  165.         bold();
  166.         printHyperLink(path, usingPackage.name(), usedClass.name(), true);
  167.         boldEnd();
  168.         println(); br();
  169.         printNbsps();
  170.         printIndexComment(usedClass); 
  171.         summaryRowEnd();
  172.         trEnd(); 
  173.     }
  174.  
  175.     /** 
  176.      * Print the package use list.
  177.      */ 
  178.     protected void generatePackageUse(PackageDoc pkg) throws IOException {
  179.         trBgcolorStyle("white", "TableRowColor");
  180.     summaryRow(0);
  181.     printHyperLink("", pkg.name(), pkg.name(), true);
  182.     summaryRowEnd();
  183.     summaryRow(0);
  184.     printSummaryComment(pkg);
  185.     space();
  186.     summaryRowEnd();
  187.     trEnd();
  188.     }
  189.  
  190.     /**
  191.      * Print the header for the class use Listing.
  192.      */
  193.     protected void printPackageUseHeader() {
  194.         String packageLabel = getText("doclet.Package");
  195.         String name = pkgdoc.name();
  196.         printHeader(getText("doclet.Window_ClassUse_Header", 
  197.                             Standard.configuration().windowtitle, 
  198.                             packageLabel, name));
  199.         navLinks(true);
  200.         hr();
  201.         center();
  202.         h2();
  203.         boldText("doclet.ClassUse_Title", packageLabel, name);
  204.         h2End();
  205.         centerEnd();
  206.     }
  207.  
  208.     /**
  209.      * Print the footer for the class use Listing.
  210.      */
  211.     protected void printPackageUseFooter() {
  212.         hr();
  213.         navLinks(false);
  214.         printBottom();
  215.         printBodyHtmlEnd();
  216.     }
  217.  
  218.  
  219.     /**
  220.      * Print this package link
  221.      */
  222.     protected void navLinkPackage() {
  223.         navCellStart();
  224.         printHyperLink("package-summary.html", "", getText("doclet.Package"),
  225.                         true, "NavBarFont1");
  226.         navCellEnd();
  227.     }
  228.                                 
  229.     /**
  230.      * Print class use link
  231.      */
  232.     protected void navLinkClassUse() {
  233.         navCellRevStart();
  234.         fontStyle("NavBarFont1Rev");
  235.         boldText("doclet.navClassUse");
  236.         fontEnd();
  237.         navCellEnd();
  238.     }
  239.  
  240.     protected void navLinkTree() {
  241.         navCellStart();
  242.         printHyperLink("package-tree.html", "", getText("doclet.Tree"),
  243.                         true, "NavBarFont1");
  244.         navCellEnd();
  245.     }
  246.  
  247. }
  248.