package examples.rtf2fo;

import de.vc.jfo.flow.TableCell;
import de.vc.jfo.rtf.FieldListener;
import de.vc.jfo.rtf.listeners.SimpleDataSource;

/**
 * Example for fill-in tables with JFO.
 */

public class FillinTables extends AbstractFillinExample{

  //---- Attributes ------------------------------------------------------------

  private final static String RTF_FILE  = "docs-in/rtf2fo/tables.rtf";
  private final static String FO_FILE  = "docs-out/rtf2fo/tables.fo";
  private final static String PDF_FILE  = "docs-out/rtf2fo/tables.pdf";

  //---- statics ---------------------------------------------------------------

  public static void main(String[] args) throws Exception{
    new FillinTables().run();
  }

  //---- Constructors ----------------------------------------------------------

  //---- public  ---------------------------------------------------------------

  //---- protected -------------------------------------------------------------


  /**
   * Gets a field listener that listens for some fields we want to insert
   * values for.
   * @return The field listener.
   */
  protected FieldListener getFieldListener() {
  	SimpleDataSource p = new SimpleDataSource();

    // First Table (very simple)
    p.setTableColumn("t1no", new String[]{"1","2","3"});
    p.setTableColumn("t1item", new String[]{"Item 1","Item 2", "Item 3"});
    p.setTableColumn("t1price", new String[]{"1.00","2.00","3.00"});

    // Second Table (with column spanning)
    p.setTableColumn("t2quantity", new Object[]{
      "1",
      new TableCell("flatrate",2), // span second row of first column over 2 columns
      "3"});
    p.setTableColumn("t2unit", new Object[]{"m", null,"kg"});
    p.setTableColumn("t2item", new String[]{"Item 1","Item 2", "Item 3"});
    p.setTableColumn("t2itemprice", new Object[]{
      "2.00",new TableCell("39.00",3), "2.00"});
    p.setTableColumn("t2totalprice", new String[]{"2.00",null, "6.00"});

    // Third Table (with column conditions)
    p.setTableColumn("t3number", new Object[]{"200","-200","10.5","-10.5","0"});

    return p;
  }



  protected String getRTFFile() {
    return RTF_FILE;
  }


  protected String getFOFile() {
    return FO_FILE;
  }


  protected String getPDFFile() {
    return PDF_FILE;
  }

  //---- package ---------------------------------------------------------------

  //---- privat ----------------------------------------------------------------

}
