|
26 | 26 | package sun.lwawt.macosx; |
27 | 27 |
|
28 | 28 |
|
29 | | -import java.awt.*; |
| 29 | +import java.awt.Color; |
| 30 | +import java.awt.EventQueue; |
| 31 | +import java.awt.HeadlessException; |
| 32 | +import java.awt.Font; |
| 33 | +import java.awt.Graphics; |
| 34 | +import java.awt.Graphics2D; |
| 35 | +import java.awt.GraphicsEnvironment; |
| 36 | +import java.awt.SecondaryLoop; |
| 37 | +import java.awt.Toolkit; |
30 | 38 | import java.awt.geom.Rectangle2D; |
31 | 39 | import java.awt.image.BufferedImage; |
32 | | -import java.awt.print.*; |
| 40 | +import java.awt.print.Pageable; |
| 41 | +import java.awt.print.PageFormat; |
| 42 | +import java.awt.print.Paper; |
| 43 | +import java.awt.print.Printable; |
| 44 | +import java.awt.print.PrinterAbortException; |
| 45 | +import java.awt.print.PrinterException; |
| 46 | +import java.awt.print.PrinterJob; |
33 | 47 | import java.net.URI; |
34 | 48 | import java.util.concurrent.atomic.AtomicReference; |
35 | 49 |
|
36 | | -import javax.print.*; |
| 50 | +import javax.print.DocFlavor; |
| 51 | +import javax.print.PrintService; |
| 52 | +import javax.print.PrintServiceLookup; |
| 53 | +import javax.print.StreamPrintService; |
37 | 54 | import javax.print.attribute.PrintRequestAttributeSet; |
38 | 55 | import javax.print.attribute.HashPrintRequestAttributeSet; |
39 | 56 | import javax.print.attribute.standard.Chromaticity; |
|
48 | 65 | import javax.print.attribute.standard.Sides; |
49 | 66 | import javax.print.attribute.Attribute; |
50 | 67 |
|
51 | | -import sun.java2d.*; |
52 | | -import sun.print.*; |
| 68 | +import sun.java2d.Disposer; |
| 69 | +import sun.java2d.DisposerRecord; |
| 70 | +import sun.java2d.SunGraphics2D; |
| 71 | +import sun.java2d.SurfaceData; |
| 72 | +import sun.print.CustomMediaTray; |
| 73 | +import sun.print.CustomOutputBin; |
| 74 | +import sun.print.GrayscaleProxyGraphics2D; |
| 75 | +import sun.print.PeekGraphics; |
| 76 | +import sun.print.RasterPrinterJob; |
| 77 | +import sun.print.SunPageSelection; |
53 | 78 |
|
54 | 79 | public final class CPrinterJob extends RasterPrinterJob { |
55 | 80 | // NOTE: This uses RasterPrinterJob as a base, but it doesn't use |
@@ -82,7 +107,8 @@ public final class CPrinterJob extends RasterPrinterJob { |
82 | 107 | // PageFormat data is passed in and set on the fNSPrintInfo on a per call |
83 | 108 | // basis. |
84 | 109 | private long fNSPrintInfo = -1; |
85 | | - private Object fNSPrintInfoLock = new Object(); |
| 110 | + private final Object fNSPrintInfoLock = new Object(); |
| 111 | + private final Object disposerReferent = new Object(); |
86 | 112 |
|
87 | 113 | static { |
88 | 114 | // AWT has to be initialized for the native code to function correctly. |
@@ -610,25 +636,29 @@ private boolean jobSetup(Pageable doc) { |
610 | 636 |
|
611 | 637 | // The following methods are CPrinterJob specific. |
612 | 638 |
|
613 | | - @Override |
614 | | - @SuppressWarnings("removal") |
615 | | - protected void finalize() { |
616 | | - synchronized (fNSPrintInfoLock) { |
617 | | - if (fNSPrintInfo != -1) { |
618 | | - dispose(fNSPrintInfo); |
619 | | - } |
620 | | - fNSPrintInfo = -1; |
| 639 | + static class NSPrintInfoDisposer implements DisposerRecord { |
| 640 | + |
| 641 | + private final long fNSPrintInfo; |
| 642 | + |
| 643 | + NSPrintInfoDisposer(long ptr) { |
| 644 | + fNSPrintInfo = ptr; |
| 645 | + } |
| 646 | + |
| 647 | + public void dispose() { |
| 648 | + CPrinterJob.disposeNSPrintInfo(fNSPrintInfo); |
621 | 649 | } |
622 | 650 | } |
623 | 651 |
|
624 | | - private native long createNSPrintInfo(); |
625 | | - private native void dispose(long printInfo); |
| 652 | + private static native long createNSPrintInfo(); |
| 653 | + private static native void disposeNSPrintInfo(long printInfo); |
626 | 654 |
|
627 | 655 | private long getNSPrintInfo() { |
628 | 656 | // This is called from the native side. |
629 | 657 | synchronized (fNSPrintInfoLock) { |
630 | 658 | if (fNSPrintInfo == -1) { |
631 | 659 | fNSPrintInfo = createNSPrintInfo(); |
| 660 | + Disposer.addRecord(disposerReferent, |
| 661 | + new NSPrintInfoDisposer(fNSPrintInfo)); |
632 | 662 | } |
633 | 663 | return fNSPrintInfo; |
634 | 664 | } |
|
0 commit comments