com.lowagie.text.pdf.PdfPCell Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfPCell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addCell_WithTextField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName,
    int fieldCellType, String value )
    throws IOException, DocumentException
{
    TextField nameField = new TextField( writer, rect, strfldName );

    nameField.setBorderWidth( 1 );
    nameField.setBorderColor( Color.BLACK );
    nameField.setBorderStyle( PdfBorderDictionary.STYLE_SOLID );
    nameField.setBackgroundColor( COLOR_BACKGROUDTEXTBOX );

    nameField.setText( value );

    nameField.setAlignment( Element.ALIGN_RIGHT );
    nameField.setFont( pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ).getBaseFont() );

    cell.setCellEvent( new PdfFieldCell( nameField.getTextField(), rect.getWidth(), rect.getHeight(), fieldCellType, writer ) );

    table.addCell( cell );
}
 
Example #2
Source File: SimpleCell.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
	float sp_left = spacing_left;
	if (Float.isNaN(sp_left)) sp_left = 0f;
	float sp_right = spacing_right;
	if (Float.isNaN(sp_right)) sp_right = 0f;
	float sp_top = spacing_top;
	if (Float.isNaN(sp_top)) sp_top = 0f;
	float sp_bottom = spacing_bottom;
	if (Float.isNaN(sp_bottom)) sp_bottom = 0f;
	Rectangle rect = new Rectangle(position.getLeft(sp_left), position.getBottom(sp_bottom), position.getRight(sp_right), position.getTop(sp_top));
	rect.cloneNonPositionParameters(this);
	canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
	rect.setBackgroundColor(null);
	canvases[PdfPTable.LINECANVAS].rectangle(rect);
}
 
Example #3
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
private PdfPCell pdfBuildPrefGroupDemand(PreferenceGroup prefGroup, boolean isEditable){
  	if (prefGroup instanceof Class_) {
	Class_ c = (Class_) prefGroup;
	if (StudentClassEnrollment.sessionHasEnrollments(c.getSessionId())){
		PdfPCell tc = createCell();
		if (c.getEnrollment() != null){
			addText(tc, c.getEnrollment().toString());
		} else {
			addText(tc, "0");
		}
		tc.setHorizontalAlignment(Element.ALIGN_RIGHT);
		return(tc);
	}
}
  	return createCell();
  }
 
Example #4
Source File: PdfWebTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private float addImage(PdfPCell cell, String name) {
	try {
		java.awt.Image awtImage = (java.awt.Image)iImages.get(name);
		if (awtImage==null) return 0;
		Image img = Image.getInstance(awtImage, Color.WHITE);
		Chunk ck = new Chunk(img, 0, 0);
		if (cell.getPhrase()==null) {
			cell.setPhrase(new Paragraph(ck));
			cell.setVerticalAlignment(Element.ALIGN_TOP);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		} else {
			cell.getPhrase().add(ck);
		}
		return awtImage.getWidth(null);
	} catch (Exception e) {
		return 0;
	}
}
 
Example #5
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected PdfPCell pdfBuildNote(PreferenceGroup prefGroup, boolean isEditable, UserContext user){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();

	if (prefGroup instanceof Class_) {
		Class_ c = (Class_) prefGroup;
		if (c.getNotes()!=null) {
			if (c.getNotes().length() <= 30  || user == null || CommonValues.NoteAsFullText.eq(user.getProperty(UserProperty.ManagerNoteDisplay))){
				addText(cell, c.getNotes(), false, false, Element.ALIGN_LEFT, color, true);
			} else {
				addText(cell, c.getNotes().substring(0, 30) + "...", false, false, Element.ALIGN_LEFT, color, true);
			}
		}
	}
	
    return cell;
}
 
Example #6
Source File: TableBordersTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading,
		float padding, Rectangle borders, boolean ascender, boolean descender) {
	Paragraph p = new Paragraph(text, font);
	p.setLeading(leading);

	PdfPCell cell = new PdfPCell(p);
	cell.setLeading(leading, 0);
	cell.setVerticalAlignment(vAlignment);
	cell.setHorizontalAlignment(hAlignment);
	cell.cloneNonPositionParameters(borders);
	cell.setUseAscender(ascender);
	cell.setUseDescender(descender);
	cell.setUseBorderPadding(true);
	cell.setPadding(padding);
	return cell;
}
 
