--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/DestinationTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4846344 4851365 4851321 4851316 4863656 5046198 6293139
+ * @summary Confirm that cancelling the dialog will not prompt for file.
+ * @run main/manual DestinationTest
+ */
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.io.*;
+
+public class DestinationTest extends Frame implements ActionListener {
+ //Declare things used in the test, like buttons and labels here
+
+ DisplayImages images;
+ Button nativeDlg, nativeDlg2, commonSelectionDlg, commonRangeDlg, fileDlg;
+
+ public DestinationTest() {
+
+ images = new DisplayImages();
+ images.setSize(530, 480);
+ add(images, "Center");
+
+ Panel printpanel = new Panel();
+
+ nativeDlg = new Button("Native");
+ nativeDlg.addActionListener(this);
+ printpanel.add(nativeDlg);
+
+ nativeDlg2 = new Button("Native 2");
+ nativeDlg2.addActionListener(this);
+ printpanel.add(nativeDlg2);
+
+ commonSelectionDlg = new Button("Common Selection");
+ commonSelectionDlg.addActionListener(this);
+ printpanel.add(commonSelectionDlg);
+
+ commonRangeDlg = new Button("Common Range");
+ commonRangeDlg.addActionListener(this);
+ printpanel.add(commonRangeDlg);
+
+ fileDlg = new Button("Print To File - Common Dialog");
+ fileDlg.addActionListener(this);
+ printpanel.add(fileDlg);
+
+ add(printpanel, "South");
+ setSize(900, 300);
+ setVisible(true);
+ }
+
+ public static void main (String args[]) {
+ DestinationTest test = new DestinationTest();
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+
+ JobAttributes ja = new JobAttributes();
+ PageAttributes pa = new PageAttributes();
+ ja.setDestination(JobAttributes.DestinationType.FILE);
+ ja.setFileName("test_file_name.prn");
+
+ if(e.getSource()== nativeDlg) {
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
+ ja.setPageRanges(new int[][] {new int[] {2,3}, new int[] {5,6}});
+ ja.setDialog(JobAttributes.DialogType.NATIVE);
+ }
+
+ if(e.getSource()== nativeDlg2) {
+ ja.setFileName("");
+ ja.setDialog(JobAttributes.DialogType.NATIVE);
+ }
+
+ if(e.getSource()== commonRangeDlg) {
+ ja = new JobAttributes();
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE);
+ ja.setPageRanges(new int[][] {new int[] {1,3}, new int[] {5,6}});
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ if (e.getSource() == fileDlg) {
+ ja = new JobAttributes();
+ ja.setDestination(JobAttributes.DestinationType.FILE);
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ if(e.getSource()== commonSelectionDlg) {
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ PrintJob pjob = getToolkit().getPrintJob(this,"Printing Test",ja,pa);
+ System.out.println("6293139: Chosen printer is: "+ja.getPrinter());
+ if(pjob != null) {
+
+ Graphics pg = pjob.getGraphics();
+
+ if(pg != null) {
+ //images.printAll(pg);
+ this.printAll(pg);
+ pg.dispose();
+ }
+ pjob.end();
+ }
+ }
+}
+
+class DisplayImages extends Canvas {
+
+ public void paint(Graphics g) {
+
+ g.setFont(new Font("Helvetica", Font.BOLD, 12));
+ g.drawString("PRINTING TEST", 1, 10);
+ g.drawString(" 4846344: Confirm that cancelling the native dialog will not prompt for file.", 1, 25);
+ g.drawString(" 4851365: Confirm that printing in native dialog shows test_file_name.prn as default.", 1, 40);
+ g.drawString(" 4851321: Confirm that in the Common Range dialog, page ranges is set to 1-6.", 1, 55);
+ g.drawString(" 4851316: Confirm that NPE is not thrown upon selecting Common Selection dialog.", 1, 70);
+ g.drawString(" 4863656: Confirm that no IAE is thrown when printing in native dialog.", 1, 85);
+ g.drawString(" 4864444: Confirm that the default directory in Native 2 is same as current one with no filename set.", 1, 100);
+ g.drawString(" 5046198: Confirm that the default filename in Common Range dialog when printing to a file is same as that of PrintToFile dialog.", 1, 115);
+ g.drawString(" 6293139: In Common Range dialog, change printer before printing then confirm the chosen printer.", 1, 130);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/MediaInPrintable.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4869575 6361766
+ * @summary Setting orientation in the page format does not have any effect on the printout. To test 6361766, the application must exit.
+ * @run main/manual MediaInPrintable
+ */
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+
+public class MediaInPrintable implements Printable {
+ private static Font fnt = new Font("Helvetica",Font.PLAIN,24);
+ public static void main(String[] args) {
+
+ System.out.println("arguments : native1 | native2\nExpected output :\n\tnative1 - Landscape orientation.\n\tnative2 - Legal paper is selected.");
+ if (args.length == 0) {
+ return;
+ }
+
+
+ // Get a PrinterJob
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat pf = new PageFormat();
+
+ if (args[0].equals("native1")) {
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ job.setPrintable(new MediaInPrintable(), pf);
+ if (job.printDialog()) {
+ // Print the job if the user didn't cancel printing
+ try {
+ job.print();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } else if (args[0].equals("native2")) {
+ Paper p = new Paper();
+ p.setSize(612.0, 1008.0);
+ p.setImageableArea(72.0, 72.0, 468.0, 864.0);
+ pf.setPaper(p);
+
+ job.setPrintable(new MediaInPrintable(), pf);
+ if (job.printDialog()) {
+ // Print the job if the user didn't cancel printing
+ try {
+ job.print();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ //System.exit(0);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ g.setFont(fnt);
+ g.setColor(Color.green);
+ g.drawString("Page " + (pageIndex+1), 100, 100);
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintApplet.html Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,29 @@
+!--
+ Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<title>PrintApplet</title>
+<h1>PrintApplet</h1>
+
+
+<applet code="PrintApplet.class" width=300 height=300>
+</applet><p>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintApplet.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 5024549
+ @summary Pass if dialogs are modal.
+ @run applet/manual PrintApplet.html
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PrintApplet extends JApplet implements Printable {
+ private JButton jButton1 = new JButton();
+
+
+ public PrintApplet() {
+ }
+
+ public void init() {
+ try {
+ jbInit();
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void jbInit() throws Exception {
+ jButton1.setText("PRINT");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ jButton1_actionPerformed(e);
+ }
+ });
+ jButton1.setBounds(new Rectangle(165, 248, 80, 30));
+ this.setSize(new Dimension(400,300));
+ this.getContentPane().setLayout(null);
+ this.getContentPane().setBackground(Color.pink);
+ this.getContentPane().add(jButton1, BorderLayout.SOUTH);
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+ public void destroy() {
+ }
+
+ public String getAppletInfo() {
+ return "Applet inf";
+ }
+
+ public String[][] getParameterInfo() {
+ return null;
+ }
+
+
+ public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
+ System.out.println("Calling print");
+ if (page == 0) {
+ Graphics2D g2 = (Graphics2D)g;
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.setColor(Color.black);
+ g2.drawString("Hello World", 20, 100);
+
+ return Printable.PAGE_EXISTS;
+ }
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+
+ void jButton1_actionPerformed(ActionEvent e) {
+ PrinterJob printJob = null;
+ PageFormat pageFormat = null;
+ Paper prtPaper = null;
+ boolean bPrintFlg = true;
+
+
+ try{
+ printJob = PrinterJob.getPrinterJob();
+
+ }
+ catch(SecurityException se){
+
+ bPrintFlg = false;
+ }
+
+ if (bPrintFlg) {
+
+ pageFormat = printJob.pageDialog(printJob.defaultPage());
+ System.out.println("PrintApplet: pageFormat = "+pageFormat.getWidth()/72.0+" x "+pageFormat.getHeight()/72.0);
+ if (pageFormat != null) {
+
+ prtPaper = pageFormat.getPaper();
+ pageFormat.setPaper(prtPaper);
+
+
+ printJob.setPrintable(this, pageFormat);
+ }
+
+ if (printJob.printDialog()) {
+
+ try {
+ printJob.print();
+ }
+ catch (java.awt.print.PrinterException ex) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDialog.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 6342748
+ @summary Pass if dialogs display correctly
+ @run main/manual PrintDialog
+*/
+import java.awt.print.*;
+import javax.print.attribute.*;
+
+public class PrintDialog {
+
+ public static void main(java.lang.String[] args) {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
+ System.out.println("Verify page setup dialog appears correctly then cancel or OK");
+ pj.pageDialog(pSet);
+ System.out.println("Verify all tabs of print dialog appear correctly then cancel or OK");
+ pj.printDialog(pSet);
+ return;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDlgApp.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4865976 7158366
+ @summary Pass if it program exits.
+ @run main/manual PrintDlgApp
+*/
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.Destination;
+import java.util.Locale;
+
+import javax.print.*;
+
+class PrintDlgApp implements Printable {
+ /**
+ * Constructor
+ */
+ public PrintDlgApp() {
+ super();
+ }
+ /**
+ * Starts the application.
+ */
+ public static void main(java.lang.String[] args) {
+ PrintDlgApp pd = new PrintDlgApp();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ System.out.println(pj);
+ PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
+ pSet.add(new Copies(1));
+ //PageFormat pf = pj.pageDialog(pSet);
+ PageFormat pf = new PageFormat();
+ System.out.println("Setting Printable...pf = "+pf);
+ if (pf == null) {
+ return;
+ }
+ pj.setPrintable(pd,pf);
+
+ //try { pj.setPrintService(services[0]); } catch(Exception e) { e.printStackTrace(); }
+ pSet.add(new Destination(new java.io.File("./out.prn").toURI()));
+ System.out.println("open PrintDialog..");
+ for (int i=0; i<2; i++) {
+ if (pj.printDialog(pSet)) {
+ try {
+ System.out.println("About to print the data ...");
+ pj.print(pSet);
+ System.out.println("Printed");
+ }
+ catch (PrinterException pe) {
+ pe.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ //printable interface
+ public int print(Graphics g, PageFormat pf, int pi) throws
+PrinterException {
+
+ if (pi > 0) {
+ System.out.println("pi is greater than 0");
+ return Printable.NO_SUCH_PAGE;
+ }
+ // Simply draw two rectangles
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setColor(Color.black);
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.drawRect(1,1,200,300);
+ g2.drawRect(1,1,25,25);
+ System.out.println("print method called "+pi);
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDlgPageable.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4869502 4869539
+ * @summary Confirm that ToPage is populated for argument =2. Range is disabled for argument = 0.
+ * @run main/manual PrintDlgPageable
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.util.Locale;
+
+import javax.print.*;
+
+class PrintDlgPageable implements Printable {
+ public static int arg;
+ /**
+ * Constructor
+ */
+ public PrintDlgPageable() {
+ super();
+ }
+ /**
+ * Starts the application.
+ */
+ public static void main(java.lang.String[] args) {
+ if (args.length < 1) {
+ System.out.println("usage: java PrintDlgPageable { 0 | 2}");
+ return;
+ }
+ arg = Integer.parseInt(args[0]);
+ PrintDlgPageable pd = new PrintDlgPageable();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ PageableHandler handler = new PageableHandler();
+ pj.setPageable(handler);
+
+ System.out.println("open PrintDialog..");
+ if (pj.printDialog()) {
+ try {
+ System.out.println("About to print the data ...");
+ pj.print();
+ System.out.println("Printed");
+ }
+ catch (PrinterException pe) {
+ pe.printStackTrace();
+ }
+ }
+
+ }
+
+ //printable interface
+ public int print(Graphics g, PageFormat pf, int pi) throws
+PrinterException {
+
+ /*if (pi > 0) {
+ System.out.println("pi is greater than 0");
+ return Printable.NO_SUCH_PAGE;
+ }*/
+ // Simply draw two rectangles
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setColor(Color.black);
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.drawRect(1,1,200,300);
+ g2.drawRect(1,1,25,25);
+ System.out.println("print method called "+pi + " Orientation "+pf.getOrientation());
+ return Printable.PAGE_EXISTS;
+ }
+}
+
+class PageableHandler implements Pageable {
+
+ PageFormat pf = new PageFormat();
+
+ public int getNumberOfPages() {
+ return PrintDlgPageable.arg;
+ //return 0;
+ }
+
+ public Printable getPrintable(int pageIndex) {
+ return new PrintDlgPageable();
+ }
+
+ public PageFormat getPageFormat(int pageIndex) {
+ System.out.println("getPageFormat called "+pageIndex);
+ if (pageIndex == 0) {
+ pf.setOrientation(PageFormat.PORTRAIT);
+ System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
+ return pf;
+ } else {
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
+ return pf;
+ }
+ }
+
+ public String findOrientation(int orient) {
+ if (orient == PageFormat.LANDSCAPE) {
+ return "LANDSCAPE";
+ }else if (orient == PageFormat.PORTRAIT) {
+ return "PORTRAIT";
+ } else if (orient == PageFormat.REVERSE_LANDSCAPE) {
+ return "REVERSE LANDSCAPE";
+ } else {
+ return null;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/RestoreActiveWindowTest/RestoreActiveWindowTest.html Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,43 @@
+<!--
+ Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<html>
+<!--
+ @test
+ @bug 6365992 6379599
+ @summary REG: Showing and disposing a native print dialog makes the main frame inactive, Win32
+ @author Dmitry.Cherepanov@SUN.COM area=awt.printdialog
+ @run applet/manual=yesno RestoreActiveWindowTest.html
+ -->
+<head>
+<title>RestoreActiveWindowTest</title>
+</head>
+<body>
+
+<h1>RestoreActiveWindowTest<br>Bug ID: 6365992</h1>
+
+<p> See the dialog box (usually in upper left corner) for instructions</p>
+
+<APPLET CODE="RestoreActiveWindowTest.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/RestoreActiveWindowTest/RestoreActiveWindowTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ test
+ @bug 6365992 6379599
+ @summary REG: Showing and disposing a native print dialog makes the main frame inactive, Win32
+ @author Dmitry.Cherepanov@SUN.COM area=awt.printdialog
+ @run applet/manual=yesno RestoreActiveWindowTest.html
+*/
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+
+public class RestoreActiveWindowTest extends Applet
+{
+ Button showBtn1 = new Button("show a native print dialog");
+ Button showBtn2 = new Button("show a native page dialog");
+
+ public void init()
+ {
+ showBtn1.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent ae) {
+ PrinterJob.getPrinterJob().printDialog();
+ }
+ });
+ showBtn2.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent ae){
+ PrinterJob.getPrinterJob().pageDialog(new PageFormat());
+ }
+ });
+
+ add(showBtn1);
+ add(showBtn2);
+
+ String[] instructions = {
+ "1.1) Click on 'show a native print dialog'. A native print dialog will come up.",
+ "1.2) Click on the 'close'(X) button. The dialog will be closed.",
+ "1.3) After the dialog closing another window should become the active window.",
+ "1.4) If there no any active window then the test failed.",
+ "2.1) Click on 'show a native page dialog'. A native page dialog will come up.",
+ "2.2) Click on the 'close'(X) button. The dialog will be closed.",
+ "2.3) After the dialog closing another window should become the active window.",
+ "2.4) If there no any active window then the test failed.",
+ "3) Test Passed."
+ };
+
+ Sysout.createDialogWithInstructions( instructions );
+
+ }//End init()
+
+ public void start ()
+ {
+ //Get things going. Request focus, set size, et cetera
+ setSize (200,200);
+ show();
+
+ }// start()
+
+ //The rest of this class is the actions which perform the test...
+
+ //Use Sysout.println to communicate with the user NOT System.out!!
+ //Sysout.println ("Something Happened!");
+
+}// class ManualYesNoTest
+
+/* Place other classes related to the test after this line */
+
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+{
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+{
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ setVisible(true);
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ System.out.println(messageIn);
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/CustomPaper.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4355514
+ * @bug 4385157
+ * @author Jennifer Godinez
+ * @summary Prints a rectangle to show the imageable area of a
+ * 12in x 14in custom paper size.
+ * @run main/manual CustomPaper
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.geom.*;
+
+public class CustomPaper implements Pageable, Printable{
+
+ private static double PIXELS_PER_INCH = 72.0;
+
+ private PrinterJob printerJob;
+ private PageFormat pageFormat;
+
+ CustomPaper(){
+ printerJob = PrinterJob.getPrinterJob();
+ createPageFormat();
+ }
+
+ private void createPageFormat(){
+ pageFormat = new PageFormat();
+ Paper p = new Paper();
+ double width = 12.0*PIXELS_PER_INCH;
+ double height = 14.0*PIXELS_PER_INCH;
+ double ix = PIXELS_PER_INCH;
+ double iy = PIXELS_PER_INCH;
+ double iwidth = width - 2.0*PIXELS_PER_INCH;
+ double iheight = height - 2.0*PIXELS_PER_INCH;
+ p.setSize(width, height);
+ p.setImageableArea(ix, iy, iwidth, iheight);
+ pageFormat.setPaper(p);
+ }
+
+ public Printable getPrintable(int index){
+ return this;
+ }
+
+ public PageFormat getPageFormat(int index){
+ return pageFormat;
+ }
+
+ public int getNumberOfPages(){
+ return 1;
+ }
+
+ public void print(){
+ if(printerJob.printDialog())
+ {
+ try{
+ printerJob.setPageable(this);
+ printerJob.print();
+ }catch(Exception e){e.printStackTrace();}
+ }
+
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex){
+ if(pageIndex == 0){
+ Graphics2D g2 = (Graphics2D)g;
+ Rectangle2D r = new Rectangle2D.Double(pf.getImageableX(),
+ pf.getImageableY(),
+ pf.getImageableWidth(),
+ pf.getImageableHeight());
+ g2.setStroke(new BasicStroke(3.0f));
+ g2.draw(r);
+ return PAGE_EXISTS;
+ }else{
+ return NO_SUCH_PAGE;
+ }
+ }
+
+ public static void main(String[] args){
+
+ String[] instructions =
+ {
+ "You must have a printer that supports custom paper size of ",
+ "at least 12 x 14 inches to perform this test. It requires",
+ "user interaction and you must have a 12 x 14 inch paper available.",
+ " ",
+ "To test bug ID 4385157, click OK on print dialog box to print.",
+ " ",
+ "To test bug ID 4355514, select the printer in the Print Setup dialog and add a ",
+ "custom paper size under Printer properties' Paper selection menu. ",
+ "Set the dimension to width=12 inches and height=14 inches.",
+ "Select this custom paper size before proceeding to print.",
+ " ",
+ "Visual inspection of the one-page printout is needed. A passing",
+ "test will print a rectangle of the imageable area which is approximately",
+ "10 x 12 inches.",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ CustomPaper pt = new CustomPaper();
+ pt.print();
+ //System.exit (0);
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/NullPaper.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4199506
+ @summary java.awt.print.PageFormat.setpaper(Paper paper)
+ assertion test fails by not throwing
+ NullPointerException when a null paper instance is
+ passed as argument and this is specified in the doc.
+ @author rbi: area=PageFormat
+ @run main NullPaper
+*/
+
+
+//*** global search and replace NullPaper with name of the test ***
+
+/**
+ * NullPaper.java
+ *
+ * summary: java.awt.print.PageFormat.setpaper(Paper paper)
+ assertion test fails by not throwing
+ NullPointerException when a null paper instance is
+ passed as argument and this is specified in the doc.
+
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class NullPaper {
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "This test should throw a NullPointerException. ",
+ "If the NullPointerException is correctly thrown ",
+ "by the call to setPaper() then the test succeeds. ",
+ "If no exception is thrown by setPaper() or if an ",
+ "exception other than NullPointerException is thrown ",
+ "then the test fails."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ boolean settingNullWorked = false;
+
+ try {
+ /* Setting the paper to null should throw an exception.
+ * The bug was the exception was not being thrown.
+ */
+ new PageFormat().setPaper(null);
+ settingNullWorked = true;
+
+ /* If the test succeeds we'll end up here, so write
+ * to standard out.
+ */
+ } catch (NullPointerException e) {
+ pass();
+
+ /* The test failed if we end up here because an exception
+ * other than the one we were expecting was thrown.
+ */
+ } catch (Exception e) {
+ fail("Instead of the expected NullPointerException, '" + e + "' was thrown.");
+ }
+
+ if (settingNullWorked) {
+ fail("The expected NullPointerException was not thrown");
+ }
+
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class NullPaper
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ NullPaper.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ NullPaper.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //NullPaper
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ NullPaper.pass();
+ }
+ else
+ {
+ NullPaper.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/Orient.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4236095
+ @summary Confirm that the you get three pages of output, one
+ each in portrait, landscape, and reverse landscape
+ orientations.
+ @author rbi: area=PageFormat
+ @run main/manual Orient
+*/
+
+
+//*** global search and replace Orient with name of the test ***
+
+/**
+ * Orient.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class Orient implements Printable {
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is three printed pages.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print three pages each containing a large oval ",
+ "with the text describing the orientation: PORTRAIT, LANDSCAPE",
+ "or REVERSE_LANDSCAPE, inside of it. The first page will ",
+ "be emitted in portait orientation, the second page in landscape ",
+ "orientation and the third page in reverse-landscape orientation. ",
+ "On each page the oval will be wholly within the imageable area ",
+ "of the page. In a failing test the oval on the third page ",
+ "will be clipped against the imageable area.",
+ "Axes will indicate the direction of increasing X and Y"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ // Page 1
+ PageFormat portrait = pjob.defaultPage();
+ portrait.setOrientation(PageFormat.PORTRAIT);
+ book.append(new Orient(), portrait);
+
+ // Page 2
+ PageFormat landscape = pjob.defaultPage();
+ landscape.setOrientation(PageFormat.LANDSCAPE);
+ book.append(new Orient(), landscape);
+
+ // Page 3
+ PageFormat reverseLandscape = pjob.defaultPage();
+ reverseLandscape.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+ book.append(new Orient(), reverseLandscape);
+
+ pjob.setPageable(book);
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ }
+
+ }//End init()
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ drawGraphics(g2d, pf);
+ return Printable.PAGE_EXISTS;
+ }
+
+ void drawGraphics(Graphics2D g, PageFormat pf) {
+ double iw = pf.getImageableWidth();
+ double ih = pf.getImageableHeight();
+
+ g.setColor(Color.black);
+ String orientation;
+ switch (pf.getOrientation()) {
+ case PageFormat.PORTRAIT : orientation = "PORTRAIT";
+ break;
+ case PageFormat.LANDSCAPE : orientation = "LANDSCAPE";
+ break;
+ case PageFormat.REVERSE_LANDSCAPE :
+ orientation = "REVERSE_LANDSCAPE";
+ break;
+ default : orientation = "INVALID";
+ }
+ g.drawString(orientation, 100, 300);
+ g.draw(new Ellipse2D.Double(0, 0, iw, ih));
+ g.drawString("(0,0)", 5,15);
+ g.drawLine(0,0,300,0);
+ g.drawString("X", 300,15);
+ g.drawLine(0,0,0,300);
+ g.drawString("Y",5,300);
+ }
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class Orient
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ Orient.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ Orient.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //Orient
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ Orient.pass();
+ }
+ else
+ {
+ Orient.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/PDialogTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4855801
+ * @summary Changing margins in the page format does not have any effect
+ * @run main/manual PDialogTest
+ */
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PDialogTest
+{
+
+ public static void main(String[] args) {
+ PageFormat page=new PageFormat();
+ while(true){
+ page=java.awt.print.PrinterJob.getPrinterJob().pageDialog(page);
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/PageSetupDialog.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4197377
+ * @bug 4299145
+ * @bug 6358747
+ * @bug 6574633
+ * @summary Page setup dialog settings
+ * @author prr
+ * @run main/manual PageSetupDialog
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class PageSetupDialog extends Frame implements Printable {
+
+ PrinterJob myPrinterJob;
+ PageFormat myPageFormat;
+ Label pw, ph, pglm, pgiw, pgrm, pgtm, pgih, pgbm;
+ Label myWidthLabel;
+ Label myHeightLabel;
+ Label myImageableXLabel;
+ Label myImageableYLabel;
+ Label myImageableRightLabel;
+ Label myImageableBottomLabel;
+ Label myImageableWidthLabel;
+ Label myImageableHeightLabel;
+ Label myOrientationLabel;
+ Checkbox reverseCB;
+ boolean alpha = false;
+ boolean reverse = false;
+
+ protected void displayPageFormatAttributes() {
+
+ myWidthLabel.setText("Format Width = " + (float)myPageFormat.getWidth());
+ myHeightLabel.setText("Format Height = " + (float)myPageFormat.getHeight());
+ myImageableXLabel.setText
+ ("Format Left Margin = " + (float)myPageFormat.getImageableX());
+ myImageableRightLabel.setText
+ ("Format Right Margin = " + (float)(myPageFormat.getWidth() -
+ (myPageFormat.getImageableX() + myPageFormat.getImageableWidth())));
+ myImageableWidthLabel.setText
+ ("Format ImageableWidth = " + (float)myPageFormat.getImageableWidth());
+ myImageableYLabel.setText
+ ("Format Top Margin = " + (float)myPageFormat.getImageableY());
+ myImageableBottomLabel.setText
+ ("Format Bottom Margin = " + (float)(myPageFormat.getHeight() -
+ (myPageFormat.getImageableY() + myPageFormat.getImageableHeight())));
+ myImageableHeightLabel.setText
+ ("Format ImageableHeight = " + (float)myPageFormat.getImageableHeight());
+ int o = myPageFormat.getOrientation();
+ if (o == PageFormat.LANDSCAPE && reverse) {
+ o = PageFormat.REVERSE_LANDSCAPE;
+ myPageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+ } else if (o == PageFormat.REVERSE_LANDSCAPE && !reverse) {
+ o = PageFormat.LANDSCAPE;
+ myPageFormat.setOrientation(PageFormat.LANDSCAPE);
+ }
+ myOrientationLabel.setText
+ ("Format Orientation = " +
+ (o == PageFormat.PORTRAIT ? "PORTRAIT" :
+ o == PageFormat.LANDSCAPE ? "LANDSCAPE" :
+ o == PageFormat.REVERSE_LANDSCAPE ? "REVERSE_LANDSCAPE" :
+ "<invalid>"));
+ Paper p = myPageFormat.getPaper();
+ pw.setText("Paper Width = " + (float)p.getWidth());
+ ph.setText("Paper Height = " + (float)p.getHeight());
+ pglm.setText("Paper Left Margin = " + (float)p.getImageableX());
+ pgiw.setText("Paper Imageable Width = " + (float)p.getImageableWidth());
+ pgrm.setText("Paper Right Margin = " +
+ (float)(p.getWidth() - (p.getImageableX()+p.getImageableWidth())));
+ pgtm.setText("Paper Top Margin = " + (float)p.getImageableY());
+ pgih.setText("Paper Imageable Height = " + (float)p.getImageableHeight());
+ pgbm.setText("Paper Bottom Margin = " +
+ (float)(p.getHeight() - (p.getImageableY()+p.getImageableHeight())));
+ }
+
+ public PageSetupDialog() {
+ super ("Page Dialog Test");
+ myPrinterJob = PrinterJob.getPrinterJob();
+ myPageFormat = new PageFormat();
+ Paper p = new Paper();
+ double margin = 1.5*72;
+ p.setImageableArea(margin, margin,
+ p.getWidth()-2*margin, p.getHeight()-2*margin);
+ myPageFormat.setPaper(p);
+ Panel c = new Panel();
+ c.setLayout (new GridLayout (9, 2, 0, 0));
+ c.add (reverseCB = new Checkbox("reverse if landscape"));
+ c.add (myOrientationLabel = new Label());
+ c.add (myWidthLabel = new Label());
+ c.add (pw = new Label());
+ c.add (myImageableXLabel = new Label());
+ c.add (pglm = new Label());
+ c.add (myImageableRightLabel = new Label());
+ c.add (pgrm = new Label());
+ c.add (myImageableWidthLabel = new Label());
+ c.add (pgiw = new Label());
+ c.add (myHeightLabel = new Label());
+ c.add (ph = new Label());
+ c.add (myImageableYLabel = new Label());
+ c.add (pgtm = new Label());
+ c.add (myImageableHeightLabel = new Label());
+ c.add (pgih = new Label());
+ c.add (myImageableBottomLabel = new Label());
+ c.add (pgbm = new Label());
+
+ reverseCB.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ reverse = e.getStateChange() == ItemEvent.SELECTED;
+ int o = myPageFormat.getOrientation();
+ if (o == PageFormat.LANDSCAPE ||
+ o == PageFormat.REVERSE_LANDSCAPE) {
+ displayPageFormatAttributes();
+ }
+ }
+ });
+
+ add("Center", c);
+ displayPageFormatAttributes();
+ Panel panel = new Panel();
+ Button pageButton = new Button ("Page Setup...");
+ pageButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ myPageFormat = myPrinterJob.pageDialog (myPageFormat);
+ displayPageFormatAttributes();
+ }
+ });
+ Button printButton = new Button ("Print ...");
+ printButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (myPrinterJob.printDialog()) {
+ myPrinterJob.setPrintable(PageSetupDialog.this,
+ myPageFormat);
+ alpha = false;
+ myPrinterJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ Button printAlphaButton = new Button ("Print w/Alpha...");
+ printAlphaButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (myPrinterJob.printDialog()) {
+ myPrinterJob.setPrintable(PageSetupDialog.this,
+ myPageFormat);
+ alpha = true;
+ myPrinterJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ panel.add (pageButton);
+ panel.add (printButton);
+ panel.add (printAlphaButton);
+ add("South", panel);
+ addWindowListener (new WindowAdapter() {
+ public void windowClosing (WindowEvent e) {
+ dispose();
+ System.exit (0);
+ }
+
+ });
+ //setSize (280, 550);
+ pack();
+ setVisible (true);
+ }
+
+ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D)graphics;
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+ g2d.drawString("ORIGIN("+pageFormat.getImageableX()+","+
+ pageFormat.getImageableY()+")", 20, 20);
+ g2d.drawString("X THIS WAY", 200, 50);
+ g2d.drawString("Y THIS WAY", 60 , 200);
+ g2d.drawString("Graphics is " + g2d.getClass().getName(), 100, 100);
+ g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ if (alpha) {
+ g2d.setColor(new Color(0,0,255,192));
+ } else {
+ g2d.setColor(Color.blue);
+ }
+ g2d.drawRect(1,1,(int)pageFormat.getImageableWidth()-2,
+ (int)pageFormat.getImageableHeight()-2);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main( String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test is very flexible and requires much interaction.",
+ "If the platform print dialog supports it, adjust orientation",
+ "and margins and print pages and compare the results with the",
+ "request."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new PageSetupDialog();
+ }
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/ReverseLandscapeTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4254954
+ * @summary PageFormat would fail on solaris when setting orientation
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class ReverseLandscapeTest extends Frame {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+ ReverseLandscapeTest f = new ReverseLandscapeTest();
+ f.show();
+ }
+
+ public ReverseLandscapeTest() {
+ super("JDK 1.2 Text Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ PageFormat pf = pj.defaultPage();
+ pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+
+ // This code can be added if one wishes to test printing
+// pf = pj.pageDialog(pf);
+
+// if (pj != null && pj.printDialog()) {
+
+// pj.setPrintable(c, pf);
+// try {
+// pj.print();
+// } catch (PrinterException pe) {
+// } finally {
+// System.err.println("PRINT RETURNED");
+// }
+// }
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ int iw = getWidth();
+ int ih = getHeight();
+ Graphics2D g2d = (Graphics2D)g;
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ g2d.translate(iw/2, ih/2);
+ g2d.setFont(new Font("Times",Font.PLAIN, 12));
+ g2d.setPaint(new Color(0,0,0));
+ g2d.setStroke(new BasicStroke(1f));
+ g2d.drawString("Print REVERSE_LANDSCAPE", 30, 40);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g) {
+ g.drawString("Print REVERSE_LANDSCAPE", 30, 40);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(250, 100);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SetOrient.html Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,48 @@
+<!--
+ Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<!--
+ @test
+ @bug 4186119
+ @summary Confirm that the clip and transform of the Graphics2D is
+ affected by the landscape orientation of the PageFormat.
+ @run applet/manual=yesno SetOrient.html
+ -->
+<html>
+ <head>
+ <title>SetOrient</title>
+ </head>
+
+ <body>
+This test prints two pages and sends them to the printer.
+One page is in PORTRAIT orientation and the other is in LANDSCAPE
+orientation. On each page it draws an ellipse inscribed in the clip
+boundary established by the PrinterJob. The ellipse should fill the
+page within the bounds established by the default margins and not
+extend off any end or side of the page. Also, the string "Portrait"
+or "Landscape" should be oriented correctly.
+
+ <applet code="SetOrient.class" width=200 height=200></applet>
+ </body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SetOrient.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @bug 4186119: setting orientation does not affect printer
+ * @summary Confirm that the clip and transform of the Graphics2D is
+ * affected by the landscape orientation of the PageFormat.
+ * @run applet/manual=yesno SetOrient.html
+ */
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.applet.Applet;
+
+public class SetOrient extends Applet implements Printable {
+ PrinterJob pjob;
+
+ public void init() {
+ pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+ PageFormat pf = pjob.defaultPage();
+ pf.setOrientation(PageFormat.PORTRAIT);
+ book.append(this, pf);
+ pf = pjob.defaultPage();
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ book.append(this, pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D)g;
+ drawGraphics(g2d, pf);
+ return Printable.PAGE_EXISTS;
+ }
+
+ void drawGraphics(Graphics2D g, PageFormat pf) {
+ double ix = pf.getImageableX();
+ double iy = pf.getImageableY();
+ double iw = pf.getImageableWidth();
+ double ih = pf.getImageableHeight();
+
+ g.setColor(Color.black);
+ g.drawString(((pf.getOrientation() == PageFormat.PORTRAIT)
+ ? "Portrait" : "Landscape"),
+ (int) (ix+iw/2), (int) (iy+ih/2));
+ g.draw(new Ellipse2D.Double(ix, iy, iw, ih));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SmallPaperPrinting.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ import java.awt.*;
+ import java.awt.print.*;
+
+ public class SmallPaperPrinting
+ {
+ public static void main(String args[])
+ {
+ System.out.println("----------------- Instructions --------------------");
+ System.out.println("Arguments: (none) - paper width=1, height=.0001");
+ System.out.println(" 1 - paper width=.0001, height=1");
+ System.out.println(" 2 - paper width=-1, height=1");
+ System.out.println("A passing test should catch a PrinterException");
+ System.out.println("and should display \"Print error: (exception msg)\".");
+ System.out.println("---------------------------------------------------\n");
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat format = job.defaultPage();
+ Paper paper = format.getPaper();
+
+ double w = 1, h = .0001; // Generates ArithmeticException: / by zero.
+ if(args.length > 0 && args[0].equals("1")) {
+ w = .0001; h = 1; } // Generates IllegalArgumentException.
+ else if(args.length > 0 && args[0].equals("2")) {
+ w = -1; h = 1; } // Generates NegativeArraySizeException.
+ paper.setSize(w, h);
+ paper.setImageableArea(0, 0, w, h);
+ format.setPaper(paper);
+ job.setPrintable(
+ new Printable() {
+ public int print(Graphics g, PageFormat page_format, int page) {
+ return NO_SUCH_PAGE;
+ }
+ }, format);
+
+ try {
+ job.print(); }
+ catch(PrinterException e) {
+ System.err.println("Print error:\n" + e.getMessage()); // Passing test!
+ }
+ }
+ }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/ValidateCustom.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4414987
+ * @author Jennifer Godinez
+ * @summary Displays width & height of validated custom paper size
+ * @run main/manual ValidateCustom
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.geom.*;
+import javax.swing.*;
+
+public class ValidateCustom implements Pageable, Printable{
+
+ private static double PIXELS_PER_INCH = 72.0;
+ private static double WIDTH = 17.0; //width of paper in inches
+ private static double LENGTH = 24.0; //length of paper in inches
+ private static boolean VALIDATE = true;
+
+ private PrinterJob printerJob;
+ private PageFormat pageFormat;
+
+ ValidateCustom(){
+ printerJob = PrinterJob.getPrinterJob();
+ createPageFormat();
+ }
+
+ private void createPageFormat(){
+ pageFormat = new PageFormat();
+ Paper p = new Paper();
+ double width = WIDTH*PIXELS_PER_INCH;
+ double height = LENGTH*PIXELS_PER_INCH;
+ double ix = PIXELS_PER_INCH;
+ double iy = PIXELS_PER_INCH;
+ double iwidth = width - 2.0*PIXELS_PER_INCH;
+ double iheight = height - 2.0*PIXELS_PER_INCH;
+ p.setSize(width, height);
+ p.setImageableArea(ix, iy, iwidth, iheight);
+ pageFormat.setPaper(p);
+ }
+
+ public Printable getPrintable(int index){
+ return this;
+ }
+
+ public PageFormat getPageFormat(int index){
+ return pageFormat;
+ }
+
+ public int getNumberOfPages(){
+ return 1;
+ }
+
+ private void printPaperSize(PageFormat pf){
+ Paper p = pf.getPaper();
+ System.out.println("paper size = ("+p.getWidth()+", "+p.getHeight()+")");
+ }
+
+ public void print(){
+ //if(printerJob.printDialog())
+ {
+ try{
+ //printPaperSize(pageFormat);
+ if(VALIDATE){
+ this.pageFormat = printerJob.validatePage(this.pageFormat);
+ }
+ printPaperSize(pageFormat);
+ //printerJob.setPageable(this);
+ //printerJob.print();
+ }catch(Exception e){e.printStackTrace();}
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex){
+ if(pageIndex == 0){
+ Graphics2D g2 = (Graphics2D)g;
+ Rectangle2D r = new Rectangle2D.Double(PIXELS_PER_INCH, PIXELS_PER_INCH, PIXELS_PER_INCH, PIXELS_PER_INCH);
+ g2.setStroke(new BasicStroke(1.0f));
+ g2.draw(r);
+ return PAGE_EXISTS;
+ }else{
+ return NO_SUCH_PAGE;
+ }
+ }
+
+ public static void main(String[] args){
+ System.out.println("-----------------instructions--------------------");
+ System.out.println("You must have a printer installed in your system \nthat supports custom paper sizes in order to run this test.");
+ System.out.println("Passing test will display the correct width & height\nof custom paper in 1/72nds of an inch.\n");
+ System.out.println("-------------------------------------------------");
+ ValidateCustom pt = new ValidateCustom();
+ pt.print();
+ try{
+ System.in.read();
+ }catch(Exception e){}
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/Cancel/PrinterJobCancel.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4245280
+ * @summary PrinterJob not cancelled when PrinterJob.cancel() is used
+ * @author prr
+ * @run main/manual PrinterJobCancel
+ */
+
+import java.awt.* ;
+import java.awt.print.* ;
+
+public class PrinterJobCancel extends Thread implements Printable {
+
+ PrinterJob pj ;
+ boolean okayed;
+
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {
+ "Test that print job cancellation works.",
+ "You must have a printer available to perform this test.",
+ "This test silently starts a print job and while the job is",
+ "still being printed, cancels the print job",
+ "You should see a message on System.out that the job",
+ "was properly cancelled.",
+ "You will need to kill the application manually since regression",
+ "tests apparently aren't supposed to call System.exit()"
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJobCancel pjc = new PrinterJobCancel() ;
+
+ if (pjc.okayed) {
+ pjc.start();
+ try {
+ Thread.sleep(5000);
+ pjc.pj.cancel();
+ } catch ( InterruptedException e ) {
+ }
+ }
+ }
+
+ public PrinterJobCancel() {
+
+ pj = PrinterJob.getPrinterJob() ;
+ pj.setPrintable(this);
+ okayed = pj.printDialog();
+ }
+
+ public void run() {
+ boolean cancelWorked = false;
+ try {
+ pj.print() ;
+ }
+ catch ( PrinterAbortException paex ) {
+ cancelWorked = true;
+ System.out.println("Job was properly cancelled and we");
+ System.out.println("got the expected PrintAbortException");
+ }
+ catch ( PrinterException prex ) {
+ System.out.println("This is wrong .. we shouldn't be here");
+ System.out.println("Looks like a test failure");
+ prex.printStackTrace() ;
+ //throw prex;
+ }
+ finally {
+ System.out.println("DONE PRINTING");
+ if (!cancelWorked) {
+ System.out.println("Looks like the test failed - we didn't get");
+ System.out.println("the expected PrintAbortException ");
+ }
+ }
+ //System.exit(0);
+ }
+
+ public int print(Graphics g, PageFormat pagef, int pidx) {
+
+ if (pidx > 5) {
+ return( Printable.NO_SUCH_PAGE ) ;
+ }
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pagef.getImageableX(), pagef.getImageableY());
+ g2d.setColor(Color.black);
+
+ g2d.drawString(("This is page"+(pidx+1)), 60 , 80);
+ // Need to slow things down a bit .. important not to try this
+ // on the event dispathching thread of course.
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ }
+
+ return ( Printable.PAGE_EXISTS );
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CheckAccess.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4151121
+ * @summary Confirm that PrinterJob.getPrinterJob is access checked.
+ * @author Graham Hamilton
+ */
+
+import java.awt.print.*;
+import java.security.*;
+
+public class CheckAccess {
+
+ static boolean verbose;
+
+ private static void println(String mess) {
+ if (verbose) {
+ System.err.println(mess);
+ }
+ }
+
+ /**
+ * SecurityManager that rejects all print requests,
+ * but allows everything else.
+ */
+ static class PrintHater extends SecurityManager {
+
+ public void checkPermission(Permission p) {
+ // We're easy.
+ }
+
+ public void checkPrintJobAccess() {
+ throw new SecurityException("No way!");
+ }
+ }
+
+ public static void main(String argv[]) {
+
+ if (argv.length > 0 && argv[0].equals("-v")) {
+ verbose = true;
+ }
+
+ // Try to install our own security manager.
+ try {
+ SecurityManager sm = new PrintHater();
+ println("Installing PrintHater security manager");
+ System.setSecurityManager(sm);
+ println("Installed security manager OK");
+
+ } catch (Throwable th) {
+ System.err.println("Failed to install SecurityManager");
+ th.printStackTrace();
+ throw new RuntimeException("Failed to install SecurityManager");
+ }
+
+ try {
+
+ println("Calling PrinterJob.getPrinterJob()");
+ PrinterJob.getPrinterJob();
+
+ // Woops. We did not get the SecurityException we expected.
+ println("Failed to get SecurityException");
+ throw new RuntimeException("Failed to get expected SecurityException");
+
+ } catch (SecurityException ex) {
+ // Happy, happy. This is what we want.
+ println("Got expected SecurityException OK.");
+ return;
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CheckPrivilege.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4151151
+ * @summary Confirm that low-level print code does doPrivilege.
+ * @author Graham Hamilton
+ */
+
+import java.awt.print.*;
+
+public class CheckPrivilege implements Printable {
+
+ static boolean verbose;
+
+ private static void println(String mess) {
+ if (verbose) {
+ System.err.println(mess);
+ }
+ }
+
+ /**
+ * SecurityManager that allows print requests, but
+ * causes things like "exec" to get checked.
+ */
+ static class PrintLover extends SecurityManager {
+ public void checkPrintJobAccess() {
+ }
+ public void checkPackageAccess(String pkg) {
+ }
+ public void checkPropertyAccess(String key) {
+ }
+ }
+
+ /**
+ * Internal exception to boucne us out of the print code
+ */
+ class Printing extends RuntimeException {
+ }
+
+ public static void main(String argv[]) {
+
+ System.out.println( "-----------------------------------------------------------------------");
+ System.out.println( "INSTRUCTIONS: You should have a printer configured in your system to do this test. Test fails if you get this error message:");
+ System.out.println(" \"Regression: printing causes a NullPointerException\"");
+ System.out.println( "-----------------------------------------------------------------------");
+
+ if (argv.length > 0 && argv[0].equals("-v")) {
+ verbose = true;
+ }
+
+ // We need to make sure AWT is initialized. This is bug #4162674
+ java.awt.Toolkit.getDefaultToolkit();
+
+ // Try to install our own security manager.
+ try {
+ SecurityManager sm = new PrintLover();
+ println("Installing PrintLover security manager");
+ System.setSecurityManager(sm);
+ println("Installed security manager OK");
+
+ } catch (Throwable th) {
+ System.err.println("Failed to install SecurityManager");
+ th.printStackTrace();
+ throw new RuntimeException("Failed to install SecurityManager");
+ }
+
+ try {
+ println("calling getPrinterJob");
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if ((pj == null) || (pj.getPrintService() == null)){
+ return;
+ }
+
+ println("PrinterJob class is " + pj.getClass());
+ println("calling pj.setPrintable");
+ pj.setPrintable(new CheckPrivilege());
+ println("calling pj.print");
+ pj.print();
+ println("done pj.print");
+
+ } catch (Printing ex) {
+ // We get here if the print request started OK.
+ println("Caught \"Printing\" exception OK");
+
+ } catch (PrinterException ex) {
+ System.err.println("Caught " + ex);
+ throw new RuntimeException("" + ex);
+
+ } catch (NullPointerException ex) {
+ // This is the bug:
+ System.err.println("Caught " + ex);
+ System.err.println("Regression: printing causes a NullPointerException");
+ throw ex;
+ }
+
+ //System.exit(0);
+
+ }
+
+ // Back-call from the new print APIs.
+ // We always say we have bothing to print.
+ public int print(java.awt.Graphics g, PageFormat pf, int index) {
+ println("Started printing " + index);
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CompareImageable.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4748055
+ @summary PASS if the values are same in both cases (2 and 3) below.
+ @run main/manual CompareImageable
+*/
+
+/********************************************************************
+Testcase for comparing the imageable width and height of the paper
+with and without using print dialog.
+
+How to run:
+
+1. Launch the app. You'll find a checkbox and a print button.
+2. Click on the print button with the checkbox unselected. Note the
+imageable width and height displayed on the console
+3. Click on the print button with the checkbox selected. This popus up
+the print dialog. Click ok on the dialog. Note the imageable width and
+height displayed on the console.
+
+Result: It's a PASS if the values are same in both cases (2 and 3),
+ otherwise not.
+
+*********************************************************************/
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.awt.print.*;
+
+
+public class CompareImageable implements Printable {
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ //get the printable width and height of the paper.
+ int pageHeight = (int)pgFmt.getImageableHeight();
+ int pageWidth = (int)pgFmt.getImageableWidth();
+
+ System.out.println("imageable width = " + pageWidth + " height = " + pageHeight);
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+ public static void main(String [] args) {
+
+ final JFrame frame = new JFrame("Print Test");
+ final JButton printBtn = new JButton("Print");
+ final JCheckBox dialogBtn = new JCheckBox("Native dialog");
+
+ JPanel panel = new JPanel(new FlowLayout());
+ panel.add(dialogBtn);
+ panel.add(printBtn);
+ frame.getContentPane().add(panel);
+
+ printBtn.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+
+ CompareImageable test = new CompareImageable();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (dialogBtn.isSelected() && !pj.printDialog()) {
+ //user clicked 'Cancel' button in the print dialog. No printing.
+ return;
+ }
+
+ if (dialogBtn.isSelected()) {
+ System.out.println("With print dialog...");
+ } else {
+ System.out.println("Without print dialog...");
+ }
+
+ if (pj == null) {
+ System.out.println("No printer job found...");
+ return;
+ }
+ pj.setPrintable(test);
+
+ try {
+ pj.print();
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+
+
+ frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
+ frame.setSize(400, 400);
+ frame.setVisible(true);
+
+ }
+}
Binary file jdk/test/java/awt/print/PrinterJob/CustomFont/A.ttf has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CustomFont/CustomFont.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4386025
+ @summary fonts not in win32 font directory print incorrectly.
+ @author prr: area=PrinterJob
+ @run main/manual CustomFont
+*/
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+
+public class CustomFont implements Printable {
+
+ private Image opaqueimg,transimg;
+
+ private static void init() {
+
+ //*** Create instructions for the user here ***
+
+ String[] instructions = {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is a printed page.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print a page on which one line of text will be",
+ "printed: a long string of 'A' characters.",
+ "The A should have of a curly style",
+ "If instead its in the default sansserif font, the test fails",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ PageFormat portrait = pjob.defaultPage();
+ book.append(new CustomFont(),portrait);
+
+ pjob.setPageable(book);
+
+ if (pjob.printDialog()) {
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ System.err.println(e);
+ e.printStackTrace();
+ }
+ }
+ System.out.println("Done Printing");
+
+ }//End init()
+
+
+ Font customFont;
+ public CustomFont() {
+ try {
+ FileInputStream fin = new FileInputStream("A.ttf");
+ Font cf = Font.createFont(Font.TRUETYPE_FONT, fin);
+ customFont = cf.deriveFont(Font.PLAIN, 14);
+ } catch (Exception ioe) {
+ System.err.println(ioe.getMessage());
+ customFont = new Font("serif", Font.PLAIN, 14);
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ g2D.setColor(Color.black);
+ g2D.setFont(customFont);
+ String str = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ g.drawString(str, 100, 100);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ /**
+ * The graphics is scaled and the font and the positions
+ * are reduced in respect to the scaling, so that all
+ * printing should be the same.
+ *
+ * @param g2D graphics2D to paint on
+ * @param font font to paint
+ * @param scale scale for the painting
+ * @param x x position
+ * @param y y position
+ */
+ private void printScale(Graphics2D g2D, Font font,
+ float scale, float x, float y) {
+
+ int RES = 72;
+
+ g2D.scale(scale, scale);
+
+ g2D.setFont (font.deriveFont(10.0f / scale));
+ g2D.drawString("This text is scaled by a factor of " + scale,
+ x * RES / scale, y * RES / scale);
+
+ g2D.scale(1/scale, 1/scale);
+
+}
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, s fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+}// class CustomFont
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //CustomFont
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ CustomFont.pass();
+ }
+ else
+ {
+ CustomFont.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DeviceScale.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test 1.2 02/05/15
+ @bug 4810363 4924441
+ @run main DeviceScale
+ @summary check the peek scale is the same as the device scale, and that the
+ clips are also the same
+*/
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class DeviceScale implements Printable {
+
+ boolean firstTime = true;
+ double sx, sy;
+ Shape clip, firstClip;
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2 = (Graphics2D)g;
+ if (pageIndex>=1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ AffineTransform at = g2.getTransform();
+ System.out.println(at);
+ clip = g2.getClip();
+ System.out.println(clip);
+ if (firstTime) {
+ firstTime = false;
+ sx = Math.abs(at.getScaleX());
+ sy = Math.abs(at.getScaleY());
+ firstClip = clip;
+ } else {
+ double newSx = Math.abs(at.getScaleX());
+ double newSy = Math.abs(at.getScaleY());
+ if (Math.abs(sx - newSx) > 0.1 ||
+ Math.abs(sy - newSy) > 0.1) {
+ throw new RuntimeException("different scale, was "+
+ sx+","+sy+" now " +
+ newSx+","+ newSy);
+ }
+ if (!clip.equals(firstClip)) {
+ throw new RuntimeException("different clip, was "+ firstClip +
+ " now "+ clip);
+ }
+ }
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void doit(OrientationRequested o) throws Exception {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj.getPrintService() == null) {
+ System.out.println("No print service found.");
+ return;
+ }
+ pj.setPrintable(new DeviceScale());
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ aset.add(o);
+ String fileName = "out.prn";
+ File f = new File(fileName);
+ f.deleteOnExit();
+ URI dest = f.toURI();
+ aset.add(new Destination(dest));
+ pj.print(aset);
+ }
+
+
+ public static void main(String arg[]) throws Exception {
+
+ doit(OrientationRequested.PORTRAIT);
+ doit(OrientationRequested.LANDSCAPE);
+ doit(OrientationRequested.REVERSE_LANDSCAPE);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DrawImage.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4329866
+ * @summary Confirm that no printing exception is generated.
+ * @author jgodinez
+ * @run main/manual DrawImage
+ */
+
+import java.util.*;
+import java.text.*;
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.image.renderable.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+
+public class DrawImage
+{
+ protected static final double _hwBorder = 72 / 4; // 1/4 inch
+ protected static final double _border = 72 / 4; // 1/4 inch
+ protected static final int _objectBorder = 15;
+ protected static final int _verticalGap = 20;
+ protected static final int _textIndent = 150;
+
+ protected BufferedImage _image;
+
+ protected PageFormat _pageFormat;
+
+ public DrawImage(BufferedImage image) {
+ _image = image;
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ _pageFormat = pj.defaultPage();
+
+ }
+
+
+ protected int printImage(Graphics g, PageFormat pf, BufferedImage image) {
+ Graphics2D g2D = (Graphics2D)g;
+ g2D.transform(new AffineTransform(_pageFormat.getMatrix()));
+
+ int paperW = (int)pf.getImageableWidth(), paperH =
+ (int)pf.getImageableHeight();
+
+ int x = (int)pf.getImageableX(), y = (int)pf.getImageableY();
+ g2D.setClip(x, y, paperW, paperH);
+
+ // print images
+ if (image != null ) {
+ int imageH = image.getHeight(), imageW = image.getWidth();
+ // make slightly smaller (25) than max possible width
+ float scaleFactor = ((float)((paperW - 25) - _objectBorder -
+ _objectBorder) / (float)(imageW));
+ int scaledW = (int)(imageW * scaleFactor),
+ scaledH = (int)(imageH *scaleFactor);
+ BufferedImageOp scaleOp = new RescaleOp(scaleFactor, 0, null);
+ g2D.drawImage(image, scaleOp, x + _objectBorder, y + _objectBorder);
+ y += _objectBorder + scaledH + _objectBorder;
+ return Printable.PAGE_EXISTS;
+ }
+ else {
+ return Printable.NO_SUCH_PAGE;
+ }
+ }
+
+ public void print() {
+ try {
+ final PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setJobName("Print Image");
+ pj.setPrintable(new Printable() {
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ int result = NO_SUCH_PAGE;
+ if (pageIndex == 0) {
+ result = printImage(g, _pageFormat, _image);
+ }
+ return result;
+ }
+ });
+ if (pj.printDialog()) {
+ try { pj.print(); }
+ catch (PrinterException e) {
+ System.out.println(e);
+ }
+ }
+
+ }
+ catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public static void main(String[] args) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test.",
+ "The test passes if you get a printout of a gray rectangle",
+ "with white text without any exception."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ BufferedImage image = prepareFrontImage();
+ DrawImage pt = new DrawImage(image);
+ pt.print();
+ // System.exit(0);
+ }
+
+
+
+ public static BufferedImage prepareFrontImage() {
+ // build my own test images
+ BufferedImage result = new BufferedImage(400, 200,
+ BufferedImage.TYPE_BYTE_GRAY);
+
+ Graphics2D g2D = (Graphics2D)result.getGraphics();
+ g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF);
+ int w = result.getWidth(), h = result.getHeight();
+
+ g2D.setColor(Color.gray);
+ g2D.fill(new Rectangle(0, 0, w, h));
+
+ g2D.setColor(Color.white);
+
+ AffineTransform original = g2D.getTransform();
+ AffineTransform originXform = AffineTransform.getTranslateInstance(w /
+5, h / 5);
+ g2D.transform(originXform);
+
+
+ g2D.drawString("Front Side", 20, h / 2);
+
+ return result;
+ }
+
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DrawStringMethods.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4185019
+ * @summary Confirm that all of the drawString methods on Graphics2D
+ * work for printer graphics objects.
+ * @run main/manual DrawStringMethods
+ */
+
+import java.awt.*;
+import java.text.*;
+import java.awt.font.*;
+import java.awt.print.*;
+
+public class DrawStringMethods implements Printable {
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "Confirm that the methods are printed.",
+ " For Graphics: drawString, drawString, drawChars, drawBytes",
+ " For Graphics2D: drawString, drawString, drawGlyphVector"
+ };
+ Sysout.createDialogWithInstructions( instructions );
+
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat pf = pjob.defaultPage();
+ Book book = new Book();
+
+ book.append(new DrawStringMethods(), pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public static AttributedCharacterIterator getIterator(String s) {
+ return new AttributedString(s).getIterator();
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ int ix = (int) pf.getImageableX();
+ int iy = (int) pf.getImageableY();
+ String s;
+
+ g.setColor(Color.black);
+
+ iy += 50;
+ s = "--- Graphics methods: ---";
+ g.drawString(s, ix, iy);
+
+ iy += 30;
+ s = "drawString(String str, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawString(s, ix+20, iy);
+
+ iy += 30;
+ s = "drawString(AttributedCharacterIterator iterator, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawString(getIterator(s), ix+20, iy);
+
+ iy += 30;
+ s = "drawChars(char data[], int offset, int length, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawChars(s.toCharArray(), 0, s.length(), ix+20, iy);
+
+ iy += 30;
+ s = "drawBytes(byte data[], int offset, int length, int x, int y)";
+ byte data[] = new byte[s.length()];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) s.charAt(i);
+ }
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawBytes(data, 0, data.length, ix+20, iy);
+
+ iy += 50;
+ s = "--- Graphics2D methods: ---";
+ g.drawString(s, ix, iy);
+
+ if (g instanceof Graphics2D) {
+ Graphics2D g2d = (Graphics2D) g;
+ Font f = g2d.getFont();
+ FontRenderContext frc = g2d.getFontRenderContext();
+
+ iy += 30;
+ s = "drawString(String s, float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawString(s, (float) ix+20, (float) iy);
+
+ iy += 30;
+ s = "drawString(AttributedCharacterIterator iterator, "+
+ "float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawString(getIterator(s), (float) ix+20, (float) iy);
+
+ iy += 30;
+ s = "drawGlyphVector(GlyphVector g, float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawGlyphVector(f.createGlyphVector(frc, s), ix+20, iy);
+ } else {
+ iy += 30;
+ s = "Graphics object does not support Graphics2D methods";
+ g.drawString(s, ix+20, iy);
+ }
+
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/EmptyFill.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4509958
+ * @summary Tests that the empty areas aren't drawn.
+ * @run main EmptyFill
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class EmptyFill implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+
+ int[] xq = { 75, 125, 75 };
+ int[] yq = { 140, 140, 140};
+
+ g.fillPolygon( xq, yq, 3 );
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new EmptyFill());
+ pj.print();
+
+ String outStr = baos.toString("ISO-8859-1");
+ if (outStr.indexOf("\nfill\n") > 0) {
+ throw new Exception("Expected no fills");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/GlyphPositions.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6186840 6324057
+ * @summary Tests that explicitly positioned glyphs print correctly.
+ * @run main GlyphPositions
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class GlyphPositions implements Printable {
+
+ static String testString = "0123456789";
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+ float x = (float)pf.getImageableX() + 20f,
+ y = (float)pf.getImageableY() + 30f;
+
+ Graphics2D g2 = (Graphics2D)g;
+ Font font = new Font("SansSerif", Font.PLAIN, 20);
+ FontRenderContext frc = g2.getFontRenderContext();
+ GlyphVector v = font.createGlyphVector(frc, testString);
+
+ for(int i = 0; i <= v.getNumGlyphs(); i++)
+ {
+ Point2D.Float p = new Point2D.Float();
+ p.x = i * 40f;
+ p.y = 0;
+ v.setGlyphPosition(i, p);
+ }
+
+ g2.drawGlyphVector(v, x, y);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new GlyphPositions());
+ pj.print();
+
+ /* Expect to see that the 10 glyphs are drawn individually which
+ * because of their positions.
+ * This test will need to be updated if the postscript generation
+ * changes.
+ */
+ String outStr = baos.toString("ISO-8859-1");
+ String ls = System.getProperty("line.separator");
+ int indexCount = 0;
+ int index = 0;
+ while (index >= 0) {
+ index = outStr.indexOf("20.0 12 F"+ls, index+1);
+ if (index > 0) indexCount++;
+ }
+ if (indexCount < testString.length()) {
+ throw new Exception("Positions not used");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/HeadlessPrintingTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4936867
+ * @summary Printing crashes in headless mode.
+ * @run main/othervm HeadlessPrintingTest
+ */
+
+
+import java.awt.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import java.awt.print.*;
+import java.io.*;
+
+public class HeadlessPrintingTest {
+
+ public static void main(String[] args) {
+ System.setProperty("java.awt.headless", "true");
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setPrintable(new Printable() {
+ public int print(Graphics g, PageFormat pg, int pageIndex) {
+ Graphics2D g2d = (Graphics2D)g;
+ if (pageIndex > 2) {
+ return Printable.NO_SUCH_PAGE;
+ } else {
+ g2d.translate(pg.getImageableX(), pg.getImageableY());
+ g2d.setColor(Color.RED);
+ g2d.drawString("page " + pageIndex, 100, 100);
+ return Printable.PAGE_EXISTS;
+ }
+ }
+ });
+
+ try {
+ HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
+ File f = File.createTempFile("out", "ps");
+ f.deleteOnExit();
+ Destination dest = new Destination(f.toURI());
+ attr.add(dest);
+ pj.print(attr);
+ } catch (Exception e) {
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/InitToBlack.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @bug 4184565
+ * @summary Confirm that the default foreground color on a printer
+ * graphics object is black so that rendering will appear
+ * without having to execute setColor first.
+ * @run applet/manual=yesno InitToBlack.html
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.applet.Applet;
+
+public class InitToBlack extends Applet implements Printable {
+
+ public void init() {
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+ book.append(this, pjob.defaultPage());
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+
+ g.drawString("Test Passes", 200, 200);
+
+ return PAGE_EXISTS;
+ }
+
+ public static void main(String[] args) {
+ new InitToBlack().init();
+ System.exit(0);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/InvalidPage.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test InvalidPage.java
+ * @bug 4671634 6506286
+ * @summary Invalid page format can crash win32 JRE
+ * @author prr
+ * @run main/manual InvalidPage
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class InvalidPage extends Frame implements Printable {
+
+ PrinterJob pJob;
+ PageFormat pf;
+
+ public InvalidPage() {
+ super ("Validate Page Test");
+ pJob = PrinterJob.getPrinterJob();
+ pf = pJob.defaultPage();
+ Paper p = pf.getPaper();
+ p.setImageableArea(0,0,p.getWidth(), p.getHeight());
+ pf.setPaper(p);
+ setLayout(new FlowLayout());
+ Panel panel = new Panel();
+ Button printButton = new Button ("Print");
+ printButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (pJob.printDialog()) {
+ pJob.setPrintable(InvalidPage.this, pf);
+ pJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ panel.add (printButton);
+ add(panel);
+
+ addWindowListener (new WindowAdapter() {
+ public void windowClosing (WindowEvent e) {
+ dispose();
+ System.exit (0);
+ }
+
+ });
+ setSize (200, 200);
+ setVisible (true);
+ }
+
+ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
+
+ if (pageIndex > 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D)graphics;
+
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+ g2d.drawString("ORIGIN", 30, 30);
+ g2d.drawString("X THIS WAY", 200, 50);
+ g2d.drawString("Y THIS WAY", 60 , 200);
+ g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ if (pageIndex == 0) {
+ g2d.setColor(Color.black);
+ } else {
+ g2d.setColor(new Color(0,0,0,128));
+ }
+ g2d.drawRect(1,1,(int)pageFormat.getImageableWidth()-2,
+ (int)pageFormat.getImageableHeight()-2);
+
+ g2d.drawLine(0,0,
+ (int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ g2d.drawLine((int)pageFormat.getImageableWidth(),0,
+ 0,(int)pageFormat.getImageableHeight());
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main( String[] args) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "Press the print button, which brings up a print dialog and",
+ "in the dialog select a printer and press the print button",
+ "in the dialog. Repeat for as many printers as you have installed",
+ "On solaris and linux just one printer is sufficient",
+ "Collect the output and examine it, each print job has two pages",
+ "of very similar output, except that the 2nd page of the job may",
+ "appear in a different colour, and the output near the edge of",
+ "the page may be clipped. This is OK. Hold up both pieces of paper",
+ "to the light and confirm that the lines and text (where present)",
+ "are positioned identically on both pages",
+ "The test fails if the JRE crashes, or if the output from the two",
+ "pages of a job is aligned differently"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new InvalidPage();
+ }
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/JobName/PrinterJobName.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4205601
+ * @summary setJobName should be used by PrinterJob
+ * @author prr
+ * @run main/manual PrinterJobName
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class PrinterJobName implements Printable {
+
+
+ static String theName = "Testing the Jobname setting";
+
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test prints a page with a banner/job name of",
+ theName
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setJobName(theName);
+ job.setPrintable(new PrinterJobName());
+ try {
+ job.print();
+ System.out.println("PRINTING DONE.");
+ }
+ catch (Exception exc) {
+ System.out.println("Printer Exception");
+ }
+ }
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0 ) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ g2d.drawString("Name is: "+theName,20,20 );
+ return Printable.PAGE_EXISTS;
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/Legal/PrintTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4886069 8023045
+ * @summary Confirm that printer recognizes the Legal selection either by
+ * prompting the user to put Legal paper or automatically selecting
+ * the tray containing Legal Paper. The printout image should not
+ * be shifted up by about 3".
+ * @run main/manual PrintTest
+ *
+ */
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import java.io.*;
+
+
+public class PrintTest extends JFrame {
+ private JPanel contentPane;
+ private JMenuBar jMenuBar1 = new JMenuBar();
+ private JMenu jMenuFile = new JMenu();
+ private JMenuItem jMenuItem1 = new JMenuItem();
+ private BorderLayout borderLayout1 = new BorderLayout();
+ private JPanel jPanel1 = new JPanel();
+ private BorderLayout borderLayout2 = new BorderLayout();
+ private JScrollPane jScrollPane1 = new JScrollPane();
+ private JTextArea jTextArea1 = new JTextArea();
+ private Border border1;
+
+ //Construct the frame
+ public PrintTest() {
+ enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+ try {
+ jbInit();
+
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ private void jbInit() throws Exception {
+ contentPane = (JPanel) this.getContentPane();
+ border1 = BorderFactory.createLineBorder(Color.black,1);
+ contentPane.setLayout(borderLayout1);
+ this.setTitle("Print Test");
+ jMenuFile.setText("File");
+ jMenuItem1.setText("Print");
+ jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(80, java.awt.event.KeyEvent.CTRL_MASK, false));
+ jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ jMenuItem1_actionPerformed(e);
+ }
+ });
+ jPanel1.setLayout(borderLayout2);
+ jTextArea1.setBorder(border1);
+ jTextArea1.setText("1. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "2. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "3. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "4. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "5. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "6. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "7. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "8. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "9. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "10. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "11. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "12. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "13. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "14. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "15. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "16. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "17. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "18. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "19. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "20. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "21. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "22. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "23. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "24. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "25. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "26. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "27. This is a printer test designed to illustrate a bug in the java printing API.");
+ jMenuFile.add(jMenuItem1);
+ contentPane.add(jPanel1, BorderLayout.CENTER);
+ jPanel1.add(jScrollPane1, BorderLayout.CENTER);
+ jScrollPane1.getViewport().add(jTextArea1, null);
+ jScrollPane1.setPreferredSize(new Dimension(468,648));
+ jTextArea1.setPreferredSize(new Dimension(468,864));
+ jMenuBar1.add(jMenuFile);
+ this.setJMenuBar(jMenuBar1);
+ }
+
+ protected void processWindowEvent(WindowEvent e) {
+ super.processWindowEvent(e);
+ if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+ System.exit(0);
+ }
+ }
+
+ void jMenuItem1_actionPerformed(ActionEvent e) {
+ PrintUtils.printComponent(jTextArea1);
+ }
+
+
+
+
+ public static class PrintUtils implements Printable {
+ private JComponent componentToBePrinted;
+ protected double scale =1.0;
+ PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
+
+
+ public static void printComponent(JComponent c) {
+ new PrintUtils(c).print();
+ }
+
+ public PrintUtils(JComponent componentToBePrinted) {
+ this.componentToBePrinted = componentToBePrinted;
+
+ }
+
+ void print() {
+ DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
+ pras.add(MediaSizeName.NA_LEGAL);
+
+ PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor,pras);
+ PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
+ if ((defaultService == null) || (printService.length == 0)) {
+ System.out.println("No default print service found. Test aborted.");
+ return;
+ }
+
+ PrintService service = ServiceUI.printDialog(null,100,100,printService,defaultService,flavor,pras);
+
+ if(service != null) {
+ DocPrintJob job = service.createPrintJob();
+ DocAttributeSet das = new HashDocAttributeSet();
+
+ Doc doc = new SimpleDoc(this,flavor,das);
+
+ try {
+ job.print(doc,pras);
+
+ } catch(PrintException pe) {
+ pe.printStackTrace();
+ }
+ }
+
+ }
+
+
+ public int print(Graphics g, PageFormat pageFormat, int pageIndex)
+ {
+
+ double h=componentToBePrinted.getHeight();
+ double pageHeight=pageFormat.getImageableHeight();
+
+ if (pageIndex * pageHeight > h * scale) {
+ return(NO_SUCH_PAGE);
+ } else {
+
+ Graphics2D g2d = (Graphics2D)g;
+
+ //move past unprintable area
+ double xOffset=pageFormat.getImageableX();
+ double yOffset=pageFormat.getImageableY();
+ g2d.translate(xOffset,yOffset);
+
+
+ //move to correct page taking into account the scaling
+ double newx=0;
+ double newy=pageHeight*(-pageIndex);
+ g2d.translate(newx / 1.0,newy / 1.0 );
+
+ //print
+
+ componentToBePrinted.print(g2d);
+ return(PAGE_EXISTS);
+ }
+ }
+
+ public static void disableDoubleBuffering(Component c) {
+ RepaintManager currentManager = RepaintManager.currentManager(c);
+ currentManager.setDoubleBufferingEnabled(false);
+ }
+
+ /** Re-enables double buffering globally. */
+
+ public static void enableDoubleBuffering(Component c) {
+ RepaintManager currentManager = RepaintManager.currentManager(c);
+ currentManager.setDoubleBufferingEnabled(true);
+ }
+}
+
+ public static void main(String[] args) {
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ PrintTest frame = new PrintTest();
+ frame.pack();
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Dimension frameSize = frame.getSize();
+ if (frameSize.height > screenSize.height) {
+ frameSize.height = screenSize.height;
+ }
+ if (frameSize.width > screenSize.width) {
+ frameSize.width = screenSize.width;
+ }
+ frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
+ frame.setVisible(true);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/MultiThread/MultiThreadTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4922036
+ * @summary Confirm that no Exception is thrown and 2 identical output is produced.
+ * @run main/manual MultiThreadTest
+ */
+import java.io.*;
+import javax.print.*;
+
+
+public class MultiThreadTest extends Thread {
+
+ private PrintService service = PrintServiceLookup.lookupDefaultPrintService();
+ private Doc doc = null;
+
+ public MultiThreadTest(Doc docObject) {
+ this.doc = docObject;
+ }
+
+ public void print() {
+ try {
+ DocPrintJob job = null;
+
+ job = this.service.createPrintJob();
+ if (job == null) {
+ System.out.println("Fail: DocPrintJob is null...");
+ return;
+ }
+ System.out.println("About to print image...");
+
+ job.print(this.doc, null);
+ System.out.println("Image printed.");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void run() {
+ this.print();
+ }
+
+ public static void main(String args[]) {
+ if (args.length <= 0) {
+ System.out.println("Usage: java MultiThreadTest <img file>");
+ return;
+ }
+ Object printData = null;
+
+ try {
+ File file = new File(args[0]);
+
+ printData = new byte[(int) file.length()];
+ FileInputStream in = new FileInputStream(file);
+
+ in.read((byte[]) printData);
+ in.close();
+ } catch (FileNotFoundException fe) {
+ System.out.println("ByteDoc: FileNotFoundException: "
+ + fe.toString());
+
+ } catch (IOException ie) {
+ System.out.println("ByteDoc: IOException: " + ie.toString());
+ }
+ Doc doc1 = new ByteDoc(printData, DocFlavor.BYTE_ARRAY.GIF);
+ Doc doc2 = new ByteDoc(printData, DocFlavor.BYTE_ARRAY.GIF);
+
+ Thread thread1 = new MultiThreadTest(doc1);
+ Thread thread2 = new MultiThreadTest(doc2);
+
+ thread1.start();
+ thread2.start();
+ }
+}
+
+
+class ByteDoc implements Doc {
+
+ protected DocFlavor flavor = null;
+ protected Object printData = null;
+ protected InputStream instream = null;
+ protected FileReader reader = null;
+
+ // constructor takes the resource file and the document flavor.
+ public ByteDoc(Object printdata, DocFlavor docFlavor) {
+ this.printData = printdata;
+ this.flavor = docFlavor;
+ }
+
+ public javax.print.attribute.DocAttributeSet getAttributes() {
+ return null;
+ }
+
+ public DocFlavor getDocFlavor() {
+ return this.flavor;
+ }
+
+ public Object getPrintData() {
+ return this.printData;
+ }
+
+ public Reader getReaderForText() {
+ // Document says that if MIME type is non-text and representation class is input stream
+ // then return null;
+ return null;
+ }
+
+ public InputStream getStreamForBytes() {
+ synchronized (this) {
+ if ((this.instream == null) && (this.printData instanceof byte[])) {
+ // its a byte array so create a ByteArrayInputStream.
+ System.out.println("creating ByteArrayInputStream...");
+ this.instream = new ByteArrayInputStream((byte[]) printData);
+ }
+ }
+ return this.instream;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/NullGetName.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 6397684
+ @summary PASS if no VM crash.
+ @run main NullGetName
+*/
+
+
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.event.*;
+import java.awt.print.*;
+
+
+public class NullGetName {
+
+ public static void main(String[] args) {
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ try {
+ printerJob.setPrintService(new ImagePrintService());
+ } catch (PrinterException e) {
+ }
+ }
+}
+
+
+class ImagePrintService implements PrintService {
+
+
+ public Class[] getSupportedAttributeCategories() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAttributeCategorySupported(Class category) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DocFlavor[] getSupportedDocFlavors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public boolean isDocFlavorSupported(DocFlavor flavor) {
+ if(DocFlavor.SERVICE_FORMATTED.PAGEABLE.equals(flavor))
+ return true;
+ if(DocFlavor.SERVICE_FORMATTED.PRINTABLE.equals(flavor))
+ return true;
+ return false;
+ }
+
+ public DocPrintJob createPrintJob() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ServiceUIFactory getServiceUIFactory() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public PrintServiceAttributeSet getAttributes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void addPrintServiceAttributeListener(
+ PrintServiceAttributeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removePrintServiceAttributeListener(
+ PrintServiceAttributeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object getDefaultAttributeValue(Class category) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends PrintServiceAttribute> T
+ getAttribute(Class<T> category) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAttributeValueSupported(Attribute attrval,
+ DocFlavor flavor, AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
+ AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
+ AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/NumCopies.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4258003
+ * @summary Checks the right number of copies are printed
+ * @author prr
+ * @run main/manual NumCopies
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class NumCopies implements Printable {
+
+
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a total of four pages which are two",
+ " copies of each of two pages which consist of the text :-",
+ "'This is page number N', where N is 0 and 1.",
+ "The pages should be uncollated."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setCopies(2);
+ job.setPrintable(new NumCopies());
+ try {
+ job.print();
+ }
+ catch (Exception exc) {
+ System.out.println("Printer Exception");
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex)
+ throws PrinterException {
+
+ if (pageIndex > 1) {
+ return NO_SUCH_PAGE;
+ }
+ g.translate((int)pf.getImageableX(), (int)pf.getImageableY());
+ g.setColor(Color.black);
+ g.drawString("This is page number " + Integer.toString(pageIndex), 50, 50);
+ return PAGE_EXISTS ;
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PSQuestionMark.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6217355 6324057
+ * @summary Tests that '?' prints with postscript fonts
+ * @run main PSQuestionMark
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class PSQuestionMark implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+ g.setFont(new Font("Serif", Font.PLAIN, 12));
+ g.drawString("?", 100, 150);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ //FileOutputStream baos = new FileOutputStream("q.ps");
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new PSQuestionMark());
+ pj.print();
+ //baos.close();
+
+ /* Expect to see the PS we generate for setting 12 pt Times Roman
+ * and the hex value of '?'
+ * "12.0 12 F"
+ * "<3f> 6.72 100.0 150.0 S"
+ * This test will need to be updated if the postscript generation
+ * changes.
+ */
+ String outStr = baos.toString("ISO-8859-1");
+ String ls = System.getProperty("line.separator");
+ if (outStr.indexOf("12.0 32 F"+ls+"<3f>") < 0) {
+ throw new Exception("PS font not used");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PSWindingRule.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4423489
+ * @summary Tests that the postscript renders using the appropriate
+ * winding rule. Runs as "main" as can't run in sandbox.
+ * @run main PSWindingRule
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class PSWindingRule implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2 = (Graphics2D)g;
+
+ GeneralPath path1 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ GeneralPath path2 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ GeneralPath path3 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ path1.append(new Ellipse2D.Double(100, 100, 100, 100), false);
+ path1.append(new Ellipse2D.Double(120, 120, 60, 60), false);
+ path1.append(new Ellipse2D.Double(140, 140, 20, 20), false);
+
+ path2.append(new Ellipse2D.Double(150, 100, 100, 100), false);
+ path2.append(new Ellipse2D.Double(170, 120, 60, 60), false);
+ path2.append(new Ellipse2D.Double(190, 140, 20, 20), false);
+
+ path3.append(new Ellipse2D.Double(-50, -50, 100, 100), false);
+ path3.append(new Ellipse2D.Double(-30, -30, 60, 60), false);
+ path3.append(new Ellipse2D.Double(-10, -10, 20, 20), false);
+
+ Rectangle clip = new Rectangle();
+ g2.getClipBounds(clip);
+
+ g2.setColor(Color.white);
+ g2.fillRect(clip.x, clip.y, clip.width, clip.height);
+
+ g2.setColor(Color.red);
+ g2.fill(path1);
+
+ g2.setColor(Color.black);
+ g2.fill(path2);
+
+ g2.translate(150, 400);
+ g2.setColor(Color.red);
+ g2.fill(path3);
+
+ g2.translate(50, 0);
+ g2.setColor(Color.black);
+ g2.fill(path3);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new PSWindingRule());
+ pj.print();
+
+ String outStr = baos.toString("ISO-8859-1");
+ int eofillCnt = 0;
+ int index = 0;
+ String ls = System.getProperty ("line.separator");
+
+ while (index >= 0) {
+ index = outStr.indexOf(ls+"EF"+ls, index+1);
+ if (index >=0 ) {
+ eofillCnt++;
+ }
+ }
+ if (eofillCnt != 4) {
+ throw new Exception("Expected 4 eofill's, got: " + eofillCnt);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PageDialogTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ @bug 6302514
+ @run main/manual=yesno PageDialogTest
+ @summary A toolkit modal dialog should not be blocked by Page/Print dialog.
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+import javax.swing.*;
+
+public class PageDialogTest {
+
+ public static void main(String[] args) {
+ String[] instructions =
+ {
+ "The test shows a Toolkit modal dialog. ",
+ "Click the 'Open' button. It opens a page dialog.",
+ "The test fails if the page dialog blocks the toolkit",
+ "modal dialog, otherwise it passes."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ Dialog td = new Dialog((Frame) null, "Toolkit modal dialog",
+ Dialog.ModalityType.TOOLKIT_MODAL);
+ td.setLayout(new FlowLayout());
+ td.add(new Button("Dummy"));
+ Button tdb = new Button("Open");
+ tdb.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ PrinterJob.getPrinterJob().pageDialog(new PageFormat());
+ }
+ });
+ td.add(tdb);
+ td.setSize(250, 150);
+ td.setVisible(true);
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PageDlgPrnButton.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4956397
+ * @run main/manual PageDlgPrnButton
+ */
+
+import java.awt.print.PrinterJob;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.* ;
+
+public class PageDlgPrnButton implements Printable
+{
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {"For non-windows OS, this test PASSes.",
+ "You must have at least 2 printers available to perform this test.",
+ "This test brings up a native Windows page dialog.",
+ "Click on the Printer... button and change the selected printer. ",
+ "Test passes if the printout comes from the new selected printer.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PageDlgPrnButton pdpb = new PageDlgPrnButton() ;
+ }
+
+ public PageDlgPrnButton()
+ {
+ try
+ {
+ pageDialogExample();
+ }
+ catch(Exception e)
+ {e.printStackTrace(System.err);}
+ }
+
+
+ // This example just displays the page dialog - you cannot change
+ // the printer (press the "Printer..." button and choose one if you like).
+ public void pageDialogExample() throws PrinterException
+ {
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat originalPageFormat = job.defaultPage();
+ PageFormat pageFormat = job.pageDialog(originalPageFormat);
+
+ if(originalPageFormat == pageFormat) return;
+
+ job.setPrintable(this,pageFormat);
+ job.print();
+ }
+
+
+
+ public int print(Graphics g, PageFormat pageFormat, int pageIndex)
+ {
+ final int boxWidth = 100;
+ final int boxHeight = 100;
+ final Rectangle rect = new Rectangle(0,0,boxWidth,boxHeight);
+ final double pageH = pageFormat.getImageableHeight();
+ final double pageW = pageFormat.getImageableWidth();
+
+ if (pageIndex > 0) return (NO_SUCH_PAGE);
+
+ final Graphics2D g2d = (Graphics2D)g;
+
+ // Move the (x,y) origin to account for the left-hand and top margins
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+
+ // Draw the page bounding box
+ g2d.drawRect(0,0,(int)pageW,(int)pageH);
+
+ // Select the smaller scaling factor so that the figure
+ // fits on the page in both dimensions
+ final double scale = Math.min( (pageW/boxWidth), (pageH/boxHeight) );
+
+ if(scale < 1.0) g2d.scale(scale, scale);
+
+ // Paint the scaled component on the printer
+ g2d.fillRect(rect.x, rect.y, rect.width, rect.height);
+
+ return(PAGE_EXISTS);
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PaintText.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6498340
+ * @summary No exception when printing text with a paint.
+ * @run main PaintText
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.text.*;
+import java.util.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PaintText extends Component implements Printable {
+
+ static int preferredSize;
+ static int NUMTABS = 6;
+ int tabNumber;
+
+ public static void main(String args[]) {
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ if (pjob.getPrintService() == null) {
+ System.out.println("No printers: cannot continue");
+ return;
+ }
+
+ PageFormat pf = pjob.defaultPage();
+ preferredSize = (int)pf.getImageableWidth();
+
+ Book book = new Book();
+
+ JTabbedPane p = new JTabbedPane();
+
+ for (int id=1; id <= NUMTABS; id++) {
+ String name = "Tab " + new Integer(id);
+ PaintText ptt = new PaintText(id);
+ p.add(name, ptt);
+ book.append(ptt, pf);
+ }
+ pjob.setPageable(book);
+
+ JFrame f = new JFrame();
+ f.add(BorderLayout.CENTER, p);
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ f.pack();
+ f.show();
+
+ /* Non-jtreg execution will display the dialog */
+ if (System.getProperty("test.java") == null) {
+ if (!pjob.printDialog()) {
+ return;
+ }
+ }
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public PaintText(int id) {
+ tabNumber = id;
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ System.out.println(""+pageIndex);
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g.drawString("ID="+tabNumber,100,20);
+ g.translate(0, 25);
+ paint(g);
+ return PAGE_EXISTS;
+ }
+
+ public Dimension getMinimumSize() {
+ return getPreferredSize();
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(preferredSize, preferredSize);
+ }
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+ Graphics2D g2d = (Graphics2D)g;
+
+ Font f = new Font("Lucida Sans", Font.PLAIN, 40);
+ Color c = new Color(0,0,255,96);
+ Paint p = new GradientPaint(0f, 0f, Color.green,
+ 10f, 10f, Color.red,
+ true);
+ String s = "Sample Text To Paint";
+ float x = 20, y= 50;
+
+ switch (tabNumber) {
+ case 1:
+ g2d.setFont(f);
+ g2d.setColor(c);
+ g2d.drawString(s, x, y);
+ break;
+
+ case 2:
+ g2d.setFont(f);
+ g2d.setPaint(p);
+ g2d.drawString(s, x, y);
+ break;
+
+ case 3:
+ AttributedString as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, c);
+ g2d.drawString(as.getIterator(), x, y);
+ break;
+
+ case 4:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, p);
+ g2d.drawString(as.getIterator(), x, y);
+ break;
+
+ case 5:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, c);
+ FontRenderContext frc = g2d.getFontRenderContext();
+ TextLayout tl = new TextLayout(as.getIterator(), frc);
+ tl.draw(g2d, x, y);
+ break;
+
+ case 6:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, p);
+ frc = g2d.getFontRenderContext();
+ tl = new TextLayout(as.getIterator(), frc);
+ tl.draw(g2d, x, y);
+ break;
+
+ default:
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintAllFonts.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ *
+ * @bug 4884389 7183516
+ * @summary Font specified with face name loses style on printing
+ * @run main/manual PrintRotatedText
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.GraphicsEnvironment;
+
+public class PrintAllFonts implements Printable {
+
+ static Font[] allFonts;
+ int fontNum = 0;
+ int startNum = 0;
+ int lineHeight = 18;
+ boolean done = false;
+ int thisPage = 0;
+
+
+ public static void main(String[] args) throws Exception {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test and should use Win 98.",
+ "This bug is system dependent and is not always reproducible.",
+ " ",
+ "A passing test will have all text printed with correct font style.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ allFonts = ge.getAllFonts();
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setPrintable(new PrintAllFonts());
+ if (pj.printDialog()) {
+ pj.print();
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (fontNum >= allFonts.length && pageIndex > thisPage) {
+ return NO_SUCH_PAGE;
+ }
+ if (pageIndex > thisPage) {
+ startNum = fontNum;
+ thisPage = pageIndex;
+ } else {
+ fontNum = startNum;
+ }
+ g.setColor(Color.black);
+
+ int hgt = (int)pf.getImageableHeight();
+ int fontsPerPage = hgt/lineHeight;
+ int x = (int)pf.getImageableX()+10;
+ int y = (int)pf.getImageableY()+lineHeight;
+
+ for (int n = 0; n < fontsPerPage; n++) {
+ Font f = allFonts[fontNum].deriveFont(Font.PLAIN, 16);
+ g.setFont(f);
+ g.drawString(f.getFontName(), x, y);
+ y+= lineHeight;
+ fontNum++;
+ if (fontNum >= allFonts.length) {
+ break;
+ }
+ }
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintBadImage.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4398853
+ * @summary Printing shouldn't hang on bad images
+ * @author prr
+ * @run main/manual PrintBadImage
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+
+public class PrintBadImage implements Printable {
+
+ public static void main(String args[]) {
+
+ PrintBadImage pbi = new PrintBadImage();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj != null) {
+ pj.setPrintable(pbi);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ Image imgJava = Toolkit.getDefaultToolkit().getImage("img.bad");
+ g2d.drawImage(imgJava, 0, 0, null);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintCompoundString.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4396835
+ * @summary Compound font string not printing.
+ * @author prr
+ * @run main/manual PrintCompoundString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintCompoundString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text message as in the test window on the screen",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintCompoundString f = new PrintCompoundString();
+ f.show();
+ }
+
+ public PrintCompoundString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ String str = "Test string compound printing \u2203\u2200\u2211";
+ g.drawString(str, 20, 40);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintDialog.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test PrintDialog.java
+ @bug 4257903
+ @summary Confirm that the you see the print dialog.
+ @author prr: area=PrinterJob
+ @run main/manual PrintDialog
+*/
+
+
+//*** global search and replace PrintDialog with name of the test ***
+
+/**
+ * PrintDialog.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class PrintDialog {
+
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "Visual inspection of the dialog is needed. It should be",
+ "a Printer Job Setup Dialog",
+ "You may cancel or OK the dialog."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ pjob.printDialog();
+
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class PrintDialog
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ PrintDialog.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ PrintDialog.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //PrintDialog
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ PrintDialog.pass();
+ }
+ else
+ {
+ PrintDialog.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintDialogCancel.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,394 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4398231
+ @summary Confirm that the print dialog returns false when cancelled.
+ @author prr: area=PrinterJob
+ @run main/manual PrintDialogCancel
+*/
+
+
+//*** global search and replace PrintDialogCancel with name of the test ***
+
+/**
+ * PrintDialogCancel.java
+ *
+ * summary:
+ */
+
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class PrintDialogCancel {
+
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "Visual inspection of the dialog is needed. It should be",
+ "a Printer Job Setup Dialog",
+ "Do nothing except Cancel",
+ "You must NOT press OK",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ boolean rv = pjob.printDialog(new HashPrintRequestAttributeSet());
+ if (rv) {
+ throw new RuntimeException("User pressed cancel, but true returned");
+ }
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class PrintDialogCancel
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ PrintDialogCancel.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ PrintDialogCancel.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //PrintDialogCancel
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ PrintDialogCancel.pass();
+ }
+ else
+ {
+ PrintDialogCancel.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintFontStyle.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.GraphicsEnvironment;
+
+public class PrintFontStyle {
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test and should use Win 98.",
+ "This bug is system dependent and is not always reproducible.",
+ " ",
+ "A passing test will have all text printed with correct font style.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pj=PrinterJob.getPrinterJob();
+ pj.setPrintable(new FontPrintable());
+ if (pj.printDialog())
+ {
+ try { pj.print(); }
+ catch (PrinterException e) {
+ System.out.println(e);
+ }
+ }
+ }
+}
+
+class FontPrintable
+ implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ if (pageIndex != 0) return NO_SUCH_PAGE;
+ Graphics2D g2= (Graphics2D)g;
+
+ g2.setPaint(Color.black);
+
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ String[] fontList = ge.getAvailableFontFamilyNames();
+ g2.setFont (new Font ("Arial", Font.PLAIN, 20));
+ g2.drawString("Arial - Plain", 144, 120);
+ g2.setFont (new Font ("Arial", Font.BOLD, 20));
+ g2.drawString("Arial - Bold", 144, 145);
+ g2.setFont (new Font ("Arial", Font.ITALIC, 20));
+ g2.drawString("Arial - Italic", 144, 170);
+ g2.setFont (new Font ("Times New Roman", Font.PLAIN, 20));
+ g2.drawString("Times New Roman - Plain", 144, 195);
+ g2.setFont (new Font ("Times New Roman", Font.BOLD, 20));
+ g2.drawString("Times New Roman - Bold", 144, 220);
+ g2.setFont (new Font ("Times New Roman", Font.ITALIC, 20));
+ g2.drawString("Times New Roman - Italic", 144, 245);
+
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintImage.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test %I %W
+ * @bug 4298489
+ * @summary Confirm that output is same as screen.
+ * @author jgodinez
+ * @run main/manual PrintImage
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.event.*;
+
+public class PrintImage extends Frame implements ActionListener {
+
+ private PrintImageCanvas printImageCanvas;
+
+ private MenuItem print1Menu = new MenuItem("PrintTest1");
+ private MenuItem print2Menu = new MenuItem("PrintTest2");
+ private MenuItem exitMenu = new MenuItem("Exit");
+
+ public static void main(String[] argv) {
+ String[] instructions =
+ { "You must have a printer available to perform this test,",
+ "prefererably Canon LaserShot A309GII.",
+ "Printing must be done in Win 98 Japanese 2nd Edition.",
+ "",
+ "Passing test : Output of text image for PrintTest1 and PrintTest2 should be same as that on the screen.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new PrintImage();
+ }
+
+ public PrintImage() {
+ super("PrintImage");
+ initPrintImage();
+ }
+
+ public void initPrintImage() {
+
+ printImageCanvas = new PrintImageCanvas(this);
+
+ initMenu();
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent ev) {
+ dispose();
+ }
+ public void windowClosed(WindowEvent ev) {
+ System.exit(0);
+ }
+ });
+
+ setLayout(new BorderLayout());
+ add(printImageCanvas, BorderLayout.CENTER);
+ pack();
+
+ setSize(500,500);
+ setVisible(true);
+ }
+
+ private void initMenu() {
+ MenuBar mb = new MenuBar();
+ Menu me = new Menu("File");
+ me.add(print1Menu);
+ me.add(print2Menu);
+ me.add("-");
+ me.add(exitMenu);
+ mb.add(me);
+ this.setMenuBar(mb);
+
+ print1Menu.addActionListener(this);
+ print2Menu.addActionListener(this);
+ exitMenu.addActionListener(this);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ Object target = e.getSource();
+ if( target.equals(print1Menu) ) {
+ printMain1();
+ }
+ else if( target.equals(print2Menu) ) {
+ printMain2();
+ }
+ else if( target.equals(exitMenu) ) {
+ dispose();
+ }
+ }
+
+ private void printMain1(){
+
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ PageFormat pageFormat = printerJob.defaultPage();
+
+ printerJob.setPrintable((Printable)printImageCanvas, pageFormat);
+
+ if(printerJob.printDialog()){
+ try {
+ printerJob.print();
+ }
+ catch(PrinterException p){
+ }
+ }
+ else
+ printerJob.cancel();
+ }
+
+ private void printMain2(){
+
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ PageFormat pageFormat = printerJob.pageDialog(printerJob.defaultPage());
+
+ printerJob.setPrintable((Printable)printImageCanvas, pageFormat);
+
+ if(printerJob.printDialog()){
+ try {
+ printerJob.print();
+ }
+ catch(PrinterException p){
+ }
+ }
+ else
+ printerJob.cancel();
+ }
+
+}
+
+class PrintImageCanvas extends Canvas implements Printable {
+
+ private PrintImage pdsFrame;
+
+ public PrintImageCanvas(PrintImage pds) {
+ pdsFrame = pds;
+ }
+
+ public void paint(Graphics g) {
+ Font drawFont = new Font("MS Mincho",Font.ITALIC,50);
+ g.setFont(drawFont);
+ g.drawString("PrintSample!",100,150);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pi)
+ throws PrinterException {
+
+ if(pi>=1)
+ return NO_SUCH_PAGE;
+ else{
+ Graphics2D g2 = (Graphics2D)g;
+ g.setColor(new Color(0,0,0,200));
+
+ Font drawFont = new Font("MS Mincho",Font.ITALIC,50);
+ g.setFont(drawFont);
+ g.drawString("PrintSample!",100,150);
+ return PAGE_EXISTS;
+ }
+ }
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintNullString.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,328 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4223328
+ * @summary Printer graphics must behave the same as screen graphics
+ * @author prr
+ * @run main/manual PrintNullString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintNullString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text messages as in the test window on the screen",
+ "The messages should contain only 'OK' and 'expected' messages",
+ "There should be no FAILURE messages.",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If the page fails to print, but there were no exceptions",
+ "then the problem is likely elsewhere (ie your printer)"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintNullString f = new PrintNullString();
+ f.show();
+ }
+
+ public PrintNullString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ // API 1: null & empty drawString(String, int, int);
+ try {
+ g.drawString(nullStr, 20, 40);
+ g.drawString("FAILURE: No NPE for null String, int", 20, 40);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null String, int", 20, 40);
+ }/* catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null String, int",
+ 20, 40);
+ }*/
+
+ //try {
+ g.drawString(emptyStr, 20, 60);
+ g.drawString("OK for empty String, int", 20, 60);
+ /*} catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty String, int",
+ 20, 60);
+ }*/
+
+
+ // API 2: null & empty drawString(String, float, float);
+ try {
+ g.drawString(nullStr, 20.0f, 80.0f);
+ g.drawString("FAILURE: No NPE for null String, float", 20, 80);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null String, float", 20, 80);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null String, float",
+ 20, 80);
+ }*/
+ //try {
+ g.drawString(emptyStr, 20.0f, 100.0f);
+ g.drawString("OK for empty String, float", 20.0f, 100.f);
+ /* } catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty String, float",
+ 20, 100);
+ }*/
+
+ // API 3: null & empty drawString(Iterator, int, int);
+ try {
+ g.drawString(nullIterator, 20, 120);
+ g.drawString("FAILURE: No NPE for null iterator, float", 20, 120);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null iterator, int", 20, 120);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null iterator, int",
+ 20, 120);
+ } */
+ try {
+ g.drawString(emptyIterator, 20, 140);
+ g.drawString("FAILURE: No IAE for empty iterator, int",
+ 20, 140);
+ } catch (IllegalArgumentException e) {
+ g.drawString("caught expected IAE for empty iterator, int",
+ 20, 140);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty iterator, int",
+ 20, 140);
+ } */
+
+
+ // API 4: null & empty drawString(Iterator, float, int);
+ try {
+ g.drawString(nullIterator, 20.0f, 160.0f);
+ g.drawString("FAILURE: No NPE for null iterator, float", 20, 160);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null iterator, float", 20, 160);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null iterator, float",
+ 20, 160);
+ } */
+
+ try {
+ g.drawString(emptyIterator, 20, 180);
+ g.drawString("FAILURE: No IAE for empty iterator, float",
+ 20, 180);
+ } catch (IllegalArgumentException e) {
+ g.drawString("caught expected IAE for empty iterator, float",
+ 20, 180);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty iterator, float",
+ 20, 180);
+ } */
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintParenString.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4399442
+ * @summary Brackets should be quoted in Postscript output
+ * @author prr
+ * @run main/manual PrintParenString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintParenString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text message as in the test window on the screen",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintParenString f = new PrintParenString();
+ f.show();
+ }
+
+ public PrintParenString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ String str = "String containing unclosed parenthesis (.";
+ g.drawString(str, 20, 40);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintRotatedText.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4271596
+ * @bug 4460699
+ * @summary Rotated text printing
+ * @author prr
+ * @run main/manual PrintRotatedText
+ */
+
+/* Text is drawn as spokes of a wheel with both a uniform scale and
+ * a non-uniform scale.
+ * The test is checking whether the implementation properly handles this
+ * and in particular that asking win32 GDI to draw text rotated works
+ * properly.
+ *
+ */
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+public class PrintRotatedText extends Frame implements ActionListener {
+ static String fontname="Lucida Sans Regular"; // our font
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ PrintRotatedText f = new PrintRotatedText();
+ f.show();
+ }
+
+ public PrintRotatedText() {
+ super("JDK 1.2 Text Printing");
+
+ String []fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+ for (int i=0;i<fonts.length;i++) {
+ if (fonts[i].equals("Times New Roman")) {
+ fontname = "Times New Roman";
+ }
+ }
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPageable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Pageable, Printable {
+
+ public static final int MAXPAGE = 8;
+ // public static final String extra ="\u0391A\u2200B\u2702C\u2778D";
+ public static final String extra ="\u0394\u03A9ABCD";
+ public String estr=extra;
+
+ public int getNumberOfPages() {
+ return MAXPAGE;
+ }
+
+ public PageFormat getPageFormat(int pageIndex) {
+ if (pageIndex > MAXPAGE) throw new IndexOutOfBoundsException();
+ PageFormat pf = new PageFormat();
+ Paper p = pf.getPaper();
+ p.setImageableArea(36, 36, p.getWidth()-72, p.getHeight()-72);
+ pf.setPaper(p);
+
+/*
+ if (pageIndex==1)
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ else if (pageIndex==2)
+ pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+*/
+
+ return pf;
+ }
+
+ public Printable getPrintable(int pageIndex) {
+ if (pageIndex > MAXPAGE) throw new IndexOutOfBoundsException();
+ return this;
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+System.out.println("****"+pgIndex);
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ //g2d.drawString("top left of page format",20,20 );
+ int modulo = pgIndex % 4;
+ int divvy = pgIndex / 4;
+ if (divvy != 0 ) {
+ g2d.setFont(new Font(fontname,Font.PLAIN, 18));
+ estr = "";
+ } else {
+ estr = extra;
+ }
+
+ int xs = 1;
+ int ys = 1;
+
+ if (modulo == 1) {
+ xs = -1;
+ }
+ if (modulo == 2) {
+ ys = -1;
+ }
+ if (modulo == 3) {
+ xs = -1;
+ ys = -1;
+ }
+
+ g2d.translate(iw*0.25, ih*0.2);
+ drawTheText((Graphics2D)g2d.create(), xs*1.0,ys* 1.0);
+ g2d.translate(iw*0.25, ih*0.2);
+ drawTheText((Graphics2D)g2d.create(), xs*1.0,ys* 1.5);
+ g2d.translate(-iw*0.2, ih*0.3);
+ drawTheText((Graphics2D)g2d.create(), xs*1.5, ys*1.0);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ private void drawTheText(Graphics2D g2d, double sx, double sy) {
+ double mat[]= new double[6];
+
+ g2d.drawOval(-75,-75,150,150);
+ int degrees = 30;
+ for (int i=0;i<360;i=i+degrees) {
+ AffineTransform saveXfm = g2d.getTransform();
+ g2d.scale(sx, sy);
+ int ttype = g2d.getTransform().getType();
+ String s = "ANGLE="+i;
+ s +=estr;
+ g2d.drawString(s, 20, 0);
+ FontRenderContext frc = g2d.getFontRenderContext();
+ Font f = g2d.getFont();
+ Rectangle2D r2d = f.getStringBounds(s, frc);
+ g2d.drawLine(20, 1, 20+(int)r2d.getWidth(), 1);
+ g2d.scale(1.0/sx, 1.0/sy);
+ g2d.setTransform(saveXfm);
+
+ g2d.rotate(Math.toRadians(degrees));
+ }
+ }
+
+ public void paint(Graphics g) {
+ g.translate(200,200);
+ g.setFont(new Font("serif", Font.PLAIN, 12));
+ drawTheText((Graphics2D)g, 1.0, 1.5);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(400, 400);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextLayout.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4480930
+ * @summary TextLayout prints as filled shapes
+ * @author prr
+ * @run main/manual PrintTextLayout
+ */
+
+/* This is a MANUAL test and must be run on a system with a printer
+ * configured.
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PrintTextLayout implements Printable {
+ static String[] fontnames = {
+ "Lucida Sans",
+ "Lucida Bright",
+ "Lucida Sans Typewriter",
+ "SansSerif",
+ "Serif",
+ "Monospaced",
+ };
+
+ static String text =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
+
+ public static void main(String args[]) {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null) {
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ aset.add(new Destination((new File("./out.ps")).toURI()));
+ PageFormat pf = pj.defaultPage();
+ Paper p = pf.getPaper();
+ // Extend imageable width to reduce likelihood end of text
+ // is clipped as we'd like to see the end of the line.
+ p.setImageableArea(p.getImageableX(), p.getImageableY(),
+ p.getWidth()-p.getImageableX(),
+ p.getImageableHeight());
+ pf.setPaper(p);
+ pj.setPrintable( new PrintTextLayout(), pf);
+ try {
+ pj.print(aset);
+ } catch (PrinterException pe) {
+ pe.printStackTrace();
+ } finally {
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0) return Printable.NO_SUCH_PAGE;
+
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY()+50);
+
+ float ypos = 20f;
+ for (int f=0; f< fontnames.length; f++) {
+ for (int s=0;s<4;s++) {
+ Font font = new Font(fontnames[f], s, 12);
+ ypos = drawText(g2d, font, ypos);
+ }
+ }
+ return Printable.PAGE_EXISTS;
+ }
+
+ float drawText(Graphics2D g2d, Font font, float ypos) {
+ int x = 10;
+ /* Set the graphics font to something odd before using TL so
+ * can be sure it picks up the font from the TL, not the graphics */
+ Font f1 = new Font("serif", Font.ITALIC, 1);
+ g2d.setFont(f1);
+ FontRenderContext frc = new FontRenderContext(null, false, false);
+ TextLayout tl = new TextLayout(text ,font, frc);
+ float ascent = tl.getAscent();
+ int dpos = (int)(ypos+ascent);
+ tl.draw(g2d, x, dpos);
+ int dpos2 = (int)(ypos+ascent+tl.getDescent());
+ g2d.drawLine(x, dpos2, x+(int)tl.getAdvance(), dpos2);
+ float tlHeight = tl.getAscent()+tl.getDescent()+tl.getLeading();
+ return ypos+tlHeight;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextPane.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test PrintTextPane.java
+ @bug 6452415 6570471
+ @summary Test that swing text prints using GDI printer fonts.
+ @author prr: area=PrinterJob
+ @run main PrintTextPane
+
+ */
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import java.awt.print.*;
+
+public class PrintTextPane extends JTextPane implements Printable {
+
+ static String text = "Twinkle twinkle little star, \n" +
+ "How I wonder what you are. \n" +
+ "Up above the world so high, \n" +
+ "Like a diamond in the sky. \n" +
+ "Twinkle, twinkle, little star, \n" +
+ "How I wonder what you are!\n";
+
+ public int print(Graphics g, PageFormat pf, int page)
+ throws PrinterException {
+ if (page > 0) {
+ return NO_SUCH_PAGE;
+ }
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ printAll(g);
+ return PAGE_EXISTS;
+ }
+
+ public void printPane(PrintRequestAttributeSet aset) {
+ try {
+ print(null, null, false, null, aset, false);
+ } catch (PrinterException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void printPaneJob(PrintRequestAttributeSet aset) {
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setPrintable(this);
+ try {
+ job.print(aset);
+ } catch (PrinterException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public PrintTextPane(String fontFamily) {
+ super();
+ SimpleAttributeSet aset = new SimpleAttributeSet();
+ StyleConstants.setFontFamily(aset, fontFamily);
+ setCharacterAttributes(aset, false);
+ setText(text+text+text+text+text+text+text+text);
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ String os = System.getProperty("os.name");
+
+ if (!os.startsWith("Windows")) {
+ return;
+ }
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ if (job.getPrintService() == null) {
+ System.err.println("Warning: no printers, skipping test");
+ return;
+ }
+ JFrame f = new JFrame("Print Text Pane1");
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ PrintTextPane monoPane = new PrintTextPane("Monospaced");
+ f.add("East", monoPane);
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ PrintTextPane courPane = new PrintTextPane("Courier New");
+ f.add("West", courPane);
+ f.pack();
+ f.setVisible(true);
+
+ File spoolFile = File.createTempFile("CourText", ".prn");
+ System.out.println(spoolFile);
+ Destination dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ courPane.printPane(aset);
+ long courLen = spoolFile.length();
+ System.out.println("CourText="+spoolFile.length());
+ spoolFile.delete();
+
+ spoolFile = File.createTempFile("MonoText", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ monoPane.printPane(aset);
+ long monoLen = spoolFile.length();
+ System.out.println("MonoText="+spoolFile.length());
+ spoolFile.delete();
+
+ if (courLen > 2 * monoLen) {
+ throw new RuntimeException("Shapes being printed?");
+ }
+
+ spoolFile = File.createTempFile("CourJob", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ courPane.printPaneJob(aset);
+ courLen = spoolFile.length();
+ System.out.println("CourJob="+spoolFile.length());
+ spoolFile.delete();
+
+ spoolFile = File.createTempFile("MonoJob", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ monoPane.printPaneJob(aset);
+ monoLen = spoolFile.length();
+ System.out.println("MonoJob="+spoolFile.length());
+ spoolFile.delete();
+
+ if (courLen > 2 * monoLen) {
+ throw new RuntimeException("Shapes being printed?");
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6425068 7157659
+ * @summary Confirm that text prints where we expect to the length we expect.
+ * @run main/manual=yesno PrintTextTest
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.text.*;
+import java.util.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PrintTextTest extends Component implements Printable {
+
+ static int preferredSize;
+ Font textFont;
+ AffineTransform gxTx;
+ String page;
+ boolean useFM;
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "This tests that printed text renders similarly to on-screen",
+ "under a variety of APIs and graphics and font transforms",
+ "Print to your preferred printer. Collect the output.",
+ "Refer to the onscreen buttons to cycle through the on-screen",
+ "content",
+ "For each page, confirm that the printed content corresponds to",
+ "the on-screen rendering for that *same* page.",
+ "Some cases may look odd but its intentional. Verify",
+ "it looks the same on screen and on the printer.",
+ "Note that text does not scale linearly from screen to printer",
+ "so some differences are normal and not a bug.",
+ "The easiest way to spot real problems is to check that",
+ "any underlines are the same length as the underlined text",
+ "and that any rotations are the same in each case.",
+ "Note that each on-screen page is printed in both portrait",
+ "and landscape mode",
+ "So for example, Page 1/Portrait, and Page 1/Landscape when",
+ "rotated to view properly, should both match Page 1 on screen.",
+ };
+ Sysout.createDialogWithInstructions(instructions);
+
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat portrait = pjob.defaultPage();
+ portrait.setOrientation(PageFormat.PORTRAIT);
+ preferredSize = (int)portrait.getImageableWidth();
+
+ PageFormat landscape = pjob.defaultPage();
+ landscape.setOrientation(PageFormat.LANDSCAPE);
+
+ Book book = new Book();
+
+ JTabbedPane p = new JTabbedPane();
+
+ int page = 1;
+ Font font = new Font("Dialog", Font.PLAIN, 18);
+ String name = "Page " + new Integer(page++);
+ PrintTextTest ptt = new PrintTextTest(name, font, null, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Dialog", Font.PLAIN, 18);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, true);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Lucida Sans", Font.PLAIN, 18);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Lucida Sans", Font.PLAIN, 18);
+ AffineTransform rotTx = AffineTransform.getRotateInstance(0.15);
+ rotTx.translate(60,0);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, rotTx, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = font.deriveFont(rotTx);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, false);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ font = new Font("MS Gothic", Font.PLAIN, 12);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintJAText(name, font, null, true);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("MS Gothic", Font.PLAIN, 12);
+ name = "Page " + new Integer(page++);
+ rotTx = AffineTransform.getRotateInstance(0.15);
+ ptt = new PrintJAText(name, font, rotTx, true);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+ }
+
+ pjob.setPageable(book);
+
+ JFrame f = new JFrame();
+ f.add(BorderLayout.CENTER, p);
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ f.pack();
+ f.show();
+
+ try {
+ if (pjob.printDialog()) {
+ pjob.print();
+ }
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public PrintTextTest(String page, Font font, AffineTransform gxTx,
+ boolean fm) {
+ this.page = page;
+ textFont = font;
+ this.gxTx = gxTx;
+ this.useFM = fm;
+ setBackground(Color.white);
+ }
+
+ public static AttributedCharacterIterator getIterator(String s) {
+ return new AttributedString(s).getIterator();
+ }
+
+ static String orient(PageFormat pf) {
+ if (pf.getOrientation() == PageFormat.PORTRAIT) {
+ return "Portrait";
+ } else {
+ return "Landscape";
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g.drawString(page+" "+orient(pf),50,20);
+ g.translate(0, 25);
+ paint(g);
+ return PAGE_EXISTS;
+ }
+
+ public Dimension getMinimumSize() {
+ return getPreferredSize();
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(preferredSize, preferredSize);
+ }
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+
+ Graphics2D g2d = (Graphics2D) g;
+ if (gxTx != null) {
+ g2d.transform(gxTx);
+ }
+ if (useFM) {
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ }
+
+ g.setFont(textFont);
+ FontMetrics fm = g.getFontMetrics();
+
+ String s;
+ int LS = 30;
+ int ix=10, iy=LS+10;
+ g.setColor(Color.black);
+
+ s = "drawString(String str, int x, int y)";
+ g.drawString(s, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawString(AttributedCharacterIterator iterator, int x, int y)";
+ g.drawString(getIterator(s), ix, iy);
+
+ iy += LS;
+ s = "\tdrawChars(\t\r\nchar[], int off, int len, int x, int y\t)";
+ g.drawChars(s.toCharArray(), 0, s.length(), ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawBytes(byte[], int off, int len, int x, int y)";
+ byte data[] = new byte[s.length()];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) s.charAt(i);
+ }
+ g.drawBytes(data, 0, data.length, ix, iy);
+
+ Font f = g2d.getFont();
+ FontRenderContext frc = g2d.getFontRenderContext();
+
+ iy += LS;
+ s = "drawString(String s, float x, float y)";
+ g2d.drawString(s, (float) ix, (float) iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawString(AttributedCharacterIterator iterator, "+
+ "float x, float y)";
+ g2d.drawString(getIterator(s), (float) ix, (float) iy);
+
+ iy += LS;
+ s = "drawGlyphVector(GlyphVector g, float x, float y)";
+ GlyphVector gv = f.createGlyphVector(frc, s);
+ g2d.drawGlyphVector(gv, ix, iy);
+ Point2D adv = gv.getGlyphPosition(gv.getNumGlyphs());
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1);
+ }
+
+ iy += LS;
+ s = "GlyphVector with position adjustments";
+
+ gv = f.createGlyphVector(frc, s);
+ int ng = gv.getNumGlyphs();
+ adv = gv.getGlyphPosition(ng);
+ for (int i=0; i<ng; i++) {
+ Point2D gp = gv.getGlyphPosition(i);
+ double gx = gp.getX();
+ double gy = gp.getY();
+ if (i % 2 == 0) {
+ gy+=5;
+ } else {
+ gy-=5;
+ }
+ gp.setLocation(gx, gy);
+ gv.setGlyphPosition(i, gp);
+ }
+ g2d.drawGlyphVector(gv, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1);
+ }
+
+ iy +=LS;
+ s = "drawString: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ g.drawString(s, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "TextLayout 1: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ TextLayout tl = new TextLayout(s, new HashMap(), frc);
+ tl.draw(g2d, ix, iy);
+
+ iy += LS;
+ s = "TextLayout 2: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ tl = new TextLayout(s, f, frc);
+ tl.draw(g2d, ix, iy);
+ }
+}
+
+class PrintJAText extends PrintTextTest {
+
+
+ public PrintJAText(String page, Font font, AffineTransform gxTx,
+ boolean fm) {
+ super(page, font, gxTx, fm);
+ }
+
+ private static final String TEXT =
+ "\u3042\u3044\u3046\u3048\u304a\u30a4\u30ed\u30cf" +
+ "\u30cb\u30db\u30d8\u30c8\u4e00\u4e01\u4e02\u4e05\uff08";
+
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+
+ Graphics2D g2d = (Graphics2D) g;
+ if (gxTx != null) {
+ g2d.transform(gxTx);
+ }
+ if (useFM) {
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ }
+
+ String text = TEXT + TEXT + TEXT;
+ g.setColor(Color.black);
+ int y = 20;
+ float origSize = 7f;
+ for (int i=0;i<11;i++) {
+ float size = origSize+(i*0.1f);
+ g2d.translate(0, size+6);
+ Font f = textFont.deriveFont(size);
+ g2d.setFont(f);
+ FontMetrics fontMetrics = g2d.getFontMetrics();
+ int stringWidth = fontMetrics.stringWidth(text);
+ g.drawLine(0, y+1, stringWidth, y+1);
+ g.drawString(text, 0, y);
+ y +=10;
+ }
+ }
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 20, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTranslatedFont.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6359734
+ * @summary Test that fonts with a translation print where they should.
+ * @author prr
+ * @run main/manual PrintTranslatedFont
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintTranslatedFont extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "content as the test window on the screen, in particular the lines",
+ "should be immediately under the text",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintTranslatedFont f = new PrintTranslatedFont();
+ f.show();
+ }
+
+ public PrintTranslatedFont() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ Font f = new Font("Dialog", Font.PLAIN, 20);
+ int tx = 20;
+ int ty = 20;
+ AffineTransform at = AffineTransform.getTranslateInstance(tx, ty);
+ f = f.deriveFont(at);
+ g.setFont(f);
+
+ FontMetrics fm = g.getFontMetrics();
+ String str = "Basic ascii string";
+ int sw = fm.stringWidth(str);
+ int posx = 20, posy = 40;
+ g.drawString(str, posx, posy);
+ g.drawLine(posx+tx, posy+ty+2, posx+tx+sw, posy+ty+2);
+
+ posx = 20; posy = 70;
+ str = "Test string compound printing \u2203\u2200";
+ sw = fm.stringWidth(str);
+ g.drawString(str, posx, posy);
+ g.drawLine(posx+tx, posy+ty+2, posx+tx+sw, posy+ty+2);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintVolatileImage.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4511023
+ * @summary Image should be sent to printer, no exceptions thrown
+ * @author prr
+ * @run main/manual PrintVolatileImage
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.print.*;
+
+public class PrintVolatileImage extends Component
+ implements ActionListener, Printable {
+
+ VolatileImage vimg = null;
+
+ public static void main(String args[]) {
+ Frame f = new Frame();
+ PrintVolatileImage pvi = new PrintVolatileImage();
+ f.add("Center", pvi);
+ Button b = new Button("Print");
+ b.addActionListener(pvi);
+ f.add("South", b);
+ f.pack();
+ f.show();
+ }
+
+ public PrintVolatileImage() {
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(100,100);
+ }
+
+ public void paint(Graphics g) {
+ if (vimg == null) {
+ vimg = createVolatileImage(100,100);
+ Graphics ig = vimg.getGraphics();
+ ig.setColor(Color.white);
+ ig.fillRect(0,0,100,100);
+ ig.setColor(Color.black);
+ ig.drawLine(0,0,100,100);
+ ig.drawLine(100,0,0,100);
+ }
+ g.drawImage(vimg, 0,0, null);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+ pj.setPrintable(this);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ paint(g);
+ return Printable.PAGE_EXISTS;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDevice.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ *
+ * @bug 4276227
+ * @summary Checks that the PrinterGraphics is for a Printer GraphicsDevice.
+ * Test doesn't run unless there's a printer on the system.
+ * @author prr
+ * @run main/othervm PrinterDevice
+ */
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.io.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PrinterDevice implements Printable {
+
+ public static void main(String args[]) throws PrinterException {
+ System.setProperty("java.awt.headless", "true");
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj.getPrintService() == null) {
+ return; /* Need a printer to run this test */
+ }
+
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ File f = new File("./out.prn");
+ f.deleteOnExit();
+ aset.add(new Destination(f.toURI()));
+ aset.add(OrientationRequested.LANDSCAPE);
+ pj.setPrintable(new PrinterDevice());
+ pj.print(aset);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ if (pageIndex > 0 ) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ /* Make sure calls to get DeviceConfig, its transforms,
+ * etc all work without exceptions and as expected */
+ Graphics2D g2 = (Graphics2D)g;
+ GraphicsConfiguration gConfig = g2.getDeviceConfiguration();
+ AffineTransform dt = gConfig.getDefaultTransform();
+ AffineTransform nt = gConfig.getNormalizingTransform();
+ AffineTransform gt = g2.getTransform();
+
+ System.out.println("Graphics2D transform = " + gt);
+ System.out.println("Default transform = " + dt);
+ System.out.println("Normalizing transform = " + nt);
+
+ Rectangle bounds = gConfig.getBounds();
+ System.out.println("Bounds = " + bounds);
+ if (!nt.isIdentity()) {
+ throw new RuntimeException("Expected Identity transdform");
+ }
+
+ /* Make sure that device really is TYPE_PRINTER */
+ GraphicsDevice gd = gConfig.getDevice();
+ System.out.println("Printer Device ID = " + gd.getIDstring());
+ if (!(gd.getType() == GraphicsDevice.TYPE_PRINTER)) {
+ throw new RuntimeException("Expected printer device");
+ }
+ System.out.println(" *** ");
+ System.out.println("");
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDialogsModalityTest/PrinterDialogsModalityTest.html Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,43 @@
+<!--
+ Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<html>
+<!--
+ @test
+ @bug 4784285 4785920
+ @summary check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ @author Your Name: area=PrinterJob.modality
+ @run applet/manual=yesno PrinterDialogsModalityTest.html
+ -->
+<head>
+<title> PrinterDialogsModalityTest </title>
+</head>
+<body>
+
+<h1>PrinterDialogsModalityTest<br>Bug ID: 4784285 4785920</h1>
+
+<p> See the dialog box (usually in upper left corner) for instructions</p>
+
+<APPLET CODE="PrinterDialogsModalityTest.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDialogsModalityTest/PrinterDialogsModalityTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ test
+ @bug 4784285 4785920
+ @summary check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ @author son@sparc.spb.su: area=PrinterJob.modality
+ @run applet/manual=yesno PrinterDialogsModalityTest.html
+*/
+
+/**
+ * PrinterDialogsModalityTest.java
+ *
+ * summary: check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ */
+
+import java.applet.Applet;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.TextArea;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+
+public class PrinterDialogsModalityTest extends Applet
+{
+ //Declare things used in the test, like buttons and labels here
+
+ public void init()
+ {
+ //Create instructions for the user here, as well as set up
+ // the environment -- set the layout manager, add buttons,
+ // etc.
+ this.setLayout (new BorderLayout ());
+
+ String[] instructions =
+ {
+ "This is a Windows only test, for other platforms consider it passed",
+ "After test start you will see frame titled \"test Frame\"",
+ "with two buttons - \"Page Dialog\" and \"Print Dialog\"",
+ "1. make the frame active by clicking on title",
+ "2. press \"Page Dialog\" button, page dailog should popup",
+ "3. make sure page dialog is modal (if not test is failed)",
+ "4. close the dialog (either cancel it or press ok)",
+ "5. make sure the frame is still active (if not test is failed)",
+ "6. press \"Print Dialog\" button, print dialog should popup",
+ "7. repeat steps 3.-5.",
+ "",
+ "If you are able to execute all steps successfully then test is passed, else failed."
+ };
+ Sysout.createDialogWithInstructions( instructions );
+
+ }//End init()
+
+ public void start ()
+ {
+ //Get things going. Request focus, set size, et cetera
+ setSize (200,200);
+ setVisible(true);
+ validate();
+
+ Button page = new Button("Page Dialog");
+ page.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ PrinterJob prnJob = PrinterJob.getPrinterJob();
+ prnJob.pageDialog(new PageFormat());
+ }
+ });
+ Button print = new Button("Print Dialog");
+ print.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ PrinterJob prnJob = PrinterJob.getPrinterJob();
+ prnJob.printDialog();
+ }
+ });
+ Frame frame = new Frame("Test Frame");
+ frame.setLayout(new FlowLayout());
+ frame.add(page);
+ frame.add(print);
+ frame.setLocation(200, 200);
+ frame.pack();
+ frame.setVisible(true);
+
+ }// start()
+
+ //The rest of this class is the actions which perform the test...
+
+ //Use Sysout.println to communicate with the user NOT System.out!!
+ //Sysout.println ("Something Happened!");
+
+}// class PrinterDialogsModalityTest
+
+/* Place other classes related to the test after this line */
+
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+{
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+{
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ setVisible(true);
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ System.out.println(messageIn);
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterJobDialogBugDemo.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4775862
+ * @run main/manual PrinterJobDialogBugDemo
+ */
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+public class PrinterJobDialogBugDemo extends JFrame implements Printable {
+
+ public static void main(String[] args) {
+ new PrinterJobDialogBugDemo();
+ }
+
+ private PrinterJobDialogBugDemo() {
+ super("Printer Job Dialog Bug Demo");
+
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setSize(700,700);
+
+ JButton btnPrint = new JButton("Print...");
+ btnPrint.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae) {
+ showPrintDialog();
+ }
+ });
+
+ Container contentPane = getContentPane();
+ contentPane.add(
+ new JLabel("<html>This is the main Application Window. " +
+ "To demonstrate the problem:" +
+ "<ol>" +
+ "<li>Click the Print button at the bottom of this window. " +
+ "The Print dialog will appear." +
+ "<li>Select another application window." +
+ "<li>On the Windows taskbar, click the coffee-cup icon for " +
+ "this demo application. This brings this window to the " +
+ "front but the Print dialog remains hidden. " +
+ "Since this window " +
+ "is no longer selectable, it can't be moved aside to expose "
++
+ "the Print dialog that is now behind it." +
+ "</ol>",
+ SwingConstants.CENTER),
+ BorderLayout.NORTH);
+ contentPane.add(btnPrint, BorderLayout.SOUTH);
+ setVisible(true);
+ }
+
+ private void showPrintDialog() {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(this);
+ PrintRequestAttributeSet printRequestAttrSet =
+ new HashPrintRequestAttributeSet();
+ printJob.printDialog(printRequestAttrSet);
+ }
+
+ public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat,
+int pageIndex) {
+ if (pageIndex == 0) {
+ return(PAGE_EXISTS);
+ } else {
+ return(NO_SUCH_PAGE);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/RemoveListener.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test 1.1 01/05/17
+ * @bug 4459889
+ * @summary No NullPointerException should occur.
+ * @run main RemoveListener
+*/
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.event.*;
+import javax.print.attribute.standard.*;
+
+public class RemoveListener {
+ public static void main(String[] args){
+ PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);
+ if (pservices.length == 0){
+ return;
+ }
+ DocPrintJob pj = pservices[0].createPrintJob();
+ PrintJobAttributeSet aset = new HashPrintJobAttributeSet();
+ aset.add(JobState.PROCESSING);
+ PrintJobAttributeListener listener = new PJAListener();
+ pj.addPrintJobAttributeListener(listener, aset);
+ pj.removePrintJobAttributeListener(listener);
+ return;
+ }
+}
+
+class PJAListener implements PrintJobAttributeListener {
+ public void attributeUpdate(PrintJobAttributeEvent pjae){
+ return;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/ScaledText/ScaledText.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,438 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4291373
+ @summary Printing of scaled text is wrong / disappearing
+ @author prr: area=PrinterJob
+ @run main/manual ScaledText
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+
+public class ScaledText implements Printable {
+
+ private Image opaqueimg,transimg;
+
+ private static void init() {
+
+ //*** Create instructions for the user here ***
+
+ String[] instructions = {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is two printed pages.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed pages is needed. A passing",
+ "test will print a page on which 6 lines of text will be",
+ "printed, all of the same size. The test fails only if the sizes",
+ "are different, or not all of the sizes labelled 1.0, 2.0, 4.0",
+ "8.0, 16.0, 32.0 appear."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ PageFormat portrait = pjob.defaultPage();
+ book.append(new ScaledText(),portrait);
+
+ pjob.setPageable(book);
+
+ if (pjob.printDialog()) {
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ System.err.println(e);
+ e.printStackTrace();
+ }
+ }
+ System.out.println("Done Printing");
+
+ }//End init()
+
+
+ public ScaledText() {
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ g2D.setColor(Color.black);
+ Font font = new Font("serif", Font.PLAIN, 1);
+
+ float scale;
+ float x;
+ float y;
+
+ scale = 1.0f;
+ x = 3.0f;
+ y = 3.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 2.0f;
+ x = 3.0f;
+ y = 3.5f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 4.0f;
+ x = 3.0f;
+ y = 4.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 8.0f;
+ x = 3.0f;
+ y = 4.5f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 16.0f;
+ x = 3.0f;
+ y = 5.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 32.0f;
+ x = 3.0f;
+ y = 5.5f;
+ printScale(g2D, font, scale, x, y);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ /**
+ * The graphics is scaled and the font and the positions
+ * are reduced in respect to the scaling, so that all
+ * printing should be the same.
+ *
+ * @param g2D graphics2D to paint on
+ * @param font font to paint
+ * @param scale scale for the painting
+ * @param x x position
+ * @param y y position
+ */
+ private void printScale(Graphics2D g2D, Font font,
+ float scale, float x, float y) {
+
+ int RES = 72;
+
+ g2D.scale(scale, scale);
+
+ g2D.setFont (font.deriveFont(10.0f / scale));
+ g2D.drawString("This text is scaled by a factor of " + scale,
+ x * RES / scale, y * RES / scale);
+
+ g2D.scale(1/scale, 1/scale);
+
+}
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, s fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+}// class ScaledText
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //ScaledText
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ ScaledText.pass();
+ }
+ else
+ {
+ ScaledText.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SecurityDialogTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4937672 5100706 6252456
+ * @run main/manual SecurityDialogTest
+ */
+
+import java.awt.* ;
+import java.awt.print.* ;
+import java.io.*;
+import java.security.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class SecurityDialogTest {
+
+
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test.",
+ "This test brings up a native and cross-platform page and",
+ "print dialogs.",
+ "The dialogs should be displayed even when ",
+ "there is no queuePrintJob permission.",
+ "If the dialog has an option to save to file, the option ought",
+ "to be disabled if there is no read/write file permission.",
+ "You should test this by trying different policy files."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ SecurityDialogTest pjc = new SecurityDialogTest() ;
+ }
+
+
+ public SecurityDialogTest() {
+
+ PrinterJob pj = PrinterJob.getPrinterJob() ;
+
+ // Install a security manager which does not allow reading and
+ // writing of files.
+ //PrintTestSecurityManager ptsm = new PrintTestSecurityManager();
+ SecurityManager ptsm = new SecurityManager();
+
+ try {
+ System.setSecurityManager(ptsm);
+ } catch (SecurityException e) {
+ System.out.println("Could not run test - security exception");
+ }
+
+ try {
+ PrintJob pjob = Toolkit.getDefaultToolkit().getPrintJob(new Frame(), "Printing", null, null);
+ Sysout.println("If the value of pjob is null, the test fails.\n");
+ Sysout.println(" pjob = "+pjob);
+ } catch (SecurityException e) {
+ }
+
+ PrintService[] services = PrinterJob.lookupPrintServices();
+ for (int i=0; i<services.length; i++) {
+ System.out.println("SecurityDialogTest service "+i+" : "+services[i]);
+ }
+
+ PrintService defservice = pj.getPrintService();
+ System.out.println("SecurityDialogTest default service : "+defservice);
+
+ System.out.println("SecurityDialogTest native PageDialog ");
+ PageFormat pf1 = pj.pageDialog(new PageFormat());
+
+ System.out.println("SecurityDialogTest swing PageDialog ");
+ PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
+ PageFormat pf2 = pj.pageDialog(attributes);
+
+ // With the security manager installed, save to file should now
+ // be denied.
+ System.out.println("SecurityDialogTest native printDialog ");
+ pj.printDialog();
+
+ System.out.println("SecurityDialogTest swing printDialog ");
+ pj.printDialog(attributes);
+ }
+
+
+ class PrintTestSecurityManager extends SecurityManager {
+ public void checkPackageAccess(String pkg) {
+ }
+ public void checkPropertyAccess(String key) {
+ }
+
+ }
+
+}
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SetCopies/Test.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4694495
+ * @summary Check that the dialog shows copies = 3.
+ * @run main/manual Test
+ */
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class Test {
+ static public void main(String args[]) {
+ DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
+ PrintRequestAttributeSet aSet
+ = new HashPrintRequestAttributeSet();
+ PrintService[] services
+ = PrintServiceLookup.lookupPrintServices(flavor, aSet);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ for (int i=0; i<services.length; i++)
+ System.out.println(services[i].getName());
+ try { pj.setPrintService(services[services.length-1]); }
+ catch (Exception e) { e.printStackTrace(); }
+ pj.setCopies(3);
+ pj.printDialog();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SwingUIText.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6488219 6560738 7158350 8017469
+ * @summary Test that text printed in Swing UI measures and looks OK.
+ * @run main/manual=yesno PrintTextTest
+ */
+
+import java.awt.*;
+import javax.swing.*;
+import java.awt.print.*;
+
+public class SwingUIText implements Printable {
+
+ static String[] instructions = {
+ "This tests that when a Swing UI is printed, that the text",
+ "in each component properly matches the length of the component",
+ "as seen on-screen, and that the spacing of the text is of",
+ "reasonable even-ness. This latter part is very subjective and",
+ "the comparison has to be with JDK1.5 GA, or JDK 1.6 GA",
+ };
+
+ static JFrame frame;
+
+ public static void main(String args[]) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ createUI();
+ }
+ });
+ }
+
+ public static void createUI() {
+
+ Sysout.createDialogWithInstructions(instructions);
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(4,1));
+
+ String text = "marvelous suspicious solving";
+ displayText(panel, text);
+
+ String itext = "\u0641\u0642\u0643 \u0644\u0627\u064b";
+ itext = itext+itext+itext+itext+itext+itext+itext;
+ displayText(panel, itext);
+
+ String itext2 = "\u0641"+text;
+ displayText(panel, itext2);
+
+ JEditorPane editor = new JEditorPane();
+ editor.setContentType("text/html");
+ String CELL = "<TD align=\"center\"><font style=\"font-size: 18;\">Text</font></TD>";
+ String TABLE_BEGIN = "<TABLE BORDER=1 cellpadding=1 cellspacing=0 width=100%>";
+ String TABLE_END = "</TABLE>";
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<html><body>").append(TABLE_BEGIN);
+ for (int j = 0; j < 15; j++) {
+ buffer.append(CELL);
+ }
+ buffer.append("</tr>");
+ buffer.append(TABLE_END).append("</body></html>");
+ editor.setText(buffer.toString());
+
+ panel.add(editor);
+
+ frame = new JFrame("Swing UI Text Printing Test");
+ frame.getContentPane().add(panel);
+ frame.pack();
+ frame.setVisible(true);
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat pf = job.defaultPage();
+ job.setPrintable(new SwingUIText(), pf);
+ if (job.printDialog()) {
+ try { job.print(); }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+
+ static void displayText(JPanel p, String text) {
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(2,1));
+ JPanel row = new JPanel();
+ Font font = new Font("Dialog", Font.PLAIN, 12);
+
+ JLabel label = new JLabel(text);
+ label.setFont(font);
+ row.add(label);
+
+ JButton button = new JButton("Print "+text);
+ button.setMnemonic('P');
+ button.setFont(font);
+ row.add(button);
+
+ panel.add(row);
+
+ row = new JPanel();
+ JTextField textField = new JTextField(text);
+ row.add(textField);
+
+ JTextArea textArea = new JTextArea();
+ textArea.setText(text);
+ row.add(textArea);
+
+ panel.add(row);
+ p.add(panel);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex)
+ throws PrinterException {
+
+ if (pageIndex >= 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ g.translate((int)pf.getImageableX(), (int)pf.getImageableY());
+ frame.printAll(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 10, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/ThinLines.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,429 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 4190081
+ @summary Confirm that the you see "Z" shapes on the printed page.
+ @author prr/rbi: area=PrinterJob
+ @run main/manual ThinLines
+*/
+
+
+//*** global search and replace ThinLines with name of the test ***
+
+/**
+ * ThinLines.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class ThinLines implements Printable {
+
+ private static final int INCH = 72;
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is a printed page.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print a large \"Z\" shape which is repeated 6 times.",
+ "The top-most and diagonal lines of each \"Z\" are thin lines.",
+ "The bottom line of each \"Z\" is a thicker line.",
+ "In a failing test, the thin lines do not appear."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat pf = pjob.defaultPage();
+ Book book = new Book();
+
+ book.append(new ThinLines(), pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ }
+
+ }//End init()
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+
+ g2d.setColor(Color.black);
+ Stroke thinLine = new BasicStroke(0.01f);
+ Stroke thickLine = new BasicStroke(1.0f);
+
+
+ for (int y = 100; y < 900; y += 100) {
+ g2d.setStroke(thinLine);
+ g2d.drawLine(INCH, y, INCH * 3, y);
+ g2d.drawLine(INCH * 3, y, INCH, y + INCH/2);
+ g2d.setStroke(thickLine);
+ g2d.drawLine(INCH, y + INCH/2, INCH * 3, y + INCH/2);
+ }
+
+ return PAGE_EXISTS;
+ }
+
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class ThinLines
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ ThinLines.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ ThinLines.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //ThinLines
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ ThinLines.pass();
+ }
+ else
+ {
+ ThinLines.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/XparColor.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @bug 4179262
+ * @summary Confirm that transparent colors are printed correctly. The
+ * printout should show transparent rings with increasing darkness toward
+ * the center.
+ *@run applet/manual=yesno XparColor.html
+ */
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.event.*;
+import java.awt.geom.Ellipse2D;
+
+
+/**
+ * Creating colors with an alpha value.
+ */
+public class XparColor extends Applet implements Printable {
+
+ public void init() {
+ String[] instructions =
+ {
+ "This test verify that the BullsEye rings are printed correctly. The printout should show transparent rings with increasing darkness toward the center"
+ };
+ Sysout.createDialogWithInstructions( instructions );
+ }
+
+ public XparColor() {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(this);
+ if (printJob.printDialog()) {
+ try {
+ printJob.print();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+
+ public static void main(String s[]) {
+ XparColor xc = new XparColor();
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(xc);
+ if (printJob.printDialog()) {
+ try {
+ printJob.print();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pi)
+ throws PrinterException {
+ if (pi >= 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g2d.translate(pf.getImageableWidth() / 2,
+ pf.getImageableHeight() / 2);
+
+ Dimension d = new Dimension(400, 400);
+
+ double scale = Math.min(pf.getImageableWidth() / d.width,
+ pf.getImageableHeight() / d.height);
+ if (scale < 1.0) {
+ g2d.scale(scale, scale);
+ }
+
+ g2d.translate(-d.width / 2.0, -d.height / 2.0);
+
+ Graphics2D g2 = (Graphics2D)g;
+ drawDemo(d.width, d.height, g2);
+ g2.dispose();
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void drawDemo(int w, int h, Graphics2D g2) {
+
+ Color reds[] = { Color.red.darker(), Color.red };
+ for (int N = 0; N < 18; N++) {
+ float i = (N + 2) / 2.0f;
+ float x = (float) (5+i*(w/2/10));
+ float y = (float) (5+i*(h/2/10));
+ float ew = (w-10)-(i*w/10);
+ float eh = (h-10)-(i*h/10);
+ float alpha = (N == 0) ? 0.1f : 1.0f / (19.0f - N);
+ if ( N >= 16 )
+ g2.setColor(reds[N-16]);
+ else
+ g2.setColor(new Color(0f, 0f, 0f, alpha));
+ g2.fill(new Ellipse2D.Float(x,y,ew,eh));
+ }
+ }
+}
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/raster/RasterTest.java Mon Mar 31 11:13:01 2014 -0700
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4242639
+ * @summary Printing quality problem on Canon and NEC
+ * @author prr
+ * @run main/manual RasterTest
+ */
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+
+
+public class RasterTest extends Frame implements ActionListener {
+
+ private RasterCanvas c;
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test uses rendering operations which force the implementation",
+ "to print the page as a raster",
+ "You should see two square images, the 1st containing overlapping",
+ "composited squares, the lower image shows a gradient paint.",
+ "The printed output should match the on-screen display, although",
+ "only colour printers will be able to accurately reproduce the",
+ "subtle color changes."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ RasterTest f = new RasterTest();
+ f.show();
+ }
+
+ public RasterTest() {
+ super("Java 2D Raster Printing");
+
+ c = new RasterCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+
+ setBackground(Color.white);
+
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+}
+
+
+ class RasterCanvas extends Canvas implements Printable {
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d= (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ doPaint(g2d);
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g) {
+ doPaint(g);
+ }
+
+ public void paintComponent(Graphics g) {
+ doPaint(g);
+ }
+
+ public void doPaint(Graphics g) {
+ Graphics2D g2 = (Graphics2D)g;
+
+ g2.setColor(Color.black);
+
+ BufferedImage bimg = new BufferedImage(200, 200,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics ig = bimg.getGraphics();
+ Color alphared = new Color(255, 0, 0, 128);
+ Color alphagreen = new Color(0, 255, 0, 128);
+ Color alphablue = new Color(0, 0, 255, 128);
+ ig.setColor(alphared);
+ ig.fillRect(0,0,200,200);
+ ig.setColor(alphagreen);
+ ig.fillRect(25,25,150,150);
+ ig.setColor(alphablue);
+ ig.fillRect(75,75,125,125);
+ g.drawImage(bimg, 10, 25, this);
+
+ GradientPaint gp =
+ new GradientPaint(10.0f, 10.0f, alphablue, 210.0f, 210.0f, alphared, true);
+ g2.setPaint(gp);
+ g2.fillRect(10, 240, 200, 200);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(500, 500);
+ }
+
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class