Example usage for com.lowagie.text Anchor setName

List of usage examples for com.lowagie.text Anchor setName

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Sets the name of this Anchor.

Usage

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes information about the provided optimizing job to the document.
 *
 * @param  document       The document to which the job information should be
 *                        written.// w ww .  ja  v  a 2 s  . co  m
 * @param  optimizingJob  The optimizing job to include in the document.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 */
private void writeOptimizingJob(Document document, OptimizingJob optimizingJob) throws DocumentException {
    Anchor anchor = new Anchor("Optimizing Job " + optimizingJob.getOptimizingJobID(),
            FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
    anchor.setName(optimizingJob.getOptimizingJobID());
    Paragraph p = new Paragraph(anchor);
    document.add(p);

    // Write the general information to the document.
    p = new Paragraph("General Information",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    document.add(p);

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setWidths(new int[] { 30, 70 });
    writeTableCell(table, "Optimizing Job ID");
    writeTableCell(table, optimizingJob.getOptimizingJobID());

    writeTableCell(table, "Job Type");
    writeTableCell(table, optimizingJob.getJobClassName());

    String descriptionStr = optimizingJob.getDescription();
    if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
        descriptionStr = "(Not Specified)";
    }
    writeTableCell(table, "Base Description");
    writeTableCell(table, descriptionStr);

    writeTableCell(table, "Include Thread Count in Description");
    writeTableCell(table, String.valueOf(optimizingJob.includeThreadsInDescription()));

    writeTableCell(table, "Job State");
    writeTableCell(table, Constants.jobStateToString(optimizingJob.getJobState()));
    document.add(table);

    // Write the schedule config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Schedule Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date startTime = optimizingJob.getStartTime();
        String startStr;
        if (startTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(startTime);
        }
        writeTableCell(table, "Scheduled Start Time");
        writeTableCell(table, startStr);

        int duration = optimizingJob.getDuration();
        String durationStr;
        if (duration > 0) {
            durationStr = duration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Job Duration");
        writeTableCell(table, durationStr);

        writeTableCell(table, "Delay Between Iterations");
        writeTableCell(table, optimizingJob.getDelayBetweenIterations() + " seconds");

        writeTableCell(table, "Number of Clients");
        writeTableCell(table, String.valueOf(optimizingJob.getNumClients()));

        String[] requestedClients = optimizingJob.getRequestedClients();
        if ((requestedClients != null) && (requestedClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < requestedClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Requested Clients");
            table.addCell(clientTable);
        }

        String[] monitorClients = optimizingJob.getResourceMonitorClients();
        if ((monitorClients != null) && (monitorClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < monitorClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Resource Monitor Clients");
            table.addCell(clientTable);
        }

        writeTableCell(table, "Minimum Number of Threads");
        writeTableCell(table, String.valueOf(optimizingJob.getMinThreads()));

        int maxThreads = optimizingJob.getMaxThreads();
        String maxThreadsStr;
        if (maxThreads > 0) {
            maxThreadsStr = String.valueOf(maxThreads);
        } else {
            maxThreadsStr = "(Not Specified)";
        }
        writeTableCell(table, "Maximum Number of Threads");
        writeTableCell(table, maxThreadsStr);

        writeTableCell(table, "Thread Increment Between Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getThreadIncrement()));

        writeTableCell(table, "Statistics Collection Interval");
        writeTableCell(table, optimizingJob.getCollectionInterval() + " seconds");
        document.add(table);
    }

    // Get the optimization algorithm used.
    OptimizationAlgorithm optimizationAlgorithm = optimizingJob.getOptimizationAlgorithm();
    ParameterList paramList = optimizationAlgorithm.getOptimizationAlgorithmParameters();
    Parameter[] optimizationParams = paramList.getParameters();

    // Write the optimizing config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Optimization Settings",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        for (int i = 0; i < optimizationParams.length; i++) {
            writeTableCell(table, optimizationParams[i].getDisplayName());
            writeTableCell(table, optimizationParams[i].getDisplayValue());
        }

        writeTableCell(table, "Maximum Consecutive Non-Improving Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getMaxNonImproving()));

        writeTableCell(table, "Re-Run Best Iteration");
        writeTableCell(table, String.valueOf(optimizingJob.reRunBestIteration()));

        int reRunDuration = optimizingJob.getReRunDuration();
        String durationStr;
        if (reRunDuration > 0) {
            durationStr = reRunDuration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Re-Run Duration");
        writeTableCell(table, durationStr);

        document.add(table);
    }

    // Write the job-specific config to the document if appropriate.
    if (includeJobConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Parameter Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Parameter[] params = optimizingJob.getParameters().getParameters();
        for (int i = 0; i < params.length; i++) {
            writeTableCell(table, params[i].getDisplayName());
            writeTableCell(table, params[i].getDisplayValue());
        }

        document.add(table);
    }

    // Write the statistical data to the document if appropriate.
    if (includeStats && optimizingJob.hasStats()) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Execution Data",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date actualStartTime = optimizingJob.getActualStartTime();
        String startTimeStr;
        if (actualStartTime == null) {
            startTimeStr = "(Not Available)";
        } else {
            startTimeStr = dateFormat.format(actualStartTime);
        }
        writeTableCell(table, "Actual Start Time");
        writeTableCell(table, startTimeStr);

        Date actualStopTime = optimizingJob.getActualStopTime();
        String stopTimeStr;
        if (actualStopTime == null) {
            stopTimeStr = "(Not Available)";
        } else {
            stopTimeStr = dateFormat.format(actualStopTime);
        }
        writeTableCell(table, "Actual Stop Time");
        writeTableCell(table, stopTimeStr);

        Job[] iterations = optimizingJob.getAssociatedJobs();
        if ((iterations != null) && (iterations.length > 0)) {
            writeTableCell(table, "Job Iterations Completed");
            writeTableCell(table, String.valueOf(iterations.length));

            int optimalThreadCount = optimizingJob.getOptimalThreadCount();
            String threadStr;
            if (optimalThreadCount > 0) {
                threadStr = String.valueOf(optimalThreadCount);
            } else {
                threadStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Thread Count");
            writeTableCell(table, threadStr);

            double optimalValue = optimizingJob.getOptimalValue();
            String valueStr;
            if (optimalThreadCount > 0) {
                valueStr = decimalFormat.format(optimalValue);
            } else {
                valueStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Value");
            writeTableCell(table, valueStr);

            String optimalID = optimizingJob.getOptimalJobID();
            writeTableCell(table, "Optimal Job Iteration");
            if ((optimalID == null) || (optimalID.length() == 0)) {
                writeTableCell(table, "(Not Available)");
            } else if (includeOptimizingIterations) {
                anchor = new Anchor(optimalID,
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + optimalID);
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, optimalID);
            }
        }

        Job reRunIteration = optimizingJob.getReRunIteration();
        if (reRunIteration != null) {
            writeTableCell(table, "Re-Run Iteration");
            if (includeOptimizingIterations) {
                anchor = new Anchor(reRunIteration.getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + reRunIteration.getJobID());
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, reRunIteration.getJobID());
            }

            String valueStr;
            try {
                double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(reRunIteration);
                valueStr = decimalFormat.format(iterationValue);
            } catch (Exception e) {
                valueStr = "N/A";
            }

            writeTableCell(table, "Re-Run Iteration Value");
            writeTableCell(table, valueStr);
        }

        document.add(table);

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            document.add(new Paragraph(" "));
            p = new Paragraph("Job Iterations",
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
            document.add(p);

            table = new PdfPTable(2);
            table.setWidthPercentage(100);
            table.setWidths(new int[] { 50, 50 });

            for (int i = 0; i < iterations.length; i++) {
                String valueStr;
                try {
                    double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(iterations[i]);
                    valueStr = decimalFormat.format(iterationValue);
                } catch (Exception e) {
                    valueStr = "N/A";
                }

                anchor = new Anchor(iterations[i].getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + iterations[i].getJobID());
                table.addCell(new PdfPCell(anchor));
                writeTableCell(table, valueStr);
            }

            document.add(table);
        }

        if (includeGraphs && (iterations != null) && (iterations.length > 0)) {
            String[] statNames = iterations[0].getStatTrackerNames();
            for (int j = 0; j < statNames.length; j++) {
                StatTracker[] trackers = iterations[0].getStatTrackers(statNames[j]);
                if ((trackers != null) && (trackers.length > 0)) {
                    StatTracker tracker = trackers[0].newInstance();
                    tracker.aggregate(trackers);

                    try {
                        document.newPage();
                        ParameterList params = tracker.getGraphParameterStubs(iterations);
                        BufferedImage graphImage = tracker.createGraph(iterations,
                                Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            for (int i = 0; i < iterations.length; i++) {
                document.newPage();
                writeJob(document, iterations[i]);
            }
        }
        if (includeOptimizingIterations && (reRunIteration != null)) {
            document.newPage();
            writeJob(document, reRunIteration);
        }
    }
}

From source file:de.xirp.report.ReportGenerator.java

License:Open Source License

/**
 * Adds the title page with the given header string to the PDF
 * {@link com.lowagie.text.Document}./*from  www  .  ja va2 s . c  o m*/
 * 
 * @param heading
 *            The header text.
 * @throws DocumentException
 *             if something went wrong adding the page.
 * @see com.lowagie.text.Document
 */
private static void addTitle(String heading) throws DocumentException {

    para = getParagraph(heading, HEADER, Element.ALIGN_CENTER);
    document.add(para);
    addSkip(3);
    para = getParagraph(Constants.NON_UNICODE_APP_NAME, IMAGE, Image.ALIGN_CENTER);
    document.add(para);

    addSkip();

    para = getParagraph(I18n.getString("ReportGenerator.report.header.website"), TEXT, //$NON-NLS-1$
            Element.ALIGN_CENTER);
    document.add(para);

    para = getParagraph(Constants.LINE_SEPARATOR, TEXT, Element.ALIGN_CENTER);
    TEXT.setColor(new Color(0, 0, 255));
    Anchor anchor = new Anchor(I18n.getString("ReportGenerator.report.websiteLink"), TEXT); //$NON-NLS-1$
    anchor.setReference(I18n.getString("ReportGenerator.report.websiteLink")); //$NON-NLS-1$
    anchor.setName("homepage"); //$NON-NLS-1$
    para.add(anchor);
    document.add(para);
    document.newPage();
    TEXT.setColor(new Color(0, 0, 0));

    document.newPage();
}

From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java

License:Open Source License

private static void addContent(Document document, List<EventoBean> eventi, IEventiService eventiService)
        throws UtilsException, DocumentException {
    Anchor anchor = new Anchor("Eventi Selezionati", catFont);
    anchor.setName("Eventi Selezionati");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    for (EventoBean eventoBean : eventi) {

        Evento evento = eventoBean.getDTO();
        Paragraph subPara = new Paragraph("Evento Id[" + evento.getId() + "]", subFont);

        Section subCatPart = catPart.addSection(subPara);

        addEmptyLine(subCatPart, 1);//from  w  ww  .  j  av a 2s.  c  o m

        createEventoTable(subCatPart, evento);

        addEmptyLine(subCatPart, 1);

        Infospcoop infospcoop = eventoBean.getInfospcoop() != null ? eventoBean.getInfospcoop().getDTO() : null;
        if (infospcoop != null) {
            //         if(evento.getCategoria().equals(Categoria.INTERFACCIA) && evento.getIdEgov()!= null){

            //            Infospcoop infospcoop = eventiService.getInfospcoopByIdEgov(evento.getIdEgov());

            Paragraph infoParg = new Paragraph("Infospcoop", subFont);

            subCatPart.addSection(infoParg);

            addEmptyLine(subCatPart, 1);

            createInfospcoopTable(subCatPart, infospcoop);

            //subCatPart.add(new Paragraph(infospcoop.toXml()));
        }

        addEmptyLine(subCatPart, 1);

        catPart.newPage();
    }

    // now add all this to the document
    document.add(catPart);

}

From source file:net.bull.javamelody.internal.web.pdf.PdfCacheInformationsReport.java

License:Apache License

private void addConfigurationReference() throws DocumentException {
    final Anchor ehcacheAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont());
    ehcacheAnchor.setName("Ehcache configuration reference");
    ehcacheAnchor.setReference(//w w w  .j av a  2  s.c o  m
            "http://ehcache.sourceforge.net/apidocs/net/sf/ehcache/config/CacheConfiguration.html#field_summary");
    ehcacheAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph ehcacheParagraph = new Paragraph();
    ehcacheParagraph.add(ehcacheAnchor);
    ehcacheParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(ehcacheParagraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java

License:Apache License

private void writeDatabaseVersionAndDataSourceDetails(JavaInformations javaInformations) {
    if (!noDatabase && javaInformations.getDataBaseVersion() != null) {
        addCell(getString("Base_de_donnees") + ':');
        addCell(javaInformations.getDataBaseVersion());
    }//from  w ww  . j  a v a  2 s .  c  om
    if (javaInformations.getDataSourceDetails() != null) {
        addCell(getString("DataSource_jdbc") + ':');
        addCell(javaInformations.getDataSourceDetails());
        addCell("");
        final Anchor anchor = new Anchor("DataSource reference", PdfFonts.BLUE.getFont());
        anchor.setName("DataSource reference");
        anchor.setReference(
                "http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html");
        currentTable.addCell(anchor);
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfJobInformationsReport.java

License:Apache License

private void addConfigurationReference() throws DocumentException {
    final Anchor quartzAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont());
    quartzAnchor.setName("Quartz configuration reference");
    quartzAnchor.setReference("http://www.quartz-scheduler.org/docs/index.html");
    quartzAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph quartzParagraph = new Paragraph();
    quartzParagraph.add(quartzAnchor);//w ww . j a va2 s.co m
    quartzParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(quartzParagraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfProcessInformationsReport.java

License:Apache License

private void addPsCommandReference() throws DocumentException {
    final Anchor psAnchor = new Anchor("ps command reference", PdfFonts.BLUE.getFont());
    psAnchor.setName("ps command reference");
    psAnchor.setReference("http://en.wikipedia.org/wiki/Ps_(Unix)");
    psAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph psParagraph = new Paragraph();
    psParagraph.add(psAnchor);//from  ww w  .  java 2s.  c  om
    psParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(psParagraph);
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given meeting to the protocol.
 * //from w  w w  . java  2  s  .c  o  m
 * @param meeting
 *            the meeting
 * @param attachExtRefs
 *            true if the external references should be part of the protocol
 * @param showSignatureFields
 *            true, if the signature fields should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the meeting
 */
protected void writeMeeting(Meeting meeting, boolean attachExtRefs, boolean showSignatureFields)
        throws ExportException {
    Protocol protocol = meeting.getProtocol();

    if (protocol != null) {
        try {
            Font plainFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font italicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldItalicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED),
                    10);

            Font boldFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 17);

            Font italicFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 13);

            /*
             * Base table for the meeting properties
             */
            PdfPTable tableMeeting = new PdfPTable(2);
            tableMeeting.setWidthPercentage(100);
            tableMeeting.setSplitRows(false);
            tableMeeting.getDefaultCell().setBorderWidth(0);
            tableMeeting.getDefaultCell().setPadding(0);

            /*
             * Write date, time and location of the meeting
             */
            String meetingDate = sdfDate.format(protocol.getDate().getTime());

            String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - "
                    + sdfTime.format(protocol.getEnd().getTime()) + " ["
                    + protocol.getEnd().getTimeZone().getDisplayName() + "]";

            Anchor anchorTitle = new Anchor(translate("Review Meeting on") + " " + meetingDate, boldFontTitle);
            anchorTitle.setName(Long
                    .toString(protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis()));

            PdfPCell cellTitle = new PdfPCell(anchorTitle);
            cellTitle.setColspan(2);
            cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTitle.setPadding(0);
            cellTitle.setBorderWidth(0);
            cellTitle.setPaddingTop(PDFTools.cmToPt(0.6f));
            cellTitle.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTitle);

            PdfPCell cellTime = new PdfPCell(new Phrase(meetingTime, italicFontTitle));
            cellTime.setColspan(2);
            cellTime.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTime.setPadding(0);
            cellTime.setBorderWidth(0);
            cellTime.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTime);

            String location = protocol.getLocation();

            if (location.trim().equals("")) {
                location = "--";
            }

            PdfPCell cellLocation = new PdfPCell(
                    new Phrase(translate("Location") + ": " + location, italicFontTitle));
            cellLocation.setColspan(2);
            cellLocation.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellLocation.setPadding(0);
            cellLocation.setBorderWidth(0);
            cellLocation.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellLocation);

            /*
             * Compare with planned meeting
             */
            PdfPCell cellPlanned;

            boolean plannedDateEqualsProtocolDate = meeting.getPlannedDate()
                    .get(Calendar.DAY_OF_MONTH) == protocol.getDate().get(Calendar.DAY_OF_MONTH)
                    && meeting.getPlannedDate().get(Calendar.MONTH) == protocol.getDate().get(Calendar.MONTH)
                    && meeting.getPlannedDate().get(Calendar.YEAR) == protocol.getDate().get(Calendar.YEAR);
            boolean plannedStartEqualsProtocolStart = meeting.getPlannedStart().get(Calendar.HOUR) == protocol
                    .getStart().get(Calendar.HOUR)
                    && meeting.getPlannedStart().get(Calendar.MINUTE) == protocol.getStart()
                            .get(Calendar.MINUTE)
                    && meeting.getPlannedStart().get(Calendar.AM_PM) == protocol.getStart().get(Calendar.AM_PM);
            boolean plannedEndEqualsProtocolEnd = meeting.getPlannedEnd().get(Calendar.HOUR) == protocol
                    .getEnd().get(Calendar.HOUR)
                    && meeting.getPlannedEnd().get(Calendar.MINUTE) == protocol.getEnd().get(Calendar.MINUTE)
                    && meeting.getPlannedEnd().get(Calendar.AM_PM) == protocol.getEnd().get(Calendar.AM_PM);
            boolean plannedLocationEqualsProtocolLocation = meeting.getPlannedLocation()
                    .equals(protocol.getLocation());

            if (plannedDateEqualsProtocolDate && plannedStartEqualsProtocolStart && plannedEndEqualsProtocolEnd
                    && plannedLocationEqualsProtocolLocation) {
                cellPlanned = new PdfPCell(
                        new Phrase(translate("The meeting took place as it has been planned."), plainFont));
            } else {
                cellPlanned = new PdfPCell();

                cellPlanned.addElement(new Phrase(translate(
                        "The meeting didn't take place as it has been planned. The meeting was planned:"),
                        plainFont));

                /*
                 * Planned date, time and location
                 */
                String plannedDate = sdfDate.format(meeting.getPlannedDate().getTime());

                String plannedTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - "
                        + sdfTime.format(meeting.getPlannedEnd().getTime()) + " ["
                        + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]";

                Phrase phrasePlanned = new Phrase(plannedDate + " (" + plannedTime + "); "
                        + translate("Location") + ": " + meeting.getPlannedLocation(), italicFont);

                cellPlanned.addElement(phrasePlanned);
            }

            cellPlanned.setColspan(2);
            cellPlanned.setBorderWidth(0);
            cellPlanned.setPadding(padding);
            cellPlanned.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellPlanned);

            /*
             * Comments of the meeting and protocol
             */
            Phrase phraseComments = new Phrase(translate("Comments on the Meeting:"), boldFont);
            PdfPCell cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            phraseComments = new Phrase(translate("Comments on the Findings List:"), boldFont);
            cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String meetingComments = meeting.getComments();
            if (meetingComments.trim().equals("")) {
                meetingComments = "--";
            }

            phraseComments = new Phrase(meetingComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String protocolComments = protocol.getComments();
            if (protocolComments.trim().equals("")) {
                protocolComments = "--";
            }

            phraseComments = new Phrase(protocolComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            /*
             * Strut cell
             */
            tableMeeting.addCell(createVerticalStrut(PDFTools.cmToPt(1.3f), 2));

            /*
             * Write attendees
             */
            if (protMgmt.getAttendees(protocol).size() > 0) {
                PdfPCell cellAtt = new PdfPCell(new Phrase(
                        translate("The following attendees participated") + " ("
                                + protMgmt.getAttendees(protocol).size() + " " + translate("attendees") + "):",
                        boldItalicFont));
                cellAtt.setColspan(2);
                cellAtt.setPadding(0);
                cellAtt.setBorderWidth(0);
                cellAtt.setPadding(padding);
                cellAtt.setPaddingBottom(PDFTools.cmToPt(0.8f));

                tableMeeting.addCell(cellAtt);
            }

            pdfDoc.add(tableMeeting);

            if (protMgmt.getAttendees(protocol).size() > 0) {
                writeAttendees(protocol, true, true, showSignatureFields);
            }

            /*
             * If there isn't any finding, finish the export here.
             */
            if (findMgmt.getNumberOfFindings(protocol) == 0) {
                return;
            } else if (findMgmt.getNumberOfFindings(protocol) == 1) {
                Finding find = findMgmt.getFindings(protocol).get(0);

                if (find.getDescription().trim().equals("") && find.getExternalReferences().size() == 0
                        && find.getReferences().size() == 0 && find.getAspects().size() == 0) {
                    return;
                }
            }

            /*
             * Write findings
             */
            pdfDoc.newPage();

            PdfPTable tableFindIntro = new PdfPTable(1);
            tableFindIntro.setWidthPercentage(100);

            Phrase phraseFindIntro = new Phrase(
                    translate("The following findings were recorded by the participating reviewers") + " ("
                            + findMgmt.getNumberOfFindings(protocol) + " " + translate("findings") + "): ",
                    boldItalicFont);
            phraseFindIntro.setLeading(leading);

            PdfPCell cellFindIntro = new PdfPCell();
            cellFindIntro.addElement(phraseFindIntro);
            cellFindIntro.setBorderWidth(0);
            cellFindIntro.setPadding(0);
            cellFindIntro.setPaddingBottom(PDFTools.cmToPt(0.1f));

            tableFindIntro.addCell(cellFindIntro);

            pdfDoc.add(tableFindIntro);

            writeFindings(protocol, attachExtRefs);
        } catch (Exception e) {
            /*
             * Not part of unit testing because this exception is only
             * thrown if an internal error occurs.
             */
            throw new ExportException(translate("Cannot put the selected review meeting in the PDF document."));
        }
    }
}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

/**
 * Call to start a new chapter//  w  w  w. jav  a  2s.  c  o m
 * 
 * @param key The key for the chapter title
 * @param substitutions The substitutions
 */
public void startChapter(String key, String resources, AppElement element) {
    if (resources != null)
        chapterResources = ResourceBundle.getBundle(resources);

    String text = getText(key, element);

    Anchor anchor = new Anchor(text, h1Font);
    anchor.setName(text);

    chapter = new Chapter(new Paragraph(anchor), ++chapterNumber);
}

From source file:sg.edu.nus.util.ReportWriter.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a  little list
    createList(subCatPart);/*from w  w  w .j  av  a 2 s  .  co m*/

    // Add a small table
    createTable(subCatPart);
    // Now a small table

    // Now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // Now add all this to the document
    document.add(catPart);

}