Example usage for com.lowagie.text Table Table

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

Introduction

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

Prototype

public Table(Table t) 

Source Link

Document

Copy constructor (shallow copy).

Usage

From source file:com.stratelia.webactiv.kmelia.control.Callback.java

License:Open Source License

@Override
public void handleStartTag(Tag t, MutableAttributeSet a, int pos) throws KmeliaRuntimeException {
    SilverTrace.info("kmelia", "Callback.handleStartTag", "root.MSG_ENTRY_METHOD", "t = " + t.toString());
    if (TABLE.equals(t)) {
        try {//from ww  w .  j  av  a2 s  .  c om
            tbl = new Table(Integer.parseInt(columns.get(++current_table)));
            tbl.setBorderWidth(0);
            tbl.setAlignment(Element.ALIGN_LEFT);
            attribute = a.getAttribute(Attribute.WIDTH);
            if (attribute != null) {
                attribute_value = attribute.toString();
                if ("%".equals(attribute_value.substring(attribute_value.length() - 1))) {
                    tbl.setWidth(
                            (Integer.parseInt(attribute_value.substring(0, attribute_value.length() - 1))));
                }
            }
            attribute = a.getAttribute(Attribute.CELLPADDING);
            if (attribute != null) {
                attribute_value = attribute.toString();
                tbl.setSpacing(Integer.parseInt(attribute_value));
            }
            attribute = a.getAttribute(Attribute.CELLSPACING);
            if (attribute != null) {
                attribute_value = attribute.toString();
                tbl.setPadding(Integer.parseInt(attribute_value));
            }
        } catch (Exception ex) {
            throw new KmeliaRuntimeException("Callback.handleStartTag", SilverpeasRuntimeException.WARNING,
                    "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex);
        }
    } else if (TD.equals(t)) {
        try {
            if (cl == null) {
                cl = new Cell();
                cl.setBorderWidth(0);
            }
            is_was_text = false;
        } catch (Exception ex) {
            throw new KmeliaRuntimeException("Callback.handleStartTag", SilverpeasRuntimeException.WARNING,
                    "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex);
        }
    } else if (H1.equals(t)) {
        font_size = Font.DEFAULTSIZE + 1;
    } else if (H2.equals(t)) {
        font_size = Font.DEFAULTSIZE + 2;
    } else if (H3.equals(t)) {
        font_size = Font.DEFAULTSIZE + 3;
    } else if (H4.equals(t)) {
        font_size = Font.DEFAULTSIZE + 4;
    } else if (H5.equals(t)) {
        font_size = Font.DEFAULTSIZE + 5;
    } else if (H6.equals(t)) {
        font_size = Font.DEFAULTSIZE + 6;
    } else if (FONT.equals(t)) {
        attribute = a.getAttribute(Attribute.SIZE);
        if (attribute != null) {
            font_size = Integer.parseInt(attribute.toString()) + Font.DEFAULTSIZE - 1;
        }
    } else if (t.equals(B)) {
        font_properties = font_properties | Font.BOLD;
    } else if (t.equals(I)) {
        font_properties = font_properties | Font.ITALIC;
    } else if (t.equals(U)) {
        // current PDF package doesn't support it
    }
}

From source file:datasoul.servicelist.ServiceListExporterDocument.java

License:Open Source License

public void addServicePlan() throws DocumentException {

    ServiceListTable slt = ServiceListTable.getActiveInstance();

    Paragraph p = new Paragraph(
            java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("SERVICE PLAN"),
            FontFactory.getFont(FontFactory.HELVETICA, 12));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);/*from w w w. j av a2 s  . c o m*/

    p = new Paragraph(slt.getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    Table t = new Table(4);
    t.setWidths(new int[] { 10, 5, 50, 35 });
    t.setPadding(2.0f);
    t.setWidth(100.0f);

    t.addCell(createHeaderCell(
            java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TIME")));
    t.addCell(
            createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("MIN")));
    t.addCell(createHeaderCell(
            java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TITLE")));
    t.addCell(createHeaderCell(
            java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("NOTES")));

    for (int i = 0; i < slt.getRowCount(); i++) {

        ServiceItem si = (ServiceItem) slt.getServiceItem(i);
        Cell c;

        // Start time
        c = new Cell(si.getStartTime());
        c.setMaxLines(1);
        c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        c.setHorizontalAlignment(Cell.ALIGN_CENTER);
        t.addCell(c);

        // Duration
        c = new Cell(Integer.toString(si.getDuration()));
        c.setMaxLines(1);
        c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        c.setHorizontalAlignment(Cell.ALIGN_RIGHT);
        t.addCell(c);

        // Title
        c = new Cell(si.getTitle());
        c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        t.addCell(c);

        // Notes
        c = new Cell(si.getNotes());
        c.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        t.addCell(c);

    }

    document.add(t);

    p = new Paragraph(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("NOTES"),
            FontFactory.getFont(FontFactory.HELVETICA_BOLD));
    document.add(p);

    p = new Paragraph(slt.getNotes(), FontFactory.getFont(FontFactory.HELVETICA));
    p.setIndentationLeft(10.0f);
    document.add(p);

    document.newPage();

}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

@SuppressWarnings("unchecked")
private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException {

    LineSeparator hr = new LineSeparator();
    StyleSheet styles = new StyleSheet();
    Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD);

    Iterator<ClientMessage> it = cm.iterator();
    Cell c = null;//from w  w w  .j  a va 2 s.  c  o m
    while (it.hasNext()) {
        ClientMessage fwdCm = it.next();
        if (isForward) {
            c = new Cell();
        }

        // Subject (only if isForward)
        if (isForward) {
            String subjectText = fwdCm.getSubject();
            String dateText = formatDate(fwdCm.getDate());
            Chunk subject = new Chunk(subjectText, fbold);
            Chunk date = new Chunk(dateText, fbold);
            Paragraph subjectPar = new Paragraph(subject + ", " + date);
            subjectPar.setIndentationLeft(5.0f);
            c.add(subjectPar);
            c.add(Chunk.NEWLINE);
        } else {
            String dateText = formatDate(fwdCm.getDate());
            Chunk date = new Chunk(dateText, fbold);
            Paragraph datePar = new Paragraph(date);
            datePar.setAlignment(Element.ALIGN_RIGHT);
            d.add(datePar);
        }

        // Sender
        String senderText = formatAddress(fwdCm.getSender());
        Chunk sender = new Chunk(senderText, fbold);
        sender.setTextRise(10.0f);
        Paragraph senderPar = new Paragraph(sender);
        if (isForward) {
            senderPar.setIndentationLeft(5.0f);
            c.add(senderPar);
        } else {
            d.add(senderPar);
        }

        appendRecipients(d, c, isForward, "To:", fwdCm.getTo());
        appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc());
        appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc());
        if (isForward) {
            c.add(Chunk.NEWLINE);
        }

        // Body
        String bodyText = fwdCm.getBody().getCleanHtml();
        Paragraph bodyPar = new Paragraph();
        bodyPar.setFont(fnormal);
        if (bodyText != null && !bodyText.isEmpty()) {
            try {
                List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles);
                for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) {
                    Element el = iterator.next();
                    if (!(el instanceof Image)) {
                        // bodyPar.add(el);
                        if (isForward) {
                            c.add(el);
                        } else {
                            bodyPar.add(el);
                        }
                    }
                }
            } catch (Exception e) {
                logger.warn("Cannot generate pdf from html body use plain text instead", e);
                // bodyPar.add(fwdCm.getBody().getPlain());
                if (isForward) {
                    Chunk t = new Chunk(fwdCm.getBody().getPlain());
                    t.setFont(fnormal);
                    c.add(t);
                } else {
                    bodyPar.add(fwdCm.getBody().getPlain());
                }
            }
        } else {
            if (isForward) {
                Chunk t = new Chunk(fwdCm.getBody().getPlain());
                t.setFont(fnormal);
                c.add(t);
            } else {
                bodyPar.add(fwdCm.getBody().getPlain());
            }
        }

        if (isForward) {
            // c.add(bodyPar);
            Table t = new Table(1);
            t.setPadding(5);
            t.setBackgroundColor(new Color(242, 242, 242));
            t.addCell(c);
            d.add(t);
        } else {
            bodyPar.setIndentationLeft(15.0f);
            d.add(bodyPar);
        }

        if (fwdCm.getFwdMessages() != null) {
            this.exportMessage(fwdCm.getFwdMessages(), d, true);
        }
        d.add(hr);
    }

}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Mthode principale qui gre l'export d'un tableau vers un fichier ODS.
 *
 * @param export paramtres du document  exporter
 * @param out flux de sortie//from  www.jav a  2s  . co m
 * @throws DocumentException Exception
 */
