Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

In this page you can find the example usage for com.lowagie.text Chunk Chunk.

Prototype

public Chunk(DrawInterface separator, float tabPosition) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:org.areasy.common.doclet.Doclet.java

License:Open Source License

/**
 * Processes one Java package of the whole API.
 *
 * @param packageDoc The javadoc information for the package.
 * @throws Exception/*  w  w w . j  av a2 s .co m*/
 */
private void printPackage(PackageDoc packageDoc, ClassDoc[] packageClasses) throws Exception {
    State.setCurrentPackage(packageDoc.name());
    State.setCurrentDoc(packageDoc);

    Document.newPage();

    String packageName = State.getCurrentPackage();

    // Text "package"
    State.setCurrentClass("");

    Paragraph label = new Paragraph((float) 22.0, LB_PACKAGE, Fonts.getFont(TEXT_FONT, BOLD, 18));
    Document.add(label);

    Paragraph titlePara = new Paragraph((float) 30.0, "");
    // Name of the package (large font)
    Chunk titleChunk = new Chunk(packageName, Fonts.getFont(TEXT_FONT, BOLD, 30));
    titleChunk.setLocalDestination(packageName);
    if (State.getCurrentFile() != null) {
        String packageAnchor = Destinations.createAnchorDestination(State.getCurrentFile(), null);
        titlePara.add(PDFUtility.createAnchor(packageAnchor, titleChunk.font()));
    }

    titlePara.add(titleChunk);
    Document.add(titlePara);

    // Some empty space
    Document.add(new Paragraph((float) 20.0, " "));

    State.setContinued(true);

    String packageText = DocletUtility.getComment(packageDoc);
    Element[] objs = HtmlParserWrapper.createPdfObjects(packageText);

    if (objs.length == 0) {
        String packageDesc = DocletUtility.stripLineFeeds(packageText);
        Document.add(new Paragraph((float) 11.0, packageDesc, Fonts.getFont(TEXT_FONT, 10)));
    } else
        PDFUtility.printPdfElements(objs);

    State.setContinued(false);

    State.increasePackageSection();

    printClasses(DocletUtility.sort(packageClasses), packageDoc);
}

From source file:org.areasy.common.doclet.document.Appendices.java

License:Open Source License

private static void printAppendix(AppendixInfo info, BookmarkEntry entry) throws Exception {

    File file = info.file;/*from  w  w w .j a  v  a  2  s.  com*/
    State.setCurrentDoc(null);
    State.setCurrentPackage(null);
    State.setCurrentFile(file);
    State.increasePackageChapter();
    State.setCurrentHeaderType(HEADER_APPENDIX);
    State.setContinued(false);
    String label = DefaultConfiguration.getString(ARG_LB_APPENDIX, LB_APPENDIX);
    String fullTitle = label + " " + info.name;
    if (info.title != null)
        fullTitle += ": " + info.title;

    Document.newPage();
    State.setContinued(true);
    State.setCurrentClass(fullTitle);
    String appendixAnchor = Destinations.createAnchorDestination(file, null);
    Bookmarks.addSubBookmark(entry, fullTitle, appendixAnchor);

    if (file.getName().toLowerCase().endsWith(".pdf")) {
        Chunk anchorChunk = PDFUtility.createAnchor(appendixAnchor);
        Document.instance().add(anchorChunk);
        PDFUtility.insertPdfPages(file, info.pages);
    } else {
        String html = DocletUtility.getHTMLBodyContentFromFile(file);
        Chunk titleChunk = new Chunk(fullTitle, Fonts.getFont(TEXT_FONT, BOLD, 22));
        titleChunk.setLocalDestination(appendixAnchor);
        Paragraph titleParagraph = new Paragraph((float) 22.0, titleChunk);
        Document.add(titleParagraph);

        Element[] objs = HtmlParserWrapper.createPdfObjects(html);
        PDFUtility.printPdfElements(objs);
    }

    State.setContinued(false);
    State.setCurrentFile(null);
}

From source file:org.areasy.common.doclet.document.Classes.java

License:Open Source License

/**
 * Prints javadoc of one given class.//from  ww  w  . ja v  a 2 s  . c  o m
 *
 * @param classDoc   The javadoc information about the class.
 * @param packageDoc The package which the class is part of.
 * @throws Exception
 */
