Example usage for com.lowagie.text.pdf PdfPCell setBorderColor

List of usage examples for com.lowagie.text.pdf PdfPCell setBorderColor

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setBorderColor.

Prototype

public void setBorderColor(Color borderColor) 

Source Link

Document

Sets the color of the border.

Usage

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colHeader, Document document) throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
    fontSmallBold.setColor(tColor);//w  w w.j  a v a 2 s  . com

    com.krawler.utils.json.base.JSONObject colWidth = config.getJSONObject("colWidth");
    JSONArray widths = colWidth.getJSONArray("data");
    ArrayList arr = new ArrayList();
    PdfPTable table;
    float[] f = new float[widths.length() + 1];//[(stpcol - stcol) + 1];
    float[] tcol = new float[(stpcol - stcol) + 1];

    if (widths.length() == 0) {
        f[0] = 10;
        for (int k = 1; k < f.length; k++) {
            f[k] = 20;
        }
        tcol[0] = 10;
    } else {
        for (int i = 0; i < widths.length(); i++) {
            JSONObject temp = widths.getJSONObject(i);
            arr.add(temp.getInt("width"));
        }

        f[0] = 30;
        for (int k = 1; k < f.length; k++) {
            if (!config.getBoolean("landscape") && (Integer) arr.get(k - 1) > 550) {
                f[k] = 550;
            } else {
                f[k] = (Integer) arr.get(k - 1);
            }
        }
        //            table = new PdfPTable(f);
        //            table.setTotalWidth(90);
        // table.setWidthPercentage(f,document.getPageSize());
        tcol[0] = 30;
    }
    int i = 1;
    for (int k = stcol; k < stpcol; k++) {
        tcol[i] = f[k + 1];
        i++;
    }

    table = new PdfPTable(tcol);
    table.setTotalWidth(90);
    table.setWidthPercentage(tcol, document.getPageSize());

    table.setSpacingBefore(15);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    PdfPCell h2 = new PdfPCell(new Paragraph("No.", fontSmallBold));
    if (config.getBoolean("gridBorder")) {
        h2.setBorder(PdfPCell.BOX);
    } else {
        h2.setBorder(0);
    }
    h2.setPadding(4);
    h2.setBorderColor(Color.GRAY);
    h2.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colHeader[hcol], fontSmallBold));
        h1.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (config.getBoolean("gridBorder")) {
            h1.setBorder(PdfPCell.BOX);
        } else {
            h1.setBorder(0);
        }
        h1.setBorderColor(Color.GRAY);
        h1.setPadding(4);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        h2 = new PdfPCell(new Paragraph(String.valueOf(row + 1), f1));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);

        for (int col = stcol; col < stpcol; col++) {
            Paragraph para = null;
            if (store.getJSONObject(row).has(colwidth2[col]))
                para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            else
                para = new Paragraph("", f1);
            //                    Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            PdfPCell h1 = new PdfPCell(para);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(4);
            h1.setBorderColor(Color.GRAY);
            h1.setHorizontalAlignment(Element.ALIGN_CENTER);
            h1.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h1);
        }

    }
    document.add(table);
    document.newPage();

    /* add instance of OnStartPage*/
    if (widths.length() != 0) {
        if (stpcol != colwidth2.length) {
            float twidth = 0;
            stpcol1 = stpcol;

            int docwidth;
            if (config.getBoolean("landscape"))
                docwidth = 800;
            else
                docwidth = 600;

            while (twidth < docwidth && stpcol1 < f.length) {
                twidth += f[stpcol1];
                stpcol1++;
            }
            stpcol1--;

            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document);
        }

    } else {
        if (stpcol != colwidth2.length) {
            if ((colwidth2.length - stpcol) > showColumns) { // column limit
                stpcol1 = stpcol + 5;
            } else {
                stpcol1 = (colwidth2.length - stpcol) + stpcol;
            }
            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document);
        }
    }
    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

