001    /*
002     * Copyright 1998-2003 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.util.*;
029    import com.sun.javadoc.*;
030    import java.io.*;
031    import java.util.*;
032    
033    /**
034     * Generate the file with list of all the classes in this run. This page will be
035     * used in the left-hand bottom frame, when "All Classes" link is clicked in
036     * the left-hand top frame. The name of the generated file is
037     * "allclasses-frame.html".
038     *
039     * @author Atul M Dambalkar
040     * @author Doug Kramer
041     */
042    public class AllClassesFrameWriter extends HtmlDocletWriter {
043    
044        /**
045         * The name of the output file with frames
046         */
047        public static final String OUTPUT_FILE_NAME_FRAMES = "allclasses-frame.html";
048    
049        /**
050         * The name of the output file without frames
051         */
052        public static final String OUTPUT_FILE_NAME_NOFRAMES = "allclasses-noframe.html";
053    
054        /**
055         * Index of all the classes.
056         */
057        protected IndexBuilder indexbuilder;
058    
059        /**
060         * Construct AllClassesFrameWriter object. Also initilises the indexbuilder
061         * variable in this class.
062         * @throws IOException
063         * @throws DocletAbortException
064         */
065        public AllClassesFrameWriter(ConfigurationImpl configuration,
066                                     String filename, IndexBuilder indexbuilder)
067                                  throws IOException {
068            super(configuration, filename);
069            this.indexbuilder = indexbuilder;
070        }
071    
072        /**
073         * Create AllClassesFrameWriter object. Then use it to generate the
074         * "allclasses-frame.html" file. Generate the file in the current or the
075         * destination directory.
076         *
077         * @param indexbuilder IndexBuilder object for all classes index.
078         * @throws DocletAbortException
079         */
080        public static void generate(ConfigurationImpl configuration,
081                                    IndexBuilder indexbuilder) {
082            AllClassesFrameWriter allclassgen;
083            String filename = OUTPUT_FILE_NAME_FRAMES;
084            try {
085                allclassgen = new AllClassesFrameWriter(configuration,
086                                                        filename, indexbuilder);
087                allclassgen.generateAllClassesFile(true);
088                allclassgen.close();
089                filename = OUTPUT_FILE_NAME_NOFRAMES;
090                allclassgen = new AllClassesFrameWriter(configuration,
091                                                        filename, indexbuilder);
092                allclassgen.generateAllClassesFile(false);
093                allclassgen.close();
094            } catch (IOException exc) {
095                configuration.standardmessage.
096                         error("doclet.exception_encountered",
097                               exc.toString(), filename);
098                throw new DocletAbortException();
099            }
100        }
101    
102        /**
103         * Print all the classes in table format in the file.
104         * @param wantFrames True if we want frames.
105         */
106        protected void generateAllClassesFile(boolean wantFrames) throws IOException {
107            String label = configuration.getText("doclet.All_Classes");
108    
109            printHtmlHeader(label, null, false);
110    
111            printAllClassesTableHeader();
112            printAllClasses(wantFrames);
113            printAllClassesTableFooter();
114    
115            printBodyHtmlEnd();
116        }
117    
118        /**
119         * Use the sorted index of all the classes and print all the classes.
120         *
121         * @param wantFrames True if we want frames.
122         */
123        protected void printAllClasses(boolean wantFrames) {
124            for (int i = 0; i < indexbuilder.elements().length; i++) {
125                Character unicode = (Character)((indexbuilder.elements())[i]);
126                generateContents(indexbuilder.getMemberList(unicode), wantFrames);
127            }
128        }
129    
130        /**
131         * Given a list of classes, generate links for each class or interface.
132         * If the class kind is interface, print it in the italics font. Also all
133         * links should target the right-hand frame. If clicked on any class name
134         * in this page, appropriate class page should get opened in the right-hand
135         * frame.
136         *
137         * @param classlist Sorted list of classes.
138         * @param wantFrames True if we want frames.
139         */
140        protected void generateContents(List<Doc> classlist, boolean wantFrames) {
141            for (int i = 0; i < classlist.size(); i++) {
142                ClassDoc cd = (ClassDoc)classlist.get(i);
143                if (!Util.isCoreClass(cd)) {
144                    continue;
145                }
146                String label = italicsClassName(cd, false);
147                if(wantFrames){
148                    printLink(new LinkInfoImpl(LinkInfoImpl.ALL_CLASSES_FRAME, cd,
149                        label, "classFrame")
150                    );
151                } else {
152                    printLink(new LinkInfoImpl(cd, label));
153                }
154                br();
155            }
156        }
157    
158        /**
159         * Print the heading "All Classes" and also print Html table tag.
160         */
161        protected void printAllClassesTableHeader() {
162            fontSizeStyle("+1", "FrameHeadingFont");
163            strongText("doclet.All_Classes");
164            fontEnd();
165            br();
166            table();
167            tr();
168            tdNowrap();
169            fontStyle("FrameItemFont");
170        }
171    
172        /**
173         * Print Html closing table tag.
174         */
175        protected void printAllClassesTableFooter() {
176            fontEnd();
177            tdEnd();
178            trEnd();
179            tableEnd();
180        }
181    }