Example usage for com.lowagie.text Cell Cell

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

Introduction

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

Prototype

public Cell() 

Source Link

Document

Constructs an empty Cell.

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 a  va2 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: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;/*w ww. j a  v a 2s  .  c om*/
    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:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * set a table for a sessionDataObject//from   w  w w.j ava  2  s . c o m
 * 
 * @param document
 * @param sessionDataObject
 * @param mRequest
 */
private void setDetailSessionObjectTable(Document document, SessionDataObjectInformation sessionDataObject,
        HttpServletRequest mRequest) {
    try {
        int nbCol = 6;
        int nbRows = 5;
        List<Param> listParam = sessionDataObject.getListParameters();
        int idParam = 0;
        int nbParam = listParam.size();
        nbRows = Math.max(nbRows, nbParam);
        boolean secondGraph = sessionDataObject.getGraph2Path() != null
                && !sessionDataObject.getGraph2Path().isEmpty();
        if (secondGraph)
            nbCol += 1;

        Table table = new Table(nbCol);

        int l = 0;

        int[] headersWidth = new int[nbCol];

        headersWidth[l++] = 10; // def
        headersWidth[l++] = 6; // parameters title
        headersWidth[l++] = 6; // parameters value
        headersWidth[l++] = 12; // Thumbnail
        headersWidth[l++] = 12; // Snapshot
        headersWidth[l++] = 22; // Graph
        if (secondGraph)
            headersWidth[l++] = 22; // Graph2
        table.setWidths(headersWidth);

        table.setWidth(100); // percentage
        table.setPadding(1);
        table.setCellsFitPage(true);
        table.setTableFitsPage(true);
        table.setBorderWidth(1);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        // no header
        // first Row
        // firstCell: def : date
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        String collectTime = formatter.format(sessionDataObject.getDataTime());
        Cell c = getCellValue(collectTime);
        c.setBorderWidthBottom(0);
        table.addCell(c);
        // second Cell param
        setCellParam(table, listParam, idParam++, 1);
        // third Cell : thumbnail
        Cell cellThumbnail = getCellImage(sessionDataObject.getImageThumbnailPath());
        cellThumbnail.setRowspan(nbRows);
        cellThumbnail.setBorderWidth(0);
        table.addCell(cellThumbnail);
        // 4 Cell : snapshot
        Cell cellSnapshot = getCellImage(sessionDataObject.getCrystalSnapshotPath());
        cellSnapshot.setRowspan(nbRows);
        cellSnapshot.setBorderWidth(0);
        table.addCell(cellSnapshot);
        // 5 Cell : graph
        Cell cellGraph = getCellGraph(sessionDataObject);
        cellGraph.setRowspan(nbRows);
        cellGraph.setBorderWidth(0);
        table.addCell(cellGraph);
        // 6 Cell : graph2
        if (secondGraph) {
            Cell cellGraph2 = getCellImage(sessionDataObject.getGraph2Path());
            cellGraph2.setRowspan(nbRows);
            cellGraph2.setBorderWidth(0);
            table.addCell(cellGraph2);
        }

        // second row
        Cell c2 = getCellValue(sessionDataObject.getImagePrefix() + " " + sessionDataObject.getRunNumber());
        c2.setBorderWidth(0);
        table.addCell(c2);
        // param2
        setCellParam(table, listParam, idParam++, 1);

        // third row
        Cell c3 = getCellValue(sessionDataObject.getExperimentType());
        c3.setBorderWidth(0);
        table.addCell(c3);
        // param3
        setCellParam(table, listParam, idParam++, 1);

        // 4 row
        Cell c4 = getCellValue(sessionDataObject.getSampleNameProtein());
        c4.setBorderWidth(0);
        table.addCell(c4);
        // param4
        setCellParam(table, listParam, idParam++, 1);

        // 5 row
        Cell c5 = new Cell();
        c5.setHorizontalAlignment(Element.ALIGN_LEFT);
        c5.add(new Paragraph(sessionDataObject.getComments(), FONT_DOC_ITALIC));
        c5.setBorderWidth(0);
        c5.setRowspan(nbRows - 4);
        table.addCell(c5);
        // param4
        setCellParam(table, listParam, idParam++, 1);

        for (int i = 5; i < nbRows; i++) {
            setCellParam(table, listParam, idParam++, 1);
        }

        // results
        // workflow result status
        if (sessionDataObject.isWorkflow()) {
            Cell resultCell = getWorkflowResult(sessionDataObject.getWorkflow(), mRequest);
            resultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
            resultCell.setColspan(nbCol);
            table.addCell(resultCell);
        }
        // collect OSC
        if ((sessionDataObject.isDataCollection()
                && !sessionDataObject.getDataCollection().getDataCollectionGroupVO().getExperimentType()
                        .equals(Constants.EXPERIMENT_TYPE_CHARACTERIZATION))) {
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollection3VO dataCollection = sessionDataObject.getDataCollection();
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dataCollection,
                    getSampleRankingVO(dataCollection.getDataCollectionId()),
                    getAutoProcRankingVO(dataCollection.getDataCollectionId()));
            Cell resultCell = getAutoProcResultStatus(dcInfo);
            resultCell.setColspan(nbCol);
            resultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(resultCell);
            document.add(table);
            document.add(new Paragraph(" ", VERY_SMALL_FONT));

            setAutoProcResultsTable(document, dcInfo);
        } else if (sessionDataObject.isWorkflow() && sessionDataObject.getWorkflow().isMXPressEOIA()) { // MXPRESS
            // wf
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollection3VO dataCollection = sessionDataObject.getListDataCollection().get(0);
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dataCollection,
                    getSampleRankingVO(dataCollection.getDataCollectionId()),
                    getAutoProcRankingVO(dataCollection.getDataCollectionId()));
            Cell resultCell = getAutoProcResultStatus(dcInfo);
            resultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
            resultCell.setColspan(nbCol);
            table.addCell(resultCell);

            document.add(table);
            document.add(new Paragraph(" ", VERY_SMALL_FONT));

            setAutoProcResultsTable(document, dcInfo);
        } else if ((sessionDataObject.isDataCollection()
                && sessionDataObject.getDataCollection().getDataCollectionGroupVO().getExperimentType()
                        .equals(Constants.EXPERIMENT_TYPE_CHARACTERIZATION))) { // Characterization
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollection3VO dataCollection = sessionDataObject.getDataCollection();
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dataCollection,
                    getSampleRankingVO(dataCollection.getDataCollectionId()),
                    getAutoProcRankingVO(dataCollection.getDataCollectionId()));
            Cell resultCell = getCharacterizationResultStatus(dcInfo, mRequest);
            resultCell.setColspan(nbCol);
            resultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(resultCell);
            document.add(table);
            document.add(new Paragraph(" ", VERY_SMALL_FONT));

            setStrategyTable2(document, dcInfo);
        } else {
            List<Param> listResults = sessionDataObject.getListResults();
            if (listResults != null) {
                int nbResults = listResults.size();
                for (int j = 0; j < nbResults; j++) {
                    setCellParam(table, listResults, j, 2);
                    Cell eCell = getEmptyCell(nbCol - 3);
                    eCell.setBorderWidth(0);
                    table.addCell(eCell);
                }
            }
            document.add(table);
            document.add(new Paragraph(" ", FONT_SPACE));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

/**
 * returns the cell for the result of a workflow: status of this workflow
 * //from   ww w . jav a  2  s  .  c  o  m
 * @param workflow
 * @param mRequest
 * @return
 * @throws BadElementException
 * @throws MalformedURLException
 * @throws IOException
 */
private Cell getWorkflowResult(Workflow3VO workflow, HttpServletRequest mRequest)
        throws BadElementException, MalformedURLException, IOException {
    Cell resultsCell = new Cell();
    Paragraph p = new Paragraph();

    if (workflow != null && workflow.getWorkflowType() != null) {
        p.add(new Phrase(workflow.getWorkflowType() + " ", FONT_DOC_BOLD));
        String img = mRequest.getRealPath(Constants.IMAGE_BLANK);
        String wfStatus = workflow.getStatus();
        if (wfStatus != null) {
            if (wfStatus.equals("Failure")) {
                img = mRequest.getRealPath(Constants.IMAGE_FAILED);
            } else if (wfStatus.equals("Launched")) {
                img = mRequest.getRealPath(Constants.IMAGE_LAUNCHED);
            } else if (wfStatus.equals("Success")) {
                img = mRequest.getRealPath(Constants.IMAGE_SUCCESS);
            }
        }
        p.add(getChunkImage(img));
        p.add(new Phrase("  "));
    }

    resultsCell.add(p);
    return resultsCell;
}

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

License:Open Source License

/**
 * get Status for Characterization (indexing and Strategy)
 * //from www  . ja  v  a 2  s .co  m
 * @param dcInfo
 * @param mRequest
 * @return
 * @throws BadElementException
 * @throws MalformedURLException
 * @throws IOException
 */
private Cell getCharacterizationResultStatus(DataCollectionInformation dcInfo, HttpServletRequest mRequest)
        throws BadElementException, MalformedURLException, IOException {
    Cell resultsCell = new Cell();
    Paragraph p = new Paragraph();
    if (dcInfo != null && dcInfo.getScreeningIndexingSuccess() != null) {
        p.add(new Phrase("Indexing ", FONT_DOC_BOLD));
        String img = mRequest.getRealPath(Constants.IMAGE_FAILED);
        if (dcInfo.getScreeningIndexingSuccess() == 1) {
            img = mRequest.getRealPath(Constants.IMAGE_SUCCESS);
        }
        p.add(getChunkImage(img));
        p.add(new Phrase("  "));
    }

    if (dcInfo != null && dcInfo.getScreeningStrategySuccess() != null) {
        p.add(new Phrase("Strategy ", FONT_DOC_BOLD));
        String img = mRequest.getRealPath(Constants.IMAGE_FAILED);
        if (dcInfo.getScreeningStrategySuccess() == 1) {
            img = mRequest.getRealPath(Constants.IMAGE_SUCCESS);
        }
        p.add(getChunkImage(img));
        p.add(new Phrase("  "));
    }

    resultsCell.add(p);
    return resultsCell;
}

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

License:Open Source License

/**
 * set a cell for a param or empty cell if no more param in the list
 * /* ww  w. j a v a2  s  .  c o  m*/
 * @param table
 * @param listParam
 * @param id
 * @param colSpanTitle
 * @throws Exception
 */
private void setCellParam(Table table, List<Param> listParam, int id, int colSpanTitle) throws Exception {
    if (id < listParam.size()) {
        Param param = listParam.get(id);
        Cell cellTitle = new Cell();
        cellTitle.setBorderWidth(0);
        cellTitle.setColspan(colSpanTitle);
        cellTitle.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellTitle.add(new Paragraph(param.getText(), FONT_DOC_PARAM_TITLE));
        table.addCell(cellTitle);

        Cell cellValue = new Cell();
        cellValue.setBorderWidth(0);
        cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellValue.add(new Paragraph(param.getValue(), FONT_DOC));
        table.addCell(cellValue);
    } else {
        Cell cellTitle = getEmptyCell(1);
        cellTitle.setBorderWidth(0);
        cellTitle.setColspan(colSpanTitle);
        table.addCell(cellTitle);

        Cell cellValue = getEmptyCell(1);
        cellValue.setBorderWidth(0);
        table.addCell(cellValue);
    }
}

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

License:Open Source License

/**
 * returns a simple cell witha given value inside
 * //from   w w  w .  j a  va  2 s . c  o m
 * @param value
 * @return
 */
private Cell getCellValue(String value) {
    Cell cell = new Cell();
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.add(new Paragraph(value, FONT_DOC_BOLD));
    cell.setColspan(1);
    return cell;
}

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

License:Open Source License

/**
 * return the cell with the status of the different autoProc
 * /*from   w w  w  .  j  a  v  a 2s  .  com*/
 * @param dcInfo
 * @return
 * @throws IOException
 * @throws MalformedURLException
 * @throws BadElementException
 */
private Cell getAutoProcResultStatus(DataCollectionInformation dcInfo)
        throws BadElementException, MalformedURLException, IOException {
    Cell resultsCell = new Cell();
    Paragraph p = new Paragraph();
    // edna
    if (dcInfo != null && dcInfo.getAutoProcEdnaStatus() != null) {
        p.add(new Phrase("EDNA_proc ", FONT_DOC_BOLD));
        p.add(getChunkImage(dcInfo.getAutoProcEdnaStatus()));
        p.add(new Phrase("  "));
    }

    // fastproc
    if (dcInfo != null && dcInfo.getAutoProcFastStatus() != null) {
        p.add(new Phrase("grenades_fastproc ", FONT_DOC_BOLD));
        p.add(getChunkImage(dcInfo.getAutoProcFastStatus()));
        p.add(new Phrase("  "));
    }

    // parallelproc
    if (dcInfo != null && dcInfo.getAutoProcParallelStatus() != null) {
        p.add(new Phrase("grenades_parallelproc ", FONT_DOC_BOLD));
        p.add(getChunkImage(dcInfo.getAutoProcParallelStatus()));
        p.add(new Phrase("  "));
    }
    resultsCell.add(p);
    return resultsCell;
}

From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java

License:Open Source License

public static Cell columnHeaderCell(String label, boolean leaf, int hAlign) throws BadElementException {
    Paragraph para = new Paragraph(label);
    para.setFont(new Font(Font.HELVETICA, BODY_FONT_SIZE, Font.NORMAL, Color.WHITE));

    Cell cell = new Cell();
    cell.addElement(para);/* w w  w  .  ja  v a 2s.c  o  m*/
    cell.setHorizontalAlignment(hAlign);
    cell.setHeader(true);
    cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
    cell.setBackgroundColor(BLUE3);

    cell.setBorderWidth(0);

    return cell;
}

From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java

License:Open Source License

public static Cell cornerCell() {
    Cell cell = new Cell();
    cell.setHeader(true);/*from  w w w .  j  a v  a 2 s  .c  o  m*/
    cell.setBorderWidth(0);
    cell.setBackgroundColor(BLUE3);
    return cell;
}