private int addTableTimeLine(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        int maxlevel, Document document) throws JSONException, DocumentException {
    float[] f = new float[(stpcol - stcol) + 1];
    for (int k = 0; k < f.length; k++) {
        f[k] = 20;/*from w ww.j  av a  2 s  . c o  m*/
    }
    f[0] = f[0] + 10 * maxlevel;
    PdfPTable table = new PdfPTable(f);

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));

    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, tColor);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    Font f1;

    table.setWidthPercentage(90);
    PdfPCell h2 = new PdfPCell(new Paragraph("Name", font)); // new
    if (config.getBoolean("gridBorder"))
        h2.setBorder(PdfPCell.BOX);
    else
        h2.setBorder(0);
    h2.setPadding(2);
    //                h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED);
    // Paragraph(colwidth2[hcol],font);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        if (config.getBoolean("gridBorder"))
            h1.setBorder(PdfPCell.BOX);
        else
            h1.setBorder(0);
        h1.setPadding(2);
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        if (row % 62 == 61) {
            document.add(table);
            table.deleteBodyRows();
            table.setSkipFirstHeader(true);
        }
        if (store.getJSONObject(row).getBoolean("flag"))
            f1 = font;
        else
            f1 = font1;
        if (store.getJSONObject(row).getString("info").compareTo("") != 0) {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        } else {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingTop(9);
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        }

        //                h2.setBorder(0);
        //                h2.setPadding(1);
        //                Color bColor = Color.decode("DDDDDD");

        if (config.getBoolean("gridBorder")) {
            if (store.getJSONObject(row).getBoolean("flag")) {
                h2.setBackgroundColor(new Color(0xEEEEEE));
                h2.setBorder(PdfPCell.LEFT | PdfPCell.BOTTOM);
            } else
                h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(2);
        h2.setBorderColor(Color.GRAY);
        if (store.getJSONObject(row).getBoolean("flag"))
            h2.setHorizontalAlignment(Element.ALIGN_LEFT);
        else
            h2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        for (int col = stcol; col < stpcol; col++) {
            Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            PdfPCell h1 = new PdfPCell(para);
            //                    h1.setBorder(0);
            //                    h1.setPadding(1);

            h1.setMinimumHeight(15);
            h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
            h1.setVerticalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                if (store.getJSONObject(row).getBoolean("flag")) {
                    h1.setBorder(PdfPCell.BOTTOM);
                    h1.setBackgroundColor(new Color(0xEEEEEE));
                    if (col == stpcol - 1)
                        h1.setBorder(PdfPCell.BOTTOM | PdfPCell.RIGHT);
                } else
                    h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(2);
            h1.setBorderColor(Color.GRAY);
            table.addCell(h1);
            //               table.addCell(new Paragraph(store.getJSONObject(row)
            //                     .getString(colwidth2[col]), f1));
        }

    }
    document.add(table);
    document.newPage();
    if (stpcol != colwidth2.length) {
        if ((colwidth2.length - stpcol) > 5) // column limit
            stpcol1 = stpcol + 5;
        else
            stpcol1 = (colwidth2.length - stpcol) + stpcol;
        addTableTimeLine(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document);
    }

    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java

License:Open Source License

private void addTable(JSONArray store, String[] res, String[] colIndex, String[] colHeader, String[] mainHeader,
        String[] val, Document document) throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallBold.setColor(tColor);//ww  w. j  a  v a 2  s . co m
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);

    float[] colw = new float[4];
    for (int x = 0; x < 4; x++) {
        colw[x] = 150;
    }
    int col = 0;

    for (int x = 0; x < mainHeader.length; x++) {
        //table start
        PdfPTable table = new PdfPTable(colw);
        table.setTotalWidth(88);
        table.setWidthPercentage(colw, document.getPageSize());
        //table.setSpacingBefore(10);

        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setTotalWidth(90);
        mainTable.setWidthPercentage(100);
        mainTable.setSpacingBefore(20);

        //header cell for mainTable
        PdfPCell headcell = null;
        headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold));
        headcell.setBackgroundColor(new Color(0xEEEEEE));
        headcell.setPadding(padding);
        mainTable.addCell(headcell);
        document.add(mainTable);

        //header cell added to mainTable
        int row = 3;
        if (x == 0 || x == 4) {
            row = 4;
        } else if (x == 5) {
            row = 0;
        }
        for (; row > 0; row--) {
            for (int y = 1; y < colw.length + 1; y++) {// for each column add the colHeader and value cell
                if (col != colHeader.length) {
                    if (y % 2 != 0) {
                        Paragraph p = new Paragraph(colHeader[col], f1);
                        if (colHeader[col].contains("Variance")) {
                            p = new Paragraph(colHeader[col], fontSmallBold);
                        }
                        PdfPCell pcell = new PdfPCell(p);
                        if (gridBorder) {
                            pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                        } else {
                            pcell.setBorder(0);
                        }
                        pcell.setPadding(padding);
                        pcell.setBorderColor(new Color(0xF2F2F2));
                        pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                        table.addCell(pcell);
                    } else {
                        Paragraph p;
                        p = new Paragraph(val[col], f1);
                        if (colHeader[col].contains("Start Variance")
                                || colHeader[col].contains("End Variance")) {
                            p = new Paragraph(val[col] + " days", fontSmallBold);
                        } else if (colHeader[col].contains("Duration")) {
                            if (colHeader[col].contains("Duration Variance"))
                                p = new Paragraph(val[col] + " days", fontSmallBold);
                            else
                                p = new Paragraph(val[col] + " days", f1);
                        } else if (colHeader[col].contains("Work")) {
                            if (colHeader[col].contains("Work Variance"))
                                p = new Paragraph(val[col] + " hrs", fontSmallBold);
                            else
                                p = new Paragraph(val[col] + " hrs", f1);
                        } else if (colHeader[col].contains("Cost")) {
                            if (colHeader[col].contains("Cost Variance"))
                                p = new Paragraph(currSymbol + " " + val[col], fontSmallBold);
                            else
                                p = new Paragraph(currSymbol + " " + val[col], f1);
                        } else if (colHeader[col].contains("Percent Complete")) {
                            p = new Paragraph(val[col] + " %", f1);
                        }
                        PdfPCell pcell = new PdfPCell(p);
                        if (gridBorder) {
                            pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                        } else {
                            pcell.setBorder(0);
                        }
                        pcell.setPadding(padding);
                        pcell.setBorderColor(new Color(0xF2F2F2));
                        pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                        table.addCell(pcell);
                        col++;
                    }
                }
            }
        }
        if (x == 5) {
            int y = 0;
            row = res.length / 4;
            for (; row > 0; row--) {
                for (int c = 0; c < 2; c++) {
                    Paragraph p = new Paragraph(res[y], f1);
                    PdfPCell pcell = new PdfPCell(p);
                    if (gridBorder) {
                        pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                    } else {
                        pcell.setBorder(0);
                    }
                    pcell.setPadding(padding);
                    pcell.setBorderColor(new Color(0xF2F2F2));
                    pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                    table.addCell(pcell);
                    p = new Paragraph(res[y + 1], f1);
                    pcell = new PdfPCell(p);
                    if (gridBorder) {
                        pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                    } else {
                        pcell.setBorder(0);
                    }
                    pcell.setPadding(padding);
                    pcell.setBorderColor(new Color(0xF2F2F2));
                    pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                    table.addCell(pcell);
                    y += 2;
                }
            }
        }
        document.add(table);
    }
}

