Path: blob/master/test/jdk/javax/print/attribute/ServiceDlgPageRangeTest.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 5080098 816420525* @summary Verify if PageRanges option is disabled for Non service-formatted26* flavors.27* @run main/manual ServiceDlgPageRangeTest28*/29import java.awt.BorderLayout;30import java.awt.FlowLayout;31import java.awt.event.WindowAdapter;32import java.awt.event.WindowEvent;33import javax.print.DocFlavor;34import javax.print.PrintService;35import javax.print.PrintServiceLookup;36import javax.print.ServiceUI;37import javax.print.attribute.Attribute;38import javax.print.attribute.HashPrintRequestAttributeSet;39import javax.print.attribute.standard.PageRanges;40import javax.swing.JButton;41import javax.swing.JDialog;42import javax.swing.JPanel;43import javax.swing.JTextArea;44import javax.swing.SwingUtilities;4546public class ServiceDlgPageRangeTest {4748private static Thread mainThread;49private static boolean testPassed;50private static boolean testGeneratedInterrupt;51private static DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;52private static PrintService services[];5354/**55* Starts the application.56*/57public static void printTest() {5859System.out.println("\nDefault print service: " +60PrintServiceLookup.lookupDefaultPrintService());61System.out.println("is flavor: "+flavor+" supported? "+62services[0].isDocFlavorSupported(flavor));63System.out.println("is Page Ranges category supported? "+64services[0].isAttributeCategorySupported(PageRanges.class));65System.out.println("is PageRanges[2] value supported ? "+66services[0].isAttributeValueSupported(67new PageRanges(2), flavor, null));6869HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();70//prSet.add(new PageRanges(2));71PrintService selService = ServiceUI.printDialog(null, 200, 200,72services, services[0], flavor, prSet);7374System.out.println("\nSelected Values\n");75Attribute attr[] = prSet.toArray();76for (int x = 0; x < attr.length; x ++) {77System.out.println("Attribute: " + attr[x].getName() +78" Value: " + attr[x]);79}80}8182/**83* Starts the application.84*/85public static void main(java.lang.String[] args) throws Exception {86services = PrintServiceLookup.lookupPrintServices(flavor, null);8788if (services.length == 0) {89System.out.println("No print service found!!");90return;91}92SwingUtilities.invokeAndWait(() -> {93doTest(ServiceDlgPageRangeTest::printTest);94});95mainThread = Thread.currentThread();96try {97Thread.sleep(600000);98} catch (InterruptedException e) {99if (!testPassed && testGeneratedInterrupt) {100throw new RuntimeException("PageRanges option is not disabled "101+ "for for Non serv-formatted flvrs");102}103}104if (!testGeneratedInterrupt) {105throw new RuntimeException("user has not executed the test");106}107}108109public static synchronized void pass() {110testPassed = true;111testGeneratedInterrupt = true;112mainThread.interrupt();113}114115public static synchronized void fail() {116testPassed = false;117testGeneratedInterrupt = true;118mainThread.interrupt();119}120121private static void doTest(Runnable action) {122String description123= " Visual inspection of print dialog is required.\n"124+ " A print dialog will be shown.\n "125+ " Please verify Pages(From/To) option is disabled.\n"126+ " Press Cancel to close the print dialog.\n"127+ " If Pages(From/To) option is disabled, press PASS else press FAIL";128129final JDialog dialog = new JDialog();130dialog.setTitle("printSelectionTest");131JTextArea textArea = new JTextArea(description);132textArea.setEditable(false);133final JButton testButton = new JButton("Start Test");134final JButton passButton = new JButton("PASS");135passButton.setEnabled(false);136passButton.addActionListener((e) -> {137dialog.dispose();138pass();139});140final JButton failButton = new JButton("FAIL");141failButton.setEnabled(false);142failButton.addActionListener((e) -> {143dialog.dispose();144fail();145});146testButton.addActionListener((e) -> {147testButton.setEnabled(false);148action.run();149passButton.setEnabled(true);150failButton.setEnabled(true);151});152JPanel mainPanel = new JPanel(new BorderLayout());153mainPanel.add(textArea, BorderLayout.CENTER);154JPanel buttonPanel = new JPanel(new FlowLayout());155buttonPanel.add(testButton);156buttonPanel.add(passButton);157buttonPanel.add(failButton);158mainPanel.add(buttonPanel, BorderLayout.SOUTH);159dialog.add(mainPanel);160dialog.pack();161dialog.setVisible(true);162dialog.addWindowListener(new WindowAdapter() {163@Override164public void windowClosing(WindowEvent e) {165System.out.println("main dialog closing");166testGeneratedInterrupt = false;167mainThread.interrupt();168}169});170}171}172173174