package com.sammysolutions.rak;

import com.sammysolutions.common.Result;
import com.sammysolutions.common.JMessageBox;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.awt.Color;

// iText
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class TableTest  {

  public TableTest() {
  }

    public void initDocument(String docName) {
        try
        {
            Document document = new Document(PageSize.A4, 50, 20, 20, 20);
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(docName));
            document.addAuthor("Günter Sammet");
            document.addSubject("TableTest.");
            document.open();
            loadDocument(document, writer);
            document.close();
        }
        catch (Exception e2)
        {
          JMessageBox.displayMessageBox(e2.toString(), Color.yellow);
          System.out.println(e2);
        }
    }

    public void loadDocument(Document document, PdfWriter writer) {

        Font font1 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16);
        Font font2 = FontFactory.getFont(FontFactory.HELVETICA, 9);
        Font font3 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 9);
        Font font4 = FontFactory.getFont(FontFactory.HELVETICA, 7);
        Font font5 = FontFactory.getFont(FontFactory.HELVETICA, 10);
        int numColumns = 4;
        try
        {
            // we add some meta information to the document

            PdfPTable outerTable = new PdfPTable(3);
            PdfPTable innerMiddleTable = new PdfPTable(1);
            PdfPTable innerRightTable = new PdfPTable(1);
            PdfPTable lowerRightTable = new PdfPTable(2);

            int headerwidths[] = {25, 25, 25}; // percentage
            outerTable.setWidths(headerwidths);
            outerTable.setWidthPercentage(75); // percentage

            outerTable.getDefaultCell().setColspan(3);
            outerTable.addCell(new Phrase("TABLE TEST", font1));
            outerTable.getDefaultCell().setColspan(1);
            
            outerTable.addCell(new Phrase("outerTable cell 1", font1));
            outerTable.addCell(new Phrase("outerTable cell 2", font1));
            outerTable.addCell(new Phrase("outerTable cell 3", font1));
            outerTable.setHeaderRows(2);  // this is the end of the table header


            outerTable.addCell("One");
            outerTable.addCell("Two");
            outerTable.addCell("Three");

            innerMiddleTable.addCell("innerMiddleTable One");
            innerMiddleTable.addCell("innerMiddleTable Two");
            innerMiddleTable.addCell("innerMiddleTable Three");

            innerRightTable.addCell("innerRightTable One");
            innerRightTable.addCell("innerRightTable Two");

            outerTable.addCell("One");
            outerTable.addCell(innerMiddleTable);
            outerTable.addCell(innerRightTable);

            outerTable.getDefaultCell().setColspan(2);
            lowerRightTable.addCell("lowerRightTable One");
            lowerRightTable.addCell("lowerRightTable Two");
            outerTable.addCell(lowerRightTable);
            outerTable.addCell("Three");

            document.add(outerTable);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }




    public static void main (String[] args) {
    TableTest tableTest = new TableTest();


    tableTest.initDocument("TableTestOne.pdf");

    }

}