From source file:com.krawler.esp.servlets.ExportServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request,
        Session session) throws JSONException, DocumentException, SessionExpiredException {

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
    fontSmallBold.setColor(tColor);/* w w  w  .  j  av a2  s. c o m*/
    PdfPTable table;
    float[] tcol;
    tcol = new float[colHeader.length + 1];
    tcol[0] = 40;
    for (int i = 1; i < colHeader.length + 1; i++) {
        tcol[i] = Float.parseFloat(widths[i - 1]);
    }
    table = new PdfPTable(colHeader.length + 1);
    table.setWidthPercentage(tcol, document.getPageSize());
    table.setSpacingBefore(15);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    PdfPCell h2 = new PdfPCell(new Paragraph("No.", fontSmallBold));
    if (config.getBoolean("gridBorder")) {
        h2.setBorder(PdfPCell.BOX);
    } else {
        h2.setBorder(0);
    }
    h2.setPadding(4);
    h2.setBorderColor(Color.GRAY);
    h2.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(h2);
    PdfPCell h1 = null;
    for (int hcol = stcol; hcol < colwidth2.length; hcol++) {
        if (align[hcol].equals("right") && !colHeader[hcol].equals("")) {
            String currency = currencyRender("", session, request);
            h1 = new PdfPCell(new Paragraph(colHeader[hcol] + "(" + currency + ")", fontSmallBold));
        } else
            h1 = new PdfPCell(new Paragraph(colHeader[hcol], fontSmallBold));
        h1.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (config.getBoolean("gridBorder")) {
            h1.setBorder(PdfPCell.BOX);
        } else {
            h1.setBorder(0);
        }
        h1.setBorderColor(Color.GRAY);
        h1.setPadding(4);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        h2 = new PdfPCell(new Paragraph(String.valueOf(row + 1), f1));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);

        JSONObject temp = store.getJSONObject(row);
        for (int col = 0; col < colwidth2.length; col++) {
            Paragraph para = null;
            if (align[col].equals("right") && !temp.getString(colwidth2[col]).equals("")) {
                String currency = currencyRender(temp.getString(colwidth2[col]), session, request);
                para = new Paragraph(currency, f1);
            } else {
                if (colwidth2[col].equals("invoiceno")) {
                    para = new Paragraph(temp.getString("no").toString(), f1);
                } else if (colwidth2[col].equals("invoicedate")) {
                    para = new Paragraph(temp.getString("date").toString(), f1);
                } else if ((temp.isNull(colwidth2[col])) && !(colwidth2[col].equals("invoiceno"))
                        && !(colwidth2[col].equals("invoicedate"))) {
                    para = new Paragraph("", fontMediumRegular);
                } else {
                    para = new Paragraph(temp.getString(colwidth2[col]).toString(), f1);
                }
            }
            h1 = new PdfPCell(para);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(4);
            h1.setBorderColor(Color.GRAY);
            if (!align[col].equals("right") && !align[col].equals("left")) {
                h1.setHorizontalAlignment(Element.ALIGN_CENTER);
                h1.setVerticalAlignment(Element.ALIGN_CENTER);
            } else if (align[col].equals("right")) {
                h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                h1.setVerticalAlignment(Element.ALIGN_RIGHT);
            } else if (align[col].equals("left")) {
                h1.setHorizontalAlignment(Element.ALIGN_LEFT);
                h1.setVerticalAlignment(Element.ALIGN_LEFT);
            }
            table.addCell(h1);
        }
    }
    document.add(table);
    document.newPage();

    return stpcol;
}