public static void printClass(ClassDoc classDoc, PackageDoc packageDoc) throws Exception {
    Document.newPage();
    State.increasePackageSection();

    State.setCurrentClass(classDoc.qualifiedName());
    State.setCurrentDoc(classDoc);
    log.info("..> " + State.getCurrentClass());

    // Simulate javadoc HTML layout package (small) and class (large) name header
    Paragraph namePara = new Paragraph(packageDoc.name(), Fonts.getFont(TEXT_FONT, BOLD, 16));
    Document.add(namePara);

    Phrase linkPhrase = null;
    if (!classDoc.isInterface()) {
        linkPhrase = Destinations.createDestination("Class " + classDoc.name(), classDoc,
                Fonts.getFont(TEXT_FONT, BOLD, 16));
    } else {
        linkPhrase = Destinations.createDestination("Interface " + classDoc.name(), classDoc,
                Fonts.getFont(TEXT_FONT, BOLD, 16));
    }

    Paragraph titlePara = new Paragraph((float) 16.0, "");
    String classFileAnchor = Destinations.createAnchorDestination(State.getCurrentFile(), null);
    titlePara.add(PDFUtility.createAnchor(classFileAnchor, titlePara.font()));
    titlePara.add(linkPhrase);

    Document.instance().add(titlePara);

    // class derivation tree - build list first
    Hashtable list = new Hashtable();
    ClassDoc currentTreeClass = classDoc;
    ClassDoc superClass = null;
    ClassDoc subClass = null;

    Vector interfacesList = new Vector();

    while ((superClass = currentTreeClass.superclass()) != null) {
        if (!classDoc.isInterface()) {
            // Store interfaces implemented by superclasses
            // because the current class also implements all
            // interfaces of its superclass (by inheritance)
            ClassDoc[] interfaces = superClass.interfaces();

            for (int u = 0; u < interfaces.length; u++) {
                interfacesList.addElement(interfaces[u]);
            }
        }

        list.put(superClass, currentTreeClass);
        currentTreeClass = superClass;
    }

    // First line of derivation tree must NOT be printed, if it's
    // the only line, and it's an interface (not a class). This is
    // because a class ALWAYS has a superclass (if only java.lang.Object),
    // but an interface does not necessarily have a super instance.
    boolean firstLine = true;

    if (classDoc.isInterface() && (list.get(currentTreeClass) == null)) {
        firstLine = false;
    }

    // top-level-class
    String blanks = "";

    if (firstLine) {
        Document.add(new Paragraph((float) 24.0, currentTreeClass.qualifiedTypeName(),
                Fonts.getFont(CODE_FONT, 10)));
    }

    while ((subClass = (ClassDoc) list.get(currentTreeClass)) != null) {
        blanks = blanks + "   ";
        Document.add(new Paragraph((float) 10.0, blanks + "|", Fonts.getFont(CODE_FONT, 10)));

        if (list.get(subClass) == null) {
            // it's last in list, so use bold font
            Document.add(new Paragraph((float) 8.0, blanks + "+-" + subClass.qualifiedTypeName(),
                    Fonts.getFont(CODE_FONT, BOLD, 10)));
        } else {
            // If it's not last, it's a superclass. Create link to
            // it, if it's in same API.
            Paragraph newLine = new Paragraph((float) 8.0);
            newLine.add(new Chunk(blanks + "+-", Fonts.getFont(CODE_FONT, 10)));
            newLine.add(new LinkPhrase(subClass.qualifiedTypeName(), null, 10, false));
            Document.add(newLine);
        }

        currentTreeClass = subClass;
    }

    ClassDoc[] interfaces = classDoc.interfaces();

    // Now, for classes only, print implemented interfaces
    // and known subclasses
    if (!classDoc.isInterface()) {
        // List All Implemented Interfaces
        if ((interfaces != null) && (interfaces.length > 0)) {
            for (int i = 0; i < interfaces.length; i++) {
                interfacesList.addElement(interfaces[i]);
            }
        }

        String[] interfacesNames = new String[interfacesList.size()];
        for (int i = 0; i < interfacesNames.length; i++) {
            interfacesNames[i] = ((ClassDoc) interfacesList.elementAt(i)).qualifiedTypeName();
        }
        if (interfacesNames.length > 0) {
            Implementors.print("All Implemented Interfaces:", interfacesNames);
        }

        // Known subclasses
        String[] knownSubclasses = ImplementorsInformation.getDirectSubclasses(State.getCurrentClass());

        if ((knownSubclasses != null) && (knownSubclasses.length > 0)) {
            Implementors.print("Direct Known Subclasses:", knownSubclasses);
        }
    } else {
        // For interfaces, print superinterfaces and all subinterfaces
        // Known super-interfaces
        String[] knownSuperInterfaces = ImplementorsInformation.getKnownSuperclasses(State.getCurrentClass());

        if ((knownSuperInterfaces != null) && (knownSuperInterfaces.length > 0)) {
            Implementors.print("All Superinterfaces:", knownSuperInterfaces);
        }

        // Known sub-interfaces
        String[] knownSubInterfaces = ImplementorsInformation.getKnownSubclasses(State.getCurrentClass());

        if ((knownSubInterfaces != null) && (knownSubInterfaces.length > 0)) {
            Implementors.print("All Subinterfaces:", knownSubInterfaces);
        }

        // Known Implementing Classes
        String[] knownImplementingClasses = ImplementorsInformation
                .getImplementingClasses(State.getCurrentClass());

        if ((knownImplementingClasses != null) && (knownImplementingClasses.length > 0)) {
            Implementors.print("All Known Implementing Classes:", knownImplementingClasses);
        }
    }

    // Horizontal line
    PDFUtility.printLine();

    // Class type / declaration
    String info = "";

    Tag[] deprecatedTags = classDoc.tags(DOC_TAGS_DEPRECATED);

    if (deprecatedTags.length > 0) {
        Paragraph classDeprecatedParagraph = new Paragraph((float) 20);

        Chunk deprecatedClassText = new Chunk(LB_DEPRECATED_TAG, Fonts.getFont(TEXT_FONT, BOLD, 12));
        classDeprecatedParagraph.add(deprecatedClassText);

        String depText = DocletUtility.getComment(deprecatedTags[0].inlineTags());
        Element[] deprecatedInfoText = HtmlParserWrapper.createPdfObjects("<i>" + depText + "</i>");
        for (int n = 0; n < deprecatedInfoText.length; n++) {
            // Only phrases can be supported here (but no tables)
            if (deprecatedInfoText[n] instanceof Phrase) {
                classDeprecatedParagraph.add(deprecatedInfoText[n]);
            }
        }

        Document.add(classDeprecatedParagraph);
    }

    info = DocletUtility.getClassModifiers(classDoc);

    Paragraph infoParagraph = new Paragraph((float) 20, info, Fonts.getFont(TEXT_FONT, 12));
    infoParagraph.add(new Chunk(classDoc.name(), Fonts.getFont(TEXT_FONT, BOLD, 12)));
    Document.add(infoParagraph);

    // extends ...
    ClassDoc superClassOrInterface = null;

    if (classDoc.isInterface()) {
        ClassDoc[] superInterfaces = classDoc.interfaces();

        if (superInterfaces.length > 0) {
            superClassOrInterface = superInterfaces[0];
        }
    } else {
        superClassOrInterface = classDoc.superclass();
    }

    if (superClassOrInterface != null) {
        Paragraph extendsPara = new Paragraph((float) 14.0);
        extendsPara.add(new Chunk("extends ", Fonts.getFont(TEXT_FONT, 12)));

        String superClassName = DocletUtility.getQualifiedNameIfNecessary(superClassOrInterface);
        extendsPara.add(new LinkPhrase(superClassOrInterface.qualifiedName(), superClassName, 12, true));

        Document.add(extendsPara);
    }

    if (!classDoc.isInterface()) {
        //implements
        if ((interfaces != null) && (interfaces.length > 0)) {
            String[] interfacesNames = new String[interfacesList.size()];

            for (int i = 0; i < interfacesNames.length; i++) {
                interfacesNames[i] = ((ClassDoc) interfacesList.elementAt(i)).qualifiedTypeName();
            }

            Paragraph extendsPara = new Paragraph((float) 14.0);
            extendsPara.add(new Chunk("implements ", Fonts.getFont(TEXT_FONT, 12)));

            Paragraph descPg = new Paragraph((float) 24.0);

            for (int i = 0; i < interfacesNames.length; i++) {
                String subclassName = DocletUtility.getQualifiedNameIfNecessary(interfacesNames[i]);
                Phrase subclassPhrase = new LinkPhrase(interfacesNames[i], subclassName, 12, true);
                descPg.add(subclassPhrase);

                if (i < (interfacesNames.length - 1)) {
                    descPg.add(new Chunk(", ", Fonts.getFont(CODE_FONT, 10)));
                }
            }

            extendsPara.add(descPg);

            Document.add(extendsPara);
        }
    }

    Document.add(new Paragraph((float) 20.0, " "));

    // Description
    String classText = DocletUtility.getComment(classDoc);
    Element[] objs = HtmlParserWrapper.createPdfObjects(classText);

    if (objs.length == 0) {
        String desc = DocletUtility.stripLineFeeds(classText);
        Document.add(new Paragraph((float) 14.0, desc, Fonts.getFont(TEXT_FONT, 12)));
    } else {
        PDFUtility.printPdfElements(objs);
    }

    TagLists.printClassTags(classDoc);
    // Horizontal line
    PDFUtility.printLine();

    if (DefaultConfiguration.isShowSummaryActive()) {
        Summary.printAll(classDoc);
        PDFUtility.printLine();
    }

    float[] widths = { (float) 1.0, (float) 94.0 };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage((float) 100);

    // Some empty space...
    Document.add(new Paragraph((float) 6.0, " "));
    Members.printMembers(classDoc);
}

