import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.IOException;

import com.gnostice.pdfone.PDFOne;
import com.gnostice.pdfone.PdfDocument;
import com.gnostice.pdfone.PdfException;
import com.gnostice.pdfone.PdfRect;
import com.gnostice.pdfone.PdfWriter;

public class PdfRect_Examples
{
    // Activates the component PDFOne.jar
    static
    {
        PDFOne.activate("T95VZE:W8HBPVA:74VQ8QV:LO4V8",
            "9B1HRZAP:X5853ERNE:5EREMEGRQ:TX1R10");
    }

    public static void main(String[] args) throws IOException,
        PdfException
    {
        PdfRect_Examples obj = new PdfRect_Examples();

        // To try other examples, add the obj.<example_method>
        // accordingly. For example, try:
        // obj.PdfRect_PdfRect_Example();
        obj.METHODS_Example();
    }
    
    // This code segment demonstrates the use of the methods of the
    // PdfRect class
    public void METHODS_Example() throws IOException,
        PdfException
    {
        PdfWriter writer = PdfWriter.fileWriter(
                               "PdfRect_METHODS_Example.pdf");
        PdfDocument document = new PdfDocument(writer);

        // Creates a PdfRect object
        PdfRect rectangle = new PdfRect(200, 100, 250, 150);

        // Creates a string with output of the methods of the PdfRect
        // object
        String s = "Width = " + rectangle.width();
        s = s + ", Height = " + rectangle.height();
        s = s + ", Top = " + rectangle.top();
        s = s + ", Bottom = " + rectangle.bottom();
        s = s + ", Left = " + rectangle.left();
        s = s + ", Right = " + rectangle.right();
        s = s + ", x = " + rectangle.getX();
        s = s + ", y = " + rectangle.getY();

        // Writes the string inside the rectangle
        document.writeText(s, rectangle);
        // Draws the rectangle
        document.drawRect(rectangle);
        // Writes text identifying the rectangle
        document.writeText("PdfRect(200, 100, 250, 150)", 200, 80);

        // Sets the file to be opened after it is written to
        document.setOpenAfterSave(true);

        // Writes the document object to file
        document.write();

        // Closes all I/O streams associated with this writer object
        writer.dispose();
    }

    // This code segment creates PdfRect objects using overloaded
    // constructors
    public void PdfRect_PdfRect_Example() throws IOException,
        PdfException
    {
        PdfWriter writer = PdfWriter.fileWriter(
                               "PdfRect_PdfRect_Example.pdf");
        PdfDocument document = new PdfDocument(writer);
        // Creates a PdfRect object using a double-type arguments
        PdfRect rect1 = new PdfRect(200, 100, 250, 100);
        // Creates a PdfRect object using a Java Rectangle object
        PdfRect rect2 = new PdfRect(
                            new Rectangle(200, 300, 250, 100));
        // Creates a PdfRect object using a Java Rectangle2D object
        PdfRect rect3 = new PdfRect(
                            new Rectangle2D.Double(
                                200, 500, 250, 100));

        // Draws the above PdfRect objects
        document.drawRect(rect1);
        document.drawRect(rect2);
        document.drawRect(rect3);

        // Writes text inside the rectangles
        document.writeText(
            "PdfRect(double x, double y, double width, double "
            + "height) ~ PdfRect(200, 100, 250, 100)",
            rect1);
        document.writeText(
            "PdfRect(Rectangle rect) ~ PdfRect(new Rectangle(200, "
            + "300, 250, 100))",
            rect2);
        document.writeText(
            "PdfRect(Rectangle2D rect) ~ PdfRect(new "
            + "Rectangle2D.Double(200, 500, 250, 100))",
            rect3);

        // Sets the file to be opened after it is written to
        document.setOpenAfterSave(true);

        // Writes the document object to file
        document.write();

        // Closes all I/O streams associated with this writer object
        writer.dispose();
    }
}