From source file:com.krawler.spring.exportFuctionality.ExportRecord.java

License:Open Source License

public Double addBalanceSheetCell(JSONObject jobj, PdfPTable table, String currencyid)
        throws JSONException, SessionExpiredException {
    String val = "";
    double retnum = 0;
    PdfPCell cell3 = null;
    PdfPCell cell4 = null;/*from   w  w w  . j a va2s. c  o m*/
    PdfPCell cell5 = createBalanceSheetCell(val, FontContext.SMALL_TEXT, Element.ALIGN_RIGHT, 0, 0, 0);
    if (!jobj.toString().equalsIgnoreCase("{}")) {
        String accName = jobj.get("accountname").toString();
        double amount = 0;
        int padding = Integer.parseInt(jobj.get("level").toString()) * 10;
        try {
            amount = Double.parseDouble(jobj.get("amount").toString());
            val = exportDaoObj.currencyRender(Double.toString(amount), currencyid);
            java.text.DecimalFormat obj = new java.text.DecimalFormat("###0.00");
            if (padding == 0 && !accName.equals("")) {
                retnum = Double.parseDouble(obj.format(amount));
            }
        } catch (NumberFormatException ex) {
            val = com.krawler.common.util.StringUtil.serverHTMLStripper(jobj.get("amount").toString());
        }
        if (jobj.has("fmt")) {
            cell3 = createBalanceSheetCell(accName, FontContext.TABLE_HEADER, Element.ALIGN_LEFT, 0, padding,
                    0);
            cell4 = createBalanceSheetCell(val, FontContext.TABLE_HEADER, Element.ALIGN_RIGHT, 0, 0, 0);
        } else if (padding == 0 && !accName.equals("")) {
            cell3 = createBalanceSheetCell(accName, FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, padding, 0);
            cell4 = createBalanceSheetCell(val, FontContext.SMALL_TEXT, Element.ALIGN_RIGHT, 0, 0, 0);
            if (!val.equals("")) {
                cell3.setBorderWidthBottom(1);
                cell3.setBorderColor(Color.GRAY);
                cell4.setBorderWidthBottom(1);
                cell4.setBorderColor(Color.gray);
            }
        } else {
            cell3 = createBalanceSheetCell(accName, FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, padding, 0);
            cell4 = createBalanceSheetCell(val, FontContext.TABLE_DATA, Element.ALIGN_RIGHT, 0, 0, 0);
        }
        table.addCell(cell3);
        table.addCell(cell4);
        table.addCell(cell5);
    } /*else{
      cell3 = createBalanceSheetCell(val, fontSmallBold, Element.ALIGN_RIGHT, 0, 0,0);
      cell4 = createBalanceSheetCell(val, fontSmallBold, Element.ALIGN_RIGHT, 0, 0,0);
      }*/

    return retnum;

}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

License:Open Source License

public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colHeader, String[] widths, String[] align, String[] xtype, Document document)
        throws ServiceException {
    try {//w w  w. j av a  2 s.co m
        java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
        PdfPTable table;
        float[] tcol;
        tcol = new float[colHeader.length + 1];
        tcol[0] = 40;
        for (int i = 1; i < colHeader.length + 1; i++) {
            tcol[i] = Float.parseFloat(widths[i - 1]);
        }
        table = new PdfPTable(colHeader.length + 1);
        table.setWidthPercentage(tcol, document.getPageSize());

        table.setSpacingBefore(15);

        PdfPCell h2 = new PdfPCell(
                new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor)));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        PdfPCell h1 = null;
        for (int hcol = stcol; hcol < colwidth2.length; hcol++) {
            h1 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor)));
            h1.setHorizontalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setBorderColor(Color.GRAY);
            h1.setPadding(4);
            table.addCell(h1);
        }
        table.setHeaderRows(1);

        for (int row = strow; row < stprow; row++) {
            h2 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA, tColor)));
            if (config.getBoolean("gridBorder")) {
                h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h2.setBorder(0);
            }
            h2.setPadding(4);
            h2.setBorderColor(Color.GRAY);
            h2.setHorizontalAlignment(Element.ALIGN_CENTER);
            h2.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h2);

            JSONObject temp = store.getJSONObject(row);
            for (int col = 0; col < colwidth2.length; col++) {
                String str = temp.optString((colwidth2[col]), "");
                try {
                    if (xtype.length > 0) {
                        str = formatValue(temp.optString((colwidth2[col]), ""), xtype[col]);
                    }
                } catch (Exception e) {

                }
                Paragraph para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA, tColor));
                h1 = new PdfPCell(para);
                if (config.getBoolean("gridBorder")) {
                    h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                } else {
                    h1.setBorder(0);
                }
                h1.setPadding(4);
                h1.setBorderColor(Color.GRAY);

                if (!align[col].equals("right") && !align[col].equals("left")) {
                    h1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    h1.setVerticalAlignment(Element.ALIGN_CENTER);
                } else if (align[col].equals("right")) {
                    h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    h1.setVerticalAlignment(Element.ALIGN_RIGHT);
                } else if (align[col].equals("left")) {
                    h1.setHorizontalAlignment(Element.ALIGN_LEFT);
                    h1.setVerticalAlignment(Element.ALIGN_LEFT);
                }
                table.addCell(h1);
            }
        }
        document.add(table);
        document.newPage();
    } catch (Exception e) {
        throw ServiceException.FAILURE("exportDAOImpl.addTable", e);
    }
    return stpcol;
}