From source file:org.areasy.common.doclet.document.CustomTitle.java

License:Open Source License

/**
 * Prints the title page.//from www.  j  a v  a 2  s .co m
 *
 * @throws Exception
 */
public void print() throws Exception {
    String apiTitlePageProp = DefaultConfiguration.getString(ARG_DOC_TITLE_PAGE, ARG_VAL_NO).toLowerCase();

    if (apiTitlePageProp.equalsIgnoreCase(ARG_VAL_YES)) {
        String apiFileProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_TITLE_FILE, "");

        // If the (pdf) filename contains page information, remove it,
        // because for the title page only 1 page can be imported
        if (apiFileProp.indexOf(",") != -1)
            apiFileProp = apiFileProp.substring(0, apiFileProp.indexOf(","));

        String labelTitle = DefaultConfiguration.getString(ARG_LB_OUTLINE_TITLE, LB_TITLE);
        String titleDest = "TITLEPAGE:";

        if (apiFileProp.length() > 0) {
            File apiFile = new File(DefaultConfiguration.getWorkDir(), apiFileProp);

            if (apiFile.exists() && apiFile.isFile()) {
                Destinations.addValidDestinationFile(apiFile);
                State.setCurrentFile(apiFile);

                pdfDocument.newPage();
                pdfDocument.add(PDFUtility.createAnchor(titleDest));
                Bookmarks.addRootBookmark(labelTitle, titleDest);

                if (apiFile.getName().toLowerCase().endsWith(".pdf")) {
                    PDFUtility.insertPdfPages(apiFile, "1");
                } else {
                    String html = DocletUtility.getHTMLBodyContentFromFile(apiFile);
                    Element[] objs = HtmlParserWrapper.createPdfObjects(html);
                    PDFUtility.printPdfElements(objs);
                }
            } else
                log.error("Title page file not found or invalid: " + apiFileProp);
        } else {
            String apiTitleProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_TITLE, "");
            String apiCopyrightProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_COPYRIGHT, "");
            String apiAuthorProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_AUTHOR, "");
            String apiVersionProp = DefaultConfiguration.getConfiguration().getString(ARG_DOC_VERSION, "");

            if (apiVersionProp != null && apiVersionProp.length() > 0)
                apiVersionProp = "Version " + apiVersionProp;

            pdfDocument.newPage();
            pdfDocument.add(PDFUtility.createAnchor(titleDest));
            Bookmarks.addRootBookmark(labelTitle, titleDest);

            Paragraph p1 = new Paragraph((float) 100.0,
                    new Chunk(apiTitleProp, Fonts.getFont(TEXT_FONT, BOLD, 42)));
            Paragraph p2 = new Paragraph((float) 140.0,
                    new Chunk(apiAuthorProp, Fonts.getFont(TEXT_FONT, BOLD, 18)));
            Paragraph p3 = new Paragraph((float) 20.0,
                    new Chunk(apiCopyrightProp, Fonts.getFont(TEXT_FONT, 12)));
            Paragraph p4 = new Paragraph((float) 20.0,
                    new Chunk(apiVersionProp, Fonts.getFont(TEXT_FONT, BOLD, 12)));

            p1.setAlignment(Element.ALIGN_CENTER);
            p2.setAlignment(Element.ALIGN_CENTER);
            p3.setAlignment(Element.ALIGN_CENTER);
            p4.setAlignment(Element.ALIGN_CENTER);

            pdfDocument.add(p1);
            pdfDocument.add(p2);
            pdfDocument.add(p3);
            pdfDocument.add(p4);
        }
    }
}

