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

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

Introduction

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

Prototype

public void setSplitRows(boolean splitRows) 

Source Link

Document

When set the rows that won't fit in the page will be split.

Usage

From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java

License:Mozilla Public License

public void endElement(String tag) {
    if (!tagsSupported.containsKey(tag))
        return;//from  ww  w  .  j  a  v a  2s .c om
    try {
        String follow = (String) FactoryProperties.followTags.get(tag);
        if (follow != null) {
            cprops.removeChain(follow);
            return;
        }
        if (tag.equals("font") || tag.equals("span")) {
            cprops.removeChain(tag);
            return;
        }
        if (tag.equals("a")) {
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            ALink i = null;
            boolean skip = false;
            if (interfaceProps != null) {
                i = (ALink) interfaceProps.get("alink_interface");
                if (i != null)
                    skip = i.process(currentParagraph, cprops);
            }
            if (!skip) {
                String href = cprops.getProperty("href");
                if (href != null) {
                    ArrayList chunks = currentParagraph.getChunks();
                    for (int k = 0; k < chunks.size(); ++k) {
                        Chunk ck = (Chunk) chunks.get(k);
                        ck.setAnchor(href);
                    }
                }
            }
            Paragraph tmp = (Paragraph) stack.pop();
            Phrase tmp2 = new Phrase();
            tmp2.add(currentParagraph);
            tmp.add(tmp2);
            currentParagraph = tmp;
            cprops.removeChain("a");
            return;
        }
        if (tag.equals("blockquote")) {
            cprops.removeChain(tag);
            currentParagraph = new Paragraph();
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            inBLOCK = false;
            return;
        }
        if (tag.equals("br")) {
            return;
        }
        if (tag.equals("hr")) {
            return;
        }
        if (currentParagraph != null) {
            if (stack.empty())
                document.add(currentParagraph);
            else {
                Object obj = stack.pop();
                if (obj instanceof TextElementArray) {
                    TextElementArray current = (TextElementArray) obj;
                    current.add(currentParagraph);
                }
                stack.push(obj);
            }
        }
        currentParagraph = null;
        if (tag.equals("ul") || tag.equals("ol")) {
            if (pendingLI)
                endElement("li");
            skipText = false;
            cprops.removeChain(tag);
            if (stack.empty())
                return;
            Object obj = stack.pop();
            if (!(obj instanceof com.lowagie.text.List)) {
                stack.push(obj);
                return;
            }
            if (stack.empty())
                document.add((Element) obj);
            else
                ((TextElementArray) stack.peek()).add(obj);
            return;
        }
        if (tag.equals("li")) {
            pendingLI = false;
            skipText = true;
            cprops.removeChain(tag);
            if (stack.empty())
                return;
            Object obj = stack.pop();
            if (!(obj instanceof ListItem)) {
                stack.push(obj);
                return;
            }
            if (stack.empty()) {
                document.add((Element) obj);
                return;
            }
            Object list = stack.pop();
            if (!(list instanceof com.lowagie.text.List)) {
                stack.push(list);
                return;
            }
            ListItem item = (ListItem) obj;
            ((com.lowagie.text.List) list).add(item);
            ArrayList cks = item.getChunks();
            if (!cks.isEmpty())
                item.getListSymbol().setFont(((Chunk) cks.get(0)).getFont());
            stack.push(list);
            return;
        }
        if (tag.equals("div") || tag.equals("body")) {
            cprops.removeChain(tag);
            return;
        }
        if (tag.equals("pre")) {
            cprops.removeChain(tag);
            isPRE = false;
            return;
        }
        if (tag.equals("p")) {
            cprops.removeChain(tag);
            return;
        }
        if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5")
                || tag.equals("h6")) {
            cprops.removeChain(tag);
            return;
        }
        if (tag.equals("table")) {
            if (pendingTR)
                endElement("tr");
            cprops.removeChain("table");
            IncTable table = (IncTable) stack.pop();
            if (table.getRows() == null || table.getRows().isEmpty()) {
                // we have an empty table skip it 
                return;
            }
            PdfPTable tb = table.buildTable();
            tb.setSplitRows(true);
            if (stack.empty())
                document.add(tb);
            else
                ((TextElementArray) stack.peek()).add(tb);
            boolean state[] = (boolean[]) tableState.pop();
            pendingTR = state[0];
            pendingTD = state[1];
            skipText = false;
            return;
        }
        if (tag.equals("tr")) {
            if (pendingTD)
                endElement("td");
            pendingTR = false;
            cprops.removeChain("tr");
            ArrayList cells = new ArrayList();
            IncTable table = null;
            while (true) {
                Object obj = stack.pop();
                if (obj instanceof IncCell) {
                    cells.add(((IncCell) obj).getCell());
                }
                if (obj instanceof IncTable) {
                    table = (IncTable) obj;
                    break;
                }
            }
            if (cells.size() > 0) {
                table.addCols(cells);
                table.endRow();
            }
            stack.push(table);
            skipText = true;
            return;
        }
        if (tag.equals("td") || tag.equals("th")) {
            pendingTD = false;
            cprops.removeChain("td");
            skipText = true;
            return;
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.unitime.timetable.action.RoomFeatureListAction.java

License:Open Source License

public static void printPdfFeatureTable(OutputStream out, SessionContext context,
        RoomFeatureListForm roomFeatureListForm) throws Exception {
    boolean hasTypes = RoomFeatureType.hasFeatureTypes(context.getUser().getCurrentAcademicSessionId());

    PdfWebTable globalWebTable = new PdfWebTable(5, "Global Room Features", null,
            new String[] { "Name", "Abbreviation", hasTypes ? "Type" : "", "", "Rooms" },
            new String[] { "left", "left", "left", "left", "left" },
            new boolean[] { true, true, true, true, true });

    PdfWebTable departmentWebTable = new PdfWebTable(5, "Department Room Features", null,
            new String[] { "Name", "Abbreviation", hasTypes ? "Type" : "", "Department ", "Rooms" },
            new String[] { "left", "left", "left", "left", "left" },
            new boolean[] { true, true, true, true, true });

    Set<Department> depts = Department.getUserDepartments(context.getUser());
    Long examType = null;/*w  ww. j  a  va  2s .  com*/
    Department department = null;
    if (roomFeatureListForm.getDeptCodeX() != null && roomFeatureListForm.getDeptCodeX().matches("Exam[0-9]*"))
        examType = Long.valueOf(roomFeatureListForm.getDeptCodeX().substring(4));
    else if (roomFeatureListForm.getDeptCodeX() != null && !roomFeatureListForm.getDeptCodeX().isEmpty()
            && !"All".equals(roomFeatureListForm.getDeptCodeX()))
        department = Department.findByDeptCode(roomFeatureListForm.getDeptCodeX(),
                context.getUser().getCurrentAcademicSessionId());
    boolean deptCheck = examType == null
            && !context.getUser().getCurrentAuthority().hasRight(Right.DepartmentIndependent);
    if (department != null) {
        deptCheck = true;
        depts = new TreeSet<Department>();
        depts.add(department);
    }

    boolean splitRows = false;

    // build global room features rows
    Collection globalRoomFeatures = roomFeatureListForm.getGlobalRoomFeatures();
    boolean haveGlobalRoomFeature = false;
    for (Iterator it = globalRoomFeatures.iterator(); it.hasNext();) {
        GlobalRoomFeature gr = (GlobalRoomFeature) it.next();
        Collection rs = new TreeSet(gr.getRooms());

        // get rooms
        StringBuffer assignedRoom = new StringBuffer();
        int nrRows = 0;

        boolean haveRooms = false;
        for (Iterator iter = rs.iterator(); iter.hasNext();) {
            Location r = (Location) iter.next();
            if (examType != null && !r.isExamEnabled(examType))
                continue;
            if (deptCheck) {
                boolean skip = true;
                for (RoomDept rd : r.getRoomDepts())
                    if (depts.contains(rd.getDepartment())) {
                        skip = false;
                        break;
                    }
                if (skip)
                    continue;
            }
            if (assignedRoom.length() > 0)
                assignedRoom.append(", ");
            if (PdfWebTable.getWidthOfLastLine(assignedRoom.toString(), false, false) > 750) {
                assignedRoom.append("\n");
                nrRows++;
            }
            assignedRoom.append(r.getLabel());
            haveRooms = true;
        }

        if (nrRows > 40)
            splitRows = true;

        if (!haveRooms && !context.hasPermission(gr, Right.GlobalRoomFeatureEdit))
            continue;

        globalWebTable.addLine(null,
                new String[] { gr.getLabel(), gr.getAbbv(),
                        gr.getFeatureType() == null ? "" : gr.getFeatureType().getLabel(), "",
                        assignedRoom.toString() },
                new Comparable[] { gr.getLabel(), gr.getAbbv(),
                        gr.getFeatureType() == null ? "" : gr.getFeatureType().getLabel(), "", null });
        haveGlobalRoomFeature = true;
    }

    // build department room features rows
    Collection departmentRoomFeatures = roomFeatureListForm.getDepartmentRoomFeatures();
    for (Iterator it = departmentRoomFeatures.iterator(); it.hasNext();) {
        DepartmentRoomFeature drf = (DepartmentRoomFeature) it.next();

        String ownerName = drf.getDepartment().getShortLabel();

        Collection rs = new TreeSet(drf.getRooms());

        // get rooms
        StringBuffer assignedRoom = new StringBuffer();

        for (Iterator iter = rs.iterator(); iter.hasNext();) {
            Location r = (Location) iter.next();
            if (examType != null) {
                if (!r.isExamEnabled(examType))
                    continue;
            } else {
                boolean skip = true;
                for (Iterator j = r.getRoomDepts().iterator(); j.hasNext();) {
                    RoomDept rd = (RoomDept) j.next();
                    if (drf.getDepartment().equals(rd.getDepartment())) {
                        skip = false;
                        break;
                    }
                }
                if (skip)
                    continue;
            }
            if (assignedRoom.length() > 0)
                assignedRoom.append(", ");
            if (PdfWebTable.getWidthOfLastLine(assignedRoom.toString(), false, false) > 750)
                assignedRoom.append("\n");
            assignedRoom.append(r.getLabel());
        }

        departmentWebTable.addLine(null,
                new String[] { drf.getLabel(), drf.getAbbv(),
                        drf.getFeatureType() == null ? "" : drf.getFeatureType().getLabel(), ownerName,
                        assignedRoom.toString() },
                new Comparable[] { drf.getLabel(), drf.getAbbv(),
                        drf.getFeatureType() == null ? "" : drf.getFeatureType().getLabel(), ownerName, null });
    }

    Document doc = null;

    if (haveGlobalRoomFeature) {
        PdfWebTable table = globalWebTable;
        PdfPTable pdfTable = table.printPdfTable(WebTable.getOrder(context, "roomFeatureList.gord"));
        pdfTable.setSplitRows(splitRows);
        if (doc == null) {
            doc = new Document(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()), 30, 30,
                    30, 30);
            PdfWriter iWriter = PdfWriter.getInstance(doc, out);
            iWriter.setPageEvent(new PdfEventHandler());
            doc.open();
        }
        doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
        doc.add(pdfTable);
    }

    if (!departmentRoomFeatures.isEmpty()) {
        PdfWebTable table = departmentWebTable;
        PdfPTable pdfTable = table.printPdfTable(WebTable.getOrder(context, "roomFeatureList.mord"));
        if (doc == null) {
            doc = new Document(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()), 30, 30,
                    30, 30);
            PdfWriter iWriter = PdfWriter.getInstance(doc, out);
            iWriter.setPageEvent(new PdfEventHandler());
            doc.open();
        } else {
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
        }
        doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
        doc.add(pdfTable);
    }

    if (doc != null)
        doc.close();
}

