Example usage for com.lowagie.text Element ALIGN_RIGHT

List of usage examples for com.lowagie.text Element ALIGN_RIGHT

Introduction

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

Prototype

int ALIGN_RIGHT

To view the source code for com.lowagie.text Element ALIGN_RIGHT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private void generateSeriesReport(OutputStream output) {

    displayUnits = NormalTridasUnit//www.  j  av  a 2 s . c  om
            .valueOf(App.prefs.getPref(PrefKey.DISPLAY_UNITS, NormalTridasUnit.MICROMETRES.name().toString()));

    try {

        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.setPageSize(PageSize.LETTER);
        document.open();
        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Tellervo Series Report for " + s.getDisplayTitle());

        // Title Left      
        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(document.left(), document.top() - 163, 283, document.top(), 20, Element.ALIGN_LEFT);
        ct.addText(getTitlePDF());
        ct.go();

        // Barcode
        ColumnText ct2 = new ColumnText(cb);
        ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20,
                Element.ALIGN_RIGHT);
        ct2.addElement(getBarCode());
        ct2.go();

        // Timestamp
        ColumnText ct3 = new ColumnText(cb);
        ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20,
                Element.ALIGN_LEFT);
        ct3.setLeading(0, 1.2f);
        ct3.addText(getTimestampPDF());
        ct3.go();

        // Authorship
        ColumnText ct4 = new ColumnText(cb);
        ct4.setSimpleColumn(284, document.top() - 223, document.right(10), document.top() - 60, 20,
                Element.ALIGN_RIGHT);
        ct4.setLeading(0, 1.2f);
        ct4.addText(getAuthorshipPDF());
        ct4.go();

        // Pad text
        document.add(new Paragraph(" "));
        Paragraph p2 = new Paragraph();
        p2.setSpacingBefore(50);
        p2.setSpacingAfter(10);
        p2.add(new Chunk(" ", bodyFont));
        document.add(new Paragraph(p2));

        // Ring width table
        getRingWidthTable();
        document.add(getParagraphSpace());

        if (s.getSeries() instanceof TridasMeasurementSeries) {
            // MEASUREMENT SERIES

            //document.add(getRingRemarks());
            document.add(getWoodCompletenessPDF());
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            document.add(getInterpretationPDF());
            document.add(getParagraphSpace());
            document.add(getElementAndSampleInfo());
        } else {
            // DERIVED SERIES
            getWJTable();
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            //document.add(getRingRemarks());

        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private void getTableKey() throws DocumentException, IOException, IOException {
    PdfPTable mainTable = new PdfPTable(12);
    float[] widths = { 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f };
    mainTable.setWidths(widths);//  w  w w . j  a v  a 2s.c o m
    mainTable.setWidthPercentage(100);

    PdfPTable userRemarksTable = new PdfPTable(2);
    float[] widths2 = { 0.083f, 0.92f };
    userRemarksTable.setWidths(widths2);
    userRemarksTable.setWidthPercentage(100);

    Boolean userRemarkUsed = false;

    DecadalModel model;
    model = new UnitAwareDecadalModel(s);
    int rows = model.getRowCount();
    List<TridasRemark> masterList = null;

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If masterlist is still null initialize it with this remarks list
            if (remarksList.size() > 0 && masterList == null)
                masterList = remarksList;

            for (TridasRemark remark : remarksList) {
                if (!masterList.contains(remark))
                    masterList.add(remark);
            }
        }
    }

    for (TridasRemark remark : masterList) {
        PdfPCell iconCell = new PdfPCell();
        PdfPCell equalsCell = new PdfPCell();
        PdfPCell descriptionCell = new PdfPCell();

        iconCell.setBorder(0);
        equalsCell.setBorder(0);
        descriptionCell.setBorder(0);

        iconCell.setVerticalAlignment(Element.ALIGN_TOP);
        equalsCell.setVerticalAlignment(Element.ALIGN_TOP);
        descriptionCell.setVerticalAlignment(Element.ALIGN_TOP);

        Image icon = null;
        String remarkStr = null;

        // Get actual icon (either tridas or tellervo)
        if (remark.isSetNormalTridas()) {
            remarkStr = remark.getNormalTridas().toString().toLowerCase();
            remarkStr = remarkStr.replace("_", " ");
            icon = getTridasIcon(remark.getNormalTridas());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else if (TELLERVO.equals(remark.getNormalStd())) {
            remarkStr = remark.getNormal();
            icon = getCorinaIcon(remark.getNormal());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else {
            if (!userRemarkUsed) {
                remarkStr = "User Remark (See Below)";
                icon = Builder.getITextImageIcon("user.png");
                userRemarkUsed = true;
            } else {
                // User remark and we already have a key for this so continue
                continue;
            }
        }

        iconCell.addElement(icon);
        equalsCell.addElement(new Phrase("=", tableBodyFont));
        descriptionCell.addElement(new Phrase(WordUtils.capitalize(remarkStr), tableBodyFont));

        mainTable.addCell(iconCell);
        mainTable.addCell(equalsCell);
        mainTable.addCell(descriptionCell);
    }

    // Pad out empty cells
    PdfPCell blankCell = new PdfPCell();
    blankCell.addElement(new Phrase(""));
    blankCell.setBorder(0);
    for (int i = 0; i < 12; i++) {
        mainTable.addCell(blankCell);
    }

    document.add(mainTable);

    if (userRemarkUsed) {
        PdfPCell yearCell = new PdfPCell();
        yearCell.setBorder(0);
        yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        yearCell.addElement(new Phrase("Year", tableHeaderFont));
        userRemarksTable.addCell(yearCell);

        PdfPCell remarkCell = new PdfPCell();
        remarkCell.setBorder(0);
        remarkCell.addElement(new Phrase("User ring remarks", tableHeaderFont));
        userRemarksTable.addCell(remarkCell);

        for (int row = 0; row < rows; row++) {
            // Loop through columns
            for (int col = 0; col < 11; col++) {
                org.tellervo.desktop.Year year = model.getYear(row, col);
                List<TridasRemark> remarksList = null;
                remarksList = s.getRemarksForYear(year);

                for (TridasRemark remark : remarksList) {
                    if (remark.isSetNormalTridas() || remark.isSetNormalStd())
                        continue;

                    yearCell = new PdfPCell();
                    yearCell.setBorder(0);
                    yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    yearCell.addElement(new Phrase(year.toString(), tableHeaderFont));
                    userRemarksTable.addCell(yearCell);

                    remarkCell = new PdfPCell();
                    remarkCell.setBorder(0);
                    remarkCell.addElement(new Phrase(remark.getValue(), tableBodyFont));
                    userRemarksTable.addCell(remarkCell);
                }
            }
        }

        document.add(userRemarksTable);
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

/**
 * Get PdfPTable containing the ring width data for this series
 * //www .  jav a 2 s.  co  m
 * @return PdfPTable
 * @throws DocumentException 
 * @throws IOException 
 * @throws MalformedURLException 
 */
private void getDataTable(Boolean wj) throws DocumentException, MalformedURLException, IOException {
    // THE actual table
    PdfPTable mainTable = new PdfPTable(11);
    // Cell for column headers
    PdfPCell colHeadCell = new PdfPCell();
    // Model for data
    DecadalModel model;
    // Flag to show if there are *any* ring remarks
    Boolean hasRemarks = false;

    float[] columnWidths = new float[] { 20f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f };
    mainTable.setWidths(columnWidths);
    mainTable.setWidthPercentage(100f);

    if (wj == true) {
        if (s.hasWeiserjahre() == true) {
            model = new WJTableModel(s);
            document.add(new Chunk("Weiserjahre:", subSubSectionFont));
        } else {
            return;
        }
    } else {
        model = new UnitAwareDecadalModel(s);
        document.add(new Chunk("Ring widths:", subSubSectionFont));
    }

    int rows = model.getRowCount();

    // Do column headers
    if (wj == true) {
        colHeadCell.setPhrase(new Phrase("inc/dec", tableHeaderFont));
    } else if (this.s.getTridasUnits() == null) {
        // Unitless
        colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
    } else {
        // Normal tridas units
        try {
            /*if(this.s.getTridasUnits().getNormalTridas().equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }*/

            // Use the current default display units

            colHeadCell.setPhrase(new Phrase(displayUnits.value(), tableHeaderFont));

            /*if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }
            else if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
            {
               colHeadCell.setPhrase(new Phrase("1/100th mm", tableHeaderFont));
            }
            */

        } catch (Exception e) {
            colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
        }
    }
    colHeadCell.setBorderWidthBottom(headerLineWidth);
    colHeadCell.setBorderWidthTop(headerLineWidth);
    colHeadCell.setBorderWidthLeft(headerLineWidth);
    colHeadCell.setBorderWidthRight(headerLineWidth);
    mainTable.addCell(colHeadCell);
    for (int i = 0; i < 10; i++) {
        colHeadCell.setPhrase(new Phrase(Integer.toString(i), tableHeaderFont));
        colHeadCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        colHeadCell.setBorderWidthBottom(headerLineWidth);
        colHeadCell.setBorderWidthTop(headerLineWidth);
        colHeadCell.setBorderWidthLeft(lineWidth);
        colHeadCell.setBorderWidthRight(lineWidth);

        if (i == 0)
            colHeadCell.setBorderWidthLeft(headerLineWidth);
        if (i == 9)
            colHeadCell.setBorderWidthRight(headerLineWidth);
        mainTable.addCell(colHeadCell);
    }

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            // Mini table to hold remark icons
            PdfPTable remarksMiniTable = new PdfPTable(3);
            float[] widths = { 0.3f, 0.3f, 0.6f };
            remarksMiniTable.setWidths(widths);
            remarksMiniTable.setWidthPercentage(100);

            // Get ring value or year number for first column
            Phrase cellValuePhrase = null;
            Object value = model.getValueAt(row, col);
            if (value == null) {
                cellValuePhrase = new Phrase("");
            } else {
                /*if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/10;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }
                }
                else if(displayUnits.equals(NormalTridasUnit.FIFTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/20;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TWENTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/50;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TENTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/100;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
                {*/
                cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                //}
            }

            // Get any remarks and compile them into a mini table
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If there are remarks, cycle through them adding cells to the mini table
            if (col != 0 && remarksList.size() > 0) {
                hasRemarks = true;
                // Get icons for remarks
                int cellnum = 1;
                int remarknum = 0;
                for (TridasRemark remark : remarksList) {
                    // Keep track of which remark we are on.
                    remarknum++;
                    // String for holding remark name for debugging
                    String remstr = "?";
                    // The actual remark icon
                    Image icon = null;
                    // A table cell for the remark
                    PdfPCell remarkCell = new PdfPCell();

                    // Set default attributes for remark and value cells
                    remarkCell.setBorderWidthBottom(0);
                    remarkCell.setBorderWidthTop(0);
                    remarkCell.setBorderWidthLeft(0);
                    remarkCell.setBorderWidthRight(0);
                    remarkCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    remarkCell.setPadding(0);
                    remarkCell.setUseBorderPadding(true);

                    // A table cell for the ring width value
                    PdfPCell valueCell = new PdfPCell();
                    valueCell = remarkCell;

                    // Get actual icon (either tridas or tellervo)
                    if (remark.isSetNormalTridas()) {
                        remstr = remark.getNormalTridas().toString();
                        icon = getTridasIcon(remark.getNormalTridas());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else if (TELLERVO.equals(remark.getNormalStd())) {
                        remstr = remark.getNormal();
                        icon = getCorinaIcon(remark.getNormal());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else {
                        if (remark.isSetValue()) {
                            remstr = remark.getValue();
                        } else if (remark.isSetNormal()) {
                            remstr = remark.getNormal();
                        } else {
                            remstr = "Unknown";
                        }
                        icon = Builder.getITextImageIcon("user.png");

                    }

                    // Print debug info for this remark
                    String errStr = "Getting icon for " + remstr + " for year " + year.toString()
                            + "(cell value = " + cellnum + ")";
                    System.out.print(errStr);

                    // Shrink the icon a bit
                    icon.scalePercent(20);

                    // Add icon to minitable
                    remarkCell.addElement(icon);
                    remarksMiniTable.addCell(remarkCell);
                    cellnum++;

                    if (cellnum == 1 && remarksList.size() < cellnum) {
                        // First cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 2 && remarksList.size() < cellnum) {
                        // Second cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 3) {
                        // In third cell so print value
                        valueCell.setPhrase(cellValuePhrase);
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    } else if (cellnum % 3 == 0) {
                        // In third column so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }

                    if (remarknum == remarksList.size()) {
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        remarksMiniTable.addCell(valueCell);
                    }

                    remarkCell = null;
                    valueCell = null;
                }
            } else {
                // No remarks so make mini table have blank, blank, value

                // Create blank and value cells
                PdfPCell blankCell = new PdfPCell();
                PdfPCell valueCell = new PdfPCell();

                // Set up style
                blankCell.setBorderWidthBottom(0);
                blankCell.setBorderWidthTop(0);
                blankCell.setBorderWidthLeft(0);
                blankCell.setBorderWidthRight(0);
                blankCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                blankCell.setPadding(0);
                blankCell.setUseBorderPadding(true);
                valueCell = blankCell;

                // Add cells to mini table
                remarksMiniTable.addCell(blankCell);
                remarksMiniTable.addCell(blankCell);
                valueCell.setPhrase(cellValuePhrase);
                remarksMiniTable.addCell(valueCell);
            }

            // Set border styles depending on where we are in the table

            // Defaults
            PdfPCell mainTableCell = new PdfPCell();
            mainTableCell.setBorderWidthBottom(lineWidth);
            mainTableCell.setBorderWidthTop(lineWidth);
            mainTableCell.setBorderWidthLeft(lineWidth);
            mainTableCell.setBorderWidthRight(lineWidth);
            mainTableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            // Row headers
            if (col == 0) {
                mainTableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
                mainTableCell.setBorderWidthLeft(headerLineWidth);
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // First data column
            if (col == 1) {
                mainTableCell.setBorderWidthLeft(headerLineWidth);
            }

            // Last data column
            if (col == 10) {
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // Last row
            if (row == model.getRowCount() - 1) {
                mainTableCell.setBorderWidthBottom(headerLineWidth);
            }

            // Write mini table to cell       
            mainTableCell.addElement(remarksMiniTable);

            //mainTableCell.addElement(userRemarksMiniTable);

            // Write cell to main table
            mainTable.addCell(mainTableCell);

        }
    }

    // Add table to document
    document.add(mainTable);

    if (!wj && hasRemarks)
        getTableKey();
}

From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java

License:Open Source License

public void addLabelsForSamples(List<TridasSample> samples) {

    // Loop through samples in list
    for (TridasSample s : samples) {
        Barcode128 barcode = new LabBarcode(LabBarcode.Type.SAMPLE,
                UUID.fromString(s.getIdentifier().getValue().toString()));

        // if it's tiny, hide the label
        if (margins.getLabelHeight() * .80f < barcode.getBarHeight()) {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(1.8f);//from   w  ww.j  a  v  a  2s  .  c o  m
            barcode.setN(10f);
            barcode.setSize(10f);
            barcode.setBaseline(10f);
            barcode.setBarHeight(50f);
            barcode.setFont(null);
        } else {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(0.6f);
            barcode.setSize(4.0f);

        }

        PdfPCell lbcell = new PdfPCell();

        lbcell.setVerticalAlignment(Element.ALIGN_TOP);
        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        Phrase p = new Phrase();

        String labelText;
        TridasGenericField labcodeField = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText");

        if (labcodeField == null) {
            log.warn("labcode missing from sample.  Can't print!");
            continue;
        }
        labelText = (labcodeField != null) ? labcodeField.getValue() : s.getTitle();

        p.add(new Chunk(labelText, labelfont));
        //p.add(new Chunk("bbb", labelfont));
        //p.add(new Chunk(s.getIdentifier().getValue().toString(), uuidfont));

        //barcode.setFont(null);
        Image img = barcode.createImageWithBarcode(contentb, Color.black, Color.gray);

        PdfPCell labcell = new PdfPCell();

        if (App.getLabName() != null) {
            labcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            labcell.setVerticalAlignment(Element.ALIGN_TOP);
            Phrase labPhrase = new Phrase(App.getLabName().toUpperCase(), tinyfont);
            labcell.addElement(labPhrase);
        }
        addCell(labcell);

        PdfPCell bccell = new PdfPCell();
        bccell.setHorizontalAlignment(Element.ALIGN_MIDDLE);

        bccell.addElement(img);
        bccell.addElement(p);
        addCell(bccell);

        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        lbcell.addElement(p);
        addCell(lbcell);

        //addCell(new PdfPCell());

        /**   PdfPTable tbl = new PdfPTable(2);
                   
           tbl.addCell(bccell);
           tbl.addCell(lbcell);*/

    }

}

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printLine(String... fields) {
    PdfPCellEvent setLineDashEvent = new PdfPCellEvent() {
        @Override//from w ww.j a  va  2  s  .  co m
        public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            cb.setLineDash(new float[] { 2, 2 }, 0);
        }
    };

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx])))
            f = "";

        boolean number = sNumber.matcher(f).matches();

        Font font = PdfFont.getFont();
        Phrase p = new Phrase(f, PdfFont.getSmallFont());

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT);
        cell.setPaddingBottom(4f);
        cell.setCellEvent(setLineDashEvent);
        if (number)
            cell.setPaddingRight(10f);
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0));
    }
    iLastLine = fields;
}

