java.awt.PrintJob Java Examples

The following examples show how to use java.awt.PrintJob. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobAttrUpdateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void printTest() {
    JobAttributes ja = new JobAttributes();

    Toolkit tk = Toolkit.getDefaultToolkit();
    // ja.setToPage(4);
    // ja.setFromPage(3);
    // show dialog
    PrintJob pjob = tk.getPrintJob(new JFrame(), "test", ja, null);
    if (pjob == null) {
        return;
    }


    if (ja.getDefaultSelection() == JobAttributes.DefaultSelectionType.RANGE) {
        int fromPage = ja.getFromPage();
        int toPage = ja.getToPage();
        if (fromPage != 2 || toPage != 3) {
            fail();
        } else {
            pass();
        }
    }
}
 
Example #2
Source File: PrintTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    JobAttributes job = new JobAttributes();
    PageAttributes page = new PageAttributes();
    job.setDialog(JobAttributes.DialogType.NATIVE);
    job.setDefaultSelection(JobAttributes.DefaultSelectionType.ALL);
    job.setFromPage(2);
    job.setToPage(5);
    Toolkit tk = Toolkit.getDefaultToolkit();
    // setting this dialog to native printdialog
    if (tk != null) {
        PrintJob pj = tk.getPrintJob(new JFrame(),
                      "testing the attribute setting ", job, page);
    }
}
 
Example #3
Source File: PrinterException.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Thread t = new Thread (() -> {
        robot.waitForIdle();
        robot.delay(2000);
        robot.keyPress(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_ESCAPE);
       });
    Toolkit tk = Toolkit.getDefaultToolkit();
    PrintJob pj = null;

    int[][] pageRange = new int[][]{new int[]{1,1}};
    JobAttributes ja = new JobAttributes(1,
            java.awt.JobAttributes.DefaultSelectionType.ALL,
            JobAttributes.DestinationType.FILE, JobAttributes.DialogType.NATIVE,
            "filename.ps", Integer.MAX_VALUE, 1,
            JobAttributes.MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES,
             pageRange, "", JobAttributes.SidesType.ONE_SIDED);

    Frame testFrame = new Frame("print");
    try {
        if (tk != null) {
            t.start();
            pj = tk.getPrintJob(testFrame, null, ja, null);
        }
    } finally {
        testFrame.dispose();
    }
}
 
Example #4
Source File: ProxyPrintGraphics.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #5
Source File: ProxyPrintGraphics.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #6
Source File: ProxyPrintGraphics.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #7
Source File: ProxyPrintGraphics.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #8
Source File: ProxyPrintGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #9
Source File: HighResTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void init() {
    String[] instructions = {
        "To be able to run this test it is required to have a default",
     "printer configured in your user environment.",
     "If no default printer exists, then test passes.",
     " ",
     "There will be 2 print dialogs.  The first dialog should show",
     "portrait as the selected orientation.  The 2nd dialog should show",
     "landscape as the selected orientation.",
     " ",
     "Visual inspection of the printed pages is needed. A passing",
     "test will print 2 pages in portrait and 2 pages in landscape.",
     "The pages have on the center of the page the text \"Center\"",
     "2 rectangles will appear above and below it, the one below is",
     "filled."
    };
    Sysout.createDialog();
    Sysout.printInstructions(instructions);

    PrintJob job = null;
    Dimension dim = null;
    JobAttributes jobAttributes = new JobAttributes();
    PageAttributes pageAttributes = new PageAttributes();
    String center = "Center";
    Font font = new Font("SansSerif", Font.PLAIN, 200);
    FontMetrics metrics = null;
    int width = 0;
    Graphics g = null;

    jobAttributes.setDialog(DialogType.NATIVE);
    pageAttributes.setOrigin(OriginType.PRINTABLE);
    pageAttributes.setPrinterResolution(new int[]{1200, 1200, 3});
    pageAttributes.setOrientationRequested(
            OrientationRequestedType.PORTRAIT);
    jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);

    job = f.getToolkit().getPrintJob(f, "Portrait Test", jobAttributes,
                                      pageAttributes);
    if (job != null) {
        dim = job.getPageDimension();
        for (int i = 0; i < 2; i++) {
            g = job.getGraphics();

            g.drawLine(0, 0, dim.width, 0);
            g.drawLine(dim.width, 0, dim.width, dim.height);
            g.drawLine(dim.width, dim.height, 0, dim.height);
            g.drawLine(0, dim.height, 0, 0);

            g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600);
            g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600);

            g.setFont(font);
            metrics = g.getFontMetrics();
            width = metrics.stringWidth(center);
            g.setColor(Color.black);
            g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2);

            g.dispose();
        }
        job.end();
        job = null;
    }

    pageAttributes.setOrientationRequested(
            OrientationRequestedType.LANDSCAPE);

    job = f.getToolkit().getPrintJob(f, "Landscape Test", jobAttributes,
                                         pageAttributes);
    if (job != null) {
        dim = job.getPageDimension();
        for (int i = 0; i < 2; i++) {
            g = job.getGraphics();
            g.drawLine(0, 0, dim.width, 0);
            g.drawLine(dim.width, 0, dim.width, dim.height);
            g.drawLine(dim.width, dim.height, 0, dim.height);
            g.drawLine(0, dim.height, 0, 0);

            g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600);
            g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600);

            g.setFont(font);
            metrics = g.getFontMetrics();
            width = metrics.stringWidth(center);
            g.setColor(Color.black);
            g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2);

            g.dispose();
        }
        job.end();
        job = null;
    }
    System.out.println("done");
}
 
Example #10
Source File: ProxyPrintGraphics.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #11
Source File: ProxyPrintGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #12
Source File: ProxyPrintGraphics.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #13
Source File: ProxyPrintGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #14
Source File: ProxyPrintGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #15
Source File: UtilitiesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public PrintJob getPrintJob(Frame frame, String jobtitle, Properties props) {
    return Toolkit.getDefaultToolkit().getPrintJob( frame, jobtitle, props );
}
 
Example #16
Source File: ProxyPrintGraphics.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #17
Source File: ProxyPrintGraphics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #18
Source File: ProxyPrintGraphics.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #19
Source File: ProxyPrintGraphics.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
    super(graphics);
    printJob = thePrintJob;
}
 
Example #20
Source File: ProxyPrintGraphics.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #21
Source File: ProxyPrintGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #22
Source File: ProxyPrintGraphics.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #23
Source File: ProxyPrintGraphics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #24
Source File: PDFJob.java    From jpexs-decompiler with GNU General Public License v3.0 2 votes vote down vote up
/**
 * This is the PrintGraphics interface
 * @return PrintJob for this object
 */
public PrintJob getPrintJob() {
  return (PrintJob)job;
}
 
Example #25
Source File: ProxyPrintGraphics.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #26
Source File: ProxyPrintGraphics.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #27
Source File: ProxyPrintGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #28
Source File: ProxyPrintGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #29
Source File: ProxyPrintGraphics.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}
 
Example #30
Source File: ProxyPrintGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the PrintJob object from which this PrintGraphics
 * object originated.
 */
public PrintJob getPrintJob() {
    return printJob;
}