From source file:org.unitime.timetable.action.RoomGroupListAction.java

License:Open Source License

public static void printPdfGroupTable(OutputStream out, SessionContext context,
        RoomGroupListForm roomGroupListForm) throws Exception {
    PdfWebTable globalWebTable = new PdfWebTable(5, "Global Room Groups", null,
            new String[] { "Name", "Abbreviation", "Default ", "Rooms", "Description" },
            new String[] { "left", "left", "middle", "left", "left" },
            new boolean[] { true, true, true, true, true });

    PdfWebTable departmentWebTable = new PdfWebTable(5, "Department Room Groups", null,
            new String[] { "Name", "Abbreviation", "Department ", "Rooms", "Description" },
            new String[] { "left", "left", "left", "left", "left" },
            new boolean[] { true, true, true, true, true });

    Set<Department> depts = Department.getUserDepartments(context.getUser());
    Long examType = null;//from w w  w.j  a  va 2  s. c o m
    Department department = null;
    if (roomGroupListForm.getDeptCodeX() != null && roomGroupListForm.getDeptCodeX().matches("Exam[0-9]*"))
        examType = Long.valueOf(roomGroupListForm.getDeptCodeX().substring(4));
    else if (roomGroupListForm.getDeptCodeX() != null && !roomGroupListForm.getDeptCodeX().isEmpty()
            && !"All".equals(roomGroupListForm.getDeptCodeX()))
        department = Department.findByDeptCode(roomGroupListForm.getDeptCodeX(),
                context.getUser().getCurrentAcademicSessionId());
    boolean deptCheck = examType == null
            && !context.getUser().getCurrentAuthority().hasRight(Right.DepartmentIndependent);
    if (department != null) {
        deptCheck = true;
        depts = new TreeSet<Department>();
        depts.add(department);
    }

    boolean splitRows = false;

    boolean haveGlobalRoomGroup = false;
    for (RoomGroup rg : RoomGroup.getAllGlobalRoomGroups(context.getUser().getCurrentAcademicSessionId())) {
        Collection rs = new TreeSet(rg.getRooms());

        StringBuffer assignedRoom = new StringBuffer();
        int nrRows = 0;

        boolean haveRooms = false;
        for (Iterator iter = rs.iterator(); iter.hasNext();) {
            Location r = (Location) iter.next();
            if (examType != null && !r.isExamEnabled(examType))
                continue;
            if (deptCheck) {
                boolean skip = true;
                for (RoomDept rd : r.getRoomDepts())
                    if (depts.contains(rd.getDepartment())) {
                        skip = false;
                        break;
                    }
                if (skip)
                    continue;
            }
            if (assignedRoom.length() > 0)
                assignedRoom.append(", ");
            if (PdfWebTable.getWidthOfLastLine(assignedRoom.toString(), false, false) > 750) {
                assignedRoom.append("\n");
                nrRows++;
            }
            assignedRoom.append(r.getLabel());
            haveRooms = true;
        }

        if (nrRows > 40)
            splitRows = true;

        if (!haveRooms && !context.hasPermission(rg, Right.GlobalRoomGroupEdit))
            continue;

        globalWebTable.addLine(null,
                new String[] { rg.getName(), rg.getAbbv(), (rg.isDefaultGroup().booleanValue() ? "Yes" : "No"),
                        assignedRoom.toString(), (rg.getDescription() == null ? "" : rg.getDescription()) },
                new Comparable[] { rg.getName(), rg.getAbbv(),
                        new Integer(rg.isDefaultGroup().booleanValue() ? 0 : 1), null,
                        (rg.getDescription() == null ? "" : rg.getDescription()) });

        haveGlobalRoomGroup = true;
    }

    Set<RoomGroup> departmentRoomGroups = new TreeSet<RoomGroup>();
    for (Department d : Department.getUserDepartments(context.getUser())) {
        if ("All".equals(roomGroupListForm.getDeptCodeX())
                || d.getDeptCode().equals(roomGroupListForm.getDeptCodeX()))
            departmentRoomGroups.addAll(RoomGroup.getAllDepartmentRoomGroups(d));
    }
    if (department != null && department.isExternalManager()) {
        departmentRoomGroups.addAll(RoomGroup.getAllDepartmentRoomGroups(department));
    }

    for (RoomGroup rg : departmentRoomGroups) {
        String ownerName = rg.getDepartment().getShortLabel();

        Collection rs = new TreeSet(rg.getRooms());

        // get rooms
        StringBuffer assignedRoom = new StringBuffer();

        for (Iterator iter = rs.iterator(); iter.hasNext();) {
            Location r = (Location) iter.next();
            if (examType != null) {
                if (!r.isExamEnabled(examType))
                    continue;
            } else {
                boolean skip = true;
                for (Iterator j = r.getRoomDepts().iterator(); j.hasNext();) {
                    RoomDept rd = (RoomDept) j.next();
                    if (rg.getDepartment().equals(rd.getDepartment())) {
                        skip = false;
                        break;
                    }
                }
                if (skip)
                    continue;
            }
            if (assignedRoom.length() > 0)
                assignedRoom.append(", ");
            if (PdfWebTable.getWidthOfLastLine(assignedRoom.toString(), false, false) > 750)
                assignedRoom.append("\n");
            assignedRoom.append(r.getLabel());
        }

        departmentWebTable.addLine(null,
                new String[] { rg.getName(), rg.getAbbv(), ownerName, assignedRoom.toString(),
                        (rg.getDescription() == null ? "" : rg.getDescription()) },
                new Comparable[] { rg.getName(), rg.getAbbv(), ownerName, null,
                        (rg.getDescription() == null ? "" : rg.getDescription()) });
    }

    Document doc = null;

    if (haveGlobalRoomGroup) {
        PdfWebTable table = globalWebTable;
        PdfPTable pdfTable = table.printPdfTable(WebTable.getOrder(context, "roomGroupList.gord"));
        pdfTable.setSplitRows(splitRows);
        if (doc == null) {
            doc = new Document(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()), 30, 30,
                    30, 30);
            PdfWriter iWriter = PdfWriter.getInstance(doc, out);
            iWriter.setPageEvent(new PdfEventHandler());
            doc.open();
        }
        doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
        doc.add(pdfTable);
    }

    if (!departmentRoomGroups.isEmpty()) {
        PdfWebTable table = departmentWebTable;
        PdfPTable pdfTable = table.printPdfTable(WebTable.getOrder(context, "roomGroupList.mord"));
        if (doc == null) {
            doc = new Document(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()), 30, 30,
                    30, 30);
            PdfWriter iWriter = PdfWriter.getInstance(doc, out);
            iWriter.setPageEvent(new PdfEventHandler());
            doc.open();
        } else {
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
        }
        doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
        doc.add(pdfTable);
    }

    if (doc != null)
        doc.close();

}