public final void exportData(final Export export, final OutputStream out) throws DocumentException {
    // step 1: creation of a document-object
    final boolean landscape = export.getOrientation() == Export.Orientation.Landscape;
    final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4;
    final Document document = new Document(pageSize, 20, 20, 50, 50); // left,
    // right,
    // top,
    // bottom
    // step 2: we create a writer that listens to the document and directs a
    // PDF-stream to out
    createWriter(document, out);

    // we add some meta information to the document, and we open it
    final String title = export.getTitle();
    if (title != null) {
        final HeaderFooter header = new HeaderFooter(new Phrase(title), false);
        header.setAlignment(Element.ALIGN_LEFT);
        header.setBorder(Rectangle.NO_BORDER);
        document.setHeader(header);
        document.addTitle(title);
    }

    final String author = export.getAuthor();
    document.addAuthor(author);
    document.addCreator(CREATOR);
    document.open();
    try {
        // pour ajouter l'ouverture automatique de la bote de dialogue
        // imprimer
        // (print(false) pour imprimer directement)
        // ((PdfWriter) writer).addJavaScript("this.print(true);", false);

        for (final ExportSheet exportSheet : export.getSheets()) {
            final Table datatable;
            if (exportSheet.hasDtObject()) {
                // table
                datatable = new Table(2);
                datatable.setCellsFitPage(true);
                datatable.setPadding(4);
                datatable.setSpacing(0);

                // data rows
                renderObject(exportSheet, datatable);
            } else {
                // table
                datatable = new Table(exportSheet.getExportFields().size());
                datatable.setCellsFitPage(true);
                datatable.setPadding(4);
                datatable.setSpacing(0);

                // headers
                renderHeaders(exportSheet, datatable);

                // data rows
                renderList(exportSheet, datatable);
            }
            document.add(datatable);
        }
    } finally {
        // we close the document
        document.close();
    }
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Mthode principale qui gre l'export d'un tableau vers un fichier ODS.
 *
 * @param export paramtres du document  exporter
 * @param out flux de sortie/*  w  ww  . j a v  a 2s  . c o  m*/
 * @throws DocumentException Exception
 */
public final void exportData(final Export export, final OutputStream out) throws DocumentException {
    // step 1: creation of a document-object
    final boolean landscape = export.getOrientation() == Export.Orientation.Landscape;
    final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4;
    final Document document = new Document(pageSize, 20, 20, 50, 50); // left, right, top, bottom
    // step 2: we create a writer that listens to the document and directs a PDF-stream to out
    createWriter(document, out);

    // we add some meta information to the document, and we open it
    final String title = export.getTitle();
    if (title != null) {
        final HeaderFooter header = new HeaderFooter(new Phrase(title), false);
        header.setAlignment(Element.ALIGN_LEFT);
        header.setBorder(Rectangle.NO_BORDER);
        document.setHeader(header);
        document.addTitle(title);
    }

    final String author = export.getAuthor();
    document.addAuthor(author);
    document.addCreator(CREATOR);
    document.open();
    try {
        // pour ajouter l'ouverture automatique de la bote de dialogue imprimer (print(false) pour imprimer directement)
        // ((PdfWriter) writer).addJavaScript("this.print(true);", false);

        for (final ExportSheet exportSheet : export.getSheets()) {
            final Table datatable;
            if (exportSheet.hasDtObject()) {
                // table
                datatable = new Table(2);
                datatable.setCellsFitPage(true);
                datatable.setPadding(4);
                datatable.setSpacing(0);

                // data rows
                renderObject(exportSheet, datatable);
            } else {
                // table
                datatable = new Table(exportSheet.getExportFields().size());
                datatable.setCellsFitPage(true);
                datatable.setPadding(4);
                datatable.setSpacing(0);

                // headers
                renderHeaders(exportSheet, datatable);

                // data rows
                renderList(exportSheet, datatable);
            }
            document.add(datatable);
        }
    } finally {
        // we close the document
        document.close();
    }
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/***
 * sets the sessions informations in the pdf document for fx or ix accounts
 * (Issue 1049)/*ww  w  . j  a v  a  2 s.  c  o m*/
 * 
 * @param document
 * @throws Exception
 */
private void setSessionTable(Document document) throws Exception {
    if (slv != null && (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)
            || proposalCode.equals(Constants.PROPOSAL_CODE_IX))) {
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) { // session
            // title
            // only
            // for
            // FX
            // accounts
            document.add(new Paragraph("Session title:", FONT_TITLE));
            document.add(new Paragraph(slv.getSessionTitle(), FONT_DOC));
        }
        Table sessionTable = new Table(2);
        // sessionTable.setWidth(50); // percentage
        sessionTable.setPadding(3);
        sessionTable.setCellsFitPage(true);
        sessionTable.getDefaultCell().setBorderWidth(0);
        sessionTable.setBorder(0);
        sessionTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        boolean hasData = false;
        // print only if the value > 0
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) { // structure
            // determinations
            // only
            // for
            // FX
            // accounts
            if (slv.getStructureDeterminations() != null && !slv.getStructureDeterminations().isNaN()
                    && slv.getStructureDeterminations() != 0) {
                hasData = true;
                sessionTable.addCell(new Paragraph("Structure determinations", FONT_DOC_BOLD));
                sessionTable.addCell(new Paragraph("" + slv.getStructureDeterminations(), FONT_DOC));
            }
        }
        if (slv.getDewarTransport() != null && !slv.getDewarTransport().isNaN()
                && slv.getDewarTransport() != 0) {
            hasData = true;
            sessionTable.addCell(new Paragraph("Dewar transport", FONT_DOC_BOLD));
            sessionTable.addCell(new Paragraph("" + slv.getDewarTransport(), FONT_DOC));
        }
        if (slv.getDatabackupFrance() != null && !slv.getDatabackupFrance().isNaN()
                && slv.getDatabackupFrance() != 0) {
            hasData = true;
            sessionTable.addCell(new Paragraph("Data backup & Express delivery France", FONT_DOC_BOLD));
            sessionTable.addCell(new Paragraph("" + slv.getDatabackupFrance(), FONT_DOC));
        }
        if (slv.getDatabackupEurope() != null && !slv.getDatabackupEurope().isNaN()
                && slv.getDatabackupEurope() != 0) {
            hasData = true;
            sessionTable.addCell(new Paragraph("Data backup & Express delivery Europe", FONT_DOC_BOLD));
            sessionTable.addCell(new Paragraph("" + slv.getDatabackupEurope(), FONT_DOC));
        }
        if (hasData) {
            document.add(sessionTable);
        }
    }
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * set the dataCollection table//w  ww.  j a  va2 s. c om
 * 
 * @param document
 * @throws Exception
 */