From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java

License:Open Source License

protected void pdfBuildTableHeader(boolean events, boolean mainContact, int numEventsOrMeetings) {
    if (events) {
        PdfPCell c;//from w ww  .  j  a va  2 s  .c o  m
        if (numEventsOrMeetings > getMaxResults()) {
            c = createCell();
            addText(c,
                    "**Warning: More than " + getMaxResults()
                            + " events match your search criteria. Only the first " + getMaxResults()
                            + " events are displayed. Please, redefine the search criteria in your filter.",
                    true, Element.ALIGN_LEFT);
            c.setColspan(mainContact ? 6 : 5);
            iPdfTable.addCell(c);
        }
        iBgColor = new Color(224, 224, 224);
        //first line
        c = createCell();
        addText(c, LABEL, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, ENROLLMENT, true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, EVENT_CAPACITY, true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, SPONSORING_ORG, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, EVENT_TYPE, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        if (mainContact) {
            c = createCell();
            addText(c, MAIN_CONTACT, true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
        //second line
        iBgColor = new Color(244, 244, 244);
        iUnderline = true;
        c = createCell();
        iPdfTable.addCell(c);
        c = createCell();
        c.setColspan(2);
        addText(c, MEETING_DATE, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, MEETING_TIME, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, MEETING_LOCATION, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        if (mainContact) {
            c = createCell();
            addText(c, APPROVED_DATE, true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
        if (numEventsOrMeetings <= getMaxResults()) {
            iPdfTable.setHeaderRows(2);
        } else {
            iPdfTable.setHeaderRows(3);
        }
    } else {
        PdfPCell c;
        if (numEventsOrMeetings > getMaxResults()) {
            c = createCell();
            addText(c,
                    "**Warning: More than " + getMaxResults()
                            + " meetings match your search criteria. Only the first " + getMaxResults()
                            + " meetings are displayed. Please, redefine the search criteria in your filter.",
                    true, Element.ALIGN_LEFT);
            c.setColspan(mainContact ? 10 : 9);
            iPdfTable.addCell(c);
        }
        iBgColor = new Color(224, 224, 224);
        //first line
        iUnderline = true;
        c = createCell();
        addText(c, LABEL, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, EVENT_TYPE, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, (mainContact ? "Enrl." : ENROLLMENT), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, (mainContact ? "Cap." : EVENT_CAPACITY), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, SPONSORING_ORG, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, MEETING_DATE, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, MEETING_TIME, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        c = createCell();
        addText(c, MEETING_LOCATION, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
        if (mainContact) {
            c = createCell();
            addText(c, MAIN_CONTACT, true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
            c = createCell();
            addText(c, APPROVED_DATE, true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
        if (numEventsOrMeetings <= getMaxResults()) {
            iPdfTable.setHeaderRows(1);
        } else {
            iPdfTable.setHeaderRows(2);
        }

    }
    iBgColor = Color.WHITE;
    iUnderline = false;
}

From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildEventCapacity(Event e) {
    PdfPCell cell = createCell();//from  w w w . j  a va2  s . co  m
    int minCap = (e.getMinCapacity() == null ? -1 : e.getMinCapacity());
    int maxCap = (e.getMaxCapacity() == null ? -1 : e.getMaxCapacity());
    if (minCap == -1) {

    } else {
        if (maxCap != -1) {
            if (maxCap != minCap) {
                addText(cell, minCap + "-" + maxCap, Element.ALIGN_RIGHT);
            } else {
                addText(cell, String.valueOf(minCap), Element.ALIGN_RIGHT);
            }
        }
    }
    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildEventEnrollment(Event e) {
    PdfPCell cell = createCell();/*from   ww w .ja  va2 s  . c om*/
    if (Event.sEventTypeClass == e.getEventType()) {
        ClassEvent ce = new ClassEventDAO().get(Long.valueOf(e.getUniqueId()));
        if (ce.getClazz().getEnrollment() != null) {
            addText(cell, ce.getClazz().getEnrollment().toString(), Element.ALIGN_RIGHT);
        } else {
            addText(cell, "0", Element.ALIGN_RIGHT);
        }
    } else if (Event.sEventTypeFinalExam == e.getEventType()
            || Event.sEventTypeMidtermExam == e.getEventType()) {
        ExamEvent ee = new ExamEventDAO().get(e.getUniqueId());
        addText(cell, String.valueOf(ee.getExam().countStudents()), Element.ALIGN_RIGHT);
    } else if (Event.sEventTypeCourse == e.getEventType()) {
        CourseEvent ce = new CourseEventDAO().get(e.getUniqueId());
        int enrl = 0;
        for (RelatedCourseInfo rci : ce.getRelatedCourses())
            enrl += rci.countStudents();
        addText(cell, String.valueOf(enrl), Element.ALIGN_RIGHT);
    }
    return (cell);
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

protected void pdfBuildTableHeader(Long sessionId) {
    iBgColor = sBgColorHeader;/*from w  ww.j  a v a  2s. c  o m*/
    //first line
    if (isShowLabel()) {
        PdfPCell c = createCell();
        addText(c, LABEL, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowDivSec()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnExternalId(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowDemand()) {
        PdfPCell c = createCell();
        if (StudentClassEnrollment.sessionHasEnrollments(sessionId)) {
            addText(c, MSG.columnDemand(), true, Element.ALIGN_RIGHT);
        } else {
            addText(c, MSG.columnLastDemand(), true, Element.ALIGN_RIGHT);
        }
        iPdfTable.addCell(c);
    }
    if (isShowProjectedDemand()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnProjectedDemand(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowLimit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnLimit(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowRoomRatio()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnRoomRatio(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowManager()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnManager(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowDatePattern()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnDatePattern(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowMinPerWk()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnMinPerWk(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowTimePattern()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnTimePattern(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowPreferences()) {
        PdfPCell c = createCell();
        c.setColspan(PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1));
        addText(c, "----" + MSG.columnPreferences() + "----", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowInstructor()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnInstructor(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (getDisplayTimetable() && isShowTimetable()) {
        PdfPCell c = createCell();
        c.setColspan(TIMETABLE_COLUMN_ORDER.length);
        addText(c, "--------" + MSG.columnTimetable() + "--------", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowTitle()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnTitle(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowCredit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnOfferingCredit(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowSubpartCredit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnSubpartCredit(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowConsent()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnConsent(), true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowSchedulePrintNote()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnSchedulePrintNote(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowNote()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnNote(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowExam()) {
        PdfPCell c = createCell();
        c.setColspan((isShowExamName() ? 1 : 0) + (isShowExamTimetable() ? 2 : 0));
        addText(c, "--------" + MSG.columnExam() + "--------", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }

    //second line
    if (isShowLabel()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDivSec()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDemand()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowProjectedDemand()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowLimit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowRoomRatio()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowManager()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDatePattern()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowMinPerWk()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowTimePattern()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowPreferences()) {
        for (int j = 0; j < PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1); j++) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, PREFERENCE_COLUMN_ORDER[j], true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    if (isShowInstructor()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (getDisplayTimetable() && isShowTimetable()) {
        for (int j = 0; j < TIMETABLE_COLUMN_ORDER.length; j++) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, TIMETABLE_COLUMN_ORDER[j], true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    if (isShowTitle()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowCredit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowSubpartCredit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowConsent()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowSchedulePrintNote()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowNote()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowExam()) {
        if (isShowExamName()) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamName(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
        if (isShowExamTimetable()) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamPeriod(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
            c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamRoom(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    iPdfTable.setHeaderRows(2);
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

private PdfPCell pdfBuildPrefGroupDemand(PreferenceGroup prefGroup, boolean isEditable) {
    if (prefGroup instanceof Class_) {
        Class_ c = (Class_) prefGroup;
        if (StudentClassEnrollment.sessionHasEnrollments(c.getSessionId())) {
            PdfPCell tc = createCell();//from   w w  w.j av  a2  s .c o  m
            if (c.getEnrollment() != null) {
                addText(tc, c.getEnrollment().toString());
            } else {
                addText(tc, "0");
            }
            tc.setHorizontalAlignment(Element.ALIGN_RIGHT);
            return (tc);
        }
    }
    return createCell();
}