Example #7
Source File: PdfClassAssignmentReportListTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
protected PdfPCell pdfBuildInstructor(PreferenceGroup prefGroup, boolean isEditable){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();
	
	if (prefGroup instanceof Class_) {
		Class_ aClass = (Class_) prefGroup;
		if (aClass.isDisplayInstructor()) {
        	TreeSet sortedInstructors = new TreeSet(new InstructorComparator());
        	sortedInstructors.addAll(aClass.getClassInstructors());
    		for (Iterator i=sortedInstructors.iterator(); i.hasNext();) {
    			ClassInstructor ci = (ClassInstructor)i.next();
        		String label = ci.getInstructor().getName(getInstructorNameFormat());
        		addText(cell, label, false, false, Element.ALIGN_LEFT, color, true);
    		}
		}
	}
	
    return cell;
}
 
Example #8
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addCell_WithDropDownListField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName, String[] optionList,
    String[] valueList ) throws IOException, DocumentException
{
    TextField textList = new TextField( writer, rect, strfldName );

    textList.setChoices( optionList );
    textList.setChoiceExports( valueList );

    textList.setBorderWidth( 1 );
    textList.setBorderColor( Color.BLACK );
    textList.setBorderStyle( PdfBorderDictionary.STYLE_SOLID );
    textList.setBackgroundColor( COLOR_BACKGROUDTEXTBOX );

    PdfFormField dropDown = textList.getComboField();

    cell.setCellEvent( new PdfFieldCell( dropDown, rect.getWidth(), rect.getHeight(), writer ) );

    table.addCell( cell );
}
 
Example #9
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
private PdfPCell pdfBuildExamPeriod(ExamAssignmentProxy examAssignment, TreeSet exams, boolean isEditable) {
    StringBuffer sb = new StringBuffer();
    for (Iterator i=exams.iterator();i.hasNext();) {
        Exam exam = (Exam)i.next();
        if (examAssignment!=null && examAssignment.getExamTypeId().equals(exam.getExamType().getUniqueId())) {
            ExamAssignment ea = examAssignment.getAssignment(exam.getUniqueId());
            if (ea==null && !isShowExamName()) continue;
            sb.append(ea==null?"":ea.getPeriodAbbreviation());
        } else {
            if (exam.getAssignedPeriod()==null && !isShowExamName()) continue;
            sb.append(exam.getAssignedPeriod()==null?"":exam.getAssignedPeriod().getAbbreviation());
        }
        if (i.hasNext()) sb.append("\n");
    }
    Color color = (isEditable?sEnableColor:sDisableColor);
    PdfPCell cell = createCell();
    addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, color, true);
    return cell;
}
 
Example #10
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
private PdfPCell pdfBuildExamRoom(ExamAssignmentProxy examAssignment, TreeSet exams, boolean isEditable) {
    StringBuffer sb = new StringBuffer();
    for (Iterator i=exams.iterator();i.hasNext();) {
        Exam exam = (Exam)i.next();
        if (examAssignment!=null && examAssignment.getExamTypeId().equals(exam.getExamType().getUniqueId())) {
            ExamAssignment ea = examAssignment.getAssignment(exam.getUniqueId());
            if (ea==null && !isShowExamName()) continue;
            sb.append(ea==null?"":ea.getRoomsName(", "));
        } else {
            if (exam.getAssignedPeriod()==null && !isShowExamName()) continue;
            for (Iterator j=new TreeSet(exam.getAssignedRooms()).iterator();j.hasNext();) {
                Location location = (Location)j.next();
                sb.append(location.getLabel());
                if (j.hasNext()) sb.append(", ");
            }
        }
        if (i.hasNext()) sb.append("\n");
    }
    Color color = (isEditable?sEnableColor:sDisableColor);
    PdfPCell cell = createCell();
    addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, color, true);
    return cell;
}
 
