Example usage for com.lowagie.text.pdf PdfPTable addCell

List of usage examples for com.lowagie.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable addCell.

Prototype

public void addCell(Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

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

License:Open Source License

/**
 * Writes the table of contents to the document.
 *
 * @param  document  The document to which the contents are to be written.
 *
 * @return  {@code true} if the contents information was written to the
 *          PDF document, or {@code false} if not.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 *//*w w  w . j a  v  a 2s  . c  o m*/
private boolean writeContents(Document document) throws DocumentException {
    // First, make sure that there is actually something to write.  If we're
    // only going to write information for a single job or optimizing job, then
    // there is no reason to have a contents section.
    if (((reportJobs.length == 1) && (reportOptimizingJobs.length == 0))
            || ((reportJobs.length == 0) && (reportOptimizingJobs.length == 1))) {
        return false;
    }

    if (reportJobs.length > 0) {
        // Write the job data header.
        Paragraph p = new Paragraph("Job Data",
                FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
        document.add(p);

        // Create a table with the list of jobs.
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        writeTableHeaderCell(table, "Job ID");
        writeTableHeaderCell(table, "Description");
        writeTableHeaderCell(table, "Job Type");

        for (int i = 0; i < reportJobs.length; i++) {
            Job job = reportJobs[i];
            Anchor anchor = new Anchor(job.getJobID(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
            anchor.setReference('#' + job.getJobID());
            table.addCell(new PdfPCell(anchor));

            String descriptionStr = job.getJobDescription();
            if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
                descriptionStr = "(Not Specified)";
            }
            writeTableCell(table, descriptionStr);

            writeTableCell(table, job.getJobClass().getJobName());
        }
        document.add(table);

        // Write a blank line between the job data and optimizing job data.
        document.add(new Paragraph(" "));
    }

    if (reportOptimizingJobs.length > 0) {
        // Write the optimizing job data header.
        Paragraph p = new Paragraph("Optimizing Job Data",
                FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
        document.add(p);

        // Create a table with the list of jobs.
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        writeTableHeaderCell(table, "Optimizing Job ID");
        writeTableHeaderCell(table, "Description");
        writeTableHeaderCell(table, "Job Type");

        for (int i = 0; i < reportOptimizingJobs.length; i++) {
            OptimizingJob optimizingJob = reportOptimizingJobs[i];
            Anchor anchor = new Anchor(optimizingJob.getOptimizingJobID(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
            anchor.setReference('#' + optimizingJob.getOptimizingJobID());
            table.addCell(new PdfPCell(anchor));

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

            writeTableCell(table, optimizingJob.getJobClass().getJobName());
        }
        document.add(table);
    }

    return true;
}

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

License:Open Source License

/**
 * Writes information about the provided job to the document.
 *
 * @param  document  The document to which the job information should be
 *                   written./*  w w w  .ja  v a2 s. c om*/
 * @param  job       The job to include in the document.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 */
private void writeJob(Document document, Job job) throws DocumentException {
    Anchor anchor = new Anchor("Job " + job.getJobID(),
            FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
    anchor.setName(job.getJobID());
    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, "Job ID");
    writeTableCell(table, job.getJobID());

    String optimizingJobID = job.getOptimizingJobID();
    if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) {
        writeTableCell(table, "Optimizing Job ID");
        writeTableCell(table, optimizingJobID);
    }

    String descriptionStr = job.getJobDescription();
    if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
        descriptionStr = "(Not Specified)";
    }
    writeTableCell(table, "Job Description");
    writeTableCell(table, descriptionStr);

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

    writeTableCell(table, "Job Class");
    writeTableCell(table, job.getJobClass().getClass().getName());

    writeTableCell(table, "Job State");
    writeTableCell(table, job.getJobStateString());
    document.add(table);

    // Write the schedule config 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 = job.getStartTime();
        String startStr;
        if (startTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(startTime);
        }
        writeTableCell(table, "Scheduled Start Time");
        writeTableCell(table, startStr);

        Date stopTime = job.getStopTime();
        String stopStr;
        if (stopTime == null) {
            stopStr = "(Not Specified)";
        } else {
            stopStr = dateFormat.format(stopTime);
        }
        writeTableCell(table, "Scheduled Stop Time");
        writeTableCell(table, stopStr);

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

        writeTableCell(table, "Number of Clients");
        writeTableCell(table, String.valueOf(job.getNumberOfClients()));

        String[] requestedClients = job.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 = job.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, "Threads per Client");
        writeTableCell(table, String.valueOf(job.getThreadsPerClient()));

        writeTableCell(table, "Thread Startup Delay");
        writeTableCell(table, job.getThreadStartupDelay() + " milliseconds");

        writeTableCell(table, "Statistics Collection Interval");
        writeTableCell(table, job.getCollectionInterval() + " seconds");

        document.add(table);
    }

    // Write the job-specific parameter information 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 = job.getParameterList().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 if appropriate.
    if (includeStats && job.hasStats()) {
        document.add(new Paragraph(" "));
        p = new Paragraph("General 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 = job.getActualStartTime();
        String startStr;
        if (actualStartTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(actualStartTime);
        }
        writeTableCell(table, "Actual Start Time");
        writeTableCell(table, startStr);

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

        int actualDuration = job.getActualDuration();
        String durationStr;
        if (actualDuration > 0) {
            durationStr = actualDuration + " seconds";
        } else {
            durationStr = "(Not Available)";
        }
        writeTableCell(table, "Actual Duration");
        writeTableCell(table, durationStr);

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

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

        document.add(table);

        String[] trackerNames = job.getStatTrackerNames();
        for (int i = 0; i < trackerNames.length; i++) {
            StatTracker[] trackers = job.getStatTrackers(trackerNames[i]);
            if ((trackers != null) && (trackers.length > 0)) {
                document.newPage();
                StatTracker tracker = trackers[0].newInstance();
                tracker.aggregate(trackers);

                document.add(new Paragraph(" "));
                document.add(new Paragraph(trackerNames[i],
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));

                String[] summaryNames = tracker.getSummaryLabels();
                String[] summaryValues = tracker.getSummaryData();
                table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setWidths(new int[] { 50, 50 });
                for (int j = 0; j < summaryNames.length; j++) {
                    writeTableCell(table, summaryNames[j]);
                    writeTableCell(table, summaryValues[j]);
                }
                document.add(table);

                if (includeGraphs) {
                    try {
                        ParameterList params = tracker.getGraphParameterStubs(job);
                        BufferedImage graphImage = tracker.createGraph(job, 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) {
                    }
                }
            }
        }
    }

    // Write the resource monitor data if appropriate.
    if (includeMonitorStats && job.hasResourceStats()) {
        String[] trackerNames = job.getResourceStatTrackerNames();
        for (int i = 0; i < trackerNames.length; i++) {
            StatTracker[] trackers = job.getResourceStatTrackers(trackerNames[i]);
            if ((trackers != null) && (trackers.length > 0)) {
                document.newPage();
                StatTracker tracker = trackers[0].newInstance();
                tracker.aggregate(trackers);

                document.add(new Paragraph(" "));
                document.add(new Paragraph(trackerNames[i],
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));

                String[] summaryNames = tracker.getSummaryLabels();
                String[] summaryValues = tracker.getSummaryData();
                table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setWidths(new int[] { 50, 50 });
                for (int j = 0; j < summaryNames.length; j++) {
                    writeTableCell(table, summaryNames[j]);
                    writeTableCell(table, summaryValues[j]);
                }
                document.add(table);

                if (includeGraphs) {
                    try {
                        ParameterList params = tracker.getGraphParameterStubs(job);
                        BufferedImage graphImage = tracker.createMonitorGraph(job,
                                Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_MONITOR_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
}

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.//from ww w .j a v a2  s. c  o 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:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes the specified text to the provided table as a header cell.
 *
 * @param  table  The table to which the header cell should be written.
 * @param  text   The text to write to the header cell.
 *//* w ww  . j a v a2s.  c  o m*/
private void writeTableHeaderCell(PdfPTable table, String text) {
    Phrase phrase = new Phrase(text, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    table.addCell(new PdfPCell(phrase));
}

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

License:Open Source License

/**
 * Writes the specified text to the provided table as a normal cell.
 *
 * @param  table  The table to which the cell should be written.
 * @param  text   The text to write to the cell.
 *///from w ww  .ja  va2  s  . c  o m
private void writeTableCell(PdfPTable table, String text) {
    table.addCell(new PdfPCell(new Phrase(text)));
}

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

License:Open Source License

/**
 * Performs the appropriate action necessary when starting a new page.  In
 * this case, we will write the SLAMD header to the top of the page.
 *
 * @param  writer    The writer used to write the PDF document.
 * @param  document  The PDF document being written.
 */// w  ww .ja  v  a2 s . com
public void onStartPage(PdfWriter writer, Document document) {
    try {
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);

        PdfPCell blueCell = new PdfPCell(new Phrase(" \n "));
        blueCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        blueCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        blueCell.setBackgroundColor(new Color(0x59, 0x4F, 0xBF));
        blueCell.setBorderWidth(inchesToPoints(1.0 / 16));
        blueCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        blueCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(blueCell);

        Phrase titlePhrase = new Phrase("SLAMD Generated Report",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0x59, 0x4F, 0xBF)));
        PdfPCell yellowCell = new PdfPCell(titlePhrase);
        yellowCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        yellowCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        yellowCell.setBackgroundColor(new Color(0xFB, 0xE2, 0x49));
        yellowCell.setBorderWidth(inchesToPoints(1.0 / 16));
        yellowCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        yellowCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(yellowCell);

        Phrase versionPhrase = new Phrase("Version " + DynamicConstants.SLAMD_VERSION,
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0xFF, 0xFF, 0xFF)));
        PdfPCell redCell = new PdfPCell(versionPhrase);
        redCell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
        redCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        redCell.setBackgroundColor(new Color(0xD1, 0x21, 0x24));
        redCell.setBorderWidth(inchesToPoints(1.0 / 16));
        redCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        redCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(redCell);

        document.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private Element buildQrCodeSection() throws IOException, DocumentException {
    // Load images
    Image qrApkImage = PngImage//from w  ww . jav a 2 s . c o m
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_apk_qr.png"));
    Image qrPdfImage = PngImage
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_pdf_qr.png"));

    PdfPCell cell = new PdfPCell((Phrase) null);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1, 2, 1 });

    cell.setImage(qrApkImage);
    table.addCell(cell);
    cell.setImage(null);

    table.addCell(cell);

    cell.setImage(qrPdfImage);
    table.addCell(cell);
    cell.setImage(null);

    cell.setPhrase(new Phrase("APP"));
    table.addCell(cell);
    cell.setPhrase(null);

    table.addCell(cell);

    cell.setPhrase(new Phrase("PDF"));
    table.addCell(cell);
    cell.setPhrase(null);

    return table;
}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableHeader/*from   w w  w .  j  av  a2 s . c o m*/
 * 
 * @param table
 */
protected void beginTableHeader(PdfPTable table) {
    // 
    if (this.getDisplayTableModel().getHeaders() != null) {
        Font headerFont = this.getDisplayTableModel().getHeadersFont();
        if (headerFont == null) {//footer
            headerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        for (int i = 0; i < getDisplayTableModel().getColumnCount(); i++) {

            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(getDisplayTableModel().getHeaders()[i], headerFont));

            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);// 
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }

}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableFooter/*ww w . j  a  v  a  2s  . co  m*/
 * 
 * @param table
 */
protected void beginTableFooter(PdfPTable table, PdfWriter writer) {
    if (this.getDisplayTableModel().getFooters() != null) {
        List<String> cells = this.getDisplayTableModel().getFooters();
        Font footerFont = this.getDisplayTableModel().getFootersFont();
        if (footerFont == null) {//footer
            footerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        Iterator<String> it = cells.iterator();
        while (it.hasNext()) {
            String key = it.next();
            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(key, footerFont));
            cell.setColspan(getDisplayTableModel().getColumnCount());
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);// ??
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }
}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

protected void createTableRow(PdfWriter writer, PdfPTable table, Object obj, int columnCount,
        IPdfTableModel model) {/*ww w .j a  v a2 s.  c om*/
    Font contentFont = model.getContentFont();
    if (contentFont == null) {//model??
        contentFont = PdfUtils.createSongLightFont(10);
    }
    for (int i = 0; i < columnCount; i++) {
        // ??TableRow?.
        PdfPCell cell = new PdfPCell(new Phrase("", contentFont));
        // .
        cell.setCellEvent(
                new CreateTextFieldCellEvent(writer, getDisplayTableModel().getCurrentColumnValue(obj, i)));
        table.addCell(cell);
    }

}