duke@1: /*
jjg@1746: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1: *
duke@1: * This code is free software; you can redistribute it and/or modify it
duke@1: * under the terms of the GNU General Public License version 2 only, as
ohair@554: * published by the Free Software Foundation. Oracle designates this
duke@1: * particular file as subject to the "Classpath" exception as provided
ohair@554: * by Oracle in the LICENSE file that accompanied this code.
duke@1: *
duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1: * version 2 for more details (a copy is included in the LICENSE file that
duke@1: * accompanied this code).
duke@1: *
duke@1: * You should have received a copy of the GNU General Public License version
duke@1: * 2 along with this work; if not, write to the Free Software Foundation,
duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1: *
ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554: * or visit www.oracle.com if you need additional information or have any
ohair@554: * questions.
duke@1: */
duke@1:
duke@1: package com.sun.tools.doclets.formats.html;
duke@1:
bpatel@766: import java.io.*;
bpatel@1417: import java.util.*;
jjg@1357:
duke@1: import com.sun.javadoc.*;
jjg@1357: import com.sun.tools.doclets.formats.html.markup.*;
bpatel@766: import com.sun.tools.doclets.internal.toolkit.*;
duke@1: import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1:
duke@1: /**
duke@1: * This abstract class exists to provide functionality needed in the
duke@1: * the formatting of member information. Since AbstractSubWriter and its
duke@1: * subclasses control this, they would be the logical place to put this.
duke@1: * However, because each member type has its own subclass, subclassing
duke@1: * can not be used effectively to change formatting. The concrete
duke@1: * class subclass of this class can be subclassed to change formatting.
duke@1: *
jjg@1359: *
This is NOT part of any supported API.
jjg@1359: * If you write code that depends on this, you do so at your own risk.
jjg@1359: * This code and its internal interfaces are subject to change or
jjg@1359: * deletion without notice.
jjg@1359: *
duke@1: * @see AbstractMemberWriter
duke@1: * @see ClassWriterImpl
duke@1: *
duke@1: * @author Robert Field
duke@1: * @author Atul M Dambalkar
bpatel@243: * @author Bhavesh Patel (Modified)
duke@1: */
duke@1: public abstract class SubWriterHolderWriter extends HtmlDocletWriter {
duke@1:
jjg@1372: public SubWriterHolderWriter(ConfigurationImpl configuration, DocPath filename)
jjg@1372: throws IOException {
duke@1: super(configuration, filename);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Add the summary header.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param cd the classdoc to be documented
bpatel@766: * @param memberTree the content tree to which the summary header will be added
bpatel@766: */
bpatel@766: public void addSummaryHeader(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766: Content memberTree) {
bpatel@766: mw.addSummaryAnchor(cd, memberTree);
bpatel@766: mw.addSummaryLabel(memberTree);
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the summary table.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param cd the classdoc to be documented
bpatel@1417: * @param tableContents list of summary table contents
bpatel@1417: * @param showTabs true if the table needs to show tabs
bpatel@766: * @return the content tree for the summary table
bpatel@766: */
bpatel@1417: public Content getSummaryTableTree(AbstractMemberWriter mw, ClassDoc cd,
bpatel@1417: List tableContents, boolean showTabs) {
bpatel@1417: Content caption;
bpatel@1417: if (showTabs) {
bpatel@1417: caption = getTableCaption(mw.methodTypes);
bpatel@1417: generateMethodTypesScript(mw.typeMap, mw.methodTypes);
bpatel@1417: }
bpatel@1417: else {
bpatel@1417: caption = getTableCaption(mw.getCaption());
bpatel@1417: }
bpatel@766: Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0,
bpatel@1417: mw.getTableSummary(), caption);
bpatel@766: table.addContent(getSummaryTableHeader(mw.getSummaryTableHeader(cd), "col"));
bpatel@1417: for (int i = 0; i < tableContents.size(); i++) {
bpatel@1417: table.addContent(tableContents.get(i));
bpatel@1417: }
bpatel@766: return table;
duke@1: }
duke@1:
bpatel@766: /**
bpatel@1417: * Get the summary table caption.
bpatel@1417: *
bpatel@1417: * @param methodTypes set comprising of method types to show as table caption
bpatel@1417: * @return the caption for the summary table
bpatel@1417: */
bpatel@1417: public Content getTableCaption(Set methodTypes) {
bpatel@1417: Content tabbedCaption = new HtmlTree(HtmlTag.CAPTION);
bpatel@1417: for (MethodTypes type : methodTypes) {
bpatel@1417: Content captionSpan;
bpatel@1417: Content span;
bpatel@1417: if (type.isDefaultTab()) {
bpatel@1417: captionSpan = HtmlTree.SPAN(new StringContent(type.text()));
bpatel@1417: span = HtmlTree.SPAN(type.tabId(),
bpatel@1417: HtmlStyle.activeTableTab, captionSpan);
bpatel@1417: } else {
bpatel@1417: captionSpan = HtmlTree.SPAN(getMethodTypeLinks(type));
bpatel@1417: span = HtmlTree.SPAN(type.tabId(),
bpatel@1417: HtmlStyle.tableTab, captionSpan);
bpatel@1417: }
bpatel@1417: Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, getSpace());
bpatel@1417: span.addContent(tabSpan);
bpatel@1417: tabbedCaption.addContent(span);
bpatel@1417: }
bpatel@1417: return tabbedCaption;
bpatel@1417: }
bpatel@1417:
bpatel@1417: /**
bpatel@1417: * Get the method type links for the table caption.
bpatel@1417: *
bpatel@1417: * @param methodType the method type to be displayed as link
bpatel@1417: * @return the content tree for the method type link
bpatel@1417: */
bpatel@1417: public Content getMethodTypeLinks(MethodTypes methodType) {
jjg@1746: String jsShow = "javascript:show(" + methodType.value() +");";
jjg@1746: HtmlTree link = HtmlTree.A(jsShow, new StringContent(methodType.text()));
bpatel@1417: return link;
bpatel@1417: }
bpatel@1417:
bpatel@1417: /**
bpatel@766: * Add the inherited summary header.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param cd the classdoc to be documented
bpatel@766: * @param inheritedTree the content tree to which the inherited summary header will be added
bpatel@766: */
bpatel@766: public void addInheritedSummaryHeader(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766: Content inheritedTree) {
bpatel@766: mw.addInheritedSummaryAnchor(cd, inheritedTree);
bpatel@766: mw.addInheritedSummaryLabel(cd, inheritedTree);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Add the index comment.
bpatel@766: *
bpatel@766: * @param member the member being documented
bpatel@766: * @param contentTree the content tree to which the comment will be added
bpatel@766: */
bpatel@766: protected void addIndexComment(Doc member, Content contentTree) {
bpatel@766: addIndexComment(member, member.firstSentenceTags(), contentTree);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Add the index comment.
bpatel@766: *
bpatel@766: * @param member the member being documented
bpatel@766: * @param firstSentenceTags the first sentence tags for the member to be documented
bpatel@766: * @param tdSummary the content tree to which the comment will be added
bpatel@766: */
bpatel@766: protected void addIndexComment(Doc member, Tag[] firstSentenceTags,
bpatel@766: Content tdSummary) {
bpatel@766: Tag[] deprs = member.tags("deprecated");
bpatel@766: Content div;
bpatel@766: if (Util.isDeprecated((ProgramElementDoc) member)) {
bpatel@766: Content strong = HtmlTree.STRONG(deprecatedPhrase);
bpatel@766: div = HtmlTree.DIV(HtmlStyle.block, strong);
bpatel@766: div.addContent(getSpace());
bpatel@766: if (deprs.length > 0) {
bpatel@766: addInlineDeprecatedComment(member, deprs[0], div);
bpatel@766: }
bpatel@766: tdSummary.addContent(div);
bpatel@766: return;
bpatel@766: } else {
bpatel@766: ClassDoc cd = ((ProgramElementDoc)member).containingClass();
bpatel@766: if (cd != null && Util.isDeprecated(cd)) {
bpatel@766: Content strong = HtmlTree.STRONG(deprecatedPhrase);
bpatel@766: div = HtmlTree.DIV(HtmlStyle.block, strong);
bpatel@766: div.addContent(getSpace());
bpatel@766: tdSummary.addContent(div);
bpatel@766: }
bpatel@766: }
bpatel@766: addSummaryComment(member, firstSentenceTags, tdSummary);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Add the summary type for the member.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param member the member to be documented
bpatel@766: * @param tdSummaryType the content tree to which the type will be added
bpatel@766: */
bpatel@766: public void addSummaryType(AbstractMemberWriter mw, ProgramElementDoc member,
bpatel@766: Content tdSummaryType) {
bpatel@766: mw.addSummaryType(member, tdSummaryType);
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Add the summary link for the member.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param member the member to be documented
bpatel@766: * @param contentTree the content tree to which the link will be added
bpatel@766: */
bpatel@766: public void addSummaryLinkComment(AbstractMemberWriter mw,
bpatel@766: ProgramElementDoc member, Content contentTree) {
bpatel@766: addSummaryLinkComment(mw, member, member.firstSentenceTags(), contentTree);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Add the summary link comment.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param member the member being documented
bpatel@766: * @param firstSentenceTags the first sentence tags for the member to be documented
bpatel@766: * @param tdSummary the content tree to which the comment will be added
bpatel@766: */
bpatel@766: public void addSummaryLinkComment(AbstractMemberWriter mw,
bpatel@766: ProgramElementDoc member, Tag[] firstSentenceTags, Content tdSummary) {
bpatel@766: addIndexComment(member, firstSentenceTags, tdSummary);
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Add the inherited member summary.
bpatel@766: *
bpatel@766: * @param mw the writer for the member being documented
bpatel@766: * @param cd the class being documented
bpatel@766: * @param member the member being documented
bpatel@766: * @param isFirst true if its the first link being documented
bpatel@766: * @param linksTree the content tree to which the summary will be added
bpatel@766: */
bpatel@766: public void addInheritedMemberSummary(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766: ProgramElementDoc member, boolean isFirst, Content linksTree) {
duke@1: if (! isFirst) {
bpatel@766: linksTree.addContent(", ");
duke@1: }
bpatel@766: mw.addInheritedSummaryLink(cd, member, linksTree);
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Get the document content header tree
bpatel@766: *
bpatel@766: * @return a content tree the document content header
bpatel@766: */
bpatel@766: public Content getContentHeader() {
bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766: div.addStyle(HtmlStyle.contentContainer);
bpatel@766: return div;
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the member header tree
bpatel@766: *
bpatel@766: * @return a content tree the member header
bpatel@766: */
bpatel@766: public Content getMemberTreeHeader() {
bpatel@766: HtmlTree li = new HtmlTree(HtmlTag.LI);
bpatel@766: li.addStyle(HtmlStyle.blockList);
bpatel@766: return li;
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the member tree
bpatel@766: *
bpatel@766: * @param contentTree the tree used to generate the complete member tree
bpatel@766: * @return a content tree for the member
bpatel@766: */
bpatel@766: public Content getMemberTree(Content contentTree) {
bpatel@766: Content ul = HtmlTree.UL(HtmlStyle.blockList, contentTree);
bpatel@766: return ul;
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the member summary tree
bpatel@766: *
bpatel@766: * @param contentTree the tree used to generate the member summary tree
bpatel@766: * @return a content tree for the member summary
bpatel@766: */
bpatel@766: public Content getMemberSummaryTree(Content contentTree) {
bpatel@766: return getMemberTree(HtmlStyle.summary, contentTree);
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the member details tree
bpatel@766: *
bpatel@766: * @param contentTree the tree used to generate the member details tree
bpatel@766: * @return a content tree for the member details
bpatel@766: */
bpatel@766: public Content getMemberDetailsTree(Content contentTree) {
bpatel@766: return getMemberTree(HtmlStyle.details, contentTree);
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Get the member tree
bpatel@766: *
bpatel@766: * @param style the style class to be added to the content tree
bpatel@766: * @param contentTree the tree used to generate the complete member tree
bpatel@766: */
bpatel@766: public Content getMemberTree(HtmlStyle style, Content contentTree) {
bpatel@766: Content div = HtmlTree.DIV(style, getMemberTree(contentTree));
bpatel@766: return div;
bpatel@766: }
duke@1: }