Example #11
Source File: Cell.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a PdfPCell based on this Cell object.
 * @return a PdfPCell
 * @throws BadElementException
 */
public PdfPCell createPdfPCell() throws BadElementException {
	if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
	if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
	PdfPCell cell = new PdfPCell();
	cell.setVerticalAlignment(verticalAlignment);
	cell.setHorizontalAlignment(horizontalAlignment);
	cell.setColspan(colspan);
	cell.setUseBorderPadding(useBorderPadding);
	cell.setUseDescender(useDescender);
	cell.setLeading(leading(), 0);
	cell.cloneNonPositionParameters(this);
	for (Iterator i = getElements(); i.hasNext(); ) {
		cell.addElement((Element)i.next());
	}
	return cell;
}
 
Example #12
Source File: PdfProcessInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeProcessInformations(ProcessInformations processInformations) {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(processInformations.getUser());
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	addCell(integerFormat.format(processInformations.getPid()));
	if (!windows) {
		addCell(percentFormat.format(processInformations.getCpuPercentage()));
		addCell(percentFormat.format(processInformations.getMemPercentage()));
	}
	addCell(integerFormat.format(processInformations.getVsz()));
	if (!windows) {
		addCell(integerFormat.format(processInformations.getRss()));
		defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
		addCell(processInformations.getTty());
		addCell(processInformations.getStat());
		defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
		addCell(processInformations.getStart());
	}
	addCell(processInformations.getCpuTime());
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(processInformations.getCommand());
}
 
Example #13
Source File: PdfCacheInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeCacheInformations(CacheInformations cacheInformations) {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(cacheInformations.getName());
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	if (configurationEnabled) {
		addCell(integerFormat.format(cacheInformations.getInMemoryPercentUsed()));
	}
	addCell(integerFormat.format(cacheInformations.getInMemoryObjectCount()));
	addCell(integerFormat.format(cacheInformations.getOnDiskObjectCount()));
	if (hitsRatioEnabled) {
		addCell(integerFormat.format(cacheInformations.getInMemoryHitsRatio()));
		addCell(integerFormat.format(cacheInformations.getHitsRatio()));
	}
	if (configurationEnabled) {
		defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
		addCell(cacheInformations.getConfiguration());
	}
}
 
Example #14
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected PdfPCell pdfBuildInstructorAssignment(PreferenceGroup prefGroup, boolean isEditable){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();
	
	if (prefGroup instanceof Class_) {
		Class_ c = (Class_) prefGroup;
		if (c.isInstructorAssignmentNeeded()) {
			addText(cell, (c.effectiveNbrInstructors() > 1 ? c.effectiveNbrInstructors() + " \u00d7 " : "") +
					Formats.getNumberFormat("0.##").format(c.effectiveTeachingLoad()) + " " + MSG.teachingLoadUnits(),
					false, false, Element.ALIGN_RIGHT, color, false);
		} else if (c.getSchedulingSubpart().isInstructorAssignmentNeeded()) {
			addText(cell, MSG.cellNoInstructorAssignment(), false, false, Element.ALIGN_RIGHT, color, false);
		}
	} else if (prefGroup instanceof SchedulingSubpart) {
		SchedulingSubpart ss = (SchedulingSubpart)prefGroup;
		if (ss.isInstructorAssignmentNeeded()) {
			addText(cell, (ss.getNbrInstructors() > 1 ? ss.getNbrInstructors() + " \u00d7 " : "") +
					Formats.getNumberFormat("0.##").format(ss.getTeachingLoad()) + " " + MSG.teachingLoadUnits(),
					false, false, Element.ALIGN_RIGHT, color, false);
		}
	}
	
    return cell;
}
 
