Package jimm.datavision.layout.swing

Source Code of jimm.datavision.layout.swing.SwingPrintBook

package jimm.datavision.layout.swing;
import jimm.datavision.UserCancellationException;
import jimm.datavision.gui.StatusDialog;
import jimm.util.I18N;
import java.awt.print.*;
import java.util.List;

/**
* Returns printable pages to a print job.
*/
class SwingPrintBook implements Pageable {

protected StatusDialog statusDialog;
protected List pageContents;
protected PageFormat pageFormat;
protected boolean wasBuiltForUs;

SwingPrintBook(List pages, PageFormat format) {
    pageContents = pages;
    pageFormat = format;
}

void setStatusDialog(StatusDialog statusDialog) {
    this.statusDialog = statusDialog;
}

public int getNumberOfPages() {
    return pageContents.size();
}

public PageFormat getPageFormat(int pageIndex) {
    return pageFormat;
}

/**
* Returns the specified swing page. If the page has already been constructed
* for display, we return that page. If it has not, we create and return
* a new, temporary page.
*/
public Printable getPrintable(int pageIndex) {
    SwingPageContents contents;

    // "Forget" previous page if it was built 'specially for this print job.
    if (wasBuiltForUs) {
  contents = (SwingPageContents)pageContents.get(pageIndex - 1);
  contents.forgetPage();
    }

    // If user cancelled, tell the rest of the world.
    if (statusDialog.isCancelled()) {
  throw new UserCancellationException();
    }
    statusDialog.update(I18N.get("SwingPrintBook.printing_page")
      + ' ' + (pageIndex + 1) + ' '
      + I18N.get("SwingPrintBook.of") + ' '
      + getNumberOfPages());

    contents = (SwingPageContents)pageContents.get(pageIndex);
    Printable page = null;

    page = contents.getPage();
    wasBuiltForUs = !contents.isPageBuilt();

    return page;
}

}
TOP

Related Classes of jimm.datavision.layout.swing.SwingPrintBook

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.