Example usage for com.lowagie.text Element ALIGN_LEFT

List of usage examples for com.lowagie.text Element ALIGN_LEFT

Introduction

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

Prototype

int ALIGN_LEFT

To view the source code for com.lowagie.text Element ALIGN_LEFT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:nl.dykema.jxmlnote.report.pdf.PdfReport.java

License:Open Source License

public int getPdfAlign(Report.Align a) {
    if (a.equals(Align.LEFT)) {
        return Element.ALIGN_LEFT;
    } else if (a.equals(Align.RIGHT)) {
        return Element.ALIGN_RIGHT;
    } else if (a.equals(Align.CENTER)) {
        return Element.ALIGN_CENTER;
    } else if (a.equals(Align.JUSTIFY)) {
        return Element.ALIGN_JUSTIFIED;
    } else {//www.  j  a va  2s  .c o m
        return Element.ALIGN_LEFT;
    }
}

From source file:nl.dykema.jxmlnote.report.pdf.PdfReport.java

License:Open Source License

public int getAlign(AttributeSet s) {
    if (StyleConstants.getAlignment(s) == StyleConstants.ALIGN_LEFT) {
        return Element.ALIGN_LEFT;
    } else if (StyleConstants.getAlignment(s) == StyleConstants.ALIGN_CENTER) {
        return Element.ALIGN_CENTER;
    } else if (StyleConstants.getAlignment(s) == StyleConstants.ALIGN_RIGHT) {
        return Element.ALIGN_RIGHT;
    } else if (StyleConstants.getAlignment(s) == StyleConstants.ALIGN_JUSTIFIED) {
        return Element.ALIGN_JUSTIFIED;
    } else {// ww w . ja va  2s.  c  o  m
        return Element.ALIGN_LEFT;
    }
}

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