From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java

License:Open Source License

public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request)
        throws ServiceException {
    try {/*from  ww  w.  j  a  v  a  2 s.c  o m*/
        DateFormat formatter = authHandlerDAOObj.getUserDateFormatter(
                sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request),
                true);
        DateFormat frmt = authHandler.getDateFormatter(request);
        String currencyid = sessionHandlerImpl.getCurrencyID(request);
        int mode = Integer.parseInt(request.getParameter("get"));
        double totalCre = 0;
        double totalDeb = 0;
        java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
        //            fontSmallRegular.setColor(tColor);
        PdfPTable table;
        float[] tcol;
        tcol = new float[colHeader.length + 1];
        tcol[0] = 40;
        for (int i = 1; i < colHeader.length + 1; i++) {
            tcol[i] = Float.parseFloat(widths[i - 1]);
        }
        table = new PdfPTable(colHeader.length + 1);
        table.setWidthPercentage(tcol, document.getPageSize());
        table.setSpacingBefore(15);
        PdfPCell h2 = new PdfPCell(new Paragraph(
                (new Phrase(fontFamilySelector.process("No.", FontContext.FOOTER_NOTE, tColor)))));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        PdfPCell h1 = null;
        for (int hcol = stcol; hcol < colwidth2.length; hcol++) {
            String headerStr = StringUtil.serverHTMLStripper(colHeader[hcol]);
            if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) {
                String currency = currencyRender("", currencyid);
                h1 = new PdfPCell(new Paragraph((new Phrase(fontFamilySelector
                        .process(headerStr + "(" + currency + ")", FontContext.FOOTER_NOTE, tColor)))));
            } else {
                h1 = new PdfPCell(new Paragraph(
                        (new Phrase(fontFamilySelector.process(headerStr, FontContext.FOOTER_NOTE, tColor)))));
            }
            h1.setHorizontalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setBorderColor(Color.GRAY);
            h1.setPadding(4);
            table.addCell(h1);
        }
        table.setHeaderRows(1);

        for (int row = strow; row < stprow; row++) {
            h2 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA)));
            if (config.getBoolean("gridBorder")) {
                h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h2.setBorder(0);
            }
            h2.setPadding(4);
            h2.setBorderColor(Color.GRAY);
            h2.setHorizontalAlignment(Element.ALIGN_CENTER);
            h2.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h2);

            JSONObject temp = store.getJSONObject(row);
            if (mode == 116 || mode == 117) {
                totalCre = totalCre + Double
                        .parseDouble(temp.getString("c_amount") != "" ? temp.getString("c_amount") : "0");
                totalDeb = totalDeb + Double
                        .parseDouble(temp.getString("d_amount") != "" ? temp.getString("d_amount") : "0");
            }
            for (int col = 0; col < colwidth2.length; col++) {
                Paragraph para = null;
                String rowCurrencyId = temp.has("currencyid") ? temp.getString("currencyid") : currencyid;
                if (align[col].equals("currency") && !temp.getString(colwidth2[col]).equals("")) {
                    String currency = currencyRender(temp.getString(colwidth2[col]), currencyid);
                    para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA));
                } else if (align[col].equals("rowcurrency") && !temp.getString(colwidth2[col]).equals("")) {
                    String withCurrency = currencyRender(temp.getString(colwidth2[col]), rowCurrencyId);
                    para = new Paragraph(fontFamilySelector.process(withCurrency, FontContext.TABLE_DATA));
                } else if (align[col].equals("date") && !temp.getString(colwidth2[col]).equals("")) {
                    try {
                        String d1 = formatter.format(frmt.parse(temp.getString(colwidth2[col])));
                        para = new Paragraph(fontFamilySelector.process(d1, FontContext.TABLE_DATA));
                    } catch (Exception ex) {
                        para = new Paragraph(fontFamilySelector.process(temp.getString(colwidth2[col]),
                                FontContext.TABLE_DATA));
                    }
                } else if (colwidth2[col].equals("taxrate")
                        || colwidth2[col].equals("permargin") && !colHeader[col].equals("")) {
                    para = new Paragraph(fontFamilySelector.process(
                            htmlPercentageRender(temp.getString(colwidth2[col]), true),
                            FontContext.TABLE_DATA));
                } else {
                    if (colwidth2[col].equals("invoiceno")) {
                        para = new Paragraph(fontFamilySelector.process(temp.getString("no").toString(),
                                FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("invoicedate")) {
                        para = new Paragraph(fontFamilySelector.process(temp.getString("date").toString(),
                                FontContext.TABLE_DATA));
                    } else if ((temp.isNull(colwidth2[col])) && !(colwidth2[col].equals("invoiceno"))
                            && !(colwidth2[col].equals("invoicedate"))) {
                        para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("c_date")) {
                        para = new Paragraph(fontFamilySelector.process(formatter.format(
                                frmt.parse(temp.getString("c_date").toString() == "" ? temp.getString("d_date")
                                        : temp.getString("c_date"))),
                                FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("c_accountname")) {
                        para = new Paragraph(
                                fontFamilySelector.process(
                                        temp.getString("c_accountname").toString() == ""
                                                ? temp.getString("d_accountname").toString()
                                                : temp.getString("c_accountname").toString(),
                                        FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("c_entryno")) {
                        para = new Paragraph(
                                fontFamilySelector.process(
                                        temp.getString("c_entryno").toString() == ""
                                                ? temp.getString("d_entryno").toString()
                                                : temp.getString("c_entryno").toString(),
                                        FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("d_date")) {
                        para = new Paragraph(fontFamilySelector.process(formatter.format(
                                frmt.parse(temp.getString("d_date").toString() == "" ? temp.getString("c_date")
                                        : temp.getString("d_date"))),
                                FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("d_accountname")) {
                        para = new Paragraph(
                                fontFamilySelector.process(
                                        temp.getString("d_accountname").toString() == ""
                                                ? temp.getString("c_accountname").toString()
                                                : temp.getString("d_accountname").toString(),
                                        FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("d_entryno")) {
                        para = new Paragraph(
                                fontFamilySelector.process(
                                        temp.getString("d_entryno").toString() == ""
                                                ? temp.getString("c_entryno").toString()
                                                : temp.getString("d_entryno").toString(),
                                        FontContext.TABLE_DATA));
                    } else if (colwidth2[col].equals("perioddepreciation")) {
                        double adj = temp.getDouble("perioddepreciation") - temp.getDouble("firstperiodamt");
                        String currency = currencyRender("" + adj, currencyid);
                        if (adj < 0.0001) {
                            para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA));
                        } else {
                            para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA));
                        }
                    } else if (colHeader[col].equals("Opening Balance")
                            || colHeader[col].equals("Asset Value")) {
                        String currency = currencyRender("" + Math.abs(temp.getDouble("openbalance")),
                                currencyid);
                        para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA));
                    } else {
                        if (colHeader[col].equals("Opening Balance Type")) {
                            double bal = Double.parseDouble(temp.getString(colwidth2[col]));
                            String str = bal == 0 ? "" : (bal < 0 ? "Credit" : "Debit");
                            if (str.equals(""))
                                str = "N/A";
                            para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA));
                        } else {
                            para = new Paragraph(fontFamilySelector.process(
                                    temp.getString(colwidth2[col]).toString(), FontContext.TABLE_DATA));
                        }
                    }
                }
                h1 = new PdfPCell(para);
                if (config.getBoolean("gridBorder")) {
                    h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                } else {
                    h1.setBorder(0);
                }
                h1.setPadding(4);
                h1.setBorderColor(Color.GRAY);
                if (align[col].equals("currency") || align[col].equals("rowcurrency")
                        || colwidth2[col].equals("taxrate") || colwidth2[col].equals("permargin")) {
                    h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    h1.setVerticalAlignment(Element.ALIGN_RIGHT);
                } else if (align[col].equals("date")) {
                    h1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    h1.setVerticalAlignment(Element.ALIGN_CENTER);
                } else {
                    h1.setHorizontalAlignment(Element.ALIGN_LEFT);
                    h1.setVerticalAlignment(Element.ALIGN_LEFT);
                }
                table.addCell(h1);
            }
        }
        if (mode == 116 || mode == 117) {
            Paragraph para1 = null;
            PdfPCell h3 = null;
            String totCr = "";
            String totDb = "";
            h3 = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)));
            if (config.getBoolean("gridBorder")) {
                h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT);
            } else {
                h3.setBorder(0);
            }
            h3.setPadding(4);
            h3.setBorderColor(Color.GRAY);
            h3.setBackgroundColor(Color.lightGray);
            h3.setHorizontalAlignment(Element.ALIGN_CENTER);
            h3.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h3);
            para1 = new Paragraph(fontFamilySelector.process("Total", FontContext.REPORT_TITLE));
            h3 = new PdfPCell(para1);
            if (config.getBoolean("gridBorder")) {
                h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h3.setBorder(0);
            }
            h3.setPadding(4);
            h3.setBorderColor(Color.GRAY);
            h3.setBackgroundColor(Color.LIGHT_GRAY);
            h3.setHorizontalAlignment(Element.ALIGN_LEFT);
            h3.setVerticalAlignment(Element.ALIGN_LEFT);
            table.addCell(h3);

            for (int col = 1; col < colwidth2.length; col++) {
                if (colwidth2[col].equals("c_amount")) {
                    totCr = currencyRender(String.valueOf(totalCre), currencyid);
                    para1 = new Paragraph(fontFamilySelector.process(totCr, FontContext.TABLE_DATA));
                } else if (colwidth2[col].equals("d_amount")) {
                    totDb = currencyRender(String.valueOf(totalDeb), currencyid);
                    para1 = new Paragraph(fontFamilySelector.process(totDb, FontContext.TABLE_DATA));
                } else {
                    para1 = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA));
                }

                h3 = new PdfPCell(para1);
                if (config.getBoolean("gridBorder")) {
                    h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                } else {
                    h3.setBorder(0);
                }
                h3.setPadding(4);
                h3.setBorderColor(Color.GRAY);
                h3.setBackgroundColor(Color.LIGHT_GRAY);
                h3.setHorizontalAlignment(Element.ALIGN_RIGHT);
                h3.setVerticalAlignment(Element.ALIGN_RIGHT);
                table.addCell(h3);

            }
        }
        document.add(table);
        document.newPage();
    } catch (Exception e) {
        throw ServiceException.FAILURE("exportDAOImpl.addTable", e);
    }
    return stpcol;
}