From source file:org.areasy.common.doclet.document.Destinations.java

License:Open Source License

/**
 * Creates a destination in the document. This method
 * does nothing if the given destination is invalid.
 * <p/>/*w  w  w . jav  a2s.  c om*/
 * This method creates a phrase with one or two empty chunks
 * who only serve as holders for the destinations.
 *
 * @param label The label for the destination.
 * @param doc   The javadoc element for which to create a destination.
 * @param font  The font for the label.
 * @return The Phrase with the destination in it.
 */
public static Phrase createDestination(String label, ProgramElementDoc doc, Font font) {
    boolean multiPart = false;
    Chunk chunk = null;
    boolean canHaveParms = false;

    if (doc instanceof ConstructorDoc || doc instanceof MethodDoc)
        canHaveParms = true;

    if (canHaveParms)
        multiPart = true;

    chunk = new Chunk(label, font);
    Phrase phrase = new Phrase(chunk);

    String destination = doc.qualifiedName();
    phrase.add(PDFUtility.createAnchor(destination));

    if (multiPart) {
        ExecutableMemberDoc execDoc = (ExecutableMemberDoc) doc;
        String destinationTwo = destination + "()";
        phrase.add(PDFUtility.createAnchor(destinationTwo));

        String destinationThree = destination + execDoc.signature();
        phrase.add(PDFUtility.createAnchor(destinationThree));

        String destinationFour = destination + execDoc.flatSignature();
        phrase.add(PDFUtility.createAnchor(destinationFour));
    }

    return phrase;
}