From source file:org.unitime.timetable.action.SolutionReportAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    SolutionReportForm myForm = (SolutionReportForm) form;

    sessionContext.checkPermission(Right.SolutionReports);

    // Read operation to be performed
    String op = (myForm.getOp() != null ? myForm.getOp() : request.getParameter("op"));
    Session session = SessionDAO.getInstance().get(sessionContext.getUser().getCurrentAcademicSessionId());
    BitSet sessionDays = session.getDefaultDatePattern().getPatternBitSet();
    int startDayDayOfWeek = Constants.getDayOfWeek(session.getDefaultDatePattern().getStartDate());

    SolverProxy solver = courseTimetablingSolverService.getSolver();
    if (solver == null) {
        request.setAttribute("SolutionReport.message", "Neither a solver is started nor solution is loaded.");
    } else {/*from  w w w.  j a va  2s .  c  o  m*/
        try {
            for (RoomType type : RoomType.findAll()) {
                RoomReport roomReport = solver.getRoomReport(sessionDays, startDayDayOfWeek,
                        type.getUniqueId());
                if (roomReport != null && !roomReport.getGroups().isEmpty()) {
                    WebTable t = getRoomReportTable(request, roomReport, false, type.getUniqueId());
                    if (t != null)
                        request.setAttribute("SolutionReport.roomReportTable." + type.getReference(),
                                t.printTable(
                                        WebTable.getOrder(sessionContext, "solutionReports.roomReport.ord")));
                }
            }
            RoomReport roomReport = solver.getRoomReport(sessionDays, startDayDayOfWeek, null);
            if (roomReport != null && !roomReport.getGroups().isEmpty()) {
                WebTable t = getRoomReportTable(request, roomReport, false, null);
                if (t != null)
                    request.setAttribute("SolutionReport.roomReportTable.nonUniv",
                            t.printTable(WebTable.getOrder(sessionContext, "solutionReports.roomReport.ord")));
            }
            DeptBalancingReport deptBalancingReport = solver.getDeptBalancingReport();
            if (deptBalancingReport != null && !deptBalancingReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.deptBalancingReportTable",
                        getDeptBalancingReportTable(request, deptBalancingReport, false).printTable(
                                WebTable.getOrder(sessionContext, "solutionReports.deptBalancingReport.ord")));
            ViolatedDistrPreferencesReport violatedDistrPreferencesReport = solver
                    .getViolatedDistrPreferencesReport();
            if (violatedDistrPreferencesReport != null && !violatedDistrPreferencesReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.violatedDistrPreferencesReportTable",
                        getViolatedDistrPreferencesReportTable(request, violatedDistrPreferencesReport, false)
                                .printTable(WebTable.getOrder(sessionContext,
                                        "solutionReports.violDistPrefReport.ord")));
            DiscouragedInstructorBtbReport discouragedInstructorBtbReportReport = solver
                    .getDiscouragedInstructorBtbReport();
            if (discouragedInstructorBtbReportReport != null
                    && !discouragedInstructorBtbReportReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.discouragedInstructorBtbReportReportTable",
                        getDiscouragedInstructorBtbReportReportTable(request,
                                discouragedInstructorBtbReportReport, false).printTable(
                                        WebTable.getOrder(sessionContext, "solutionReports.violInstBtb.ord")));
            StudentConflictsReport studentConflictsReport = solver.getStudentConflictsReport();
            if (studentConflictsReport != null && !studentConflictsReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.studentConflictsReportTable",
                        getStudentConflictsReportTable(request, studentConflictsReport, false)
                                .printTable(WebTable.getOrder(sessionContext, "solutionReports.studConf.ord")));
            SameSubpartBalancingReport sameSubpartBalancingReport = solver.getSameSubpartBalancingReport();
            if (sameSubpartBalancingReport != null && !sameSubpartBalancingReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.sameSubpartBalancingReportTable",
                        getSameSubpartBalancingReportTable(request, sameSubpartBalancingReport, false)
                                .printTable(PdfWebTable.getOrder(sessionContext,
                                        "solutionReports.sectBalancingReport.ord")));
            PerturbationReport perturbationReport = solver.getPerturbationReport();
            if (perturbationReport != null && !perturbationReport.getGroups().isEmpty())
                request.setAttribute("SolutionReport.perturbationReportTable",
                        getPerturbationReportTable(request, perturbationReport, false)
                                .printTable(WebTable.getOrder(sessionContext, "solutionReports.pert.ord")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if ("Export PDF".equals(op)) {
        OutputStream out = ExportUtils.getPdfOutputStream(response, "report");

        Document doc = new Document(
                new Rectangle(60f + PageSize.LETTER.getHeight(), 60f + 0.75f * PageSize.LETTER.getHeight()), 30,
                30, 30, 30);

        PdfWriter iWriter = PdfWriter.getInstance(doc, out);
        iWriter.setPageEvent(new PdfEventHandler());
        doc.open();

        boolean atLeastOneRoomReport = false;
        for (RoomType type : RoomType.findAll()) {
            RoomReport roomReport = solver.getRoomReport(sessionDays, startDayDayOfWeek, type.getUniqueId());
            if (roomReport == null || roomReport.getGroups().isEmpty())
                continue;
            PdfWebTable table = getRoomReportTable(request, roomReport, true, type.getUniqueId());
            if (table == null)
                continue;
            PdfPTable pdfTable = table
                    .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.roomReport.ord"));
            if (!atLeastOneRoomReport) {
                doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
                doc.newPage();
            }
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
            atLeastOneRoomReport = true;
        }
        RoomReport roomReport = solver.getRoomReport(sessionDays, startDayDayOfWeek, null);
        if (roomReport != null && !roomReport.getGroups().isEmpty()) {
            PdfWebTable table = getRoomReportTable(request, roomReport, true, null);
            if (table != null) {
                PdfPTable pdfTable = table
                        .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.roomReport.ord"));
                if (!atLeastOneRoomReport) {
                    doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
                    doc.newPage();
                }
                doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
                doc.add(pdfTable);
                atLeastOneRoomReport = true;
            }
        }

        if (atLeastOneRoomReport) {
            PdfPTable pdfTable = new PdfPTable(new float[] { 10f, 100f });
            pdfTable.setWidthPercentage(100);
            pdfTable.getDefaultCell().setPadding(3);
            pdfTable.getDefaultCell().setBorderWidth(0);
            pdfTable.setSplitRows(false);
            pdfTable.addCell("Group");
            pdfTable.addCell("group size <minimum, maximum)");
            pdfTable.addCell("Size");
            pdfTable.addCell("actual group size (size of the smallest and the biggest room in the group)");
            pdfTable.addCell("NrRooms");
            pdfTable.addCell("number of rooms in the group");
            pdfTable.addCell("ClUse");
            pdfTable.addCell("number of classes that are using a room from the group (actual solution)");
            pdfTable.addCell("ClShould");
            pdfTable.addCell(
                    "number of classes that \"should\" use a room of the group (smallest available room of a class is in this group)");
            pdfTable.addCell("ClMust");
            pdfTable.addCell(
                    "number of classes that must use a room of the group (all available rooms of a class are in this group)");
            pdfTable.addCell("HrUse");
            pdfTable.addCell("average hours a room of the group is used (actual solution)");
            pdfTable.addCell("HrShould");
            pdfTable.addCell(
                    "average hours a room of the group should be used (smallest available room of a class is in this group)");
            pdfTable.addCell("HrMust");
            pdfTable.addCell(
                    "average hours a room of this group must be used (all available rooms of a class are in this group)");
            pdfTable.addCell("");
            pdfTable.addCell("*) cumulative numbers (group minimum ... inf) are displayed in parentheses.");
            doc.add(pdfTable);
        }

        DiscouragedInstructorBtbReport discouragedInstructorBtbReportReport = solver
                .getDiscouragedInstructorBtbReport();
        if (discouragedInstructorBtbReportReport != null
                && !discouragedInstructorBtbReportReport.getGroups().isEmpty()) {
            PdfWebTable table = getDiscouragedInstructorBtbReportReportTable(request,
                    discouragedInstructorBtbReportReport, true);
            PdfPTable pdfTable = table
                    .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.violInstBtb.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
        }

        ViolatedDistrPreferencesReport violatedDistrPreferencesReport = solver
                .getViolatedDistrPreferencesReport();
        if (violatedDistrPreferencesReport != null && !violatedDistrPreferencesReport.getGroups().isEmpty()) {
            PdfWebTable table = getViolatedDistrPreferencesReportTable(request, violatedDistrPreferencesReport,
                    true);
            PdfPTable pdfTable = table
                    .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.violDistPrefReport.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
        }

        StudentConflictsReport studentConflictsReport = solver.getStudentConflictsReport();
        if (studentConflictsReport != null && !studentConflictsReport.getGroups().isEmpty()) {
            PdfWebTable table = getStudentConflictsReportTable(request, studentConflictsReport, true);
            PdfPTable pdfTable = table
                    .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.studConf.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
        }

        SameSubpartBalancingReport sameSubpartBalancingReport = solver.getSameSubpartBalancingReport();
        if (sameSubpartBalancingReport != null && !sameSubpartBalancingReport.getGroups().isEmpty()) {
            PdfWebTable table = getSameSubpartBalancingReportTable(request, sameSubpartBalancingReport, true);
            PdfPTable pdfTable = table.printPdfTable(
                    WebTable.getOrder(sessionContext, "solutionReports.sectBalancingReport.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
        }

        DeptBalancingReport deptBalancingReport = solver.getDeptBalancingReport();
        if (deptBalancingReport != null && !deptBalancingReport.getGroups().isEmpty()) {
            PdfWebTable table = getDeptBalancingReportTable(request, deptBalancingReport, true);
            PdfPTable pdfTable = table.printPdfTable(
                    WebTable.getOrder(sessionContext, "solutionReports.deptBalancingReport.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
        }

        PerturbationReport perturbationReport = solver.getPerturbationReport();
        if (perturbationReport != null && !perturbationReport.getGroups().isEmpty()) {
            PdfWebTable table = getPerturbationReportTable(request, perturbationReport, true);
            PdfPTable pdfTable = table
                    .printPdfTable(WebTable.getOrder(sessionContext, "solutionReports.pert.ord"));
            doc.setPageSize(new Rectangle(60f + table.getWidth(), 60f + 0.75f * table.getWidth()));
            doc.newPage();
            doc.add(new Paragraph(table.getName(), PdfFont.getBigFont(true)));
            doc.add(pdfTable);
            pdfTable = new PdfPTable(new float[] { 5f, 100f });
            pdfTable.setWidthPercentage(100);
            pdfTable.getDefaultCell().setPadding(3);
            pdfTable.getDefaultCell().setBorderWidth(0);
            pdfTable.setSplitRows(false);
            pdfTable.addCell("Class");
            pdfTable.addCell("Class name");
            pdfTable.addCell("Time");
            pdfTable.addCell("Time (initial -> assigned)");
            pdfTable.addCell("Room");
            pdfTable.addCell("Room (initial -> assigned)");
            pdfTable.addCell("Dist");
            pdfTable.addCell("Distance between assignments (if different are used buildings)");
            pdfTable.addCell("St");
            pdfTable.addCell("Number of affected students");
            pdfTable.addCell("StT");
            pdfTable.addCell("Number of affected students by time change");
            pdfTable.addCell("StR");
            pdfTable.addCell("Number of affected students by room change");
            pdfTable.addCell("StB");
            pdfTable.addCell("Number of affected students by building change");
            pdfTable.addCell("Ins");
            pdfTable.addCell("Number of affected instructors");
            pdfTable.addCell("InsT");
            pdfTable.addCell("Number of affected instructors by time change");
            pdfTable.addCell("InsR");
            pdfTable.addCell("Number of affected instructors by room change");
            pdfTable.addCell("InsB");
            pdfTable.addCell("Number of affected instructors by building change");
            pdfTable.addCell("Rm");
            pdfTable.addCell("Number of rooms changed");
            pdfTable.addCell("Bld");
            pdfTable.addCell("Number of buildings changed");
            pdfTable.addCell("Tm");
            pdfTable.addCell("Number of times changed");
            pdfTable.addCell("Day");
            pdfTable.addCell("Number of days changed");
            pdfTable.addCell("Hr");
            pdfTable.addCell("Number of hours changed");
            pdfTable.addCell("TFSt");
            pdfTable.addCell("Assigned building too far for instructor (from the initial one)");
            pdfTable.addCell("TFIns");
            pdfTable.addCell("Assigned building too far for students (from the initial one)");
            pdfTable.addCell("DStC");
            pdfTable.addCell("Difference in student conflicts");
            pdfTable.addCell("NStC");
            pdfTable.addCell("Number of new student conflicts");
            pdfTable.addCell("DTPr");
            pdfTable.addCell("Difference in time preferences");
            pdfTable.addCell("DRPr");
            pdfTable.addCell("Difference in room preferences");
            pdfTable.addCell("DInsB");
            pdfTable.addCell("Difference in back-to-back instructor preferences");
            doc.add(pdfTable);
        }

        doc.close();

        out.flush();
        out.close();

        return null;
    }

    return mapping.findForward("showSolutionReport");
}

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

/**
 * Prints pdf table. By default does not split table across
 * page boundaries /*from   ww  w  . j a v  a 2s.  c om*/
 * @param ordCol
 * @param keepTogether true does not split table across pages
 * @return
 */
public PdfPTable printPdfTable(int ordCol, boolean keepTogether) {
    PdfPTable table = new PdfPTable(getNrColumns());
    table.setWidthPercentage(100);
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(0);
    table.setSplitRows(false);
    table.setKeepTogether(keepTogether);

    boolean asc = (ordCol == 0 || iAsc == null || iAsc.length <= Math.abs(ordCol) - 1 ? true
            : iAsc[Math.abs(ordCol) - 1]);
    if (ordCol < 0)
        asc = !asc;

    widths = new float[iColumns];
    for (int i = 0; i < iColumns; i++)
        widths[i] = 0f;

    String lastLine[] = new String[Math.max(iColumns, (iHeaders == null ? 0 : iHeaders.length))];

    if (iHeaders != null) {
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            float width = addText(c, iHeaders[i] == null ? "" : iHeaders[i], true);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(c);
        }
        table.setHeaderRows(1);
    }
    if (ordCol != 0) {
        Collections.sort(iLines, new WebTableComparator(Math.abs(ordCol) - 1, asc));
    }
    for (int el = 0; el < iLines.size(); el++) {
        WebTableLine wtline = (WebTableLine) iLines.elementAt(el);
        String[] line = wtline.getLine();
        boolean blank = iBlankWhenSame;
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            if (blank && line[i] != null && !line[i].equals(lastLine[i]))
                blank = false;
            PdfPCell c = createCell();
            float width = addText(c, blank || line[i] == null ? "" : line[i], false);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            applyPdfStyle(c, wtline, (el + 1 < iLines.size() ? (WebTableLine) iLines.elementAt(el + 1) : null),
                    ordCol);
            table.addCell(c);
            lastLine[i] = line[i];
        }
    }

    try {
        if (getNrFilteredColumns() < 0) {
            table.setWidths(widths);
        } else {
            float[] x = new float[getNrColumns()];
            int idx = 0;
            for (int i = 0; i < iColumns; i++) {
                if (isFiltered(i))
                    continue;
                x[idx++] = widths[i];
            }
            table.setWidths(x);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return table;
}