Path: blob/master/test/jdk/javax/print/attribute/ServiceDlgSheetCollateTest.java
41149 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 508083025* @summary Verify if SheetCollate option is disabled for flavors that do not26* support SheetCollate27* @run main/manual ServiceDlgSheetCollateTest28*/29import java.awt.BorderLayout;30import java.awt.FlowLayout;31import javax.print.DocFlavor;32import javax.print.PrintService;33import javax.print.PrintServiceLookup;34import javax.print.ServiceUI;35import javax.print.attribute.Attribute;36import javax.print.attribute.HashPrintRequestAttributeSet;37import javax.print.attribute.standard.SheetCollate;38import javax.swing.JButton;39import javax.swing.JDialog;40import javax.swing.JPanel;41import javax.swing.JTextArea;42import javax.swing.SwingUtilities;4344public class ServiceDlgSheetCollateTest {45private static Thread mainThread;46private static boolean testPassed;47private static boolean testGeneratedInterrupt;4849/**50* Starts the application.51*/52public static void main(java.lang.String[] args) throws Exception {53SwingUtilities.invokeAndWait(() -> {54doTest(ServiceDlgSheetCollateTest::printTest);55});56mainThread = Thread.currentThread();57try {58Thread.sleep(600000);59} catch (InterruptedException e) {60if (!testPassed && testGeneratedInterrupt) {61throw new RuntimeException("SheetCollate option is not disabled "62+ "for flavors that do not support sheetCollate");63}64}65if (!testGeneratedInterrupt) {66throw new RuntimeException("user has not executed the test");67}68}6970private static void printTest() {71ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest();72DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;73//DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;74PrintService defService = null, service[] = null;75defService = PrintServiceLookup.lookupDefaultPrintService();76service = PrintServiceLookup.lookupPrintServices(flavor, null);7778if ((service == null) || (service.length == 0)) {79throw new RuntimeException("No Printer services found");80}81if (defService != null) {82System.out.println("\nDefault print service: " + service );83System.out.println("is flavor: "+flavor+" supported? "+84defService.isDocFlavorSupported(flavor));85System.out.println("is SheetCollate category supported? "+86defService.isAttributeCategorySupported(SheetCollate.class));87System.out.println("is SheetCollate.COLLATED value supported ? "+88defService.isAttributeValueSupported(SheetCollate.COLLATED,89flavor, null));90}91HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();92try {93PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet);94} catch (IllegalArgumentException ia) {95System.out.println("Exception thrown : " + ia);96}9798System.out.println("\nSelected Values\n");99Attribute attr[] = prSet.toArray();100for (int x = 0; x < attr.length; x ++) {101System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]);102}103104}105106public static synchronized void pass() {107testPassed = true;108testGeneratedInterrupt = true;109mainThread.interrupt();110}111112public static synchronized void fail() {113testPassed = false;114testGeneratedInterrupt = true;115mainThread.interrupt();116}117118private static void doTest(Runnable action) {119String description120= " A print dialog would appear.\n"121+ " Increase the no. of copies.\n"122+ " If COLLATE checkbox gets enabled, press FAIL else press PASS.\n"123+ " Press Cancel to close the dialog.";124125final JDialog dialog = new JDialog();126dialog.setTitle("printSelectionTest");127JTextArea textArea = new JTextArea(description);128textArea.setEditable(false);129final JButton testButton = new JButton("Start Test");130final JButton passButton = new JButton("PASS");131passButton.setEnabled(false);132passButton.addActionListener((e) -> {133dialog.dispose();134pass();135});136final JButton failButton = new JButton("FAIL");137failButton.setEnabled(false);138failButton.addActionListener((e) -> {139dialog.dispose();140fail();141});142testButton.addActionListener((e) -> {143testButton.setEnabled(false);144action.run();145passButton.setEnabled(true);146failButton.setEnabled(true);147});148JPanel mainPanel = new JPanel(new BorderLayout());149mainPanel.add(textArea, BorderLayout.CENTER);150JPanel buttonPanel = new JPanel(new FlowLayout());151buttonPanel.add(testButton);152buttonPanel.add(passButton);153buttonPanel.add(failButton);154mainPanel.add(buttonPanel, BorderLayout.SOUTH);155dialog.add(mainPanel);156dialog.pack();157dialog.setVisible(true);158}159}160161162163