From source file:org.areasy.common.doclet.document.elements.CustomTagParagraph.java

License:Open Source License

/**
 * Creates a paragraph of PDF phrases for the given tag text.
 *
 * @param isKeyValue if the text starts with a key name, e.g., the param tag.
 * @param text       the text of the tag (starting with the key word, if any).
 *///w  w  w. j  a  v a 2s .  co m
public CustomTagParagraph(boolean isKeyValue, String text) {
    super((float) 11.0);
    text = DocletUtility.stripLineFeeds(text).trim();

    if (isKeyValue) {
        int firstWhiteSpaceIndex = text.indexOf(" ");
        int firstTabIndex = text.indexOf("\t");

        if (firstTabIndex != -1) {
            if ((firstWhiteSpaceIndex == -1) || (firstTabIndex < firstWhiteSpaceIndex)) {
                firstWhiteSpaceIndex = firstTabIndex;
            }
        }

        if (firstWhiteSpaceIndex != -1) {
            // Parameter or exception with explanation
            String key = text.substring(0, firstWhiteSpaceIndex).trim();
            text = text.substring(firstWhiteSpaceIndex, text.length()).trim();

            Chunk keyChunk = new Chunk(key + " - ", Fonts.getFont(CODE_FONT, 10));
            super.add(keyChunk);
        } else {
            // Parameter or exception without explanation
            Chunk keyChunk = new Chunk(text.trim(), Fonts.getFont(CODE_FONT, 10));
            super.add(keyChunk);
            text = "";
        }
    }

    Element[] objs = HtmlParserWrapper.createPdfObjects(text);

    if (objs.length == 0) {
        super.add(new Chunk(text, Fonts.getFont(TEXT_FONT, 10)));
    } else {
        //descCell = new PdfPCell();
        for (int i = 0; i < objs.length; i++) {
            try {
                // PdfPTable objects cannot be added into a paragraph
                if (objs[i] instanceof TableParagraph) {
                    TableParagraph tablePara = (TableParagraph) objs[i];
                    super.add(tablePara.getTable());
                } else {
                    super.add(objs[i]);
                }
            } catch (Exception e) {
                DocletUtility.error("Invalid tag text found, ignoring tag!");
            }
        }
    }
}

From source file:org.areasy.common.doclet.document.Implementors.java

License:Open Source License

/**
 * Prints all known subclasses or implementing classes.
 *
 * @param title The label for the name list
 * @param names The names (classes or interfaces)
 * @throws Exception/*from   ww w.  j a  va 2s  . c om*/
 */
public static void print(String title, String[] names) throws Exception {
    float[] widths = { (float) 6.0, (float) 94.0 };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage((float) 100);

    PdfPCell spacingCell = new CellNoBorderNoPadding(new Phrase(""));
    spacingCell.setFixedHeight((float) 12.0);
    spacingCell.setColspan(2);
    table.addCell(spacingCell);

    PdfPCell titleCell = new CellNoBorderNoPadding(
            new Paragraph((float) 20.0, title, Fonts.getFont(TEXT_FONT, BOLD, 10)));
    titleCell.setColspan(2);
    table.addCell(titleCell);

    PdfPCell leftCell = PDFUtility.createElementCell(5, new Phrase(""));
    Paragraph descPg = new Paragraph((float) 24.0);

    for (int i = names.length - 1; i > -1; i--) {
        String subclassName = DocletUtility.getQualifiedNameIfNecessary(names[i]);
        Phrase subclassPhrase = new LinkPhrase(names[i], subclassName, 10, true);
        descPg.add(subclassPhrase);

        if (i > 0)
            descPg.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, BOLD, 12)));
    }

    table.addCell(leftCell);
    table.addCell(new CellNoBorderNoPadding(descPg));

    table.addCell(spacingCell);
    Document.instance().add(table);
}

From source file:org.areasy.common.doclet.document.Index.java

License:Open Source License

