src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 2147
130b8c0e570e
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

duke@1 1 /*
jjg@1985 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
bpatel@233 28 import java.io.*;
bpatel@233 29
bpatel@233 30 import com.sun.javadoc.*;
bpatel@766 31 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@766 32 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1357 33 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@233 34
duke@1 35 /**
duke@1 36 * Generate Class Hierarchy page for all the Classes in this run. Use
duke@1 37 * ClassTree for building the Tree. The name of
duke@1 38 * the generated file is "overview-tree.html" and it is generated in the
duke@1 39 * current or the destination directory.
duke@1 40 *
jjg@1359 41 * <p><b>This is NOT part of any supported API.
jjg@1359 42 * If you write code that depends on this, you do so at your own risk.
jjg@1359 43 * This code and its internal interfaces are subject to change or
jjg@1359 44 * deletion without notice.</b>
jjg@1359 45 *
duke@1 46 * @author Atul M Dambalkar
bpatel@766 47 * @author Bhavesh Patel (Modified)
duke@1 48 */
duke@1 49 public class TreeWriter extends AbstractTreeWriter {
duke@1 50
duke@1 51 /**
duke@1 52 * Packages in this run.
duke@1 53 */
duke@1 54 private PackageDoc[] packages;
duke@1 55
duke@1 56 /**
duke@1 57 * True if there are no packages specified on the command line,
duke@1 58 * False otherwise.
duke@1 59 */
duke@1 60 private boolean classesonly;
duke@1 61
duke@1 62 /**
duke@1 63 * Constructor to construct TreeWriter object.
duke@1 64 *
duke@1 65 * @param configuration the current configuration of the doclet.
duke@1 66 * @param filename String filename
duke@1 67 * @param classtree the tree being built.
duke@1 68 */
duke@1 69 public TreeWriter(ConfigurationImpl configuration,
jjg@1372 70 DocPath filename, ClassTree classtree)
duke@1 71 throws IOException {
duke@1 72 super(configuration, filename, classtree);
duke@1 73 packages = configuration.packages;
duke@1 74 classesonly = packages.length == 0;
duke@1 75 }
duke@1 76
duke@1 77 /**
duke@1 78 * Create a TreeWriter object and use it to generate the
duke@1 79 * "overview-tree.html" file.
duke@1 80 *
duke@1 81 * @param classtree the class tree being documented.
duke@1 82 * @throws DocletAbortException
duke@1 83 */
duke@1 84 public static void generate(ConfigurationImpl configuration,
duke@1 85 ClassTree classtree) {
duke@1 86 TreeWriter treegen;
jjg@1372 87 DocPath filename = DocPaths.OVERVIEW_TREE;
duke@1 88 try {
duke@1 89 treegen = new TreeWriter(configuration, filename, classtree);
duke@1 90 treegen.generateTreeFile();
duke@1 91 treegen.close();
duke@1 92 } catch (IOException exc) {
duke@1 93 configuration.standardmessage.error(
duke@1 94 "doclet.exception_encountered",
duke@1 95 exc.toString(), filename);
jjg@1985 96 throw new DocletAbortException(exc);
duke@1 97 }
duke@1 98 }
duke@1 99
duke@1 100 /**
bpatel@766 101 * Generate the interface hierarchy and class hierarchy.
duke@1 102 */
duke@1 103 public void generateTreeFile() throws IOException {
bpatel@766 104 Content body = getTreeHeader();
bpatel@766 105 Content headContent = getResource("doclet.Hierarchy_For_All_Packages");
bpatel@766 106 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
bpatel@766 107 HtmlStyle.title, headContent);
bpatel@766 108 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
bpatel@766 109 addPackageTreeLinks(div);
bpatel@766 110 body.addContent(div);
bpatel@766 111 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
bpatel@766 112 divTree.addStyle(HtmlStyle.contentContainer);
bpatel@766 113 addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
bpatel@766 114 addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
bpatel@766 115 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
bpatel@766 116 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
bpatel@766 117 body.addContent(divTree);
bpatel@766 118 addNavLinks(false, body);
bpatel@766 119 addBottom(body);
bpatel@766 120 printHtmlDocument(null, true, body);
duke@1 121 }
duke@1 122
duke@1 123 /**
bpatel@766 124 * Add the links to all the package tree files.
bpatel@766 125 *
bpatel@766 126 * @param contentTree the content tree to which the links will be added
duke@1 127 */
bpatel@766 128 protected void addPackageTreeLinks(Content contentTree) {
duke@1 129 //Do nothing if only unnamed package is used
duke@1 130 if (packages.length == 1 && packages[0].name().length() == 0) {
duke@1 131 return;
duke@1 132 }
duke@1 133 if (!classesonly) {
bpatel@2147 134 Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel,
bpatel@766 135 getResource("doclet.Package_Hierarchies"));
bpatel@766 136 contentTree.addContent(span);
bpatel@766 137 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@766 138 ul.addStyle(HtmlStyle.horizontal);
duke@1 139 for (int i = 0; i < packages.length; i++) {
bpatel@995 140 // If the package name length is 0 or if -nodeprecated option
bpatel@995 141 // is set and the package is marked as deprecated, do not include
bpatel@995 142 // the page in the list of package hierarchies.
bpatel@995 143 if (packages[i].name().length() == 0 ||
bpatel@995 144 (configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
duke@1 145 continue;
duke@1 146 }
jjg@1372 147 DocPath link = pathString(packages[i], DocPaths.PACKAGE_TREE);
bpatel@766 148 Content li = HtmlTree.LI(getHyperLink(
jjg@1373 149 link, new StringContent(packages[i].name())));
duke@1 150 if (i < packages.length - 1) {
bpatel@766 151 li.addContent(", ");
duke@1 152 }
bpatel@766 153 ul.addContent(li);
duke@1 154 }
bpatel@766 155 contentTree.addContent(ul);
duke@1 156 }
duke@1 157 }
duke@1 158
duke@1 159 /**
bpatel@766 160 * Get the tree header.
bpatel@766 161 *
bpatel@766 162 * @return a content tree for the tree header
duke@1 163 */
bpatel@766 164 protected Content getTreeHeader() {
bpatel@766 165 String title = configuration.getText("doclet.Window_Class_Hierarchy");
bpatel@766 166 Content bodyTree = getBody(true, getWindowTitle(title));
bpatel@766 167 addTop(bodyTree);
bpatel@766 168 addNavLinks(true, bodyTree);
bpatel@766 169 return bodyTree;
duke@1 170 }
duke@1 171 }

mercurial