/*
 * Created on Jul 4, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.lowagie.parser.html;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

import com.lowagie.text.BadElementException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;

/**
 * @author Trevor Linton
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class TestLeading {

	/**
	 * 
	 */
	public TestLeading() {
		super();
		// TODO Auto-generated constructor stub
	}

	public static void main(String[] args) {
		Document document = new Document();
		OutputStream out;
		PdfWriter pdfwriter;
		
		try {
			out = new FileOutputStream(args[0]);
		} catch (IOException io) {
			System.err.println("Error opening file "+args[0]);
			return;
		}
		try {
			pdfwriter = PdfWriter.getInstance(document,out);
		} catch (DocumentException de) {
			System.err.println("Error opening document.");
			return;
		}
		
		/* Begin writing the test */
		try {
			document.open();
			
			/** TEST ONE **/
			// add a new phrase
			document.add(new Phrase("new Phrase -> Document.add(), new Phrase(\\n) -> Document.add(), new Chunk(Image, 0, 0, true) -> Document.add()"));
			// add a new line element
			document.add(new Phrase("\n"));
			// add a new image
			document.add(new Chunk(Image.getInstance(new URL("http://www.lowagie.com/iText/logo.gif")),0,0,true));
			document.add(new Phrase("new Phrase -> Document.add()"));
			
			/** TEST TWO **/
			document.add((new Chunk("")).setNewPage()); // create a new page
			// add a new phrase
			document.add(new Chunk("new Chunk -> Document.add(), new Chunk(\\n) -> Document.add(), new Chunk(Image, 0, 0, true) -> Document.add()"));
			// add a new line element
			document.add(new Chunk("\n"));
			// add a new image
			document.add(new Chunk(Image.getInstance(new URL("http://www.lowagie.com/iText/logo.gif")),0,0,true));
			document.add(new Chunk("new Chunk -> Document.add()"));
			
			/** TEST THREE **/
			document.add((new Chunk("")).setNewPage()); // create a new page
			// add a new phrase
			Paragraph paragraph = new Paragraph();
			paragraph.add(new Phrase("new Phrase -> Paragraph.add(), new Paragraph(\\n) -> Document.add(), new Phrase(new Chunk(Image, 0, 0, true)) -> Paragraph.add()"));
			// add a new line element
			paragraph.add(new Phrase("\n"));
			// add a new image
			Phrase phrase = new Phrase(new Chunk(Image.getInstance(new URL("http://www.lowagie.com/iText/logo.gif")),0,0,true));
			phrase.setLeading(((Chunk)phrase.getChunks().get(0)).getImage().height());
			paragraph.add(phrase);
			paragraph.add(new Phrase("new Phrase -> Paragraph.add(), document.add(Paragraph)"));
			document.add(paragraph);

			/** TEST THREE **/
			document.add((new Chunk("")).setNewPage()); // create a new page
			// add a new phrase
			Paragraph paragraph2 = new Paragraph();
			paragraph2.add(new Phrase("new Phrase -> Paragraph.add(), new Paragraph(\\n) -> Document.add(), new Phrase(new Chunk(Image, 0, 0, true)) -> Paragraph.add(), Paragraph.setLeading(Image.getLeading())"));
			// add a new line element
			paragraph2.add(new Phrase("\n"));
			// add a new image
			Phrase phrase2 = new Phrase(new Chunk(Image.getInstance(new URL("http://www.lowagie.com/iText/logo.gif")),0,0,true));
			phrase.setLeading(((Chunk)phrase.getChunks().get(0)).getImage().height());
			paragraph2.setLeading(phrase.leading());
			paragraph2.add(phrase2);
			
			paragraph2.add(new Phrase("new Phrase -> Paragraph.add(), document.add(Paragraph)"));
			document.add(paragraph2);

			
			document.close();
			pdfwriter.close();
		} catch (BadElementException bee) {
			System.err.println("BadElementException.");
			return;
		} catch (DocumentException de) {
			System.err.println("DocumentException.");
			return;
		} catch (IOException io) {
			System.err.println("IO exception, got an internet connection?");
			return;
		}
		
	}
}