/**
 * Creates a simple alphabetical index of all
 * classes and members of the API.//  ww  w .  j  av  a  2 s .c  om
 *
 * @throws Exception If the Index could not be created.
 */
public void create() throws Exception {
    if (!DefaultConfiguration.getBooleanConfigValue(ARG_CREATE_INDEX, false)) {
        log.trace("Index creation disabled.");
        return;
    }

    log.trace("Start creating Index...");

    State.setCurrentHeaderType(HEADER_INDEX);
    State.increasePackageChapter();

    // Name of the package (large font)
    pdfDocument.newPage();

    // Create "Index" bookmark
    String label = DefaultConfiguration.getString(ARG_LB_OUTLINE_INDEX, LB_INDEX);
    String dest = "INDEX:";
    Bookmarks.addRootBookmark(label, dest);
    Chunk indexChunk = new Chunk(label, Fonts.getFont(TEXT_FONT, BOLD, 30));
    indexChunk.setLocalDestination(dest);

    Paragraph indexParagraph = new Paragraph((float) 30.0, indexChunk);

    pdfDocument.add(indexParagraph);

    // we grab the ContentByte and do some stuff with it
    PdfContentByte cb = pdfWriter.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    ct.setLeading((float) 9.0);

    float[] right = { 70, 320 };
    float[] left = { 300, 550 };

    // fill index columns with text
    String letter = "";
    Set keys = memberList.keySet();

    // keys must be sorted case unsensitive
    ArrayList sortedKeys = new ArrayList(keys.size());

    // Build sorted list of all entries
    Iterator keysIterator = keys.iterator();
    while (keysIterator.hasNext()) {
        sortedKeys.add(keysIterator.next());
    }
    Collections.sort(sortedKeys, this);

    Iterator realNames = sortedKeys.iterator();

    while (realNames.hasNext()) {
        String memberName = (String) realNames.next();
        String currentLetter = memberName.substring(0, 1).toUpperCase();
        log.trace("Create index entry for " + memberName);

        // Check if next letter in alphabet is reached
        if (currentLetter.equalsIgnoreCase(letter) == false) {
            // If yes, switch to new letter and print it
            letter = currentLetter.toUpperCase();
            Paragraph lphrase = new Paragraph((float) 13.0);
            lphrase.add(new Chunk("\n\n" + letter + "\n", Fonts.getFont(TEXT_FONT, 12)));
            ct.addText(lphrase);
        }

        // Print member name
        Paragraph phrase = new Paragraph((float) 10.0);
        phrase.add(new Chunk("\n" + memberName + "  ", Fonts.getFont(TEXT_FONT, 9)));

        Iterator sortedPages = getSortedPageNumbers(memberName);
        boolean firstNo = true;
        while (sortedPages.hasNext()) {
            Integer pageNo = (Integer) sortedPages.next();
            // Always add 1 to the stored value, because the pages were
            // counted beginning with 0 internally, but their visible
            // numbering starts with 1
            String pageNumberText = String.valueOf(pageNo.intValue() + 1);
            if (!firstNo) {
                phrase.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, 9)));
            }
            phrase.add(new Chunk(pageNumberText, Fonts.getFont(TEXT_FONT, 9)));
            firstNo = false;
        }

        ct.addText(phrase);
    }

    // Now print index by printing columns into document
    int status = 0;
    int column = 0;

    while ((status & ColumnText.NO_MORE_TEXT) == 0) {
        ct.setSimpleColumn(right[column], 60, left[column], 790, 16, Element.ALIGN_LEFT);
        status = ct.go();

        if ((status & ColumnText.NO_MORE_COLUMN) != 0) {
            column++;

            if (column > 1) {
                pdfDocument.newPage();
                column = 0;
            }
        }
    }

    log.trace("Index created.");
}

From source file:org.areasy.common.doclet.document.Members.java

License:Open Source License

/**
 * Prints member information./*from w w w . ja  v  a2s. c o m*/
 *
 * @param declaration      The modifiers ("public static final..").
 * @param returnType       Phrase with the return type text (might be
 *                         a hyperlink)
 * @param parms            Parameters of a method or constructor, null for a field.
 * @param thrownExceptions Exceptions of a method, null for a field or constructor.
 * @param isFirst          True if it is the first field/method/constructor in the list.
 * @param isField          True if it is a field.
 * @param isConstructor    True if it is a constructor.
 * @throws Exception
 */