Example #15
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
private PdfPCell pdfBuildTimePatternCell(PreferenceGroup prefGroup, boolean isEditable){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();
	for (Iterator i=prefGroup.effectiveTimePatterns().iterator(); i.hasNext();) {
		TimePattern tp = (TimePattern)i.next();
		addText(cell, tp.getName(), false, false, Element.ALIGN_CENTER, color, true);  
	}
    if (prefGroup instanceof Class_ && prefGroup.effectiveTimePatterns().isEmpty()) {
    	Class_ clazz = (Class_)prefGroup;
    	DurationModel dm = clazz.getSchedulingSubpart().getInstrOfferingConfig().getDurationModel();
    	Integer ah = dm.getArrangedHours(clazz.getSchedulingSubpart().getMinutesPerWk(), clazz.effectiveDatePattern());
        if (ah == null) {
            addText(cell, "Arr Hrs", false, false, Element.ALIGN_CENTER, color, true);
        } else {
            addText(cell, "Arr "+ah+" Hrs", false, false, Element.ALIGN_CENTER, color, true);
        }
    }
    return cell;
}
 
Example #16
Source File: PdfClassListTableBuilder.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected PdfPCell pdfBuildPrefGroupLabel(CourseOffering co, PreferenceGroup prefGroup, String indentSpaces, boolean isEditable, String prevLabel) {
	if (prefGroup instanceof Class_) {
		Color color = (isEditable?Color.BLACK:Color.GRAY);
		String label = prefGroup.toString();
    	Class_ aClass = (Class_) prefGroup;
    	label = aClass.getClassLabel(co);
    	if (prevLabel != null && label.equals(prevLabel)){
    		label = "";
    	}
    	PdfPCell cell = createCell();
    	addText(cell, indentSpaces+label, co.isIsControl(), false, Element.ALIGN_LEFT, color, true);
     InstructionalMethod im = aClass.getSchedulingSubpart().getInstrOfferingConfig().getInstructionalMethod();
    	if (im != null)
     	addText(cell, " (" + im.getReference() + ")", false, false, Element.ALIGN_LEFT, color, false);
    	return cell;
	} else return super.pdfBuildPrefGroupLabel(co, prefGroup, indentSpaces, isEditable, null);
}
 
Example #17
Source File: PurchaseOrderQuotePdf.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * A helper method to create a PdfPCell. We can specify the content, font, horizontal alignment, border (borderless, no
 * bottom border, no right border, no top border, etc.
 *
 * @param content              The text content to be displayed in the cell.
 * @param borderless           boolean true if the cell should be borderless.
 * @param noBottom             boolean true if the cell should have borderWidthBottom = 0.
 * @param noRight              boolean true if the cell should have borderWidthRight = 0.
 * @param noTop                boolean true if the cell should have borderWidthTop = 0.
 * @param horizontalAlignment  The desired horizontal alignment for the cell.
 * @param font                 The font type to be used in the cell.
 * @return                     An instance of PdfPCell which content and attributes were set by the input parameters.
 */
private PdfPCell createCell(String content, boolean borderless, boolean noBottom, boolean noRight, boolean noTop, int horizontalAlignment, Font font) {
    PdfPCell tableCell = new PdfPCell(new Paragraph(content, font));
    if (borderless) {
        tableCell.setBorder(0);
    }
    if (noBottom) {
        tableCell.setBorderWidthBottom(0);
    }
    if (noTop) {
        tableCell.setBorderWidthTop(0);
    }
    if (noRight) {
        tableCell.setBorderWidthRight(0);
    }
    tableCell.setHorizontalAlignment(horizontalAlignment);
    return tableCell;
}
 
Example #18
Source File: FieldPositioningEvents.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
	if (cellField == null || fieldWriter == null && parent == null) {
		throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
	}
	cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	if (parent == null) {
		fieldWriter.addAnnotation(cellField);
	} else {
		parent.addKid(cellField);
	}
}
 
