List of usage examples for com.lowagie.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
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 2 s . com*/ //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 void pdfAddInstrOffrRowsToTable(ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, InstructionalOffering io, Long subjectAreaId, SessionContext context) {//w w w . j a v a 2 s . c o m iBgColor = sBgColorOffering; CourseOffering co = io.findSortCourseOfferingForSubjectArea(subjectAreaId); boolean isEditable = context.hasPermission(co.getInstructionalOffering(), Right.InstructionalOfferingDetail); boolean isManagedAs = !co.isIsControl().booleanValue(); Color color = (isEditable ? sEnableColor : sDisableColor); if (isShowLabel()) { iPdfTable.addCell(pdfSubjectAndCourseInfo(io, co)); } if (isShowDivSec()) { iPdfTable.addCell(createCell()); } if (isShowDemand()) { PdfPCell cell = createCell(); if (StudentClassEnrollment.sessionHasEnrollments(io.getSessionId())) { addText(cell, (io.getEnrollment() != null ? io.getEnrollment().toString() : "0"), false, false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true); } else { addText(cell, (io.getDemand() != null ? io.getDemand().toString() : "0"), false, false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true); } iPdfTable.addCell(cell); } if (isShowProjectedDemand()) { PdfPCell cell = createCell(); addText(cell, (io.getProjectedDemand() != null ? io.getProjectedDemand().toString() : "0"), false, false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true); iPdfTable.addCell(cell); } if (isShowLimit()) { boolean unlimited = false; for (Iterator x = io.getInstrOfferingConfigs().iterator(); !unlimited && x.hasNext();) if ((((InstrOfferingConfig) x.next())).isUnlimitedEnrollment().booleanValue()) unlimited = true; PdfPCell cell = createCell(); addText(cell, (unlimited ? "inf" : io.getLimit() == null ? "0" : io.getLimit().toString()), false, false, Element.ALIGN_RIGHT, (co.isIsControl() ? color : sDisableColor), true); iPdfTable.addCell(cell); } int emptyCels = 0; if (isShowRoomRatio()) { emptyCels++; } if (isShowManager()) { emptyCels++; } if (isShowDatePattern()) { emptyCels++; } if (isShowMinPerWk()) { emptyCels++; } if (isShowTimePattern()) { emptyCels++; } if (isShowPreferences()) { emptyCels += PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1); } if (isShowInstructor()) { emptyCels++; } if (getDisplayTimetable() && isShowTimetable()) { emptyCels += TIMETABLE_COLUMN_ORDER.length; } if (emptyCels > 0) { PdfPCell managedCell = createCell(); if (isManagedAs) { if (!isShowTitle() && io.getControllingCourseOffering().getTitle() != null) { if (co.getTitle() != null && co.getTitle().length() > 0) { addText(managedCell, " " + co.getTitle() + " (Managed As " + io.getControllingCourseOffering().getCourseName() + ")", true, false, Element.ALIGN_LEFT, sDisableColor, false); } else { addText(managedCell, " Managed As " + io.getControllingCourseOffering().getCourseName(), true, false, Element.ALIGN_LEFT, sDisableColor, true); } for (Iterator it = io .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId()) .iterator(); it.hasNext();) { CourseOffering x = (CourseOffering) it.next(); addText(managedCell, (x.getTitle() == null ? "" : " " + x.getTitle()), false, false, Element.ALIGN_LEFT, sDisableColor, true); } } else { addText(managedCell, " Managed As " + io.getControllingCourseOffering().getCourseName(), true, false, Element.ALIGN_LEFT, sDisableColor, true); } } else { if (!isShowTitle() && io.getControllingCourseOffering().getTitle() != null) { addText(managedCell, (co.getTitle() == null ? "" : " " + co.getTitle()), true, false, Element.ALIGN_LEFT, color, true); for (Iterator it = io .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId()) .iterator(); it.hasNext();) { CourseOffering x = (CourseOffering) it.next(); addText(managedCell, (x.getTitle() == null ? "" : " " + x.getTitle()), false, false, Element.ALIGN_LEFT, sDisableColor, true); } } } managedCell.setColspan(emptyCels); iPdfTable.addCell(managedCell); } if (isShowTitle()) { PdfPCell titleCell = createCell(); addText(titleCell, (io.getControllingCourseOffering().getTitle() != null ? " " + io.getControllingCourseOffering().getTitle() : ""), false, false, Element.ALIGN_LEFT, color, true); iPdfTable.addCell(titleCell); } if (isShowCredit()) { PdfPCell cell = createCell(); addText(cell, (co.getCredit() != null ? co.getCredit().creditAbbv() : ""), true, false, Element.ALIGN_LEFT, isManagedAs ? sDisableColor : color, true); for (Iterator it = io .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId()) .iterator(); it.hasNext();) { CourseOffering x = (CourseOffering) it.next(); addText(cell, (x.getCredit() != null ? x.getCredit().creditAbbv() : ""), false, false, Element.ALIGN_LEFT, sDisableColor, true); } iPdfTable.addCell(cell); } if (isShowSubpartCredit()) { iPdfTable.addCell(createCell()); } if (isShowConsent()) { PdfPCell cell = createCell(); addText(cell, co.getConsentType() != null ? co.getConsentType().getAbbv() : MSG.noConsentRequired(), true, false, Element.ALIGN_LEFT, isManagedAs ? sDisableColor : color, true); for (Iterator it = io .courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId()) .iterator(); it.hasNext();) { CourseOffering x = (CourseOffering) it.next(); addText(cell, (x.getConsentType() != null ? x.getConsentType().getAbbv() : MSG.noConsentRequired()), false, false, Element.ALIGN_LEFT, sDisableColor, true); } iPdfTable.addCell(cell); } if (isShowSchedulePrintNote()) { iPdfTable.addCell(pdfBuildSchedulePrintNote(io, isEditable, context.getUser())); } if (isShowNote()) { iPdfTable.addCell(createCell()); } if (isShowExam()) { TreeSet exams = new TreeSet(Exam.findAll(ExamOwner.sOwnerTypeOffering, io.getUniqueId())); for (Iterator i = io.getCourseOfferings().iterator(); i.hasNext();) { CourseOffering cox = (CourseOffering) i.next(); exams.addAll(Exam.findAll(ExamOwner.sOwnerTypeCourse, cox.getUniqueId())); } if (io.getInstrOfferingConfigs().size() == 1) { for (Iterator i = io.getInstrOfferingConfigs().iterator(); i.hasNext();) { InstrOfferingConfig ioc = (InstrOfferingConfig) i.next(); exams.addAll(Exam.findAll(ExamOwner.sOwnerTypeConfig, ioc.getUniqueId())); } } if (isShowExamName()) { iPdfTable.addCell(pdfBuildExamName(exams, isEditable)); } if (isShowExamTimetable()) { iPdfTable.addCell(pdfBuildExamPeriod(examAssignment, exams, isEditable)); iPdfTable.addCell(pdfBuildExamRoom(examAssignment, exams, isEditable)); } } if (io.getInstrOfferingConfigs() != null & !io.getInstrOfferingConfigs().isEmpty()) { TreeSet configs = new TreeSet(new InstrOfferingConfigComparator( io.getControllingCourseOffering().getSubjectArea().getUniqueId())); configs.addAll(io.getInstrOfferingConfigs()); pdfBuildConfigRows(classAssignment, examAssignment, io.getControllingCourseOffering(), configs, context, true); } }
From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java
License:Open Source License
public void printLegend() throws Exception { iPdfTable = new PdfPTable(2); iPdfTable.setWidths(new float[] { 10f, 200f }); iPdfTable.getDefaultCell().setPadding(3); iPdfTable.getDefaultCell().setBorderWidth(1); iPdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.setSplitRows(false);//from www .j av a 2 s. c om iPdfTable.setSpacingBefore(10); iPdfTable.setKeepTogether(true); if (iForm.getBackground() != sBgNone) { PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Assigned examinations:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); } if (iForm.getBackground() == sBgPeriodPref) { addLegendRow(pref2color(PreferenceLevel.sRequired), "Required period"); addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred period"); addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred period"); addLegendRow(pref2color(PreferenceLevel.sNeutral), "No period preference"); addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged period"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged period"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited period"); } else if (iForm.getBackground() == sBgRoomPref) { addLegendRow(pref2color(PreferenceLevel.sRequired), "Required room"); addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred room"); addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred room"); addLegendRow(pref2color(PreferenceLevel.sNeutral), "No room preference"); addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged room"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged room"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited room"); } else if (iForm.getBackground() == sBgInstructorConfs) { addLegendRow(pref2color(PreferenceLevel.sNeutral), "No instructor conflict"); addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "One or more instructor back-to-back conflicts"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "One or more instructor three or more exams a day conflicts"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "One or more instructor direct conflicts"); } else if (iForm.getBackground() == sBgStudentConfs) { addLegendRow(pref2color(PreferenceLevel.sNeutral), "No student conflict"); addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "One or more student back-to-back conflicts"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "One or more student three or more exams a day student conflicts"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "One or more student direct conflicts"); } else if (iForm.getBackground() == sBgDirectInstructorConfs) { for (int nrConflicts = 0; nrConflicts <= 6; nrConflicts++) { String color = lessConflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 6 ? "or more " : "") + "instructor direct conflicts"); } } else if (iForm.getBackground() == sBgMoreThanTwoADayInstructorConfs) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "instructor more than two exams a day conflicts"); } } else if (iForm.getBackground() == sBgBackToBackInstructorConfs) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "instructor back to back conflicts"); } } else if (iForm.getBackground() == sBgDirectStudentConfs) { for (int nrConflicts = 0; nrConflicts <= 6; nrConflicts++) { String color = lessConflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 6 ? "or more " : "") + "student direct conflicts"); } } else if (iForm.getBackground() == sBgMoreThanTwoADayStudentConfs) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "student more than two exams a day conflicts"); } } else if (iForm.getBackground() == sBgBackToBackStudentConfs) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "student back to back conflicts"); } } else if (iForm.getBackground() == sBgDistPref) { addLegendRow(pref2color(PreferenceLevel.sNeutral), "No violated constraint<i>(distance=0)</i>"); addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged/preferred constraint violated"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged/preferred constraint violated</i>"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "Required/prohibited constraint violated</i>"); } PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Free times:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); addLegendRow(sBgColorNotAvailable, "Period not available"); if (iForm.getBgPreferences() && iForm.getBackground() == sBgPeriodPref) { addLegendRow(pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred period"); addLegendRow(pref2color(PreferenceLevel.sPreferred), "Preferred period"); } addLegendRow(pref2color(PreferenceLevel.sNeutral), "No period preference"); if (iForm.getBgPreferences() && iForm.getBackground() == sBgPeriodPref) { addLegendRow(pref2color(PreferenceLevel.sDiscouraged), "Discouraged period"); addLegendRow(pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged period"); addLegendRow(pref2color(PreferenceLevel.sProhibited), "Prohibited period"); } iDocument.add(iPdfTable); }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void printHeader(TimetableGridModel model, int rowNumber) throws Exception { if (iTable.isDispModePerWeekVertical()) { for (int slot = iTable.lastSlot(); slot >= iTable.firstSlot(); slot -= iTable.nrSlotsPerPeriod()) { int time = (slot - iTable.nrSlotsPerPeriod() + 1) * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN; PdfPCell c = createCell(); c.setColspan(iTable.nrSlotsPerPeriod()); if (slot < iTable.lastSlot()) c.setBorderWidthLeft(0); addTextVertical(c, Constants.toTime(time), true); iPdfTable.addCell(c);//from w w w . j av a 2 s . c om } PdfPCell c = createCell(); c.setColspan(12); c.setBorderWidthLeft(0); addTextVertical(c, model.getName() + (model.getSize() > 0 ? " (" + model.getSize() + ")" : ""), true); iPdfTable.addCell(c); } else { PdfPCell c = createCell(); c.setColspan(12); if (iTable.isDispModeInRow()) addText(c, Constants.DAY_NAME[iDay], true); else addText(c, model.getName() + (model.getSize() > 0 ? " (" + model.getSize() + ")" : ""), true); iPdfTable.addCell(c); for (int slot = iTable.firstSlot(); slot <= iTable.lastSlot(); slot += iTable.nrSlotsPerPeriod()) { int time = slot * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN; c = createCell(); c.setBorderWidthLeft(0); c.setColspan(iTable.nrSlotsPerPeriod()); addText(c, Constants.toTime(time), true); iPdfTable.addCell(c); } } iPdfTable.setHeaderRows(1); }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void printToPdf(TimetableGridModel model, int rowNumber) throws Exception { model.clearRendered();//from www . j a v a2s . com if (iTable.isDispModePerWeek()) { createTable(); printHeader(model, 0); } else { if (rowNumber == 0) { createTable(); printHeader(model, 0); } } if (iTable.isDispModeInRow()) { int maxIdx = model.getMaxIdxForDay(iDay, iTable.firstSlot(), iTable.lastSlot()); for (int idx = 0; idx <= maxIdx; idx++) { PdfPCell c = createCell(); c.setBorderWidthTop(0); if (idx == 0) addText(c, model.getName() + (model.getSize() > 0 ? " (" + model.getSize() + ")" : ""), true); c.setBorderWidthBottom(idx == maxIdx ? 1 : 0); c.setColspan(12); iPdfTable.addCell(c); for (int slot = iTable.firstSlot(); slot <= iTable.lastSlot(); slot++) { int slotsToEnd = iTable.lastSlot() - slot + 1; TimetableGridCell cell = model.getCell(iDay, slot, idx); int length = (cell == null ? 1 : cell.getLength() + cell.getSlot() - slot); int colSpan = (cell == null ? 1 : Math.min(length, slotsToEnd)); if (cell == null) { String bgColor = model.getBackground(iDay, slot); if (bgColor == null && !model.isAvailable(iDay, slot)) bgColor = TimetableGridCell.sBgColorNotAvailable; c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthBottom( idx == maxIdx ? 1 : model.getCell(iDay, slot, idx + 1) != null ? 1 : 0); c.setBorderWidthLeft(0); boolean eod = (slot == iTable.lastSlot()); boolean in = !eod && model.getCell(iDay, slot + 1, idx) == null && ((slot + 1 - iTable.firstSlot()) % iTable.nrSlotsPerPeriod()) != 0; c.setBorderWidthRight(eod || !in ? 1 : 0); c.setColspan(colSpan); if (bgColor != null) c.setBackgroundColor(getColor(bgColor)); iPdfTable.addCell(c); } else { String bgColor = cell.getBackground(); if (iTable.getBgMode() == TimetableGridModel.sBgModeNone) { for (int i = 0; i < length; i++) if (!model.isAvailable(iDay, slot + i)) { bgColor = TimetableGridCell.sBgColorNotAvailableButAssigned; break; } } c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthLeft(0); c.setColspan(colSpan); c.setBackgroundColor(getColor(bgColor)); addText(c, cell.getName()); if (iTable.getShowTimes()) addText(c, cell.getTime()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeRoom) addText(c, cell.getRoomName()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeInstructor && iTable.getShowInstructors() && !cell.getInstructor().isEmpty()) addText(c, cell.getInstructor()); if (iTable.getShowComments()) addText(c, cell.getShortCommentNoColors() == null ? null : cell.getShortCommentNoColors()); if (iTable.getWeek() == -100 && cell.hasDays() && !cell.getDays().equals(iTable.getDefaultDatePatternName())) addText(c, cell.getDays()); iPdfTable.addCell(c); slot += length - 1; } } } } else if (iTable.isDispModePerWeekHorizontal()) { for (int day = iTable.startDay(); day <= iTable.endDay(); day++) { int maxIdx = model.getMaxIdxForDay(day, iTable.firstSlot(), iTable.lastSlot()); for (int idx = 0; idx <= maxIdx; idx++) { PdfPCell c = createCell(); c.setBorderWidthTop(0); if (idx == 0) addText(c, Constants.DAY_NAME[day], true); c.setBorderWidthBottom(idx == maxIdx ? 1 : 0); c.setColspan(12); iPdfTable.addCell(c); for (int slot = iTable.firstSlot(); slot <= iTable.lastSlot(); slot++) { int slotsToEnd = iTable.lastSlot() - slot + 1; TimetableGridCell cell = model.getCell(day, slot, idx); int length = (cell == null ? 1 : cell.getLength() + cell.getSlot() - slot); int colSpan = (cell == null ? 1 : Math.min(length, slotsToEnd)); if (cell == null) { String bgColor = model.getBackground(day, slot); if (bgColor == null && !model.isAvailable(day, slot)) bgColor = TimetableGridCell.sBgColorNotAvailable; c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthBottom( idx == maxIdx ? 1 : model.getCell(day, slot, idx + 1) != null ? 1 : 0); c.setBorderWidthLeft(0); boolean eod = (slot == iTable.lastSlot()); boolean in = !eod && model.getCell(day, slot + 1, idx) == null && ((slot + 1 - iTable.firstSlot()) % iTable.nrSlotsPerPeriod()) != 0; c.setBorderWidthRight(eod || !in ? 1 : 0); iPdfTable.addCell(c); } else { String bgColor = cell.getBackground(); if (iTable.getBgMode() == TimetableGridModel.sBgModeNone) { for (int i = 0; i < length; i++) if (!model.isAvailable(day, slot + i)) { bgColor = TimetableGridCell.sBgColorNotAvailableButAssigned; break; } } c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthLeft(0); c.setColspan(colSpan); if (bgColor != null) c.setBackgroundColor(getColor(bgColor)); addText(c, cell.getName()); if (iTable.getShowTimes()) addText(c, cell.getTime()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeRoom) addText(c, cell.getRoomName()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeInstructor && iTable.getShowInstructors() && !cell.getInstructor().isEmpty()) addText(c, cell.getInstructor()); if (iTable.getShowComments()) addText(c, cell.getShortCommentNoColors() == null ? null : cell.getShortCommentNoColors()); if (iTable.getWeek() == -100 && cell.hasDays() && !cell.getDays().equals(iTable.getDefaultDatePatternName())) addText(c, cell.getDays()); iPdfTable.addCell(c); slot += length - 1; } } } } } else if (iTable.isDispModeWeekByWeekHorizontal()) { Calendar cal = Calendar.getInstance(Locale.US); cal.setTime(iTable.iFirstDate); for (int d = 0; d < 365; d++) { if (d > 0) cal.add(Calendar.DAY_OF_YEAR, 1); int date = d + iTable.iFirstDay; if (model.getFirstDay() >= 0 && (date < model.getFirstDay() || date > model.getFirstDay() + 6)) continue; int day = d % 7; if (day < iTable.startDay() || day > iTable.endDay()) continue; boolean hasClasses = false; for (int slot = iTable.firstSlot(); slot <= iTable.lastSlot(); slot++) { if (model.getCell(day, slot, 0, date) != null) { hasClasses = true; break; } } if (!hasClasses) continue; int maxIdx = model.getMaxIdxForDay(day, iTable.firstSlot(), iTable.lastSlot(), date); for (int idx = 0; idx <= maxIdx; idx++) { PdfPCell c = createCell(); c.setBorderWidthTop(0); if (idx == 0) addText(c, Constants.DAY_NAME[day] + " " + sDF.format(cal.getTime()), true); c.setBorderWidthBottom(idx == maxIdx ? 1 : 0); c.setColspan(12); iPdfTable.addCell(c); for (int slot = iTable.firstSlot(); slot <= iTable.lastSlot(); slot++) { int slotsToEnd = iTable.lastSlot() - slot + 1; TimetableGridCell cell = model.getCell(day, slot, idx, date); int length = (cell == null ? 1 : cell.getLength() + cell.getSlot() - slot); int colSpan = (cell == null ? 1 : Math.min(length, slotsToEnd)); if (cell == null) { String bgColor = model.getBackground(day, slot); if (bgColor == null && !model.isAvailable(day, slot)) bgColor = TimetableGridCell.sBgColorNotAvailable; c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthBottom( idx == maxIdx ? 1 : model.getCell(day, slot, idx + 1, date) != null ? 1 : 0); c.setBorderWidthLeft(0); boolean eod = (slot == iTable.lastSlot()); boolean in = !eod && model.getCell(day, slot + 1, idx, date) == null && ((slot + 1 - iTable.firstSlot()) % iTable.nrSlotsPerPeriod()) != 0; c.setBorderWidthRight(eod || !in ? 1 : 0); iPdfTable.addCell(c); } else { String bgColor = cell.getBackground(); if (iTable.getBgMode() == TimetableGridModel.sBgModeNone) { for (int i = 0; i < length; i++) if (!model.isAvailable(day, slot + i)) { bgColor = TimetableGridCell.sBgColorNotAvailableButAssigned; break; } } c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthLeft(0); c.setColspan(colSpan); if (bgColor != null) c.setBackgroundColor(getColor(bgColor)); addText(c, cell.getName()); if (iTable.getShowTimes()) addText(c, cell.getTime()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeRoom) addText(c, cell.getRoomName()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeInstructor && iTable.getShowInstructors() && !cell.getInstructor().isEmpty()) addText(c, cell.getInstructor()); if (iTable.getShowComments()) addText(c, cell.getShortCommentNoColors() == null ? null : cell.getShortCommentNoColors()); iPdfTable.addCell(c); slot += length - 1; } } } } } else { //isDispModePerWeekVertical for (int day = iTable.startDay(); day <= iTable.endDay(); day++) { int maxIdx = model.getMaxIdxForDay(day, iTable.firstSlot(), iTable.lastSlot()); for (int idx = 0; idx <= maxIdx; idx++) { PdfPCell c = null; for (int slot = iTable.lastSlot(); slot >= iTable.firstSlot(); slot--) { int slotsToEnd = slot + 1 - iTable.firstSlot(); TimetableGridCell cell = model.getCell(day, slot, idx); int length = (cell == null ? 1 : 1 + slot - cell.getSlot()); int colSpan = (cell == null ? 1 : Math.min(length, slotsToEnd)); if (cell == null) { String bgColor = model.getBackground(day, slot); if (bgColor == null && !model.isAvailable(day, slot)) bgColor = TimetableGridCell.sBgColorNotAvailable; c = createCell(); c.setBorderWidthTop(0); c.setMinimumHeight(100f); c.setBorderWidthBottom( idx == maxIdx ? 1 : model.getCell(day, slot, idx + 1) != null ? 1 : 0); c.setBorderWidthLeft(slot == iTable.lastSlot() ? 1 : 0); boolean eod = (slot == iTable.firstSlot()); boolean in = !eod && model.getCell(day, slot - 1, idx) == null && ((slot - iTable.firstSlot()) % iTable.nrSlotsPerPeriod()) != 0; c.setBorderWidthRight(eod || !in ? 1 : 0); iPdfTable.addCell(c); } else { String bgColor = cell.getBackground(); if (iTable.getBgMode() == TimetableGridModel.sBgModeNone) { for (int i = 0; i < length; i++) if (!model.isAvailable(day, slot - i)) { bgColor = TimetableGridCell.sBgColorNotAvailableButAssigned; break; } } c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthLeft(slot == iTable.lastSlot() ? 1 : 0); c.setColspan(colSpan); if (bgColor != null) c.setBackgroundColor(getColor(bgColor)); if (iTable.getWeek() == -100 && cell.hasDays() && !cell.getDays().equals(iTable.getDefaultDatePatternName())) addTextVertical(c, cell.getDays()); if (iTable.getShowTimes()) addText(c, cell.getTime()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeRoom) addTextVertical(c, cell.getRoomName()); if (iTable.getResourceType() != TimetableGridModel.sResourceTypeInstructor && iTable.getShowInstructors() && !cell.getInstructor().isEmpty()) addTextVertical(c, cell.getInstructor()); if (iTable.getShowComments()) addTextVertical(c, cell.getShortCommentNoColors() == null ? null : cell.getShortCommentNoColors()); addTextVertical(c, cell.getName()); iPdfTable.addCell(c); slot -= length - 1; } } c = createCell(); c.setBorderWidthTop(0); c.setBorderWidthLeft(0); if (idx == 0) addTextVertical(c, Constants.DAY_NAME[day], true); c.setBorderWidthBottom(idx == maxIdx ? 1 : 0); c.setColspan(12); iPdfTable.addCell(c); } } /* int step = iTable.nrSlotsPerPeriod(); for (int slot=iTable.firstSlot();slot<=iTable.lastSlot();slot+=step) { int time = slot * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN; int slotsToEnd = iTable.lastSlot()-slot+1; if ((slot%iTable.nrSlotsPerPeriod()) == 0) { c = createCell("TimetableHeadCell"+(slot==iTable.firstSlot()?"":"In")+"Vertical"); addText(c, Constants.toTime(time), true); iPdfTable.addCell(c); } else { c = createCell("TimetableHeadCellInVertical"); iPdfTable.addCell(c); } for (int day=iTable.startDay();day<=iTable.endDay();day++) { int maxIdx = model.getMaxIdxForDay(day,iTable.firstSlot(),iTable.lastSlot()); for (int idx=0;idx<=maxIdx;idx++) { TimetableGridCell cell = model.getCell(day,slot, idx); if (model.isRendered(day,slot,idx)) continue; int rowSpan = (cell==null?1:Math.min(cell.getLength()+cell.getSlot()-slot,slotsToEnd)); int colSpan = (iTable.getResourceType()==TimetableGridModel.sResourceTypeDepartment && cell!=null?1:model.getDepth(day,slot,idx,maxIdx,rowSpan)); model.setRendered(day,slot,idx,colSpan,rowSpan); int rowSpanDivStep = (int)Math.ceil(((double)rowSpan)/step); if (cell==null) { String bgColor = model.getBackground(day,slot); if (bgColor==null && !model.isAvailable(day,slot)) bgColor=TimetableGridCell.sBgColorNotAvailable; boolean eol = (day==iTable.endDay() && (idx+colSpan-1)==maxIdx); c = createCell("TimetableCell"+(slot==iTable.firstSlot()?"":"In")+"Vertical"+(eol?"EOL":"")); c.setColspan(colSpan); //c.setRowspan(rowSpanDivStep); if (bgColor!=null) c.setBackgroundColor(getColor(bgColor)); iPdfTable.addCell(c); } else { String bgColor = cell.getBackground(); if (iTable.getBgMode()==TimetableGridModel.sBgModeNone) { for (int i=0;i<cell.getLength();i++) if (!model.isAvailable(day,slot+i)) { bgColor = TimetableGridCell.sBgColorNotAvailableButAssigned; break; } } boolean eol = (day==iTable.endDay()); c = createCell("TimetableCell"+(slot==iTable.firstSlot()?"":"In")+"Vertical" + (eol?"EOL":"")); c.setColspan(colSpan); //c.setRowspan(rowSpanDivStep); if (bgColor!=null) c.setBackgroundColor(getColor(bgColor)); addText(c, cell.getName()); if (iTable.getResourceType()!=TimetableGridModel.sResourceTypeRoom) addText(c, cell.getRoomName()); if (iTable.getShowComments()) addText(c, cell.getShortComment()==null?"":cell.getShortComment()); if (iTable.getWeek()==-100 && cell.hasDays() && !cell.getDays().equals(iTable.getDefaultDatePatternName())) addText(c, cell.getDays()); iPdfTable.addCell(c); } } } } */ } if (iTable.isDispModePerWeek()) { flushTable(); } }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void printLegend() throws Exception { iPdfTable = new PdfPTable(2); iPdfTable.setWidths(new float[] { 10f, 200f }); iPdfTable.getDefaultCell().setPadding(3); iPdfTable.getDefaultCell().setBorderWidth(1); iPdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.setSplitRows(false);/*from www.j av a 2 s . c o m*/ iPdfTable.setSpacingBefore(10); iPdfTable.setKeepTogether(true); if (iTable.getBgMode() != TimetableGridModel.sBgModeNone) { PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Assigned classes:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); } if (iTable.getBgMode() == TimetableGridModel.sBgModeTimePref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No time preference"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited time"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeRoomPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No room preference"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited room"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeStudentConf) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = TimetableGridCell.conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "student conflicts"); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeInstructorBtbPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No instructor back-to-back preference (distance=0)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged back-to-back (0<distance<=5)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged back-to-back (5<distance<=20)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited back-to-back (20<distance)"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDistributionConstPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No violated constraint(distance=0)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged/preferred constraint violated"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged/preferred constraint violated"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Required/prohibited constraint violated"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbations) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "No change"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No initial assignment"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Room changed"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Time changed"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Both time and room changed"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbationPenalty) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = TimetableGridCell.conflicts2color(nrConflicts); addLegendRow(color, "" + (nrConflicts == 0 ? "Zero perturbation penalty" : nrConflicts == 15 ? "Perturbation penalty above 15" : "Perturbation penalty below or equal to " + nrConflicts) + ""); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeHardConflicts) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time and room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Can be moved in room with no hard conflict"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Can be moved in room (but there is a hard conflict), can be moved in time with no conflict"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "Can be moved in room (but there is a hard conflict)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Can be moved in time with no hard conflict, cannot be moved in room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Can be moved in time (but there is a hard conflict), cannot be moved in room"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDepartmentalBalancing) { for (int nrConflicts = 0; nrConflicts <= 3; nrConflicts++) { String color = TimetableGridCell.conflicts2colorFast(nrConflicts); addLegendRow(color, "" + (nrConflicts == 0 ? "Zero penalty" : nrConflicts == 3 ? "Penalty equal or above 3" : "Penalty equal to " + nrConflicts) + ""); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeTooBigRooms) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Assigned room is smaller than room limit of a class"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "Assigned room is not more than 25% bigger than the smallest avaialable room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Assigned room is not more than 50% bigger than the smallest avaialable room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Assigned room is more than 50% bigger than the smallest avaialable room"); } PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Free times:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); addLegendRow(TimetableGridCell.sBgColorNotAvailable, "Time not available"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No preference"); if (iTable.getShowUselessTimes()) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Standard (MWF or TTh) time pattern is broken (time cannot be used for MW, WF, MF or TTh class)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Useless half-hour"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Useless half-hour and broken standard time pattern"); } if (iTable.isDispModePerWeekVertical()) iDocument.newPage(); iDocument.add(iPdfTable); }
From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java
License:Apache License
/** * @param table//from w ww. j av a 2 s .c om * @param footer * @param header * @return */ public PdfPTable pdfExport(Table table) { TableExportOptions exportOptions = table.getExportOptions(); boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns(); Font headfont = new Font(Font.UNDEFINED, Font.DEFAULTSIZE, Font.BOLD); Font bodyfont = new Font(exportOptions.getPdfFontSize(), exportOptions.getPdfFontSize(), Font.NORMAL); if (exportOptions.getPdfFontColour() != null) { Color fontColor = exportOptions.getPdfFontColour(); bodyfont.setColor(fontColor); headfont.setColor(fontColor); } List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table); int columnCount = 0; for (int i = 0; i < columns.size(); i++) { TableColumn c = (TableColumn) columns.get(i); //hide select checkbox column if (!c.isExporatble()) continue; columnCount++; } PdfPTable resulttable = new PdfPTable(columnCount); resulttable.setWidthPercentage(100f); if (StringUtils.isNotEmpty(exportOptions.getTableHeadline())) { PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableHeadline())); cell.setColspan(columns.size()); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } for (int i = 0; i < columns.size(); i++) { TableColumn c = (TableColumn) columns.get(i); // hide select checkbox column if (!c.isExporatble()) continue; String cellData = TextService.getString(c.getTitle()); if (cellData.contains("<br/>") || cellData.contains("<br>")) { cellData = cellData.replaceAll("<br\\/>", "\\/"); cellData = cellData.replaceAll("<br>", "\\/"); } PdfPCell cell = new PdfPCell(new Paragraph((cellData), headfont)); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } List tabledata = table.getDefaultModel().getFilteredList(); if (tabledata.isEmpty()) { for (int i = 0; i < columns.size(); i++) { resulttable.addCell(new PdfPCell((new Phrase("")))); } } for (Iterator it = tabledata.iterator(); it.hasNext();) { DataBag dbag = (DataBag) it.next(); for (int i = 0; i < columns.size(); i++) { TableColumn tableColumn = (TableColumn) columns.get(i); if (!tableColumn.isExporatble()) continue; logger.debug("property: " + tableColumn.getProperty()); IColumnRenderer renderer = tableColumn.getRenderer(); Converter converter = tableColumn.getConverter(); addObjectCell(bodyfont, resulttable, dbag, tableColumn, renderer, converter); } } if (StringUtils.isNotEmpty(exportOptions.getTableFooter())) { PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableFooter())); cell.setColspan(columnCount); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } resulttable.setHeaderRows(1); return resulttable; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Add's the table 'add' to the table 'main'. * @param main the host table//from w w w . j ava 2s . c om * @param add the table being added * @param border true if a border should surround the table being added * @return the cell containing the table being added to the main table. * */ private PdfPCell addToTable(PdfPTable main, PdfPTable add, boolean border) { PdfPCell cell; cell = new PdfPCell(add); if (!border) { cell.setBorder(0); } cell.setPadding(3); cell.setColspan(1); main.addCell(cell); return cell; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
private PdfPTable createLogoHeader() { float[] tableWidths; PdfPCell cell = new PdfPCell(); //tableWidths = new float[]{ 1.5f, 2.5f }; //PdfPTable infoTable = new PdfPTable(tableWidths); PdfPTable infoTable = new PdfPTable(1); try {/*from w w w. ja v a 2s .c o m*/ String filename = ""; if (props.getProperty("multisites") != null && "on".equalsIgnoreCase(props.getProperty("multisites"))) { DocumentDAO documentDao = (DocumentDAO) SpringUtils.getBean("documentDAO"); SiteDao siteDao = (SiteDao) SpringUtils.getBean("siteDao"); Site site = siteDao.getByLocation(reqFrm.siteName); if (site != null) { if (site.getSiteLogoId() != null) { org.oscarehr.document.model.Document d = documentDao .getDocument(String.valueOf(site.getSiteLogoId())); String dir = props.getProperty("DOCUMENT_DIR"); filename = dir.concat(d.getDocfilename()); } else { //If no logo file uploaded for this site, use the default one defined in oscar properties file. filename = props.getProperty("faxLogoInConsultation"); } } } else { filename = props.getProperty("faxLogoInConsultation"); } FileInputStream fileInputStream = new FileInputStream(filename); byte[] faxLogImage = new byte[1024 * 256]; fileInputStream.read(faxLogImage); Image image = Image.getInstance(faxLogImage); image.scalePercent(80f); image.setBorder(0); cell = new PdfPCell(image); cell.setBorder(0); infoTable.addCell(cell); } catch (Exception e) { logger.error("Unexpected error.", e); } // The last cell in the table is extended to the maximum available height; // inserting a blank cell here prevents the last border used to underline text from // being displaced to the bottom of this table. cell.setPhrase(new Phrase(" ", font)); cell.setBorder(0); cell.setColspan(2); infoTable.addCell(cell); return infoTable; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
private PdfPTable createReplyHeader() { PdfPCell cell; PdfPTable infoTable = new PdfPTable(1); cell = new PdfPCell(new Phrase("", headerFont)); cell.setBorder(0);/*w ww .j a v a 2 s . c om*/ cell.setPaddingLeft(25); infoTable.addCell(cell); cell.setPhrase(new Phrase(getResource("msgConsReq"), bigBoldFont)); cell.setPadding(0); cell.setBorder(0); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); if (reqFrm.pwb.equals("1")) { cell.setPhrase(new Phrase(getResource("msgPleaseReplyPatient"), boldFont)); } else if (org.oscarehr.common.IsPropertiesOn.isMultisitesEnable()) { cell.setPhrase(new Phrase("", boldFont)); } else { cell.setPhrase(new Phrase(String.format("%s %s %s", getResource("msgPleaseReplyPart1"), clinic.getClinicName(), getResource("msgPleaseReplyPart2")), boldFont)); } infoTable.addCell(cell); // The last cell in the table is extended to the maximum available height; // inserting a blank cell here prevents the last border used to underline text from // being displaced to the bottom of this table. cell.setPhrase(new Phrase(" ", font)); cell.setBorder(0); cell.setColspan(2); infoTable.addCell(cell); return infoTable; }