001: /*
002: * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html;
027:
028: import com.sun.tools.doclets.internal.toolkit.*;
029: import com.sun.tools.doclets.internal.toolkit.util.*;
030: import com.sun.javadoc.*;
031: import java.io.*;
032: import java.util.*;
033:
034: /**
035: * Write the Constants Summary Page in HTML format.
036: *
037: * @author Jamie Ho
038: * @since 1.4
039: */
040: public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
041: implements ConstantsSummaryWriter {
042:
043: /**
044: * The configuration used in this run of the standard doclet.
045: */
046: ConfigurationImpl configuration;
047:
048: /**
049: * The current class being documented.
050: */
051: private ClassDoc currentClassDoc;
052:
053: /**
054: * Construct a ConstantsSummaryWriter.
055: * @param configuration the configuration used in this run
056: * of the standard doclet.
057: */
058: public ConstantsSummaryWriterImpl(ConfigurationImpl configuration)
059: throws IOException {
060: super (configuration, ConfigurationImpl.CONSTANTS_FILE_NAME);
061: this .configuration = configuration;
062: }
063:
064: /**
065: * {@inheritDoc}
066: */
067: public void writeHeader() {
068: printHtmlHeader(configuration
069: .getText("doclet.Constants_Summary"), null, true);
070: printTop();
071: navLinks(true);
072: hr();
073:
074: center();
075: h1();
076: printText("doclet.Constants_Summary");
077: h1End();
078: centerEnd();
079:
080: hr(4, "noshade");
081: }
082:
083: /**
084: * {@inheritDoc}
085: */
086: public void writeFooter() {
087: hr();
088: navLinks(false);
089: printBottom();
090: printBodyHtmlEnd();
091: }
092:
093: /**
094: * {@inheritDoc}
095: */
096: public void writeContentsHeader() {
097: bold(configuration.getText("doclet.Contents"));
098: ul();
099: }
100:
101: /**
102: * {@inheritDoc}
103: */
104: public void writeContentsFooter() {
105: ulEnd();
106: println();
107: }
108:
109: /**
110: * {@inheritDoc}
111: */
112: public void writeLinkToPackageContent(PackageDoc pkg,
113: String parsedPackageName, Set printedPackageHeaders) {
114: String packageName = pkg.name();
115: //add link to summary
116: li();
117: if (packageName.length() == 0) {
118: printHyperLink(
119: "#" + DocletConstants.UNNAMED_PACKAGE_ANCHOR,
120: DocletConstants.DEFAULT_PACKAGE_NAME);
121: } else {
122: printHyperLink("#" + parsedPackageName, parsedPackageName
123: + ".*");
124: printedPackageHeaders.add(parsedPackageName);
125: }
126: println();
127: }
128:
129: /**
130: * {@inheritDoc}
131: */
132: public void writeConstantMembersHeader(ClassDoc cd) {
133: //generate links backward only to public classes.
134: String classlink = (cd.isPublic() || cd.isProtected()) ? getLink(new LinkInfoImpl(
135: LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, cd, false))
136: : cd.qualifiedName();
137: String name = cd.containingPackage().name();
138: if (name.length() > 0) {
139: writeClassName(name + "." + classlink);
140: } else {
141: writeClassName(classlink);
142: }
143: }
144:
145: /**
146: * {@inheritDoc}
147: */
148: public void writeConstantMembersFooter(ClassDoc cd) {
149: tableFooter(false);
150: p();
151: }
152:
153: /**
154: * Print the class name in the table heading.
155: * @param classStr the heading to print.
156: */
157: protected void writeClassName(String classStr) {
158: table(1, 3, 0);
159: trBgcolorStyle("#EEEEFF", "TableSubHeadingColor");
160: thAlignColspan("left", 3);
161: write(classStr);
162: thEnd();
163: trEnd();
164: }
165:
166: private void tableFooter(boolean isHeader) {
167: fontEnd();
168: if (isHeader) {
169: thEnd();
170: } else {
171: tdEnd();
172: }
173: trEnd();
174: tableEnd();
175: p();
176: }
177:
178: /**
179: * {@inheritDoc}
180: */
181: public void writePackageName(PackageDoc pkg,
182: String parsedPackageName) {
183: String pkgname;
184: if (parsedPackageName.length() == 0) {
185: anchor(DocletConstants.UNNAMED_PACKAGE_ANCHOR);
186: pkgname = DocletConstants.DEFAULT_PACKAGE_NAME;
187: } else {
188: anchor(parsedPackageName);
189: pkgname = parsedPackageName;
190: }
191: table(1, "100%", 3, 0);
192: trBgcolorStyle("#CCCCFF", "TableHeadingColor");
193: thAlign("left");
194: font("+2");
195: write(pkgname + ".*");
196: tableFooter(true);
197: }
198:
199: /**
200: * {@inheritDoc}
201: */
202: public void writeConstantMembers(ClassDoc cd, List fields) {
203: currentClassDoc = cd;
204: for (int i = 0; i < fields.size(); ++i) {
205: writeConstantMember((FieldDoc) (fields.get(i)));
206: }
207: }
208:
209: private void writeConstantMember(FieldDoc member) {
210: trBgcolorStyle("white", "TableRowColor");
211: anchor(currentClassDoc.qualifiedName() + "." + member.name());
212: writeTypeColumn(member);
213: writeNameColumn(member);
214: writeValue(member);
215: trEnd();
216: }
217:
218: private void writeTypeColumn(FieldDoc member) {
219: tdAlign("right");
220: font("-1");
221: code();
222: StringTokenizer mods = new StringTokenizer(member.modifiers());
223: while (mods.hasMoreTokens()) {
224: print(mods.nextToken() + " ");
225: }
226: printLink(new LinkInfoImpl(
227: LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member.type()));
228: codeEnd();
229: fontEnd();
230: tdEnd();
231: }
232:
233: private void writeNameColumn(FieldDoc member) {
234: tdAlign("left");
235: code();
236: printDocLink(LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member,
237: member.name(), false);
238: codeEnd();
239: tdEnd();
240: }
241:
242: private void writeValue(FieldDoc member) {
243: tdAlign("right");
244: code();
245: print(Util.escapeHtmlChars(member.constantValueExpression()));
246: codeEnd();
247: tdEnd();
248: }
249: }
|