1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
623 Runnable r = new Runnable() { public void run() {
624 try {
625 SurfaceData sd = CPrinterSurfaceData.createData(page, context); // Just stores page into an ivar
626 if (defaultFont == null) {
627 defaultFont = new Font("Dialog", Font.PLAIN, 12);
628 }
629 Graphics2D delegate = new SunGraphics2D(sd, Color.black, Color.white, defaultFont);
630
631 Graphics2D pathGraphics = new CPrinterGraphics(delegate, printerJob); // Just stores delegate into an ivar
632 Rectangle2D pageFormatArea = getPageFormatArea(page);
633 initPrinterGraphics(pathGraphics, pageFormatArea);
634 painter.print(pathGraphics, page, pageIndex);
635 delegate.dispose();
636 delegate = null;
637 } catch (PrinterException pe) { throw new java.lang.reflect.UndeclaredThrowableException(pe); }
638 }};
639
640 if (onEventThread) {
641 try { EventQueue.invokeAndWait(r);
642 } catch (java.lang.reflect.InvocationTargetException ite) {
643 Throwable te = (Throwable)ite.getTargetException();
644 if (te instanceof PrinterException) throw (PrinterException)te;
645 else te.printStackTrace();
646 } catch (Exception e) { e.printStackTrace(); }
647 } else {
648 r.run();
649 }
650
651 }
652
653 // Returns either 1. an array of 3 object (PageFormat, Printable, PeekGraphics) or 2. null
654 private Object[] getPageformatPrintablePeekgraphics(final int pageIndex) {
655 final Object[] ret = new Object[3];
656 final PrinterJob printerJob = this;
657
658 Runnable r = new Runnable() { public void run() { synchronized(ret) {
659 try {
660 Pageable pageable = getPageable();
661 PageFormat pageFormat = pageable.getPageFormat(pageIndex);
662 if (pageFormat != null) {
663 Printable printable = pageable.getPrintable(pageIndex);
|
1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
623 Runnable r = new Runnable() { public void run() {
624 try {
625 SurfaceData sd = CPrinterSurfaceData.createData(page, context); // Just stores page into an ivar
626 if (defaultFont == null) {
627 defaultFont = new Font("Dialog", Font.PLAIN, 12);
628 }
629 Graphics2D delegate = new SunGraphics2D(sd, Color.black, Color.white, defaultFont);
630
631 Graphics2D pathGraphics = new CPrinterGraphics(delegate, printerJob); // Just stores delegate into an ivar
632 Rectangle2D pageFormatArea = getPageFormatArea(page);
633 initPrinterGraphics(pathGraphics, pageFormatArea);
634 painter.print(pathGraphics, page, pageIndex);
635 delegate.dispose();
636 delegate = null;
637 } catch (PrinterException pe) { throw new java.lang.reflect.UndeclaredThrowableException(pe); }
638 }};
639
640 if (onEventThread) {
641 try { EventQueue.invokeAndWait(r);
642 } catch (java.lang.reflect.InvocationTargetException ite) {
643 Throwable te = ite.getTargetException();
644 if (te instanceof PrinterException) throw (PrinterException)te;
645 else te.printStackTrace();
646 } catch (Exception e) { e.printStackTrace(); }
647 } else {
648 r.run();
649 }
650
651 }
652
653 // Returns either 1. an array of 3 object (PageFormat, Printable, PeekGraphics) or 2. null
654 private Object[] getPageformatPrintablePeekgraphics(final int pageIndex) {
655 final Object[] ret = new Object[3];
656 final PrinterJob printerJob = this;
657
658 Runnable r = new Runnable() { public void run() { synchronized(ret) {
659 try {
660 Pageable pageable = getPageable();
661 PageFormat pageFormat = pageable.getPageFormat(pageIndex);
662 if (pageFormat != null) {
663 Printable printable = pageable.getPrintable(pageIndex);
|