From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java

License:Open Source License

public int addGroupableTable(JSONObject groupingConfig, String groupByField, String groupHeaderText, int stcol,
        int stpcol, int strow, int stprow, JSONArray store, String[] dataIndexArr, String[] colHeader,
        String[] widths, String[] align, Document document, HttpServletRequest request)
        throws ServiceException {
    try {/*from   w ww  .ja  v a 2 s .  c o  m*/
        String groupSummaryField = groupingConfig.getString("groupSummaryField");
        String groupSummaryText = groupingConfig.getString("groupSummaryText");
        String reportSummaryField = groupingConfig.getString("reportSummaryField");
        String reportSummaryText = groupingConfig.getString("reportSummaryText");

        DateFormat formatter = authHandlerDAOObj.getUserDateFormatter(
                sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request),
                true);
        DateFormat frmt = authHandler.getDateFormatter(request);
        String currencyid = sessionHandlerImpl.getCurrencyID(request);
        java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
        java.awt.Color gsBGColor = new Color(Integer.parseInt("E5E5E5", 16));
        java.awt.Color rsBGColor = new Color(Integer.parseInt("808080", 16));
        //            fontRegular.setColor(tColor);
        PdfPTable table;

        float[] tcol;
        tcol = new float[colHeader.length + 1];
        tcol[0] = 40;
        for (int i = 1; i < colHeader.length + 1; i++) {
            tcol[i] = Float.parseFloat(widths[i - 1]);
        }
        table = new PdfPTable(colHeader.length + 1);
        table.setWidthPercentage(tcol, document.getPageSize());
        table.setSpacingBefore(15);
        PdfPCell h2 = new PdfPCell(
                new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor)));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        PdfPCell h1 = null;
        for (int hcol = stcol; hcol < dataIndexArr.length; hcol++) {
            if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) {
                String currency = currencyRender("", currencyid);
                h1 = new PdfPCell(new Paragraph(fontFamilySelector
                        .process(colHeader[hcol] + "(" + currency + ")", FontContext.TABLE_HEADER, tColor)));
            } else {
                h1 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor)));
            }
            h1.setHorizontalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setBorderColor(Color.GRAY);
            h1.setPadding(4);
            table.addCell(h1);
        }
        table.setHeaderRows(1);
        String groupName = "", rowCurrency = "";
        Double subTotal = 0.0;
        Double grandTotal = 0.0;
        int rowSpan = 0;
        for (int row = strow; row < stprow; row++) {
            rowSpan++;
            JSONObject rowData = store.getJSONObject(row);
            if (row == 0) {
                groupName = rowData.getString(groupByField);
                rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid;
                subTotal = 0.0;
                addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr);
            }
            if (!groupName.equalsIgnoreCase(rowData.getString(groupByField))) {
                addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr,
                        false, gsBGColor);
                groupName = rowData.getString(groupByField);
                rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid;
                addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr);
                subTotal = 0.0;
                rowSpan = 1;
            }
            subTotal += Double.parseDouble(rowData.getString(groupSummaryField));
            grandTotal += Double.parseDouble(rowData.getString(reportSummaryField));
            rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid;

            h2 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_HEADER, tColor)));
            if (config.getBoolean("gridBorder")) {
                h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h2.setBorder(0);
            }
            h2.setPadding(4);
            h2.setBorderColor(Color.GRAY);
            h2.setHorizontalAlignment(Element.ALIGN_CENTER);
            h2.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h2);

            for (int col = 0; col < dataIndexArr.length; col++) {
                String cellData = null;
                if (align[col].equals("currency") && !rowData.getString(dataIndexArr[col]).equals("")) {
                    cellData = currencyRender(rowData.getString(dataIndexArr[col]),
                            rowData.getString("currencyid"));
                } else if (align[col].equals("date") && !rowData.getString(dataIndexArr[col]).equals("")) {
                    try {
                        cellData = formatter.format(frmt.parse(rowData.getString(dataIndexArr[col])));
                    } catch (Exception ex) {
                        cellData = rowData.getString(dataIndexArr[col]);
                    }
                } else {
                    cellData = rowData.getString(dataIndexArr[col]);
                }

                Paragraph para = new Paragraph(
                        fontFamilySelector.process(cellData, FontContext.TABLE_HEADER, tColor));
                h1 = new PdfPCell(para);
                if (config.getBoolean("gridBorder")) {
                    h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                } else {
                    h1.setBorder(0);
                }
                h1.setPadding(4);
                h1.setBorderColor(Color.GRAY);

                if (!align[col].equals("currency") && !align[col].equals("date")) {
                    h1.setHorizontalAlignment(Element.ALIGN_LEFT);
                    h1.setVerticalAlignment(Element.ALIGN_LEFT);
                } else if (align[col].equals("currency")) {
                    h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    h1.setVerticalAlignment(Element.ALIGN_RIGHT);
                } else if (align[col].equals("date")) {
                    h1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    h1.setVerticalAlignment(Element.ALIGN_CENTER);
                }
                table.addCell(h1);
            }
        }
        if (rowSpan > 0) {
            addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr, false,
                    gsBGColor);
        }
        addSummaryRow(reportSummaryText, grandTotal, currencyid, table, dataIndexArr, false, rsBGColor);

        document.add(table);
        document.newPage();
    } catch (Exception e) {
        throw ServiceException.FAILURE("exportDAOImpl.addTable", e);
    }
    return stpcol;
}