public static void printMember(String declaration, Phrase returnType, ProgramElementDoc commentDoc,
        Parameter[] parms, ClassDoc[] thrownExceptions, boolean isFirst, boolean isField, boolean isConstructor,
        boolean isDeprecated, Phrase deprecatedPhrase, Object constantValue) throws Exception {
    String name = commentDoc.name();

    State.setCurrentMember(State.getCurrentClass() + "." + name);
    State.setCurrentDoc(commentDoc);

    // Returns the text, resolving any "inheritDoc" inline tags
    String commentText = DocletUtility.getComment(commentDoc);

    // TODO: The following line may set the wrong page number
    //      in the index, when the member gets printed on a
    //      new page completely (because it is in one table).
    // Solution unknown yet. Probably split up table.
    Doclet.getIndex().addToMemberList(State.getCurrentMember());

    // Prepare list of exceptions (if it throws any)
    String throwsText = "throws";
    int parmsColumn = declaration.length() + (name.length() - throwsText.length());

    // First output text line (declaration of method and first parameter or "()" ).
    // This first line is a special case because the class name is bold,
    // while the rest is regular plain text, so it must be built using three Chunks.
    Paragraph declarationParagraph = new Paragraph((float) 10.0);

    // left part / declaration ("public static..")
    Chunk leftPart = new Chunk(declaration, Fonts.getFont(CODE_FONT, 10));

    declarationParagraph.add(leftPart);

    if (returnType != null) {
        // left middle part / declaration ("public static..")
        declarationParagraph.add(returnType);
        declarationParagraph.add(new Chunk(" ", Fonts.getFont(CODE_FONT, 10)));
        parmsColumn = 2;
    }

    // right middle part / bold class name
    declarationParagraph.add(new Chunk(name, Fonts.getFont(CODE_FONT, BOLD, 10)));

    if (!isField) {
        // 1st parameter or empty brackets

        if ((parms != null) && (parms.length > 0)) {
            Phrase wholePhrase = new Phrase("(", Fonts.getFont(CODE_FONT, 10));
            // create link for parameter type
            wholePhrase.add(PDFUtility.getParameterTypePhrase(parms[0], 10));
            // then normal text for parameter name
            wholePhrase.add(" " + parms[0].name());
            if (parms.length > 1) {
                wholePhrase.add(",");
            } else {
                wholePhrase.add(")");
            }

            // In order to have the parameter types in the bookmark,
            // make the current state text more detailled
            String txt = State.getCurrentMethod() + "(";
            for (int i = 0; i < parms.length; i++) {
                if (i > 0)
                    txt = txt + ",";
                txt = txt + DocletUtility.getParameterType(parms[i]);
            }

            txt = txt + ")";
            State.setCurrentMethod(txt);

            // right part / parameter and brackets
            declarationParagraph.add(wholePhrase);

        } else {
            String lastPart = "()";
            State.setCurrentMethod(State.getCurrentMethod() + lastPart);

            // right part / parameter and brackets
            declarationParagraph.add(new Chunk(lastPart, Fonts.getFont(CODE_FONT, 10)));
        }

    }

    float[] widths = { (float) 6.0, (float) 94.0 };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage((float) 100);

    // Before the first constructor or method, create a coloured title bar
    if (isFirst) {
        PdfPCell colorTitleCell = null;

        // Some empty space...
        Document.add(new Paragraph((float) 6.0, " "));

        if (isConstructor)
            colorTitleCell = new CustomPdfPCell("Constructors");
        else if (isField)
            colorTitleCell = new CustomPdfPCell("Fields");
        else
            colorTitleCell = new CustomPdfPCell("Methods");

        colorTitleCell.setColspan(2);
        table.addCell(colorTitleCell);
    }

    // Method name (large, first line of a method description block)
    Phrase linkPhrase = Destinations.createDestination(commentDoc.name(), commentDoc,
            Fonts.getFont(TEXT_FONT, BOLD, 14));
    Paragraph nameTitle = new Paragraph(linkPhrase);
    PdfPCell nameCell = new CellNoBorderNoPadding(nameTitle);

    if (isFirst)
        nameCell.setPaddingTop(10);
    else
        nameCell.setPaddingTop(0);

    nameCell.setPaddingBottom(8);
    nameCell.setColspan(1);

    // Create nested table in order to try to prevent the stuff inside
    // this table from being ripped appart over a page break. The method
    // name and the declaration/parm/exception line(s) should always be
    // together, because everything else just looks bad
    PdfPTable linesTable = new PdfPTable(1);
    linesTable.addCell(nameCell);
    linesTable.addCell(new CellNoBorderNoPadding(declarationParagraph));

    if (!isField) {
        // Set up following declaration lines
        Paragraph[] params = PDFUtility.createParameters(parmsColumn, parms);
        Paragraph[] exceps = PDFUtility.createExceptions(parmsColumn, thrownExceptions);

        for (int i = 0; i < params.length; i++) {
            linesTable.addCell(new CellNoBorderNoPadding(params[i]));
        }

        for (int i = 0; i < exceps.length; i++) {
            linesTable.addCell(new CellNoBorderNoPadding(exceps[i]));
        }
    }

    // Create cell for inserting the nested table into the outer table
    PdfPCell cell = new PdfPCell(linesTable);
    cell.setPadding(5);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    table.addCell(cell);

    // The empty, left cell (the invisible indentation column)
    State.setContinued(true);

    PdfPCell leftCell = PDFUtility.createElementCell(5, new Phrase("", Fonts.getFont(TEXT_FONT, BOLD, 6)));
    PdfPCell spacingCell = new PdfPCell();
    spacingCell.setFixedHeight((float) 8.0);
    spacingCell.setBorder(Rectangle.NO_BORDER);
    table.addCell(spacingCell);
    table.addCell(spacingCell);

    // The descriptive method explanation text

    if (isDeprecated) {
        Phrase commentPhrase = new Phrase();
        commentPhrase
                .add(new Phrase(AbstractConfiguration.LB_DEPRECATED_TAG, Fonts.getFont(TEXT_FONT, BOLD, 10)));
        commentPhrase.add(deprecatedPhrase);
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, commentPhrase));

        commentPhrase = new Phrase();
        commentPhrase.add(Chunk.NEWLINE);
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, commentPhrase));
    }

    Element[] objs = HtmlParserWrapper.createPdfObjects(commentText);

    if (objs.length == 1) {
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, objs[0]));
    } else {
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, Element.ALIGN_LEFT, objs));
    }

    // TODO: FORMAT THIS CONSTANT VALUE OUTPUT CORRECTLY

    if (isField) {
        if (constantValue != null) {
            // Add 2nd comment line (left cell empty, right cell text)
            Chunk valueTextChunk = new Chunk("Constant value: ", Fonts.getFont(TEXT_FONT, PLAIN, 10));
            Chunk valueContentChunk = new Chunk(constantValue.toString(), Fonts.getFont(CODE_FONT, BOLD, 10));
            Phrase constantValuePhrase = new Phrase("");
            constantValuePhrase.add(valueTextChunk);
            constantValuePhrase.add(valueContentChunk);
            table.addCell(leftCell);
            table.addCell(PDFUtility.createElementCell(0, constantValuePhrase));
        }
    }

    // Add whole method block to document
    Document.add(table);
}