private List<PdfPTable> createPrescriptionTbl2() {
    ClaimItem[] items;//from w w w  .  j a  v  a2 s . c o  m
    PdfPCell pcell, blank, numCell, amountCell;
    int num, cnt;
    double sum; // @009 ?????(?*)
    List<PdfPTable> preTblList = null;
    String admin, number; // @009
    String classCode, amount, medicine; // @009

    try {
        StringBuilder sb = new StringBuilder();
        sb.append(
                "???????(??)??????????????\n");
        sb.append(
                "?????????????????????????");
        PdfPTable ptbl = new PdfPTable(9); // @009
        ptbl.setWidthPercentage(100f);
        // @009 ???, ?, ??, ?, ??, , "(", , ")"
        float[] widthsP = { 14, 7, 52, 8, 15, 32, 2, 5, 9 };
        ptbl.setWidths(widthsP);
        ptbl.getDefaultCell().setPadding(0f);
        preTblList = new ArrayList<PdfPTable>();

        num = 1;
        //admin = "";  // @009 
        //number = ""; // @009 
        //amount = ""; // @009 ?
        numCell = new PdfPCell(new Paragraph("", min_8)); // @009
        numCell.setBorderWidth(LINE_WIDTH_0); // @009

        PdfPCell notes = new PdfPCell(new Paragraph("??", min_8));
        notes.setBorderWidth(LINE_WIDTH_1);
        notes.setBorderWidthBottom(LINE_WIDTH_0);
        PdfPCell bracket = new PdfPCell(new Paragraph("", min_15));
        bracket.setBorderWidth(LINE_WIDTH_0);
        bracket.setHorizontalAlignment(Element.ALIGN_RIGHT);
        bracket.setPadding(0f);
        PdfPCell notesDetail = new PdfPCell(new Paragraph(sb.toString(), min_6));
        notesDetail.setBorderWidth(LINE_WIDTH_0);
        notesDetail.setColspan(5);
        PdfPCell bracketC = new PdfPCell(new Paragraph("", min_15));
        bracketC.setBorderWidth(LINE_WIDTH_0);
        bracketC.setHorizontalAlignment(Element.ALIGN_LEFT);
        bracketC.setPadding(0f);
        bracketC.setColspan(2);

        for (Iterator<BundleMed> ite = pkg.getPriscriptionList().iterator(); ite.hasNext();) {
            BundleMed prescription = ite.next();
            admin = prescription.getAdmin(); // @009  
            number = prescription.getBundleNumber(); // @009  ????=1 bundeNumber
            classCode = prescription.getClassCode(); // @009   221 etc 

            items = prescription.getClaimItem();
            //minagawa^                
            boolean genericIsOk = true;

            if (items != null) {
                for (ClaimItem i : items) {
                    if (i.getCode().equals("099209903")) {
                        genericIsOk = false;
                        break;
                    }
                }
            }
            genericIsOk = true;
            //minagawa4                

            if (ptbl.getRows().isEmpty()) {
                ptbl.addCell(notes);
                ptbl.addCell(bracket);
                ptbl.addCell(notesDetail);
                ptbl.addCell(bracketC);
            }

            // @001 2009/11/17 ?
            // items?null???????????????
            // ???????????items ? null ??????
            // if???????????(??????????)
            if (items != null) {
                boolean clearFlg = true; // @004 2010/02/26  ?
                // ********** @009  **********
                //sum = 0; // ?????
                Font adminF = min_8; // 
                boolean wrap = true;
                if (admin != null) {
                    if (admin.length() > 17) {
                        // ??17???4??
                        adminF = min_4;
                        wrap = false;
                    } else if (admin.length() > 11) {
                        // ??11???6??
                        adminF = min_6;
                    }
                }
                Font medicineF; // ??
                // ********** @009  **********

                // ??? ClaimItem iterate
                for (cnt = 0; cnt < items.length; cnt++) {
                    //System.out.println("row size:" + ptbl.getRows().size());

                    // ??
                    if (!genericIsOk) {
                        blank = new PdfPCell(new Paragraph("", min_8));
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                        genericIsOk = true;

                    } else {
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (ptbl.getRows().size() > 13) {
                        // ?13???????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setColspan(4);
                        ptbl.addCell(blank);
                        pcell = new PdfPCell(new Paragraph("???", min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(5);
                        ptbl.addCell(pcell);
                        preTblList.add(ptbl);
                        ptbl = new PdfPTable(9);
                        ptbl.setWidthPercentage(100f);
                        ptbl.setWidths(widthsP);
                        ptbl.getDefaultCell().setPadding(0f);
                        // ??
                        ptbl.addCell(notes);
                        ptbl.addCell(bracket);
                        ptbl.addCell(notesDetail);
                        ptbl.addCell(bracketC);
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (cnt > 0) {
                        // ?1?????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(blank);
                    } else {
                        // ?1??????
                        numCell = new PdfPCell(new Paragraph(num++ + ")", min_8));
                        numCell.setBorderWidth(LINE_WIDTH_0);
                        setAlignRight(numCell);
                        ptbl.addCell(numCell);
                        // @004 2010/02/26  
                        // ?1?????? false ??
                        if (!ClaimConst.COMMENT_CODE_0.equals(items[cnt].getCode())) {
                            clearFlg = false;
                        }
                        // @004 2010/02/26  
                    }

                    // ********** @009  **********
                    amount = items[cnt].getNumber();
                    //                        System.out.println("??" + items[cnt].getName());
                    //                        System.out.println("?" + amount);
                    //medicine = "";
                    medicine = items[cnt].getName();
                    //                        System.out.println("????" + medicine.length());
                    if (medicine.length() > 19) {
                        // ????19???7??
                        medicineF = min_7;
                    } else {
                        // ????19???8???
                        medicineF = min_8;
                    }
                    // ********** @009  **********

                    if ((ClaimConst.SUBCLASS_CODE_ID.equals(items[cnt].getClassCodeSystem()))
                            && ((String.valueOf(ClaimConst.YAKUZAI).equals(items[cnt].getClassCode()))
                                    || (String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode())))) {

                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), medicineF)); // ?? ??? ????
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(pcell);
                        amountCell = new PdfPCell(new Paragraph(convertNVL(amount), min_8)); // ?
                        setAlignRight(amountCell);
                        amountCell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(amountCell);

                        if (!(String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode()))) {
                            // ?????
                            pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getUnit()), min_8)); // ??
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(pcell);
                            // ********** @009  **********
                            pcell = new PdfPCell(new Paragraph(admin, adminF)); // 
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setNoWrap(wrap);
                            ptbl.addCell(pcell);
                        } else {
                            blank = new PdfPCell();
                            blank.setColspan(2);
                            blank.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(blank);
                        }

                        if (ClaimConst.RECEIPT_CODE_GAIYO.equals(classCode)) {
                            pcell = new PdfPCell(new Paragraph("", min_8));
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setColspan(3);
                            ptbl.addCell(pcell);
                            sum = Double.parseDouble(amount) * Double.parseDouble(number);
                            DecimalFormat f = new DecimalFormat("####0.###");
                            //                                System.out.println("??" + sum);
                            amountCell.getPhrase().clear();
                            amountCell.getPhrase().add(new Paragraph(String.valueOf(f.format(sum)), min_8)); // ?
                        } else {
                            // 
                            if ((number != null) && !("".equals(number))) {
                                pcell = new PdfPCell(new Paragraph("(", min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                ptbl.addCell(pcell);
                                pcell = new PdfPCell(new Paragraph(number, min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);

                                //minagawa^          
                                if (classCode.startsWith("22")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                } else if (classCode.startsWith("21")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                    // 
                                } else if (classCode.startsWith("23")) {
                                    pcell = new PdfPCell(new Paragraph("", min_8));
                                }
                                //minagawa$     
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);
                            } else {
                                blank = new PdfPCell();
                                blank.setBorderWidth(LINE_WIDTH_0);
                                blank.setColspan(3);
                                ptbl.addCell(blank);
                            }
                        }
                        // ********** @009  **********
                    } else {
                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(7);
                        ptbl.addCell(pcell);
                    }
                }
                // @004 2010/02/26  
                // ?? true ????
                if (clearFlg && (admin == null)) {
                    numCell.getPhrase().clear();
                    num--;
                }
                // @004 2010/02/26  

            } else {
                String stampName = prescription.getOrderName();
                System.err.println("??" + stampName
                        + "????????????");
                StringBuilder b = new StringBuilder();
                b.append("??").append(stampName)
                        .append("?????????").append(System.getProperty(STR_LF));
                System.err.println(b.toString());
            }

            if (!ite.hasNext()) {
                blank = new PdfPCell();
                blank.setBorderWidth(LINE_WIDTH_0);
                ptbl.addCell(blank);
                pcell = new PdfPCell(new Paragraph("", min_8));
                pcell.setBorderWidth(LINE_WIDTH_0);
                pcell.setBorderWidthLeft(LINE_WIDTH_1);
                pcell.setPaddingLeft(30f);
                pcell.setColspan(8);
                ptbl.addCell(pcell);
                preTblList.add(ptbl);
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    return preTblList;
}

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

/**
 * ??
 * ??
 * @param pcell
 */
private void setAlignLeft(PdfPCell pcell) {
    pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
}

From source file:org.apache.poi.xwpf.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

public void applyStyles(XWPFParagraph p, Style style) {

    if (style != null) {
        // first process values from "style"
        // will be overridden by in-line values if available...
        StyleParagraphProperties paragraphProperties = style.getParagraphProperties();

        if (paragraphProperties != null) {
            FontInfos fontInfos = paragraphProperties.getFontInfos();
            if (fontInfos != null) {
                Font font = XWPFFontRegistry.getRegistry().getFont(fontInfos.getFontFamily(),
                        fontInfos.getFontEncoding(), fontInfos.getFontSize(), fontInfos.getFontStyle(),
                        fontInfos.getFontColor());
                setFont(font);//  www. ja v  a2 s. c  o  m
            }
            // Alignment
            int alignment = paragraphProperties.getAlignment();
            if (alignment != Element.ALIGN_UNDEFINED) {
                setAlignment(alignment);
            }

            Float lineHeight = paragraphProperties.getLineHeight();
            if (lineHeight != null) {
                // super.getPdfPCell().setMinimumHeight(lineHeight);
                // FIXME : Is it correct???
                setLeading(lineHeight * super.getTotalLeading());
            }
            // System.err.println("IndentationRight "+paragraphProperties.getIndentationRight());
            setIndentationRight(paragraphProperties.getIndentationRight());
            setIndentationLeft(paragraphProperties.getIndentationLeft());
            setFirstLineIndent(paragraphProperties.getIndentationFirstLine());
            // StyleBorder borderBottom= paragraphProperties.getBorderBottom();

        }

    }

    ParagraphAlignment paragraphAlignment = p.getAlignment();

    // text-align

    if (paragraphAlignment != null) {
        int alignment = Element.ALIGN_UNDEFINED;
        switch (paragraphAlignment) {
        case LEFT:
            alignment = Element.ALIGN_LEFT;
            break;
        case RIGHT:
            alignment = Element.ALIGN_RIGHT;
            break;
        case CENTER:
            alignment = Element.ALIGN_CENTER;
            break;
        case BOTH:
            alignment = Element.ALIGN_JUSTIFIED;
            break;
        default:
            break;
        }

        setAlignment(alignment);
    }

    int indentationLeft = p.getIndentationLeft();
    if (indentationLeft > 0) {
        setIndentationLeft(indentationLeft);
    }

    // text-indent
    int indentationFirstLine = p.getIndentationFirstLine();
    if (indentationFirstLine > 0) {
        setFirstLineIndent(indentationFirstLine);
    }

    int indentationRight = p.getIndentationRight();

    if (indentationRight > 0) {
        setIndentationRight(indentationRight);
    }
    // verticalAlignment DOES not exists in StyleParagraphProperties iText
    // TextAlignment textAlignment = p.getVerticalAlignment();

    int left = p.getIndentationLeft();
    int right = p.getIndentationRight();

    if (right > 0) {
        setIndentationRight(dxa2points(right));
    }

    if (left > 0) {
        setIndentationLeft(dxa2points(left));
    }

    int firstLineIndent = p.getIndentationFirstLine();
    if (firstLineIndent > 0) {
        setFirstLineIndent(dxa2points(firstLineIndent));
    }

    int spacingBefore = p.getSpacingBefore();
    if (spacingBefore > 0) {
        setSpacingBefore(dxa2points(spacingBefore));
    }
    if (p.getSpacingAfter() >= 0) {
        setSpacingAfter(dxa2points(p.getSpacingAfter()));

    } else {
        // XXX Seems to be a default :
        setSpacingAfter(10f);
    }

    if (p.getCTP().getPPr() != null) {
        if (p.getCTP().getPPr().getSpacing() != null) {

            if (p.getCTP().getPPr().getSpacing().getLine() != null) {

                // XXX PLQ : why 240 ???
                float leading = (p.getCTP().getPPr().getSpacing().getLine().floatValue() / 240);
                setMultipliedLeading(leading);
            }

        }
    }

    ParagraphAlignment alignment = p.getAlignment();
    switch (alignment) {
    case LEFT:
        setAlignment(Element.ALIGN_LEFT);
        break;
    case RIGHT:
        setAlignment(Element.ALIGN_RIGHT);
        break;

    case CENTER:
        setAlignment(Element.ALIGN_CENTER);
        break;

    case BOTH:
        setAlignment(Element.ALIGN_JUSTIFIED);
        break;

    default:
        break;
    }

}

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./*from  ww w  . j  a  v a 2s .  co  m*/
 *
 * @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 . j  a  va 2  s . 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.TagLists.java

License:Open Source License

/**
 * Prints tags of a class member (method, field).
 *
 * @param title    The bold face title text for the tag (like "Parameters:")
 * @param tags     The list of tags to be printed.
 * @param compress If true, the text of all the given tags will be concatenated
 *                 into one, comma separated. This is used for the author tag,
 *                 for example, where several separate author tags should be
 *                 printed as one only./*from ww  w. ja  v  a2s .  com*/
 * @param isMember If true, the whole tag paragraph is printed with additional
 *                 intendation (because it's a tag of a method, like the
 *                 "Parameters:" tag).
 * @throws Exception
 */
private static void printTags(String title, Tag[] tags, boolean compress, boolean isMember) throws Exception {
    if ((tags != null) && (tags.length > 0)) {
        float[] widthsMember = { (float) 6.0, (float) 4.0, (float) 94.0 };
        float[] widthsClass = { (float) 6.0, (float) 94.0 };

        PdfPTable table = null;
        if (isMember) {
            table = new PdfPTable(widthsMember);
        } else {
            table = new PdfPTable(widthsClass);
        }
        table.setWidthPercentage((float) 100);

        Paragraph empty = new Paragraph(" ");

        // Add empty line after the title ("Parameters:" etc.)
        if (isMember) {
            table.addCell(new CellNoBorderNoPadding(empty));
            table.addCell(new CellNoBorderNoPadding(empty));
            table.addCell(new CellNoBorderNoPadding(empty));
        }

        PdfPCell titleCell = new CellNoBorderNoPadding(
                new Paragraph((float) 24.0, title, Fonts.getFont(TEXT_FONT, BOLD, 10)));
        titleCell.setColspan(2);
        if (isMember) {
            table.addCell(new CellNoBorderNoPadding(empty)); // indentation
            // column
        }
        table.addCell(titleCell);

        int number = tags.length;
        String tagText = "";
        if (compress) {
            number = 1;
            for (int i = 0; i < tags.length; i++) {
                tagText = tagText + getTagText(tags[i]);
                if (i < tags.length - 1) {
                    tagText = tagText + ", ";
                }
            }
        }

        for (int i = 0; i < number; i++) {

            // indentation columns
            if (isMember) {
                table.addCell(new CellNoBorderNoPadding(empty));
                table.addCell(new CellNoBorderNoPadding(empty));
            } else {
                table.addCell(new CellNoBorderNoPadding(empty));
            }

            if (!compress) {
                tagText = getTagText(tags[i]);
            }

            Element[] elements = HtmlParserWrapper.createPdfObjects(tagText);
            table.addCell(PDFUtility.createElementCell(0, Element.ALIGN_LEFT, elements));
        }

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

From source file:org.areasy.common.doclet.document.tags.HtmlTagUtility.java

License:Open Source License

/**
 * Returns the Element constant associated with the specified horizontal
 * alignment (left, right, center, justified).
 *//*from  w  w w  .  j  av  a2s  .c om*/
public static int getAlignment(String htmlAlignString, int defaultAlign) {
    if (htmlAlignString == null)
        return defaultAlign;

    if ("center".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_CENTER;
    if ("right".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_RIGHT;
    if ("left".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_LEFT;
    if ("justify".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_JUSTIFIED;

    return defaultAlign;
}

From source file:org.areasy.common.doclet.document.tags.TagTD.java

License:Open Source License

private PdfPCell createCell(Element[] content) {
    int defaultAlign = (getType() == TAG_TH) ? Element.ALIGN_CENTER : Element.ALIGN_LEFT;

    String align = getInheritedAttribute("align", false);
    String valign = getInheritedAttribute("valign", false);
    String bgcolor = getInheritedAttribute("bgcolor", true);
    int alignment = HtmlTagUtility.getAlignment(align, defaultAlign);

    PdfPCell cell = PDFUtility.createElementCell(2, alignment, content);

    cell.setHorizontalAlignment(HtmlTagUtility.getAlignment(align, defaultAlign));
    cell.setVerticalAlignment(HtmlTagUtility.getVerticalAlignment(valign, Element.ALIGN_MIDDLE));
    cell.setBackgroundColor(HtmlTagUtility.getColor(bgcolor));
    cell.setColspan(parseSpan(getAttribute("colspan")));

    cell.setUseAscender(true); // needs newer iText
    cell.setUseDescender(true); // needs newer iText
    cell.setUseBorderPadding(true); // needs newer iText

    if (getAttribute("nowrap") != null)
        cell.setNoWrap(true);/*from w w w.  java  2 s.c  o m*/
    if (getType() == TAG_TH)
        cell.setMarkupAttribute(HEADER_INDICATOR_ATTR, "true");

    return cell;
}