From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java

License:Open Source License

public void addSummaryRow(String summeryText, double subTotal, String currencyid, PdfPTable table,
        String[] dataIndexArr, boolean addBlankRow, java.awt.Color bgColor)
        throws JSONException, SessionExpiredException {
    Paragraph para = new Paragraph(fontFamilySelector.process(summeryText, FontContext.TABLE_HEADER));
    PdfPCell h1 = new PdfPCell(para);
    if (config.getBoolean("gridBorder")) {
        h1.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
    } else {/* w w  w .  j  a va2  s  .c om*/
        h1.setBorder(PdfPCell.TOP);
    }
    h1.setPadding(4);
    h1.setBorderColor(Color.GRAY);
    h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    h1.setVerticalAlignment(Element.ALIGN_RIGHT);
    h1.setColspan(dataIndexArr.length);
    h1.setBackgroundColor(bgColor);
    table.addCell(h1);

    String withCurrency = currencyRender(Double.toString(subTotal), currencyid);
    para = new Paragraph(fontFamilySelector.process(withCurrency, FontContext.TABLE_HEADER));
    h1 = new PdfPCell(para);
    if (config.getBoolean("gridBorder")) {
        h1.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
    } else {
        h1.setBorder(PdfPCell.TOP);
    }
    h1.setPadding(4);
    h1.setBorderColor(Color.GRAY);
    h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    h1.setVerticalAlignment(Element.ALIGN_RIGHT);
    h1.setBackgroundColor(bgColor);
    table.addCell(h1);

    if (addBlankRow) {
        para = new Paragraph(fontFamilySelector.process(" ", FontContext.TABLE_HEADER));
        h1 = new PdfPCell(para);
        if (config.getBoolean("gridBorder")) {
            h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
        } else {
            h1.setBorder(0);
        }
        h1.setPadding(4);
        h1.setBorderColor(Color.GRAY);
        h1.setHorizontalAlignment(Element.ALIGN_LEFT);
        h1.setVerticalAlignment(Element.ALIGN_LEFT);
        h1.setColspan(dataIndexArr.length + 1);
        table.addCell(h1);
    }
}

From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java

License:Open Source License

public void addGroupRow(String groupText, String currencyid, PdfPTable table, String[] dataIndexArr)
        throws JSONException, SessionExpiredException {
    Paragraph para = new Paragraph(fontFamilySelector.process(groupText, FontContext.REPORT_TITLE));
    PdfPCell h1 = new PdfPCell(para);
    if (config.getBoolean("gridBorder")) {
        h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
    } else {//from   w w w .jav a  2  s .co m
        h1.setBorder(PdfPCell.BOTTOM);
    }
    h1.setBorderWidthBottom(1);
    h1.setPadding(4);
    h1.setBorderColor(Color.GRAY);
    h1.setBorderColorBottom(Color.DARK_GRAY);
    h1.setHorizontalAlignment(Element.ALIGN_LEFT);
    h1.setVerticalAlignment(Element.ALIGN_LEFT);
    h1.setColspan(dataIndexArr.length + 1);
    table.addCell(h1);
}