aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.formats.html; aoqi@0: aoqi@0: import java.io.*; aoqi@0: import java.util.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.formats.html.markup.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * This abstract class exists to provide functionality needed in the aoqi@0: * the formatting of member information. Since AbstractSubWriter and its aoqi@0: * subclasses control this, they would be the logical place to put this. aoqi@0: * However, because each member type has its own subclass, subclassing aoqi@0: * can not be used effectively to change formatting. The concrete aoqi@0: * class subclass of this class can be subclassed to change formatting. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @see AbstractMemberWriter aoqi@0: * @see ClassWriterImpl aoqi@0: * aoqi@0: * @author Robert Field aoqi@0: * @author Atul M Dambalkar aoqi@0: * @author Bhavesh Patel (Modified) aoqi@0: */ aoqi@0: public abstract class SubWriterHolderWriter extends HtmlDocletWriter { aoqi@0: aoqi@0: public SubWriterHolderWriter(ConfigurationImpl configuration, DocPath filename) aoqi@0: throws IOException { aoqi@0: super(configuration, filename); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the summary header. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param cd the classdoc to be documented aoqi@0: * @param memberTree the content tree to which the summary header will be added aoqi@0: */ aoqi@0: public void addSummaryHeader(AbstractMemberWriter mw, ClassDoc cd, aoqi@0: Content memberTree) { aoqi@0: mw.addSummaryAnchor(cd, memberTree); aoqi@0: mw.addSummaryLabel(memberTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the summary table. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param cd the classdoc to be documented aoqi@0: * @param tableContents list of summary table contents aoqi@0: * @param showTabs true if the table needs to show tabs aoqi@0: * @return the content tree for the summary table aoqi@0: */ aoqi@0: public Content getSummaryTableTree(AbstractMemberWriter mw, ClassDoc cd, aoqi@0: List tableContents, boolean showTabs) { aoqi@0: Content caption; aoqi@0: if (showTabs) { aoqi@0: caption = getTableCaption(mw.methodTypes); aoqi@0: generateMethodTypesScript(mw.typeMap, mw.methodTypes); aoqi@0: } aoqi@0: else { aoqi@0: caption = getTableCaption(mw.getCaption()); aoqi@0: } aoqi@0: Content table = HtmlTree.TABLE(HtmlStyle.memberSummary, 0, 3, 0, aoqi@0: mw.getTableSummary(), caption); aoqi@0: table.addContent(getSummaryTableHeader(mw.getSummaryTableHeader(cd), "col")); aoqi@0: for (int i = 0; i < tableContents.size(); i++) { aoqi@0: table.addContent(tableContents.get(i)); aoqi@0: } aoqi@0: return table; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the summary table caption. aoqi@0: * aoqi@0: * @param methodTypes set comprising of method types to show as table caption aoqi@0: * @return the caption for the summary table aoqi@0: */ aoqi@0: public Content getTableCaption(Set methodTypes) { aoqi@0: Content tabbedCaption = new HtmlTree(HtmlTag.CAPTION); aoqi@0: for (MethodTypes type : methodTypes) { aoqi@0: Content captionSpan; aoqi@0: Content span; aoqi@0: if (type.isDefaultTab()) { bpatel@2800: captionSpan = HtmlTree.SPAN(configuration.getResource(type.resourceKey())); aoqi@0: span = HtmlTree.SPAN(type.tabId(), aoqi@0: HtmlStyle.activeTableTab, captionSpan); aoqi@0: } else { aoqi@0: captionSpan = HtmlTree.SPAN(getMethodTypeLinks(type)); aoqi@0: span = HtmlTree.SPAN(type.tabId(), aoqi@0: HtmlStyle.tableTab, captionSpan); aoqi@0: } aoqi@0: Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, getSpace()); aoqi@0: span.addContent(tabSpan); aoqi@0: tabbedCaption.addContent(span); aoqi@0: } aoqi@0: return tabbedCaption; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the method type links for the table caption. aoqi@0: * aoqi@0: * @param methodType the method type to be displayed as link aoqi@0: * @return the content tree for the method type link aoqi@0: */ aoqi@0: public Content getMethodTypeLinks(MethodTypes methodType) { aoqi@0: String jsShow = "javascript:show(" + methodType.value() +");"; bpatel@2800: HtmlTree link = HtmlTree.A(jsShow, configuration.getResource(methodType.resourceKey())); aoqi@0: return link; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the inherited summary header. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param cd the classdoc to be documented aoqi@0: * @param inheritedTree the content tree to which the inherited summary header will be added aoqi@0: */ aoqi@0: public void addInheritedSummaryHeader(AbstractMemberWriter mw, ClassDoc cd, aoqi@0: Content inheritedTree) { aoqi@0: mw.addInheritedSummaryAnchor(cd, inheritedTree); aoqi@0: mw.addInheritedSummaryLabel(cd, inheritedTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the index comment. aoqi@0: * aoqi@0: * @param member the member being documented aoqi@0: * @param contentTree the content tree to which the comment will be added aoqi@0: */ aoqi@0: protected void addIndexComment(Doc member, Content contentTree) { aoqi@0: addIndexComment(member, member.firstSentenceTags(), contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the index comment. aoqi@0: * aoqi@0: * @param member the member being documented aoqi@0: * @param firstSentenceTags the first sentence tags for the member to be documented aoqi@0: * @param tdSummary the content tree to which the comment will be added aoqi@0: */ aoqi@0: protected void addIndexComment(Doc member, Tag[] firstSentenceTags, aoqi@0: Content tdSummary) { aoqi@0: Tag[] deprs = member.tags("deprecated"); aoqi@0: Content div; aoqi@0: if (Util.isDeprecated((ProgramElementDoc) member)) { aoqi@0: Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase); aoqi@0: div = HtmlTree.DIV(HtmlStyle.block, deprLabel); aoqi@0: div.addContent(getSpace()); aoqi@0: if (deprs.length > 0) { aoqi@0: addInlineDeprecatedComment(member, deprs[0], div); aoqi@0: } aoqi@0: tdSummary.addContent(div); aoqi@0: return; aoqi@0: } else { aoqi@0: ClassDoc cd = ((ProgramElementDoc)member).containingClass(); aoqi@0: if (cd != null && Util.isDeprecated(cd)) { aoqi@0: Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase); aoqi@0: div = HtmlTree.DIV(HtmlStyle.block, deprLabel); aoqi@0: div.addContent(getSpace()); aoqi@0: tdSummary.addContent(div); aoqi@0: } aoqi@0: } aoqi@0: addSummaryComment(member, firstSentenceTags, tdSummary); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the summary type for the member. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param member the member to be documented aoqi@0: * @param tdSummaryType the content tree to which the type will be added aoqi@0: */ aoqi@0: public void addSummaryType(AbstractMemberWriter mw, ProgramElementDoc member, aoqi@0: Content tdSummaryType) { aoqi@0: mw.addSummaryType(member, tdSummaryType); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the summary link for the member. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param member the member to be documented aoqi@0: * @param contentTree the content tree to which the link will be added aoqi@0: */ aoqi@0: public void addSummaryLinkComment(AbstractMemberWriter mw, aoqi@0: ProgramElementDoc member, Content contentTree) { aoqi@0: addSummaryLinkComment(mw, member, member.firstSentenceTags(), contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the summary link comment. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param member the member being documented aoqi@0: * @param firstSentenceTags the first sentence tags for the member to be documented aoqi@0: * @param tdSummary the content tree to which the comment will be added aoqi@0: */ aoqi@0: public void addSummaryLinkComment(AbstractMemberWriter mw, aoqi@0: ProgramElementDoc member, Tag[] firstSentenceTags, Content tdSummary) { aoqi@0: addIndexComment(member, firstSentenceTags, tdSummary); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the inherited member summary. aoqi@0: * aoqi@0: * @param mw the writer for the member being documented aoqi@0: * @param cd the class being documented aoqi@0: * @param member the member being documented aoqi@0: * @param isFirst true if its the first link being documented aoqi@0: * @param linksTree the content tree to which the summary will be added aoqi@0: */ aoqi@0: public void addInheritedMemberSummary(AbstractMemberWriter mw, ClassDoc cd, aoqi@0: ProgramElementDoc member, boolean isFirst, Content linksTree) { aoqi@0: if (! isFirst) { aoqi@0: linksTree.addContent(", "); aoqi@0: } aoqi@0: mw.addInheritedSummaryLink(cd, member, linksTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the document content header tree aoqi@0: * aoqi@0: * @return a content tree the document content header aoqi@0: */ aoqi@0: public Content getContentHeader() { aoqi@0: HtmlTree div = new HtmlTree(HtmlTag.DIV); aoqi@0: div.addStyle(HtmlStyle.contentContainer); aoqi@0: return div; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the member header tree aoqi@0: * aoqi@0: * @return a content tree the member header aoqi@0: */ aoqi@0: public Content getMemberTreeHeader() { aoqi@0: HtmlTree li = new HtmlTree(HtmlTag.LI); aoqi@0: li.addStyle(HtmlStyle.blockList); aoqi@0: return li; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the member tree aoqi@0: * aoqi@0: * @param contentTree the tree used to generate the complete member tree aoqi@0: * @return a content tree for the member aoqi@0: */ aoqi@0: public Content getMemberTree(Content contentTree) { aoqi@0: Content ul = HtmlTree.UL(HtmlStyle.blockList, contentTree); aoqi@0: return ul; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the member summary tree aoqi@0: * aoqi@0: * @param contentTree the tree used to generate the member summary tree aoqi@0: * @return a content tree for the member summary aoqi@0: */ aoqi@0: public Content getMemberSummaryTree(Content contentTree) { aoqi@0: return getMemberTree(HtmlStyle.summary, contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the member details tree aoqi@0: * aoqi@0: * @param contentTree the tree used to generate the member details tree aoqi@0: * @return a content tree for the member details aoqi@0: */ aoqi@0: public Content getMemberDetailsTree(Content contentTree) { aoqi@0: return getMemberTree(HtmlStyle.details, contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the member tree aoqi@0: * aoqi@0: * @param style the style class to be added to the content tree aoqi@0: * @param contentTree the tree used to generate the complete member tree aoqi@0: */ aoqi@0: public Content getMemberTree(HtmlStyle style, Content contentTree) { aoqi@0: Content div = HtmlTree.DIV(style, getMemberTree(contentTree)); aoqi@0: return div; aoqi@0: } aoqi@0: }