Example #19
Source File: IncCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Creates a new instance of IncCell */
public IncCell(String tag, ChainedProperties props) {
    cell = new PdfPCell((Phrase)null);
    String value = props.getProperty("colspan");
    if (value != null)
        cell.setColspan(Integer.parseInt(value));
    value = props.getProperty("align");
    if (tag.equals("th"))
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (value != null) {
        if ("center".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        else if ("right".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        else if ("left".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        else if ("justify".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    }
    value = props.getProperty("valign");
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    if (value != null) {
        if ("top".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_TOP);
        else if ("bottom".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    }
    value = props.getProperty("border");
    float border = 0;
    if (value != null)
        border = Float.parseFloat(value);
    cell.setBorderWidth(border);
    value = props.getProperty("cellpadding");
    if (value != null)
        cell.setPadding(Float.parseFloat(value));
    cell.setUseDescender(true);
    value = props.getProperty("bgcolor");
    cell.setBackgroundColor(Markup.decodeColor(value));
}
 
Example #20
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequest childRequest, float executionsByRequest,
		boolean allChildHitsDisplayed) throws IOException, DocumentException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
	if (executionsByRequest != -1) {
		paragraph.setIndentationLeft(5);
	}
	final Counter parentCounter = getCounterByRequestId(childRequest);
	if (parentCounter != null && parentCounter.getIconName() != null) {
		paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
	}
	paragraph.add(new Phrase(childRequest.getName(), cellFont));
	final PdfPCell requestCell = new PdfPCell();
	requestCell.addElement(paragraph);
	requestCell.setGrayFill(defaultCell.getGrayFill());
	requestCell.setPaddingTop(defaultCell.getPaddingTop());
	addCell(requestCell);

	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	if (executionsByRequest != -1) {
		addCell(nbExecutionsFormat.format(executionsByRequest));
	} else {
		final boolean hasChildren = !request.getChildRequestsExecutionsByRequestId().isEmpty();
		if (hasChildren) {
			addCell("");
		}
	}
	writeRequestValues(childRequest, allChildHitsDisplayed);
}
 
Example #21
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setBorderColor(sBorderColor);
    cell.setPadding(3);
    cell.setBorderWidth(0);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidthTop(1);
    cell.setBorderWidthBottom(1);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthRight(1);
    return cell;
}
 
Example #22
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 5 votes vote down vote up
private PdfPCell pdfBuildRoomLimit(PreferenceGroup prefGroup, boolean isEditable, boolean classLimitDisplayed){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();

	if (prefGroup instanceof Class_){
		Class_ aClass = (Class_) prefGroup;
		if (aClass.getNbrRooms()!=null && aClass.getNbrRooms().intValue()!=1) {
			if (aClass.getNbrRooms().intValue()==0)
				addText(cell, "N/A", false, true, Element.ALIGN_RIGHT, color, true);
			else {
				String text = aClass.getNbrRooms().toString();
				text += " at ";
				if (aClass.getRoomRatio() != null)
					text += sRoomRatioFormat.format(aClass.getRoomRatio().floatValue());
				else
					text += "0";
				addText(cell, text, false, false, Element.ALIGN_RIGHT, color, true);
			}
		} else {
			if (aClass.getRoomRatio() != null){
				if (classLimitDisplayed && aClass.getRoomRatio().equals(new Float(1.0))){
					addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
				} else {
					addText(cell, sRoomRatioFormat.format(aClass.getRoomRatio().floatValue()), false, false, Element.ALIGN_RIGHT, color, true);
				}
			} else {
				if (aClass.getExpectedCapacity() == null){
					addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
				} else {
					addText(cell, "0", false, false, Element.ALIGN_RIGHT, color, true);
				}
			}
		}
	}
	
    return cell;
}
 
Example #23
Source File: IncTable.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public PdfPTable buildTable() {
	if (rows.isEmpty()) {
		return new PdfPTable(1);
	}
	int ncol = 0;
	ArrayList c0 = (ArrayList) rows.get(0);
	for (int k = 0; k < c0.size(); ++k) {
		ncol += ((PdfPCell) c0.get(k)).getColspan();
	}
	PdfPTable table = new PdfPTable(ncol);
	String width = (String) props.get("width");
	if (width == null) {
		table.setWidthPercentage(100);
	} else {
		if (width.endsWith("%")) {
			table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
		} else {
			table.setTotalWidth(Float.parseFloat(width));
			table.setLockedWidth(true);
		}
	}
	for (int row = 0; row < rows.size(); ++row) {
		ArrayList col = (ArrayList) rows.get(row);
		for (int k = 0; k < col.size(); ++k) {
			table.addCell((PdfPCell) col.get(k));
		}
	}
	return table;
}
 
Example #24
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an empty cell.
 *
 * @param colspan The column span of the cell.
 * @param height  The height of the column.
 * @return A PdfCell.
 */
public static PdfPCell getEmptyCell( int colSpan, int height )
{
    PdfPCell cell = new PdfPCell();

    cell.setColspan( colSpan );
    cell.setBorder( 0 );
    cell.setMinimumHeight( height );

    return cell;
}
 
Example #25
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void printRowHeaderCell(String name, int idx, int maxIdx, boolean vertical, boolean head, boolean in) {
    PdfPCell c = createCell();
    c.setBorderWidthTop(idx==0 && (head || (!in && !vertical)) ? 1 : 0);
    c.setBorderWidthBottom(idx<maxIdx ? 0 : 1);
    c.setBorderWidthRight(0);
    if (idx==0) addText(c, name);
    iPdfTable.addCell(c);
}
 
Example #26
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public PdfPCell createCellNoBorder() {
    PdfPCell cell = new PdfPCell();
    cell.setBorderColor(sBorderColor);
    cell.setPadding(3);
    cell.setBorderWidth(0);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;
}
 
Example #27
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a cell.
 *
 * @param text            The text to include in the cell.
 * @param colspan         The column span of the cell.
 * @param font            The font of the cell text.
 * @param horizontalAlign The vertical alignment of the text in the cell.
 * @return A PdfCell.
 */
public static PdfPCell getCell( String text, int colspan, Font font, int horizontalAlign )
{
    Paragraph paragraph = new Paragraph( text, font );

    PdfPCell cell = new PdfPCell( paragraph );

    cell.setColspan( colspan );
    cell.setBorder( 0 );
    cell.setMinimumHeight( 15 );
    cell.setHorizontalAlignment( horizontalAlign );

    return cell;
}
 
Example #28
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCell_WithPushButtonField( PdfPTable table, PdfWriter writer, PdfPCell cell, String strfldName, String jsAction )
{
    cell.setCellEvent( new PdfFieldCell( null, jsAction, "BTN_SAVEPDF", "Save PDF", PdfFieldCell.TYPE_BUTTON,
        writer ) );

    table.addCell( cell );
}
 
Example #29
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
	if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
	BaseFont bf = font.getBaseFont();
	float width = bf.getWidthPoint(text, font.getSize());
	PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
	template.beginText();
	template.setColorFill(Color.BLACK);
	template.setFontAndSize(bf, font.getSize());
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(font.getSize() + 2);
	//make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(270);
	//embed the image in a Chunk
	Chunk ck = new Chunk(img, 0, 0);
	
	if (cell.getPhrase()==null) {
		cell.setPhrase(new Paragraph(ck));
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	} else {
		cell.getPhrase().add(ck);
	}
}
 
Example #30
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequestValues(CounterRequest aRequest, boolean allChildHitsDisplayed) {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	addCell(integerFormat.format(aRequest.getMean()));
	addCell(integerFormat.format(aRequest.getMaximum()));
	addCell(integerFormat.format(aRequest.getStandardDeviation()));
	if (aRequest.getCpuTimeMean() >= 0) {
		addCell(integerFormat.format(aRequest.getCpuTimeMean()));
	} else {
		addCell("");
	}
	if (isAllocatedKBytesDisplayed()) {
		if (aRequest.getAllocatedKBytesMean() >= 0) {
			addCell(integerFormat.format(aRequest.getAllocatedKBytesMean()));
		} else {
			addCell("");
		}
	}
	addCell(systemErrorFormat.format(aRequest.getSystemErrorPercentage()));
	if (allChildHitsDisplayed) {
		final boolean childHitsDisplayed = aRequest.hasChildHits();
		if (childHitsDisplayed) {
			addCell(integerFormat.format(aRequest.getChildHitsMean()));
		} else {
			addCell("");
		}
		if (childHitsDisplayed) {
			addCell(integerFormat.format(aRequest.getChildDurationsMean()));
		} else {
			addCell("");
		}
	}
}