Example usage for java.awt PageAttributes PageAttributes

List of usage examples for java.awt PageAttributes PageAttributes

Introduction

In this page you can find the example usage for java.awt PageAttributes PageAttributes.

Prototype

public PageAttributes() 

Source Link

Document

Constructs a PageAttributes instance with default values for every attribute.

Usage

From source file:JuliaSet2.java

public void print() {
    // Create some attributes objects. This is Java 1.3 stuff.
    // In Java 1.1, we'd use a java.util.Preferences object instead.
    JobAttributes jattrs = new JobAttributes();
    PageAttributes pattrs = new PageAttributes();

    // Set some example attributes: monochrome, landscape mode
    pattrs.setColor(PageAttributes.ColorType.MONOCHROME);
    pattrs.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE);
    // Print to file by default
    jattrs.setDestination(JobAttributes.DestinationType.FILE);
    jattrs.setFileName("juliaset.ps");

    // Look up the Frame that holds this component
    Component frame = this;
    while (!(frame instanceof Frame))
        frame = frame.getParent();// w  w  w.  j  av  a 2  s  .c o  m

    // Get a PrintJob object to print the Julia set with.
    // The getPrintJob() method displays a print dialog and allows the user
    // to override and modify the default JobAttributes and PageAttributes
    Toolkit toolkit = this.getToolkit();
    PrintJob job = toolkit.getPrintJob((Frame) frame, "JuliaSet1", jattrs, pattrs);

    // We get a null PrintJob if the user clicked cancel
    if (job == null)
        return;

    // Get a Graphics object from the PrintJob.
    // We print simply by drawing to this Graphics object.
    Graphics g = job.getGraphics();

    // Center the image on the page
    Dimension pagesize = job.getPageDimension(); // how big is page?
    Dimension panesize = this.getSize(); // how big is image?
    g.translate((pagesize.width - panesize.width) / 2, // center it
            (pagesize.height - panesize.height) / 2);

    // Draw a box around the Julia Set and label it
    g.drawRect(-1, -1, panesize.width + 2, panesize.height + 2);
    g.drawString("Julia Set for c={" + cx + "," + cy + "}", 0, -15);

    // Set a clipping region
    g.setClip(0, 0, panesize.width, panesize.height);

    // Now print the component by calling its paint method
    this.paint(g);

    // Finally tell the printer we're done with the page.
    // No output will be generated if we don't call dispose() here.
    g.dispose();
}