private Band createTable() {
    final Band tableCellA1 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell A1"));
    final Band tableCellA2 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell A2"));
    final Band tableCellB1 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell B1"));
    final Band tableCellB2 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell B2"));
    final Band tableCellC1 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell C1"));
    final Band tableCellC2 = TableTestUtil.createCell(TableTestUtil.createDataItem("Cell C2"));

    final Band tableRowA = TableTestUtil.createRow(tableCellA1, tableCellA2);
    final Band tableRowB = TableTestUtil.createRow(tableCellB1, tableCellB2);
    final Band tableRowC = TableTestUtil.createRow(tableCellC1, tableCellC2);

    final Band tableBody = new Band();
    tableBody.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_BODY);
    tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f);
    tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 150f);
    tableBody.addElement(tableRowA);
    tableBody.addElement(tableRowB);
    tableBody.addElement(tableRowC);

    final Band table = new Band();
    table.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 200f);
    table.addElement(tableBody);
    return table;
  }
  public void testMissingTableRow() throws ReportProcessingException, ContentProcessingException {
    final Band tableBody = new Band();
    tableBody.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_BODY);
    tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f);
    tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 200f);

    final Band table = new Band();
    table.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 200f);
    table.addElement(TableTestUtil.createAutoBox(tableBody));

    final MasterReport report = new MasterReport();
    final ReportHeader band = report.getReportHeader();
    band.addElement(table);

    final LogicalPageBox logicalPageBox =
        DebugReportRunner.layoutSingleBand(report, band, false, false);
    // ModelPrinter.print(logicalPageBox);

    final DescendantMatcher matcher =
        new DescendantMatcher(new ElementMatcher("TableCellRenderBox"));
    final RenderNode[] all = MatchFactory.matchAll(logicalPageBox, matcher);

    assertEquals(0, all.length);
  }
  @Test
  public void testCanvasWithPrePostPad() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, new CustomProducer());
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f);
    table.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 100f);
    table.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 10f);
    table.setName("table");
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10));
    report.getReportHeader().addElement(table);

    Element postPaddingItem = TableTestUtil.createDataItem("Post-Padding", 100, 10);
    postPaddingItem.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 300f);
    report.getReportHeader().addElement(postPaddingItem);
    report.getReportHeader().setLayout("canvas");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-canvas.pdf");

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);
    assertPageValid(pages, 0, StrictGeomUtility.toInternalValue(10));
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
  }
 private void configureBand(final javax.swing.text.Element textElement, final Band band) {
   if ("paragraph".equals(textElement.getName()) || "section".equals(textElement.getName())) {
     band.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, "block");
     band.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(-100));
   } else {
     band.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, "inline");
   }
 }
  public Object convert(final ReportElement source, final Object value) {
    try {
      final Document doc = RichTextConverterUtilities.parseDocument(editorKit, value);
      if (doc == null) {
        return value;
      }

      final Element element = process(doc.getDefaultRootElement());
      final Band band =
          RichTextConverterUtilities.convertToBand(StyleKey.getDefinedStyleKeys(), source, element);
      band.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, "inline");
      return band;
    } catch (Exception e) {
      return value;
    }
  }
  @Test
  public void testRowWithPrePostPad() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, true);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f);
    table.setName("table");
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10));
    report.getReportHeader().addElement(table);
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Post-Padding", 100, 10));
    report.getReportHeader().setLayout("row");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-row.pdf");
    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);

    assertPageValid(pages, 0);
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
    //    assertPageValid(report, 3);
    //    assertPageValid(report, 4);
  }
  public void testWeirdTocLayout() throws ReportProcessingException, ContentProcessingException {
    Element textField = new Element();
    textField.setName("textField");
    textField.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial");
    textField.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 14);
    textField.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE);
    textField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 97f);
    textField.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 20f);
    textField.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 0f);
    textField.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 0f);
    textField.setElementType(LabelType.INSTANCE);
    textField.setAttribute(
        AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Classic Cars");

    Element dotField = new Element();
    dotField.setName("dotField");
    dotField.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial");
    dotField.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 14);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.RIGHT);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.VALIGNMENT, ElementAlignment.TOP);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 97f);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 0f);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 628.463f);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 20f);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.WIDTH, 100f);
    dotField.getStyle().setStyleProperty(ElementStyleKeys.MAX_WIDTH, 100f);
    dotField.setElementType(LabelType.INSTANCE);
    dotField.setAttribute(
        AttributeNames.Core.NAMESPACE,
        AttributeNames.Core.VALUE,
        " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
            + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
            + ". . . . . . . . . . . . . . . . . .");

    Band band = new Band();
    band.setName("outer-box");
    band.setLayout("inline");
    band.getStyle().setStyleProperty(ElementStyleKeys.BOX_SIZING, BoxSizing.CONTENT_BOX);
    band.getStyle().setStyleProperty(ElementStyleKeys.OVERFLOW_X, false);
    band.getStyle().setStyleProperty(ElementStyleKeys.OVERFLOW_Y, false);
    band.getStyle().setStyleProperty(TextStyleKeys.LINEHEIGHT, 1f);
    band.getStyle()
        .setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS);
    band.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 708f);
    band.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 12f);
    band.getStyle().setStyleProperty(ElementStyleKeys.MAX_HEIGHT, 20f);
    band.addElement(textField);
    band.addElement(dotField);

    final MasterReport report = new MasterReport();
    report.getReportHeader().addElement(band);

    LogicalPageBox logicalPageBox =
        DebugReportRunner.layoutSingleBand(report, report.getReportHeader(), false, false);
    // ModelPrinter.INSTANCE.print(logicalPageBox);

    RenderBox outerBox = (RenderBox) MatchFactory.findElementByName(logicalPageBox, "outer-box");
    RenderNode dotFieldBox = MatchFactory.findElementByName(logicalPageBox, "dotField");
    RenderNode textFieldBox = MatchFactory.findElementByName(logicalPageBox, "textField");
    assertNotNull(outerBox);
    assertNotNull(dotFieldBox);
    assertNotNull(textFieldBox);

    assertEquals(0, outerBox.getY());
    assertEquals(0, dotFieldBox.getY());
    assertEquals(0, textFieldBox.getY());

    // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of
    // 14.024 is used.
    assertEquals(StrictGeomUtility.toInternalValue(14.024), outerBox.getHeight());
    assertEquals(StrictGeomUtility.toInternalValue(14.024), outerBox.getFirstChild().getHeight());
    assertEquals(StrictGeomUtility.toInternalValue(14), dotFieldBox.getHeight());
    assertEquals(StrictGeomUtility.toInternalValue(14), textFieldBox.getHeight());
  }