2362N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** This class is a collection of UI convenience methods which provide a 0N/A * graphical user dialog for browsing print services looked up through the Java 0N/A * Print Service API. 0N/A *for a user as well as allowing the user to select the print service to use 0N/A *and specify choices such as paper size and number of copies. 0N/A * The dialogs are designed to work with pluggable print services though the 0N/A * public APIs of those print services. 0N/A * If a print service provides any vendor extensions these may be made 0N/A * accessible to the user through a vendor supplied tab panel Component. 0N/A * Such a vendor extension is encouraged to use Swing! and to support its 0N/A * accessibility APIs. 0N/A * The vendor extensions should return the settings as part of the 0N/A * Applications which want to preserve the user settings should use those 0N/A * settings to specify the print job. 0N/A * Note that this class is not referenced by any other part of the Java 0N/A * Print Service and may not be included in profiles which cannot depend 0N/A * on the presence of the AWT packages. 0N/A * Presents a dialog to the user for selecting a print service (printer). 0N/A * It is displayed at the location specified by the application and 0N/A * If the specification is invalid or would make the dialog not visible it 0N/A * will be displayed at a location determined by the implementation. 0N/A * The dialog blocks its calling thread and is application modal. 0N/A * The dialog may include a tab panel with custom UI lazily obtained from 0N/A * the PrintService's ServiceUIFactory when the PrintService is browsed. 0N/A * The dialog will attempt to locate a MAIN_UIROLE first as a JComponent, 0N/A * then as a Panel. If there is no ServiceUIFactory or no matching role 0N/A * the custom tab will be empty or not visible. 0N/A * The dialog returns the print service selected by the user if the user 0N/A * OK's the dialog and null if the user cancels the dialog. 0N/A * An application must pass in an array of print services to browse. 0N/A * The array must be non-null and non-empty. 0N/A * Typically an application will pass in only PrintServices capable 0N/A * of printing a particular document flavor. 0N/A * An application may pass in a PrintService to be initially displayed. 0N/A * A non-null parameter must be included in the array of browsable 0N/A * If this parameter is null a service is chosen by the implementation. 0N/A * An application may optionally pass in the flavor to be printed. 0N/A * If this is non-null choices presented to the user can be better 0N/A * validated against those supported by the services. 0N/A * An application must pass in a PrintRequestAttributeSet for returning 0N/A * On calling the PrintRequestAttributeSet may be empty, or may contain 0N/A * application-specified values. 0N/A * These are used to set the initial settings for the initially 0N/A * displayed print service. Values which are not supported by the print 0N/A * service are ignored. As the user browses print services, attributes 0N/A * and values are copied to the new display. If a user browses a 0N/A * print service which does not support a particular attribute-value, the 0N/A * default for that service is used as the new value to be copied. 0N/A * If the user cancels the dialog, the returned attributes will not reflect 0N/A * any changes made by the user. 0N/A * A typical basic usage of this method may be : 0N/A * PrintService[] services = PrintServiceLookup.lookupPrintServices( 0N/A * DocFlavor.INPUT_STREAM.JPEG, null); 0N/A * PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); 0N/A * if (services.length > 0) { 0N/A * PrintService service = ServiceUI.printDialog(null, 50, 50, 0N/A * services, services[0], 0N/A * if (service != null) { 0N/A * @param gc used to select screen. null means primary or default screen. 0N/A * @param x location of dialog including border in screen coordinates 0N/A * @param y location of dialog including border in screen coordinates 0N/A * @param services to be browsable, must be non-null. 0N/A * @param defaultService - initial PrintService to display. 0N/A * @param flavor - the flavor to be printed, or null. 0N/A * @param attributes on input is the initial application supplied 0N/A * preferences. This cannot be null but may be empty. 0N/A * On output the attributes reflect changes made by the user. 0N/A * @return print service selected by the user, or null if the user 0N/A * cancelled the dialog. 0N/A * @throws HeadlessException if GraphicsEnvironment.isHeadless() 0N/A * @throws IllegalArgumentException if services is null or empty, 0N/A * or attributes is null, or the initial PrintService is not in the 0N/A * list of browsable services. 0N/A // For now we set owner to null. In the future, it may be passed 0N/A // get union of all GC bounds 0N/A // if portion of dialog is not within the gc boundary 0N/A * POSSIBLE FUTURE API: This method may be used down the road if we 0N/A * decide to allow developers to explicitly display a "page setup" dialog. 0N/A * Currently we use that functionality internally for the AWT print model. 0N/A public static void pageDialog(GraphicsConfiguration gc, 0N/A PrintService service, 0N/A PrintRequestAttributeSet attributes) 0N/A throws HeadlessException 0N/A if (GraphicsEnvironment.isHeadless()) { 0N/A throw new HeadlessException(); 0N/A } else if (service == null) { 0N/A throw new IllegalArgumentException("service must be non-null"); 0N/A } else if (attributes == null) { 0N/A throw new IllegalArgumentException("attributes must be non-null"); 0N/A ServiceDialog dialog = new ServiceDialog(gc, x, y, service, 0N/A flavor, attributes); 0N/A if (dialog.getStatus() == ServiceDialog.APPROVE) { 0N/A PrintRequestAttributeSet newas = dialog.getAttributes(); 0N/A Class amCategory = SunAlternateMedia.class; 0N/A if (attributes.containsKey(amCategory) && 0N/A !newas.containsKey(amCategory)) 0N/A attributes.remove(amCategory); 0N/A attributes.addAll(newas.values()); 0N/A dialog.getOwner().dispose(); 0N/A * Removes any attributes from the given AttributeSet that are