List of usage examples for com.itextpdf.layout.element Table startNewRow
public Table startNewRow()
From source file:com.tcay.slalom.UI.PDF.PDF_Results.java
License:Open Source License
public void doit(String title, ArrayList<RaceRun> runs, boolean breakOnClassChange) { Document doc = null;/* ww w . ja v a2s.c om*/ Table table = null; try { File file = new File(DEST); file.getParentFile().mkdirs(); // new PDF_Results().manipulatePdf(DEST); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST)); //Document doc = new Document(pdfDoc); table = new Table(9); // # of columns // for (int i = 0; i < 16; i++) { // table.addCell("hi"); // } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } String lastBoatClass = null; for (RaceRun r : runs) { float totalTime; if (breakOnClassChange) { if (lastBoatClass != null) { if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) ; // log.info("---"); } lastBoatClass = r.getBoat().getBoatClass(); } totalTime = (float) r.getTotalPenalties(); totalTime += r.getElapsed(); } try { ArrayList<Result> sorted = Race.getInstance().getTempResults(); for (Result r : sorted) { if (true || breakOnClassChange) { //Fixme constant true if (lastBoatClass != null) { if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) ; // output.newLine(); } if (lastBoatClass == null || lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) { // output.write(r.getBoat().getBoatClass()); // output.newLine(); } lastBoatClass = r.getBoat().getBoatClass(); } String s1; // Cell cell23 = new Cell(1, 6).add("a Class ???multi 1,3 and 1,4"); // table.addCell(cell23); // table.startNewRow(); s1 = String.format("%1$3s", r.getBoat().getRacer().getBibNumber()); table.addCell(s1); String s = r.getBoat().getRacer().getShortName(); s1 = String.format("%1$-15s", s); table.addCell(s1); s1 = r.getRun1().getResultString(); table.addCell(s1); s1 = r.getRun1().getPenaltyString(); table.addCell(s1); s1 = r.getRun1().getTotalTimeString(); table.addCell(s1); if (r.getRun2() != null) { table.startNewRow(); table.addCell("."); table.addCell(".."); s1 = r.getRun2().getResultString(); table.addCell(s1); s1 = r.getRun2().getPenaltyString(); table.addCell(s1); s1 = r.getRun2().getTotalTimeString(); table.addCell(s1); } // else { // table.addCell("")//; //} table.startNewRow(); /// todo must integrate TH results before sort - DONE VERIFY 10/11/2013 // output.write(" best="); // s1 = r.getBestRun() != null ? r.getBestRun().formatTimeTotalOnly() : RaceRun.TIME_ONLY_FILL; // output.write(s1); // if (r.getBestRun().getPhotoCellRaceRun() != null) { /// todo must integrate TH results before sort // output.write(ResultsTable.TIMINGMODE_AUTOMATIC); // } // output.newLine(); } PdfFont f = PdfFontFactory.createFont(FontConstants.HELVETICA); Cell cell = new Cell(1, 3); cell.add(new Paragraph("Class K1 ... or whateever")).setFont(f).setFontSize(13) .setFontColor(DeviceGray.WHITE).setBackgroundColor(DeviceGray.BLACK); // .setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(cell); /* for (int i = 0; i < 2; i++) { Cell[] headerFooter = new Cell[] { new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("#"), new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Key"), new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Value") }; for (Cell hfCell : headerFooter) { if (i == 0) { table.addHeaderCell(hfCell); } else { table.addFooterCell(hfCell); } } } for (int counter = 1; counter < 20; counter++) { table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add(String.valueOf(counter))); table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("key " + counter)); table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("value " + counter)); } */ doc.add(table); doc.close(); } catch (Exception e) { System.out.println(e); System.out.println(e.getStackTrace()); e.printStackTrace(); // log.write(e); } finally { try { // output.close(); } catch (Exception ex) { System.out.println(ex); System.out.println(ex.getStackTrace()); ex.printStackTrace(); } } }