|
1 | 1 | /* |
2 | | - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
28 | 28 | * entry is working |
29 | 29 | * @run main/manual PageDialogMarginTest |
30 | 30 | */ |
31 | | -import java.awt.Component; |
| 31 | + |
32 | 32 | import java.awt.print.PageFormat; |
33 | 33 | import java.awt.print.PrinterJob; |
| 34 | +import java.util.Locale; |
34 | 35 | import javax.print.attribute.HashPrintRequestAttributeSet; |
35 | 36 | import javax.print.attribute.PrintRequestAttributeSet; |
36 | 37 | import javax.print.attribute.standard.MediaPrintableArea; |
|
39 | 40 |
|
40 | 41 | public class PageDialogMarginTest { |
41 | 42 |
|
42 | | - public static void main(String args[]) throws Exception { |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + Locale.setDefault(Locale.US); |
43 | 45 | String[] instructions |
44 | 46 | = { |
45 | 47 | "Page Dialog will be shown.", |
46 | 48 | "Change top(in) margin value from 1.0 to 2.0", |
47 | 49 | "Then select OK." |
48 | 50 | }; |
49 | | - SwingUtilities.invokeAndWait(() -> { |
50 | | - JOptionPane.showMessageDialog((Component) null, |
51 | | - instructions, "Instructions", |
52 | | - JOptionPane.INFORMATION_MESSAGE); |
53 | | - }); |
| 51 | + SwingUtilities.invokeAndWait(() -> JOptionPane.showMessageDialog(null, |
| 52 | + instructions, "Instructions", |
| 53 | + JOptionPane.INFORMATION_MESSAGE)); |
54 | 54 | PrinterJob pj = PrinterJob.getPrinterJob(); |
55 | | - try { |
56 | | - HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); |
57 | | - PageFormat pf; |
58 | | - pf = pj.pageDialog(aset); |
59 | | - double left = pf.getImageableX(); |
60 | | - double top = pf.getImageableY(); |
61 | | - System.out.println("pageDialog - left/top from pageFormat: " + left / 72 |
62 | | - + " " + top / 72); |
63 | | - System.out.println("pageDialog - left/top from attribute set: " |
64 | | - + getPrintableXFromASet(aset) + " " |
65 | | - + getPrintableYFromASet(aset)); |
66 | | - if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) { |
67 | | - throw new RuntimeException("Top margin value not updated"); |
68 | | - } |
69 | | - } catch (Exception e) { |
70 | | - e.printStackTrace(); |
| 55 | + |
| 56 | + HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); |
| 57 | + PageFormat pf = pj.pageDialog(aset); |
| 58 | + double left = pf.getImageableX(); |
| 59 | + double top = pf.getImageableY(); |
| 60 | + |
| 61 | + System.out.println("pageDialog - left/top from pageFormat: " + left / 72 |
| 62 | + + " " + top / 72); |
| 63 | + System.out.println("pageDialog - left/top from attribute set: " |
| 64 | + + getPrintableXFromASet(aset) + " " |
| 65 | + + getPrintableYFromASet(aset)); |
| 66 | + if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) { |
| 67 | + throw new RuntimeException("Top margin value not updated"); |
71 | 68 | } |
72 | 69 | } |
73 | 70 |
|
|
0 commit comments