private void setDataCollectionTable(Document document) throws Exception {
    document.add(new Paragraph("Data Collections:", FONT_TITLE));
    document.add(new Paragraph(" "));
    if (dataCollectionList.isEmpty()) {
        document.add(new Paragraph("There is no data collection in this report", FONT_DOC));
    } else {
        Table table = new Table(NB_COL_DATACOLLECTION);
        table = setDataCollectionHeader(document, table, true);
        DecimalFormat df2 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
        df2.applyPattern("#####0.00");
        DecimalFormat df3 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
        df3.applyPattern("#####0.000");
        // DataCollection Rows
        AutoProc3VO[] autoProcs = wrapper.getAutoProcs();
        AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall();
        AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner();
        AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter();
        Session3Service sessionService = (Session3Service) ejb3ServiceLocator
                .getLocalService(Session3Service.class);
        DataCollectionGroup3Service dcgService = (DataCollectionGroup3Service) ejb3ServiceLocator
                .getLocalService(DataCollectionGroup3Service.class);

        Iterator<DataCollection3VO> it = dataCollectionList.iterator();
        int i = 0;
        while (it.hasNext()) {
            DataCollection3VO col = it.next();
            ScreeningOutput3VO screeningOutput = null;
            ScreeningOutputLattice3VO screeningOutputLattice = null;
            DataCollectionGroup3VO colGroup = dcgService.findByPk(col.getDataCollectionGroupVOId(), false,
                    true);
            Screening3VO[] tabScreening = colGroup.getScreeningsTab();
            if (tabScreening != null && tabScreening.length > 0) {
                Screening3VO screeningVO = tabScreening[0];
                ScreeningOutput3VO[] screeningOutputTab = screeningVO.getScreeningOutputsTab();
                if (screeningOutputTab != null && screeningOutputTab.length > 0) {
                    screeningOutput = screeningOutputTab[0];
                    if (screeningOutputTab[0].getScreeningOutputLatticesTab() != null
                            && screeningOutputTab[0].getScreeningOutputLatticesTab().length > 0) {
                        screeningOutputLattice = screeningOutputTab[0].getScreeningOutputLatticesTab()[0];
                    }
                }
            }
            setDataCollectionData(document, table, col, sessionService, autoProcs[i], autoProcsOverall[i],
                    autoProcsInner[i], autoProcsOuter[i], true, true, screeningOutput, screeningOutputLattice);
            i++;
        }
        document.add(table);
    }
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * set the header for the dataCollection table
 * //from www  .ja  v a2  s. c  o m
 * @param document
 * @param table
 * @throws Exception
 */
private Table setDataCollectionHeader(Document document, Table table, boolean withAutoProcessing)
        throws Exception {
    int nbCol = NB_COL_DATACOLLECTION;
    boolean withoutAutoProc = !withAutoProcessing;
    boolean withSampleName = name != null;
    boolean isIfx = proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX);
    if (withoutAutoProc) {
        nbCol -= 5;
    }
    if (withSampleName) {
        nbCol += 1;
    }
    if (isIfx) {
        nbCol += 1;
    }
    table = new Table(nbCol);
    int[] headersWidth = new int[nbCol];
    int i = 0;
    // image prefix
    headersWidth[i] = 12;
    if (withSampleName && !withAutoProcessing)
        headersWidth[i] = 10;
    i++;
    // beamline
    if (withSampleName) {
        headersWidth[i++] = 5;
    }
    // run no
    headersWidth[i++] = 5;
    // nb images
    headersWidth[i++] = 6;
    // auto proc
    if (withAutoProcessing) {
        headersWidth[i++] = 9; // space group
        headersWidth[i++] = 9; // unit cell
        headersWidth[i++] = 10; // completeness
        headersWidth[i++] = 9; // rsymm
        headersWidth[i++] = 9; // resolution
    }
    // detector
    headersWidth[i++] = 7;
    // wavelength
    headersWidth[i++] = 8;
    // phi range
    headersWidth[i++] = 5;
    // crytsl class
    if (isIfx) {
        headersWidth[i++] = 8;
    }
    // comments
    headersWidth[i++] = 17;
    //
    table.setWidths(headersWidth);

    table.setWidth(100); // percentage
    table.setPadding(3);
    table.setCellsFitPage(true);
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    // DataCollection Header

    table.getDefaultCell().setGrayFill(GREY_FILL_HEADER);
    table.addCell(new Paragraph("Image prefix", FONT_DOC_BOLD));
    if (withSampleName)
        table.addCell(new Paragraph("Beamline", FONT_DOC_BOLD));
    table.addCell(new Paragraph("Run no", FONT_DOC_BOLD));
    table.addCell(new Paragraph("# images", FONT_DOC_BOLD));
    if (withAutoProcessing) {
        table.addCell(new Paragraph("Space Group", FONT_DOC_BOLD));
        table.addCell(new Paragraph("Unit Cell", FONT_DOC_BOLD));
        table.addCell(new Paragraph("Completeness (Inner, Outer, Overall)", FONT_DOC_BOLD));
        table.addCell(new Paragraph("Rsymm (Inner, Outer, Overall)", FONT_DOC_BOLD));
        table.addCell(new Paragraph("Resolution", FONT_DOC_BOLD));
    }
    table.addCell(new Paragraph("Detector\nResolution\n(" + Constants.ANGSTROM + ")", FONT_DOC_BOLD));
    table.addCell(new Paragraph("Wavelength\n(" + Constants.ANGSTROM + ")", FONT_DOC_BOLD));
    table.addCell(new Paragraph("Phi range\n(" + Constants.DEGREE + ")", FONT_DOC_BOLD));
    // Column crystalClass only for IFX proposal in case of MXPress
    // experiment
    if (isIfx)
        table.addCell(new Paragraph("Crystal class", FONT_DOC_BOLD));
    table.addCell(new Paragraph("Comments", FONT_DOC_BOLD));
    table.getDefaultCell().setBorderWidth(1);
    return table;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * set the energy scan table//from  w  ww  . ja  v a 2 s.  c  o m
 * 
 * @param document
 * @throws Exception
 */
private void setEnergyScansTable(Document document) throws Exception {
    if (slv == null) {// if session is null, no sense to display energy
                      // scans
        return;
    }
    document.add(new Paragraph("Energy Scans:", FONT_TITLE));
    document.add(new Paragraph(" "));
    if (energyScanList == null || energyScanList.isEmpty()) {
        document.add(new Paragraph("There is no energy scan in this report", FONT_DOC));
    } else {
        int NumColumnsES = 12;
        Table tableES = new Table(NumColumnsES);
        int headerwidthsSessionES[] = { 7, 7, 7, 7, 7, 7, 6, 6, 7, 7, 7, 25 }; // percentage
        int headerwidthsMXPressES[] = { 7, 7, 7, 7, 7, 7, 6, 6, 7, 7, 7, 8, 17 }; // percentage
        tableES.setWidths(headerwidthsSessionES);
        // Column crystalClass added only for IFX proposal in case of
        // MXPress experiment
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) {
            tableES = new Table(NumColumnsES + 1);
            tableES.setWidths(headerwidthsMXPressES);
        }

        tableES.setWidth(100); // percentage
        tableES.setPadding(3);
        tableES.setCellsFitPage(true);
        tableES.getDefaultCell().setBorderWidth(1);
        tableES.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        // Energy Scan Header

        tableES.getDefaultCell().setGrayFill(GREY_FILL_HEADER);
        tableES.addCell(new Paragraph("Element", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Inflection Energy\n(keV)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Exposure Time\n(s)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Inflection f'\n(e)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Inflection f''\n(e)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Peak Energy\n(keV)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Peak f'\n(e)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Peak f''\n(e)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Beam size Hor.\n(" + Constants.MICRO + "m)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Beam size Ver.\n(" + Constants.MICRO + "m)", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Transm. Factor\n(%)", FONT_DOC_BOLD));
        // Column crystalClass only for IFX proposal in case of MXPress
        // experiment
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX))
            tableES.addCell(new Paragraph("Crystal class", FONT_DOC_BOLD));
        tableES.addCell(new Paragraph("Comments", FONT_DOC_BOLD));
        tableES.getDefaultCell().setGrayFill(GREY_FILL_DATA);
        tableES.getDefaultCell().setBorderWidth(1);

        // Energy Scan Rows

        Iterator<EnergyScan3VO> itES = energyScanList.iterator();
        while (itES.hasNext()) {
            EnergyScan3VO col = itES.next();

            if (col.getElement() != null)
                tableES.addCell(new Paragraph(col.getElement().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getExposureTime() != null)
                tableES.addCell(new Paragraph(col.getExposureTime().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getInflectionEnergy() != null)
                tableES.addCell(new Paragraph(col.getInflectionEnergy().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getInflectionFPrime() != null)
                tableES.addCell(new Paragraph(col.getInflectionFPrime().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getInflectionFDoublePrime() != null)
                tableES.addCell(new Paragraph(col.getInflectionFDoublePrime().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getPeakEnergy() != null)
                tableES.addCell(new Paragraph(col.getPeakEnergy().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getPeakFPrime() != null)
                tableES.addCell(new Paragraph(col.getPeakFPrime().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getPeakFDoublePrime() != null)
                tableES.addCell(new Paragraph(col.getPeakFDoublePrime().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getBeamSizeHorizontal() != null)
                tableES.addCell(new Paragraph(col.getBeamSizeHorizontal().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getBeamSizeVertical() != null)
                tableES.addCell(new Paragraph(col.getBeamSizeVertical().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (col.getTransmissionFactor() != null)
                tableES.addCell(new Paragraph(col.getTransmissionFactor().toString(), FONT_DOC));
            else
                tableES.addCell("");

            if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) {
                // if (col.getCrystalClass()!= null) tableES.addCell(new
                // Paragraph(col.getCrystalClass().toString(),
                // new Font(Font.HELVETICA, 8)));
                // else tableES.addCell("");
                if (col.getCrystalClass() != null) {
                    int idCC = getCrystalClassIndex(listOfCrystalClass,
                            col.getCrystalClass().trim().toUpperCase());
                    if (idCC == -1) {
                        tableES.addCell(new Paragraph(col.getCrystalClass().toString(), FONT_DOC));
                    } else
                        tableES.addCell(
                                new Paragraph(listOfCrystalClass.get(idCC).getCrystalClassName(), FONT_DOC));
                } else
                    tableES.addCell("");
            }

            tableES.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            if (col.getComments() != null)
                tableES.addCell(new Paragraph(col.getComments().toString(), FONT_DOC));
            else
                tableES.addCell("");
            tableES.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        }
        document.add(tableES);
    }
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * set the XFR Spectra table//from   ww  w. j a v a2 s  .  c o  m
 * 
 * @param document
 * @throws Exception
 */
private void setXfrSpectraTable(Document document) throws Exception {
    if (slv == null) {// if session is null, no sense to display XFRSpectra
        return;
    }
    document.add(new Paragraph("XRF Spectra:", FONT_TITLE));
    document.add(new Paragraph(" "));
    if (xfeList == null || xfeList.isEmpty()) {
        document.add(new Paragraph("There is no XRF spectra in this report", FONT_DOC));
    } else {
        int NumColumnsXRF = 6;
        Table tableXRF = new Table(NumColumnsXRF);
        int headerwidthsSessionXRF[] = { 15, 15, 15, 15, 15, 25 }; // percentage
        int headerwidthsMXPressXRF[] = { 16, 16, 15, 15, 15, 8, 17 }; // percentage
        tableXRF.setWidths(headerwidthsSessionXRF);
        // Column crystalClass added only for IFX proposal in case of
        // MXPress experiment
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) {
            tableXRF = new Table(NumColumnsXRF + 1);
            tableXRF.setWidths(headerwidthsMXPressXRF);
        }

        tableXRF.setWidth(100); // percentage
        tableXRF.setPadding(3);
        tableXRF.setCellsFitPage(true);
        tableXRF.getDefaultCell().setBorderWidth(1);
        tableXRF.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        // XRF Spectra Header

        tableXRF.getDefaultCell().setGrayFill(GREY_FILL_HEADER);
        tableXRF.addCell(new Paragraph("Energy\n(keV)", FONT_DOC_BOLD));
        tableXRF.addCell(new Paragraph("Exposure Time\n(s)", FONT_DOC_BOLD));
        tableXRF.addCell(new Paragraph("Beam size Hor.\n(" + Constants.MICRO + "m)", FONT_DOC_BOLD));
        tableXRF.addCell(new Paragraph("Beam size Ver.\n(" + Constants.MICRO + "m)", FONT_DOC_BOLD));
        tableXRF.addCell(new Paragraph("Transm. Factor\n(%)", FONT_DOC_BOLD));
        // Column crystalClass only for IFX proposal in case of MXPress
        // experiment
        if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX))
            tableXRF.addCell(new Paragraph("Crystal class", FONT_DOC_BOLD));
        tableXRF.addCell(new Paragraph("Comments", FONT_DOC_BOLD));
        tableXRF.getDefaultCell().setGrayFill(GREY_FILL_DATA);
        tableXRF.getDefaultCell().setBorderWidth(1);

        // XRF Spectra Rows
        Iterator<XFEFluorescenceSpectrum3VO> itES = xfeList.iterator();
        while (itES.hasNext()) {
            XFEFluorescenceSpectrum3VO col = itES.next();
            if (col.getEnergy() != null)
                tableXRF.addCell(new Paragraph(col.getEnergy().toString(), FONT_DOC));
            else
                tableXRF.addCell("");

            if (col.getExposureTime() != null)
                tableXRF.addCell(new Paragraph(col.getExposureTime().toString(), FONT_DOC));
            else
                tableXRF.addCell("");

            if (col.getBeamSizeHorizontal() != null)
                tableXRF.addCell(new Paragraph(col.getBeamSizeHorizontal().toString(), FONT_DOC));
            else
                tableXRF.addCell("");

            if (col.getBeamSizeVertical() != null)
                tableXRF.addCell(new Paragraph(col.getBeamSizeVertical().toString(), FONT_DOC));
            else
                tableXRF.addCell("");

            if (col.getBeamTransmission() != null)
                tableXRF.addCell(new Paragraph(col.getBeamTransmission().toString(), FONT_DOC));
            else
                tableXRF.addCell("");

            if (proposalCode.toLowerCase().equals(Constants.PROPOSAL_CODE_FX)) {
                // if (col.getCrystalClass()!= null) tableXRF.addCell(new
                // Paragraph(col.getCrystalClass().toString(), new
                // Font(Font.HELVETICA, 8)));
                // else tableXRF.addCell("");
                if (col.getCrystalClass() != null) {
                    int idCC = getCrystalClassIndex(listOfCrystalClass,
                            col.getCrystalClass().trim().toUpperCase());
                    if (idCC == -1) {
                        tableXRF.addCell(new Paragraph(col.getCrystalClass().toString(), FONT_DOC));
                    } else
                        tableXRF.addCell(
                                new Paragraph(listOfCrystalClass.get(idCC).getCrystalClassName(), FONT_DOC));
                } else
                    tableXRF.addCell("");
            }

            tableXRF.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            if (col.getComments() != null)
                tableXRF.addCell(new Paragraph(col.getComments().toString(), FONT_DOC));
            else
                tableXRF.addCell("");
            tableXRF.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        }
        document.add(tableXRF);
    }
}