From source file:org.areasy.common.doclet.document.Summary.java

License:Open Source License

/**
 * Prints field summaries./*from ww  w .jav a 2  s .co  m*/
 * @param constantValue
 * @param isDeprecated
 * @param deprecatedPhrase
 * @param mainTable
 * @throws Exception
 */
private static void printField(FieldDoc fieldDoc, Object constantValue, boolean isDeprecated,
        Phrase deprecatedPhrase, PdfPTable mainTable) throws Exception {

    String name = fieldDoc.name();
    String modifier = fieldDoc.modifiers();
    String commentText = DocletUtility.getFirstSentence(fieldDoc);
    String destination = fieldDoc.qualifiedName();

    Element[] objs = HtmlParserWrapper.createPdfObjects(commentText);

    PdfPTable commentsTable = createColumnsAndDeprecated(objs, isDeprecated, deprecatedPhrase);

    if (constantValue != null) {
        // Add 2nd comment line (left cell empty, right cell text)
        commentsTable.addCell(new Phrase(""));
        Chunk valueTextChunk = new Chunk("Value: ", Fonts.getFont(TEXT_FONT, PLAIN, 10));
        Chunk valueContentChunk = new Chunk(constantValue.toString(), Fonts.getFont(CODE_FONT, BOLD, 10));
        Phrase constantValuePhrase = new Phrase("");
        constantValuePhrase.add(valueTextChunk);
        constantValuePhrase.add(valueContentChunk);
        commentsTable.addCell(constantValuePhrase);
    }

    PdfPTable anotherinnertable = new PdfPTable(1);
    anotherinnertable.setWidthPercentage(100f);
    anotherinnertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    PdfPTable innerTable = addDeclaration(modifier, null);

    // Link to field
    LinkPhrase linkPhrase = new LinkPhrase(destination, name, Fonts.getFont(CODE_FONT, 9));

    // right part of the table
    PdfPCell cell = PDFUtility.createElementCell(2, linkPhrase);
    cell.setPaddingTop((float) 2.0);
    cell.setPaddingLeft((float) 7.0);
    anotherinnertable.addCell(cell);
    anotherinnertable.addCell(commentsTable);

    innerTable.addCell(anotherinnertable);
    mainTable.addCell(innerTable);
}